CorujaFileManipulation Class Reference

List of all members.

Static Public Member Functions

static getRelativePath ($strFileFrom, $strFileTo, $booValidPath=true)
static isRelativePath ($strFile)
static getPathOfFile ($strFile)


Detailed Description

Class for manipulation of files

Author:
Thiago Henrique Ramos da Mata <thiago.henrique.mata@gmail.com>

Definition at line 12 of file CorujaFileManipulation.class.php.


Member Function Documentation

static getPathOfFile ( strFile  )  [static]

Get the path of the file

Parameters:
string $strFile
Returns:
string

Definition at line 140 of file CorujaFileManipulation.class.php.

References $strFile.

Referenced by CodeToDiagram::checkPermissionToWrite(), Loader::requireOnce(), and CodeToDiagram::setCallerPathByFile().

00141     {
00142         return str_replace( "\\" , "/" , str_replace( basename( $strFile ) , "" , $strFile ) );
00143     }

static getRelativePath ( strFileFrom,
strFileTo,
booValidPath = true 
) [static]

Returns a path to a folder relative from another folder. Both parameters must be absolute.

  • check for valid parameters
  • in case paths are equal return './'
  • explode parameters using '/'
  • remove similar base folders
  • make final address

Parameters:
String $strFileFrom Base from the path. This must be an absolute path.
String $strFileTo Destination of the path. This must be an absolute path.
Boolean $booValidPath Use false if you don't want to check for valid folders.
Exceptions:
InvalidArgumentException In case of invalid values
Example:
 \1 
returns
 true 
.... $path = CorujaStringManipulation::getRelativePath( "/www/folder/", "/www/another/big/" ); // "../another/big/"
Assert:
( "/www/folder/", "/www/another/big/", false ) == "../another/big/"
Assert:
( "", "" ) throws InvalidArgumentException
Assert:
( "hello", "" ) throws InvalidArgumentException
Assert:
( "", "hello" ) throws InvalidArgumentException
Assert:
( "cool", "hello" ) throws InvalidArgumentException
Assert:
( "/cool/", "hello" ) throws InvalidArgumentException
Assert:
( "cool", "/hello/" ) throws InvalidArgumentException
Assert:
( "/cool/", "/hello/", false ) == "../hello/"
Assert:
( "/cool/", "/hello/", false ) == "../hello/"
Assert:
( "/cool/", "/cool/", false ) == "./"
Assert:
( "/cool/more/", "/other/", false ) == "../../other/"
Assert:
( "/cool/", "/other/more/", false ) == "../other/more/"

Definition at line 44 of file CorujaFileManipulation.class.php.

Referenced by UmlSequenceDiagramPrinterConfigurationToXml::getPublicFolderPath(), and UmlSequenceDiagramPrinterConfigurationToHtml::getPublicFolderPath().

00045     {
00046         // check for valid parameters
00047 
00048         $strFileFrom = str_replace( "\\" , "/" , $strFileFrom );
00049         $strFileTo = str_replace( "\\" , "/" , $strFileTo );
00050 
00051         if( $booValidPath
00052             && ( ! is_dir( $strFileFrom ) || ! is_dir( $strFileTo ) )
00053         )
00054         {
00055             throw new InvalidArgumentException("Invalid parameter: strFileFrom: ".$strFileFrom." strFileTo: ".$strFileTo);
00056         }
00057 
00058         // special case: equal paths
00059         if( $strFileFrom == $strFileTo )
00060         {
00061              $strReturnPath = './';
00062         }
00063         else
00064         {
00065             // explode parameters using '/'
00066             $arrFileFrom = explode( '/', $strFileFrom );
00067             $arrFileTo   = explode( '/', $strFileTo );
00068 
00069             // remove similar base folders
00070             while(
00071                 current( $arrFileFrom ) == current( $arrFileTo )
00072                 && count( $arrFileFrom ) > 0
00073             )
00074             {
00075                 array_shift( $arrFileFrom );
00076                 array_shift( $arrFileTo );
00077             }
00078 
00079             $arrReturnPath = array();
00080 
00081             // make final address
00082             foreach( $arrFileFrom as $strFolder )
00083             {
00084                 if( $strFolder != "" ) {
00085                     $arrReturnPath[] = "..";
00086                 }
00087             }
00088 
00089             foreach( $arrFileTo as $strFolder )
00090             {
00091                 $arrReturnPath[] = $strFolder;
00092             }
00093 
00094             $strReturnPath = implode( '/', $arrReturnPath );
00095         }
00096         return $strReturnPath;
00097     }

static isRelativePath ( strFile  )  [static]

Check if a address is relative

Assert:
( "c:\www\temp.php" ) == false
Assert:
( "d:/www/temp.php" ) == false
Assert:
( "temp.php" ) == true
Assert:
( "./temp.php" ) == true
Assert:
( "/www/something.php" ) == false
Assert:
( "./www/something.php" ) == true
Assert:
( ".\www\something.php" ) == true
Assert:
( "..\www\something.php" ) == true
Assert:
( "..\www\something.php" ) == true

Definition at line 113 of file CorujaFileManipulation.class.php.

References $strFile.

Referenced by CodeToDiagram::loadFile(), and Loader::requireOnce().

00114     {
00115         $strFile = str_replace( "\\", "/", $strFile);
00116         if(
00117             ( strpos( $strFile, "./") === 0 )
00118             or
00119             ( strpos( $strFile, "../") === 0 )
00120          )
00121         {
00122             return true;
00123         }
00124         elseif( strpos( $strFile, "/") === false )
00125         {
00126             return true;
00127         }
00128         else
00129         {
00130             return false;
00131         }
00132    }


The documentation for this class was generated from the following file:

Generated on Thu Feb 3 03:55:03 2011 for CodeToDiagram by  doxygen 1.5.9