Find all template files in a given directory

@param string $directory Directory to search for templates
426430
private function get_templates($directory) {
		$templates = [];
		foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::LEAVES_ONLY) as $file)
		{
		    if ($file->isFile() === false) {
		        continue;
		    }

			if ($file->getExtension() != 'twig' && $file->getExtension() != 'tpl') {
				continue;
			}

		    $resource = str_replace($directory, '', $file);
		    $templates[] = $resource;
		}

		return $templates;
	}
478914
protected static function isWordPressThemeDirectory( $directory ) {
		$composer = Composer::getComposerJson( $directory );

		if ( ! $composer ) {
			return false;
		}

		if ( $composer['type'] !== 'wordpress-theme' ) {
			return false;
		}

		return true;
	}
607129
public function rm(string $directory): bool {
    if (is_dir($directory)) {
      foreach (new DirectoryIterator(Path::replaceOSSeparator($directory)) as $fileInfo) {
        if (!$fileInfo->isDot()) {
          if ($fileInfo->isDir()) {
            $this->rm($fileInfo->getPathname());
            @rmdir($fileInfo->getPathname());
          } else if ($fileInfo->isFile()) {
            @unlink($fileInfo->getPathname());
          }
        }
      }
      @rmdir($directory);
    }
    return !file_exists($directory);
  }
1014975
public function initialize($template, $directory, $file = 'deploy.php', $params = [])
    {
        if (!isset($this->templates[$template])) {
            throw TemplateNotFoundException::create($template, array_keys($this->templates));
        }

        $this->checkDirectoryBeforeInitialize($directory);
        $this->checkFileBeforeInitialize($directory, $file);

        $filePath = $directory . '/' . $file;

        $this->templates[$template]->initialize($filePath, $params);

        return $filePath;
    }
193258
private function loadPackageTemplate($directory)
    {
        $namespacedPackageClass = $this->packageLoader->loadPackage(realpath($directory));
        $this->autoLoaderManager->mergePackageLoader(realpath($directory));
        $this->package = app($namespacedPackageClass);
    }
1049315
public static function get_template_parts( $directory, $exclude_underscore = false ) {
		if ( ! is_dir( $directory ) ) {
			return;
		}

		$files = static::get_include_files( $directory, $exclude_underscore );

		foreach ( $files['files'] as $file ) {
			$file = realpath( $file );
			$template_name = str_replace( [ trailingslashit( realpath( get_template_directory() ) ), '.php' ], '', $file );
			\get_template_part( $template_name );
		}

		foreach ( $files['directories'] as $directory ) {
			static::get_template_parts( $directory, $exclude_underscore );
		}
	}
986219
private function findInDir($dir, $templateName)
    {
        if (! array_key_exists($dir, $this->dirs)) {
            return false;
        }

        return $this->exists($this->dirs[$dir], $templateName);
    }
356878
public function directories($directory)
    {
        return collect($this->filesystem->directories($directory))
            ->map(function ($file) {
                return new File($file, $this);
            });
    }
766285
protected function _loadTemplate($directory, $filename)
    {
        $adminRoute = Uri::getAdministratorRoute();

        $this->baseurl = rtrim(\JUri::root(), '/\\');

        if (\JFactory::getApplication()->isAdmin()) {
            $this->baseurl .= $adminRoute->getPath();
        }

        $this->baseurl = rtrim($this->baseurl, '/\\');

        return parent::_loadTemplate($directory, $filename);
    }
811822
public function setDirectory($directory)
    {
        $this->directory = $directory . DIRECTORY_SEPARATOR . $this->id;
        if (file_exists($this->directory) === false) {
            mkdir($this->directory, $this->fileMode, true);
        }
    }
635484
public function setDirectory($directory)
	{
		$this->directory = $directory;

		// Set the finder to use this directory as well
		$this->finder->in($directory);

		return $this;
	}
135437
public static function include_files( $directory, $exclude_underscore = false ) {
		if ( ! is_dir( $directory ) ) {
			return;
		}

		$files = static::get_include_files( $directory, $exclude_underscore );

		foreach ( $files['files'] as $file ) {
			include_once( $file );
		}

		foreach ( $files['directories'] as $directory ) {
			static::include_files( $directory, $exclude_underscore );
		}
	}
1022250
private static function getAllYamls(string $directory): \Generator
    {
        /** @var \SplFileInfo $file */
        foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file) {
            if ($file->isFile() && $file->getExtension() === 'yml') {
                $fileName = $file->getPathname();
                yield $fileName => Yaml::parse(file_get_contents($fileName));
            }
        }
    }
596912
public function items($directory)
    {
        $directory = ltrim($directory, "/");

        $iterator = new FilesystemIterator($this->pathRoot.$directory);

        $files = array();

        foreach ($iterator as $file) {
            $files[] = strval($file);
        }
        
        return $files;
    }
831197
public function scanDirectory($directory)
    {
        $extensions = $this->getOption('extensions');

        foreach (scandir($directory) as $object) {
            if ($object === '.' || $object === '..') {
                continue;
            }
            $inputFile = $directory.DIRECTORY_SEPARATOR.$object;
            if (is_dir($inputFile)) {
                foreach ($this->scanDirectory($inputFile) as $file) {
                    yield $file;
                }

                continue;
            }
            if ($this->fileMatchExtensions($object, $extensions)) {
                yield $inputFile;
            }
        }
    }
438907
public function isDirectory($directory)
	{
		$directory = Util::normalizePath($directory);

		return (bool) $this->adapter->isDirectory($directory);
	}
541670
private function isDir($directory)
    {
        if ('/' === $directory) {
            return true;
        }

        if (!@ftp_chdir($this->getConnection(), $directory)) {
            return false;
        }

        // change directory again to return in the base directory
        ftp_chdir($this->getConnection(), $this->directory);

        return true;
    }