99
1010namespace Zend \Tag \Cloud ;
1111
12+ use RuntimeException ;
1213use Zend \ServiceManager \AbstractPluginManager ;
1314use 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}
0 commit comments