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

Commit

Permalink
Merge branch 'feature/sm-forwards-compat' into develop
Browse files Browse the repository at this point in the history
Close #18
  • Loading branch information
weierophinney committed Feb 17, 2016
2 parents 325773b + 8a35528 commit e6e69e8
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 40 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- ZEND_SERVICEMANAGER_VERSION="^2.7.5"
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- ZEND_SERVICEMANAGER_VERSION="^2.7.5"
- php: 7
- php: 7
env:
- ZEND_SERVICEMANAGER_VERSION="^2.7.5"
- php: hhvm
- php: hhvm
env:
- ZEND_SERVICEMANAGER_VERSION="^2.7.5"
allow_failures:
- php: hhvm

Expand All @@ -33,6 +45,9 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $ZEND_SERVICEMANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$ZEND_SERVICEMANAGER_VERSION" ; fi
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
- if [[ $ZEND_SERVICEMANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-progressbar ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## 2.6.0 - TBD
## 2.6.0 - 2016-02-17

### Added

Expand All @@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#18](https://github.com/zendframework/zend-file/pull/18) updates the codebase
to be forwards compatible with zend-servicemanager and zend-stdlib v3.

## 2.5.3 - TBD

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
},
"require": {
"php": "^5.5 || ^7.0",
"zendframework/zend-stdlib": "~2.5"
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"zendframework/zend-filter": "~2.6",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-servicemanager": "~2.5",
"zendframework/zend-validator": "~2.5",
"zendframework/zend-filter": "^2.6.1",
"zendframework/zend-i18n": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-validator": "^2.6",
"zendframework/zend-progressbar": "~2.5",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
Expand Down
25 changes: 23 additions & 2 deletions src/Transfer/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
namespace Zend\File\Transfer\Adapter;

use ErrorException;
use ReflectionClass;
use Zend\File\Transfer;
use Zend\File\Transfer\Exception;
use Zend\Filter;
use Zend\Filter\Exception as FilterException;
use Zend\I18n\Translator\TranslatorInterface as Translator;
use Zend\I18n\Translator\TranslatorAwareInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ErrorHandler;
use Zend\Validator;

Expand Down Expand Up @@ -241,7 +243,7 @@ public function setFilterManager(FilterPluginManager $filterManager)
public function getFilterManager()
{
if (!$this->filterManager instanceof FilterPluginManager) {
$this->setFilterManager(new FilterPluginManager());
$this->setFilterManager(new FilterPluginManager(new ServiceManager()));
}
return $this->filterManager;
}
Expand All @@ -266,7 +268,11 @@ public function setValidatorManager(ValidatorPluginManager $validatorManager)
public function getValidatorManager()
{
if (!$this->validatorManager instanceof ValidatorPluginManager) {
$this->setValidatorManager(new ValidatorPluginManager());
if ($this->isServiceManagerV3()) {
$this->setValidatorManager(new ValidatorPluginManager(new ServiceManager()));
} else {
$this->setValidatorManager(new ValidatorPluginManager());
}
}
return $this->validatorManager;
}
Expand All @@ -284,6 +290,7 @@ public function getValidatorManager()
public function addValidator($validator, $breakChainOnFailure = false, $options = null, $files = null)
{
if (is_string($validator)) {
$options = (null !== $options && is_scalar($options)) ? [$options] : $options;
$validator = $this->getValidatorManager()->get($validator, $options);
if (is_array($options) && isset($options['messages'])) {
if (is_array($options['messages'])) {
Expand Down Expand Up @@ -1506,4 +1513,18 @@ protected function getFilterIdentifier($name)

return false;
}

/**
* Is the service manager component v3?
*
* This is needed until zend-validator is updated, to ensure we instantiate
* the validator plugin manager properly.
*
* @return bool
*/
private function isServiceManagerV3()
{
$r = new ReflectionClass(ServiceManager::class);
return ! $r->hasProperty('invokableClasses');
}
}
24 changes: 16 additions & 8 deletions src/Transfer/Adapter/FilterPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
*/
class FilterPluginManager extends BaseManager
{
protected $defaultFileFilterAliases = [
'decrypt' => File\Decrypt::class,
'Decrypt' => File\Decrypt::class,
'encrypt' => File\Encrypt::class,
'Encrypt' => File\Encrypt::class,
'lowercase' => File\LowerCase::class,
'lowerCase' => File\LowerCase::class,
'LowerCase' => File\LowerCase::class,
'rename' => File\Rename::class,
'Rename' => File\Rename::class,
'uppercase' => File\UpperCase::class,
'upperCase' => File\UpperCase::class,
'UpperCase' => File\UpperCase::class,
];

/**
* Constructor
*
Expand All @@ -33,14 +48,7 @@ class FilterPluginManager extends BaseManager
*/
public function __construct($configOrContainerInstance = null, array $v3config = [])
{
$this->aliases = array_merge([
'decrypt' => File\Decrypt::class,
'encrypt' => File\Encrypt::class,
'lowercase' => File\LowerCase::class,
'rename' => File\Rename::class,
'uppercase' => File\UpperCase::class,
], $this->aliases);

$this->aliases = array_merge($this->defaultFileFilterAliases, $this->aliases);
parent::__construct($configOrContainerInstance, $v3config);
}
}
85 changes: 66 additions & 19 deletions src/Transfer/Adapter/ValidatorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,75 @@

namespace Zend\File\Transfer\Adapter;

use Zend\Validator\File;
use Zend\Validator\ValidatorPluginManager as BaseManager;

class ValidatorPluginManager extends BaseManager
{
protected $aliases = [
'count' => 'filecount',
'crc32' => 'filecrc32',
'excludeextension' => 'fileexcludeextension',
'excludemimetype' => 'fileexcludemimetype',
'exists' => 'fileexists',
'extension' => 'fileextension',
'filessize' => 'filefilessize',
'hash' => 'filehash',
'imagesize' => 'fileimagesize',
'iscompressed' => 'fileiscompressed',
'isimage' => 'fileisimage',
'md5' => 'filemd5',
'mimetype' => 'filemimetype',
'notexists' => 'filenotexists',
'sha1' => 'filesha1',
'size' => 'filesize',
'upload' => 'fileupload',
'wordcount' => 'filewordcount',
protected $defaultFileValidationAliases = [
'count' => File\Count::class,
'Count' => File\Count::class,
'crc32' => File\Crc32::class,
'Crc32' => File\Crc32::class,
'CRC32' => File\Crc32::class,
'excludeextension' => File\ExcludeExtension::class,
'excludeExtension' => File\ExcludeExtension::class,
'ExcludeExtension' => File\ExcludeExtension::class,
'excludemimetype' => File\ExcludeMimeType::class,
'excludeMimeType' => File\ExcludeMimeType::class,
'ExcludeMimeType' => File\ExcludeMimeType::class,
'exists' => File\Exists::class,
'Exists' => File\Exists::class,
'extension' => File\Extension::class,
'Extension' => File\Extension::class,
'filessize' => File\FilesSize::class,
'filesSize' => File\FilesSize::class,
'FilesSize' => File\FilesSize::class,
'hash' => File\Hash::class,
'Hash' => File\Hash::class,
'imagesize' => File\ImageSize::class,
'imageSize' => File\ImageSize::class,
'ImageSize' => File\ImageSize::class,
'iscompressed' => File\IsCompressed::class,
'isCompressed' => File\IsCompressed::class,
'IsCompressed' => File\IsCompressed::class,
'isimage' => File\IsImage::class,
'isImage' => File\IsImage::class,
'IsImage' => File\IsImage::class,
'md5' => File\Md5::class,
'Md5' => File\Md5::class,
'MD5' => File\Md5::class,
'mimetype' => File\MimeType::class,
'mimeType' => File\MimeType::class,
'MimeType' => File\MimeType::class,
'notexists' => File\NotExists::class,
'notExists' => File\NotExists::class,
'NotExists' => File\NotExists::class,
'sha1' => File\Sha1::class,
'Sha1' => File\Sha1::class,
'SHA1' => File\Sha1::class,
'size' => File\Size::class,
'Size' => File\Size::class,
'upload' => File\Upload::class,
'Upload' => File\Upload::class,
'wordcount' => File\WordCount::class,
'wordCount' => File\WordCount::class,
'WordCount' => File\WordCount::class,
];

/**
* Constructor
*
* Merges default aliases pertinent to this plugin manager with those
* defined in the parent filter plugin manager.
*
* @param null|\Zend\ServiceManager\ConfigInterface|\Interop\Container\ContainerInterface $configOrContainerInstance
* @param array $v3config If $configOrContainerInstance is a container, this
* value will be passed to the parent constructor.
*/
public function __construct($configOrContainerInstance = null, array $v3config = [])
{
$this->aliases = array_merge($this->defaultFileValidationAliases, $this->aliases);
parent::__construct($configOrContainerInstance, $v3config);
}
}
10 changes: 6 additions & 4 deletions test/Transfer/Adapter/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace ZendTest\File\Transfer\Adapter;

use Interop\Container\ContainerInterface;
use stdClass;
use Zend\File;
use Zend\Filter;
use Zend\Filter\Word;
use Zend\Validator;
use Zend\Validator\File as FileValidator;

Expand Down Expand Up @@ -51,7 +52,8 @@ public function testAdapterShouldLazyLoadValidatorPluginManager()

public function testAdapterShouldAllowSettingFilterPluginManagerInstance()
{
$manager = new File\Transfer\Adapter\FilterPluginManager();
$container = $this->prophesize(ContainerInterface::class)->reveal();
$manager = new File\Transfer\Adapter\FilterPluginManager($container);
$this->adapter->setFilterManager($manager);
$this->assertSame($manager, $this->adapter->getFilterManager());
}
Expand Down Expand Up @@ -268,13 +270,13 @@ public function testAdapterShouldAllowAddingFilterViaPluginManager()
public function testAdapterhShouldRaiseExceptionWhenAddingInvalidFilterType()
{
$this->setExpectedException('Zend\File\Transfer\Exception\InvalidArgumentException', 'Invalid filter specified');
$this->adapter->addFilter(new FileValidator\Extension('jpg'));
$this->adapter->addFilter(new stdClass());
}

public function testAdapterShouldAllowAddingMultipleFiltersAtOnceUsingBothInstancesAndPluginLoader()
{
$filters = [
'Word\SeparatorToCamelCase' => ['separator' => ' '],
'wordSeparatorToCamelCase' => ['separator' => ' '],
[
'filter' => 'Boolean',
'casting' => true
Expand Down

0 comments on commit e6e69e8

Please sign in to comment.