@@ -9,12 +9,6 @@ Macroable Component is a trait that, gives you the ability in effect to add new
99
1010<br >
1111
12- * [ Installation] ( #installation )
13- * [ Usage] ( #usage )
14- * [ Methods] ( #methods )
15- * [ Tests] ( #tests )
16- * [ License] ( #license )
17-
1812### Installation
1913
2014#### With [ Composer] ( https://getcomposer.org )
@@ -23,136 +17,9 @@ Macroable Component is a trait that, gives you the ability in effect to add new
2317composer require atomastic/macroable
2418```
2519
26- ### Usage
27-
28- ``` php
29- use Atomastic\Macroable\Macroable;
30- ```
31-
32- ### Methods
33-
34- | Method | Description |
35- | ---| ---|
36- | <a href =" #macroable_macro " >` macro() ` </a > | Register a custom macro. |
37- | <a href =" #macroable_mixin " >` mixin() ` </a > | Mix another object into the class. |
38- | <a href =" #macroable_hasMacro " >` hasMacro() ` </a > | Checks if macro is registered. |
39-
40- #### Methods Details
41-
42- ##### <a name =" macroable_macro " ></a > Method: ` macro() `
43-
44- ``` php
45- /**
46- * Register a custom macro.
47- *
48- * @param string $name Name.
49- * @param object|callable $macro Macro.
50- * @return void
51- */
52- public static function macro(string $name, $macro): void
53- ```
54-
55- ##### Example
56-
57- ``` php
58- $macroableClass = new class() {
59- use Macroable;
60- };
61-
62- $macroableClass::macro('concatenate', function(... $strings) {
63- return implode('-', $strings);
64- });
65-
66- $macroableClass::macro('message', function($name) {
67- return 'Hello ' . $name;
68- });
69-
70- echo $macroableClass->concatenate('one', 'two', 'three');
71- echo $macroableClass->message('Jack');
72- ```
73-
74- ##### The above example will output:
75-
76- ```
77- one-two-three
78- Hello Jack
79- ```
80-
81- ##### <a name =" macroable_mixin " ></a > Method: ` mixin() `
20+ ### Resources
21+ * [ Documentation] ( https://atomastic.com/components/macroable )
8222
83- ``` php
84- /**
85- * Mix another object into the class.
86- *
87- * @param object $mixin Mixin.
88- * @param bool $replace Replace.
89- * @return void
90- *
91- * @throws ReflectionException
92- */
93- public static function mixin($mixin, bool $replace = true): void
94- ```
95-
96- ##### Example
97-
98- ``` php
99- $mixinClass = new class() {
100- public function mixinMethod()
101- {
102- return function() {
103- return 'mixinMethod';
104- };
105- }
106-
107- public function anotherMixinMethod()
108- {
109- return function() {
110- return 'anotherMixinMethod';
111- };
112- }
113- };
114-
115- $macroableClass->mixin($mixin);
116-
117- $macroableClass->mixinMethod();
118- $macroableClass->anotherMixinMethod();
119- ```
120-
121- ##### The above example will output:
122-
123- ```
124- mixinMethod
125- anotherMixinMethod
126- ```
127-
128-
129- ##### <a name =" macroable_hasMacro " ></a > Method: ` hasMacro() `
130-
131- ``` php
132- /**
133- * Checks if macro is registered.
134- *
135- * @param string $name Name
136- * @return bool
137- */
138- public static function hasMacro(string $name): bool
139- ```
140-
141- ##### Example
142-
143- ``` php
144- $macroableClass = new class() {
145- use Macroable;
146- };
147-
148- $macroableClass::macro('message', function($name) {
149- return 'Hello ' . $name;
150- });
151-
152- if ($macroableClass::hasMacro('message')) {
153- // do something...
154- }
155- ```
15623
15724### Tests
15825
0 commit comments