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

Commit a79045b

Browse files
committed
Merge pull request #10 from ezimuel/feature/sm-v2-v3
Code refactor to support SM v2 + v3
2 parents 624730e + dab8e6f commit a79045b

File tree

5 files changed

+111
-5
lines changed

5 files changed

+111
-5
lines changed

.travis.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ matrix:
1717
- php: 5.5
1818
env:
1919
- EXECUTE_CS_CHECK=true
20+
- php: 5.5
21+
env:
22+
- SERVICE_MANAGER_VERSION='^2.7.3'
2023
- php: 5.6
2124
env:
2225
- EXECUTE_TEST_COVERALLS=true
26+
- php: 5.6
27+
env:
28+
- SERVICE_MANAGER_VERSION='^2.7.3'
2329
- php: 7
24-
- php: hhvm
25-
allow_failures:
2630
- php: 7
31+
env:
32+
- SERVICE_MANAGER_VERSION='^2.7.3'
33+
- php: hhvm
34+
- php: hhvm
35+
env:
36+
- SERVICE_MANAGER_VERSION='^2.7.3'
37+
allow_failures:
38+
- php: hhvm
2739

2840
notifications:
2941
irc: "irc.freenode.org#zftalk.dev"
@@ -33,6 +45,8 @@ before_install:
3345
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
3446
- composer self-update
3547
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
48+
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
49+
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0" ; fi
3650

3751
install:
3852
- travis_retry composer install --no-interaction --ignore-platform-reqs

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"require": {
1616
"php": ">=5.5",
1717
"zendframework/zend-escaper": "~2.5",
18-
"zendframework/zend-stdlib": "~2.5"
18+
"zendframework/zend-stdlib": "^3.0"
1919
},
2020
"require-dev": {
21-
"zendframework/zend-config": "~2.5",
22-
"zendframework/zend-servicemanager": "dev-develop as 2.7.0",
21+
"zendframework/zend-config": "dev-develop as 2.6.0",
22+
"zendframework/zend-servicemanager": "^2.7.4 || ^3.0.3",
2323
"fabpot/php-cs-fixer": "1.7.*",
2424
"phpunit/PHPUnit": "~4.0"
2525
},

src/Cloud/DecoratorPluginManager.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
namespace Zend\Tag\Cloud;
1111

12+
use RuntimeException;
1213
use Zend\ServiceManager\AbstractPluginManager;
1314
use Zend\ServiceManager\Factory\InvokableFactory;
15+
use Zend\ServiceManager\Exception\InvalidServiceException;
1416

1517
/**
1618
* Plugin manager implementation for decorators.
@@ -37,7 +39,49 @@ class DecoratorPluginManager extends AbstractPluginManager
3739
protected $factories = [
3840
Decorator\HtmlCloud::class => InvokableFactory::class,
3941
Decorator\HtmlTag::class => InvokableFactory::class,
42+
// Legacy (v2) due to alias resolution; canonical form of resolved
43+
// alias is used to look up the factory, while the non-normalized
44+
// resolved alias is used as the requested name passed to the factory.
45+
'zendtagclouddecoratorhtmlcloud' => InvokableFactory::class,
46+
'zendtagclouddecoratorhtmltag' => InvokableFactory::class
4047
];
4148

4249
protected $instanceOf = Decorator\DecoratorInterface::class;
50+
51+
/**
52+
* Validate the plugin is of the expected type (v3).
53+
*
54+
* Validates against `$instanceOf`.
55+
*
56+
* @param mixed $instance
57+
* @throws InvalidServiceException
58+
*/
59+
public function validate($instance)
60+
{
61+
if (! $instance instanceof $this->instanceOf) {
62+
throw new InvalidServiceException(sprintf(
63+
'%s can only create instances of %s; %s is invalid',
64+
get_class($this),
65+
$this->instanceOf,
66+
(is_object($instance) ? get_class($instance) : gettype($instance))
67+
));
68+
}
69+
}
70+
71+
/**
72+
* Validate the plugin is of the expected type (v2).
73+
*
74+
* Proxies to `validate()`.
75+
*
76+
* @param mixed $instance
77+
* @throws InvalidServiceException
78+
*/
79+
public function validatePlugin($instance)
80+
{
81+
try {
82+
$this->validate($instance);
83+
} catch (InvalidServiceException $e) {
84+
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
85+
}
86+
}
4387
}

test/Cloud/CloudTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use stdClass;
1313
use Zend\ServiceManager\ServiceManager;
14+
use Zend\ServiceManager\Config as SMConfig;
1415
use Zend\Tag;
1516
use Zend\Tag\Cloud;
1617
use Zend\Tag\Cloud\Decorator\HtmlCloud;
@@ -320,12 +321,21 @@ protected function getCloud($options = null, $setDecoratorPluginManager = true)
320321

321322
if ($setDecoratorPluginManager) {
322323
$decorators = $cloud->getDecoratorPluginManager();
324+
/*
323325
$decorators->configure([
324326
'invokables' => [
325327
'CloudDummy' => CloudDummy::class,
326328
'TagDummy' => TagDummy::class
327329
]
328330
]);
331+
*/
332+
$smConfig = new SMConfig([
333+
'invokables' => [
334+
'CloudDummy' => CloudDummy::class,
335+
'TagDummy' => TagDummy::class
336+
]
337+
]);
338+
$smConfig->configureServiceManager($decorators);
329339
}
330340

331341
return $cloud;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
namespace ZendTest\ServiceManager;
10+
11+
use PHPUnit_Framework_TestCase as TestCase;
12+
use Zend\ServiceManager\ServiceManager;
13+
use Zend\Tag\Cloud\DecoratorPluginManager;
14+
use Zend\Tag\Cloud\Decorator\DecoratorInterface;
15+
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
16+
17+
/**
18+
* Example test of using CommonPluginManagerTrait
19+
*/
20+
class DecoratorPluginManagerCompatibilityTest extends TestCase
21+
{
22+
use CommonPluginManagerTrait;
23+
24+
protected function getPluginManager()
25+
{
26+
return new DecoratorPluginManager(new ServiceManager());
27+
}
28+
29+
protected function getV2InvalidPluginException()
30+
{
31+
return \RuntimeException::class;
32+
}
33+
34+
protected function getInstanceOf()
35+
{
36+
return DecoratorInterface::class;
37+
}
38+
}

0 commit comments

Comments
 (0)