22
33namespace Pboivin \Flou ;
44
5+ use InvalidArgumentException ;
56use Stringable ;
67
78abstract class ImgRenderable implements Stringable
@@ -22,32 +23,53 @@ abstract class ImgRenderable implements Stringable
2223
2324 protected $ wrapper = false ;
2425
26+ protected $ base64Lqip = false ;
27+
28+ /* Internal */
2529 protected $ includeLqip = true ;
2630
27- protected $ base64Lqip = false ;
31+ protected function acceptRenderConfig (array $ config ): void
32+ {
33+ foreach ($ config as $ key => $ value ) {
34+ if (method_exists ($ this , $ method = "set {$ key }" )) {
35+ $ this ->$ method ($ value );
36+ } elseif (method_exists ($ this , $ method = "use {$ key }" )) {
37+ $ this ->$ method ($ value );
38+ } else {
39+ throw new InvalidArgumentException ("Invalid option ' $ key'. " );
40+ }
41+ }
42+ }
2843
2944 public function __toString (): string
3045 {
3146 return $ this ->img ();
3247 }
3348
34- public function setBaseClass (string $ cls ): self
49+ public function setBaseClass (string $ cssClass ): self
3550 {
36- $ this ->baseClass = $ cls ;
51+ $ this ->baseClass = $ cssClass ;
3752
3853 return $ this ;
3954 }
4055
41- public function setWrapperClass (string $ cls ): self
56+ public function setWrapperClass (string $ cssClass ): self
4257 {
43- $ this ->wrapperClass = $ cls ;
58+ $ this ->wrapperClass = $ cssClass ;
4459
4560 return $ this ;
4661 }
4762
48- public function setLqipClass (string $ cls ): self
63+ public function setLqipClass (string $ cssClass ): self
4964 {
50- $ this ->lqipClass = $ cls ;
65+ $ this ->lqipClass = $ cssClass ;
66+
67+ return $ this ;
68+ }
69+
70+ public function setPaddingClass (string $ cssClass ): self
71+ {
72+ $ this ->paddingClass = $ cssClass ;
5173
5274 return $ this ;
5375 }
@@ -59,18 +81,24 @@ public function useWrapper(bool $value = true): self
5981 return $ this ;
6082 }
6183
62- public function useAspectRatio (? float $ value = null ): self
84+ public function useAspectRatio (mixed $ value = true ): self
6385 {
64- $ this ->aspectRatio = is_null ($ value ) ? $ this ->main ()->ratio () : $ value ;
86+ if ($ value === true ) {
87+ $ this ->aspectRatio = $ this ->main ()->ratio ();
88+ } elseif ($ value === false ) {
89+ $ this ->aspectRatio = false ;
90+ } else {
91+ $ this ->aspectRatio = $ value ;
92+ }
6593
6694 return $ this ;
6795 }
6896
69- public function usePaddingTop (? float $ value = null ): self
97+ public function usePaddingTop (mixed $ value = true ): self
7098 {
7199 $ this ->useAspectRatio ($ value );
72100
73- $ this ->paddingTop = true ;
101+ $ this ->paddingTop = !! $ value ;
74102
75103 return $ this ;
76104 }
@@ -182,7 +210,7 @@ protected function handleWrapper(string $input): string
182210 $ this ->includeLqip
183211 ? $ this ->htmlTag ('img ' , [
184212 'class ' => $ this ->lqipClass ,
185- 'src ' => $ this ->lqip ()-> url (),
213+ 'src ' => $ this ->lqipUrl (),
186214 ])
187215 : '' ,
188216 ])
0 commit comments