mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-16 16:38:40 +00:00
Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop
This commit is contained in:
commit
877e56c5cd
|
|
@ -136,7 +136,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Account type.
|
||||
*
|
||||
* @var AccountType|int
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = AccountType::USER;
|
||||
|
|
@ -144,7 +144,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Account status.
|
||||
*
|
||||
* @var AccountStatus|int
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $status = AccountStatus::INACTIVE;
|
||||
|
|
@ -560,7 +560,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
*/
|
||||
public function generatePassword(string $password) /* : void */
|
||||
{
|
||||
$this->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$this->password = \password_hash($password, \PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -625,7 +625,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Json serialize.
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ class Group implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Json serialize.
|
||||
*
|
||||
* @return string
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@ class PermissionAbstract
|
|||
*
|
||||
* @param int $permission Permission
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Auth;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -754,6 +754,20 @@ class FinanceFormulas
|
|||
return log(2) / log(1 + $r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate to dobule
|
||||
*
|
||||
* @param float $t Time in which to double investment
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getDoublingRate(float $t) : float
|
||||
{
|
||||
return exp(log(2) / $t) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubling Time - Continuous Compounding
|
||||
*
|
||||
|
|
|
|||
|
|
@ -48,11 +48,10 @@ class Metrics {
|
|||
/**
|
||||
* Calculate the C.R.A.P score
|
||||
*
|
||||
* @latex r = \sqrt{a^{2} + b^{2} + c^{2}}
|
||||
* @latex r = com^{2} \times (1 - cov)^{3} + com
|
||||
*
|
||||
* @param int $a Assignments
|
||||
* @param int $b Branches
|
||||
* @param int $c Conditionals
|
||||
* @param int $complexity Complexity
|
||||
* @param int $coverage Coverage
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class CachePool implements OptionsInterface
|
|||
/**
|
||||
* MemCache instance.
|
||||
*
|
||||
* @var \phpOMS\DataStorage\Cache\CacheInterface
|
||||
* @var \phpOMS\DataStorage\Cache\CacheInterface[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $pool = null;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class MemCache implements CacheInterface
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->memc = new self();
|
||||
$this->memc = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
178
DataStorage/Cache/MemCached.php
Normal file
178
DataStorage/Cache/MemCached.php
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace phpOMS\DataStorage\Cache;
|
||||
|
||||
/**
|
||||
* Memcache class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Cache
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MemCached implements CacheInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Memcache instance.
|
||||
*
|
||||
* @var \Memcache
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $memc = null;
|
||||
|
||||
/**
|
||||
* Only cache if data is larger than threshold (0-100).
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $threshold = 10;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->memc = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding server to server pool.
|
||||
*
|
||||
* @param mixed $data Server data array
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addServer($data)
|
||||
{
|
||||
$this->memc->addServer($data['host'], $data['port'], $data['timeout']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, int $expire = -1) /* : void */
|
||||
{
|
||||
$this->memc->set($key, $value, false, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function add($key, $value, int $expire = -1) : bool
|
||||
{
|
||||
return $this->memc->add($key, $value, false, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($key, int $expire = -1)
|
||||
{
|
||||
return $this->memc->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($key, int $expire = -1) : bool
|
||||
{
|
||||
$this->memc->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function flush(int $expire = 0) : bool
|
||||
{
|
||||
$this->memc->flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function flushAll() : bool
|
||||
{
|
||||
$this->memc->flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function replace($key, $value, int $expire = -1) : bool
|
||||
{
|
||||
$this->memc->replace($key, $value, false, $expire);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function stats() : array
|
||||
{
|
||||
/** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
|
||||
return $this->memc->getExtendedStats();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getThreshold() : int
|
||||
{
|
||||
return $this->threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStatus(int $status) /* : void */
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closing cache.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
if ($this->memc !== null) {
|
||||
$this->memc->close();
|
||||
$this->memc = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -65,15 +65,15 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
/**
|
||||
* Database type.
|
||||
*
|
||||
* @var \phpOMS\DataStorage\Database\DatabaseType
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = null;
|
||||
protected $type = 'undefined';
|
||||
|
||||
/**
|
||||
* Database status.
|
||||
*
|
||||
* @var DatabaseStatus
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $status = DatabaseStatus::CLOSED;
|
||||
|
|
@ -89,7 +89,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
/**
|
||||
* Database grammar.
|
||||
*
|
||||
* @var Grammar
|
||||
* @var SchemaGrammar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $schemaGrammar = null;
|
||||
|
|
|
|||
|
|
@ -60,32 +60,11 @@ class MysqlConnection extends ConnectionAbstract
|
|||
{
|
||||
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
|
||||
|
||||
if(!isset($this->dbdata['db'])) {
|
||||
throw new InvalidConnectionConfigException('db');
|
||||
}
|
||||
|
||||
if(!isset($this->dbdata['host'])) {
|
||||
throw new InvalidConnectionConfigException('host');
|
||||
}
|
||||
|
||||
if(!isset($this->dbdata['port'])) {
|
||||
throw new InvalidConnectionConfigException('port');
|
||||
}
|
||||
|
||||
if(!isset($this->dbdata['database'])) {
|
||||
throw new InvalidConnectionConfigException('database');
|
||||
}
|
||||
|
||||
if(!isset($this->dbdata['login'])) {
|
||||
throw new InvalidConnectionConfigException('login');
|
||||
}
|
||||
|
||||
if(!isset($this->dbdata['password'])) {
|
||||
throw new InvalidConnectionConfigException('password');
|
||||
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) {
|
||||
throw new InvalidConnectionConfigException(json_encode($this->dbdata));
|
||||
}
|
||||
|
||||
$this->close();
|
||||
|
||||
$this->prefix = $dbdata['prefix'] ?? '';
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Highest mapper to know when to clear initialized objects
|
||||
*
|
||||
* @var DataMapperAbstract
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $parentMapper = null;
|
||||
|
|
@ -269,8 +269,6 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
// todo: how to handle with of parent objects/extends/relations
|
||||
|
||||
self::$fields = $objects;
|
||||
|
||||
//return __CLASS__;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -507,7 +505,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null)
|
||||
{
|
||||
$reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = $reflectionClass ?? new \ReflectionClass($obj);
|
||||
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
|
||||
|
||||
if (!($isPublic = $reflectionProperty->isPublic())) {
|
||||
|
|
@ -596,7 +594,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
$relReflectionClass = new \ReflectionClass($value);
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
|
@ -931,7 +929,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
$relReflectionClass = new \ReflectionClass($value);
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
|
@ -1162,7 +1160,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
$objId = self::getObjectId($obj, $reflectionClass);
|
||||
$update = true;
|
||||
|
||||
|
|
@ -1229,7 +1227,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
$relReflectionClass = new \ReflectionClass($value);
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
|
@ -1372,7 +1370,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
$objId = self::getObjectId($obj, $reflectionClass);
|
||||
|
||||
if (empty($objId)) {
|
||||
|
|
@ -1478,7 +1476,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
public static function populateManyToMany(array $result, &$obj) /* : void */
|
||||
{
|
||||
// todo: maybe pass reflectionClass as optional parameter for performance increase
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
|
||||
foreach ($result as $member => $values) {
|
||||
if (!empty($values) && $reflectionClass->hasProperty($member)) {
|
||||
|
|
@ -1546,7 +1544,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public static function populateHasOne(&$obj) /* : void */
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
|
||||
foreach (static::$hasOne as $member => $one) {
|
||||
// todo: is that if necessary? performance is suffering for sure!
|
||||
|
|
@ -1615,7 +1613,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public static function populateOwnsOne(&$obj) /* : void */
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
|
||||
foreach (static::$ownsOne as $member => $one) {
|
||||
// todo: is that if necessary? performance is suffering for sure!
|
||||
|
|
@ -1684,7 +1682,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public static function populateBelongsTo(&$obj) /* : void */
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
|
||||
foreach (static::$belongsTo as $member => $one) {
|
||||
// todo: is that if necessary? performance is suffering for sure!
|
||||
|
|
@ -1754,7 +1752,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public static function populateAbstract(array $result, $obj)
|
||||
{
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$reflectionClass = new \ReflectionClass($obj);
|
||||
|
||||
foreach ($result as $column => $value) {
|
||||
if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidConnectionConfigException extends \InvalidArgumentException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidMapperException extends \RuntimeException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class Builder extends BuilderAbstract
|
|||
/**
|
||||
* Offset.
|
||||
*
|
||||
* @var array
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $offset = null;
|
||||
|
|
@ -184,7 +184,7 @@ class Builder extends BuilderAbstract
|
|||
/**
|
||||
* Raw query.
|
||||
*
|
||||
* @var bool
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $raw = '';
|
||||
|
|
@ -356,7 +356,32 @@ class Builder extends BuilderAbstract
|
|||
*/
|
||||
public function raw(string $raw) : Builder
|
||||
{
|
||||
if($this->isReadOnly) {
|
||||
if (!$this->isValidReadOnly($raw)) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->type = QueryType::RAW;
|
||||
$this->raw = rtrim($raw, ';');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a string contains a non read only component in case the builder is read only.
|
||||
* If the builder is not read only it will always return true
|
||||
*
|
||||
* @param string $raw Raw query
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function isValidReadOnly($raw) : bool
|
||||
{
|
||||
if (!$this->isReadOnly) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$test = strtolower($raw);
|
||||
|
||||
if (strpos($test, 'insert') !== false
|
||||
|
|
@ -364,15 +389,12 @@ class Builder extends BuilderAbstract
|
|||
|| strpos($test, 'drop') !== false
|
||||
|| strpos($test, 'delete') !== false
|
||||
|| strpos($test, 'create') !== false
|
||||
|| strpos($test, 'alter') !== false) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|| strpos($test, 'alter') !== false
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->type = QueryType::RAW;
|
||||
$this->raw = rtrim($raw, ';');
|
||||
|
||||
return $this;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -459,12 +481,17 @@ class Builder extends BuilderAbstract
|
|||
*/
|
||||
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
|
||||
{
|
||||
// TODO: handle $value is null -> operator NULL
|
||||
if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
if (is_array($columns)) {
|
||||
if (is_string($columns)) {
|
||||
$colums = [$columns];
|
||||
$operator = [$operator];
|
||||
$values = [$values];
|
||||
$boolean = [$boolean];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($columns as $key => $column) {
|
||||
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
|
||||
|
|
@ -480,16 +507,6 @@ class Builder extends BuilderAbstract
|
|||
|
||||
$i++;
|
||||
}
|
||||
} elseif (is_string($columns)) {
|
||||
if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
$this->wheres[self::getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values,
|
||||
'boolean' => $boolean,];
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ class Grammar extends GrammarAbstract
|
|||
break;
|
||||
case QueryType::RAW:
|
||||
return [$query->raw];
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown query type.');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query\Grammar;
|
||||
|
||||
class GrammarInterface
|
||||
interface GrammarInterface
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TableException extends \PDOException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class LockException extends \RuntimeException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ZeroDevisionException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -250,15 +250,15 @@ class Functions
|
|||
* @example The relative fiscal month (August) in a company where the fiscal year starts in July.
|
||||
* @example 2 = getRelativeDegree(8, 12, 7);
|
||||
*
|
||||
* @param mixed $value Value to get degree
|
||||
* @param mixed $length Circle size
|
||||
* @param mixed $start Start value
|
||||
* @param int $value Value to get degree
|
||||
* @param int $length Circle size
|
||||
* @param int $start Start value
|
||||
*
|
||||
* @return int Lowest value is 0 and highest value is length - 1
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getRelativeDegree($value, $length, $start = 0) : int
|
||||
public static function getRelativeDegree(int $value, int $length, int $start = 0) : int
|
||||
{
|
||||
return abs(self::mod($value - $start, $length));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ class Polygon implements D2ShapeInterface
|
|||
*
|
||||
* @return int
|
||||
*
|
||||
* @link http://erich.realtimerendering.com/ptinpoly/
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function isPointInPolygon(array $point, array $polygon) : int
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace phpOMS\Math\Matrix;
|
||||
|
||||
class EigenValueDecomposition
|
||||
{
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ class InvalidDimensionException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ class LUDecomposition
|
|||
|
||||
public function getL()
|
||||
{
|
||||
$L = [[]];
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($i > $j) {
|
||||
|
|
@ -104,6 +106,8 @@ class LUDecomposition
|
|||
|
||||
public function getU()
|
||||
{
|
||||
$U = [[]];
|
||||
|
||||
for ($i = 0; $i < $this->n; ++$i) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($i <= $j) {
|
||||
|
|
@ -154,8 +158,6 @@ class LUDecomposition
|
|||
if (!$this->isNonsingular()) {
|
||||
}
|
||||
|
||||
var_dump($this->piv);
|
||||
|
||||
$nx = $B->getM();
|
||||
$X = $B->getMatrix($this->piv, 0, $nx - 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,8 @@ class QRDecomposition
|
|||
|
||||
public function getH()
|
||||
{
|
||||
$H = [[]];
|
||||
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($i >= $j) {
|
||||
|
|
@ -99,6 +101,8 @@ class QRDecomposition
|
|||
|
||||
public function getR()
|
||||
{
|
||||
$R = [[]];
|
||||
|
||||
for ($i = 0; $i < $this->n; ++$i) {
|
||||
for ($j = 0; $j < $this->n; ++$j) {
|
||||
if ($i < $j) {
|
||||
|
|
@ -119,10 +123,13 @@ class QRDecomposition
|
|||
|
||||
public function getQ()
|
||||
{
|
||||
$Q = [[]];
|
||||
|
||||
for ($k = $this->n - 1; $k >= 0; --$k) {
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
$Q[$i][$k] = 0.0;
|
||||
}
|
||||
|
||||
$Q[$k][$k] = 1.0;
|
||||
for ($j = $k; $j < $this->n; ++$j) {
|
||||
if ($this->QR[$k][$k] != 0) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace phpOMS\Math\Matrix;
|
||||
|
||||
class SingularValueDecomposition
|
||||
{
|
||||
}
|
||||
|
|
@ -1,222 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Math\Optimization\Graph;
|
||||
|
||||
use phpOMS\Stdlib\Map\KeyType;
|
||||
use phpOMS\Stdlib\Map\MultiMap;
|
||||
use phpOMS\Stdlib\Map\OrderType;
|
||||
|
||||
/**
|
||||
* Graph class
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Asset
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Graph
|
||||
{
|
||||
/**
|
||||
* Vertices.
|
||||
*
|
||||
* @var VerticeInterface[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $vertices = [];
|
||||
|
||||
/**
|
||||
* Edge.
|
||||
*
|
||||
* @var EdgeInterface[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $edges = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->edges = new MultiMap(KeyType::MULTIPLE, OrderType::LOOSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add vertice to graph.
|
||||
*
|
||||
* @param VerticeInterface $vertice Vertice
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addVertice(VerticeInterface $vertice) : bool
|
||||
{
|
||||
if (!isset($this->vertices[$vertice->getId()])) {
|
||||
$this->vertices[$vertice->getId()] = $vertice;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add edge to graph.
|
||||
*
|
||||
* @param EdgeInterface $edge Edge
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addEdge(EdgeInterface $edge) : bool
|
||||
{
|
||||
if (!isset($this->edges[$edge->getId()])) {
|
||||
$this->edges[$edge->getId()] = $edge;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove vertice from graph.
|
||||
*
|
||||
* @param mixed $id Id of vertice to remove
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function removeVertice($id) : bool
|
||||
{
|
||||
if (isset($this->vertices[$id])) {
|
||||
unset($this->vertices[$id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove edge by nodes from graph.
|
||||
*
|
||||
* @param mixed $a First node of edge
|
||||
* @param mixed $b Second node of edge
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function removeEdge($a, $b) : bool
|
||||
{
|
||||
return $this->edges->remove([$a, $b]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove edge from graph.
|
||||
*
|
||||
* @param mixed $id Id of edge to remove
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function removeEdgeById($id) : bool
|
||||
{
|
||||
if (isset($this->edges[$id])) {
|
||||
unset($this->edges[$id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get vertice.
|
||||
*
|
||||
* @param mixed $id Id of vertice
|
||||
*
|
||||
* @return VerticeInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getVertice($id) : VerticeInterface
|
||||
{
|
||||
return $this->vertices[$id] ?? new NullVertice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edge by nodes.
|
||||
*
|
||||
* Order of nodes is irrelevant
|
||||
*
|
||||
* @param mixed $a First node of edge
|
||||
* @param mixed $b Second node of edge
|
||||
*
|
||||
* @return EdgeInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEdge($a, $b) : EdgeInterface
|
||||
{
|
||||
return $this->edges->get([$a, $b]) ?? new NullEdge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edge by id.
|
||||
*
|
||||
* @param int $id Edge id
|
||||
*
|
||||
* @return EdgeInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getEdgeById(int $id) : EdgeInterface
|
||||
{
|
||||
return $this->edges->get($id) ?? new NullEdge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Count vertices.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function countVertices() : int
|
||||
{
|
||||
return count($this->vertices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count edges.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function countEdges() : int
|
||||
{
|
||||
return count($this->edges);
|
||||
}
|
||||
}
|
||||
|
|
@ -52,11 +52,11 @@ class Average
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function averageChange(array $x, int $h = 1) : float
|
||||
public static function averageDatasetChange(array $x, int $h = 1) : float
|
||||
{
|
||||
$count = count($x);
|
||||
|
||||
return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1);
|
||||
return $h * ($x[$count - 1] - $x[0]) / ($count - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -185,12 +185,12 @@ class Average
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function mode($values)
|
||||
public static function mode(array $values)
|
||||
{
|
||||
$count = array_count_values($values);
|
||||
$best = max($count);
|
||||
|
||||
return array_keys($count, $best);
|
||||
return (float) (array_keys($count, $best)[0] ?? 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class MeasureOfDispersion
|
|||
$end = end($values);
|
||||
$start = reset($values);
|
||||
|
||||
return $start - $end;
|
||||
return $end - $start;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -71,18 +71,18 @@ class Header extends HeaderAbstract
|
|||
throw new LockException('HTTP header');
|
||||
}
|
||||
|
||||
$key = strtolower($key);
|
||||
|
||||
if (!$overwrite && isset($this->header[$key])) {
|
||||
return false;
|
||||
} elseif ($overwrite || !isset($this->header[$key])) {
|
||||
if (self::isSecurityHeader($key) && isset($this->header[$key])) {
|
||||
throw new \Exception('Cannot change security headers.');
|
||||
}
|
||||
|
||||
unset($this->header[$key]);
|
||||
$key = strtolower($key);
|
||||
|
||||
if (!$overwrite && isset($this->header[$key])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($this->header[$key]);
|
||||
|
||||
if (!isset($this->header[$key])) {
|
||||
$this->header[$key] = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,6 +141,12 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
}
|
||||
}
|
||||
|
||||
$types = $this->header->get('Content-Type');
|
||||
|
||||
if (stripos($types[0], MimeType::M_HTML) !== false) {
|
||||
return trim(preg_replace('/(\s{2,}|\n|\t)(?![^<>]*<\/pre>)/', ' ', $render));
|
||||
}
|
||||
|
||||
return $render;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Message;
|
||||
|
||||
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Uri\UriInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -75,7 +74,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
/**
|
||||
* Request type.
|
||||
*
|
||||
* @var \phpOMS\Message\RequestSource
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $source = RequestSource::UNDEFINED;
|
||||
|
|
@ -266,7 +265,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract function getOrigin() : string;
|
||||
abstract public function getOrigin() : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidModuleException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidThemeException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ abstract class ModuleAbstract
|
|||
/**
|
||||
* Dependencies.
|
||||
*
|
||||
* @var string
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $dependencies = [];
|
||||
|
|
|
|||
|
|
@ -419,13 +419,13 @@ class ModuleManager
|
|||
public function reInit(string $module) : bool
|
||||
{
|
||||
$info = $this->loadInfo($module);
|
||||
/** @var $class InstallerAbstract */
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class InstallerAbstract */
|
||||
$class::reInit($this->modulePath, $info);
|
||||
}
|
||||
|
||||
|
|
@ -511,13 +511,13 @@ class ModuleManager
|
|||
*/
|
||||
private function installModule(InfoManager $info) /* : void */
|
||||
{
|
||||
/** @var $class InstallerAbstract */
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
|
||||
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new InvalidModuleException($info->getDirectory());
|
||||
}
|
||||
|
||||
/** @var $class InstallerAbstract */
|
||||
$class::install($this->modulePath, $this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Module;
|
||||
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\Utils\ArrayUtils;
|
||||
use phpOMS\System\File\Local\File;
|
||||
use phpOMS\System\File\Local\Directory;
|
||||
use phpOMS\System\File\Local\LocalStorage;
|
||||
|
|
@ -71,7 +70,7 @@ class PackageManager
|
|||
* Constructor.
|
||||
*
|
||||
* @param string $path Package source path e.g. path after download.
|
||||
* @param string basePath Path of the application
|
||||
* @param string $basePath Path of the application
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -86,11 +85,11 @@ class PackageManager
|
|||
*
|
||||
* @param string $path Temporary extract path
|
||||
*
|
||||
* @return bool
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function extract(string $path) : bool
|
||||
public function extract(string $path) /* : void */
|
||||
{
|
||||
$this->extractPath = $path;
|
||||
Zip::unpack($this->path, $this->extractPath);
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Router
|
|||
* @param string|RequestAbstract $request Request to route
|
||||
* @param int $verb Route verb
|
||||
*
|
||||
* @return string[]
|
||||
* @return array[]
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class InvalidEnumName extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class InvalidEnumValue extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class MultiMap implements \Countable
|
|||
$inserted = false;
|
||||
|
||||
if ($this->keyType !== KeyType::SINGLE) {
|
||||
$keys = [implode($keys, ':')];
|
||||
$keys = [implode(':', $keys)];
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
|
|
@ -186,14 +186,14 @@ class MultiMap implements \Countable
|
|||
$keys = Permutation::permut($key);
|
||||
|
||||
foreach ($keys as $key => $value) {
|
||||
$key = implode($value, ':');
|
||||
$key = implode(':', $value);
|
||||
|
||||
if (isset($this->keys[$key])) {
|
||||
return $this->values[$this->keys[$key]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$key = implode($key, ':');
|
||||
$key = implode(':', $key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,12 +235,12 @@ class MultiMap implements \Countable
|
|||
$permutation = Permutation::permut($key);
|
||||
|
||||
foreach ($permutation as $permut) {
|
||||
if ($this->set(implode($permut, ':'), $value)) {
|
||||
if ($this->set(implode(':', $permut), $value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->set(implode($key, ':'), $value);
|
||||
return $this->set(implode(':', $key), $value);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -302,12 +302,12 @@ class MultiMap implements \Countable
|
|||
$removed = false;
|
||||
|
||||
foreach ($keys as $key => $value) {
|
||||
$removed |= $this->remove(implode($value, ':'));
|
||||
$removed |= $this->remove(implode(':', $value));
|
||||
}
|
||||
|
||||
return $removed;
|
||||
} else {
|
||||
return $this->remove(implode($key, ':'));
|
||||
return $this->remove(implode(':', $key));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -403,12 +403,12 @@ class MultiMap implements \Countable
|
|||
$removed = false;
|
||||
|
||||
foreach ($keys as $key => $value) {
|
||||
$removed |= $this->removeKey(implode($value, ':'));
|
||||
$removed |= $this->removeKey(implode(':', $value));
|
||||
}
|
||||
|
||||
return $removed;
|
||||
} else {
|
||||
return $this->removeKey(implode($key, ':'));
|
||||
return $this->removeKey(implode(':', $key));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -315,11 +315,11 @@ interface ContainerInterface
|
|||
/**
|
||||
* Get the permissions id of the resource.
|
||||
*
|
||||
* @return string Permissions (e.g. 0644);
|
||||
* @return int Permissions (e.g. 0644);
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPermission() : string;
|
||||
public function getPermission() : int;
|
||||
|
||||
/**
|
||||
* (Re-)Initialize resource
|
||||
|
|
|
|||
|
|
@ -156,27 +156,23 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
*/
|
||||
public static function size(string $dir, bool $recursive = true) : int
|
||||
{
|
||||
if (!file_exists($dir)) {
|
||||
if (!file_exists($dir) || !is_readable($dir)) {
|
||||
throw new PathException($dir);
|
||||
}
|
||||
|
||||
$countSize = 0;
|
||||
$count = 0;
|
||||
|
||||
if (is_readable($dir)) {
|
||||
$dir_array = scandir($dir);
|
||||
|
||||
foreach ($dir_array as $key => $filename) {
|
||||
if ($filename != ".." && $filename != ".") {
|
||||
if (is_dir($dir . "/" . $filename) && $recursive) {
|
||||
$countSize += self::size($dir . "/" . $filename, $recursive);
|
||||
} else {
|
||||
if (is_file($dir . "/" . $filename)) {
|
||||
$countSize += filesize($dir . "/" . $filename);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
if ($filename === ".." || $filename === ".") {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = $dir . "/" . $filename;
|
||||
if (is_dir($path) && $recursive) {
|
||||
$countSize += self::size($path, $recursive);
|
||||
} elseif (is_file($path)) {
|
||||
$countSize += filesize($path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,14 +308,12 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
throw new PathException($from);
|
||||
}
|
||||
|
||||
if(!$overwrite && file_exists($to)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($to)) {
|
||||
self::create($to, 0644, true);
|
||||
} elseif ($overwrite && file_exists($to)) {
|
||||
self::delete($to);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($iterator = new \RecursiveIteratorIterator(
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ abstract class FileAbstract implements ContainerInterface
|
|||
/**
|
||||
* Permission.
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $permission = 0644;
|
||||
|
|
@ -176,7 +176,7 @@ abstract class FileAbstract implements ContainerInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPermission() : string
|
||||
public function getPermission() : int
|
||||
{
|
||||
return $this->permission;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
declare(strict_types = 1);
|
||||
|
||||
namespace phpOMS\System\File\Local;
|
||||
use phpOMS\System\File\ContainerInterface;
|
||||
use phpOMS\System\File\StorageAbstract;
|
||||
use phpOMS\System\File\PathException;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class PathException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class PermissionException extends \RuntimeException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,120 +72,120 @@ abstract class StorageAbstract
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function created(string $path) : \DateTime;
|
||||
abstract public static function created(string $path) : \DateTime;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function changed(string $path) : \DateTime;
|
||||
abstract public static function changed(string $path) : \DateTime;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function owner(string $path) : int;
|
||||
abstract public static function owner(string $path) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function permission(string $path) : int;
|
||||
abstract public static function permission(string $path) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function parent(string $path) : string;
|
||||
abstract public static function parent(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function create(string $path) : bool;
|
||||
abstract public static function create(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function delete(string $path) : bool;
|
||||
abstract public static function delete(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||
abstract public static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||
abstract public static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function size(string $path, bool $recursive = true) : int;
|
||||
abstract public static function size(string $path, bool $recursive = true) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function exists(string $path) : bool;
|
||||
abstract public static function exists(string $path) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function name(string $path) : string;
|
||||
abstract public static function name(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function basename(string $path) : string;
|
||||
abstract public static function basename(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function dirname(string $path) : string;
|
||||
abstract public static function dirname(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function dirpath(string $path) : string;
|
||||
abstract public static function dirpath(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function list(string $path, string $filter = '*') : array;
|
||||
abstract public static function list(string $path, string $filter = '*') : array;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function count(string $path, bool $recursive = true, array $ignore = []) : int;
|
||||
abstract public static function count(string $path, bool $recursive = true, array $ignore = []) : int;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function put(string $path, string $content, int $mode = 0) : bool;
|
||||
abstract public static function put(string $path, string $content, int $mode = 0) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function get(string $path) : string;
|
||||
abstract public static function get(string $path) : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function sanitize(string $path, string $replace = '') : string;
|
||||
abstract public static function sanitize(string $path, string $replace = '') : string;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function set(string $path, string $content) : bool;
|
||||
abstract public static function set(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function append(string $path, string $content) : bool;
|
||||
abstract public static function append(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function prepend(string $path, string $content) : bool;
|
||||
abstract public static function prepend(string $path, string $content) : bool;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public abstract static function extension(string $path) : string;
|
||||
abstract public static function extension(string $path) : string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,12 @@ class SystemUtils
|
|||
*/
|
||||
public static function getRAM() : int
|
||||
{
|
||||
$mem = null;
|
||||
$mem = 0;
|
||||
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
exec('wmic memorychip get capacity', $mem);
|
||||
|
||||
/** @var array $mem */
|
||||
$mem = array_sum($mem) / 1024;
|
||||
} elseif (stristr(PHP_OS, 'LINUX')) {
|
||||
$fh = fopen('/proc/meminfo', 'r');
|
||||
|
|
@ -62,6 +64,7 @@ class SystemUtils
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
|
|
@ -79,9 +82,7 @@ class SystemUtils
|
|||
{
|
||||
$memusage = 0;
|
||||
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
|
||||
} elseif (stristr(PHP_OS, 'LINUX')) {
|
||||
if (stristr(PHP_OS, 'LINUX')) {
|
||||
$free = shell_exec('free');
|
||||
$free = (string) trim($free);
|
||||
$free_arr = explode("\n", $free);
|
||||
|
|
|
|||
|
|
@ -281,7 +281,7 @@ class Http implements UriInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuery(string $key = null) /* : ?string */
|
||||
public function getQuery(string $key = null) : string
|
||||
{
|
||||
if (isset($key)) {
|
||||
$key = strtolower($key);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidUriException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -187,7 +187,6 @@ class UriFactory
|
|||
$full = $parts[1];
|
||||
$pars = explode('&', $full);
|
||||
$comps = [];
|
||||
$spl = null;
|
||||
$length = count($pars);
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
|
|
|
|||
|
|
@ -117,11 +117,11 @@ interface UriInterface
|
|||
*
|
||||
* @param string $key Query key
|
||||
*
|
||||
* @return string|array
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getQuery(string $key = null);
|
||||
public function getQuery(string $key = null) : string;
|
||||
|
||||
/**
|
||||
* Get fragment.
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class ArrayUtils
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if needle exists in multidimensional array.
|
||||
* Set element in array by path
|
||||
*
|
||||
* @param string $path Path to element
|
||||
* @param array $data Array
|
||||
|
|
@ -97,8 +97,7 @@ class ArrayUtils
|
|||
|
||||
if ($overwrite) {
|
||||
$current = $value;
|
||||
} else {
|
||||
if (is_array($current) && !is_array($value)) {
|
||||
} elseif (is_array($current) && !is_array($value)) {
|
||||
$current[] = $value;
|
||||
} elseif (is_array($current) && is_array($value)) {
|
||||
$current += $value;
|
||||
|
|
@ -107,11 +106,33 @@ class ArrayUtils
|
|||
} else {
|
||||
$current = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element of array by path
|
||||
*
|
||||
* @param string $path Path to element
|
||||
* @param array $data Array
|
||||
* @param string $delim Delimiter for path
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getArray(string $path, array $data, string $delim = '/')
|
||||
{
|
||||
$pathParts = explode($delim, trim($path, $delim));
|
||||
$current = $data;
|
||||
|
||||
foreach ($pathParts as $key) {
|
||||
$current = $current[$key];
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if needle exists in multidimensional array.
|
||||
*
|
||||
|
|
@ -133,7 +154,7 @@ class ArrayUtils
|
|||
$found = self::inArrayRecursive($needle, $item);
|
||||
|
||||
if ($found) {
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class InvalidJsonException extends \UnexpectedValueException
|
|||
*
|
||||
* @param string $message Exception message
|
||||
* @param int $code Exception code
|
||||
* @param \Exception Previous exception
|
||||
* @param \Exception $previous Previous exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -91,12 +91,7 @@ class JobQueue
|
|||
fclose(STDOUT);
|
||||
fclose(STDERR);
|
||||
|
||||
function shutdown()
|
||||
{
|
||||
posix_kill(posix_getpid(), SIGHUP);
|
||||
}
|
||||
|
||||
register_shutdown_function('shutdown');
|
||||
register_shutdown_function(function() { posix_kill(posix_getpid(), SIGHUP); });
|
||||
}
|
||||
|
||||
public function setRunning(bool $run = true) /* : void */
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ final class Validator extends ValidatorAbstract
|
|||
*/
|
||||
public static function isValid($var, array $constraints = null) : bool
|
||||
{
|
||||
if (!isset($constraints)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($constraints as $callback => $settings) {
|
||||
$callback = StringUtils::endsWith($callback, 'Not') ? substr($callback, 0, -3) : $callback;
|
||||
$valid = self::$callback($var, ...$settings);
|
||||
|
|
|
|||
|
|
@ -82,12 +82,12 @@ class View extends ViewAbstract
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(ApplicationAbstract $app, RequestAbstract $request, ResponseAbstract $response)
|
||||
public function __construct(ApplicationAbstract $app = null, RequestAbstract $request = null, ResponseAbstract $response = null)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->request = $request;
|
||||
$this->response = $response;
|
||||
$this->l11n = $response->getHeader()->getL11n();
|
||||
$this->l11n = isset($response) ? $response->getHeader()->getL11n() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -175,14 +175,14 @@ abstract class ViewAbstract implements \Serializable
|
|||
/**
|
||||
* Serialize view for rendering.
|
||||
*
|
||||
* @return string|array
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0 <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
if (empty($this->template)) {
|
||||
return $this->toArray();
|
||||
return json_encode($this->toArray());
|
||||
}
|
||||
|
||||
return $this->render();
|
||||
|
|
@ -215,11 +215,11 @@ abstract class ViewAbstract implements \Serializable
|
|||
*
|
||||
* @param array $data Data to pass to renderer
|
||||
*
|
||||
* @return array|string
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0 <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function render(...$data)
|
||||
public function render(...$data) : string
|
||||
{
|
||||
$ob = '';
|
||||
$path = __DIR__ . '/../..' . $this->template . '.tpl.php';
|
||||
|
|
@ -235,7 +235,7 @@ abstract class ViewAbstract implements \Serializable
|
|||
$ob = ob_get_clean();
|
||||
|
||||
if (is_array($includeData)) {
|
||||
return $includeData;
|
||||
return json_encode($includeData);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$ob = '';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user