22
33namespace Contributte \ImageStorage \Latte ;
44
5+ use Contributte \ImageStorage \ImageStorage ;
56use Latte \Compiler \Node ;
67use Latte \Compiler \Nodes \AuxiliaryNode ;
78use Latte \Compiler \PrintContext ;
1112class LatteExtension extends Extension
1213{
1314
15+ public function __construct (protected readonly ImageStorage $ imageStorage )
16+ {
17+ }
18+
1419 /**
1520 * @return array<mixed>
1621 */
@@ -32,7 +37,7 @@ public function tagImg(Tag $tag): Node
3237 $ args = $ tag ->parser ->parseArguments ();
3338
3439 return new AuxiliaryNode (
35- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo "<img src=\"" . $basePath . "/" . $_img->createLink() . "\">"; ' , $ args )
40+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo "<img src=\"" . $basePath . "/" . $_img->createLink() . "\">"; ' , $ args )
3641 );
3742 }
3843
@@ -41,7 +46,7 @@ public function tagImgAbs(Tag $tag): Node
4146 $ args = $ tag ->parser ->parseArguments ();
4247
4348 return new AuxiliaryNode (
44- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo "<img src=\"" . $baseUrl . "/" . $_img->createLink() . "\">"; ' , $ args )
49+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo "<img src=\"" . $baseUrl . "/" . $_img->createLink() . "\">"; ' , $ args )
4550 );
4651 }
4752
@@ -50,7 +55,7 @@ public function attrImg(Tag $tag): Node
5055 $ args = $ tag ->parser ->parseArguments ();
5156
5257 return new AuxiliaryNode (
53- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo \' src=" \' . $basePath . "/" . $_img->createLink() . \'" \'; ' , $ args )
58+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo \' src=" \' . $basePath . "/" . $_img->createLink() . \'" \'; ' , $ args )
5459 );
5560 }
5661
@@ -59,7 +64,7 @@ public function attrImgAbs(Tag $tag): Node
5964 $ args = $ tag ->parser ->parseArguments ();
6065
6166 return new AuxiliaryNode (
62- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo \' src=" \' . $baseUrl . "/" . $_img->createLink() . \'" \'; ' , $ args )
67+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo \' src=" \' . $baseUrl . "/" . $_img->createLink() . \'" \'; ' , $ args )
6368 );
6469 }
6570
@@ -68,7 +73,7 @@ public function linkImg(Tag $tag): Node
6873 $ args = $ tag ->parser ->parseArguments ();
6974
7075 return new AuxiliaryNode (
71- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo $basePath . "/" . $_img->createLink(); ' , $ args )
76+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo $basePath . "/" . $_img->createLink(); ' , $ args )
7277 );
7378 }
7479
@@ -77,8 +82,15 @@ public function linkImgAbs(Tag $tag): Node
7782 $ args = $ tag ->parser ->parseArguments ();
7883
7984 return new AuxiliaryNode (
80- fn (PrintContext $ context ) => $ context ->format ('$_img = $imageStorage->fromIdentifier(%node); echo $baseUrl . "/" . $_img->createLink(); ' , $ args )
85+ fn (PrintContext $ context ) => $ context ->format ('$_img = $this->global-> imageStorage->fromIdentifier(%node); echo $baseUrl . "/" . $_img->createLink(); ' , $ args )
8186 );
8287 }
8388
89+ public function getProviders (): array
90+ {
91+ return [
92+ 'imageStorage ' => $ this ->imageStorage , // Register the provider
93+ ];
94+ }
95+
8496}
0 commit comments