From 0d7c17aa888fbd7a69be8f86981e855ea5d5c640 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 20 Aug 2016 12:02:41 +0200 Subject: [PATCH] Fix after bug fixes and file changes --- Log/FileLogger.php | 5 ++-- System/File/Directory.php | 8 +++--- System/File/File.php | 28 +++++++++++++++++-- System/File/FileInterface.php | 4 +-- Uri/Http.php | 52 ++++++++++++++++++++--------------- Views/View.php | 4 +-- Views/ViewAbstract.php | 9 ------ 7 files changed, 64 insertions(+), 46 deletions(-) diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 3095c4402..653c489f1 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -104,12 +104,11 @@ class FileLogger implements LoggerInterface } if (is_dir($lpath) || strpos($lpath, '.') === false) { - Directory::create($lpath, '0644'); - File::createFile($path = $lpath . '/' . date('Y-m-d') . '.log'); + File::create($path = $lpath . '/' . date('Y-m-d') . '.log'); $path = realpath($path); } else { - File::createFile($lpath); + File::create($lpath); $path = realpath($lpath); } diff --git a/System/File/Directory.php b/System/File/Directory.php index 09c7b8b82..f3562ca4d 100644 --- a/System/File/Directory.php +++ b/System/File/Directory.php @@ -235,7 +235,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess */ public function createNode() : bool { - return self::createPath($this->path, $this->permission, true); + return self::create($this->path, $this->permission, true); } /** @@ -433,7 +433,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess // TODO: Implement owner() method. } - public static function permission(string $path) : string + public static function permission(string $path) : int { // TODO: Implement permission() method. } @@ -463,13 +463,13 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess // TODO: Implement get() method. } - public static function size(string $path) : string + public static function size(string $path) : int { // TODO: Implement size() method. } public static function exists(string $path) : bool { - // TODO: Implement exists() method. + return file_exists($path); } } \ No newline at end of file diff --git a/System/File/File.php b/System/File/File.php index fd4c92dfb..063046f7b 100644 --- a/System/File/File.php +++ b/System/File/File.php @@ -49,6 +49,16 @@ class File extends FileAbstract } } + public function getDirName() : string + { + return basename(dirname($this->path)); + } + + public function getDirPath() : string + { + return dirname($this->path); + } + /** * Index file. * @@ -113,6 +123,18 @@ class File extends FileAbstract return false; } + public function getFileName() : string + { + return explode('.', $this->name)[0]; + } + + public function getExtension() : string + { + $extension = explode('.', $this->name); + + return $extension[1] ?? ''; + } + public static function get(string $path) : string { if(!file_exists($path)) { @@ -127,7 +149,7 @@ class File extends FileAbstract return file_exists($path); } - public static function create(string $path) : string + public static function create(string $path) : bool { if(!file_exists($path)) { if(!Directory::exists(dirname($path))) { @@ -186,7 +208,7 @@ class File extends FileAbstract throw new PathException($path); } - return fileperms($path); + return fileowner($path); } public static function permission(string $path) : int @@ -195,7 +217,7 @@ class File extends FileAbstract throw new PathException($path); } - return fileowner($path); + return fileperms($path); } public static function dirname(string $path) : string diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php index b2425bb11..c3518ed3b 100644 --- a/System/File/FileInterface.php +++ b/System/File/FileInterface.php @@ -68,7 +68,7 @@ interface FileInterface public static function owner(string $path) : int; - public static function permission(string $path) : string; + public static function permission(string $path) : int; public static function parent(string $path) : string; @@ -84,7 +84,7 @@ interface FileInterface public static function get(string $path) : string; - public static function size(string $path) : string; + public static function size(string $path) : int; public static function exists(string $path) : bool; } diff --git a/Uri/Http.php b/Uri/Http.php index 98e5d6d7d..425906bc9 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -95,13 +95,21 @@ class Http implements UriInterface */ private $path = ''; + /** + * Uri query. + * + * @var array + * @since 1.0.0 + */ + private $query = []; + /** * Uri query. * * @var string * @since 1.0.0 */ - private $query = null; + private $queryString = ''; /** * Uri fragment. @@ -138,18 +146,18 @@ class Http implements UriInterface public function set(string $uri) { $this->uri = $uri; + $url = parse_url($this->uri); - $url = parse_url($this->uri); - - $this->scheme = $url['scheme'] ?? ''; - $this->host = $url['host'] ?? null; - $this->port = $url['port'] ?? null; - $this->user = $url['user'] ?? null; - $this->pass = $url['pass'] ?? null; - $this->path = $url['path'] ?? null; - $this->path = rtrim($this->path, '.php'); - $this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; // TODO: this could cause a bug if the rootpath is the same as a regular path which is usually the language - $this->query = $url['query'] ?? null; + $this->scheme = $url['scheme'] ?? ''; + $this->host = $url['host'] ?? null; + $this->port = $url['port'] ?? null; + $this->user = $url['user'] ?? null; + $this->pass = $url['pass'] ?? null; + $this->path = $url['path'] ?? null; + $this->path = rtrim($this->path, '.php'); + $this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; // TODO: this could cause a bug if the rootpath is the same as a regular path which is usually the language + $this->query = $url['query'] ?? null; + $this->queryString = $this->query; if (isset($this->query)) { parse_str($this->query, $this->query); @@ -192,7 +200,7 @@ class Http implements UriInterface */ public function getRootPath() : string { - return $this->rootPath; + return $this->rootPath ?? ''; } /** @@ -209,7 +217,7 @@ class Http implements UriInterface */ public function getScheme() : string { - return $this->scheme; + return $this->scheme ?? ''; } /** @@ -217,7 +225,7 @@ class Http implements UriInterface */ public function getHost() : string { - return $this->host; + return $this->host ?? ''; } /** @@ -225,7 +233,7 @@ class Http implements UriInterface */ public function getPort() : int { - return $this->port; + return $this->port ?? 80; } /** @@ -238,7 +246,7 @@ class Http implements UriInterface */ public function getPass() : string { - return $this->pass; + return $this->pass ?? ''; } /** @@ -246,7 +254,7 @@ class Http implements UriInterface */ public function getPath() : string { - return $this->path; + return $this->path ?? ''; } /** @@ -254,7 +262,7 @@ class Http implements UriInterface */ public function getQuery(string $key = null) { - return isset($key) ? $this->query[$key] ?? null : $this->query; + return isset($key) ? $this->query[$key] ?? null : $this->queryString ?? ''; } /** @@ -262,7 +270,7 @@ class Http implements UriInterface */ public function getFragment() : string { - return $this->fragment; + return $this->fragment ?? ''; } /** @@ -270,7 +278,7 @@ class Http implements UriInterface */ public function getBase() : string { - return $this->base; + return $this->base ?? ''; } /** @@ -299,7 +307,7 @@ class Http implements UriInterface */ public function getUser() : string { - return $this->user; + return $this->user ?? ''; } /** diff --git a/Views/View.php b/Views/View.php index 3aab87f38..36d8a4bc6 100644 --- a/Views/View.php +++ b/Views/View.php @@ -19,8 +19,6 @@ use phpOMS\ApplicationAbstract; use phpOMS\Localization\Localization; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; -use phpOMS\System\File\PathException; -use phpOMS\Utils\StringUtils; /** * List view. @@ -169,7 +167,7 @@ class View extends ViewAbstract * @since 1.0.0 * @author Dennis Eichhorn */ - private function getText(string $translation, string $module = null, string $theme = null) + protected function getText(string $translation, string $module = null, string $theme = null) { if (!isset($module)) { $match = '/Modules/'; diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index b465318c7..2c815db5b 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -15,12 +15,7 @@ */ namespace phpOMS\Views; -use phpOMS\ApplicationAbstract; -use phpOMS\Localization\Localization; -use phpOMS\Message\RequestAbstract; -use phpOMS\Message\ResponseAbstract; use phpOMS\System\File\PathException; -use phpOMS\Utils\StringUtils; /** * List view. @@ -55,10 +50,6 @@ abstract class ViewAbstract implements \Serializable /** * Constructor. * - * @param ApplicationAbstract $app Application - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Request - * * @since 1.0.0 * @author Dennis Eichhorn */