diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 70cfba3a9..3095c4402 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -104,7 +104,7 @@ class FileLogger implements LoggerInterface } if (is_dir($lpath) || strpos($lpath, '.') === false) { - Directory::createPath($lpath, '0644'); + Directory::create($lpath, '0644'); File::createFile($path = $lpath . '/' . date('Y-m-d') . '.log'); $path = realpath($path); diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 3036fcf88..12f6df690 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -204,8 +204,14 @@ class Request extends RequestAbstract UriFactory::setQuery('/scheme', $this->uri->getScheme()); UriFactory::setQuery('/host', $this->uri->getHost()); UriFactory::setQuery('/lang', $this->l11n->getLanguage()); + UriFactory::setQuery('/base', $this->uri->getBase()); + UriFactory::setQuery('/rootPath', $this->uri->getRootPath()); UriFactory::setQuery('?', $this->uri->getQuery()); UriFactory::setQuery('%', $this->uri->__toString()); + UriFactory::setQuery('#', $this->uri->getFragment()); + UriFactory::setQuery('/', $this->uri->getPath()); + UriFactory::setQuery(':user', $this->uri->getUser()); + UriFactory::setQuery(':pass', $this->uri->getPass()); } /** diff --git a/Router/RouteVerb.php b/Router/RouteVerb.php index 386a8f763..37de149e0 100644 --- a/Router/RouteVerb.php +++ b/Router/RouteVerb.php @@ -32,7 +32,7 @@ abstract class RouteVerb extends Enum { const GET = 1; const PUT = 2; - const SET = 3; - const DELETE = 4; - const ANY = 5; + const SET = 4; + const DELETE = 8; + const ANY = 16; } diff --git a/Router/Router.php b/Router/Router.php index ed529f03d..759a753f6 100644 --- a/Router/Router.php +++ b/Router/Router.php @@ -76,14 +76,14 @@ class Router * * @param string $route Route regex * @param mixed $destination Destination e.g. Module:function & verb - * @param string $verb Request verb + * @param int $verb Request verb * * @return void * * @since 1.0.0 * @author Dennis Eichhorn */ - public function add(string $route, $destination, string $verb = RouteVerb::GET) + public function add(string $route, $destination, int $verb = RouteVerb::GET) { if(!isset($this->routes[$route])) { $this->routes[$route] = []; @@ -99,6 +99,7 @@ class Router * Route request. * * @param RequestAbstract $request Request to route + * @param int $verb Route verb * * @return string[] * @@ -107,7 +108,7 @@ class Router * @since 1.0.0 * @author Dennis Eichhorn */ - public function route($request, string $verb = RouteVerb::GET) : array + public function route($request, int $verb = RouteVerb::GET) : array { if($request instanceof RequestAbstract) { $uri = $request->getUri(); @@ -134,17 +135,17 @@ class Router * Match route and uri. * * @param string $route Route - * @param string $routeVerb GET,POST for this route + * @param int $routeVerb GET,POST for this route * @param string $uri Uri - * @param string $remoteVerb Verb this request is using + * @param int $remoteVerb Verb this request is using * * @return bool * * @since 1.0.0 * @author Dennis Eichhorn */ - private function match(string $route, string $routeVerb, string $uri, string $remoteVerb = RouteVerb::GET) : bool + private function match(string $route, int $routeVerb, string $uri, int $remoteVerb = RouteVerb::GET) : bool { - return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb == RouteVerb::ANY || $remoteVerb == $routeVerb); + return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb == RouteVerb::ANY || $remoteVerb & $routeVerb === $remoteVerb); } } diff --git a/System/File/Directory.php b/System/File/Directory.php index 41e632433..09c7b8b82 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -225,7 +225,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess * @since 1.0.0 * @author Dennis Eichhorn */ - public function get(string $name) : FileAbstract + public function getNode(string $name) : FileAbstract { return $this->nodes[$name] ?? new NullFile(''); } @@ -250,7 +250,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess * @since 1.0.0 * @author Dennis Eichhorn */ - public static function createPath(string $path, string $permission = '0644', bool $recursive = true) : bool + public static function create(string $path, string $permission = '0644', bool $recursive = false) : bool { if (!file_exists($path)) { mkdir($path, $permission, $recursive); @@ -271,7 +271,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess * @since 1.0.0 * @author Dennis Eichhorn */ - public static function getParent(string $path) : string + public static function parent(string $path) : string { $path = explode('/', str_replace('\\', '/', $path)); array_pop($path); @@ -387,4 +387,89 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess { return $this->nodes[$offset] ?? null; } + + public function getParent() : FileInterface + { + // TODO: Implement getParent() method. + } + + public function copyNode() : bool + { + // TODO: Implement copyNode() method. + } + + public function moveNode() : bool + { + // TODO: Implement moveNode() method. + } + + public function deleteNode() : bool + { + // TODO: Implement deleteNode() method. + } + + public function putContent() : bool + { + // TODO: Implement putContent() method. + } + + public function getContent() : string + { + // TODO: Implement getContent() method. + } + + public static function created(string $path) : \DateTime + { + // TODO: Implement created() method. + } + + public static function changed(string $path) : \DateTime + { + // TODO: Implement changed() method. + } + + public static function owner(string $path) : int + { + // TODO: Implement owner() method. + } + + public static function permission(string $path) : string + { + // TODO: Implement permission() method. + } + + public static function delete(string $path) : bool + { + // TODO: Implement delete() method. + } + + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + // TODO: Implement copy() method. + } + + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + // TODO: Implement move() method. + } + + public static function put(string $path, string $content, bool $overwrite = true) : bool + { + // TODO: Implement put() method. + } + + public static function get(string $path) : string + { + // TODO: Implement get() method. + } + + public static function size(string $path) : string + { + // TODO: Implement size() method. + } + + public static function exists(string $path) : bool + { + // TODO: Implement exists() method. + } } \ No newline at end of file diff --git a/System/File/File.php b/System/File/File.php index 04b772282..fd4c92dfb 100644 --- a/System/File/File.php +++ b/System/File/File.php @@ -69,32 +69,7 @@ class File extends FileAbstract */ public function createNode() : bool { - return self::createFile($this->path); - } - - /** - * Create file. - * - * @param string $path Path - * - * @return bool - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public static function createFile(string $path) : bool - { - if (!file_exists($path)) { - if (is_writable(Directory::getParent($path))) { - touch($path); - - return true; - } else { - throw new PermissionException($path); - } - } - - return false; + return self::create($this->path); } /** @@ -123,14 +98,182 @@ class File extends FileAbstract file_put_contents($this->path, $content); } - public static function copy(string $p1, string $p2, bool $recursive = true) : bool + public static function put(string $path, string $content, bool $overwrite = true) : bool { - Directory::createPath(dirname($p2)); + if($overwrite || !file_exists($path)) { + if(!Directory::exists(dirname($path))) { + Directory::create(dirname($path), '0644', true); + } - if(realpath($p1) === false) { - throw new PathException($p1); + file_put_contents($path, $content); + + return true; } - return copy($p1, $p2); + return false; + } + + public static function get(string $path) : string + { + if(!file_exists($path)) { + throw new PathException($path); + } + + return file_get_contents($path); + } + + public static function exists(string $path) : bool + { + return file_exists($path); + } + + public static function create(string $path) : string + { + if(!file_exists($path)) { + if(!Directory::exists(dirname($path))) { + Directory::create(dirname($path), '0644', true); + } + + touch($path); + + return true; + } + + return false; + } + + public static function parent(string $path) : string + { + return Directory::parent(dirname($path)); + } + + public static function created(string $path) : \DateTime + { + if(!file_exists($path)) { + throw new PathException($path); + } + + $created = new \DateTime(); + $created->setTimestamp(filemtime($path)); + + return $created; + } + + public static function changed(string $path) : \DateTime + { + if(!file_exists($path)) { + throw new PathException($path); + } + + $changed = new \DateTime(); + $changed->setTimestamp(filectime($path)); + + return $changed; + } + + public static function size(string $path) : int + { + if(!file_exists($path)) { + throw new PathException($path); + } + + return filesize($path); + } + + public static function owner(string $path) : int + { + if(!file_exists($path)) { + throw new PathException($path); + } + + return fileperms($path); + } + + public static function permission(string $path) : int + { + if(!file_exists($path)) { + throw new PathException($path); + } + + return fileowner($path); + } + + public static function dirname(string $path) : string + { + return dirname($path); + } + + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + if(!file_exists($from)) { + throw new PathException($from); + } + + if($overwrite || !file_exists($to)) { + if(!Directory::exists(dirname($to))) { + Directory::create(dirname($to), '0644', true); + } + + copy($from, $to); + + return true; + } + + return false; + } + + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + if(!file_exists($from)) { + throw new PathException($from); + } + + if($overwrite || !file_exists($to)) { + if(!Directory::exists(dirname($to))) { + Directory::create(dirname($to), '0644', true); + } + + rename($from, $to); + + return true; + } + + return false; + } + + public static function delete(string $path) : bool + { + if(!file_exists($path)) { + return false; + } + + unlink($path); + + return true; + } + + public function getParent() : FileInterface + { + // TODO: Implement getParent() method. + } + + public function copyNode() : bool + { + // TODO: Implement copyNode() method. + } + + public function moveNode() : bool + { + // TODO: Implement moveNode() method. + } + + public function deleteNode() : bool + { + // TODO: Implement deleteNode() method. + } + + public function putContent() : bool + { + // TODO: Implement putContent() method. } } \ No newline at end of file diff --git a/System/File/FileAbstract.php b/System/File/FileAbstract.php index 96a3a184e..ba0bef6be 100644 --- a/System/File/FileAbstract.php +++ b/System/File/FileAbstract.php @@ -28,7 +28,7 @@ namespace phpOMS\System\File; * @link http://orange-management.com * @since 1.0.0 */ -abstract class FileAbstract +abstract class FileAbstract implements FileInterface { /** * Path. @@ -171,9 +171,9 @@ abstract class FileAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - public function parent() : Directory + public function parentNode() : Directory { - return new Directory(Directory::getParent($this->path)); + return new Directory(Directory::parent($this->path)); } /** diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php new file mode 100644 index 000000000..b2425bb11 --- /dev/null +++ b/System/File/FileInterface.php @@ -0,0 +1,90 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace phpOMS\System\File; + +/** + * Filesystem class. + * + * Performing operations on the file system + * + * @category Framework + * @package phpOMS\System\File + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +interface FileInterface +{ + public function getCount() : int; + + public function getSize() : int; + + public function getName() : string; + + public function getPath() : string; + + public function getParent() : FileInterface; + + public function createNode() : bool; + + public function copyNode() : bool; + + public function moveNode() : bool; + + public function deleteNode() : bool; + + public function putContent() : bool; + + public function getContent() : string; + + public function getCreatedAt() : \DateTime; + + public function getChangedAt() : \DateTime; + + public function getOwner() : int; + + public function getPermission() : string; + + public function index(); + + public static function created(string $path) : \DateTime; + + public static function changed(string $path) : \DateTime; + + public static function owner(string $path) : int; + + public static function permission(string $path) : string; + + public static function parent(string $path) : string; + + public static function create(string $path) : bool; + + public static function delete(string $path) : bool; + + public static function copy(string $from, string $to, bool $overwrite = false) : bool; + + public static function move(string $from, string $to, bool $overwrite = false) : bool; + + public static function put(string $path, string $content, bool $overwrite = true) : bool; + + public static function get(string $path) : string; + + public static function size(string $path) : string; + + public static function exists(string $path) : bool; +} diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index 10f8a8eba..b9d847c49 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -222,12 +222,27 @@ class ArrayUtils return $csv; } + /** + * Get array value by argument id. + * + * Useful for parsing command line parsing + * + * @param array $data Data to convert + * @param string $delimiter Delim to use + * @param string $enclosure Enclosure to use + * @param string $escape Escape to use + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public static function getArg(string $id, array $args) { if(($key = array_search($id, $args)) === false || $key === count($args) - 1) { return null; } - return $args[$key+1]; + return trim($args[$key+1], '" '); } }