mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-20 21:38:41 +00:00
Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # System/File/Directory.php # System/File/File.php
This commit is contained in:
commit
1c59c7bce0
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function parent() : Directory
|
||||
public function parentNode() : Directory
|
||||
{
|
||||
return new Directory(Directory::getParent($this->path));
|
||||
return new Directory(Directory::parent($this->path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
90
System/File/FileInterface.php
Normal file
90
System/File/FileInterface.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.0
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @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 <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @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;
|
||||
}
|
||||
|
|
@ -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 <d.eichhorn@oms.com>
|
||||
*/
|
||||
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], '" ');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user