Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop

This commit is contained in:
Dennis Eichhorn 2017-10-30 10:59:38 +01:00
commit 877e56c5cd
505 changed files with 1720 additions and 1692 deletions

View File

@ -136,7 +136,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/** /**
* Account type. * Account type.
* *
* @var AccountType|int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $type = AccountType::USER; protected $type = AccountType::USER;
@ -144,7 +144,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/** /**
* Account status. * Account status.
* *
* @var AccountStatus|int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $status = AccountStatus::INACTIVE; protected $status = AccountStatus::INACTIVE;
@ -560,7 +560,7 @@ class Account implements ArrayableInterface, \JsonSerializable
*/ */
public function generatePassword(string $password) /* : void */ 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. * Json serialize.
* *
* @return string * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -208,7 +208,7 @@ class Group implements ArrayableInterface, \JsonSerializable
/** /**
* Json serialize. * Json serialize.
* *
* @return string * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -340,7 +340,7 @@ class PermissionAbstract
* *
* @param int $permission Permission * @param int $permission Permission
* *
* @return void * @return bool
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace phpOMS\Auth; namespace phpOMS\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface; use phpOMS\DataStorage\Session\SessionInterface;
/** /**

View File

@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -754,6 +754,20 @@ class FinanceFormulas
return log(2) / log(1 + $r); 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 * Doubling Time - Continuous Compounding
* *

View File

@ -48,11 +48,10 @@ class Metrics {
/** /**
* Calculate the C.R.A.P score * 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 $complexity Complexity
* @param int $b Branches * @param int $coverage Coverage
* @param int $c Conditionals
* *
* @return int * @return int
* *

View File

@ -39,7 +39,7 @@ class CachePool implements OptionsInterface
/** /**
* MemCache instance. * MemCache instance.
* *
* @var \phpOMS\DataStorage\Cache\CacheInterface * @var \phpOMS\DataStorage\Cache\CacheInterface[]
* @since 1.0.0 * @since 1.0.0
*/ */
private $pool = null; private $pool = null;

View File

@ -50,7 +50,7 @@ class MemCache implements CacheInterface
*/ */
public function __construct() public function __construct()
{ {
$this->memc = new self(); $this->memc = null;
} }
/** /**

View 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;
}
}
}

View File

@ -65,15 +65,15 @@ abstract class ConnectionAbstract implements ConnectionInterface
/** /**
* Database type. * Database type.
* *
* @var \phpOMS\DataStorage\Database\DatabaseType * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected $type = null; protected $type = 'undefined';
/** /**
* Database status. * Database status.
* *
* @var DatabaseStatus * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $status = DatabaseStatus::CLOSED; protected $status = DatabaseStatus::CLOSED;
@ -89,7 +89,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
/** /**
* Database grammar. * Database grammar.
* *
* @var Grammar * @var SchemaGrammar
* @since 1.0.0 * @since 1.0.0
*/ */
protected $schemaGrammar = null; protected $schemaGrammar = null;

View File

@ -60,32 +60,11 @@ class MysqlConnection extends ConnectionAbstract
{ {
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
if(!isset($this->dbdata['db'])) { if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) {
throw new InvalidConnectionConfigException('db'); throw new InvalidConnectionConfigException(json_encode($this->dbdata));
}
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');
} }
$this->close(); $this->close();
$this->prefix = $dbdata['prefix'] ?? ''; $this->prefix = $dbdata['prefix'] ?? '';
try { try {

View File

@ -149,7 +149,7 @@ class DataMapperAbstract implements DataMapperInterface
/** /**
* Highest mapper to know when to clear initialized objects * Highest mapper to know when to clear initialized objects
* *
* @var DataMapperAbstract * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static $parentMapper = null; protected static $parentMapper = null;
@ -269,8 +269,6 @@ class DataMapperAbstract implements DataMapperInterface
// todo: how to handle with of parent objects/extends/relations // todo: how to handle with of parent objects/extends/relations
self::$fields = $objects; self::$fields = $objects;
//return __CLASS__;
} }
/** /**
@ -507,7 +505,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null) 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']); $reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
if (!($isPublic = $reflectionProperty->isPublic())) { if (!($isPublic = $reflectionProperty->isPublic())) {
@ -596,7 +594,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -931,7 +929,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -1162,7 +1160,7 @@ class DataMapperAbstract implements DataMapperInterface
{ {
self::extend(__CLASS__); self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass); $objId = self::getObjectId($obj, $reflectionClass);
$update = true; $update = true;
@ -1229,7 +1227,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -1372,7 +1370,7 @@ class DataMapperAbstract implements DataMapperInterface
{ {
self::extend(__CLASS__); self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass); $objId = self::getObjectId($obj, $reflectionClass);
if (empty($objId)) { if (empty($objId)) {
@ -1478,7 +1476,7 @@ class DataMapperAbstract implements DataMapperInterface
public static function populateManyToMany(array $result, &$obj) /* : void */ public static function populateManyToMany(array $result, &$obj) /* : void */
{ {
// todo: maybe pass reflectionClass as optional parameter for performance increase // 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) { foreach ($result as $member => $values) {
if (!empty($values) && $reflectionClass->hasProperty($member)) { if (!empty($values) && $reflectionClass->hasProperty($member)) {
@ -1546,7 +1544,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
public static function populateHasOne(&$obj) /* : void */ public static function populateHasOne(&$obj) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$hasOne as $member => $one) { foreach (static::$hasOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // todo: is that if necessary? performance is suffering for sure!
@ -1615,7 +1613,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
public static function populateOwnsOne(&$obj) /* : void */ public static function populateOwnsOne(&$obj) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$ownsOne as $member => $one) { foreach (static::$ownsOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // todo: is that if necessary? performance is suffering for sure!
@ -1684,7 +1682,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
public static function populateBelongsTo(&$obj) /* : void */ public static function populateBelongsTo(&$obj) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$belongsTo as $member => $one) { foreach (static::$belongsTo as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // 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) public static function populateAbstract(array $result, $obj)
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach ($result as $column => $value) { foreach ($result as $column => $value) {
if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) { if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) {

View File

@ -31,7 +31,7 @@ class InvalidConnectionConfigException extends \InvalidArgumentException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -31,7 +31,7 @@ class InvalidMapperException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -152,7 +152,7 @@ class Builder extends BuilderAbstract
/** /**
* Offset. * Offset.
* *
* @var array * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
public $offset = null; public $offset = null;
@ -184,7 +184,7 @@ class Builder extends BuilderAbstract
/** /**
* Raw query. * Raw query.
* *
* @var bool * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
public $raw = ''; public $raw = '';
@ -356,7 +356,32 @@ class Builder extends BuilderAbstract
*/ */
public function raw(string $raw) : Builder 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); $test = strtolower($raw);
if (strpos($test, 'insert') !== false if (strpos($test, 'insert') !== false
@ -364,15 +389,12 @@ class Builder extends BuilderAbstract
|| strpos($test, 'drop') !== false || strpos($test, 'drop') !== false
|| strpos($test, 'delete') !== false || strpos($test, 'delete') !== false
|| strpos($test, 'create') !== false || strpos($test, 'create') !== false
|| strpos($test, 'alter') !== false) { || strpos($test, 'alter') !== false
throw new \Exception(); ) {
} return false;
} }
$this->type = QueryType::RAW; return true;
$this->raw = rtrim($raw, ';');
return $this;
} }
/** /**
@ -459,12 +481,17 @@ class Builder extends BuilderAbstract
*/ */
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder 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)) { if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.'); throw new \InvalidArgumentException('Unknown operator.');
} }
if (is_array($columns)) { if (is_string($columns)) {
$colums = [$columns];
$operator = [$operator];
$values = [$values];
$boolean = [$boolean];
}
$i = 0; $i = 0;
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) { if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
@ -480,16 +507,6 @@ class Builder extends BuilderAbstract
$i++; $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; return $this;
} }

View File

@ -133,7 +133,6 @@ class Grammar extends GrammarAbstract
break; break;
case QueryType::RAW: case QueryType::RAW:
return [$query->raw]; return [$query->raw];
break;
default: default:
throw new \InvalidArgumentException('Unknown query type.'); throw new \InvalidArgumentException('Unknown query type.');
} }

View File

@ -15,6 +15,6 @@ declare(strict_types=1);
namespace phpOMS\DataStorage\Database\Query\Grammar; namespace phpOMS\DataStorage\Database\Query\Grammar;
class GrammarInterface interface GrammarInterface
{ {
} }

View File

@ -31,7 +31,7 @@ class TableException extends \PDOException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -31,7 +31,7 @@ class LockException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -31,7 +31,7 @@ class ZeroDevisionException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -250,15 +250,15 @@ class Functions
* @example The relative fiscal month (August) in a company where the fiscal year starts in July. * @example The relative fiscal month (August) in a company where the fiscal year starts in July.
* @example 2 = getRelativeDegree(8, 12, 7); * @example 2 = getRelativeDegree(8, 12, 7);
* *
* @param mixed $value Value to get degree * @param int $value Value to get degree
* @param mixed $length Circle size * @param int $length Circle size
* @param mixed $start Start value * @param int $start Start value
* *
* @return int Lowest value is 0 and highest value is length - 1 * @return int Lowest value is 0 and highest value is length - 1
* *
* @since 1.0.0 * @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)); return abs(self::mod($value - $start, $length));
} }

View File

@ -139,6 +139,7 @@ class Polygon implements D2ShapeInterface
* *
* @return int * @return int
* *
* @link http://erich.realtimerendering.com/ptinpoly/
* @since 1.0.0 * @since 1.0.0
*/ */
public static function isPointInPolygon(array $point, array $polygon) : int public static function isPointInPolygon(array $point, array $polygon) : int

View File

@ -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
{
}

View File

@ -31,7 +31,7 @@ class InvalidDimensionException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -84,6 +84,8 @@ class LUDecomposition
public function getL() public function getL()
{ {
$L = [[]];
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) { if ($i > $j) {
@ -104,6 +106,8 @@ class LUDecomposition
public function getU() public function getU()
{ {
$U = [[]];
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) { if ($i <= $j) {
@ -154,8 +158,6 @@ class LUDecomposition
if (!$this->isNonsingular()) { if (!$this->isNonsingular()) {
} }
var_dump($this->piv);
$nx = $B->getM(); $nx = $B->getM();
$X = $B->getMatrix($this->piv, 0, $nx - 1); $X = $B->getMatrix($this->piv, 0, $nx - 1);

View File

@ -81,6 +81,8 @@ class QRDecomposition
public function getH() public function getH()
{ {
$H = [[]];
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) { if ($i >= $j) {
@ -99,6 +101,8 @@ class QRDecomposition
public function getR() public function getR()
{ {
$R = [[]];
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) { if ($i < $j) {
@ -119,10 +123,13 @@ class QRDecomposition
public function getQ() public function getQ()
{ {
$Q = [[]];
for ($k = $this->n - 1; $k >= 0; --$k) { for ($k = $this->n - 1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0; $Q[$i][$k] = 0.0;
} }
$Q[$k][$k] = 1.0; $Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; ++$j) { for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) { if ($this->QR[$k][$k] != 0) {

View File

@ -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
{
}

View File

@ -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);
}
}

View File

@ -52,11 +52,11 @@ class Average
* *
* @since 1.0.0 * @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); $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 * @since 1.0.0
*/ */
public static function mode($values) public static function mode(array $values)
{ {
$count = array_count_values($values); $count = array_count_values($values);
$best = max($count); $best = max($count);
return array_keys($count, $best); return (float) (array_keys($count, $best)[0] ?? 0.0);
} }
/** /**

View File

@ -47,7 +47,7 @@ class MeasureOfDispersion
$end = end($values); $end = end($values);
$start = reset($values); $start = reset($values);
return $start - $end; return $end - $start;
} }
/** /**

View File

@ -71,18 +71,18 @@ class Header extends HeaderAbstract
throw new LockException('HTTP header'); 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])) { if (self::isSecurityHeader($key) && isset($this->header[$key])) {
throw new \Exception('Cannot change security headers.'); 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])) { if (!isset($this->header[$key])) {
$this->header[$key] = []; $this->header[$key] = [];
} }

View File

@ -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; return $render;
} }

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace phpOMS\Message; namespace phpOMS\Message;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
use phpOMS\Localization\Localization;
use phpOMS\Uri\UriInterface; use phpOMS\Uri\UriInterface;
/** /**
@ -75,7 +74,7 @@ abstract class RequestAbstract implements MessageInterface
/** /**
* Request type. * Request type.
* *
* @var \phpOMS\Message\RequestSource * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $source = RequestSource::UNDEFINED; protected $source = RequestSource::UNDEFINED;
@ -266,7 +265,7 @@ abstract class RequestAbstract implements MessageInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract function getOrigin() : string; abstract public function getOrigin() : string;
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -31,7 +31,7 @@ class InvalidModuleException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -31,7 +31,7 @@ class InvalidThemeException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -76,7 +76,7 @@ abstract class ModuleAbstract
/** /**
* Dependencies. * Dependencies.
* *
* @var string * @var string[]
* @since 1.0.0 * @since 1.0.0
*/ */
protected static $dependencies = []; protected static $dependencies = [];

View File

@ -419,13 +419,13 @@ class ModuleManager
public function reInit(string $module) : bool public function reInit(string $module) : bool
{ {
$info = $this->loadInfo($module); $info = $this->loadInfo($module);
/** @var $class InstallerAbstract */
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
if (!Autoloader::exists($class)) { if (!Autoloader::exists($class)) {
throw new InvalidModuleException($info->getDirectory()); throw new InvalidModuleException($info->getDirectory());
} }
/** @var $class InstallerAbstract */
$class::reInit($this->modulePath, $info); $class::reInit($this->modulePath, $info);
} }
@ -511,13 +511,13 @@ class ModuleManager
*/ */
private function installModule(InfoManager $info) /* : void */ private function installModule(InfoManager $info) /* : void */
{ {
/** @var $class InstallerAbstract */
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
if (!Autoloader::exists($class)) { if (!Autoloader::exists($class)) {
throw new InvalidModuleException($info->getDirectory()); throw new InvalidModuleException($info->getDirectory());
} }
/** @var $class InstallerAbstract */
$class::install($this->modulePath, $this->app->dbPool, $info); $class::install($this->modulePath, $this->app->dbPool, $info);
} }

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace phpOMS\Module; namespace phpOMS\Module;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;
use phpOMS\Utils\ArrayUtils;
use phpOMS\System\File\Local\File; use phpOMS\System\File\Local\File;
use phpOMS\System\File\Local\Directory; use phpOMS\System\File\Local\Directory;
use phpOMS\System\File\Local\LocalStorage; use phpOMS\System\File\Local\LocalStorage;
@ -71,7 +70,7 @@ class PackageManager
* Constructor. * Constructor.
* *
* @param string $path Package source path e.g. path after download. * @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 * @since 1.0.0
*/ */
@ -86,11 +85,11 @@ class PackageManager
* *
* @param string $path Temporary extract path * @param string $path Temporary extract path
* *
* @return bool * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function extract(string $path) : bool public function extract(string $path) /* : void */
{ {
$this->extractPath = $path; $this->extractPath = $path;
Zip::unpack($this->path, $this->extractPath); Zip::unpack($this->path, $this->extractPath);

View File

@ -96,7 +96,7 @@ class Router
* @param string|RequestAbstract $request Request to route * @param string|RequestAbstract $request Request to route
* @param int $verb Route verb * @param int $verb Route verb
* *
* @return string[] * @return array[]
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* *

View File

@ -34,7 +34,7 @@ class InvalidEnumName extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -34,7 +34,7 @@ class InvalidEnumValue extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -92,7 +92,7 @@ class MultiMap implements \Countable
$inserted = false; $inserted = false;
if ($this->keyType !== KeyType::SINGLE) { if ($this->keyType !== KeyType::SINGLE) {
$keys = [implode($keys, ':')]; $keys = [implode(':', $keys)];
} }
foreach ($keys as $key) { foreach ($keys as $key) {
@ -186,14 +186,14 @@ class MultiMap implements \Countable
$keys = Permutation::permut($key); $keys = Permutation::permut($key);
foreach ($keys as $key => $value) { foreach ($keys as $key => $value) {
$key = implode($value, ':'); $key = implode(':', $value);
if (isset($this->keys[$key])) { if (isset($this->keys[$key])) {
return $this->values[$this->keys[$key]]; return $this->values[$this->keys[$key]];
} }
} }
} else { } else {
$key = implode($key, ':'); $key = implode(':', $key);
} }
} }
@ -235,12 +235,12 @@ class MultiMap implements \Countable
$permutation = Permutation::permut($key); $permutation = Permutation::permut($key);
foreach ($permutation as $permut) { foreach ($permutation as $permut) {
if ($this->set(implode($permut, ':'), $value)) { if ($this->set(implode(':', $permut), $value)) {
return true; return true;
} }
} }
} else { } else {
return $this->set(implode($key, ':'), $value); return $this->set(implode(':', $key), $value);
} }
return false; return false;
@ -302,12 +302,12 @@ class MultiMap implements \Countable
$removed = false; $removed = false;
foreach ($keys as $key => $value) { foreach ($keys as $key => $value) {
$removed |= $this->remove(implode($value, ':')); $removed |= $this->remove(implode(':', $value));
} }
return $removed; return $removed;
} else { } else {
return $this->remove(implode($key, ':')); return $this->remove(implode(':', $key));
} }
} }
@ -403,12 +403,12 @@ class MultiMap implements \Countable
$removed = false; $removed = false;
foreach ($keys as $key => $value) { foreach ($keys as $key => $value) {
$removed |= $this->removeKey(implode($value, ':')); $removed |= $this->removeKey(implode(':', $value));
} }
return $removed; return $removed;
} else { } else {
return $this->removeKey(implode($key, ':')); return $this->removeKey(implode(':', $key));
} }
} }

View File

@ -315,11 +315,11 @@ interface ContainerInterface
/** /**
* Get the permissions id of the resource. * Get the permissions id of the resource.
* *
* @return string Permissions (e.g. 0644); * @return int Permissions (e.g. 0644);
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getPermission() : string; public function getPermission() : int;
/** /**
* (Re-)Initialize resource * (Re-)Initialize resource

View File

@ -156,27 +156,23 @@ class Directory extends FileAbstract implements DirectoryInterface
*/ */
public static function size(string $dir, bool $recursive = true) : int 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); throw new PathException($dir);
} }
$countSize = 0; $countSize = 0;
$count = 0;
if (is_readable($dir)) {
$dir_array = scandir($dir); $dir_array = scandir($dir);
foreach ($dir_array as $key => $filename) { foreach ($dir_array as $key => $filename) {
if ($filename != ".." && $filename != ".") { if ($filename === ".." || $filename === ".") {
if (is_dir($dir . "/" . $filename) && $recursive) { continue;
$countSize += self::size($dir . "/" . $filename, $recursive);
} else {
if (is_file($dir . "/" . $filename)) {
$countSize += filesize($dir . "/" . $filename);
$count++;
}
}
} }
$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); throw new PathException($from);
} }
if(!$overwrite && file_exists($to)) {
return false;
}
if (!file_exists($to)) { if (!file_exists($to)) {
self::create($to, 0644, true); self::create($to, 0644, true);
} elseif ($overwrite && file_exists($to)) { } elseif ($overwrite && file_exists($to)) {
self::delete($to); self::delete($to);
} else {
return false;
} }
foreach ($iterator = new \RecursiveIteratorIterator( foreach ($iterator = new \RecursiveIteratorIterator(

View File

@ -88,7 +88,7 @@ abstract class FileAbstract implements ContainerInterface
/** /**
* Permission. * Permission.
* *
* @var string * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $permission = 0644; protected $permission = 0644;
@ -176,7 +176,7 @@ abstract class FileAbstract implements ContainerInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getPermission() : string public function getPermission() : int
{ {
return $this->permission; return $this->permission;
} }

View File

@ -14,7 +14,6 @@
declare(strict_types = 1); declare(strict_types = 1);
namespace phpOMS\System\File\Local; namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\StorageAbstract; use phpOMS\System\File\StorageAbstract;
use phpOMS\System\File\PathException; use phpOMS\System\File\PathException;

View File

@ -31,7 +31,7 @@ class PathException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -31,7 +31,7 @@ class PermissionException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -72,120 +72,120 @@ abstract class StorageAbstract
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function created(string $path) : \DateTime; abstract public static function created(string $path) : \DateTime;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function changed(string $path) : \DateTime; abstract public static function changed(string $path) : \DateTime;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function owner(string $path) : int; abstract public static function owner(string $path) : int;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function permission(string $path) : int; abstract public static function permission(string $path) : int;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function parent(string $path) : string; abstract public static function parent(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function create(string $path) : bool; abstract public static function create(string $path) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function delete(string $path) : bool; abstract public static function delete(string $path) : bool;
/** /**
* {@inheritdoc} * {@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} * {@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} * {@inheritdoc}
*/ */
public abstract static function size(string $path, bool $recursive = true) : int; abstract public static function size(string $path, bool $recursive = true) : int;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function exists(string $path) : bool; abstract public static function exists(string $path) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function name(string $path) : string; abstract public static function name(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function basename(string $path) : string; abstract public static function basename(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function dirname(string $path) : string; abstract public static function dirname(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function dirpath(string $path) : string; abstract public static function dirpath(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function list(string $path, string $filter = '*') : array; abstract public static function list(string $path, string $filter = '*') : array;
/** /**
* {@inheritdoc} * {@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} * {@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} * {@inheritdoc}
*/ */
public abstract static function get(string $path) : string; abstract public static function get(string $path) : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function sanitize(string $path, string $replace = '') : string; abstract public static function sanitize(string $path, string $replace = '') : string;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function set(string $path, string $content) : bool; abstract public static function set(string $path, string $content) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function append(string $path, string $content) : bool; abstract public static function append(string $path, string $content) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function prepend(string $path, string $content) : bool; abstract public static function prepend(string $path, string $content) : bool;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public abstract static function extension(string $path) : string; abstract public static function extension(string $path) : string;
} }

View File

@ -46,10 +46,12 @@ class SystemUtils
*/ */
public static function getRAM() : int public static function getRAM() : int
{ {
$mem = null; $mem = 0;
if (stristr(PHP_OS, 'WIN')) { if (stristr(PHP_OS, 'WIN')) {
exec('wmic memorychip get capacity', $mem); exec('wmic memorychip get capacity', $mem);
/** @var array $mem */
$mem = array_sum($mem) / 1024; $mem = array_sum($mem) / 1024;
} elseif (stristr(PHP_OS, 'LINUX')) { } elseif (stristr(PHP_OS, 'LINUX')) {
$fh = fopen('/proc/meminfo', 'r'); $fh = fopen('/proc/meminfo', 'r');
@ -62,6 +64,7 @@ class SystemUtils
break; break;
} }
} }
fclose($fh); fclose($fh);
} }
@ -79,9 +82,7 @@ class SystemUtils
{ {
$memusage = 0; $memusage = 0;
if (stristr(PHP_OS, 'WIN')) { if (stristr(PHP_OS, 'LINUX')) {
} elseif (stristr(PHP_OS, 'LINUX')) {
$free = shell_exec('free'); $free = shell_exec('free');
$free = (string) trim($free); $free = (string) trim($free);
$free_arr = explode("\n", $free); $free_arr = explode("\n", $free);

View File

@ -281,7 +281,7 @@ class Http implements UriInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getQuery(string $key = null) /* : ?string */ public function getQuery(string $key = null) : string
{ {
if (isset($key)) { if (isset($key)) {
$key = strtolower($key); $key = strtolower($key);

View File

@ -31,7 +31,7 @@ class InvalidUriException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -187,7 +187,6 @@ class UriFactory
$full = $parts[1]; $full = $parts[1];
$pars = explode('&', $full); $pars = explode('&', $full);
$comps = []; $comps = [];
$spl = null;
$length = count($pars); $length = count($pars);
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {

View File

@ -117,11 +117,11 @@ interface UriInterface
* *
* @param string $key Query key * @param string $key Query key
* *
* @return string|array * @return string
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getQuery(string $key = null); public function getQuery(string $key = null) : string;
/** /**
* Get fragment. * Get fragment.

View File

@ -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 string $path Path to element
* @param array $data Array * @param array $data Array
@ -97,8 +97,7 @@ class ArrayUtils
if ($overwrite) { if ($overwrite) {
$current = $value; $current = $value;
} else { } elseif (is_array($current) && !is_array($value)) {
if (is_array($current) && !is_array($value)) {
$current[] = $value; $current[] = $value;
} elseif (is_array($current) && is_array($value)) { } elseif (is_array($current) && is_array($value)) {
$current += $value; $current += $value;
@ -107,11 +106,33 @@ class ArrayUtils
} else { } else {
$current = $value; $current = $value;
} }
}
return $data; 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. * Check if needle exists in multidimensional array.
* *
@ -133,7 +154,7 @@ class ArrayUtils
$found = self::inArrayRecursive($needle, $item); $found = self::inArrayRecursive($needle, $item);
if ($found) { if ($found) {
break; return true;
} }
} }
} }

View File

@ -31,7 +31,7 @@ class InvalidJsonException extends \UnexpectedValueException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -91,12 +91,7 @@ class JobQueue
fclose(STDOUT); fclose(STDOUT);
fclose(STDERR); fclose(STDERR);
function shutdown() register_shutdown_function(function() { posix_kill(posix_getpid(), SIGHUP); });
{
posix_kill(posix_getpid(), SIGHUP);
}
register_shutdown_function('shutdown');
} }
public function setRunning(bool $run = true) /* : void */ public function setRunning(bool $run = true) /* : void */

View File

@ -39,6 +39,10 @@ final class Validator extends ValidatorAbstract
*/ */
public static function isValid($var, array $constraints = null) : bool public static function isValid($var, array $constraints = null) : bool
{ {
if (!isset($constraints)) {
return true;
}
foreach ($constraints as $callback => $settings) { foreach ($constraints as $callback => $settings) {
$callback = StringUtils::endsWith($callback, 'Not') ? substr($callback, 0, -3) : $callback; $callback = StringUtils::endsWith($callback, 'Not') ? substr($callback, 0, -3) : $callback;
$valid = self::$callback($var, ...$settings); $valid = self::$callback($var, ...$settings);

View File

@ -82,12 +82,12 @@ class View extends ViewAbstract
* *
* @since 1.0.0 * @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->app = $app;
$this->request = $request; $this->request = $request;
$this->response = $response; $this->response = $response;
$this->l11n = $response->getHeader()->getL11n(); $this->l11n = isset($response) ? $response->getHeader()->getL11n() : null;
} }
/** /**

View File

@ -175,14 +175,14 @@ abstract class ViewAbstract implements \Serializable
/** /**
* Serialize view for rendering. * Serialize view for rendering.
* *
* @return string|array * @return string
* *
* @since 1.0.0 <d.eichhorn@oms.com> * @since 1.0.0 <d.eichhorn@oms.com>
*/ */
public function serialize() public function serialize()
{ {
if (empty($this->template)) { if (empty($this->template)) {
return $this->toArray(); return json_encode($this->toArray());
} }
return $this->render(); return $this->render();
@ -215,11 +215,11 @@ abstract class ViewAbstract implements \Serializable
* *
* @param array $data Data to pass to renderer * @param array $data Data to pass to renderer
* *
* @return array|string * @return string
* *
* @since 1.0.0 <d.eichhorn@oms.com> * @since 1.0.0 <d.eichhorn@oms.com>
*/ */
public function render(...$data) public function render(...$data) : string
{ {
$ob = ''; $ob = '';
$path = __DIR__ . '/../..' . $this->template . '.tpl.php'; $path = __DIR__ . '/../..' . $this->template . '.tpl.php';
@ -235,7 +235,7 @@ abstract class ViewAbstract implements \Serializable
$ob = ob_get_clean(); $ob = ob_get_clean();
if (is_array($includeData)) { if (is_array($includeData)) {
return $includeData; return json_encode($includeData);
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
$ob = ''; $ob = '';