99
1010namespace Zend \InputFilter ;
1111
12+ use Interop \Container \ContainerInterface ;
1213use Zend \Filter \FilterPluginManager ;
1314use Zend \ServiceManager \AbstractFactoryInterface ;
1415use Zend \ServiceManager \ServiceLocatorInterface ;
@@ -22,21 +23,34 @@ class InputFilterAbstractServiceFactory implements AbstractFactoryInterface
2223 protected $ factory ;
2324
2425 /**
25- * @param ServiceLocatorInterface $inputFilters
26+ * @param ContainerInterface $services
27+ * @param string $rName
28+ * @param array $options
29+ * @return InputFilterInterface
30+ */
31+ public function __invoke (ContainerInterface $ services , $ rName , array $ options = null )
32+ {
33+ $ allConfig = $ services ->get ('config ' );
34+ $ config = $ allConfig ['input_filter_specs ' ][$ rName ];
35+ $ factory = $ this ->getInputFilterFactory ($ services );
36+
37+ return $ factory ->createInputFilter ($ config );
38+ }
39+
40+ /**
41+ *
42+ * @param ContainerInterface $services
2643 * @param string $cName
2744 * @param string $rName
2845 * @return bool
2946 */
30- public function canCreateServiceWithName ( ServiceLocatorInterface $ inputFilters , $ cName , $ rName )
47+ public function canCreate ( ContainerInterface $ services , $ rName )
3148 {
32- $ services = $ inputFilters ->getServiceLocator ();
33- if (! $ services instanceof ServiceLocatorInterface
34- || ! $ services ->has ('Config ' )
35- ) {
49+ if (! $ services ->has ('config ' )) {
3650 return false ;
3751 }
3852
39- $ config = $ services ->get ('Config ' );
53+ $ config = $ services ->get ('config ' );
4054 if (!isset ($ config ['input_filter_specs ' ][$ rName ])
4155 || !is_array ($ config ['input_filter_specs ' ][$ rName ])
4256 ) {
@@ -46,6 +60,27 @@ public function canCreateServiceWithName(ServiceLocatorInterface $inputFilters,
4660 return true ;
4761 }
4862
63+ /**
64+ * Determine if we can create a service with name (v2)
65+ *
66+ * @param ServiceLocatorInterface $serviceLocator
67+ * @param $name
68+ * @param $requestedName
69+ * @return bool
70+ */
71+ public function canCreateServiceWithName (ServiceLocatorInterface $ serviceLocator , $ name , $ requestedName )
72+ {
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 ;
79+ }
80+
81+ return $ this ->canCreate ($ services , $ requestedName );
82+ }
83+
4984 /**
5085 * @param ServiceLocatorInterface $inputFilters
5186 * @param string $cName
@@ -54,13 +89,15 @@ public function canCreateServiceWithName(ServiceLocatorInterface $inputFilters,
5489 */
5590 public function createServiceWithName (ServiceLocatorInterface $ inputFilters , $ cName , $ rName )
5691 {
57- $ services = $ inputFilters ->getServiceLocator ();
58- $ allConfig = $ services ->get ('Config ' );
59- $ config = $ allConfig ['input_filter_specs ' ][$ rName ];
92+ // v2 => need to get parent service locator
93+ $ services = $ inputFilters ->getServiceLocator ();
6094
61- $ factory = $ this ->getInputFilterFactory ($ services );
95+ // No parent locator => cannot create service.
96+ if (! $ services ) {
97+ return false ;
98+ }
6299
63- return $ factory -> createInputFilter ( $ config );
100+ return $ this ( $ services , $ rName );
64101 }
65102
66103 /**
@@ -94,7 +131,7 @@ protected function getFilterPluginManager(ServiceLocatorInterface $services)
94131 return $ services ->get ('FilterManager ' );
95132 }
96133
97- return new FilterPluginManager ();
134+ return new FilterPluginManager ($ services );
98135 }
99136
100137 /**
@@ -107,6 +144,6 @@ protected function getValidatorPluginManager(ServiceLocatorInterface $services)
107144 return $ services ->get ('ValidatorManager ' );
108145 }
109146
110- return new ValidatorPluginManager ();
147+ return new ValidatorPluginManager ($ services );
111148 }
112149}
0 commit comments