Cradle  0.3.3
Simple library for creating Web-based applications
Files Class Reference

Digger File Class. More...

Static Public Member Functions

static glob ($path, $mask="*", $flags=NULL, $recursive=false)
 
static globFiles ($paths=array(''), $filePatterns=array(''), $excludePatterns=NULL, $recursive=true)
 
static getRelativePath ($targetPath, $currentPath=NULL)
 
static getFilesTree ($arraySources, $stripBase=true)
 

Detailed Description

Digger File Class.

Class for file operations

Version
3.0
Author
Digger mrdig.nosp@m.ger@.nosp@m.sad-s.nosp@m.yste.nosp@m.ms.ru

Member Function Documentation

static getFilesTree (   $arraySources,
  $stripBase = true 
)
static

Create a hash array represents a file tree structure

Parameters
hash$arraySourcesHash array of sources returned by globFiles method.
boolean$stripBase(Option) =TRUE - creates relative file path structure. =FALSE - creates absolute file path structure.
Returns
boolean|array A hash array represents a file tree structure.
See also
globFiles

Exapmle:

// $files = Files::globFiles('/base/path/', '\.php$');
$files = array(
'/base/path/file1.php' => '/base/path',
'/base/path/file2.php' => '/base/path',
'/base/path/folder1/file1_in_folder1.php' => '/base/path',
'/base/path/folder1/file2_in_folder1.php' => '/base/path',
'/base/path/folder1/subfolder1/file1_in_subfolder1.php' => '/base/path',
)
Files::getFilesTree($files, true);
//--------
// Return:
Array
(
[file1.php] => file1.php
[file2.php] => file2.php
[folder1] => Array
(
[file1_in_folder1.php] => folder1/file1_in_folder1.php
[file2_in_folder1.php] => folder1/file2_in_folder1.php
[subfolder1] => Array
(
[file1_in_subfolder1.php] => folder1/subfolder1/file1_in_subfolder1.php
)
)
)
static getRelativePath (   $targetPath,
  $currentPath = NULL 
)
static

Returns file path of $targetPath relatively $currentPath

Parameters
string$targetPathSource directory (absolute path).
string$currentPathCurrent (or another) directory (absolute path).
Returns
array A hash array structure:
array
(
"common" => "common base part of $targetPath and $currentPath",
"current" => "current path (absolute)",
"relative" => "part of $targetPath relatively $currentPath"
);
Full path to target = "current" + "relative"

Example:

getRelativePath ("/var/www/doc_root/path/to/site1", "/var/www/doc_root/otherpath/to/site2")
return: Array
(
[common] => /var/www/doc_root
[current] => /var/www/doc_root/otherpath/to/site2
[relative] => /../../../path/to/site1
)
Full relative path from current to target will be: /var/www/doc_root/otherpath/to/site2/../../../path/to/site1
static glob (   $path,
  $mask = "*",
  $flags = NULL,
  $recursive = false 
)
static

Extends PHP glob with recursion

Parameters
string$pathPath to search files.
string$maskFile mask. Note: ::glob('/my/path' ,'{,.}*', GLOB_BRACE, true) - will output system hidden files.
int$flagsPHP glob flags.
boolean$recursiveSearch files recursively.
Returns
array An array containing the matched files/directories, an empty array if no file matched or FALSE on error. (Such as php glob).

Example of usage:

print_r( Files::glob("/some/path") );
//--------
// Return:
Array (
[0] => "/some/path/file1",
[1] => "/some/path/file2",
...
)
static globFiles (   $paths = array(''),
  $filePatterns = array(''),
  $excludePatterns = NULL,
  $recursive = true 
)
static

Extends PHP glob with recursion and base path (files only)

Parameters
string | array$pathsPaths to find files (base paths). Default = system current directory.
string | array$filePatternsRegExp patterns to filter files (to find files). Default = "" - all files.
string | array$excludePatternsRegExp patterns to filter files (to ignore files). Default = NULL - no files to exclusion.
boolean$recursive=TRUE - find files in sub directories. Default = TRUE.
Returns
array A hash array of found files. Hash structure:
array(
"/absolute/file/name1" => "/base/path"
"/absolute/file/name2" => "/base/path"
...
)

Exapmle:

print_r( Files::globFiles('/base/path/', '\.php$') );
//--------
// Return:
Array (
'/base/path/file1.php' => '/base/path',
'/base/path/file2.php' => '/base/path',
'/base/path/folder1/file1_in_folder1.php' => '/base/path',
'/base/path/folder1/file2_in_folder1.php' => '/base/path',
'/base/path/folder1/subfolder1/file1_in_subfolder1.php' => '/base/path',
)

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