Eclipse tool belt for PHP

You are developing with PHP 5 and you’ve got the free Zend Server Community Edition on OS X installed? Now you want more, you want a great IDE for free too? Sure the newly released Zend Studio 7 looks nice, but it’s not cheap. Luckily it’s based on Eclipse PDT 2.1, and this one is free. Of course there’s some things missing when you get stuff for free, like PHPUnit Integration and Zend Framework integration.

The good thing about Eclipse is that it can be customized easily to work with external tools. Making it really easy to add features to your editor. Let’s see an example:

PHP_CodeSniffer

PHP CodeSniffer is a tool that analyze your code and give you error and warning about what to change in it to make it standard compliant. It is a great learning to as it force you to understand, and it doesn’t make any change to your source code.

If you have installed Zend Server CE, PEAR will be already installed and ready to go. It should be the latest version, but you may want to make sure by running

/usr/local/zend/bin/pear channel-update pear.php.net
/usr/local/zend/bin/pear upgrade pear    

Now you can install PHP_CodeSniffer:

    sudo /usr/local/zend/bin/pear install --alldeps PHP_CodeSniffer

The external tool can be added from this menu entry:

menu > Run > External Tools > Open External Tools Dialog...

Select ‘Program’ and press the ‘New’ button to create a configuration.

name: PHP_CodeSniffer
main > Location: /usr/local/zend/bin/phpcs
main > Arguments: --standard=PEAR "${resource_loc}"
Common > check the 'Allocate Console'

The last step is to add this tool to your ‘External Tools Favorites’ by selecting

menu > Run > External Tools > Organize Favorites...

Click add and then choose you PHP_CodeSniffer tool. Now it should be available in the Run > External Tools menu, and in the corresponding icon in the toolbar (green circle with a white triangle in it, and a suitcase).

Setting up an external tools could be more user friendly, but keep in mind that your gonna do this configuration only once, as you will be able to launch it with a single click once configured.

Sky is the limit

This was just a simple example with PHP_CodeSniffer, but it can easily be applied to your zf.php script if you’re into the Zend Framework, or the phpunit or doctrine command, or anything you can think of.

2 comments so far, add yours

Zend Framework Poster

Thanks to Björn Schotte at http://mayflower.biz, I have received my Planetary-sized Zend Framework poster. Yes, they shipped it as far as Ontario in Canada, thanks guys. It’s the perfect cheat sheet for ZF, and it’s great to cover a large and boring grey wall.

Just to give you and idea of the size of the poster, here’s a picture of my trying to hide it :)

Zend Framework Poster

By the way, if you don’t know what I’m talking about or if you want yours, just check out their blog post at thinkphp

One comment so far, add another

PHP Developers in Ottawa

I’ve got some extra time last week, so I’ve started a website aggregating blogs and Twitter accounts of PHP Developers in Ottawa, check out the new Ottawa PHP Community website or browse the source on GitHub. For the curious, it’s build with the Zend Framework.

I don’t know everybody in Ottawa that use PHP, so If you know some sources that should be added, drop me a line. BTW, the code is still a work in progress, work is still being done on the rss feed, caching, feed reader, etc…

2009-07-21 update: the RSS feed have been updated to provide a daily digest of the Twitter posting, This change may confuse some feed reader, sorry about that.

2 comments so far, add yours

Zend PHP 5 Certification

After seven years of PHP development, I was wondering what my skill level was. I was doubtful of the Zend PHP5 Certification test, but as it’s the only PHP certification that I was aware of, I’ve taken the test in downtown Ottawa. I’m not allowed to talk about any specifics of the exam, as I have accepted a big disclaimer right between the moment I’ve paid and the first question :) So here’s my ‘generic’ comments:

The test is great to prove that you know PHP fairly well, and that you’re able to read and understand PHP code. One don’t need to work for seven years with PHP to succeed at this exam —nonetheless, one can’t pass this exam with a “I have installed a lot of blog engines in PHP” kind of experience. Obviously, there’s questions about the syntax of the language itself, but there is also questions about PHP Configuration, Security, Regular Expression, Design Patterns, Object Oriented Programming and XML. I was really glad to see questions about all of these subjects, as I have meet countless PHP developer who have never heard of an abstract class or interface, let alone design pattern.

If you don’t care about the certificate, (ie: you don’t need to prove to yourself or to any HR people that you know your stuff) then I still suggest that you try the online practice test. What’s really great about this test is that it breakdown your result by subjects. By doing it I’ve learned that I didn’t really knew as much as I thought about the differences between PHP 4 and 5, and that I haven’t done enough stream programming. The Zend PHP 5 Certification Online Practice Testing is available for a very low price, and it will help you grow as a PHP developer as it will point out some possible area of improvements.

btw, I have succeeded, here’s my shiny new logo and Zend Yellow Pages record:

ZCE PHP5 Logo

One comment so far, add another

ZFDebug and Doctrine ORM

This is a follow-up to my post: Doctrine ORM and the Zend Framework

ZFDebug is a debug bar for Zend Framework, largely inspired by the Symfony Debug Bar. I have created a ZFDebug plugin that displays informations form the Doctrine profiler in the debug bar. You can see the sample code on my GitHub repository for zfdebugdoctrine.

If you already know how to use ZF, Doctrine and ZFDebug, you can jump right to the zfdebug doctrine plugin file.

update 2009/10/29: This was build with ZFDebug 1.5, Zend Framework 1.8 and Doctrine 1.1, you can check out Doctrine 1.2 is Zend Framework friendly too.

5 comments so far, add yours

Doctrine ORM and Zend Framework

This is my notes on integrating the Doctrine ORM with a Zend Framework project that use Zend_Application. This post was largely inspired by the post Integrating Zend Framework and Doctrine. In fact, you can see mine as an updated version of this great post to work in ZF 1.8. Ruben Vermeersch, the author, have stated on his blog that he want to update the post but he don’t have the time yet, so this is me trying to help.

This was done on OS X, so the instructions here assume a n*x like environment. You should also be comfortable with Zend Framework 1.8+ and the new Zend_Application. As stated in the ZF quickstart tutorial, you can create a project by running this command from the uncompressed Zend Framework folder:

./bin/zf.sh create project ~/Sites/zfdoctrine

In the newly created directory, which is a complete zf application, create the directories that will be needed by doctrine

cd ~/Sites/zfdoctrine
mkdir doctrine doctrine/migrations doctrine/schema
mkdir doctrine/data doctrine/data/fixtures doctrine/data/sql

Now, put the content of the Doctrine (1.0 or 1.1) lib folder in library. I strongly suggest that you put the ZF library here too. If you manage more that one project, it’s very unlikely that you will have time to update all your projects at the same time, which is needed if you use a global include path.

Create the Doctrine configuration in application/configs/application.ini

;doctrine.connection_string = "mysql://root:pwd@localhost/zfdoctrine"
doctrine.connection_string = "sqlite:///" APPLICATION_PATH "/zfdoctrine.db"
doctrine.data_fixtures_path = APPLICATION_PATH "/../doctrine/data/fixtures"
doctrine.models_path = APPLICATION_PATH "/models"
doctrine.migrations_path = APPLICATION_PATH "/../doctrine/migrations"
doctrine.sql_path = APPLICATION_PATH "/../doctrine/data/sql"
doctrine.yaml_schema_path = APPLICATION_PATH "/../doctrine/schema"

Initialize Doctrine in you application by adding this function to application/Bootstrap.php

public function _initDoctrine()
{
    require_once 'Doctrine.php';        
    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->pushAutoloader(array('Doctrine', 'autoload'));
 
    $doctrineConfig = $this->getOption('doctrine');
 
    $manager = Doctrine_Manager::getInstance();
    $manager->setAttribute(
        Doctrine::ATTR_MODEL_LOADING, 
        Doctrine::MODEL_LOADING_CONSERVATIVE);    
 
    // Add models and generated base classes to Doctrine autoloader
    Doctrine::loadModels($doctrineConfig['models_path']);
 
    $manager->openConnection($doctrineConfig['connection_string']);    
 
    return $manager;
}

One of the fun thing about Doctrine is that you have access to a lot of command line tool to create your database, models, sql, schema, etc. Create a new file called doctrine-cli in a scripts folder at the root of you project with the following content:

#!/usr/bin/env php
<?php
/**
 * Doctrine CLI script
 */
 
define('APPLICATION_ENV', 'development');
 
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
 
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));
 
require_once 'Zend/Application.php';
 
// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
 
$application->getBootstrap()->bootstrap('doctrine');
 
$cli = new Doctrine_Cli($application->getOption('doctrine'));
$cli->run($_SERVER['argv']);

You can make this script executable and try it, to see the list of task that doctrine-cli can do for you

chmod +x ./scripts/doctrine-cli
./scripts/doctrine-cli

Now you can jump back to [Ruben Vermeersch's Tutorial]http://ruben.savanne.be/articles/integrating-zend-framework-and-doctrine) tutorial in the “Building an application” section and create the sample application. You’ll learn how to use Doctrine do a simple insert, a query and how to use the command line to create your database and model.

note: If you’re using these two projects together, you may be interested in my next post too: ZFDebug and Doctrine ORM

update 2009/10/29: things are getting easier, check out: Doctrine 1.2 is Zend Framework friendly

19 comments so far, add yours

Reading Skills Testing

Want to test your reading skills? try out the ZCE PHP5 Mock Exam from PHP|Arch. Don’t be turned off by the name of the test, you don’t need to know anything about PHP to have this answer right :)

choose5

disclaimer : for those easily offended, I’m not bashing Zend or PHP|Arch. There was 69 other questions that were actually about PHP5, and some of them were pretty hard to answer.

Comments Off

Update for Markdown and GeSHi

Since I have started using the Zend Framework, I have noticed a limitation in the Markdown parser. As there is classes with names such as Zend_Form_Decorator_Fieldset, and Markdown replace everything between underscore with emphasis, they get rendered like this: ZendFormDecorator_Fieldset. So I have switched to PHP Markdown Extra which fix this, and I have applied the same modifications as before to have syntax coloring.

My new patch for PHP Markdown Extra and GeSHi is availlable on GitHub.

Don’t forget to adjust the require_once line to your GeSHi folder location, and start your code block with the language name between square brackets. ie [PHP]

Also added, is the ability to use the parser from the commande line. If used from the command line with a valid file as an argument, it will ouptput the result to stdout, one sample usage could be:

markdown-geshi-extra.php README.markdown > README.html
Comments Off