1313
1414use Cache \CacheBundle \Session \SessionHandler ;
1515use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
16+ use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
17+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
1618use Symfony \Component \DependencyInjection \Definition ;
1719use Symfony \Component \DependencyInjection \Reference ;
1820
2123 *
2224 * @author Aaron Scherer <aequasi@gmail.com>
2325 */
24- class SessionSupportCompilerPass extends BaseCompilerPass
26+ class SessionSupportCompilerPass implements CompilerPassInterface
2527{
2628 /**
27- *
29+ * @type ContainerBuilder
30+ */
31+ protected $ container ;
32+
33+ /**
34+ * @param ContainerBuilder $container
35+ * @throws \Exception
2836 */
29- protected function prepare ( )
37+ public function process ( ContainerBuilder $ container )
3038 {
3139 // Check if session support is enabled
32- if (!$ this -> container ->hasParameter ($ this -> getAlias (). ' .session ' )) {
40+ if (!$ container ->hasParameter (' cache .session ' )) {
3341 return ;
3442 }
3543
3644 // If there is no active session support, throw
37- if (!$ this -> container ->hasAlias ('session.storage ' )) {
45+ if (!$ container ->hasAlias ('session.storage ' )) {
3846 throw new \Exception ('Session cache support cannot be enabled if there is no session.storage service ' );
3947 }
4048
41- $ this ->enableSessionSupport ($ this -> container ->getParameter ($ this -> getAlias (). ' .session ' ));
49+ $ this ->enableSessionSupport ($ container, $ container ->getParameter (' cache .session ' ));
4250 }
4351
4452 /**
@@ -48,10 +56,10 @@ protected function prepare()
4856 *
4957 * @throws InvalidConfigurationException
5058 */
51- private function enableSessionSupport (array $ config )
59+ private function enableSessionSupport (ContainerBuilder $ container , array $ config )
5260 {
5361 // calculate options
54- $ sessionOptions = $ this -> container ->getParameter ('session.storage.options ' );
62+ $ sessionOptions = $ container ->getParameter ('session.storage.options ' );
5563 if (isset ($ sessionOptions ['cookie_lifetime ' ]) && !isset ($ config ['cookie_lifetime ' ])) {
5664 $ config ['cookie_lifetime ' ] = $ sessionOptions ['cookie_lifetime ' ];
5765 }
@@ -60,8 +68,8 @@ private function enableSessionSupport(array $config)
6068 $ definition ->addArgument (new Reference ($ config ['service_id ' ]))
6169 ->addArgument ($ config );
6270
63- $ this -> container ->setDefinition ('cache.session_handler ' , $ definition );
71+ $ container ->setDefinition ('cache.session_handler ' , $ definition );
6472
65- $ this -> container ->setAlias ('session.handler ' , 'cache.session_handler ' );
73+ $ container ->setAlias ('session.handler ' , 'cache.session_handler ' );
6674 }
6775}
0 commit comments