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

Commit 2e58d8d

Browse files
committed
Expose as a generic config provider and ZF component
Adds: - `ConfigProvider`, which maps the service `ValidatorManager` to the new `ValidatorPluginManagerFactory`. - `Module`, which maps the service `ValidatorManager` to the new `ValidatorPluginManagerFactory`, and adds zend-modulemanager `ServiceListener` specifications for providing validator configuration.
1 parent d7f31e1 commit 2e58d8d

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

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+
}

0 commit comments

Comments
 (0)