mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Creating static create functions
This commit is contained in:
parent
ef243a7ee4
commit
6b84376742
|
|
@ -33,6 +33,21 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess
|
|||
private $filter = '*';
|
||||
private $nodes = [];
|
||||
|
||||
public static create(string $path, $permission = 0644) : bool
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
if(is_writable($path)) {
|
||||
mkdir($path, $permission, true);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new PathException($path);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct(string $path, string $filter = '*')
|
||||
{
|
||||
$this->filter = $filter;
|
||||
|
|
@ -112,7 +127,7 @@ class Directory extends FileAbstract implements Iterator, ArrayAccess
|
|||
{
|
||||
return next($this->node);
|
||||
}
|
||||
|
||||
|
||||
public function valid()
|
||||
{
|
||||
$key = key($this->node);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,22 @@ namespace phpOMS\System\File;
|
|||
*/
|
||||
class File extends FileAbstract
|
||||
{
|
||||
|
||||
public static create(string $path) : bool
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
if(is_writable($path)) {
|
||||
touch($path);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
throw new PathException($path);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct(string $path)
|
||||
{
|
||||
parent::__constrct($path);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user