| @@ 32-171 (lines=140) @@ | ||
| 29 | use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse; |
|
| 30 | use \HOWI3\libhowi\Filesystem\php5\TraitForSharedMethods; |
|
| 31 | ||
| 32 | class DirectoryPlaceholderObject extends Directory implements DirectoryPlaceholderInterface, |
|
| 33 | SharedMethodsInterface |
|
| 34 | { |
|
| 35 | use TraitForResponse; |
|
| 36 | use TraitForSharedMethods; |
|
| 37 | ||
| 38 | public $path = ''; |
|
| 39 | ||
| 40 | public $handle; |
|
| 41 | ||
| 42 | private $mode = 750; |
|
| 43 | ||
| 44 | private $recursive = true; |
|
| 45 | ||
| 46 | private $context = false; |
|
| 47 | ||
| 48 | /** |
|
| 49 | * |
|
| 50 | * {@inheritDoc} |
|
| 51 | * |
|
| 52 | */ |
|
| 53 | public function __construct($pathname = false, $recursive = true, $mode = false, $context = false, $logfile = false, |
|
| 54 | $loglevel = false, $UID = false, $username = false) |
|
| 55 | { |
|
| 56 | if (! empty($logfile) && file_exists($logfile) && ! empty($loglevel)) { |
|
| 57 | $this->setLogfile($logfile); |
|
| 58 | $this->setLoglevel($loglevel); |
|
| 59 | $this->setUID($UID); |
|
| 60 | $this->setUsername($username); |
|
| 61 | } |
|
| 62 | ||
| 63 | $pathname = (! empty($pathname) ? $this->makeAbsolute($pathname) : $this->path); |
|
| 64 | ||
| 65 | $HID = md5($pathname); |
|
| 66 | ||
| 67 | $this->dirsetPath($pathname, $HID); |
|
| 68 | $this->dirsetMode(! empty($mode) ? $mode : $this->mode, $HID); |
|
| 69 | ||
| 70 | $this->dirsetRecursive(! empty($recursive) ? true : false, $HID); |
|
| 71 | ||
| 72 | $context = ! empty($context) ? $this->dirsetContext($context, $HID) : false; |
|
| 73 | ||
| 74 | $this->info(701, $pathname); |
|
| 75 | $this->response()->setStatus($this->dirCreate($HID)); |
|
| 76 | } |
|
| 77 | ||
| 78 | /** |
|
| 79 | * |
|
| 80 | * {@inheritDoc} |
|
| 81 | * |
|
| 82 | */ |
|
| 83 | public function dirsetPath($pathname = false, $HID = false) |
|
| 84 | { |
|
| 85 | if (! empty($pathname) && is_string($pathname) && ! empty($HID)) { |
|
| 86 | ||
| 87 | $this->path = $this->makeAbsolute($pathname); |
|
| 88 | ||
| 89 | return true; |
|
| 90 | } else { |
|
| 91 | $this->debug(802, 'DirectoryTrait->dirsetPath'); |
|
| 92 | return false; |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * |
|
| 98 | * {@inheritDoc} |
|
| 99 | * |
|
| 100 | */ |
|
| 101 | public function dirsetMode($mode = false, $HID = false) |
|
| 102 | { |
|
| 103 | if (! empty($HID) && ! empty($mode) && is_int($mode)) { |
|
| 104 | $this->mode = $mode; |
|
| 105 | return true; |
|
| 106 | } else { |
|
| 107 | ||
| 108 | $this->debug(802, 'DirectoryTrait->dirsetMode'); |
|
| 109 | return false; |
|
| 110 | } |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * |
|
| 115 | * {@inheritDoc} |
|
| 116 | * |
|
| 117 | */ |
|
| 118 | public function dirsetRecursive($recursive = false, $HID = false) |
|
| 119 | { |
|
| 120 | if (! empty($HID) && is_bool($recursive)) { |
|
| 121 | $this->recursive = $recursive; |
|
| 122 | return true; |
|
| 123 | } else { |
|
| 124 | $this->debug(802, 'DirectoryTrait->dirsetRecursive'); |
|
| 125 | } |
|
| 126 | ||
| 127 | return false; |
|
| 128 | } |
|
| 129 | ||
| 130 | /** |
|
| 131 | * |
|
| 132 | * {@inheritDoc} |
|
| 133 | * |
|
| 134 | */ |
|
| 135 | public function dirsetContext($context = false, $HID = false) |
|
| 136 | { |
|
| 137 | if (! empty($HID) && is_resource($context)) { |
|
| 138 | $this->context = $context; |
|
| 139 | return true; |
|
| 140 | } |
|
| 141 | ||
| 142 | else { |
|
| 143 | $this->debug(802, 'DirectoryTrait->dirsetContext'); |
|
| 144 | return false; |
|
| 145 | } |
|
| 146 | } |
|
| 147 | ||
| 148 | /** |
|
| 149 | * |
|
| 150 | * {@inheritDoc} |
|
| 151 | * |
|
| 152 | */ |
|
| 153 | public function dirCreate($HID = false) |
|
| 154 | { |
|
| 155 | if ((! is_dir(dirname($this->path)) && $this->recursive === false) || |
|
| 156 | is_dir(dirname($this->path)) && ! $this->isWritable(dirname($this->path))) { |
|
| 157 | $this->warning(502, $this->path); |
|
| 158 | $result = false; |
|
| 159 | } else { |
|
| 160 | if (! empty($HID) && ! $this->exists($this->path) && ! empty($this->context)) { |
|
| 161 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), |
|
| 162 | $this->recursive, $this->context); |
|
| 163 | } |
|
| 164 | if (! empty($HID) && ! $this->exists($this->path) && empty($this->context)) { |
|
| 165 | ||
| 166 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), true); |
|
| 167 | } |
|
| 168 | } |
|
| 169 | return $result; |
|
| 170 | } |
|
| 171 | } |
|
| 172 | ||
| @@ 32-171 (lines=140) @@ | ||
| 29 | use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse; |
|
| 30 | use \HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods; |
|
| 31 | ||
| 32 | class DirectoryPlaceholderObject extends Directory implements DirectoryPlaceholderInterface, |
|
| 33 | SharedMethodsInterface |
|
| 34 | { |
|
| 35 | use TraitForResponse; |
|
| 36 | use TraitForSharedMethods; |
|
| 37 | ||
| 38 | public $path = ''; |
|
| 39 | ||
| 40 | public $handle; |
|
| 41 | ||
| 42 | private $mode = 750; |
|
| 43 | ||
| 44 | private $recursive = true; |
|
| 45 | ||
| 46 | private $context = false; |
|
| 47 | ||
| 48 | /** |
|
| 49 | * |
|
| 50 | * {@inheritDoc} |
|
| 51 | * |
|
| 52 | */ |
|
| 53 | public function __construct($pathname = false, $recursive = true, $mode = false, $context = false, $logfile = false, |
|
| 54 | $loglevel = false, $UID = false, $username = false) |
|
| 55 | { |
|
| 56 | if (! empty($logfile) && file_exists($logfile) && ! empty($loglevel)) { |
|
| 57 | $this->setLogfile($logfile); |
|
| 58 | $this->setLoglevel($loglevel); |
|
| 59 | $this->setUID($UID); |
|
| 60 | $this->setUsername($username); |
|
| 61 | } |
|
| 62 | ||
| 63 | $pathname = (! empty($pathname) ? $this->makeAbsolute($pathname) : $this->path); |
|
| 64 | ||
| 65 | $HID = md5($pathname); |
|
| 66 | ||
| 67 | $this->dirsetPath($pathname, $HID); |
|
| 68 | $this->dirsetMode(! empty($mode) ? $mode : $this->mode, $HID); |
|
| 69 | ||
| 70 | $this->dirsetRecursive(! empty($recursive) ? true : false, $HID); |
|
| 71 | ||
| 72 | $context = ! empty($context) ? $this->dirsetContext($context, $HID) : false; |
|
| 73 | ||
| 74 | $this->info(701, $pathname); |
|
| 75 | $this->response()->setStatus($this->dirCreate($HID)); |
|
| 76 | } |
|
| 77 | ||
| 78 | /** |
|
| 79 | * |
|
| 80 | * {@inheritDoc} |
|
| 81 | * |
|
| 82 | */ |
|
| 83 | public function dirsetPath($pathname = false, $HID = false) |
|
| 84 | { |
|
| 85 | if (! empty($pathname) && is_string($pathname) && ! empty($HID)) { |
|
| 86 | ||
| 87 | $this->path = $this->makeAbsolute($pathname); |
|
| 88 | ||
| 89 | return true; |
|
| 90 | } else { |
|
| 91 | $this->debug(802, 'DirectoryTrait->dirsetPath'); |
|
| 92 | return false; |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * |
|
| 98 | * {@inheritDoc} |
|
| 99 | * |
|
| 100 | */ |
|
| 101 | public function dirsetMode($mode = false, $HID = false) |
|
| 102 | { |
|
| 103 | if (! empty($HID) && ! empty($mode) && is_int($mode)) { |
|
| 104 | $this->mode = $mode; |
|
| 105 | return true; |
|
| 106 | } else { |
|
| 107 | ||
| 108 | $this->debug(802, 'DirectoryTrait->dirsetMode'); |
|
| 109 | return false; |
|
| 110 | } |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * |
|
| 115 | * {@inheritDoc} |
|
| 116 | * |
|
| 117 | */ |
|
| 118 | public function dirsetRecursive($recursive = false, $HID = false) |
|
| 119 | { |
|
| 120 | if (! empty($HID) && is_bool($recursive)) { |
|
| 121 | $this->recursive = $recursive; |
|
| 122 | return true; |
|
| 123 | } else { |
|
| 124 | $this->debug(802, 'DirectoryTrait->dirsetRecursive'); |
|
| 125 | } |
|
| 126 | ||
| 127 | return false; |
|
| 128 | } |
|
| 129 | ||
| 130 | /** |
|
| 131 | * |
|
| 132 | * {@inheritDoc} |
|
| 133 | * |
|
| 134 | */ |
|
| 135 | public function dirsetContext($context = false, $HID = false) |
|
| 136 | { |
|
| 137 | if (! empty($HID) && is_resource($context)) { |
|
| 138 | $this->context = $context; |
|
| 139 | return true; |
|
| 140 | } |
|
| 141 | ||
| 142 | else { |
|
| 143 | $this->debug(802, 'DirectoryTrait->dirsetContext'); |
|
| 144 | return false; |
|
| 145 | } |
|
| 146 | } |
|
| 147 | ||
| 148 | /** |
|
| 149 | * |
|
| 150 | * {@inheritDoc} |
|
| 151 | * |
|
| 152 | */ |
|
| 153 | public function dirCreate($HID = false) |
|
| 154 | { |
|
| 155 | if ((! is_dir(dirname($this->path)) && $this->recursive === false) || |
|
| 156 | is_dir(dirname($this->path)) && ! $this->isWritable(dirname($this->path))) { |
|
| 157 | $this->warning(502, $this->path); |
|
| 158 | $result = false; |
|
| 159 | } else { |
|
| 160 | if (! empty($HID) && ! $this->exists($this->path) && ! empty($this->context)) { |
|
| 161 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), |
|
| 162 | $this->recursive, $this->context); |
|
| 163 | } |
|
| 164 | if (! empty($HID) && ! $this->exists($this->path) && empty($this->context)) { |
|
| 165 | ||
| 166 | $result = mkdir($this->path, octdec(str_pad($this->mode, 4, 0, STR_PAD_LEFT)), true); |
|
| 167 | } |
|
| 168 | } |
|
| 169 | return $result; |
|
| 170 | } |
|
| 171 | } |
|
| 172 | ||