locateResource example


                $this->kernel->boot();
            }

            public function shutdown(): void
            {
                $this->kernel->shutdown();
            }

            public function locateResource(string $name): string
            {
                return $this->kernel->locateResource(...\func_get_args());
            }

            public function getEnvironment(): string
            {
                return $this->kernel->getEnvironment();
            }

            public function isDebug(): bool
            {
                return $this->kernel->isDebug();
            }

            
public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;

        parent::__construct();
    }

    public function locate(string $file, string $currentPath = null, bool $first = true): string|array
    {
        if (isset($file[0]) && '@' === $file[0]) {
            $resource = $this->kernel->locateResource($file);

            return $first ? $resource : [$resource];
        }

        return parent::locate($file$currentPath$first);
    }
}

        $env = 'test_env';
        $debug = true;
        $kernel = new KernelForTest($env$debug);
        $expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}";
        $this->assertEquals($expectedserialize($kernel));
    }

    public function testLocateResourceThrowsExceptionWhenNameIsNotValid()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->getKernel()->locateResource('Foo');
    }

    public function testLocateResourceThrowsExceptionWhenNameIsUnsafe()
    {
        $this->expectException(\RuntimeException::class);
        $this->getKernel()->locateResource('@FooBundle/../bar');
    }

    public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        
EOF
            )
        ;
    }

    protected function findFiles(string $filename): iterable
    {
        if (str_starts_with($filename, '@')) {
            $filename = $this->getApplication()->getKernel()->locateResource($filename);
        }

        return parent::findFiles($filename);
    }
}
public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;

        parent::__construct();
    }

    public function locate(string $file, string $currentPath = null, bool $first = true): string|array
    {
        if (isset($file[0]) && '@' === $file[0]) {
            $resource = $this->kernel->locateResource($file);

            return $first ? $resource : [$resource];
        }

        return parent::locate($file$currentPath$first);
    }
}

#[AsCommand(name: 'lint:xliff', description: 'Lints an XLIFF file and outputs encountered errors')] class XliffLintCommand extends BaseLintCommand
{
    public function __construct()
    {
        $directoryIteratorProvider = function D$directory$default) {
            if (!is_dir($directory)) {
                $directory = $this->getApplication()->getKernel()->locateResource($directory);
            }

            return $default($directory);
        };

        $isReadableProvider = fn ($fileOrDirectory$default) => str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);

        parent::__construct(null, $directoryIteratorProvider$isReadableProvider);
    }

    protected function configure(): void
    {

#[AsCommand(name: 'lint:yaml', description: 'Lint a YAML file and outputs encountered errors')] class YamlLintCommand extends BaseLintCommand
{
    public function __construct()
    {
        $directoryIteratorProvider = function D$directory$default) {
            if (!is_dir($directory)) {
                $directory = $this->getApplication()->getKernel()->locateResource($directory);
            }

            return $default($directory);
        };

        $isReadableProvider = fn ($fileOrDirectory$default) => str_starts_with($fileOrDirectory, '@') || $default($fileOrDirectory);

        parent::__construct(null, $directoryIteratorProvider$isReadableProvider);
    }

    protected function configure(): void
    {
Home | Imprint | This part of the site doesn't use cookies.