12
12
use Interop \Container \ContainerInterface ;
13
13
use Zend \Filter \FilterPluginManager ;
14
14
use Zend \ServiceManager \AbstractFactoryInterface ;
15
+ use Zend \ServiceManager \AbstractPluginManager ;
15
16
use Zend \ServiceManager \ServiceLocatorInterface ;
16
17
use Zend \Validator \ValidatorPluginManager ;
17
18
@@ -63,48 +64,44 @@ public function canCreate(ContainerInterface $services, $rName)
63
64
/**
64
65
* Determine if we can create a service with name (v2)
65
66
*
66
- * @param ServiceLocatorInterface $serviceLocator
67
+ * @param ServiceLocatorInterface $container
67
68
* @param $name
68
69
* @param $requestedName
69
70
* @return bool
70
71
*/
71
- public function canCreateServiceWithName (ServiceLocatorInterface $ serviceLocator , $ name , $ requestedName )
72
+ public function canCreateServiceWithName (ServiceLocatorInterface $ container , $ name , $ requestedName )
72
73
{
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 ;
79
77
}
80
78
81
- return $ this ->canCreate ($ services , $ requestedName );
79
+ return $ this ->canCreate ($ container , $ requestedName );
82
80
}
83
81
84
82
/**
85
- * @param ServiceLocatorInterface $inputFilters
83
+ * Create the requested service (v2)
84
+ *
85
+ * @param ServiceLocatorInterface $container
86
86
* @param string $cName
87
87
* @param string $rName
88
88
* @return InputFilterInterface
89
89
*/
90
- public function createServiceWithName (ServiceLocatorInterface $ inputFilters , $ cName , $ rName )
90
+ public function createServiceWithName (ServiceLocatorInterface $ container , $ cName , $ rName )
91
91
{
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 ;
98
95
}
99
96
100
- return $ this ($ services , $ rName );
97
+ return $ this ($ container , $ rName );
101
98
}
102
99
103
100
/**
104
- * @param ServiceLocatorInterface $services
101
+ * @param ContainerInterface $container
105
102
* @return Factory
106
103
*/
107
- protected function getInputFilterFactory (ServiceLocatorInterface $ services )
104
+ protected function getInputFilterFactory (ContainerInterface $ container )
108
105
{
109
106
if ($ this ->factory instanceof Factory) {
110
107
return $ this ->factory ;
@@ -113,39 +110,39 @@ protected function getInputFilterFactory(ServiceLocatorInterface $services)
113
110
$ this ->factory = new Factory ();
114
111
$ this ->factory
115
112
->getDefaultFilterChain ()
116
- ->setPluginManager ($ this ->getFilterPluginManager ($ services ));
113
+ ->setPluginManager ($ this ->getFilterPluginManager ($ container ));
117
114
$ this ->factory
118
115
->getDefaultValidatorChain ()
119
- ->setPluginManager ($ this ->getValidatorPluginManager ($ services ));
116
+ ->setPluginManager ($ this ->getValidatorPluginManager ($ container ));
120
117
121
- $ this ->factory ->setInputFilterManager ($ services ->get ('InputFilterManager ' ));
118
+ $ this ->factory ->setInputFilterManager ($ container ->get ('InputFilterManager ' ));
122
119
123
120
return $ this ->factory ;
124
121
}
125
122
126
123
/**
127
- * @param ServiceLocatorInterface $services
124
+ * @param ContainerInterface $container
128
125
* @return FilterPluginManager
129
126
*/
130
- protected function getFilterPluginManager (ServiceLocatorInterface $ services )
127
+ protected function getFilterPluginManager (ContainerInterface $ container )
131
128
{
132
- if ($ services ->has ('FilterManager ' )) {
133
- return $ services ->get ('FilterManager ' );
129
+ if ($ container ->has ('FilterManager ' )) {
130
+ return $ container ->get ('FilterManager ' );
134
131
}
135
132
136
- return new FilterPluginManager ($ services );
133
+ return new FilterPluginManager ($ container );
137
134
}
138
135
139
136
/**
140
- * @param ServiceLocatorInterface $services
137
+ * @param ContainerInterface $container
141
138
* @return ValidatorPluginManager
142
139
*/
143
- protected function getValidatorPluginManager (ServiceLocatorInterface $ services )
140
+ protected function getValidatorPluginManager (ContainerInterface $ container )
144
141
{
145
- if ($ services ->has ('ValidatorManager ' )) {
146
- return $ services ->get ('ValidatorManager ' );
142
+ if ($ container ->has ('ValidatorManager ' )) {
143
+ return $ container ->get ('ValidatorManager ' );
147
144
}
148
145
149
- return new ValidatorPluginManager ($ services );
146
+ return new ValidatorPluginManager ($ container );
150
147
}
151
148
}
0 commit comments