dev-master
9999999-devReusable library
MIT
The Requires
The Development Requires
by Martin Poirier ThĂ©orĂȘt
library cookie session binding nucleus
Reusable library
A Symfony bundle to use the binder library., (*2)
The main purpose is to hide the usage of the session to the user (developer)., (*3)
To use it in your application you must register 2 bundles since there is a dependency on nucleus-bundle., (*4)
<?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., (*5)
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., (*6)
<?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 !!, (*7)
The default value of the property will be use if the proper variable in not available in the Binder service., (*8)
By calling the TheService::setVariable() the value will be change and at the end of the request on kernel.terminate., (*9)
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., (*10)
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., (*11)
Reusable library
MIT
library cookie session binding nucleus