ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilFileSystemHelper Class Reference

File System Helper, to reduce deps. More...

+ Collaboration diagram for ilFileSystemHelper:

Public Member Functions

 __construct (ilLanguage $lng, ilSystemStyleMessageStack $message_stack)
 
 move (string $from, string $to)
 Used to move a complete directory of a skin. More...
 
 delete (string $file_path)
 
 saveDeleteFile (string $file_path)
 Deletes a given file in the container. More...
 
 recursiveRemoveDir (string $dir)
 Recursive delete of a folder. More...
 
 removeResourceDirectory (string $skin_dir, string $dir)
 Deletes a resource directory. More...
 
 createResourceDirectory (string $source, string $target)
 Creates a resource directory (sound, images or fonts) by copying from the source (mostly delos) More...
 
 changeResourceDirectory (string $skin_dir, string $new_dir, string $old_dir)
 Alters the name/path of a resource directory. More...
 
 recursiveCopy (string $src, string $dest)
 Recursive copy of a folder. More...
 
 getMessageStack ()
 
 setMessageStack (ilSystemStyleMessageStack $message_stack)
 

Protected Attributes

ilSystemStyleMessageStack $message_stack
 Used to stack messages to be displayed to the user (mostly reports for failed actions) More...
 
ilLanguage $lng
 

Detailed Description

File System Helper, to reduce deps.

to ilUtil or wrap them properly. Should be replaced by src/Filesystem as soon as templates/default is accessible by src/Filesystem

Definition at line 25 of file class.ilFileSystemHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ilFileSystemHelper::__construct ( ilLanguage  $lng,
ilSystemStyleMessageStack  $message_stack 
)

Definition at line 33 of file class.ilFileSystemHelper.php.

References $lng, ILIAS\Repository\lng(), and setMessageStack().

34  {
35  $this->setMessageStack($message_stack);
36  $this->lng = $lng;
37  }
setMessageStack(ilSystemStyleMessageStack $message_stack)
+ Here is the call graph for this function:

Member Function Documentation

◆ changeResourceDirectory()

ilFileSystemHelper::changeResourceDirectory ( string  $skin_dir,
string  $new_dir,
string  $old_dir 
)

Alters the name/path of a resource directory.

Exceptions
ilSystemStyleException

Definition at line 129 of file class.ilFileSystemHelper.php.

References getMessageStack(), ILIAS\Repository\lng(), recursiveCopy(), recursiveRemoveDir(), and ilSystemStyleMessage\TYPE_SUCCESS.

129  : void
130  {
131  $absolut_new_dir = $skin_dir . $new_dir;
132  $absolut_old_dir = $skin_dir . $old_dir;
133 
134  if (file_exists($absolut_new_dir)) {
135  $this->getMessageStack()->addMessage(
137  $this->lng->txt('dir_changed_to') . ' ' . $absolut_new_dir,
139  )
140  );
141  $this->getMessageStack()->addMessage(
143  $this->lng->txt('dir_preserved_backup') . ' ' . $absolut_old_dir,
145  )
146  );
147  } else {
148  mkdir($absolut_new_dir, 0775, true);
149  $this->recursiveCopy($absolut_old_dir, $absolut_new_dir);
150  $this->getMessageStack()->addMessage(
152  $this->lng->txt('dir_copied_from') . ' ' . $absolut_old_dir . ' ' . $this->lng->txt('sty_copy_to') . ' ' . $absolut_new_dir,
154  )
155  );
156  $this->recursiveRemoveDir($skin_dir . $old_dir);
157  $this->getMessageStack()->addMessage(
159  $this->lng->txt('dir_deleted') . ' ' . $absolut_old_dir,
161  )
162  );
163  }
164  }
recursiveRemoveDir(string $dir)
Recursive delete of a folder.
recursiveCopy(string $src, string $dest)
Recursive copy of a folder.
+ Here is the call graph for this function:

◆ createResourceDirectory()

ilFileSystemHelper::createResourceDirectory ( string  $source,
string  $target 
)

Creates a resource directory (sound, images or fonts) by copying from the source (mostly delos)

Exceptions
ilSystemStyleException

Definition at line 110 of file class.ilFileSystemHelper.php.

References getMessageStack(), ILIAS\Repository\lng(), recursiveCopy(), and ilSystemStyleMessage\TYPE_SUCCESS.

110  : void
111  {
112  mkdir($target, 0775, true);
113 
114  if ($source != '') {
115  $this->recursiveCopy($source, $target);
116  $this->getMessageStack()->addMessage(
118  $this->lng->txt('dir_created') . $target,
120  )
121  );
122  }
123  }
recursiveCopy(string $src, string $dest)
Recursive copy of a folder.
+ Here is the call graph for this function:

◆ delete()

ilFileSystemHelper::delete ( string  $file_path)

Definition at line 47 of file class.ilFileSystemHelper.php.

47  : void
48  {
49  unlink($file_path);
50  }

◆ getMessageStack()

ilFileSystemHelper::getMessageStack ( )

Definition at line 207 of file class.ilFileSystemHelper.php.

References $message_stack.

Referenced by changeResourceDirectory(), createResourceDirectory(), removeResourceDirectory(), and saveDeleteFile().

208  {
209  return $this->message_stack;
210  }
Used to stack messages to be shown to the user.
ilSystemStyleMessageStack $message_stack
Used to stack messages to be displayed to the user (mostly reports for failed actions) ...
+ Here is the caller graph for this function:

◆ move()

ilFileSystemHelper::move ( string  $from,
string  $to 
)

Used to move a complete directory of a skin.

Definition at line 42 of file class.ilFileSystemHelper.php.

42  : void
43  {
44  rename($from, $to);
45  }

◆ recursiveCopy()

ilFileSystemHelper::recursiveCopy ( string  $src,
string  $dest 
)

Recursive copy of a folder.

Exceptions
ilSystemStyleException

Definition at line 170 of file class.ilFileSystemHelper.php.

References Vendor\Package\$e, ilSystemStyleException\FILE_CREATION_FAILED, ilSystemStyleException\FILE_OPENING_FAILED, and ilSystemStyleException\FOLDER_CREATION_FAILED.

Referenced by changeResourceDirectory(), ilSkinFactory\copyFromSkinStyleContainer(), and createResourceDirectory().

170  : void
171  {
172  foreach (scandir($src) as $file) {
173  $src_file = rtrim($src, '/') . '/' . $file;
174  $dest_file = rtrim($dest, '/') . '/' . $file;
175  if (!is_readable($src_file)) {
177  }
178  if (substr($file, 0, 1) != '.') {
179  if (is_dir($src_file)) {
180  if (!file_exists($dest_file)) {
181  try {
182  mkdir($dest_file);
183  } catch (Exception $e) {
184  throw new ilSystemStyleException(
186  'Copy ' . $src_file . ' to ' . $dest_file . ' Error: ' . $e
187  );
188  }
189  }
190  $this->recursiveCopy($src_file, $dest_file);
191  } else {
192  try {
193  copy($src_file, $dest_file);
194  } catch (Exception $e) {
195  throw new ilSystemStyleException(
197  'Copy ' . $src_file . ' to ' . $dest_file . ' Error: ' . $e
198  );
199  }
200  }
201  }
202  }
203  }
recursiveCopy(string $src, string $dest)
Recursive copy of a folder.
+ Here is the caller graph for this function:

◆ recursiveRemoveDir()

ilFileSystemHelper::recursiveRemoveDir ( string  $dir)

Recursive delete of a folder.

Definition at line 71 of file class.ilFileSystemHelper.php.

Referenced by changeResourceDirectory().

71  : void
72  {
73  if (is_dir($dir)) {
74  $objects = scandir($dir);
75  foreach ($objects as $object) {
76  if ($object != '.' && $object != '..') {
77  if (is_dir($dir . '/' . $object)) {
78  $this->recursiveRemoveDir($dir . '/' . $object);
79  } else {
80  unlink($dir . '/' . $object);
81  }
82  }
83  }
84  rmdir($dir);
85  }
86  }
recursiveRemoveDir(string $dir)
Recursive delete of a folder.
+ Here is the caller graph for this function:

◆ removeResourceDirectory()

ilFileSystemHelper::removeResourceDirectory ( string  $skin_dir,
string  $dir 
)

Deletes a resource directory.

Definition at line 91 of file class.ilFileSystemHelper.php.

References getMessageStack(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_SUCCESS.

92  {
93  $absolut_dir = $skin_dir . $dir;
94 
95  if (file_exists($absolut_dir)) {
96  self::recursiveRemoveDir($absolut_dir);
97  $this->getMessageStack()->addMessage(
99  $this->lng->txt('dir_deleted') . ' ' . $dir,
101  )
102  );
103  }
104  }
+ Here is the call graph for this function:

◆ saveDeleteFile()

ilFileSystemHelper::saveDeleteFile ( string  $file_path)

Deletes a given file in the container.

Definition at line 55 of file class.ilFileSystemHelper.php.

References getMessageStack(), ILIAS\Repository\lng(), and ilSystemStyleMessage\TYPE_SUCCESS.

55  : void
56  {
57  if (file_exists($file_path)) {
58  unlink($file_path);
59  $this->getMessageStack()->addMessage(
61  $this->lng->txt('file_deleted') . ' ' . $file_path,
63  )
64  );
65  }
66  }
+ Here is the call graph for this function:

◆ setMessageStack()

ilFileSystemHelper::setMessageStack ( ilSystemStyleMessageStack  $message_stack)

Definition at line 212 of file class.ilFileSystemHelper.php.

References $message_stack.

Referenced by __construct().

212  : void
213  {
214  $this->message_stack = $message_stack;
215  }
ilSystemStyleMessageStack $message_stack
Used to stack messages to be displayed to the user (mostly reports for failed actions) ...
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

ilLanguage ilFileSystemHelper::$lng
protected

Definition at line 31 of file class.ilFileSystemHelper.php.

Referenced by __construct().

◆ $message_stack

ilSystemStyleMessageStack ilFileSystemHelper::$message_stack
protected

Used to stack messages to be displayed to the user (mostly reports for failed actions)

Definition at line 30 of file class.ilFileSystemHelper.php.

Referenced by getMessageStack(), and setMessageStack().


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