1212use Interop \Container \ContainerInterface ;
1313use Zend \Filter \FilterPluginManager ;
1414use Zend \ServiceManager \AbstractFactoryInterface ;
15+ use Zend \ServiceManager \AbstractPluginManager ;
1516use Zend \ServiceManager \ServiceLocatorInterface ;
1617use Zend \Validator \ValidatorPluginManager ;
1718
@@ -63,48 +64,44 @@ public function canCreate(ContainerInterface $services, $rName)
6364 /**
6465 * Determine if we can create a service with name (v2)
6566 *
66- * @param ServiceLocatorInterface $serviceLocator
67+ * @param ServiceLocatorInterface $container
6768 * @param $name
6869 * @param $requestedName
6970 * @return bool
7071 */
71- public function canCreateServiceWithName (ServiceLocatorInterface $ serviceLocator , $ name , $ requestedName )
72+ public function canCreateServiceWithName (ServiceLocatorInterface $ container , $ name , $ requestedName )
7273 {
73- // v2 => need to get parent service locator
74- $ services = $ serviceLocator ->getServiceLocator ();
75-
76- // No parent locator => cannot create service.
77- if (! $ services ) {
78- return false ;
74+ // v2 => may need to get parent service locator
75+ if ($ container instanceof AbstractPluginManager) {
76+ $ container = $ container ->getServiceLocator () ?: $ container ;
7977 }
8078
81- return $ this ->canCreate ($ services , $ requestedName );
79+ return $ this ->canCreate ($ container , $ requestedName );
8280 }
8381
8482 /**
85- * @param ServiceLocatorInterface $inputFilters
83+ * Create the requested service (v2)
84+ *
85+ * @param ServiceLocatorInterface $container
8686 * @param string $cName
8787 * @param string $rName
8888 * @return InputFilterInterface
8989 */
90- public function createServiceWithName (ServiceLocatorInterface $ inputFilters , $ cName , $ rName )
90+ public function createServiceWithName (ServiceLocatorInterface $ container , $ cName , $ rName )
9191 {
92- // v2 => need to get parent service locator
93- $ services = $ inputFilters ->getServiceLocator ();
94-
95- // No parent locator => cannot create service.
96- if (! $ services ) {
97- return false ;
92+ // v2 => may need to get parent service locator
93+ if ($ container instanceof AbstractPluginManager) {
94+ $ container = $ container ->getServiceLocator () ?: $ container ;
9895 }
9996
100- return $ this ($ services , $ rName );
97+ return $ this ($ container , $ rName );
10198 }
10299
103100 /**
104- * @param ServiceLocatorInterface $services
101+ * @param ContainerInterface $container
105102 * @return Factory
106103 */
107- protected function getInputFilterFactory (ServiceLocatorInterface $ services )
104+ protected function getInputFilterFactory (ContainerInterface $ container )
108105 {
109106 if ($ this ->factory instanceof Factory) {
110107 return $ this ->factory ;
@@ -113,39 +110,39 @@ protected function getInputFilterFactory(ServiceLocatorInterface $services)
113110 $ this ->factory = new Factory ();
114111 $ this ->factory
115112 ->getDefaultFilterChain ()
116- ->setPluginManager ($ this ->getFilterPluginManager ($ services ));
113+ ->setPluginManager ($ this ->getFilterPluginManager ($ container ));
117114 $ this ->factory
118115 ->getDefaultValidatorChain ()
119- ->setPluginManager ($ this ->getValidatorPluginManager ($ services ));
116+ ->setPluginManager ($ this ->getValidatorPluginManager ($ container ));
120117
121- $ this ->factory ->setInputFilterManager ($ services ->get ('InputFilterManager ' ));
118+ $ this ->factory ->setInputFilterManager ($ container ->get ('InputFilterManager ' ));
122119
123120 return $ this ->factory ;
124121 }
125122
126123 /**
127- * @param ServiceLocatorInterface $services
124+ * @param ContainerInterface $container
128125 * @return FilterPluginManager
129126 */
130- protected function getFilterPluginManager (ServiceLocatorInterface $ services )
127+ protected function getFilterPluginManager (ContainerInterface $ container )
131128 {
132- if ($ services ->has ('FilterManager ' )) {
133- return $ services ->get ('FilterManager ' );
129+ if ($ container ->has ('FilterManager ' )) {
130+ return $ container ->get ('FilterManager ' );
134131 }
135132
136- return new FilterPluginManager ($ services );
133+ return new FilterPluginManager ($ container );
137134 }
138135
139136 /**
140- * @param ServiceLocatorInterface $services
137+ * @param ContainerInterface $container
141138 * @return ValidatorPluginManager
142139 */
143- protected function getValidatorPluginManager (ServiceLocatorInterface $ services )
140+ protected function getValidatorPluginManager (ContainerInterface $ container )
144141 {
145- if ($ services ->has ('ValidatorManager ' )) {
146- return $ services ->get ('ValidatorManager ' );
142+ if ($ container ->has ('ValidatorManager ' )) {
143+ return $ container ->get ('ValidatorManager ' );
147144 }
148145
149- return new ValidatorPluginManager ($ services );
146+ return new ValidatorPluginManager ($ container );
150147 }
151148}
0 commit comments