From 4864f6031253bf6957bb42d5c9b00ef4dd323f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20L=C3=A9pine?= Date: Fri, 31 Jan 2025 07:55:43 +0100 Subject: [PATCH] Use finder insteadof f* function --- .../ComponentRepository/OfficialRepository.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Toolkit/src/ComponentRepository/OfficialRepository.php b/src/Toolkit/src/ComponentRepository/OfficialRepository.php index 3fb95a3391..8623a34805 100644 --- a/src/Toolkit/src/ComponentRepository/OfficialRepository.php +++ b/src/Toolkit/src/ComponentRepository/OfficialRepository.php @@ -11,6 +11,8 @@ namespace Symfony\Ux\Toolkit\ComponentRepository; +use Symfony\Component\Finder\Finder; + /** * @author Jean-François Lépine * @@ -20,17 +22,16 @@ class OfficialRepository implements ComponentRepository { public function getContent(ComponentIdentity $component): string { - $source = \sprintf(__DIR__.'/../../templates/components/ux/%s.html.twig', $component->getName()); - if (!file_exists($source) || !is_readable($source)) { + $finder = new Finder(); + $finder->files()->in(__DIR__.'/../../templates/components/ux/')->name($component->getName().'.html.twig'); + if (!$finder->hasResults()) { throw new \InvalidArgumentException(\sprintf('The component "%s" does not exist', $component->getName())); } - set_error_handler(function ($errno, $errstr, $errfile, $errline) { - throw new \InvalidArgumentException(\sprintf('Error reading file "%s" at line %d: %s', $errfile, $errline, $errstr)); - }); - $content = file_get_contents($source); - restore_error_handler(); + foreach ($finder as $file) { + return $file->getContents(); + } - return $content; + throw new \InvalidArgumentException(\sprintf('The component "%s" does not exist', $component->getName())); } }