This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +113
-0
lines changed Expand file tree Collapse file tree 3 files changed +113
-0
lines changed Original file line number Diff line number Diff line change @@ -783,4 +783,26 @@ public function testOptionsArePassedAsCreationOptionsToFactories()
783
783
$ this ->assertInstanceOf (DateTime::class, $ created );
784
784
$ this ->assertSame ('2016-02-19 ' , $ created ->format ('Y-m-d ' ));
785
785
}
786
+
787
+ public function testCanCreateWithConstructionLogicInOptions ()
788
+ {
789
+ $ formManager = $ this ->factory ->getFormElementManager ();
790
+ $ formManager ->setFactory (TestAsset \FieldsetWithDependency::class, TestAsset \FieldsetWithDependencyFactory::class);
791
+
792
+ $ collection = $ this ->factory ->create ([
793
+ 'type ' => Form \Element \Collection::class,
794
+ 'name ' => 'my_fieldset_collection ' ,
795
+ 'options ' => [
796
+ 'target_element ' => [
797
+ 'type ' => TestAsset \FieldsetWithDependency::class,
798
+ ],
799
+ ],
800
+ ]);
801
+
802
+ $ this ->assertInstanceOf (Form \Element \Collection::class, $ collection );
803
+
804
+ $ targetElement = $ collection ->getTargetElement ();
805
+ $ this ->assertInstanceOf (TestAsset \FieldsetWithDependency::class, $ targetElement );
806
+ $ this ->assertInstanceOf (TestAsset \InputFilter::class, $ targetElement ->getDependency ());
807
+ }
786
808
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @link http://github.com/zendframework/zend-form for the canonical source repository
4
+ * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5
+ * @license http://framework.zend.com/license/new-bsd New BSD License
6
+ */
7
+
8
+ namespace ZendTest \Form \TestAsset ;
9
+
10
+ use Zend \Form \Element ;
11
+ use Zend \Form \Fieldset ;
12
+
13
+ class FieldsetWithDependency extends Fieldset
14
+ {
15
+ /**
16
+ * @var InputFilter
17
+ */
18
+ private $ dependency ;
19
+
20
+ public function __construct ($ name = null , $ options = [])
21
+ {
22
+ parent ::__construct ('fielset_with_dependency ' , $ options );
23
+ }
24
+
25
+ public function init ()
26
+ {
27
+ // should not fail
28
+ $ this ->dependency ->getValues ();
29
+ }
30
+
31
+ /**
32
+ * @return InputFilter
33
+ */
34
+ public function getDependency ()
35
+ {
36
+ return $ this ->dependency ;
37
+ }
38
+
39
+ /**
40
+ * @param InputFilter $dependency
41
+ */
42
+ public function setDependency ($ dependency )
43
+ {
44
+ $ this ->dependency = $ dependency ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @link http://github.com/zendframework/zend-form for the canonical source repository
4
+ * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5
+ * @license http://framework.zend.com/license/new-bsd New BSD License
6
+ */
7
+
8
+ namespace ZendTest \Form \TestAsset ;
9
+
10
+ use Interop \Container \ContainerInterface ;
11
+ use Zend \ServiceManager \FactoryInterface ;
12
+ use Zend \ServiceManager \ServiceLocatorInterface ;
13
+
14
+ class FieldsetWithDependencyFactory implements FactoryInterface
15
+ {
16
+ private $ creationOptions = [];
17
+
18
+ public function __invoke (ContainerInterface $ container , $ name , array $ options = null )
19
+ {
20
+ $ options = $ options ?: [];
21
+
22
+ $ name = null ;
23
+ if (isset ($ options ['name ' ])) {
24
+ $ name = $ options ['name ' ];
25
+ unset($ options ['name ' ]);
26
+ }
27
+
28
+ $ form = new FieldsetWithDependency ($ name , $ options );
29
+ $ dependency = new InputFilter ();
30
+
31
+ $ form ->setDependency ($ dependency );
32
+
33
+ return $ form ;
34
+ }
35
+
36
+ public function createService (ServiceLocatorInterface $ container )
37
+ {
38
+ return $ this ($ container , CustomCreatedForm::class, $ this ->creationOptions );
39
+ }
40
+
41
+ public function setCreationOptions (array $ options )
42
+ {
43
+ $ this ->creationOptions = $ options ;
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments