File tree Expand file tree Collapse file tree 7 files changed +130
-36
lines changed
Expand file tree Collapse file tree 7 files changed +130
-36
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray ;
4+
5+ interface Configurable
6+ {
7+ /**
8+ * @param FluentArray|null $defaultConfig
9+ * @return mixed
10+ */
11+ public static function defaultConfig (FluentArray $ defaultConfig = null );
12+
13+ /**
14+ * @param FluentArray|null $config
15+ * @return mixed
16+ */
17+ public function config (FluentArray $ config = null );
18+ }
Original file line number Diff line number Diff line change 22
33namespace BabenkoIvan \FluentArray ;
44
5- class FluentArray
5+ class FluentArray implements Configurable
66{
7+ use HasConfiguration;
8+
79 /**
810 * @var array
911 */
1012 private $ storage = [];
1113
12- /**
13- * @var FluentArray
14- */
15- private static $ defaultConfig ;
16-
17- /**
18- * @var FluentArray
19- */
20- private $ config ;
21-
2214 /**
2315 * @param FluentArray|null $config
2416 */
2517 public function __construct (FluentArray $ config = null )
2618 {
27- $ this ->config = $ config ;
28- }
29-
30- /**
31- * @return FluentArray
32- */
33- public static function defaultConfig ()
34- {
35- if (!isset (static ::$ defaultConfig )) {
36- static ::$ defaultConfig = new FluentArray ();
37- }
38-
39- return static ::$ defaultConfig ;
40- }
41-
42- /**
43- * @return FluentArray
44- */
45- public function config ()
46- {
47- if (!isset ($ this ->config )) {
48- $ this ->config = clone static ::defaultConfig ();
49- }
50-
51- return $ this ->config ;
19+ $ this ->config ($ config );
5220 }
5321
5422 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray ;
4+
5+ trait HasConfiguration
6+ {
7+ /**
8+ * @var FluentArray
9+ */
10+ private static $ defaultConfig ;
11+
12+ /**
13+ * @var FluentArray
14+ */
15+ private $ config ;
16+
17+ /**
18+ * @param FluentArray|null $defaultConfig
19+ * @return mixed
20+ */
21+ public static function defaultConfig (FluentArray $ defaultConfig = null )
22+ {
23+ if (isset ($ defaultConfig )) {
24+ static ::$ defaultConfig = $ defaultConfig ;
25+ } else {
26+ if (!isset (static ::$ defaultConfig )) {
27+ static ::$ defaultConfig = new FluentArray ();
28+ }
29+
30+ return static ::$ defaultConfig ;
31+ }
32+ }
33+
34+ /**
35+ * @param FluentArray|null $config
36+ * @return mixed
37+ */
38+ public function config (FluentArray $ config = null )
39+ {
40+ if (isset ($ config )) {
41+ $ this ->config = $ config ;
42+ return $ this ;
43+ } else {
44+ if (!isset ($ this ->config )) {
45+ $ this ->config = clone static ::defaultConfig ();
46+ }
47+
48+ return $ this ->config ;
49+ }
50+ }
51+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray \NamingStrategies ;
4+
5+ class CamelCaseStrategy implements NamingStrategy
6+ {
7+ /**
8+ * @param string $key
9+ * @return string
10+ */
11+ public function transform (string $ key ): string
12+ {
13+ // TODO: Implement transform() method.
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray \NamingStrategies ;
4+
5+ interface NamingStrategy
6+ {
7+ /**
8+ * @param string $key
9+ * @return string
10+ */
11+ public function transform (string $ key ): string ;
12+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray \NamingStrategies ;
4+
5+ class NullStrategy implements NamingStrategy
6+ {
7+ /**
8+ * @param string $key
9+ * @return string
10+ */
11+ public function transform (string $ key ): string
12+ {
13+ return $ key ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace BabenkoIvan \FluentArray \NamingStrategies ;
4+
5+ class UnderscoreStrategy implements NamingStrategy
6+ {
7+ /**
8+ * @param string $key
9+ * @return string
10+ */
11+ public function transform (string $ key ): string
12+ {
13+ // TODO: Implement transform() method.
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments