|
| _parseArgs ($argv, $short_options, $long_options=null) |
| returns the commandline arguments of a function More...
|
|
| raiseError ($error) |
| Output errors with PHP trigger_error(). More...
|
|
| _dirToStruct ($sPath, $maxinst, $aktinst=0, $silent=false) |
| Creates a nested array representing the structure of a directory. More...
|
|
| _multipleToStruct ($files) |
| Creates a nested array representing the structure of a directory and files. More...
|
|
| rm ($args) |
| The rm command for removing files. More...
|
|
| mkDir ($args) |
| Make directories. More...
|
|
& | cat ($args) |
| Concatenate files. More...
|
|
| mktemp ($args=null) |
| Creates temporary files or directories. More...
|
|
| _removeTmpFiles () |
| Remove temporary files created my mkTemp. More...
|
|
| tmpdir () |
| Get the path of the temporal directory set in the system by looking in its environments variables. More...
|
|
| which ($program, $fallback=false) |
| The "which" command (show the full path of a command) More...
|
|
| find ($args) |
| The "find" command. More...
|
|
Definition at line 59 of file System.php.
◆ _dirToStruct()
System::_dirToStruct |
( |
|
$sPath, |
|
|
|
$maxinst, |
|
|
|
$aktinst = 0 , |
|
|
|
$silent = false |
|
) |
| |
|
static |
Creates a nested array representing the structure of a directory.
System::_dirToStruct('dir1', 0) => Array ( [dirs] => Array ( [0] => dir1 )
[files] => Array ( [0] => dir1/file2 [1] => dir1/file3 ) )
- Parameters
-
string | $sPath | Name of the directory |
integer | $maxinst | max. deep of the lookup |
integer | $aktinst | starting deep of the lookup |
bool | $silent | if true, do not emit errors. |
- Returns
- array the structure of the dir private
Definition at line 122 of file System.php.
References $file, $path, and raiseError().
Referenced by _multipleToStruct(), and find().
124 $struct = array(
'dirs' => array(),
'files' => array());
125 if (($dir = @opendir($sPath)) ===
false) {
132 $struct[
'dirs'][] = $sPath = realpath($sPath);
134 while (
false !== (
$file = readdir($dir))) {
142 if ($aktinst < $maxinst || $maxinst == 0) {
143 foreach ($list as $val) {
144 $path = $sPath . DIRECTORY_SEPARATOR . $val;
147 $struct = array_merge_recursive($struct, $tmp);
149 $struct[
'files'][] =
$path;
_dirToStruct($sPath, $maxinst, $aktinst=0, $silent=false)
Creates a nested array representing the structure of a directory.
raiseError($error)
Output errors with PHP trigger_error().
◆ _multipleToStruct()
System::_multipleToStruct |
( |
|
$files | ) |
|
|
static |
Creates a nested array representing the structure of a directory and files.
- Parameters
-
array | $files | Array listing files and dirs |
- Returns
- array
- See also
- System::_dirToStruct()
Definition at line 165 of file System.php.
References $file, and _dirToStruct().
Referenced by rm().
167 $struct = array(
'dirs' => array(),
'files' => array());
168 settype($files,
'array');
169 foreach ($files as
$file) {
170 if (is_dir($file) && !is_link($file)) {
172 $struct = array_merge_recursive($tmp, $struct);
174 if (!in_array($file, $struct[
'files'])) {
175 $struct[
'files'][] =
$file;
_dirToStruct($sPath, $maxinst, $aktinst=0, $silent=false)
Creates a nested array representing the structure of a directory.
◆ _parseArgs()
System::_parseArgs |
( |
|
$argv, |
|
|
|
$short_options, |
|
|
|
$long_options = null |
|
) |
| |
|
static |
returns the commandline arguments of a function
- Parameters
-
string | $argv | the commandline |
string | $short_options | the allowed option short-tags |
string | $long_options | the allowed option long-tags |
- Returns
- array the given options and there values private
Definition at line 71 of file System.php.
References Console_Getopt\getopt2().
Referenced by mkDir(), mktemp(), and rm().
73 if (!is_array($argv) && $argv !== null) {
74 $argv = preg_split(
'/\s+/', $argv, -1, PREG_SPLIT_NO_EMPTY);
getopt2($args, $short_options, $long_options=null, $skip_unknown=false)
Parses the command-line options.
◆ _removeTmpFiles()
System::_removeTmpFiles |
( |
| ) |
|
|
static |
Remove temporary files created my mkTemp.
This function is executed at script shutdown time
private
Definition at line 435 of file System.php.
References $GLOBALS, and rm().
437 if (count(
$GLOBALS[
'_System_temp_files'])) {
438 $delete =
$GLOBALS[
'_System_temp_files'];
439 array_unshift($delete,
'-r');
441 $GLOBALS[
'_System_temp_files'] = array();
$GLOBALS['_System_temp_files']
base class
rm($args)
The rm command for removing files.
◆ cat()
Concatenate files.
Usage: 1) $var = System::cat('sample.txt test.txt'); 2) System::cat('sample.txt test.txt > final.txt'); 3) System::cat('sample.txt test.txt >> final.txt');
Note: as the class use fopen, urls should work also (test that)
- Parameters
-
- Returns
- boolean true on success public
Definition at line 308 of file System.php.
References $file, $ret, and raiseError().
312 if (!is_array($args)) {
313 $args = preg_split(
'/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
316 $count_args = count($args);
317 for ($i = 0; $i < $count_args; $i++) {
318 if ($args[$i] ==
'>') {
320 $outputfile = $args[$i+1];
322 } elseif ($args[$i] ==
'>>') {
324 $outputfile = $args[$i+1];
327 $files[] = $args[$i];
332 if (!$outputfd = fopen($outputfile, $mode)) {
338 foreach ($files as
$file) {
339 if (!$fd = fopen($file,
'r')) {
343 while ($cont = fread($fd, 2048)) {
344 if (is_resource($outputfd)) {
345 fwrite($outputfd, $cont);
352 if (is_resource($outputfd)) {
raiseError($error)
Output errors with PHP trigger_error().
◆ find()
The "find" command.
Usage:
System::find($dir); System::find("$dir -type d"); System::find("$dir -type f"); System::find("$dir -name *.php"); System::find("$dir -name *.php -name *.htm*"); System::find("$dir -maxdepth 1");
Params implmented: $dir -> Start the search at this directory -type d -> return only directories -type f -> return only files -maxdepth <n> -> max depth of recursion -name <pattern> -> search pattern (bash style). Multiple -name param allowed
- Parameters
-
mixed | Either array or string with the command line |
- Returns
- array Array of found files
Definition at line 559 of file System.php.
References $path, $ret, and _dirToStruct().
561 if (!is_array($args)) {
562 $args = preg_split(
'/\s+/', $args, -1, PREG_SPLIT_NO_EMPTY);
564 $dir = realpath(array_shift($args));
570 $do_files = $do_dirs =
true;
571 $args_count = count($args);
572 for ($i = 0; $i < $args_count; $i++) {
575 if (in_array($args[$i+1], array(
'd',
'f'))) {
576 if ($args[$i+1] ==
'd') {
585 $name = preg_quote($args[$i+1],
'#');
588 $name = strtr($name, array(
'\?' =>
'.',
'\*' =>
'.*'));
589 $patterns[] =
'('.$name.
')';
593 $depth = $args[$i+1];
598 if ($do_files && $do_dirs) {
599 $files = array_merge(
$path[
'files'],
$path[
'dirs']);
600 } elseif ($do_dirs) {
601 $files =
$path[
'dirs'];
603 $files =
$path[
'files'];
605 if (count($patterns)) {
606 $dsq = preg_quote(DIRECTORY_SEPARATOR,
'#');
607 $pattern =
'#(^|'.$dsq.
')'.implode(
'|', $patterns).
'($|'.$dsq.
')#';
609 $files_count = count($files);
610 for ($i = 0; $i < $files_count; $i++) {
612 $filepart = basename($files[$i]);
613 if (preg_match($pattern, $filepart)) {
_dirToStruct($sPath, $maxinst, $aktinst=0, $silent=false)
Creates a nested array representing the structure of a directory.
◆ mkDir()
Make directories.
The -p option will create parent directories
- Parameters
-
string | $args | the name of the director(y|ies) to create |
- Returns
- bool True for success public
Definition at line 237 of file System.php.
References $ret, _parseArgs(), PEAR\isError(), and raiseError().
Referenced by mktemp().
245 foreach ($opts[0] as $opt) {
246 if ($opt[0] ==
'p') {
247 $create_parents =
true;
248 } elseif ($opt[0] ==
'm') {
251 if (strlen($opt[1]) && $opt[1]{0} ==
'0') {
252 $opt[1] = octdec($opt[1]);
262 if (isset($create_parents)) {
263 foreach ($opts[1] as $dir) {
265 while ((!file_exists($dir) || !is_dir($dir)) &&
266 $dir != DIRECTORY_SEPARATOR) {
267 array_unshift($dirstack, $dir);
268 $dir = dirname($dir);
271 while ($newdir = array_shift($dirstack)) {
272 if (!is_writeable(dirname($newdir))) {
277 if (!mkdir($newdir, $mode)) {
283 foreach($opts[1] as $dir) {
284 if ((@file_exists($dir) || !is_dir($dir)) && !mkdir($dir, $mode)) {
_parseArgs($argv, $short_options, $long_options=null)
returns the commandline arguments of a function
raiseError($error)
Output errors with PHP trigger_error().
isError($data, $code=null)
Tell whether a value is a PEAR error.
◆ mktemp()
System::mktemp |
( |
|
$args = null | ) |
|
|
static |
Creates temporary files or directories.
This function will remove the created files when the scripts finish its execution.
Usage: 1) $tempfile = System::mktemp("prefix"); 2) $tempdir = System::mktemp("-d prefix"); 3) $tempfile = System::mktemp(); 4) $tempfile = System::mktemp("-t /var/tmp prefix");
prefix -> The string that will be prepended to the temp name (defaults to "tmp"). -d -> A temporary dir will be created instead of a file. -t -> The target dir where the temporary (file|dir) will be created. If this param is missing by default the env vars TMP on Windows or TMPDIR in Unix will be used. If these vars are also missing c: or /tmp will be used.
- Parameters
-
- Returns
- mixed the full path of the created (file|dir) or false
- See also
- System::tmpdir() User interface
Definition at line 382 of file System.php.
References $GLOBALS, _parseArgs(), PEAR\isError(), mkDir(), raiseError(), PEAR\registerShutdownFunc(), and tmpdir().
384 static $first_time =
true;
390 foreach ($opts[0] as $opt) {
391 if ($opt[0] ==
'd') {
393 } elseif ($opt[0] ==
't') {
398 $prefix = (isset($opts[1][0])) ? $opts[1][0] :
'tmp';
399 if (!isset($tmpdir)) {
407 $tmp = tempnam($tmpdir, $prefix);
408 if (isset($tmp_is_dir)) {
410 if (!mkdir($tmp, 0700)) {
415 $GLOBALS[
'_System_temp_files'][] = $tmp;
416 if (isset($tmp_is_dir)) {
registerShutdownFunc($func, $args=array())
Use this function to register a shutdown method for static classes.
_parseArgs($argv, $short_options, $long_options=null)
returns the commandline arguments of a function
tmpdir()
Get the path of the temporal directory set in the system by looking in its environments variables...
mkDir($args)
Make directories.
$GLOBALS['_System_temp_files']
base class
raiseError($error)
Output errors with PHP trigger_error().
isError($data, $code=null)
Tell whether a value is a PEAR error.
◆ raiseError()
System::raiseError |
( |
|
$error | ) |
|
|
static |
Output errors with PHP trigger_error().
You can silence the errors with prefixing a "@" sign to the function call: ::mkdir(..);
- Parameters
-
mixed | $error | a PEAR error or a string with the error message |
- Returns
- bool false private
Definition at line 88 of file System.php.
References PEAR\isError().
Referenced by _dirToStruct(), cat(), mkDir(), mktemp(), and rm().
91 $error = $error->getMessage();
93 trigger_error($error, E_USER_WARNING);
isError($data, $code=null)
Tell whether a value is a PEAR error.
◆ rm()
The rm command for removing files.
Supports multiple files and dirs and also recursive deletes
- Parameters
-
string | $args | the arguments for rm |
- Returns
- mixed PEAR_Error or true for success public
Definition at line 191 of file System.php.
References $file, $ret, _multipleToStruct(), _parseArgs(), PEAR\isError(), and raiseError().
Referenced by _removeTmpFiles().
197 foreach ($opts[0] as $opt) {
198 if ($opt[0] ==
'r') {
199 $do_recursive =
true;
203 if (isset($do_recursive)) {
205 foreach ($struct[
'files'] as
$file) {
206 if (!@unlink($file)) {
211 rsort($struct[
'dirs']);
212 foreach ($struct[
'dirs'] as $dir) {
218 foreach ($opts[1] as $file) {
219 $delete = (is_dir($file)) ?
'rmdir' :
'unlink';
220 if (!@$delete($file)) {
_parseArgs($argv, $short_options, $long_options=null)
returns the commandline arguments of a function
_multipleToStruct($files)
Creates a nested array representing the structure of a directory and files.
raiseError($error)
Output errors with PHP trigger_error().
isError($data, $code=null)
Tell whether a value is a PEAR error.
◆ tmpdir()
Get the path of the temporal directory set in the system by looking in its environments variables.
Note: php.ini-recommended removes the "E" from the variables_order setting, making unavaible the $_ENV array, that s why we do tests with _ENV
- Returns
- string The temporary directory on the system
Definition at line 454 of file System.php.
Referenced by mktemp(), OLE_PPS_File\OLE_PPS_File(), and OLE_PPS_Root\OLE_PPS_Root().
457 if ($var = isset($_ENV[
'TMP']) ? $_ENV[
'TMP'] : getenv(
'TMP')) {
460 if ($var = isset($_ENV[
'TEMP']) ? $_ENV[
'TEMP'] : getenv(
'TEMP')) {
463 if ($var = isset($_ENV[
'USERPROFILE']) ? $_ENV[
'USERPROFILE'] : getenv(
'USERPROFILE')) {
466 if ($var = isset($_ENV[
'windir']) ? $_ENV[
'windir'] : getenv(
'windir')) {
469 return getenv(
'SystemRoot') .
'\temp';
471 if ($var = isset($_ENV[
'TMPDIR']) ? $_ENV[
'TMPDIR'] : getenv(
'TMPDIR')) {
474 return realpath(
'/tmp');
◆ which()
System::which |
( |
|
$program, |
|
|
|
$fallback = false |
|
) |
| |
|
static |
The "which" command (show the full path of a command)
- Parameters
-
string | $program | The command to search for |
mixed | $fallback | Value to return if $program is not found |
- Returns
- mixed A string with the full path or false if not found
- Author
- Stig Bakken ssb@p.nosp@m.hp.n.nosp@m.et
Definition at line 487 of file System.php.
References $fallback, $file, and $path.
490 if (!is_string($program) ||
'' == $program) {
495 if (basename($program) != $program) {
496 $path_elements[] = dirname($program);
497 $program = basename($program);
500 if (!ini_get(
'safe_mode') || !
$path = ini_get(
'safe_mode_exec_dir')) {
501 $path = getenv(
'PATH');
503 $path = getenv(
'Path');
506 $path_elements = explode(PATH_SEPARATOR,
$path);
510 $exe_suffixes = getenv(
'PATHEXT')
511 ? explode(PATH_SEPARATOR, getenv(
'PATHEXT'))
512 : array(
'.exe',
'.bat',
'.cmd',
'.com');
514 if (strpos($program,
'.') !==
false) {
515 array_unshift($exe_suffixes,
'');
518 $pear_is_executable = (function_exists(
'is_executable')) ?
'is_executable' :
'is_file';
520 $exe_suffixes = array(
'');
521 $pear_is_executable =
'is_executable';
524 foreach ($exe_suffixes as $suff) {
525 foreach ($path_elements as $dir) {
526 $file = $dir . DIRECTORY_SEPARATOR . $program . $suff;
527 if (@$pear_is_executable(
$file)) {
The documentation for this class was generated from the following file: