Add all assets matching $pattern within $directory.

@param  string $directory Relative to $this->public_dir
@param  string $pattern (regex)
@return Manager
773069
public function addDir($directory, $pattern = null)
	{
		// Make sure directory exists
		$absolute_path = realpath($this->public_dir . DIRECTORY_SEPARATOR . $directory);
		if($absolute_path === false)
			return $this;

		// By default match all assets
		if(is_null($pattern))
			$pattern = $this->asset_regex;

		// Get assets files
		$files = $this->rglob($absolute_path, $pattern, $this->public_dir);

		// No luck? Nothing to do
		if( ! $files)
			return $this;

		// Avoid polling if the pattern is our old friend JavaScript
		if($pattern === $this->js_regex)
			$this->js = array_unique(array_merge($this->js, $files));

		// Avoid polling if the pattern is our old friend CSS
		elseif($pattern === $this->css_regex)
			$this->css = array_unique(array_merge($this->css, $files));

		// Unknown pattern. We must poll to know the asset type :(
		else
		{
			foreach($files as $asset)
			{
				if(preg_match($this->js_regex, $asset))
					$this->js[] = $asset;

				elseif(preg_match($this->css_regex, $asset))
					$this->css[] = $asset;
			}
			$this->js = array_unique($this->js);
			$this->css = array_unique($this->css);
		}

		return $this;
	}
285654
protected static function addPatterns(IgnoreManager $manager, $patterns)
    {
        $enabled = false === $patterns ? false : true;
        $manager->setEnabled($enabled);

        if (\is_array($patterns)) {
            foreach ($patterns as $pattern) {
                $manager->addPattern($pattern);
            }
        }
    }
424995
public function registerModuleDirectory($directory, $excludePattern = '/\/tests\//')
    {
        if (!isset($this->moduleDirectories[$directory])) {
            $this->moduleDirectories[$directory] = $excludePattern;
            
            return true;
        }
        
        return false;
    }
198756
public static function getFileList( $path, $pattern = NULL )
	{
		$index	= new FS_Folder_RecursiveLister( $path );
		$index->setPattern( $pattern );
		$index->showFiles( TRUE );
		$index->showFolders( FALSE );
		return $index->getList();
	}
67642
static function unlinkWildcard( $dir, $pattern )
    {
        $availableFiles = array();
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $file = readdir( $handle ) ) !== false )
            {
                if ( $file != "." && $file != ".." )
                {
                    $availableFiles[] = $file;
                }
            }
            @closedir( $handle );

            if( strpos( $pattern, "." ) )
            {
                $baseexp = substr( $pattern, 0, strpos( $pattern, "." ) );
                $typeexp = substr( $pattern, ( strpos( $pattern, "." ) + 1 ), strlen( $pattern ) );
            }
            else
            {
                $baseexp = $pattern;
                $typeexp = "";
            }

            $baseexp=preg_quote( $baseexp );
            $typeexp=preg_quote( $typeexp );

            $baseexp = str_replace( array( "\*", "\?" ), array( ".*", "." ), $baseexp );
            $typeexp = str_replace(array( "\*", "\?" ), array( ".*", "." ), $typeexp );

            $i=0;
            $matchedFileArray = array();
            foreach( $availableFiles as $file )
            {
                $fileName = basename( $file );

                if( strpos( $fileName, "." ) )
                {
                    $base = substr( $fileName, 0, strpos( $fileName, "."));
                    $type = substr( $fileName, ( strpos( $fileName,"." ) + 1 ), strlen( $fileName ) );
                }
                else
                {
                    $base = $fileName;
                    $type = "";
                }

                if( preg_match( "/^".$baseexp."$/i", $base ) && preg_match( "/^".$typeexp."$/i", $type ) )
                {
                    $matchedFileArray[$i] = $file;
                    $i++;
                }
            }

            foreach ( array_keys( $matchedFileArray ) as $key )
            {
                $matchedFile =& $matchedFileArray[$key];
                if ( substr( $dir,-1 ) == "/")
                {
                    unlink( $dir.$matchedFile );
                }
                else
                {
                    unlink( $dir."/".$matchedFile );
                }
            }
        }
    }
783692
protected function replacePattern($pattern) {
    $replace = array(
      '$DIR' => dirname($this->configFile),
      '$CWD' => getcwd(),
    );
    return str_replace(array_keys($replace), array_values($replace), $pattern);
  }
929902
public function buildFromDirectory($dir, $regex = null)
    {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator(
                $dir,
                FilesystemIterator::KEY_AS_PATHNAME
                | FilesystemIterator::CURRENT_AS_FILEINFO
                | FilesystemIterator::SKIP_DOTS
            )
        );

        if ($regex) {
            $iterator = new RegexIterator($iterator, $regex);
        }

        $this->buildFromIterator($iterator, $dir);
    }
76219
private File searchFile(File directory, String pattern) {
        if (!directory.isDirectory()) {
            throw new IllegalArgumentException("Not a directly: "+directory);
        }
        File[] files = directory.listFiles();
        assert files != null; //checked for directly above.
        for (File file : files) {
            if (file.getName().matches(pattern)) return file;
        }
        return null;
    }
585246
private function replaceDummy($directory)
    {
        $files = File::allFiles($directory);
        foreach ($files as $file) {
            $this->replaceDummyInFile($file->getPathName());
        }

        return $this;
    }
851485
protected function addPattern($pattern, $ruleName, $childRuleName = null) {
        if (!isset($this->patterns[$ruleName])) {
            $this->patterns[$ruleName] = new LexerPattern($ruleName);
        }
        $this->patterns[$ruleName]->addPattern($pattern, $childRuleName);

        return $this;
    }
913746
public function addPattern($pattern)
    {
        $this->doAddPattern($this->convertPattern($pattern));
        $this->hasPattern = true;
    }
577713
public function command($pattern) {
        if (!isset($this->commandSchemas[$pattern])) {
            $this->commandSchemas[$pattern] = [Cli::META => []];
        }
        $this->currentSchema =& $this->commandSchemas[$pattern];

        return $this;
    }
717908
public function find($pattern)
    {
        if (! $this->adapter->isAbsolute($pattern)) {
            $pattern = $this->rootPath . $pattern;
        }
        $list = new Collection;
        foreach ($this->adapter->glob($pattern) as $path) {
            if ($this->isFile($path, true)) {
                $list->add(new File($path, $this->adapter));
            } else {
                $list->add(new Directory($path, $this->adapter));
            }
        }
        return $list;
    }
44714
public static function addDirectory($directory = '.')
    {
        $directory = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $directory);
        $directory = rtrim($directory, '/\\');
        $directory = empty($directory) ? '.' : $directory;
        array_push(self::$configDirectory, $directory);
        return true;
    }
353919
public function glob($pattern = '*', $flag = 0) {
        $files = [];
        foreach (glob($this->fullName.'/'.$pattern, $flag) as $item) {
            if (is_dir($item)) {
                $files[] = new static($item);
                continue;
            }
            $files[] = new File($item);
        }
        return $files;
    }
314913
protected function searchRecursive( $pattern, $directory )
    {
        $itemArr = glob( $directory . $pattern );
        $dirArr = glob( $directory . "*", GLOB_ONLYDIR );
        foreach ( $dirArr as $dirEntry )
        {
            $result = $this->searchRecursive( $pattern, "$dirEntry/" );
            $itemArr = array_merge( $itemArr, $result );
        }
        return $itemArr;
    }
539322
public function findFolders(string $pattern, int $flags = 0): FolderCollection
    {
        $folders = glob($this->path.'/'.$pattern, $flags);
        foreach ($folders as $index => $folder) {
            if (is_dir($folder)) {
                $folders[$index] = new self($folder);
            } else {
                unset($folders[$index]);
            }
        }

        return new FolderCollection($folders);
    }