From DocBook to PDF using Apache FOP

Creating user manuals for the software you are building is an important task. Sometimes it is a project requirement but more often than that it is just more efficient having a document to which you can refer users to and stop waisting you precious time explaining the fundamentals of content management systems to novice users instead of actually doing what you are payed for.

Since I do not like to repeat myself I wanted a system that is capable of generating documentation in variety of formats, PDF being the most important one.

DocBook is the first thing that came to mind, but as it is usually the case the things are not so simple as they should be. After playing fore the most part of the day with DocBook and various utilities I decided to write it down for future reference. Continue reading From DocBook to PDF using Apache FOP…

Adding filters automatically to your Zend_Form_Element_Text objects

Although you can create a custom form element as described in ZF manual and set the properties for all instances of this element I really did not like this solution since my application already has a lot of already working forms.

I wanted to add the Zend_Filter_StringTrim filter to all of my text form elements so I decided to just add them on the fly.

Since my forms already extend a custom “MyApp_Form” object (MyApp_Form extend Zend_Form) it was just a matter of intercepting the addElement() method.

So, here it goes, in all its glory:

public function addElement($element, $name = null, $options = null)
{
    parent::addElement($element, $name, $options);
 
    if (is_null($name)) {
        $name = $element->getName();
    }
 
    $addedElement = $this->getElement($name);
 
    if ($addedElement instanceof Zend_Form_Element_Text) {
        if ( ! $addedElement->getFilter('StringTrim') instanceof Zend_Filter_Interface ) {
            $addedElement->addFilter(new Zend_Filter_StringTrim());
        }
    }
}

Since the element is already added to the form using the parent method I didn’t have to check if the element is passed as a string, but does not have a name, or if it’s passed as a Zend_Form_Element object without the name property since the Zend_Form::addElement() already checks for this.

Zend Framework 1.8

Yesterday Zend Framework 1.8 was released and since I was ill and didn’t have much else to do I decided to have a look and make necessary changes to port our company CMS to the new version.

The new autoloader Zend_Loader_Autoloader is just what I was looking for to easily group the forms and models with my application modules. I definitively recommend to read a great article about the new autoloader at Zend Developer Zone.

The whole process of migrating from ZF 1.7.7 was quite painless I just had to replace:

Zend_Loader::registerAutoload

with

$loader Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyApp_');

Zend_Log_Writer_Mail is finally in the stable distribution and It took only couple of lines of code to add this to our application logger so now when stuff go terribly wrong I at least know I will be getting an email about it.

You can view the full list of changes in the 1.8 release here.

I look forward to playing with Zend_Navigation and see if we how could we use it to cleanup some of the mumbo-jumbo we are currently doing with ACLs and navigational elements.

Zend_Validate_Db_RecordExists doesn’t look like much, but it makes me happy to remove some custom code because it is now supported in the framework.

Removing require_once() calls from Zend Framework

If you are using Zend_Loader to load your classes in Zend Framework, there is no need for all the require_once() calls that are littered all over ZF files.

Some acctually report big improvements in responsiveness of their applications and increase in number of transactions per second their hardware can handle because require_once() is quite an expensive operation, especially if the required file is already included prior to the call. Continue reading Removing require_once() calls from Zend Framework…

Dual display setup with Nvidia on Ubuntu 8.04

Setting up multiple monitors under Linux can sometimes be quite a daunting task. TwinView, Xinerama, restricted drivers, editing configuration files, etc. doesn’t sound user friendly at all.

After you install Ubuntu and boot it the first time, you will get a notification in the tray asking you if you would like to install nVidia restricted drivers. They don’t get installed by default because the source code for this drivers isn’t open source. Since we don’t care about that, and just want the damn thing to work install the drivers. Continue reading Dual display setup with Nvidia on Ubuntu 8.04…

Optimizing frontend performance with some Javascript magic

So, you know Yahoo!’s Best Practices for Speeding Up Your Web Site by hart and you have already implemented most of the tips on your web site but you are still not satisfied with the performance bottlenecks caused by your banner serving services (OpenX, formerly known as OpenAds and PhpAdsNew in my case) and other stuff you need to use but have no control over it.

Fear no more!

Continue reading Optimizing frontend performance with some Javascript magic…

“Benchmarking” PHP frameworks

Although I am not a Drupal user, the chance to visit Drupalcon in Szeged (Hungary) appeared and I couldn’t pass on that one. We got there a little bit late, but just in time to hear Rasmus Lerdorfs keynote speech Simple is Hard. There are some really good ideas for optimizing your applications performance and I strongly recommend it for every PHP developer.

There were also some things I really don’t agree that much. He showed a small PHP frameworks “benchmark” measuring the speed (response time and transactions per second) for each of this frameworks to output the simple HTML page printing out the “Hello world” string. Zend Framework (the framework of my choice) didn’t perform all that bad. Symfony was around 30% slower, and Solar was about 2 times faster. If you are really interested in the numbers have a look at the slides from the session.

Continue reading “Benchmarking” PHP frameworks…

Hello World!

Every nice blog should start with a “Hello World!”. Right? :)

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.