Finder example


    public function getScriptPathsForApp(string $appPath): array
    {
        $scriptDirectory = $this->appLoader->locatePath($appPath, self::SCRIPT_DIR);

        if ($scriptDirectory === null || !is_dir($scriptDirectory)) {
            return [];
        }

        $finder = new Finder();
        $finder->files()
            ->in($scriptDirectory)
            ->exclude('rule-conditions')
            ->name(self::ALLOWED_FILE_EXTENSIONS)
            ->ignoreUnreadableDirs();

        return array_values(array_map(static fn (\SplFileInfo $file): string => ltrim(mb_substr($file->getPathname()mb_strlen($scriptDirectory)), '/')iterator_to_array($finder)));
    }

    /** * Returns the content of the script */


        static::assertEquals($expectedDe$actualDe);
        static::assertEquals($expectedEn$actualEn);
    }

    /** * @return array<string> */
    private function getSnippetFilePathsOfFixtures(string $folder, string $namePattern): array
    {
        $finder = (new Finder())
            ->files()
            ->in(__DIR__ . '/fixtures/' . $folder . '/')
            ->ignoreUnreadableDirs()
            ->name($namePattern);

        $iterator = $finder->getIterator();

        $files = [];
        foreach ($iterator as $file) {
            $files[] = $file->getRealPath();
        }

        
'reason' => $item['error']['reason'] ?? $item['result'],
            ];

            $this->logger->error($item['error']['reason'] ?? $item['result']);
        }

        return $errors;
    }

    private function createScripts(): void
    {
        $finder = (new Finder())
            ->files()
            ->in(__DIR__ . '/Scripts')
            ->name('*.groovy');

        foreach ($finder as $file) {
            $name = pathinfo($file->getFilename(), \PATHINFO_FILENAME);

            $this->client->putScript([
                'id' => $name,
                'body' => [
                    'script' => [
                        
$this->cleanupOldContainerCacheDirectories();
    }

    public function clearContainerCache(): void
    {
        if ($this->clusterMode) {
            // In cluster mode we can't delete caches on the filesystem             // because this only runs on one node in the cluster             return;
        }

        $finder = (new Finder())->in($this->cacheDir)->name('*Container*')->depth(0);
        $containerCaches = [];

        foreach ($finder->getIterator() as $containerPaths) {
            $containerCaches[] = $containerPaths->getRealPath();
        }

        $this->filesystem->remove($containerCaches);
    }

    public function scheduleCacheFolderCleanup(): void
    {
        
/** * Find all the composer.json files for components. * * @param string $drupal_root * The Drupal root directory. * * @return \Symfony\Component\Finder\Finder * A Finder object with all the composer.json files for components. */
  protected function getComponentPathsFinder(string $drupal_root): Finder {
    $finder = new Finder();
    $finder->name('composer.json')
      ->in($drupal_root . static::$componentsPath)
      ->ignoreUnreadableDirs()
      ->depth(1);

    return $finder;
  }

}


    /** * @return Manifest[] */
    private function getManifestsFromDir(string $dir): array
    {
        if (!file_exists($dir)) {
            throw new ManifestNotFoundException($dir);
        }

        $finder = new Finder();
        $finder->in($dir)
            ->depth('<= 1')
            ->name('manifest.xml');

        $manifests = [];
        foreach ($finder->files() as $xml) {
            $manifests[] = Manifest::createFromXmlFile($xml->getPathname());
        }

        if (\count($manifests) === 0) {
            throw new ManifestNotFoundException($dir);
        }
true,
            new StaticKernelPluginLoader(KernelLifecycleManager::getClassLoader()),
            Uuid::randomHex(),
            '1.1.1',
            $this->getContainer()->get(Connection::class)
        );

        $newTestKernel->boot();
        $cacheDir = $newTestKernel->getCacheDir();
        $newTestKernel->shutdown();

        $finder = (new Finder())->in($cacheDir)->directories()->name('Container*');
        $containerCaches = [];

        foreach ($finder->getIterator() as $containerPaths) {
            $containerCaches[] = $containerPaths->getRealPath();
        }

        static::assertCount(1, $containerCaches);

        $filesystem = $this->getContainer()->get('filesystem');
        $cacheClearer = new CacheClearer(
            [],
            
/** * Clear directory contents */
    private function clearDirectory(string $dir): void
    {
        if (!file_exists($dir)) {
            return;
        }

        $fileSystem = new Filesystem();
        $finder = new Finder();

        $tempFileExtension = 'sw_bak';
        $tempFileName = sprintf('%s_%s.%s', $diruniqid()$tempFileExtension);

        // Move the existing cache to a temporary new location prior to deletion, so it won't be written to in the meantime         $fileSystem->rename($dir$tempFileName);

        $finder->directories()
            ->in(\dirname($dir, 1))
            ->name(sprintf('*.%s', $tempFileExtension));

        

        return ($realPath ? $this->getUpgradeDir() . '/' : '') . \sprintf('UPGRADE-%s.md', $this->getNextMajorVersion($version));
    }

    /** * Prepare the list of changelog files which need to process */
    protected function prepareChangelogFiles(?string $version = null, bool $includeFeatureFlags = false): ChangelogFileCollection
    {
        $entries = new ChangelogFileCollection();

        $finder = new Finder();
        $finder->in($version ? $this->getTargetReleaseDir($version) : $this->getUnreleasedDir())->files()->sortByName()->depth('0')->name('*.md');
        if ($finder->hasResults()) {
            foreach ($finder as $file) {
                $definition = $this->parser->parse($file->getContents());

                $issues = $this->validator->validate($definition);
                if ($issues->count()) {
                    $messages = \array_map(static fn (ConstraintViolationInterface $violation) => $violation->getMessage(), \iterator_to_array($issues));

                    throw new \InvalidArgumentException(\sprintf('Invalid file at path: %s, errors: %s', $file->getRealPath(), \implode(', ', $messages)));
                }

                
private const TEMPLATE_FILE = __DIR__ . '/../../../Resources/templates/coverage-by-area-report.html.twig';

    public function __construct(
        private readonly string $projectDir,
        private readonly Environment $twig
    ) {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $finder = new Finder();

        $phpCoveragePerArea = [];
        $jsCoveragePerArea = [];

        foreach ($finder->in($this->projectDir . '/coverage/php')->depth(0)->directories() as $dir) {
            // We need to create a new Instance of Finder every time, because Symfony Finder doesn't reset it's internal state             $finder = new Finder();
            $xmlFiles = $finder->in($dir->getRealPath())->files()->name('cobertura.xml')->getIterator();
            $xmlFiles->rewind();
            $xml = new Crawler(file_get_contents($xmlFiles->current()->getRealPath()) ?: '');
            $phpCoveragePerArea[$dir->getFilename()] = $xml;
        }
private ?AnnotationTagTester $deprecationTagTester = null;

    protected function setUp(): void
    {
        $this->rootDir = $this->getPathForClass(Kernel::class);
        $this->manifestRoot = $this->getPathForClass(Manifest::class);
    }

    public function testSourceFilesForWrongDeprecatedAnnotations(): void
    {
        $finder = new Finder();
        $finder->in($this->rootDir)
            ->files()
            ->name('*.php')
            ->name('*.js')
            ->name('*.scss')
            ->name('*.html.twig')
            ->name('*.xsd')
            ->exclude('node_modules')
            ->contains(['@deprecated', '@experimental']);

        foreach ($this->whiteList as $path) {
            
return $basePath . \DIRECTORY_SEPARATOR . $path;
    }

    /** * @return array<int, string> */
    private function getFilesInDir(string $path): array
    {
        if (!is_dir($path)) {
            return [];
        }
        $finder = new Finder();
        $finder->files()->in($path);

        $files = [];
        foreach ($finder as $file) {
            $files[] = $this->stripProjectDir($file->getPathname());
        }

        return $files;
    }

    /** * @return array<int, string> */
$errors[] = $serviceId . ':' . $t->getMessage();
            }
        }

        static::assertCount(0, $errors, 'Found invalid services: ' . print_r($errors, true));
    }

    public function testServiceDefinitionNaming(): void
    {
        $basePath = __DIR__ . '/../../../';

        $xmlFiles = (new Finder())->in($basePath)->files()->path('~DependencyInjection/[^/]+\.xml$~')->getIterator();

        $errors = [];
        foreach ($xmlFiles as $file) {
            $content = $file->getContents();

            $parameterErrors = $this->checkServiceParameterOrder($content);
            $argumentErrors = $this->checkArgumentOrder($content);

            $errors[$file->getRelativePathname()] = array_merge($parameterErrors$argumentErrors);
        }

        
$snippetFile->setTechnicalName($app['name']);
                $snippetFileCollection->add($snippetFile);
            }
        }
    }

    /** * @return AbstractSnippetFile[] */
    private function loadSnippetFilesInDir(string $snippetDir, Bundle $bundle): array
    {
        $finder = new Finder();
        $finder->in($snippetDir)
            ->files()
            ->name('*.json');

        try {
            /** @var array<string, string> $authors */
            $authors = $this->connection->fetchAllKeyValue(' SELECT `base_class` AS `baseClass`, `author` FROM `plugin` ');
        } catch (Exception) {
            


        $localeRepository = $this->em->getRepository('Shopware\Models\Shop\Locale');

        $inputAdapter = new Enlight_Config_Adapter_File([
            'configDir' => $snippetsDir,
        ]);

        $databaseWriter = new DatabaseWriter($this->em->getConnection());
        $databaseWriter->setForce($force);

        $finder = new Finder();
        $finder->files()->in($snippetsDir);
        $defaultLocale = $localeRepository->findOneBy(['locale' => 'en_GB']);

        $snippetCount = $this->em->getConnection()->fetchArray('SELECT * FROM s_core_snippets LIMIT 1');
        $databaseWriter->setUpdate((bool) $snippetCount);

        foreach ($finder as $file) {
            $filePath = $file->getRelativePathname();
            if (strpos($filePath, '.ini') == \strlen($filePath) - 4) {
                $namespace = substr($filePath, 0, -4);
                $namespace = str_replace('\\', '/', $namespace);
            }
Home | Imprint | This part of the site doesn't use cookies.