mpoiriert/binder-bundle

Reusable library

Installs: 659

Dependents: 0

Suggesters: 1

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 1

Type:symfony-bundle

dev-master 2014-03-26 11:57 UTC

This package is auto-updated.

Last update: 2024-04-09 12:57:25 UTC


README

Build Status

A Symfony bundle to use the binder library.

The main purpose is to hide the usage of the session to the user (developer).

To use it in your application you must register 2 bundles since there is a dependency on nucleus-bundle.

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Nucleus\Bundle\CoreBundle\NucleusCoreBundle(),
    new Nucleus\Bundle\BinderBundle\NucleusBinderBundle(),
    // ...
);

The system does use the kernel.terminate event to work. Don't forget to use the Symfony/Component/HttpKernel/TerminableInterface on your kernel.

In any service you can put a annotation above a property and this property will be automatically save to the session and restore on the next call.

<?php

class TheService
{
    /**
     * @\Nucleus\Binder\Bounding
     */
    protected $variable = 'default';

    public function getVariable()
    {
        return $this->variable;
    }

    public function setVariable($value)
    {
        $this->variable = $value;
    }

    //...
}

That's all !!

The default value of the property will be use if the proper variable in not available in the Binder service.

By calling the TheService::setVariable() the value will be change and at the end of the request on kernel.terminate.

If you need to access the value of this variable in "AnotherService" you need to inject "TheService" in "AnotherService" and call the TheService::getVariable(). The service who have the Bounded property is in charge of all the access to it.

This approach also help for unit test since you don't need to use the session anymore. It also force to have a separation of concern in your service since no other service can change the value in the session by manipulating it directly since it's inner working are hidden.