Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->end();
->arrayNode('zf1')
->children()
->scalarNode('main_namespace')
->end()
->arrayNode('namespaces')
->prototype('scalar')->end()
->end()
->end()
->end();

return $treeBuilder;
}
Expand Down
7 changes: 7 additions & 0 deletions DependencyInjection/TheodoEvolutionSessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public function load(array $configs, ContainerBuilder $container)

public function addBagManager($container, $configs)
{
if($configs[0]['zf1'])
{
$container->getDefinition('theodo_evolution.session.bag_manager_configuration')
->addArgument($configs[0]['zf1']['main_namespace'])
->addArgument($configs[0]['zf1']['namespaces']);
}

$container->setParameter(
'theodo_evolution.session.bag_manager.class',
$configs[0]['bag_manager']['class']
Expand Down
23 changes: 21 additions & 2 deletions Manager/ZendFramework1/BagConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@
*/
class BagConfiguration implements BagManagerConfigurationInterface
{

private $namespaces = array(
BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE => 'mysession',
BagManagerConfigurationInterface::LAST_REQUEST_NAMESPACE => 'symfony/user/sfUser/lastRequest',
BagManagerConfigurationInterface::AUTH_NAMESPACE => 'symfony/user/sfUser/authenticated',
BagManagerConfigurationInterface::CREDENTIAL_NAMESPACE => 'symfony/user/sfUser/credentials',
BagManagerConfigurationInterface::CULTURE_NAMESPACE => 'symfony/user/sfUser/culture',
);

private $zf1Namespaces;

public function __construct($zf1MainNamespace, $zf1Namespaces) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add type hint: array $zf1Namespaces

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please add PHPDoc every where

$this->namespaces[BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE] = $zf1MainNamespace;
$this->zf1Namespaces = $zf1Namespaces;
}

/**
* {@inheritdoc}
*/
Expand All @@ -28,6 +35,18 @@ public function getNamespaces()
return $this->namespaces;
}

public function getZf1MainNamespace() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets should be on a new line

return $this->namespaces[BagManagerConfigurationInterface::ATTRIBUTE_NAMESPACE];
}

/**
* Returns the zend session's namespaces
* @return array
*/
public function getZf1Namespaces(){
return $this->zf1Namespaces;
}

/**
* {@inheritdoc}
*/
Expand All @@ -46,4 +65,4 @@ public function isArray($namespaceName)
return false;
}
}
}
}
9 changes: 3 additions & 6 deletions Manager/ZendFramework1/BagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public function initialize(SessionInterface $session)
parent::initialize($session);

$namespaces = $this->configuration->getNamespaces();

/* Symfony1 keeps the last request value here
* update it as if it was Symfony1 who accessed it
*/
$session->getBag($namespaces['last_request_namespace'])->set(time());
$zf1Namespaces = $this->configuration->getZf1Namespaces();
$zf1MainNamespace = $this->configuration->getZf1MainNamespace();
}
}
}
3 changes: 2 additions & 1 deletion Resources/config/services/session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
<parameter key="theodo_evolution.session.storage.mock_file.class">Theodo\Evolution\Bundle\SessionBundle\Storage\MockFileSessionStorage</parameter>
<parameter key="theodo_evolution.session.session_subscriber.class">Theodo\Evolution\Bundle\SessionBundle\Listener\SessionSubscriber</parameter>
<parameter key="theodo_evolution.session.symfony1x_bag_manager.class">Theodo\Evolution\Bundle\SessionBundle\Manager\Symfony1xBagManager</parameter>
<parameter key="theodo_evolution.session.zendframework1_bag_manager.class">Theodo\Evolution\Bundle\SessionBundle\Manager\ZendFramework1BagManager</parameter>
</parameters>

<services>
<service id="theodo_evolution.session.session_subscriber" class="%theodo_evolution.session.session_subscriber.class%">
<argument type="service" id="theodo_evolution.session.bag_manager" />
<tag name="kernel.event_subscriber" event="kernel.request"/>
</service>
<service id="theodo_evolution.session.bag_manager_configuration" class="%theodo_evolution.session.bag_manager_configuration.class%"/>
<service id="theodo_evolution.session.bag_manager_configuration" class="%theodo_evolution.session.bag_manager_configuration.class%" />
<service id="theodo_evolution.session.bag_manager" class="%theodo_evolution.session.bag_manager.class%">
<argument type="service" id="theodo_evolution.session.bag_manager_configuration" />
</service>
Expand Down
7 changes: 6 additions & 1 deletion Resources/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ Configuration
);
}

2. Choose the BagManager and the corresponding BagConfiguration you want to use:
2. Choose the BagManager and the corresponding BagConfiguration you want to use.

If you want to share session between ZendFramework 1.12 and Symfony2, set zf1.main_namespace to the namespace of your Zend_Session_Namespace object.
To access Zend session in Symfony inside a controller use $this->get('session')->get('{zf1_main_namespace}') where you have to replace {zf1_main_namespace} by the right value.

::

Expand All @@ -43,6 +46,8 @@ Configuration
bag_manager:
class: Theodo\Evolution\Bundle\SessionBundle\Manager\Symfony1\BagManager
configuration_class: Theodo\Evolution\Bundle\SessionBundle\Manager\Symfony1\BagConfiguration
zf1:
main_namespace: 'zf_main_namespace'


Choose one from those in Theodo\Evolution\Bundle\SessionBundle\Manager or use the
Expand Down