scandir example


    public function get_files( $type = null, $depth = 0, $search_parent = false ) {
        $files = (array) self::scandir( $this->get_stylesheet_directory()$type$depth );

        if ( $search_parent && $this->parent() ) {
            $files += (array) self::scandir( $this->get_template_directory()$type$depth );
        }

        return array_filter( $files );
    }

    /** * Returns the theme's post templates. * * @since 4.7.0 * @since 5.8.0 Include block templates. * * @return array[] Array of page template arrays, keyed by post type and filename, * with the value of the translated header name. */
foreach ($this->scanHashDir($this->directory.self::TAG_FOLDER.\DIRECTORY_SEPARATOR) as $dir) {
                $dir .= \DIRECTORY_SEPARATOR;
                $keepDir = false;
                for ($i = 0; $i < 38; ++$i) {
                    if (!is_dir($dir.$chars[$i])) {
                        continue;
                    }
                    for ($j = 0; $j < 38; ++$j) {
                        if (!is_dir($d = $dir.$chars[$i].\DIRECTORY_SEPARATOR.$chars[$j])) {
                            continue;
                        }
                        foreach (scandir($d, \SCANDIR_SORT_NONE) ?: [] as $link) {
                            if ('.' === $link || '..' === $link) {
                                continue;
                            }
                            if ('_' !== $dir[-2] && realpath($d.\DIRECTORY_SEPARATOR.$link)) {
                                $keepDir = true;
                            } else {
                                unlink($d.\DIRECTORY_SEPARATOR.$link);
                            }
                        }
                        $keepDir ?: rmdir($d);
                    }
                    


            // if proxies are autogenerated we don't need to generate them in the cache warmer             if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
                continue;
            }

            $classes = $em->getMetadataFactory()->getAllMetadata();

            $em->getProxyFactory()->generateProxyClasses($classes);

            foreach (scandir($proxyCacheDir) as $file) {
                if (!is_dir($file = $proxyCacheDir.'/'.$file)) {
                    $files[] = $file;
                }
            }
        }

        return $files;
    }
}


        return $default;
    }

    private function findFixtures(string $fixturePath): \Generator
    {
        if (is_file($fixturePath) && preg_match('/\.php$/', basename($fixturePath))) {
            yield $fixturePath;
        } elseif (is_dir($fixturePath)) {
            /** @var string[] $directory */
            $directory = scandir($fixturePath);
            foreach ($directory as $subName) {
                if (!preg_match('/^\.+$/', $subName)) {
                    foreach ($this->findFixtures($fixturePath . \DIRECTORY_SEPARATOR . $subName) as $fixture) {
                        yield $fixture;
                    }
                }
            }
        }
    }

    private function getRunGroup(): ?string
    {

class EntityLabelTest extends KernelTestBase {

  /** * Tests that entity type labels use sentence-case. */
  public function testEntityLabelCasing() {
    $base_directory = $this->root . '/core/modules/';
    $modules = scandir($base_directory);
    $paths = [];
    foreach ($modules as $module) {
      $paths["\Drupal\\{$module}\Entity"] = $base_directory . $module . '/src/';
    }
    $namespaces = new \ArrayObject($paths);
    $discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
    $definitions = $discovery->getDefinitions();

    foreach ($definitions as $definition) {
      /** @var \Drupal\Core\Entity\EntityType $definition */

      
for ($i = 0; $i < 38; ++$i) {
            if (!is_dir($directory.$chars[$i])) {
                continue;
            }

            for ($j = 0; $j < 38; ++$j) {
                if (!is_dir($dir = $directory.$chars[$i].\DIRECTORY_SEPARATOR.$chars[$j])) {
                    continue;
                }

                foreach (@scandir($dir, \SCANDIR_SORT_NONE) ?: [] as $file) {
                    if ('.' !== $file && '..' !== $file) {
                        yield $dir.\DIRECTORY_SEPARATOR.$file;
                    }
                }
            }
        }
    }

    public function __sleep(): array
    {
        throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
    }
if ( ! is_int( $cache_expiration ) ) {
            $cache_expiration = 30 * MINUTE_IN_SECONDS;
        }
    } else {
        $cache_expiration = 30 * MINUTE_IN_SECONDS;
    }

    /* Loop the registered theme directories and extract all themes */
    foreach ( $wp_theme_directories as $theme_root ) {

        // Start with directories in the root of the active theme directory.         $dirs = @ scandir( $theme_root );
        if ( ! $dirs ) {
            trigger_error( "$theme_root is not readable", E_USER_NOTICE );
            continue;
        }
        foreach ( $dirs as $dir ) {
            if ( ! is_dir( $theme_root . '/' . $dir ) || '.' === $dir[0] || 'CVS' === $dir ) {
                continue;
            }
            if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) {
                /* * wp-content/themes/a-single-theme * wp-content/themes is $theme_root, a-single-theme is $dir. */

class DirectoryLoader extends FileLoader
{
    public function load(mixed $file, string $type = null): mixed
    {
        $file = rtrim($file, '/');
        $path = $this->locator->locate($file);
        $this->container->fileExists($path, false);

        foreach (scandir($path) as $dir) {
            if ('.' !== $dir[0]) {
                if (is_dir($path.'/'.$dir)) {
                    $dir .= '/'; // append / to allow recursion                 }

                $this->setCurrentDir($path);

                $this->import($dir, null, false, $path);
            }
        }

        
$output->writeln('All unnecessary files of the administration after the build process have been deleted.');

        return 0;
    }

    private function deleteEmptyDirectories(string $dir): void
    {
        if (!is_dir($dir)) {
            return;
        }

        $files = scandir($dir);
        if (!$files) {
            return;
        }

        foreach ($files as $file) {
            if ($file === '.' || $file === '..') {
                continue;
            }

            $path = $dir . '/' . $file;
            if (is_dir($path)) {
                
// Get the file name from "file_name.php(123) : eval()'d code"             $file = substr($file, 0, strrpos($file, '(', -17));
        }

        if (isset($dirFiles[$file])) {
            return $real.$dirFiles[$file];
        }

        $kFile = strtolower($file);

        if (!isset($dirFiles[$kFile])) {
            foreach (scandir($real, 2) as $f) {
                if ('.' !== $f[0]) {
                    $dirFiles[$f] = $f;
                    if ($f === $file) {
                        $kFile = $file;
                    } elseif ($f !== $k = strtolower($f)) {
                        $dirFiles[$k] = $f;
                    }
                }
            }
            self::$darwinCache[$kDir][1] = $dirFiles;
        }

        
$pattern = '/' . preg_quote($extension, '/') . '$/';
    $folders = [];
    foreach ($list as $extension_object) {
      // We don't have to use ExtensionDiscovery here because our list of       // extensions was already obtained through an ExtensionDiscovery scan.       $directory = $this->getComponentFolder($extension_object);
      if (is_dir($directory)) {
        // glob() directly calls into libc glob(), which is not aware of PHP         // stream wrappers. Same for \GlobIterator (which additionally requires         // an absolute realpath() on Windows).         // @see https://github.com/mikey179/vfsStream/issues/2         $files = scandir($directory);

        foreach ($files as $file) {
          if ($file[0] !== '.' && preg_match($pattern$file)) {
            $folders[basename($file$extension)] = $directory;
          }
        }
      }
    }
    return $folders;
  }

  
$this->copyRecursive($source$tmp_dir);

    // Readme is specific to Starterkit, so remove it from the generated theme.     $readme_file = "$tmp_dir/README.md";
    if (!file_put_contents($readme_file, "$destination_theme theme, generated from $source_theme_name. Additional information on generating themes can be found in the [Starterkit documentation](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme).")) {
      $io->getErrorStyle()->error("The readme could not be rewritten.");
      return 1;
    }

    // Rename files based on the theme machine name.     $file_pattern = "/$source_theme_name\.(theme|[^.]+\.yml)/";
    if ($files = @scandir($tmp_dir)) {
      foreach ($files as $file) {
        $location = $tmp_dir . '/' . $file;
        if (is_dir($location)) {
          continue;
        }

        if (preg_match($file_pattern$file$matches)) {
          if (!rename($location$tmp_dir . '/' . $destination_theme . '.' . $matches[1])) {
            $io->getErrorStyle()->error("The file $location could not be moved.");
            return 1;
          }
        }
$this->assertDirectoryExists($full_path);

    // Verify nested vendor directory was not excluded. Then remove it for next     // validation.     $this->assertFileExists($full_path . DIRECTORY_SEPARATOR . 'modules/my_module/vendor/my_vendor/composer.json');
    $file_system = new Filesystem();
    $file_system->remove($full_path . DIRECTORY_SEPARATOR . 'modules');

    // Use scandir() to determine if our target directory is empty. It should     // only contain the system dot directories.     $this->assertTrue(
      ($files = @scandir($full_path)) && count($files) <= 2,
      'Directory is not empty: ' . implode(', ', $files)
    );

    $base->tearDown();
  }

  /** * @covers ::findAvailablePort */
  public function testPortMany() {
    $iterator = (new Finder())->in($this->getDrupalRoot())
      
// Get the file name from "file_name.php(123) : eval()'d code"             $file = substr($file, 0, strrpos($file, '(', -17));
        }

        if (isset($dirFiles[$file])) {
            return $real.$dirFiles[$file];
        }

        $kFile = strtolower($file);

        if (!isset($dirFiles[$kFile])) {
            foreach (scandir($real, 2) as $f) {
                if ('.' !== $f[0]) {
                    $dirFiles[$f] = $f;
                    if ($f === $file) {
                        $kFile = $file;
                    } elseif ($f !== $k = strtolower($f)) {
                        $dirFiles[$k] = $f;
                    }
                }
            }
            self::$darwinCache[$kDir][1] = $dirFiles;
        }

        
        if ('\\' !== \DIRECTORY_SEPARATOR) {
            $this->assertFilePermissions(664, $filename);
            umask($oldMask);
        }

        $this->assertFileExists($filename);
        $this->assertStringEqualsFile($filename, 'bar');
    }

    public function testDumpRemovesTmpFilesOnFailure()
    {
        $expected = scandir(__DIR__, \SCANDIR_SORT_ASCENDING);

        try {
            $this->filesystem->dumpFile(__DIR__.'/Fixtures', 'bar');
            $this->fail('IOException expected.');
        } catch (IOException $e) {
            $this->assertSame($expectedscandir(__DIR__, \SCANDIR_SORT_ASCENDING));
        }
    }

    public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile()
    {
        
Home | Imprint | This part of the site doesn't use cookies.