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

Code refactor to support SM v2 + v3 #10

Merged
merged 4 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: 7
- php: hhvm
allow_failures:
- php: 7
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
- php: hhvm
- php: hhvm
env:
- SERVICE_MANAGER_VERSION='^2.7.3'
allow_failures:
- php: hhvm

notifications:
irc: "irc.freenode.org#zftalk.dev"
Expand All @@ -33,6 +45,8 @@ 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 [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0" ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"require": {
"php": ">=5.5",
"zendframework/zend-escaper": "~2.5",
"zendframework/zend-stdlib": "~2.5"
"zendframework/zend-stdlib": "dev-develop as 2.8.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should finish up zend-stdlib and tag it before merging this; would make things simpler. :)

Same goes for zend-config, below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weierophinney I think we can tag 2.8 of zend-stdlib and 2.6 of zend-config, we have a ton of usage around with "dev-develop as".

},
"require-dev": {
"zendframework/zend-config": "~2.5",
"zendframework/zend-servicemanager": "dev-develop as 2.7.0",
"zendframework/zend-config": "dev-develop as 2.6.0",
"zendframework/zend-servicemanager": "^2.7.3 || ^3.0",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
Expand Down
34 changes: 34 additions & 0 deletions src/Cloud/DecoratorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\Exception\InvalidServiceException;

/**
* Plugin manager implementation for decorators.
Expand Down Expand Up @@ -40,4 +41,37 @@ class DecoratorPluginManager extends AbstractPluginManager
];

protected $instanceOf = Decorator\DecoratorInterface::class;

/**
* Validate the plugin is of the expected type (v3).
*
* Validates against `$instanceOf`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validate($instance)
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'%s can only create instances of %s; %s is invalid',
get_class($this),
$this->instanceOf,
(is_object($instance) ? get_class($instance) : gettype($instance))
));
}
}

/**
* Validate the plugin is of the expected type (v2).
*
* Proxies to `validate()`.
*
* @param mixed $instance
* @throws InvalidServiceException
*/
public function validatePlugin($instance)
{
$this->validate($instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at zendframework/zend-servicemanager#93 — the author details having validatePlugin() do a try/catch around the validate() call, to allow it to throw the component-specific exception for v2.

We don't 100% need to do that, but it would ensure that if users are doing try/catch around calls to the plugin manager, those don't break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weierophinney I really like the idea to throw exception on validatePlugin(), I'm changing this, thanks!

}
}
10 changes: 10 additions & 0 deletions test/Cloud/CloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use stdClass;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config as SMConfig;
use Zend\Tag;
use Zend\Tag\Cloud;
use Zend\Tag\Cloud\Decorator\HtmlCloud;
Expand Down Expand Up @@ -320,12 +321,21 @@ protected function getCloud($options = null, $setDecoratorPluginManager = true)

if ($setDecoratorPluginManager) {
$decorators = $cloud->getDecoratorPluginManager();
/*
$decorators->configure([
'invokables' => [
'CloudDummy' => CloudDummy::class,
'TagDummy' => TagDummy::class
]
]);
*/
$smConfig = new SMConfig([
'invokables' => [
'CloudDummy' => CloudDummy::class,
'TagDummy' => TagDummy::class
]
]);
$smConfig->configureServiceManager($decorators);
}

return $cloud;
Expand Down