This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree 2 files changed +47
-11
lines changed
2 files changed +47
-11
lines changed Original file line number Diff line number Diff line change @@ -171,19 +171,20 @@ public function createInput($inputSpecification)
171
171
172
172
if (isset ($ inputSpecification ['type ' ])) {
173
173
$ class = $ inputSpecification ['type ' ];
174
+ }
174
175
175
- if ($ this ->getInputFilterManager ()->has ($ class )) {
176
- return $ this ->createInputFilter ($ inputSpecification );
177
- }
178
-
179
- if (!class_exists ($ class )) {
180
- throw new Exception \RuntimeException (sprintf (
181
- 'Input factory expects the "type" to be a valid class; received "%s" ' ,
182
- $ class
183
- ));
184
- }
176
+ $ managerInstance = null ;
177
+ if ($ this ->getInputFilterManager ()->has ($ class )) {
178
+ $ managerInstance = $ this ->getInputFilterManager ()->get ($ class );
185
179
}
186
- $ input = new $ class ();
180
+ if (!$ managerInstance && !class_exists ($ class )) {
181
+ throw new Exception \RuntimeException (sprintf (
182
+ 'Input factory expects the "type" to be a valid class or a plugin name; received "%s" ' ,
183
+ $ class
184
+ ));
185
+ }
186
+
187
+ $ input = $ managerInstance ?: new $ class ();
187
188
188
189
if ($ input instanceof InputFilterInterface) {
189
190
return $ this ->createInputFilter ($ inputSpecification );
Original file line number Diff line number Diff line change @@ -647,4 +647,39 @@ public function testCanCreateInputFilterFromProvider()
647
647
648
648
$ this ->assertInstanceOf ('Zend\InputFilter\InputFilterInterface ' , $ inputFilter );
649
649
}
650
+
651
+ public function testSuggestedTypeMayBePluginNameInInputFilterPluginManager ()
652
+ {
653
+ $ factory = new Factory ();
654
+ $ pluginManager = new InputFilterPluginManager ();
655
+ $ pluginManager ->setService ('bar ' , new Input ('bar ' ));
656
+ $ factory ->setInputFilterManager ($ pluginManager );
657
+
658
+ $ input = $ factory ->createInput (array (
659
+ 'type ' => 'bar '
660
+ ));
661
+ $ this ->assertSame ('bar ' , $ input ->getName ());
662
+
663
+ $ this ->setExpectedException ('Zend\Filter\Exception\RuntimeException ' );
664
+ $ factory ->createInput (array (
665
+ 'type ' => 'foo '
666
+ ));
667
+ }
668
+
669
+ public function testInputFromPluginManagerMayBeFurtherConfiguredWithSpec ()
670
+ {
671
+ $ factory = new Factory ();
672
+ $ pluginManager = new InputFilterPluginManager ();
673
+ $ pluginManager ->setService ('bar ' , $ barInput = new Input ('bar ' ));
674
+ $ this ->assertTrue ($ barInput ->isRequired ());
675
+ $ factory ->setInputFilterManager ($ pluginManager );
676
+
677
+ $ input = $ factory ->createInput (array (
678
+ 'type ' => 'bar ' ,
679
+ 'required ' => false
680
+ ));
681
+
682
+ $ this ->assertFalse ($ input ->isRequired ());
683
+ $ this ->assertSame ('bar ' , $ input ->getName ());
684
+ }
650
685
}
You can’t perform that action at this time.
0 commit comments