src/core/framework/core/3rdparty/ezcomponents/Base/src/file.php
static public function walkRecursive( $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), $callback, &$callbackContext )
    {
        if ( !is_dir( $sourceDir ) )
        {
            throw new ezcBaseFileNotFoundException( $sourceDir, 'directory' );
        }
        $elements = array();
        $d = @dir( $sourceDir );
        if ( !$d )
        {
            throw new ezcBaseFilePermissionException( $sourceDir, ezcBaseFileException::READ );
        }

        while ( ( $entry = $d->read() ) !== false )
        {
            if ( $entry == '.' || $entry == '..' )
            {
                continue;
            }

            $fileInfo = @stat( $sourceDir . DIRECTORY_SEPARATOR . $entry );
            if ( !$fileInfo )
            {
                $fileInfo = array( 'size' => 0, 'mode' => 0 );
            }

            if ( $fileInfo['mode'] & 0x4000 )
            {
                // We need to ignore the Permission exceptions here as it can
                // be normal that a directory can not be accessed. We only need
                // the exception if the top directory could not be read.
                try
                {
                    call_user_func_array( $callback, array( $callbackContext, $sourceDir, $entry, $fileInfo ) );
                    $subList = self::walkRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry, $includeFilters, $excludeFilters, $callback, $callbackContext );
                    $elements = array_merge( $elements, $subList );
                }
                catch ( ezcBaseFilePermissionException $e )
                {
                }
            }
            else
            {
                // By default a file is included in the return list
                $ok = true;
                // Iterate over the $includeFilters and prohibit the file from
                // being returned when atleast one of them does not match
                foreach ( $includeFilters as $filter )
                {
                    if ( !preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
                    {
                        $ok = false;
                        break;
                    }
                }
                // Iterate over the $excludeFilters and prohibit the file from
                // being returns when atleast one of them matches
                foreach ( $excludeFilters as $filter )
                {
                    if ( preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
                    {
                        $ok = false;
                        break;
                    }
                }

                // If everything's allright, call the callback and add the
                // entry to the elements array
                if ( $ok )
                {
                    call_user_func( $callback, $callbackContext, $sourceDir, $entry, $fileInfo );
                    $elements[] = $sourceDir . DIRECTORY_SEPARATOR . $entry;
                }
            }
        }
        sort( $elements );
        return $elements;
    }
static public function walkRecursive( $sourceDir, array $includeFilters = array(), array $excludeFilters = array(), $callback, &$callbackContext )
    {
        if ( !is_dir( $sourceDir ) )
        {
            throw new ezcBaseFileNotFoundException( $sourceDir, 'directory' );
        }
        $elements = array();
        $d = @dir( $sourceDir );
        if ( !$d )
        {
            throw new ezcBaseFilePermissionException( $sourceDir, ezcBaseFileException::READ );
        }

        while ( ( $entry = $d->read() ) !== false )
        {
            if ( $entry == '.' || $entry == '..' )
            {
                continue;
            }

            $fileInfo = @stat( $sourceDir . DIRECTORY_SEPARATOR . $entry );
            if ( !$fileInfo )
            {
                $fileInfo = array( 'size' => 0, 'mode' => 0 );
            }

            if ( $fileInfo['mode'] & 0x4000 )
            {
                // We need to ignore the Permission exceptions here as it can
                // be normal that a directory can not be accessed. We only need
                // the exception if the top directory could not be read.
                try
                {
                    call_user_func_array( $callback, array( $callbackContext, $sourceDir, $entry, $fileInfo ) );
                    $subList = self::walkRecursive( $sourceDir . DIRECTORY_SEPARATOR . $entry, $includeFilters, $excludeFilters, $callback, $callbackContext );
                    $elements = array_merge( $elements, $subList );
                }
                catch ( ezcBaseFilePermissionException $e )
                {
                }
            }
            else
            {
                // By default a file is included in the return list
                $ok = true;
                // Iterate over the $includeFilters and prohibit the file from
                // being returned when atleast one of them does not match
                foreach ( $includeFilters as $filter )
                {
                    if ( !preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
                    {
                        $ok = false;
                        break;
                    }
                }
                // Iterate over the $excludeFilters and prohibit the file from
                // being returns when atleast one of them matches
                foreach ( $excludeFilters as $filter )
                {
                    if ( preg_match( $filter, $sourceDir . DIRECTORY_SEPARATOR . $entry ) )
                    {
                        $ok = false;
                        break;
                    }
                }

                // If everything's allright, call the callback and add the
                // entry to the elements array
                if ( $ok )
                {
                    call_user_func( $callback, $callbackContext, $sourceDir, $entry, $fileInfo );
                    $elements[] = $sourceDir . DIRECTORY_SEPARATOR . $entry;
                }
            }
        }
        sort( $elements );
        return $elements;
    }
static public function walkRecursive ( $ sourceDir , array $ includeFilters = array ( ) , array $ excludeFilters = array ( ) , $ callback , & $ callbackContext ) { if ( ! is_dir ( $ sourceDir ) ) { throw new ezcBaseFileNotFoundException ( $ sourceDir , 'directory' ) ; } $ elements = array ( ) ; $ d = @ dir ( $ sourceDir ) ; if ( ! $ d ) { throw new ezcBaseFilePermissionException ( $ sourceDir , ezcBaseFileException :: READ ) ; } while ( ( $ entry = $ d -> read ( ) ) !== false ) { if ( $ entry == '.' || $ entry == '..' ) { continue ; } $ fileInfo = @ stat ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ; if ( ! $ fileInfo ) { $ fileInfo = array ( 'size' => 0 , 'mode' => 0 ) ; } if ( $ fileInfo [ 'mode' ] & 0x4000 ) { // We need to ignore the Permission exceptions here as it can // be normal that a directory can not be accessed. We only need // the exception if the top directory could not be read. try { call_user_func_array ( $ callback , array ( $ callbackContext , $ sourceDir , $ entry , $ fileInfo ) ) ; $ subList = self :: walkRecursive ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry , $ includeFilters , $ excludeFilters , $ callback , $ callbackContext ) ; $ elements = array_merge ( $ elements , $ subList ) ; } catch ( ezcBaseFilePermissionException $ e ) { } } else { // By default a file is included in the return list $ ok = true ; // Iterate over the $includeFilters and prohibit the file from // being returned when atleast one of them does not match foreach ( $ includeFilters as $ filter ) { if ( ! preg_match ( $ filter , $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ) { $ ok = false ; break ; } } // Iterate over the $excludeFilters and prohibit the file from // being returns when atleast one of them matches foreach ( $ excludeFilters as $ filter ) { if ( preg_match ( $ filter , $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ) { $ ok = false ; break ; } } // If everything's allright, call the callback and add the // entry to the elements array if ( $ ok ) { call_user_func ( $ callback , $ callbackContext , $ sourceDir , $ entry , $ fileInfo ) ; $ elements [ ] = $ sourceDir . DIRECTORY_SEPARATOR . $ entry ; } } } sort ( $ elements ) ; return $ elements ; }
Walks files and directories recursively on a file system

This method walks over a directory and calls a callback from every file
and directory it finds. You can use $includeFilters to include only
specific files, and $excludeFilters to exclude certain files from being
returned. The function will always go into subdirectories even if the
entry would not have passed the filters.

The callback is passed in the $callback parameter, and the
$callbackContext will be send to the callback function/method as
parameter so that you can store data in there that persists with all the
calls and recursive calls to this method. It's up to the callback method
to do something useful with this. The callback function's parameters are
in order:

<ul>
<li>ezcBaseFileFindContext $context</li>
<li>string $sourceDir</li>
<li>string $fileName</li>
<li>array(stat) $fileInfo</li>
</ul>

See {@see findRecursiveCallback()} for an example of a callback function.

Filters are regular expressions and are therefore required to have
starting and ending delimiters. The Perl Compatible syntax is used as
regular expression language.

@param string         $sourceDir
@param array(string)  $includeFilters
@param array(string)  $excludeFilters
@param callback       $callback
@param mixed          $callbackContext

@throws ezcBaseFileNotFoundException if the $sourceDir directory is not
a directory or does not exist.
@throws ezcBaseFilePermissionException if the $sourceDir directory could
not be opened for reading.
@return array
Walks files and directories recursively on a file system