This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging develop to master in preparation for 2.7.0
- Loading branch information
Showing
6 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-validator for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Validator; | ||
|
||
class ConfigProvider | ||
{ | ||
/** | ||
* Return configuration for this component. | ||
* | ||
* @return array | ||
*/ | ||
public function __invoke() | ||
{ | ||
return [ | ||
'dependencies' => $this->getDependencyConfig(), | ||
]; | ||
} | ||
|
||
/** | ||
* Return dependency mappings for this component. | ||
* | ||
* @return array | ||
*/ | ||
public function getDependencyConfig() | ||
{ | ||
return [ | ||
'factories' => [ | ||
'ValidatorManager' => ValidatorPluginManagerFactory::class, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-validator for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Validator; | ||
|
||
class Module | ||
{ | ||
/** | ||
* Return default zend-validator configuration for zend-mvc applications. | ||
*/ | ||
public function getConfig() | ||
{ | ||
$provider = new ConfigProvider(); | ||
|
||
return [ | ||
'service_manager' => $provider->getDependencyConfig(), | ||
]; | ||
} | ||
|
||
/** | ||
* Register a specification for the ValidatorManager with the ServiceListener. | ||
* | ||
* @param \Zend\ModuleManager\ModuleEvent | ||
* @return void | ||
*/ | ||
public function init($event) | ||
{ | ||
$container = $event->getParam('ServiceManager'); | ||
$serviceListener = $container->get('ServiceListener'); | ||
|
||
$serviceListener->addServiceManager( | ||
'ValidatorManager', | ||
'validators', | ||
'Zend\ModuleManager\Feature\ValidatorProviderInterface', | ||
'getValidatorConfig' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-validator for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Validator; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Zend\ServiceManager\FactoryInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ValidatorPluginManagerFactory implements FactoryInterface | ||
{ | ||
/** | ||
* zend-servicemanager v2 support for invocation options. | ||
* | ||
* @param array | ||
*/ | ||
protected $creationOptions; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return ValidatorPluginManager | ||
*/ | ||
public function __invoke(ContainerInterface $container, $name, array $options = null) | ||
{ | ||
return new ValidatorPluginManager($container, $options ?: []); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return ValidatorPluginManager | ||
*/ | ||
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null) | ||
{ | ||
return $this($container, $requestedName ?: ValidatorPluginManager::class, $this->creationOptions); | ||
} | ||
|
||
/** | ||
* zend-servicemanager v2 support for invocation options. | ||
* | ||
* @param array $options | ||
* @return void | ||
*/ | ||
public function setCreationOptions(array $options) | ||
{ | ||
$this->creationOptions = $options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-validator for the canonical source repository | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Validator; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Zend\Validator\ValidatorInterface; | ||
use Zend\Validator\ValidatorPluginManager; | ||
use Zend\Validator\ValidatorPluginManagerFactory; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
|
||
class ValidatorPluginManagerFactoryTest extends TestCase | ||
{ | ||
public function testFactoryReturnsPluginManager() | ||
{ | ||
$container = $this->prophesize(ContainerInterface::class)->reveal(); | ||
$factory = new ValidatorPluginManagerFactory(); | ||
|
||
$validators = $factory($container, ValidatorPluginManagerFactory::class); | ||
$this->assertInstanceOf(ValidatorPluginManager::class, $validators); | ||
|
||
if (method_exists($validators, 'configure')) { | ||
// zend-servicemanager v3 | ||
$this->assertAttributeSame($container, 'creationContext', $validators); | ||
} else { | ||
// zend-servicemanager v2 | ||
$this->assertSame($container, $validators->getServiceLocator()); | ||
} | ||
} | ||
|
||
/** | ||
* @depends testFactoryReturnsPluginManager | ||
*/ | ||
public function testFactoryConfiguresPluginManagerUnderContainerInterop() | ||
{ | ||
$container = $this->prophesize(ContainerInterface::class)->reveal(); | ||
$validator = $this->prophesize(ValidatorInterface::class)->reveal(); | ||
|
||
$factory = new ValidatorPluginManagerFactory(); | ||
$validators = $factory($container, ValidatorPluginManagerFactory::class, [ | ||
'services' => [ | ||
'test' => $validator, | ||
], | ||
]); | ||
$this->assertSame($validator, $validators->get('test')); | ||
} | ||
|
||
/** | ||
* @depends testFactoryReturnsPluginManager | ||
*/ | ||
public function testFactoryConfiguresPluginManagerUnderServiceManagerV2() | ||
{ | ||
$container = $this->prophesize(ServiceLocatorInterface::class); | ||
$container->willImplement(ContainerInterface::class); | ||
|
||
$validator = $this->prophesize(ValidatorInterface::class)->reveal(); | ||
|
||
$factory = new ValidatorPluginManagerFactory(); | ||
$factory->setCreationOptions([ | ||
'services' => [ | ||
'test' => $validator, | ||
], | ||
]); | ||
|
||
$validators = $factory->createService($container->reveal()); | ||
$this->assertSame($validator, $validators->get('test')); | ||
} | ||
} |