published on November 10, 2011 in technical
PHP YaF, as Yet another Framework, is object oriented PHP framework. But there are a few things about it, that make it a bit different. I have tried it a few days back and decided to write up a few articles about my quest with it.
Update: I have published a second part of the review, which you may read here.
1. My name is YaF
One of the most important characteristiques of YaF is that it is developed in C language and available as a PECL extension. It should be instaled like this:
sudo pecl install yaf
If your server runs on Debian Linux, then you might need to install a few more packages. The ones that I needed were make and libpcre3-dev and also php5-dev. I actually started the pecl install, but it kept telling me errors with missing packages. So I just installed what was missinng. In the end, I had a working YaF.
At least that was what I was hoping for.
2. Documentation, resources
I have used Kohana frameworks for a few years and got used to understanding the code an its possibilities by navigating, reading the code. Navigating YaF source is possible, but due to it being written in C language, this was a bit difficult.
You may say that there is an easier way, known by many as docs.php.net. True, but YaF is quite new, this way the documentation on the site is actually non existent.
I tried to figure out how I should use the available classes and methods from the list available, but I came to realize that there is a better way of getting to know YaF: contacting its developer. Laruence is very helpfull, so I should thank him from here, too.
3. Making a plan
When I first read about YaF on twitter, I had a very quick thought: I wanted to test it. So I made up a quick plan in my mind, which in the end reached a very simple form. I had to be able to compare it with something I already knew quite well. Thus, the plan ended up to creating my site's hompage in YaF and running some stress testing on both, on the same machine. This way I would get a good picture about YaF's capabilities.
4. Folder structure
YaF has a classical folder structure:
- index.php - .htaccess + conf |- application.ini //application config - application/ - Bootstrap.php + controllers - Index.php //default controller + views |+ index - index.phtml //view template for default action + modules - library - models - plugins
The index.php is the only entry point into the application. A very simple index.php example would be this:
define('APP_PATH', dirname(__FILE__) . ''); $app = new Yaf_Application(APP_PATH . '/conf/application.ini'); $app->bootstrap()->run();
As you may see here, we define the application path, then we run it with a configuration, which in my case looks like this:
[production] application.directory=APP_PATH "/application/" database.host="localhost" database.user="root" database.password="mypassword" database.database="mydatabase"
It starts with a production section. I loved this very simple way of keeping one configuration file for all settings, all environments. Surely, one may load different configuration files in the index.php for each of his environments.
I think I may say that Routing was my biggest struggle. But when finally Laruence helped me figure this out, It worked like a charm! Stay tuned for my next post, I will examine a feew routing examples, and write a bit about how routing should be used.