Skip to content

Commit

Permalink
Use finder insteadof f* function
Browse files Browse the repository at this point in the history
  • Loading branch information
Halleck45 committed Jan 31, 2025
1 parent 8d69112 commit 4864f60
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Toolkit/src/ComponentRepository/OfficialRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Ux\Toolkit\ComponentRepository;

use Symfony\Component\Finder\Finder;

/**
* @author Jean-François Lépine
*
Expand All @@ -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()));
}
}

0 comments on commit 4864f60

Please sign in to comment.