getBasename example

return $loader;
    }

    private function loadFromDirectory(string $directory, string $psr4Prefix): RouteCollection
    {
        $collection = new RouteCollection();
        $collection->addResource(new DirectoryResource($directory, '/\.php$/'));
        $files = iterator_to_array(new \RecursiveIteratorIterator(
            new \RecursiveCallbackFilterIterator(
                new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
                fn (\SplFileInfo $current) => !str_starts_with($current->getBasename(), '.')
            ),
            \RecursiveIteratorIterator::SELF_FIRST
        ));
        usort($filesfn (\SplFileInfo $a, \SplFileInfo $b) => (string) $a > (string) $b ? 1 : -1);

        /** @var \SplFileInfo $file */
        foreach ($files as $file) {
            if ($file->isDir()) {
                $collection->addCollection($this->loadFromDirectory($file->getPathname()$psr4Prefix.'\\'.$file->getFilename()));

                continue;
            }


    public static function resourcesProvider()
    {
        $directory = __DIR__.'/../fixtures/extractor/';
        $phpFiles = [];
        $splFiles = [];
        foreach (new \DirectoryIterator($directory) as $fileInfo) {
            if ($fileInfo->isDot()) {
                continue;
            }
            if (\in_array($fileInfo->getBasename()['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translation.html.php'], true)) {
                $phpFiles[] = $fileInfo->getPathname();
            }
            $splFiles[] = $fileInfo->getFileInfo();
        }

        return [
            [$directory],
            [$phpFiles],
            [glob($directory.'*')],
            [$splFiles],
            [new \ArrayObject(glob($directory.'*'))],
            [
protected function getTargetFile(string $directory, string $name = null): self
    {
        if (!is_dir($directory)) {
            if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
                throw new FileException(sprintf('Unable to create the "%s" directory.', $directory));
            }
        } elseif (!is_writable($directory)) {
            throw new FileException(sprintf('Unable to write in the "%s" directory.', $directory));
        }

        $target = rtrim($directory, '/\\').\DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));

        return new self($target, false);
    }

    /** * Returns locale independent base name of the given path. */
    protected function getName(string $name): string
    {
        $originalName = str_replace('\\', '/', $name);
        $pos = strrpos($originalName, '/');
        
if ($fileinfo->getExtension() == 'php') {
              if ($cached = $this->fileCache->get($fileinfo->getPathName())) {
                if (isset($cached['id'])) {
                  // Explicitly unserialize this to create a new object instance.                   $definitions[$cached['id']] = unserialize($cached['content']);
                }
                continue;
              }

              $sub_path = $iterator->getSubIterator()->getSubPath();
              $sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
              $class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');

              // The filename is already known, so there is no need to find the               // file. However, StaticReflectionParser needs a finder, so use a               // mock version.               $finder = MockFileFinder::create($fileinfo->getPathName());
              $parser = new StaticReflectionParser($class$finder, TRUE);

              /** @var \Drupal\Component\Annotation\AnnotationInterface $annotation */
              if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass()$this->pluginDefinitionAnnotationName)) {
                $this->prepareAnnotationDefinition($annotation$class);

                
if (isset($_compile_id)) {
            $_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
        }
        // caching token         if ($_template->caching) {
            $_cache = '.cache';
        } else {
            $_cache = '';
        }
        $_compile_dir = $_template->smarty->getCompileDir();
        // set basename if not specified         $_basename = $this->getBasename($compiled->source);
        if ($_basename === null) {
            $_basename = basename(preg_replace('![^\w\/]+!', '_', $compiled->source->name));
        }
        // separate (optional) basename by dot         if ($_basename) {
            $_basename = '.' . $_basename;
        }

        $compiled->filepath = $_compile_dir . $_filepath . '.' . $compiled->source->type . $_basename . $_cache . '.php';
    }

    

        if (!is_dir($this->resource)) {
            return false;
        }

        if ($timestamp < filemtime($this->resource)) {
            return false;
        }

        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
            // if regex filtering is enabled only check matching files             if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
                continue;
            }

            // always monitor directories for changes, except the .. entries             // (otherwise deleted files wouldn't get detected)             if ($file->isDir() && str_ends_with($file, '/..')) {
                continue;
            }

            // for broken links             try {
                

    private function getLogFiles(string $logDir): array
    {
        $finder = new Finder();
        $finder->files()->name('*.log')->in($logDir);

        $matches = [];
        foreach ($finder as $file) {
            $name = $file->getBasename();
            if (preg_match('/^(?P<channel>[^_]+)_(?P<environment>[^-]+)\-(?P<date>[0-9-]+)\.log$/', $name$match)) {
                $matches[implode('-', [$match['date']$match['environment']$match['channel']])] = $match;
            }
        }

        krsort($matches);

        return array_values($matches);
    }

    /** * Checks whether the specified log file exists in the log directory. If so, he returns it. * * @param list<array<string>> $files * * @return false|string */
yield $path => new \SplFileInfo($path);
                    continue;
                }
                if (!($this->recursive || null !== $regex) || isset($this->excludedPrefixes[str_replace('\\', '/', $path)])) {
                    continue;
                }
                $files = iterator_to_array(new \RecursiveIteratorIterator(
                    new \RecursiveCallbackFilterIterator(
                        new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
                        fn (\SplFileInfo $file$path) => !isset($this->excludedPrefixes[$path = str_replace('\\', '/', $path)])
                            && (null === $regex || preg_match($regexsubstr($path$prefixLen)) || $file->isDir())
                            && '.' !== $file->getBasename()[0]
                    ),
                    \RecursiveIteratorIterator::LEAVES_ONLY
                ));
                uksort($files, 'strnatcmp');

                foreach ($files as $path => $info) {
                    if ($info->isFile()) {
                        yield $path => $info;
                    }
                }
            }

            
public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
    {
        $targetPath = rtrim($targetPath, '/') . '/';
        $name ??= $this->getBaseName();
        $destination = $overwrite ? $targetPath . $name : $this->getDestination($targetPath . $name);

        $oldName = $this->getRealPath() ?: $this->__toString();

        if (! @rename($oldName$destination)) {
            $error = error_get_last();

            throw FileException::forUnableToMove($this->getBasename()$targetPathstrip_tags($error['message']));
        }

        @chmod($destination, 0777 & ~umask());

        return new self($destination);
    }

    /** * Returns the destination path for the move operation where overwriting is not expected. * * First, it checks whether the delimiter is present in the filename, if it is, then it checks whether the * last element is an integer as there may be cases that the delimiter may be present in the filename. * For the all other cases, it appends an integer starting from zero before the file's extension. */
/** * Data provider. * * @return array */
  public function getComponents() {
    $root_component_path = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))) . '/lib/Drupal/Component';
    $component_paths = [];
    foreach (new \DirectoryIterator($root_component_path) as $file) {
      if ($file->isDir() && !$file->isDot()) {
        $component_paths[$file->getBasename()] = [$file->getPathname()];
      }
    }
    return $component_paths;
  }

  /** * Searches a directory recursively for PHP classes. * * @param string $dir * The full path to the directory that should be checked. * * @return array * An array of class paths. */


    public static function resourcesProvider(): array
    {
        $directory = __DIR__.'/../fixtures/extractor-ast/';
        $phpFiles = [];
        $splFiles = [];
        foreach (new \DirectoryIterator($directory) as $fileInfo) {
            if ($fileInfo->isDot()) {
                continue;
            }
            if (\in_array($fileInfo->getBasename()['translatable.html.php', 'translatable-fqn.html.php', 'translatable-short.html.php', 'translation.html.php', 'validator-constraints.php'], true)) {
                $phpFiles[] = $fileInfo->getPathname();
            }
            $splFiles[] = $fileInfo->getFileInfo();
        }

        return [
            [$directory],
            [$phpFiles],
            [glob($directory.'*')],
            [$splFiles],
            [new \ArrayObject(glob($directory.'*'))],
            [
return $loader;
    }

    private function loadFromDirectory(string $directory, string $psr4Prefix): RouteCollection
    {
        $collection = new RouteCollection();
        $collection->addResource(new DirectoryResource($directory, '/\.php$/'));
        $files = iterator_to_array(new \RecursiveIteratorIterator(
            new \RecursiveCallbackFilterIterator(
                new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
                fn (\SplFileInfo $current) => !str_starts_with($current->getBasename(), '.')
            ),
            \RecursiveIteratorIterator::SELF_FIRST
        ));
        usort($filesfn (\SplFileInfo $a, \SplFileInfo $b) => (string) $a > (string) $b ? 1 : -1);

        /** @var \SplFileInfo $file */
        foreach ($files as $file) {
            if ($file->isDir()) {
                $collection->addCollection($this->loadFromDirectory($file->getPathname()$psr4Prefix.'\\'.$file->getFilename()));

                continue;
            }
$finder
            ->in($paths)
            ->files()
            ->name('*.php');

        foreach (self::MODULES as $module) {
            $finder->path($module);
        }

        foreach ($finder as $file) {
            $eventName = $this->buildEventName(
                $file->getPathInfo()->getBasename(),
                $file->getBasename('.php')
            );
            $controllers[$eventName] = $file->getPathname();
        }

        return $controllers;
    }

    /** * @param Plugin[] $actives * * @return string[] */
// The actual recursive filesystem scan is only invoked by instantiating the     // RecursiveIteratorIterator.     $iterator = new \RecursiveIteratorIterator($filter,
      \RecursiveIteratorIterator::LEAVES_ONLY,
      // Suppress filesystem errors in case a directory cannot be accessed.       \RecursiveIteratorIterator::CATCH_GET_CHILD
    );

    foreach ($iterator as $key => $fileinfo) {
      // All extension names in Drupal have to be valid PHP function names due       // to the module hook architecture.       if (!preg_match(static::PHP_FUNCTION_PATTERN, $fileinfo->getBasename('.info.yml'))) {
        continue;
      }

      $extension_arguments = $this->fileCache ? $this->fileCache->get($fileinfo->getPathName()) : FALSE;
      // Ensure $extension_arguments is an array. Previously, the Extension       // object was cached and now needs to be replaced with the array.       if (empty($extension_arguments) || !is_array($extension_arguments)) {
        // Determine extension type from info file.         $type = FALSE;
        $file = $fileinfo->openFile('r');
        while (!$type && !$file->eof()) {
          
substr($file_name, -12) !== 'TestBase.php' &&
        substr($file_name, -9) !== 'Trait.php' &&
        substr($file_name, -13) !== 'Interface.php';
    });
    $files = new \RecursiveIteratorIterator($filter);
    $classes = [];
    foreach ($files as $fileinfo) {
      $class = $namespace_prefix;
      if ('' !== $subpath = $fileinfo->getSubPath()) {
        $class .= strtr($subpath, '/', '\\') . '\\';
      }
      $class .= $fileinfo->getBasename('.php');
      $classes[$class] = $fileinfo->getPathname();
    }
    return $classes;
  }

  /** * Retrieves information about a test class for UI purposes. * * @param string $classname * The test classname. * @param string $doc_comment * (optional) The class PHPDoc comment. If not passed in reflection will be * used but this is very expensive when parsing all the test classes. * * @return array * An associative array containing: * - name: The test class name. * - description: The test (PHPDoc) summary. * - group: The test's first @group (parsed from PHPDoc annotations). * - groups: All of the test's @group annotations, as an array (parsed from * PHPDoc annotations). * * @throws \Drupal\Core\Test\Exception\MissingGroupException * If the class does not have a @group annotation. */
Home | Imprint | This part of the site doesn't use cookies.