SVN pre-commit hook script to check PHP syntax and CodeSniffer

August 16th, 2010

SVN supports pre and post-commit hook scripts.

The former can be used to do some checks on the code before having it committed. In the example below, a hook script I use (on a dreamhost server of mine) to check if the committed files contain PHP syntax errors or the code doesn't satisfy the code sniffer rules.
Read the rest of this entry »

Map svn inside another svn with svn:externals. Example with Zend Framework and Netbeans

August 15th, 2010

SVN supports external definitions.

Basically, it allows to map a subdirectory of our SVN working copy to an URL of another SVN repository. See the link above for more details.

That's can be useful for example to mount zend framework libraries in our repository, in order to have a smaller and faster svn as well as an automatic update of the libraries directly from the Zend repositories (instead of download them again and add to the working copy, that is a very long process with the ~3k ZF files).
Read the rest of this entry »

Improve performances of any web site: cache pages with Zend Framework

August 15th, 2010

Zend Framework is decoupled, so it's possible to use only the needed features.

I had to improve the performances of an old site, with no cache at all. Changing all the database/file_get_contents requests would have been a long process, so I decided to enable the cache of the web pages with Zend Framework  FrontEnd Page Cache using only few lines of code at the beginning of each page.
That web site uses a header file so I placed there the code only once.
Read the rest of this entry »

Dropbox, a swiss-knife tool for developers

August 1st, 2010

dropbox Among the tools I consider useful, Dropbox is one ! It offers a free online storage space of 2 Gb with automatic synchronization with local directory and versioning ! I personally use to keep my digital books, guides, code snippets, software (php, apache, mysql, portable graphic software, IDEs, etc...) between two houses and workplace.

Nice features are the possibility to share contents with other dropbox users and get public links of the selected files (to let anyone to download that file). The second feature can be used to easily download our compressed files (custom libraries, frameworks) into our new hosting (wget via ssh).

Another feature I like is the "immediate upload": if the same file (thanks probably to a hash of the file) is already on the dropbox servers (as uploaded by another dropbox user I suppose), the file is automatically copied online-to-online without the need to upload it.  Practically, any file downloaded online is probably already on dropbox, of course except personal files and compressed files. When saving the OpenOffice installer, it will be helpful.

Download and enjoy it ! (that's an affiliate link, if you download from that link, I get  additional 250Mb of space, thanks :) )

Using PHP Closures to get cached object with one call

August 1st, 2010

Getting caching objects if a fairly frequent task when dealing with performative web applications.

Standard approach

if (cache object is valid)  {
return cached object
} else {
get fresh object (*)
save object into cache
return object
}

I don't like that approach as there are a lots of LOC that wraps the only meaningful code (to get the fresh object).
Read the rest of this entry »

Free web-based software for project management

July 27th, 2010

project managementAfter being part of a new team that works with outsourcing team with dynamic allocation of resources (developers) without using a software to plan and schedule the project, I'm now interested in experimenting some free web-based software for project management [project magement wiki].

As expected, the awesome wikipedia contains a page about the software used for project management, as well as a comparison of the  project management software.

Among the open source, web-based, here is the list of the ones that seem more insteresting, with some notes. I'm making this list in order to having them read to try.

Zend framework scaffolding CRUD libraries (for CMS and admin areas)

July 21st, 2010

I've recently made extensible Zend Framework libraries for admin scaffolding, that is the automatic creation of CRUD forms. Differently from Symfony admin generator, Code Igniter and CakePHP, on ZF there is nothing similar already made :(

My libraries create forms by automatic reading of table structure (fields and type), with extra customization support. The code is strong object oriented, so extensible and re-usable. There are helpers to make dropdown and ajax components for foreign key table fields (in order to make forms for 1-N and N-N table relationships).

Before putting them on a public SVN and writing the documentation, I prefer to test more and improve them. However, I'll send the code to whom may be already interested.

Details of the components

  • Controller (subclass of Zend_Controller_Action) with CRUD (create, read, update, delete) actions already made. When creating a CRUD form, it's enough to extend that abstract  CRUD controller, then implement to methods that return the dependent form and model.
  • Models
  • Views (not strongly necessary as if not existing the controller prints the default content, but suggested)
  • Forms: automatically generated by reading metadata, with validation created depending on the field type (e.g: required values for not null values, integer validation when the field is INT, maxlengtt checks etc...), datepicker in case of timestamps etc....
    Forms extensible and customizable.
  • Order and filter form (for listing action) working with URL string (so order and filters are kept during CRUD actions)
  • Various interfaces for each component to keep the code OO and understand better errors.
  • Various Helpers
  • Other stuff ...

When creating a new CRUD form, the components must be extended, then customised. I've used my libs to generate two different admin areas and it doesn't take long by copying and pasting the components already made, anywayin the future I'll probably think of a Zend_tool extension to generate them easier.

Preview:

CRUD forms

The power of the Regular expression on the web

July 19th, 2010

Regular Expression are Swiss-knife tools developers should know, extremely useful for  web-purposes and unavoidable when dealing with content scraping.
A single call of a preg_match_all with a medium complex regular expression could save hundres of LOC and time as well as obtaining much more maintainable code.

There  are advanced features like subpatterns and conditional expressions. They might be useful to extract some patterns, task  otherwise not easily feasible.

Pattern Syntax guide - php.net

Useful links about regular expressions

Zend tool not working after Netbeans 6.9 setup

July 12th, 2010

Netbeans 6.9 modifies the  zend framework tool and adds an additional class in order to use it directly from the IDE.

The problem is that Netbeans changes the common INI file of the tool (.zf.ini placed inside the user folder). Without specifying additional parameters, the tool does not work anymore from the external command line.

My quick solution was temporarily moving the INI file, however it's possible to specify additional parameters to use another config file.

Details:
the command

zf create project ...

returned the error

prompt>zf create project
Warning: include_once(NetBeansCommandsProvider.php): failed to open stream: 
No such file or directory in C:\wamp\www\ZendFramework-1.10.6\library\Zend\Loader.php on line 146
PHP Warning:  include_once(): Failed opening 'NetBeansCommandsProvider.php' for inclusion )
include_path='C:\wamp\www\ZendFramework.10.6\library;.;C:\wamp\bin\php\php5.3.0\PEAR\pear')
 in :\wamp\www\ZendFramework-1.10.6\library\Zend\Loader.php on line 146

Chrome and Internet Explorer ignore Windows hosts file

July 12th, 2010

I've recently had some issue with local websites (in addition to " localhost"->127.0.0.1). Chrome and Internet Explorer didn't use the hosts file to solve the other local addresses (e.g: "zendapp.localhost"->127.0.0.1) I've previously set.

I've had this problem on Windows Seven. After some googling its seems that the issue is not OS-dependent but it's a default setting, that developers do not like :)

Solution: open Internet Explorer, got to "Internet options" -> "Connection" -> "Local area network (LAN)" and untick "Automatic configuration"