@@ -25,13 +25,31 @@ class InlineDirectory extends DataReference {
25
25
/**
26
26
* Constructor.
27
27
*
28
- * @param string $name The directory name.
29
- * @param array $children The directory children.
28
+ * @param array $data The blueprint data array.
30
29
*/
31
- public function __construct ( string $ name , array $ children ) {
32
- $ this ->name = $ name ;
30
+ public function __construct ( array $ data ) {
31
+ if ( ! isset ( $ data ['directoryName ' ] ) || ! isset ( $ data ['files ' ] ) || ! is_array ( $ data ['files ' ] ) ) {
32
+ throw new InvalidArgumentException ( 'Invalid inline directory data ' );
33
+ }
34
+
35
+ $ this ->name = $ data ['directoryName ' ];
36
+
37
+ $ children = [];
38
+ foreach ( $ data ['files ' ] as $ fileName => $ child ) {
39
+ if ( is_string ( $ child ) ) {
40
+ $ children [$ fileName ] = new InlineFile ( [
41
+ 'filename ' => $ fileName ,
42
+ 'content ' => $ child
43
+ ] );
44
+ } elseif ( self ::is_valid ( $ child ) ) {
45
+ $ children [$ fileName ] = new self ( $ child );
46
+ } else {
47
+ throw new InvalidArgumentException ( 'Invalid inline directory child ' );
48
+ }
49
+ }
50
+
33
51
$ this ->children = $ children ;
34
- parent ::__construct ();
52
+ parent ::__construct ( $ data );
35
53
}
36
54
37
55
/**
@@ -81,31 +99,6 @@ public function as_directory(): Directory {
81
99
return new Directory ( $ this ->as_filesystem (), $ this ->get_name () );
82
100
}
83
101
84
- /**
85
- * Create an instance from an array.
86
- *
87
- * @param array $data The array data.
88
- *
89
- * @return self The created instance.
90
- */
91
- public static function from_blueprint_data ( array $ data ): self {
92
- if ( ! isset ( $ data ['directoryName ' ] ) || ! isset ( $ data ['files ' ] ) || ! is_array ( $ data ['files ' ] ) ) {
93
- throw new InvalidArgumentException ( 'Invalid inline directory data ' );
94
- }
95
-
96
- $ children = [];
97
- foreach ( $ data ['files ' ] as $ fileName => $ child ) {
98
- if ( is_string ( $ child ) ) {
99
- $ children [$ fileName ] = new InlineFile ( $ fileName , $ child );
100
- } elseif ( self ::is_valid ( $ child ) ) {
101
- $ children [$ fileName ] = self ::from_blueprint_data ( $ child );
102
- } else {
103
- throw new InvalidArgumentException ( 'Invalid inline directory child ' );
104
- }
105
- }
106
-
107
- return new self ( $ data ['directoryName ' ], $ children );
108
- }
109
102
110
103
/**
111
104
* Check if an array represents a valid inline directory.
0 commit comments