Digger File Class.
More...
|
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) |
|
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
- Copyright
- (c) 2015, SAD-Systems
static getFilesTree |
( |
|
$arraySources, |
|
|
|
$stripBase = true |
|
) |
| |
|
static |
Create a hash array represents a file tree structure
- Parameters
-
hash | $arraySources | Hash 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 = 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',
)
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 | $targetPath | Source directory (absolute path). |
string | $currentPath | Current (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 | $path | Path to search files. |
string | $mask | File mask. Note: ::glob('/my/path' ,'{,.}*', GLOB_BRACE, true) - will output system hidden files. |
int | $flags | PHP glob flags. |
boolean | $recursive | Search 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:
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 | $paths | Paths to find files (base paths). Default = system current directory. |
string | array | $filePatterns | RegExp patterns to filter files (to find files). Default = "" - all files. |
string | array | $excludePatterns | RegExp 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:
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: