forked from symfony/ux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
535 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent; | ||
|
||
use Symfony\UX\TwigComponent\Attribute\ExposeInTemplate; | ||
|
||
/** | ||
* @author Matheo Daninos <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
final class AnonymousComponent | ||
{ | ||
private array $props; | ||
|
||
public function mount($props = []): void | ||
{ | ||
$this->props = $props; | ||
} | ||
|
||
#[ExposeInTemplate(destruct: true)] | ||
public function getProps(): array | ||
{ | ||
return $this->props; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent; | ||
|
||
use Twig\Environment; | ||
|
||
/** | ||
* @author Matheo Daninos <[email protected]> | ||
*/ | ||
final class ComponentTemplateFinder implements ComponentTemplateFinderInterface | ||
{ | ||
public function __construct( | ||
private Environment $environment | ||
) { | ||
} | ||
|
||
public function findAnonymousComponentTemplate(string $name): ?string | ||
{ | ||
$loader = $this->environment->getLoader(); | ||
$componentPath = rtrim(str_replace(':', '/', $name)); | ||
|
||
if ($loader->exists('components/'.$componentPath.'.html.twig')) { | ||
return 'components/'.$componentPath.'.html.twig'; | ||
} | ||
|
||
if ($loader->exists($componentPath.'.html.twig')) { | ||
return $componentPath.'.html.twig'; | ||
} | ||
|
||
if ($loader->exists('components/'.$componentPath)) { | ||
return 'components/'.$componentPath; | ||
} | ||
|
||
if ($loader->exists($componentPath)) { | ||
return $componentPath; | ||
} | ||
|
||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/TwigComponent/src/ComponentTemplateFinderInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent; | ||
|
||
/** | ||
* @author Matheo Daninos <[email protected]> | ||
*/ | ||
interface ComponentTemplateFinderInterface | ||
{ | ||
public function findAnonymousComponentTemplate(string $name): ?string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\TwigComponent\Twig; | ||
|
||
use Twig\Compiler; | ||
use Twig\Node\Node; | ||
|
||
/** | ||
* @author Matheo Daninos <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class PropsNode extends Node | ||
{ | ||
public function __construct(array $propsNames, array $values, $lineno = 0, string $tag = null) | ||
{ | ||
parent::__construct($values, ['names' => $propsNames], $lineno, $tag); | ||
} | ||
|
||
public function compile(Compiler $compiler): void | ||
{ | ||
foreach ($this->getAttribute('names') as $name) { | ||
$compiler | ||
->addDebugInfo($this) | ||
->write('if (!isset($context[\''.$name.'\'])) {') | ||
; | ||
|
||
if (!$this->hasNode($name)) { | ||
$compiler | ||
->write('throw new \Twig\Error\RuntimeError("'.$name.' should be defined for component '.$this->getTemplateName().'");') | ||
->write('}') | ||
; | ||
|
||
continue; | ||
} | ||
|
||
$compiler | ||
->write('$context[\''.$name.'\'] = ') | ||
->subcompile($this->getNode($name)) | ||
->raw(";\n") | ||
->write('}') | ||
; | ||
} | ||
} | ||
} |
Oops, something went wrong.