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

Commit

Permalink
Merging develop to master in preparation for 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Apr 6, 2016
2 parents 0288147 + f051dd0 commit 968f855
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 0 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

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

## 2.7.0 - TBD

### Added

- [#63](https://github.com/zendframework/zend-validator/pull/63) exposes the
package as a ZF component and/or generic configuration provider, by adding the
following:
- `ValidatorPluginManagerFactory`, which can be consumed by container-interop /
zend-servicemanager to create and return a `ValidatorPluginManager` instance.
- `ConfigProvider`, which maps the service `ValidatorManager` to the above
factory.
- `Module`, which does the same as `ConfigProvider`, but specifically for
zend-mvc applications. It also provices a specification to
`Zend\ModuleManager\Listener\ServiceListener` to allow modules to provide
validator configuration.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- Nothing.

## 2.6.1 - TBD

### Added
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
"branch-alias": {
"dev-master": "2.6-dev",
"dev-develop": "2.7-dev"
},
"zf": {
"component": "Zend\\Validator",
"config-provider": "Zend\\Validator\\ConfigProvider"
}
},
"autoload-dev": {
Expand Down
37 changes: 37 additions & 0 deletions src/ConfigProvider.php
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,
],
];
}
}
42 changes: 42 additions & 0 deletions src/Module.php
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'
);
}
}
53 changes: 53 additions & 0 deletions src/ValidatorPluginManagerFactory.php
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;
}
}
73 changes: 73 additions & 0 deletions test/ValidatorPluginManagerFactoryTest.php
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'));
}
}

0 comments on commit 968f855

Please sign in to comment.