Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#4995 from Blinden/sess…
Browse files Browse the repository at this point in the history
…ion-manager-factory-validators

[SessionManagerFactory] Configuration of validators in SessionManagerFactory
  • Loading branch information
weierophinney committed Oct 22, 2013
180 parents 4048ff7 + 46af048 + f8de14f + 5bd58ff + 3efc3e6 + fbe1bf7 + 599bb28 + a1894dc + 5d1b205 + 09ba436 + f8fc5b0 + 17494e9 + 91105ad + e3a1818 + a31ffcc + 370a890 + 79102c3 + 0d79e94 + c3f023e + 7ee4fbe + 7c5f46f + 93e1c5e + 300993b + 3fa60b1 + 56e7a3b + f66fb69 + 65e3dc5 + 893db4e + 1f95227 + 37eba61 + a8a134d + 2a58e81 + c687156 + ff43991 + bad6a8b + aba47b0 + 955d97a + 2b78fdc + 0094c19 + 4985e6d + d904244 + 52367d8 + dce778a + 2305c94 + 052b9a4 + ef11064 + 4efb47c + b3dcf28 + 778fbea + cdde9b4 + 6ade9b9 + 435888b + 2ad89a8 + e232251 + 5932189 + d0360d2 + 52242e5 + 3804b57 + 1cecc58 + 4a4065c + f9b61b5 + 0a07b63 + 0e321e0 + 95ceb90 + 4380d08 + ec9c36c + 4de92b2 + b6eb950 + fca746d + ff69119 + 5351804 + 3617ea6 + 24c8a1f + 0aa6c03 + b24267c + beadb3c + 51c4ced + d92ccc9 + eb1f131 + f383de1 + abc631a + 666ec86 + e22a167 + bb8b8f6 + b55f760 + f23a913 + 9ba9f17 + d01f94f + 9c4e0cc + 63c4a7e + 9eedf95 + 980bffb + 03cf7b3 + 8bbf35d + aff3454 + 1c6567c + a102513 + 90b7795 + 286539e + 7f08291 + 417d368 + ae0f13d + 7894420 + 8ff1b30 + 55ca16f + 0c6cb6c + 7010e32 + 745a36a + f021693 + cd91ba2 + 5586879 + 1cd9259 + b611b41 + e07e054 + 7657d67 + 52b6014 + 00211c2 + 0d594de + f919c63 + 7e217f4 + 3e0da00 + 3723e41 + facd3ee + 4d8294f + 3cdb12a + f09df31 + 34e6a86 + 4e1b451 + 2d3566a + ef9466a + 3c172af + 2260c5e + dd964bc + f325c01 + 3cd4478 + dc3a58e + cf0af6f + 6e93d7b + 6b3eedb + ce63e39 + 1bd656e + cc16778 + 720b563 + 039e86a + b27a1fe + 88022d1 + b4847de + 1b48124 + 6a22f1e + b63de1e + 770056f + 9e9a6cb + f6a6b75 + 9533639 + 82f2194 + 1c82c93 + b2d0ea0 + 65cd119 + b2e527d + 513214f + 3a8340e + 251bd01 + 6cd974a + 8a9cfe7 + c0ef35c + a4120f3 + 83998db + ce6e83d + 79d9ad3 + 06667fc + e9a0a25 + 8a45042 + 476e819 + ec53915 + dabe526 + 473d00f + ef75c1e + cc7aba9 + 8c31f0a + 822e502 commit 54cc265
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Service/SessionManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SessionManagerFactory implements FactoryInterface
* - enable_default_container_manager: whether to inject the created instance
* as the default manager for Container instances. The default value for
* this is true; set it to false to disable.
* - validators: ...
*
* @param ServiceLocatorInterface $services
* @return SessionManager
Expand Down Expand Up @@ -112,6 +113,15 @@ public function createService(ServiceLocatorInterface $services)
) {
$managerConfig = array_merge($managerConfig, $configService['session_manager']);
}
// Attach validators to session manager, if any
if (isset($managerConfig['validators'])) {
$chain = $manager->getValidatorChain();
foreach ($managerConfig['validators'] as $validator) {
$validator = new $validator();
$chain->attach('session.validate', array($validator, 'isValid'));

}
}
}

// If configuration enables the session manager as the default manager for container
Expand Down
13 changes: 13 additions & 0 deletions test/Service/SessionManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,17 @@ public function testCanDisableContainerDefaultManagerInjectionViaConfiguration()
$manager = $this->services->get('Zend\Session\ManagerInterface');
$this->assertNotSame($manager, Container::getDefaultManager());
}

public function testFactoryWillAddValidatorViaConfiguration()
{
$config = array('session_manager' => array(
'validators' => array(
'Zend\Session\Validator\RemoteAddr',
),
));
$this->services->setService('Config', $config);
$manager = $this->services->get('Zend\Session\ManagerInterface');

$this->assertEquals(1, $manager->getValidatorChain()->getListeners('session.validate')->count());
}
}

0 comments on commit 54cc265

Please sign in to comment.