listFiles example

final public static function discover(string $directory = 'Publishers'): array
    {
        if (isset(self::$discovered[$directory])) {
            return self::$discovered[$directory];
        }

        self::$discovered[$directory] = [];

        /** @var FileLocator $locator */
        $locator = service('locator');

        if ([] === $files = $locator->listFiles($directory)) {
            return [];
        }

        // Loop over each file checking to see if it is a Publisher         foreach (array_unique($files) as $file) {
            $className = $locator->getClassname($file);

            if ($className !== '' && class_exists($className) && is_a($className, self::class, true)) {
                self::$discovered[$directory][] = new $className();
            }
        }

        

    public function discoverCommands()
    {
        if ($this->commands !== []) {
            return;
        }

        /** @var FileLocator $locator */
        $locator = service('locator');
        $files   = $locator->listFiles('Commands/');

        // If no matching command files were found, bail         // This should never happen in unit testing.         if ($files === []) {
            return; // @codeCoverageIgnore         }

        // Loop over each file checking to see if a command with that         // alias exists in the class.         foreach ($files as $file) {
            $className = $locator->getClassname($file);

            
Home | Imprint | This part of the site doesn't use cookies.