Author: dr
Date: Mon Aug 13 13:20:46 2007
New Revision: 5896

Log:
- Create Base/ezcBaseFile from File/ezcFile and deprecate the latter class by
  extending the former.
#- http://thread.gmane.org/gmane.comp.web.ezcomponents.devel/3088

Added:
    trunk/Base/src/file.php
      - copied, changed from r5889, trunk/File/src/file.php
    trunk/Base/tests/file_calculate_relative_path_test.php
      - copied unchanged from r5889, 
trunk/File/tests/file_calculate_relative_path_test.php
    trunk/Base/tests/file_find_recursive_test.php
      - copied unchanged from r5889, 
trunk/File/tests/file_find_recursive_test.php
    trunk/Base/tests/file_remove_recursive_test.php
      - copied unchanged from r5889, 
trunk/File/tests/file_remove_recursive_test.php
Modified:
    trunk/Base/design/class_diagram.png
    trunk/Base/src/base_autoload.php
    trunk/File/design/class_diagram.png
    trunk/File/src/file.php

Modified: trunk/Base/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/Base/src/base_autoload.php
==============================================================================
--- trunk/Base/src/base_autoload.php [iso-8859-1] (original)
+++ trunk/Base/src/base_autoload.php [iso-8859-1] Mon Aug 13 13:20:46 2007
@@ -33,6 +33,7 @@
     'ezcBaseAutoloadOptions'                      => 
'Base/options/autoload.php',
     'ezcBaseConfigurationInitializer'             => 
'Base/interfaces/configuration_initializer.php',
     'ezcBaseFeatures'                             => 'Base/features.php',
+    'ezcBaseFile'                                 => 'Base/file.php',
     'ezcBaseInit'                                 => 'Base/init.php',
     'ezcBaseRepositoryDirectory'                  => 
'Base/structs/repository_directory.php',
 );

Copied: trunk/Base/src/file.php (from r5889, trunk/File/src/file.php)
==============================================================================
--- trunk/File/src/file.php [iso-8859-1] (original)
+++ trunk/Base/src/file.php [iso-8859-1] Mon Aug 13 13:20:46 2007
@@ -4,7 +4,7 @@
  * @license http://ez.no/licenses/new_bsd New BSD License
  * @version //autogentag//
  * @filesource
- * @package File
+ * @package Base
  */
 
 /**
@@ -31,11 +31,11 @@
  * ?>
  * </code>
  *
- * @package File
+ * @package Base
  * @version //autogentag//
  * @mainclass
  */
-class ezcFile
+class ezcBaseFile
 {
     /**
      * Finds files recursively on a file system

Modified: trunk/File/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/File/src/file.php
==============================================================================
--- trunk/File/src/file.php [iso-8859-1] (original)
+++ trunk/File/src/file.php [iso-8859-1] Mon Aug 13 13:20:46 2007
@@ -9,206 +9,14 @@
 
 /**
  * Provides a selection of static independent methods to provide functionality
- * for file and file system handling.
- *
- * This example shows how to use the findRecursive method:
- * <code>
- * <?php
- * // lists all the files under /etc (including subdirectories) that end in 
- * // .conf
- * $confFiles = ezcFile::findRecursive( "/etc", array( '@\.conf$@' ) );
- *
- * // lists all autoload files in the components source tree and excludes the
- * // ones in the autoload subdirectory.
- * $files = ezcFile::findRecursive(
- *     "/dat/dev/ezcomponents",
- *     array( '@src/.*_autoload.php$@' ),
- *     array( '@/autoload/@' )
- * );
- *
- * // lists all binaries in /bin except the ones starting with a "g"
- * $data = ezcFile::findRecursive( "/bin", array(), array( '@^/bin/g@' ) );
- * ?>
- * </code>
+ * for file and file system handling. This class is deprecated, please use
+ * ezcBaseFile instead.
  *
  * @package File
  * @version //autogentag//
- * @mainclass
+ * @apichange Has been deprecated by ezcBaseFile
  */
-class ezcFile
+class ezcFile extends ezcBaseFile
 {
-    /**
-     * Finds files recursively on a file system
-     *
-     * With this method you can scan the file system for files. 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.
-     *
-     * @param string $sourceDir
-     * @param array(string) $includeFilters
-     * @param array(string) $excludeFilters
-     *
-     * @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
-     */
-    static public function findRecursive( $sourceDir, array $includeFilters = 
array(), array $excludeFilters = array() )
-    {
-        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;
-            }
-
-            if ( is_dir( $sourceDir . '/' . $entry ) )
-            {
-                // 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
-                {
-                    $subList = self::findRecursive( $sourceDir . '/' . $entry, 
$includeFilters, $excludeFilters );
-                    $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 . '/' . $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 . '/' . $entry ) )
-                    {
-                        $ok = false;
-                        break;
-                    }
-                }
-
-                if ( $ok )
-                {
-                    $elements[] = $sourceDir . '/' . $entry;
-                }
-            }
-        }
-        sort( $elements );
-        return $elements;
-    }
-
-    /**
-     * Removes files and directories recursively from a file system
-     *
-     * This method recursively removes the $directory and all its contents.
-     * You should be <b>extremely</b> careful with this method as it has the
-     * potential to erase everything that the current user has access to.
-     *
-     * @param string $directory
-     */
-    static public function removeRecursive( $directory )
-    {
-        $sourceDir = realpath( $directory );
-        if ( !$sourceDir )
-        {
-            throw new ezcBaseFileNotFoundException( $directory, 'directory' );
-        }
-        $d = @dir( $sourceDir );
-        if ( !$d )
-        {
-            throw new ezcBaseFilePermissionException( $directory, 
ezcBaseFileException::READ );
-        }
-        while ( ( $entry = $d->read() ) !== false )
-        {
-            if ( $entry == '.' || $entry == '..' )
-            {
-                continue;
-            }
-
-            if ( is_dir( $sourceDir . '/' . $entry ) )
-            {
-                self::removeRecursive( $sourceDir . '/' . $entry );
-            }
-            else
-            {
-                if ( @unlink( $sourceDir . '/' . $entry ) === false )
-                {
-                    throw new ezcBaseFilePermissionException( $directory . '/' 
. $entry, ezcBaseFileException::REMOVE );
-                }
-            }
-        }
-        $d->close();
-        rmdir( $sourceDir );
-    }
-
-    /**
-     * Calculates the relative path of the file/directory '$path' to a given
-     * $base path.
-     * This method does not touch the filesystem.
-     *
-     * @param string $path
-     * @param string $base
-     * @return string
-     */
-    static public function calculateRelativePath( $path, $base )
-    {
-        // Sanitize the paths to use the correct directory separator for the 
platform
-        $path = strtr( $path, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR 
);
-        $base = strtr( $base, '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR 
);
-
-        $base = explode( DIRECTORY_SEPARATOR, $base );
-        $path = explode( DIRECTORY_SEPARATOR, $path );
-
-        $result = '';
-
-        $pathPart = array_shift( $path );
-        $basePart = array_shift( $base );
-        while ( $pathPart == $basePart )
-        {
-            $pathPart = array_shift( $path );
-            $basePart = array_shift( $base );
-        }
-
-        if ( $pathPart != null )
-        {
-            array_unshift( $path, $pathPart );
-        }
-        if ( $basePart != null ) 
-        {
-            array_unshift( $base, $basePart );
-        }
-
-        $result = str_repeat( '..' . DIRECTORY_SEPARATOR, count( $base ) );
-        $result .= join( DIRECTORY_SEPARATOR, $path );
-
-        return $result;
-    }
 }
 ?>


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to