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

Commit 968f855

Browse files
committed
Merging develop to master in preparation for 2.7.0
2 parents 0288147 + f051dd0 commit 968f855

File tree

6 files changed

+237
-0
lines changed

6 files changed

+237
-0
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 2.7.0 - TBD
6+
7+
### Added
8+
9+
- [#63](https://github.com/zendframework/zend-validator/pull/63) exposes the
10+
package as a ZF component and/or generic configuration provider, by adding the
11+
following:
12+
- `ValidatorPluginManagerFactory`, which can be consumed by container-interop /
13+
zend-servicemanager to create and return a `ValidatorPluginManager` instance.
14+
- `ConfigProvider`, which maps the service `ValidatorManager` to the above
15+
factory.
16+
- `Module`, which does the same as `ConfigProvider`, but specifically for
17+
zend-mvc applications. It also provices a specification to
18+
`Zend\ModuleManager\Listener\ServiceListener` to allow modules to provide
19+
validator configuration.
20+
21+
### Deprecated
22+
23+
- Nothing.
24+
25+
### Removed
26+
27+
- Nothing.
28+
29+
### Fixed
30+
31+
- Nothing.
32+
533
## 2.6.1 - TBD
634

735
### Added

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"branch-alias": {
4848
"dev-master": "2.6-dev",
4949
"dev-develop": "2.7-dev"
50+
},
51+
"zf": {
52+
"component": "Zend\\Validator",
53+
"config-provider": "Zend\\Validator\\ConfigProvider"
5054
}
5155
},
5256
"autoload-dev": {

src/ConfigProvider.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-validator for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Validator;
9+
10+
class ConfigProvider
11+
{
12+
/**
13+
* Return configuration for this component.
14+
*
15+
* @return array
16+
*/
17+
public function __invoke()
18+
{
19+
return [
20+
'dependencies' => $this->getDependencyConfig(),
21+
];
22+
}
23+
24+
/**
25+
* Return dependency mappings for this component.
26+
*
27+
* @return array
28+
*/
29+
public function getDependencyConfig()
30+
{
31+
return [
32+
'factories' => [
33+
'ValidatorManager' => ValidatorPluginManagerFactory::class,
34+
],
35+
];
36+
}
37+
}

src/Module.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-validator for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Validator;
9+
10+
class Module
11+
{
12+
/**
13+
* Return default zend-validator configuration for zend-mvc applications.
14+
*/
15+
public function getConfig()
16+
{
17+
$provider = new ConfigProvider();
18+
19+
return [
20+
'service_manager' => $provider->getDependencyConfig(),
21+
];
22+
}
23+
24+
/**
25+
* Register a specification for the ValidatorManager with the ServiceListener.
26+
*
27+
* @param \Zend\ModuleManager\ModuleEvent
28+
* @return void
29+
*/
30+
public function init($event)
31+
{
32+
$container = $event->getParam('ServiceManager');
33+
$serviceListener = $container->get('ServiceListener');
34+
35+
$serviceListener->addServiceManager(
36+
'ValidatorManager',
37+
'validators',
38+
'Zend\ModuleManager\Feature\ValidatorProviderInterface',
39+
'getValidatorConfig'
40+
);
41+
}
42+
}

src/ValidatorPluginManagerFactory.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-validator for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace Zend\Validator;
9+
10+
use Interop\Container\ContainerInterface;
11+
use Zend\ServiceManager\FactoryInterface;
12+
use Zend\ServiceManager\ServiceLocatorInterface;
13+
14+
class ValidatorPluginManagerFactory implements FactoryInterface
15+
{
16+
/**
17+
* zend-servicemanager v2 support for invocation options.
18+
*
19+
* @param array
20+
*/
21+
protected $creationOptions;
22+
23+
/**
24+
* {@inheritDoc}
25+
*
26+
* @return ValidatorPluginManager
27+
*/
28+
public function __invoke(ContainerInterface $container, $name, array $options = null)
29+
{
30+
return new ValidatorPluginManager($container, $options ?: []);
31+
}
32+
33+
/**
34+
* {@inheritDoc}
35+
*
36+
* @return ValidatorPluginManager
37+
*/
38+
public function createService(ServiceLocatorInterface $container, $name = null, $requestedName = null)
39+
{
40+
return $this($container, $requestedName ?: ValidatorPluginManager::class, $this->creationOptions);
41+
}
42+
43+
/**
44+
* zend-servicemanager v2 support for invocation options.
45+
*
46+
* @param array $options
47+
* @return void
48+
*/
49+
public function setCreationOptions(array $options)
50+
{
51+
$this->creationOptions = $options;
52+
}
53+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* @link http://github.com/zendframework/zend-validator for the canonical source repository
4+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license http://framework.zend.com/license/new-bsd New BSD License
6+
*/
7+
8+
namespace ZendTest\Validator;
9+
10+
use Interop\Container\ContainerInterface;
11+
use PHPUnit_Framework_TestCase as TestCase;
12+
use Zend\Validator\ValidatorInterface;
13+
use Zend\Validator\ValidatorPluginManager;
14+
use Zend\Validator\ValidatorPluginManagerFactory;
15+
use Zend\ServiceManager\ServiceLocatorInterface;
16+
17+
class ValidatorPluginManagerFactoryTest extends TestCase
18+
{
19+
public function testFactoryReturnsPluginManager()
20+
{
21+
$container = $this->prophesize(ContainerInterface::class)->reveal();
22+
$factory = new ValidatorPluginManagerFactory();
23+
24+
$validators = $factory($container, ValidatorPluginManagerFactory::class);
25+
$this->assertInstanceOf(ValidatorPluginManager::class, $validators);
26+
27+
if (method_exists($validators, 'configure')) {
28+
// zend-servicemanager v3
29+
$this->assertAttributeSame($container, 'creationContext', $validators);
30+
} else {
31+
// zend-servicemanager v2
32+
$this->assertSame($container, $validators->getServiceLocator());
33+
}
34+
}
35+
36+
/**
37+
* @depends testFactoryReturnsPluginManager
38+
*/
39+
public function testFactoryConfiguresPluginManagerUnderContainerInterop()
40+
{
41+
$container = $this->prophesize(ContainerInterface::class)->reveal();
42+
$validator = $this->prophesize(ValidatorInterface::class)->reveal();
43+
44+
$factory = new ValidatorPluginManagerFactory();
45+
$validators = $factory($container, ValidatorPluginManagerFactory::class, [
46+
'services' => [
47+
'test' => $validator,
48+
],
49+
]);
50+
$this->assertSame($validator, $validators->get('test'));
51+
}
52+
53+
/**
54+
* @depends testFactoryReturnsPluginManager
55+
*/
56+
public function testFactoryConfiguresPluginManagerUnderServiceManagerV2()
57+
{
58+
$container = $this->prophesize(ServiceLocatorInterface::class);
59+
$container->willImplement(ContainerInterface::class);
60+
61+
$validator = $this->prophesize(ValidatorInterface::class)->reveal();
62+
63+
$factory = new ValidatorPluginManagerFactory();
64+
$factory->setCreationOptions([
65+
'services' => [
66+
'test' => $validator,
67+
],
68+
]);
69+
70+
$validators = $factory->createService($container->reveal());
71+
$this->assertSame($validator, $validators->get('test'));
72+
}
73+
}

0 commit comments

Comments
 (0)