ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
FSTools.php
Go to the documentation of this file.
1 <?php
2 
10 class FSTools
11 {
12 
13  private static $singleton;
14 
18  public static function singleton()
19  {
21  return FSTools::$singleton;
22  }
23 
28  public static function setSingleton($singleton)
29  {
31  }
32 
38  public function mkdirr($folder)
39  {
40  $folders = preg_split("#[\\\\/]#", $folder);
41  $base = '';
42  for($i = 0, $c = count($folders); $i < $c; $i++) {
43  if(empty($folders[$i])) {
44  if (!$i) {
45  // special case for root level
46  $base .= DIRECTORY_SEPARATOR;
47  }
48  continue;
49  }
50  $base .= $folders[$i];
51  if(!is_dir($base)){
52  $this->mkdir($base);
53  }
54  $base .= DIRECTORY_SEPARATOR;
55  }
56  }
57 
63  public function copyr($source, $dest)
64  {
65  // Simple copy for a file
66  if (is_file($source)) {
67  return $this->copy($source, $dest);
68  }
69  // Make destination directory
70  if (!is_dir($dest)) {
71  $this->mkdir($dest);
72  }
73  // Loop through the folder
74  $dir = $this->dir($source);
75  while ( false !== ($entry = $dir->read()) ) {
76  // Skip pointers
77  if ($entry == '.' || $entry == '..') {
78  continue;
79  }
80  if (!$this->copyable($entry)) {
81  continue;
82  }
83  // Deep copy directories
84  if ($dest !== "$source/$entry") {
85  $this->copyr("$source/$entry", "$dest/$entry");
86  }
87  }
88  // Clean up
89  $dir->close();
90  return true;
91  }
92 
99  public function copyable($file)
100  {
101  return true;
102  }
103 
108  public function rmdirr($dirname)
109  {
110  // Sanity check
111  if (!$this->file_exists($dirname)) {
112  return false;
113  }
114 
115  // Simple delete for a file
116  if ($this->is_file($dirname) || $this->is_link($dirname)) {
117  return $this->unlink($dirname);
118  }
119 
120  // Loop through the folder
121  $dir = $this->dir($dirname);
122  while (false !== $entry = $dir->read()) {
123  // Skip pointers
124  if ($entry == '.' || $entry == '..') {
125  continue;
126  }
127  // Recurse
128  $this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
129  }
130 
131  // Clean up
132  $dir->close();
133  return $this->rmdir($dirname);
134  }
135 
139  public function globr($dir, $pattern, $flags = NULL)
140  {
141  $files = $this->glob("$dir/$pattern", $flags);
142  if ($files === false) $files = array();
143  $sub_dirs = $this->glob("$dir/*", GLOB_ONLYDIR);
144  if ($sub_dirs === false) $sub_dirs = array();
145  foreach ($sub_dirs as $sub_dir) {
146  $sub_files = $this->globr($sub_dir, $pattern, $flags);
147  $files = array_merge($files, $sub_files);
148  }
149  return $files;
150  }
151 
157  public function __call($name, $args)
158  {
159  return call_user_func_array($name, $args);
160  }
161 
162 }
163 
164 // vim: et sw=4 sts=4
$files
Definition: add-vimline.php:18
globr($dir, $pattern, $flags=NULL)
Recursively globs a directory.
Definition: FSTools.php:139
static $singleton
Definition: FSTools.php:13
mkdirr($folder)
Recursively creates a directory.
Definition: FSTools.php:38
Filesystem tools not provided by default; can recursively create, copy and delete folders...
Definition: FSTools.php:10
copyr($source, $dest)
Copy a file, or recursively copy a folder and its contents; modified so that copied files...
Definition: FSTools.php:63
static setSingleton($singleton)
Sets our global singleton to something else; useful for overloading functions.
Definition: FSTools.php:28
__call($name, $args)
Allows for PHP functions to be called and be stubbed.
Definition: FSTools.php:157
rmdirr($dirname)
Delete a file, or a folder and its contents.
Definition: FSTools.php:108
Create styles array
The data for the language used.
copyable($file)
Overloadable function that tests a filename for copyability.
Definition: FSTools.php:99
static singleton()
Returns a global instance of FSTools.
Definition: FSTools.php:18
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file