Author Archives: zechim - Page 2

Running single test on phpunit

phpunit -c app/ --filter YourTestClass

Event Listener (after login) on Symfony 2

If you need to do some kind of action after the user has logged-in on your system, you should add an event listener.

First, you need to create a service.

On your app/config.yml you must define your service:

        class: YourApp\YourBundle\Listener\LoginListener
        arguments: [@doctrine]
          - { name: kernel.event_listener, event: security.interactive_login, method: onInteractiveLogin }

After that you need to code your listener

namespace YourApp\YourBundle\Listener;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class LoginListener
     * @var Doctrine\Bundle\DoctrineBundle\Registry
    private $doctrine;
    public function __construct(Doctrine $doctrine)
        $this->doctrine = $doctrine;
    public function onInteractiveLogin(InteractiveLoginEvent $event)
        $user = $event->getAuthenticationToken()->getUser();
        if ($user) {
            // your action with the current user

Dump update SQL From Doctrine 2 on Symfony 2

php app/console doctrine:schema:update --dump-sql



Today I decided to write about some Design Patters I’m currently studying for my future reference and I hope it’ll be helpful for you too.

Each post on this post series will be based on books, websites and my own code. I’ll show each external reference I’ll use.

To make it simple I’ll use ClassLoader from Symfony 2 Framework (in a composer dependency, installed easy as “composer install” command)

Source code will be available on

These are the patterns I’m intending to write about:

- Specification
- Strategy
- Decorator
- Chain of Responsibility
- Facade
- Abstract Factory
- Factory Method
- Template Method
- Adapter
- Bridge
- Composite
- Proxy
- Mediator
- Observer
- Visitor

Install less and Configure on Symfony 2 on Ubuntu 12.04

This also can fix the following errors when parsing a less file with node:
- Error: Cannot find module ‘less’
- TypeError: Cannot call method ‘charAt’ of undefined

First you need to install npm ( Package manager for node)

sudo apt-get install npm

Install less (latest version)

sudo npm install --global less

Now configure your app/config.yml

            node_paths: [/usr/local/lib/node_modules] (or /usr/lib/node_modules)

Create Single Entity on Doctrine 2 + Symfony 2

First if you don’t have an YML file but have table on your database, run this command to import YML file from this database:

php app/console doctrine:mapping:import YourAppBundle yml --filter="Table"

Based on an YML File this command will create a single entity for you:

php app/console doctrine:generate:entities YourAppBundle:Table --path src/

And if you want to create all entities

php app/console doctrine:mapping:import YourAppBundle yml
php app/console doctrine:generate:entities YourAppBundle

Install Oracle Client on Ubuntu (PHP)

Download Instant Client on:
- oracle-instantclient11.2-basic-
- oracle-instantclient11.2-devel-

Install alien to convert to rmp to deb package:

sudo apt-get install alien

Convert Packages:

sudo alien oracle-instantclient11.2-basic-
sudo alien oracle-instantclient11.2-devel-

Install client:

sudo dpkg -i oracle*.deb

Install Lib for PHP:

sudo pecl install oci8
sudo apt-get install libaio1


Add ”” to your php.ini

show full var_dump

Just update xdebug.ini file

xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1


Catch SoapClient Exception

If you can’t get SoapClient exception if WSDL cant be loaded (PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn’t load from xxx)

Try this (before instantiating SoapClient):


Found this solution up here:

Input is not proper UTF-8, indicate encoding (DOMDocument::loadXML)

Probably your XML string isn’t in UTF-8. Try this:

Page 2 of 1012345...10...Last »