Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UFileSystemWriter.php
Go to the documentation of this file.
1<?php
2
4
6
8
9 public static function openReplaceInTemplateFile($source, $keyAndValues) {
10 if (\file_exists($source)) {
11 $str=\file_get_contents($source);
12 return self::replaceFromTemplate($str, $keyAndValues);
13 }
14 return false;
15 }
16
17 public static function openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues) {
18 if (($str=self::openReplaceInTemplateFile($source, $keyAndValues))) {
19 return \file_put_contents($destination, $str, LOCK_EX);
20 }
21 return false;
22 }
23
24 public static function replaceFromTemplate($content, $keyAndValues) {
25 \array_walk($keyAndValues, function (&$item) {
26 if (\is_array($item))
27 $item=\implode("\n", $item);
28 });
29 $str=\str_replace(\array_keys($keyAndValues), \array_values($keyAndValues), $content);
30 return $str;
31 }
32
33 public static function replaceWriteFromContent($content, $destination, $keyAndValues) {
34 return \file_put_contents($destination, self::replaceFromTemplate($content, $keyAndValues), LOCK_EX);
35 }
36
37 public static function save($filename,$content,$flags=LOCK_EX){
38 return \file_put_contents($filename, $content, $flags);
39 }
40
41 public static function xcopy($source, $dest, $permissions = 0755){
42 if (\is_link($source)) {
43 return \symlink(\readlink($source), $dest);
44 }
45 if (\is_file($source)) {
46 return \copy($source, $dest);
47 }
48 if (!\is_dir($dest)) {
49 \mkdir($dest, $permissions,true);
50 }
51 $dir = \dir($source);
52 while (false !== $entry = $dir->read()) {
53 if ($entry == '.' || $entry == '..') {
54 continue;
55 }
56 self::xcopy("$source/$entry", "$dest/$entry", $permissions);
57 }
58 $dir->close();
59 return true;
60 }
61
62 public static function xmove(string $source,string $dest, int $permission=0755):bool {
63 if (\is_link($source)) {
64 if( \symlink(\readlink($source), $dest)){
65 return \unlink($source);
66 }
67 return false;
68 }
69 if(self::xcopy($source, $dest,$permission)){
70 if(\is_dir($source)){
71 return UFileSystem::delTree($source);
72 }
73 return \unlink($source);
74 }
75 return false;
76 }
77}
78
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
static delTree($dir)
Deletes recursivly a folder and its content.
static xmove(string $source, string $dest, int $permission=0755)
static replaceFromTemplate($content, $keyAndValues)
static openReplaceInTemplateFile($source, $keyAndValues)
static replaceWriteFromContent($content, $destination, $keyAndValues)
static save($filename, $content, $flags=LOCK_EX)
static xcopy($source, $dest, $permissions=0755)
static openReplaceWriteFromTemplateFile($source, $destination, $keyAndValues)