mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Code inspection fixes
This commit is contained in:
parent
d451301a33
commit
34c465766e
|
|
@ -109,7 +109,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Permissions.
|
||||
*
|
||||
* @var array
|
||||
* @var PermissionAbstract[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $permissions = [];
|
||||
|
|
@ -125,7 +125,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
/**
|
||||
* Password.
|
||||
*
|
||||
* @var Password
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $password = '';
|
||||
|
|
@ -207,11 +207,35 @@ class Account implements ArrayableInterface, \JsonSerializable
|
|||
$this->l11n = $l11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set permissions.
|
||||
*
|
||||
* @param PermissionAbstract[] $permissions
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setPermissions(array $permissions) /* : void */
|
||||
{
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has permissions.
|
||||
*
|
||||
* @param int $permission Check if user has this permission
|
||||
* @param int $unit Unit
|
||||
* @param string $app App
|
||||
* @param int $module Module
|
||||
* @param int $type Type (e.g. customer)
|
||||
* @param int $element (e.g. customer id)
|
||||
* @param int $component (e.g. address)
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function hasPermission(int $permission, int $unit = null, string $app = null, int $module = null, int $type = null, $element = null, $component = null) : bool
|
||||
{
|
||||
foreach($this->permissions as $p) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
namespace phpOMS\Account;
|
||||
use Modules\Admin\Models\PermissionType;
|
||||
|
||||
/**
|
||||
* InfoManager class.
|
||||
|
|
@ -27,110 +28,309 @@ namespace phpOMS\Account;
|
|||
*/
|
||||
abstract class PermissionAbstract
|
||||
{
|
||||
/**
|
||||
* Permission id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $id = 0;
|
||||
|
||||
/**
|
||||
* Unit id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $unit = null;
|
||||
|
||||
/**
|
||||
* App name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $app = null;
|
||||
|
||||
/**
|
||||
* Module id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $module = null;
|
||||
|
||||
/**
|
||||
* Providing module id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $from = 0;
|
||||
|
||||
/**
|
||||
* Type.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = null;
|
||||
|
||||
/**
|
||||
* Element id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $element = null;
|
||||
|
||||
/**
|
||||
* Component id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $component = null;
|
||||
|
||||
protected $permission = 0;
|
||||
/**
|
||||
* Permission.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $permission = PermissionType::NONE;
|
||||
|
||||
public function getId()
|
||||
/**
|
||||
* Get permission id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $id;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUnit()
|
||||
/**
|
||||
* Get unit id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getUnit() /* : ?int */
|
||||
{
|
||||
return $this->unit;
|
||||
}
|
||||
|
||||
public function getApp()
|
||||
/**
|
||||
* Get app name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getApp() /* : ?string */
|
||||
{
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
public function getModule()
|
||||
/**
|
||||
* Get module id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getModule() /* : ?int */
|
||||
{
|
||||
return $this->module;
|
||||
}
|
||||
|
||||
public function getFrom()
|
||||
/**
|
||||
* Get providing module id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFrom() /* : ?int */
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
/**
|
||||
* Get type.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getType() /* : ?int */
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getElement()
|
||||
/**
|
||||
* Get element id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getElement() /* : ?int */
|
||||
{
|
||||
return $this->element;
|
||||
}
|
||||
|
||||
public function getComponent()
|
||||
/**
|
||||
* Get component id.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getComponent() /* : ?int */
|
||||
{
|
||||
return $this->component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get permission
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPermission() : int
|
||||
{
|
||||
return $this->permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set unit id.
|
||||
*
|
||||
* @param int $unit Unit
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setUnit(int $unit = null) /* : void */
|
||||
{
|
||||
$this->unit = $unit;
|
||||
}
|
||||
|
||||
public function setApp(int $app = null) /* : void */
|
||||
/**
|
||||
* Set app name.
|
||||
*
|
||||
* @param string $app App name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setApp(string $app = null) /* : void */
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set module id.
|
||||
*
|
||||
* @param int $module Module
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setModule(int $module = null) /* : void */
|
||||
{
|
||||
$this->module = $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set providing module id.
|
||||
*
|
||||
* @param int $from Providing module
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setFrom(int $from = null) /* : void */
|
||||
{
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type.
|
||||
*
|
||||
* @param int $type Type
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setType(int $type = null) /* : void */
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set element id.
|
||||
*
|
||||
* @param int $element Element id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setElement(int $element = null) /* : void */
|
||||
{
|
||||
$this->element = $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set component id.
|
||||
*
|
||||
* @param int $component Component
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setComponent(int $component = null) /* : void */
|
||||
{
|
||||
$this->component = $component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set permission.
|
||||
*
|
||||
* @param int $permission Permission
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setPermission(int $permission = 0) /* : void */
|
||||
{
|
||||
if($permission === 0) {
|
||||
$this->permission = 0;
|
||||
} else {
|
||||
$this->permission |= $permission;
|
||||
}
|
||||
$this->permission = $permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add permission.
|
||||
*
|
||||
* @param int $permission Permission
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function addPermission(int $permission = 0) /* : void */
|
||||
{
|
||||
$this->permission |= $permission;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
Account/PermissionType.php
Normal file
41
Account/PermissionType.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Account;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Permission type enum.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class PermissionType extends Enum
|
||||
{
|
||||
/* public */ const NONE = 0;
|
||||
/* public */ const READ = 1;
|
||||
/* public */ const CREATE = 2;
|
||||
/* public */ const MODIFY = 4;
|
||||
/* public */ const DELETE = 8;
|
||||
/* public */ const PERMISSION = 16;
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Auth;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\DatabaseType;
|
||||
use phpOMS\DataStorage\Session\SessionInterface;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class MarketShareEstimation {
|
|||
* @param float $marketShare (m)
|
||||
* @param float $modifier (s)
|
||||
*
|
||||
* @return float
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,511 +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\DataStorage\Database;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\DataMapperBaseAbstract;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
|
||||
|
||||
/**
|
||||
* Datamapper for databases.
|
||||
*
|
||||
* DB, Cache, Session
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CreateMapperAbstract extends DataMapperBaseAbstract
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object in db.
|
||||
*
|
||||
* @param mixed $obj Object reference (gets filled with insert id)
|
||||
* @param int $relations Create all relations as well
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function create($obj, int $relations = RelationType::ALL)
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
if($obj === null ||
|
||||
(is_object($obj) && strpos($className = get_class($obj), '\Null') !== false)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$reflectionClass = new \ReflectionClass($className);
|
||||
$objId = self::createModel($obj, $reflectionClass);
|
||||
self::setObjectId($reflectionClass, $obj, $objId);
|
||||
|
||||
if ($relations === RelationType::ALL) {
|
||||
self::createHasMany($reflectionClass, $obj, $objId);
|
||||
}
|
||||
|
||||
return $objId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object in db.
|
||||
*
|
||||
* @param array $obj Object reference (gets filled with insert id)
|
||||
* @param int $relations Create all relations as well
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function createArray(array &$obj, int $relations = RelationType::ALL)
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
$objId = self::createModelArray($obj);
|
||||
settype($objId, static::$columns[static::$primaryField]['type']);
|
||||
$obj[static::$columns[static::$primaryField]['internal']] = $objId;
|
||||
|
||||
if ($relations === RelationType::ALL) {
|
||||
self::createHasManyArray($obj, $objId);
|
||||
}
|
||||
|
||||
return $objId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create base model.
|
||||
*
|
||||
* @param Object $obj Model to create
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createModel($obj, \ReflectionClass $reflectionClass)
|
||||
{
|
||||
$query = new Builder(self::$db);
|
||||
$query->prefix(self::$db->getPrefix())->into(static::$table);
|
||||
|
||||
$properties = $reflectionClass->getProperties();
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$propertyName = $property->getName();
|
||||
|
||||
if (isset(static::$hasMany[$propertyName]) || isset(static::$hasOne[$propertyName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
foreach (static::$columns as $key => $column) {
|
||||
if (isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::createOwnsOne($propertyName, $property->getValue($obj));
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif (isset(static::$belongsTo[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::createBelongsTo($propertyName, $property->getValue($obj));
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif ($column['internal'] === $propertyName && $column['type'] !== static::$primaryField) {
|
||||
$value = self::parseValue($column['type'], $property->getValue($obj));
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
}
|
||||
|
||||
self::$db->con->prepare($query->toSql())->execute();
|
||||
|
||||
return self::$db->con->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create base model.
|
||||
*
|
||||
* @param Object $obj Model to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createModelArray($obj)
|
||||
{
|
||||
$query = new Builder(self::$db);
|
||||
$query->prefix(self::$db->getPrefix())->into(static::$table);
|
||||
|
||||
foreach ($obj as $propertyName => &$property) {
|
||||
if (isset(static::$hasMany[$propertyName]) || isset(static::$hasOne[$propertyName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (static::$columns as $key => $column) {
|
||||
if (isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::createOwnsOneArray($propertyName, $property);
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif (isset(static::$belongsTo[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::createBelongsToArray($propertyName, $property);
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif ($column['internal'] === $propertyName && $column['type'] !== static::$primaryField) {
|
||||
$value = self::parseValue($column['type'], $property);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::$db->con->prepare($query->toSql())->execute();
|
||||
|
||||
return self::$db->con->lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create has many
|
||||
*
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
* @param Object $obj Object to create
|
||||
* @param mixed $objId Id to set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidMapperException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createHasMany(\ReflectionClass $reflectionClass, $obj, $objId) /* : void */
|
||||
{
|
||||
foreach (static::$hasMany as $propertyName => $rel) {
|
||||
$property = $reflectionClass->getProperty($propertyName);
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
$values = $property->getValue($obj);
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
|
||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
||||
foreach ($values as $key => &$value) {
|
||||
if (!is_object($value)) {
|
||||
// Is scalar => already in database
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
||||
// already in db
|
||||
if (!empty($primaryKey)) {
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
|
||||
/** @var string $table */
|
||||
/** @var array $columns */
|
||||
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table) {
|
||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['dst']]['internal']);
|
||||
|
||||
if (!$isPublic) {
|
||||
$relProperty->setAccessible(true);
|
||||
}
|
||||
|
||||
$relProperty->setValue($value, $objId);
|
||||
|
||||
if (!($isPublic)) {
|
||||
$relProperty->setAccessible(false);
|
||||
}
|
||||
}
|
||||
|
||||
$objsIds[$key] = $mapper::create($value);
|
||||
}
|
||||
|
||||
self::createRelationTable($propertyName, $objsIds, $objId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create has many
|
||||
*
|
||||
* @param array $obj Object to create
|
||||
* @param mixed $objId Id to set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidMapperException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createHasManyArray(array &$obj, $objId) /* : void */
|
||||
{
|
||||
foreach (static::$hasMany as $propertyName => $rel) {
|
||||
$values = $obj[$propertyName];
|
||||
|
||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
|
||||
foreach ($values as $key => &$value) {
|
||||
if (!is_object($value)) {
|
||||
// Is scalar => already in database
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$primaryKey = $obj[static::$columns[static::$primaryField]['internal']];
|
||||
|
||||
// already in db
|
||||
if (!empty($primaryKey)) {
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
|
||||
/** @var string $table */
|
||||
/** @var array $columns */
|
||||
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table) {
|
||||
$value[$mapper::$columns[static::$hasMany[$propertyName]['dst']]['internal']] = $objId;
|
||||
}
|
||||
|
||||
$objsIds[$key] = $mapper::createArray($value);
|
||||
}
|
||||
|
||||
self::createRelationTable($propertyName, $objsIds, $objId);
|
||||
}
|
||||
}
|
||||
|
||||
private static function createHasOne(\ReflectionClass $reflectionClass, $obj)
|
||||
{
|
||||
throw new \Exception();
|
||||
|
||||
foreach (static::$hasOne as $propertyName => $rel) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
$primaryKey = $mapper::getObjectId($obj);
|
||||
|
||||
if (empty($primaryKey)) {
|
||||
return $mapper::create($obj);
|
||||
}
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param array $obj Object to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createOwnsOneArray(string $propertyName, array &$obj)
|
||||
{
|
||||
if (is_array($obj)) {
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
$primaryKey = $obj[static::$columns[static::$primaryField]['internal']];
|
||||
|
||||
if (empty($primaryKey)) {
|
||||
return $mapper::createArray($obj);
|
||||
}
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
$primaryKey = $mapper::getObjectId($obj);
|
||||
|
||||
if (empty($primaryKey)) {
|
||||
return $mapper::create($obj);
|
||||
}
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createBelongsToArray(string $propertyName, array $obj)
|
||||
{
|
||||
if (is_array($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
$primaryKey = $obj[static::$columns[static::$primaryField]['internal']];
|
||||
|
||||
if (empty($primaryKey)) {
|
||||
return $mapper::createArray($obj);
|
||||
}
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create relation table entry
|
||||
*
|
||||
* In case of a many to many relation the relation has to be stored in a relation table
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param array $objsIds Object ids to insert
|
||||
* @param mixed $objId Model to reference
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createRelationTable(string $propertyName, array $objsIds, $objId)
|
||||
{
|
||||
/** @var string $table */
|
||||
if (
|
||||
!empty($objsIds)
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$table
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table
|
||||
) {
|
||||
$relQuery = new Builder(self::$db);
|
||||
$relQuery->prefix(self::$db->getPrefix())
|
||||
->into(static::$hasMany[$propertyName]['table'])
|
||||
->insert(static::$hasMany[$propertyName]['src'], static::$hasMany[$propertyName]['dst']);
|
||||
|
||||
foreach ($objsIds as $key => $src) {
|
||||
$relQuery->values($src, $objId);
|
||||
}
|
||||
|
||||
self::$db->con->prepare($relQuery->toSql())->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
self::$fields = $objects;
|
||||
|
||||
return __CLASS__;
|
||||
//return __CLASS__;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -450,7 +450,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Create base model.
|
||||
*
|
||||
* @param Object $obj Model to create
|
||||
* @param array $obj Model to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
@ -580,7 +580,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -651,7 +651,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
|
||||
|
|
@ -766,7 +766,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function createBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
$primaryKey = $mapper::getObjectId($obj);
|
||||
|
||||
|
|
@ -786,7 +786,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to create
|
||||
* @param array $obj Object to create
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
@ -795,7 +795,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function createBelongsToArray(string $propertyName, array $obj)
|
||||
{
|
||||
if (is_array($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
$primaryKey = $obj[static::$columns[static::$primaryField]['internal']];
|
||||
|
||||
|
|
@ -912,7 +912,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -1052,7 +1052,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function updateOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
|
|
@ -1078,7 +1078,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function updateBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::update($obj);
|
||||
|
|
@ -1218,7 +1218,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -1271,7 +1271,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function deleteOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
|
|
@ -1296,7 +1296,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function deleteBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::delete($obj);
|
||||
|
|
@ -1485,7 +1485,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
foreach ($result as $member => $values) {
|
||||
if (!empty($values) && $reflectionClass->hasProperty($member)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$member]['mapper'];
|
||||
$reflectionProperty = $reflectionClass->getProperty($member);
|
||||
|
||||
|
|
@ -1522,7 +1522,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
foreach ($result as $member => $values) {
|
||||
if (!empty($values)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasMany[$member]['mapper'];
|
||||
$values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? []));
|
||||
|
||||
|
|
@ -1560,10 +1560,10 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$reflectionProperty->setAccessible(true);
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasOne[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $reflectionProperty->getValue($obj))) {
|
||||
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
} else {
|
||||
$value = $mapper::get($reflectionProperty->getValue($obj));
|
||||
|
|
@ -1592,11 +1592,11 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
public static function populateHasOneArray(array &$obj) /* : void */
|
||||
{
|
||||
foreach (static::$hasOne as $member => $one) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$hasOne[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $obj['member'])) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
$value = self::$initObjects[$mapper][$obj['member']];
|
||||
} else {
|
||||
$value = $mapper::getArray($obj[$member]);
|
||||
}
|
||||
|
|
@ -1629,10 +1629,10 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$reflectionProperty->setAccessible(true);
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$ownsOne[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $reflectionProperty->getValue($obj))) {
|
||||
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
} else {
|
||||
$value = $mapper::get($reflectionProperty->getValue($obj));
|
||||
|
|
@ -1661,11 +1661,11 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
public static function populateOwnsOneArray(array &$obj) /* : void */
|
||||
{
|
||||
foreach (static::$ownsOne as $member => $one) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$ownsOne[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $obj[$member])) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
$value = self::$initObjects[$mapper][$obj[$member]];
|
||||
} else {
|
||||
$value = $mapper::getArray($obj[$member]);
|
||||
}
|
||||
|
|
@ -1698,10 +1698,10 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$reflectionProperty->setAccessible(true);
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $reflectionProperty->getValue($obj))) {
|
||||
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
} else {
|
||||
$value = $mapper::get($reflectionProperty->getValue($obj));
|
||||
|
|
@ -1730,11 +1730,11 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
public static function populateBelongsToArray(array &$obj) /* : void */
|
||||
{
|
||||
foreach (static::$belongsTo as $member => $one) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
/** @var string $mapper */
|
||||
$mapper = static::$belongsTo[$member]['mapper'];
|
||||
|
||||
if(self::isInitialized($mapper, $obj[$member])) {
|
||||
$value = self::$initObjects[$mapper][$id];
|
||||
$value = self::$initObjects[$mapper][$obj[$member]];
|
||||
} else {
|
||||
$value = $mapper::get($obj[$member]);
|
||||
}
|
||||
|
|
@ -1905,7 +1905,6 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
self::extend(__CLASS__);
|
||||
|
||||
$primaryKey = (array) $primaryKey;
|
||||
$fill = (array) $fill;
|
||||
$obj = [];
|
||||
|
||||
foreach ($primaryKey as $key => $value) {
|
||||
|
|
@ -2550,6 +2549,17 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
return count($results) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find database column name by member name
|
||||
*
|
||||
* @param string $name member name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception Throws this exception if the member couldn't be found
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function getColumnByMember(string $name) : string
|
||||
{
|
||||
foreach(static::$columns as $cName => $column) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
|
||||
use phpOMS\DataStorage\Database\Schema\Exception\TableException;
|
||||
|
||||
/**
|
||||
* Database exception factory.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ use phpOMS\Stdlib\Base\Enum;
|
|||
*/
|
||||
abstract class DatabaseStatus extends Enum
|
||||
{
|
||||
/* public */ const OK = 0; /* Database connection successful */
|
||||
/* public */ const OK = 0; /* Database connection successful */
|
||||
/* public */ const MISSING_DATABASE = 1; /* Couldn't find database */
|
||||
/* public */ const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
||||
/* public */ const FAILURE = 3; /* Unknown failure */
|
||||
/* public */ const READONLY = 4; /* Database connection is in readonly (but ok) */
|
||||
/* public */ const CLOSED = 5; /* Database connection closed */
|
||||
/* public */ const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
||||
/* public */ const FAILURE = 3; /* Unknown failure */
|
||||
/* public */ const READONLY = 4; /* Database connection is in readonly (but ok) */
|
||||
/* public */ const CLOSED = 5; /* Database connection closed */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ use phpOMS\Stdlib\Base\Enum;
|
|||
*/
|
||||
abstract class DatabaseType extends Enum
|
||||
{
|
||||
/* public */ const MYSQL = 'mysql'; /* MySQL */
|
||||
/* public */ const SQLITE = 'sqlite'; /* SQLITE */
|
||||
/* public */ const PGSQL = 2; /* PostgreSQL */
|
||||
/* public */ const ORACLE = 3; /* Oracle */
|
||||
/* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */
|
||||
/* public */ const MYSQL = 'mysql'; /* MySQL */
|
||||
/* public */ const SQLITE = 'sqlite'; /* SQLITE */
|
||||
/* public */ const PGSQL = 2; /* PostgreSQL */
|
||||
/* public */ const ORACLE = 3; /* Oracle */
|
||||
/* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,295 +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\DataStorage\Database;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\DataMapperBaseAbstract;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
|
||||
|
||||
/**
|
||||
* Datamapper for databases.
|
||||
*
|
||||
* DB, Cache, Session
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class DeleteMapperAbstract extends DataMapperBaseAbstract
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete has many
|
||||
*
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
* @param Object $obj Object to create
|
||||
* @param mixed $objId Id to set
|
||||
* @param int $relations Delete all relations as well
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidMapperException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deleteHasMany(\ReflectionClass $reflectionClass, $obj, $objId, int $relations) /* : void */
|
||||
{
|
||||
foreach (static::$hasMany as $propertyName => $rel) {
|
||||
$property = $reflectionClass->getProperty($propertyName);
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
$values = $property->getValue($obj);
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
|
||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
||||
foreach ($values as $key => &$value) {
|
||||
if (!is_object($value)) {
|
||||
// Is scalar => already in database
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
||||
// already in db
|
||||
if (!empty($primaryKey)) {
|
||||
if($relations === RelationType::ALL) {
|
||||
$objsIds[$key] = $mapper::delete($value);
|
||||
} else {
|
||||
$objsIds[$key] = $primaryKey;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// todo: could be a problem, relation needs to be removed first?!
|
||||
|
||||
}
|
||||
|
||||
self::deleteRelationTable($propertyName, $objsIds, $objId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to delete
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deleteOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
return $mapper::delete($obj);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to delete
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deleteBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::delete($obj);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete object in db.
|
||||
*
|
||||
* @param Object $obj Model to delete
|
||||
* @param mixed $objId Model id
|
||||
* @param int $relations Delete all relations as well
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deleteModel($obj, $objId, int $relations = RelationType::REFERENCE, \ReflectionClass $reflectionClass = null) /* : void */
|
||||
{
|
||||
$query = new Builder(self::$db);
|
||||
$query->prefix(self::$db->getPrefix())
|
||||
->delete()
|
||||
->into(static::$table)
|
||||
->where(static::$primaryField, '=', $objId);
|
||||
|
||||
$properties = $reflectionClass->getProperties();
|
||||
|
||||
if($relations === RelationType::ALL) {
|
||||
foreach ($properties as $property) {
|
||||
$propertyName = $property->getName();
|
||||
|
||||
if (isset(static::$hasMany[$propertyName]) || isset(static::$hasOne[$propertyName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
// todo: the order of deletion could be a problem. maybe looping through ownsOne and belongsTo first is better.
|
||||
// todo: support other relation types as well (belongsto, ownsone) = for better control
|
||||
|
||||
foreach (static::$columns as $key => $column) {
|
||||
if ($relations === RelationType::ALL && isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
self::deleteOwnsOne($propertyName, $property->getValue($obj));
|
||||
break;
|
||||
} elseif ($relations === RelationType::ALL && isset(static::$belongsTo[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
self::deleteBelongsTo($propertyName, $property->getValue($obj));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::$db->con->prepare($query->toSql())->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete object in db.
|
||||
*
|
||||
* @param mixed $obj Object reference (gets filled with insert id)
|
||||
* @param int $relations Create all relations as well
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function delete($obj, int $relations = RelationType::REFERENCE)
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$objId = self::getObjectId($obj, $reflectionClass);
|
||||
|
||||
if(empty($objId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($relations !== RelationType::NONE) {
|
||||
self::deleteHasMany($reflectionClass, $obj, $objId, $relations);
|
||||
}
|
||||
|
||||
self::deleteModel($obj, $objId, $relations, $reflectionClass);
|
||||
|
||||
return $objId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete relation table entry
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param array $objsIds Object ids to insert
|
||||
* @param mixed $objId Model to reference
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function deleteRelationTable(string $propertyName, array $objsIds, $objId)
|
||||
{
|
||||
/** @var string $table */
|
||||
if (
|
||||
!empty($objsIds)
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$table
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table
|
||||
) {
|
||||
foreach ($objsIds as $key => $src) {
|
||||
$relQuery = new Builder(self::$db);
|
||||
$relQuery->prefix(self::$db->getPrefix())
|
||||
->into(static::$hasMany[$propertyName]['table'])
|
||||
->delete();
|
||||
|
||||
$relQuery->where(static::$hasMany[$propertyName]['src'], '=', $src)
|
||||
->where(static::$hasMany[$propertyName]['dst'], '=', $objId, 'and');
|
||||
|
||||
self::$db->con->prepare($relQuery->toSql())->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
|
||||
use phpOMS\Utils\StringUtils;
|
||||
|
||||
/**
|
||||
* Grammar.
|
||||
*
|
||||
|
|
@ -79,7 +77,7 @@ abstract class GrammarAbstract
|
|||
/**
|
||||
* Special keywords.
|
||||
*
|
||||
* @var string
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $specialKeywords = [
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -30,11 +30,11 @@ use phpOMS\Stdlib\Base\Enum;
|
|||
*/
|
||||
abstract class RelationType extends Enum
|
||||
{
|
||||
/* public */ const NONE = 0;
|
||||
/* public */ const NEWEST = 1;
|
||||
/* public */ const NONE = 0;
|
||||
/* public */ const NEWEST = 1;
|
||||
/* public */ const BELONGS_TO = 2;
|
||||
/* public */ const OWNS_ONE = 4;
|
||||
/* public */ const HAS_MANY = 8;
|
||||
/* public */ const ALL = 16;
|
||||
/* public */ const REFERENCE = 32;
|
||||
/* public */ const OWNS_ONE = 4;
|
||||
/* public */ const HAS_MANY = 8;
|
||||
/* public */ const ALL = 16;
|
||||
/* public */ const REFERENCE = 32;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,326 +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\DataStorage\Database;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\DataMapperBaseAbstract;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
|
||||
|
||||
/**
|
||||
* Datamapper for databases.
|
||||
*
|
||||
* DB, Cache, Session
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\DataStorage\Database
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class UpdateMapperAbstract extends DataMapperBaseAbstract
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Update has many
|
||||
*
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
* @param Object $obj Object to create
|
||||
* @param mixed $objId Id to set
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidMapperException
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function updateHasMany(\ReflectionClass $reflectionClass, $obj, $objId) /* : void */
|
||||
{
|
||||
foreach (static::$hasMany as $propertyName => $rel) {
|
||||
$property = $reflectionClass->getProperty($propertyName);
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
$values = $property->getValue($obj);
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
|
||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||
throw new InvalidMapperException();
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
||||
foreach ($values as $key => &$value) {
|
||||
if (!is_object($value)) {
|
||||
// Is scalar => already in database
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($relReflectionClass)) {
|
||||
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||
}
|
||||
|
||||
$primaryKey = $mapper::getObjectId($value, $relReflectionClass);
|
||||
|
||||
// already in db
|
||||
if (!empty($primaryKey)) {
|
||||
$objsIds[$key] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// create if not existing
|
||||
/** @var string $table */
|
||||
/** @var array $columns */
|
||||
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table) {
|
||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['dst']]['internal']);
|
||||
|
||||
if (!$isPublic) {
|
||||
$relProperty->setAccessible(true);
|
||||
}
|
||||
|
||||
$relProperty->setValue($value, $objId);
|
||||
|
||||
if (!($isPublic)) {
|
||||
$relProperty->setAccessible(false);
|
||||
}
|
||||
}
|
||||
|
||||
$objsIds[$key] = $mapper::create($value);
|
||||
}
|
||||
|
||||
self::updateRelationTable($propertyName, $objsIds, $objId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update relation table entry
|
||||
*
|
||||
* Deletes old entries and creates new ones
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param array $objsIds Object ids to insert
|
||||
* @param mixed $objId Model to reference
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function updateRelationTable(string $propertyName, array $objsIds, $objId)
|
||||
{
|
||||
/** @var string $table */
|
||||
if (
|
||||
!empty($objsIds)
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$table
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table
|
||||
) {
|
||||
$many = self::getHasManyRaw($objId);
|
||||
|
||||
foreach(static::$hasMany as $member => $value) {
|
||||
// todo: definately an error here. needs testing
|
||||
throw new \Exception();
|
||||
$removes = array_diff_key($many[$member], $objsIds[$member]);
|
||||
$adds = array_diff_key($objsIds[$member], $many[$member]);
|
||||
|
||||
if(!empty($removes)) {
|
||||
self::deleteRelationTable($propertyName, $removes, $objId);
|
||||
}
|
||||
|
||||
if(!empty($adds)) {
|
||||
self::createRelationTable($propertyName, $adds, $objId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to update
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function updateOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
|
||||
return $mapper::update($obj);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update owns one
|
||||
*
|
||||
* The reference is stored in the main model
|
||||
*
|
||||
* @param string $propertyName Property name to initialize
|
||||
* @param Object $obj Object to update
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function updateBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::update($obj);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object in db.
|
||||
*
|
||||
* @param Object $obj Model to update
|
||||
* @param mixed $objId Model id
|
||||
* @param \ReflectionClass $reflectionClass Reflection class
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function updateModel($obj, $objId, \ReflectionClass $reflectionClass = null) /* : void */
|
||||
{
|
||||
$query = new Builder(self::$db);
|
||||
$query->prefix(self::$db->getPrefix())
|
||||
->into(static::$table)
|
||||
->where(static::$primaryField, '=', $objId);
|
||||
|
||||
$properties = $reflectionClass->getProperties();
|
||||
|
||||
foreach ($properties as $property) {
|
||||
$propertyName = $property->getName();
|
||||
|
||||
if (isset(static::$hasMany[$propertyName]) || isset(static::$hasOne[$propertyName])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($isPublic = $property->isPublic())) {
|
||||
$property->setAccessible(true);
|
||||
}
|
||||
|
||||
// todo: the order of updating could be a problem. maybe looping through ownsOne and belongsTo first is better.
|
||||
|
||||
foreach (static::$columns as $key => $column) {
|
||||
if (isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::updateOwnsOne($propertyName, $property->getValue($obj));
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
// todo: should not be done if the id didn't change. but for now don't know if id changed
|
||||
$query->update($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif (isset(static::$belongsTo[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::updateBelongsTo($propertyName, $property->getValue($obj));
|
||||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
// todo: should not be done if the id didn't change. but for now don't know if id changed
|
||||
$query->update($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
} elseif ($column['internal'] === $propertyName && $column['type'] !== static::$primaryField) {
|
||||
$value = self::parseValue($column['type'], $property->getValue($obj));
|
||||
|
||||
$query->update($column['name'])->value($value, $column['type']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!($isPublic)) {
|
||||
$property->setAccessible(false);
|
||||
}
|
||||
}
|
||||
|
||||
self::$db->con->prepare($query->toSql())->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object in db.
|
||||
*
|
||||
* @param mixed $obj Object reference (gets filled with insert id)
|
||||
* @param int $relations Create all relations as well
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function update($obj, int $relations = RelationType::ALL) : int
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$objId = self::getObjectId($obj, $reflectionClass);
|
||||
$update = true;
|
||||
|
||||
if(empty($objId)) {
|
||||
$update = false;
|
||||
self::create($obj, $relations);
|
||||
}
|
||||
|
||||
if ($relations === RelationType::ALL) {
|
||||
self::updateHasMany($reflectionClass, $obj, $objId);
|
||||
}
|
||||
|
||||
if($update) {
|
||||
self::updateModel($obj, $objId, $reflectionClass);
|
||||
}
|
||||
|
||||
return $objId;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Localization;
|
||||
|
||||
use phpOMS\Log\FileLogger;
|
||||
use phpOMS\Log\LoggerInterface;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
|
||||
/**
|
||||
|
|
@ -39,24 +38,13 @@ class L11nManager
|
|||
*/
|
||||
private $language = [];
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
*
|
||||
* @var LoggerInterface
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $logger = null;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param LoggerInterface $logger Logger
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -170,16 +158,10 @@ class L11nManager
|
|||
$this->loadLanguage($code, $module, $class::getLocalization($code, $theme));
|
||||
|
||||
if (!isset($this->language[$code][$module][$translation])) {
|
||||
if(isset($this->logger)) {
|
||||
$this->logger->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.',
|
||||
]);
|
||||
}
|
||||
|
||||
return 'ERROR';
|
||||
}
|
||||
} catch(\Excpetion $e) {
|
||||
$this->logger->warning(FileLogger::MSG_FULL, [
|
||||
} catch(\Exception $e) {
|
||||
FileLogger::getInstance()->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.',
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ namespace phpOMS\Log;
|
|||
|
||||
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
||||
use phpOMS\System\File\Local\File;
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\Utils\StringUtils;
|
||||
|
||||
/**
|
||||
* Logging class.
|
||||
|
|
|
|||
|
|
@ -12,13 +12,22 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||
|
||||
use phpOMS\Math\Statistic\Average;
|
||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||
use phpOMS\Math\Matrix\Exception\InvalidDimensionException;
|
||||
|
||||
/**
|
||||
* Regression abstract class.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Math\Statistic
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class RegressionAbstract
|
||||
{
|
||||
/**
|
||||
|
|
@ -146,7 +155,35 @@ abstract class RegressionAbstract
|
|||
return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x);
|
||||
}
|
||||
|
||||
abstract public static function getSlope(float $b1, float $y, float $x) : float;
|
||||
/**
|
||||
* Get slope
|
||||
*
|
||||
* @param float $b1 Beta 1
|
||||
* @param float $x Obersved x values
|
||||
* @param float $y Observed y values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getSlope(float $b1, float $y, float $x) : float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
abstract public static function getElasticity(float $b1, float $y, float $x): float;
|
||||
/**
|
||||
* Get elasticity
|
||||
*
|
||||
* @param float $b1 Beta 1
|
||||
* @param float $x Obersved x values
|
||||
* @param float $y Observed y values
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getElasticity(float $b1, float $y, float $x): float
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ class NaiveBayesFilter
|
|||
}
|
||||
}
|
||||
|
||||
return 1 / (1+exp(M_E, $n));
|
||||
return 1 / (1+exp($n));
|
||||
}
|
||||
|
||||
private function normalizeDictionary() : array
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ abstract class HeaderAbstract
|
|||
/**
|
||||
* Set localization
|
||||
*
|
||||
* @param int $localization Localization
|
||||
* @param Localization $l11n Localization
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -135,7 +135,7 @@ abstract class HeaderAbstract
|
|||
public function setStatusCode(int $status) /* : void */
|
||||
{
|
||||
$this->status = $status;
|
||||
$this->header->generate($status);
|
||||
$this->generate($status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Message\Http;
|
||||
|
||||
use phpOMS\Message\HeaderAbstract;
|
||||
use phpOMS\DataStorage\LockExcpetion;
|
||||
use phpOMS\DataStorage\LockException;
|
||||
|
||||
/**
|
||||
* Response class.
|
||||
|
|
@ -68,7 +68,7 @@ class Header extends HeaderAbstract
|
|||
public function set(string $key, string $header, bool $overwrite = false) : bool
|
||||
{
|
||||
if (self::$isLocked) {
|
||||
throw new LockExcpetion('HTTP header');
|
||||
throw new LockException('HTTP header');
|
||||
}
|
||||
|
||||
$key = strtolower($key);
|
||||
|
|
@ -145,18 +145,6 @@ class Header extends HeaderAbstract
|
|||
return self::getAllHeaders();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pushed header by name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getHeader(string $name) : string
|
||||
{
|
||||
return self::getAllHeaders()[$name] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all headers for apache and nginx
|
||||
*
|
||||
|
|
@ -194,7 +182,7 @@ class Header extends HeaderAbstract
|
|||
public function remove(int $key) : bool
|
||||
{
|
||||
if (self::$isLocked) {
|
||||
throw new \LockException('HTTP header');
|
||||
throw new LockException('HTTP header');
|
||||
}
|
||||
|
||||
if (isset($this->header[$key])) {
|
||||
|
|
@ -209,7 +197,7 @@ class Header extends HeaderAbstract
|
|||
/**
|
||||
* Get header by name.
|
||||
*
|
||||
* @param int $key Header key
|
||||
* @param string $key Header key
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -219,19 +207,19 @@ class Header extends HeaderAbstract
|
|||
{
|
||||
return $this->header[strtolower($key)] ?? [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReasonPhrase() : string
|
||||
{
|
||||
return $this->header->getHeader('Status');
|
||||
return $this->get('Status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if header is defined.
|
||||
*
|
||||
* @param int $key Header key
|
||||
* @param string $key Header key
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -74,10 +74,11 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
public function __construct(Localization $l11n = null, UriInterface $uri = null)
|
||||
{
|
||||
$this->l11n = $l11n;
|
||||
$this->uri = $uri;
|
||||
$this->source = RequestSource::WEB;
|
||||
$this->header = new Header();
|
||||
$this->header->setL11n($l11n);
|
||||
|
||||
$this->uri = $uri;
|
||||
$this->source = RequestSource::WEB;
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
|
@ -110,7 +111,7 @@ class Request extends RequestAbstract
|
|||
*
|
||||
* This is used in order to either initialize the current http request or a batch of GET requests
|
||||
*
|
||||
* @param mixed $uri URL
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -143,7 +144,7 @@ class Request extends RequestAbstract
|
|||
$this->uri = new Http(Http::getCurrent());
|
||||
$this->data = $_GET ?? [];
|
||||
$this->files = $_FILES ?? [];
|
||||
$this->language = $this->loadRequestLanguage();
|
||||
$this->header->getL11n()->setLanguage($this->loadRequestLanguage());
|
||||
|
||||
if (isset($_SERVER['CONTENT_TYPE'])) {
|
||||
if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
|
||||
|
|
@ -204,7 +205,7 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
private function setupUriBuilder() /* : void */
|
||||
{
|
||||
UriFactory::setQuery('/lang', $this->l11n->getLanguage());
|
||||
UriFactory::setQuery('/lang', $this->header->getL11n()->getLanguage());
|
||||
|
||||
// todo: flush previous
|
||||
foreach($this->data as $key => $value) {
|
||||
|
|
@ -212,14 +213,6 @@ class Request extends RequestAbstract
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getLanguage() : string
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create request hashs of current request
|
||||
*
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
public function __construct(Localization $l11n)
|
||||
{
|
||||
$this->header = new Header();
|
||||
$this->l11n = $l11n;
|
||||
$this->header->setL11n($l11n);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Message;
|
||||
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Utils\ArrayUtils;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class InstallerAbstract
|
|||
/**
|
||||
* Init routes.
|
||||
*
|
||||
* @param string $routePath Route Path
|
||||
* @param string $modulePath Path to the module
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ class ModuleManager
|
|||
* Constructor.
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param string $modulePath Path to modules
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,8 +25,6 @@ use phpOMS\Validation\Finance\IbanEnum;
|
|||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @todo : there is a bug with Hungary ibans since they have two k (checksums) in their definition
|
||||
*/
|
||||
class Iban implements \Serializable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get location id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -111,6 +113,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get location type
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -120,12 +124,23 @@ class Location implements \JsonSerializable, \Serializable
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set location type
|
||||
*
|
||||
* @param int $type Location type
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setType(int $type) /* : void */
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get postal or zip code
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -136,6 +151,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set postal or zip code
|
||||
*
|
||||
* @param string $postal
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -148,6 +165,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get city name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -158,6 +177,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set city name
|
||||
*
|
||||
* @param string $city
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -170,6 +191,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get country code
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -180,6 +203,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set country code
|
||||
*
|
||||
* @param string $country
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -192,6 +217,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get address
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -202,6 +229,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set address
|
||||
*
|
||||
* @param string $address
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -214,6 +243,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get state name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -224,6 +255,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set state name
|
||||
*
|
||||
* @param string $state
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -236,6 +269,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get geo location
|
||||
*
|
||||
* @return float[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -246,6 +281,8 @@ class Location implements \JsonSerializable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Set geo location
|
||||
*
|
||||
* @param float[] $geo
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class SmartDateTime extends \DateTime
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function createFromDateTime(\Datetime $date) : SmartDateTime
|
||||
public static function createFromDateTime(\DateTime $date) : SmartDateTime
|
||||
{
|
||||
return new self($date->format('Y-m-d H:i:s'), $date->getTimezone());
|
||||
}
|
||||
|
|
@ -192,6 +192,8 @@ class SmartDateTime extends \DateTime
|
|||
/**
|
||||
* Test year if leap year in gregorian calendar
|
||||
*
|
||||
* @param int $year Year to check
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
|
|||
|
|
@ -36,11 +36,25 @@ class FileUtils
|
|||
/* public */ const SPREADSHEET_EXTENSION = ['xls', 'xlsm'];
|
||||
/* public */ const IMAGE_EXTENSION = ['png', 'gif', 'jpg', 'jpeg', 'tiff', 'bmp'];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file extension type.
|
||||
*
|
||||
* @param string $extension Extension string
|
||||
*
|
||||
* @return int Extension type
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getExtensionType(string $extension) : int
|
||||
{
|
||||
$extension = strtolower($extension);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ final class Storage
|
|||
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
|
||||
|
||||
try {
|
||||
/** @var StorageAbstract $env */
|
||||
$env = $env::getInstance();
|
||||
|
||||
self::$registered[$stg] = $env;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract public static function getInstance() : StorageAbstract;
|
||||
public static function getInstance() : StorageAbstract
|
||||
{
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get storage type.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -60,12 +60,21 @@ final class UnhandledHandler
|
|||
*/
|
||||
public static function errorHandler(int $errno, string $errstr, string $errfile, int $errline) : bool
|
||||
{
|
||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||
|
||||
if (!(error_reporting() & $errno)) {
|
||||
// This error code is not included in error_reporting
|
||||
$logger->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'Undefined error',
|
||||
'line' => $errline,
|
||||
'file' => $errfile,
|
||||
]);
|
||||
|
||||
error_clear_last();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||
|
||||
$logger->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'Unhandled error',
|
||||
'line' => $errline,
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ class Http implements UriInterface
|
|||
$this->path = substr($this->path, 0, -4);
|
||||
}
|
||||
|
||||
$this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; // TODO: this could cause a bug if the rootpath is the same as a regular path which is usually the language
|
||||
$this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path;
|
||||
$this->queryString = $url['query'] ?? '';
|
||||
|
||||
if (!empty($this->queryString)) {
|
||||
|
|
@ -286,6 +286,9 @@ class Http implements UriInterface
|
|||
return explode('/', $this->path)[$pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPathElements() : array
|
||||
{
|
||||
return explode('/', $this->path);
|
||||
|
|
|
|||
|
|
@ -103,6 +103,15 @@ interface UriInterface
|
|||
*/
|
||||
public function getPathElement(int $pos) : string;
|
||||
|
||||
/**
|
||||
* Get path elements.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getPathElements() : array;
|
||||
|
||||
/**
|
||||
* Get query.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class FunctionalGroupHedaer
|
|||
public function serialize()
|
||||
{
|
||||
return $this->functionalGroupHeader . '*'
|
||||
. $this->getfunctionalIdentifierCode() . '*'
|
||||
. $this->getFunctionalIdentifierCode() . '*'
|
||||
. $this->getApplicationSenderCode() . '*'
|
||||
. $this->getApplicationReceiverCode() . '*'
|
||||
. $this->getDate() . '*'
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ class InterchangeControlHeader
|
|||
$this->setInterchangeIdQualifier((int) trim($split[5]));
|
||||
$this->setInterchangeSender(trim($split[6]));
|
||||
$this->setInterchangeReceiver(trim($split[8]));
|
||||
$this->setInterchangeDateTime(new \DateTime(trim($split[9]) . '-' . trim($split[10])));
|
||||
$this->setInterchangeDatetime(new \DateTime(trim($split[9]) . '-' . trim($split[10])));
|
||||
$this->setInterchangeControlStandardId(trim($split[11]));
|
||||
$this->setInterchangeControlVersionNumber((int) trim($split[12]));
|
||||
$this->setInterchangeControlNumber((int) trim($split[13]));
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Caesar
|
|||
/**
|
||||
* ASCII upper char limit.
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
/* public */ const LIMIT_UPPER = 127;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Gz implements ArchiveInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function pack(string $source, string $destination, bool $overwrite = true) : bool
|
||||
public static function pack($source, string $destination, bool $overwrite = true) : bool
|
||||
{
|
||||
$destination = str_replace('\\', '/', realpath($destination));
|
||||
if (!$overwrite && file_exists($destination)) {
|
||||
|
|
@ -56,7 +56,7 @@ class Gz implements ArchiveInterface
|
|||
public static function unpack(string $source, string $destination) : bool
|
||||
{
|
||||
$destination = str_replace('\\', '/', realpath($destination));
|
||||
if (!$overwrite && file_exists($destination)) {
|
||||
if (file_exists($destination)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -65,8 +65,8 @@ class Gz implements ArchiveInterface
|
|||
}
|
||||
|
||||
$dest = fopen($destination, 'w');
|
||||
while (!gzeof($handle)) {
|
||||
fwrite($dest, gzread($handle, 4096));
|
||||
while (!gzeof($gz)) {
|
||||
fwrite($dest, gzread($gz, 4096));
|
||||
}
|
||||
|
||||
fclose($dest);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class Tar implements ArchiveInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function pack(array $source, string $destination, bool $overwrite = true) : bool
|
||||
public static function pack($sources, string $destination, bool $overwrite = true) : bool
|
||||
{
|
||||
$destination = str_replace('\\', '/', realpath($destination));
|
||||
|
||||
|
|
@ -37,6 +37,7 @@ class Tar implements ArchiveInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
/** @var array $sources */
|
||||
foreach ($sources as $source) {
|
||||
$source = str_replace('\\', '/', realpath($source));
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TarGz implements ArchiveInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function pack(array $source, string $destination, bool $overwrite = true) : bool
|
||||
public static function pack($source, string $destination, bool $overwrite = true) : bool
|
||||
{
|
||||
if(!Tar::pack($source, $destination . '.tmp', $overwrite)) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class Zip implements ArchiveInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function pack(array $sources, string $destination, bool $overwrite = true) : bool
|
||||
public static function pack($sources, string $destination, bool $overwrite = true) : bool
|
||||
{
|
||||
$destination = str_replace('\\', '/', realpath($destination));
|
||||
|
||||
|
|
@ -45,6 +45,7 @@ class Zip implements ArchiveInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
/** @var array $sources */
|
||||
foreach ($sources as $source) {
|
||||
$source = str_replace('\\', '/', realpath($source));
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class JobQueue
|
|||
$this->runAsDeamon();
|
||||
|
||||
if (posix_setsid() < 0 || $pid = pcntl_fork()) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class StringCompare
|
|||
$bestScore = PHP_INT_MAX;
|
||||
$bestMatch = '';
|
||||
|
||||
foreach($dictionary as $word) {
|
||||
foreach($this->dictionary as $word) {
|
||||
$score = self::fuzzyMatch($word, $match);
|
||||
|
||||
if($score < $bestScore) {
|
||||
|
|
@ -145,7 +145,7 @@ class StringCompare
|
|||
*
|
||||
* @param string $s1 Word 1
|
||||
* @param string $s2 Word 2
|
||||
* @param float $prhaseWeight Weighting for phrase score
|
||||
* @param float $phraseWeight Weighting for phrase score
|
||||
* @param float $wordWeight Weighting for word score
|
||||
* @param float $minWeight Min weight
|
||||
* @param float $maxWeight Max weight
|
||||
|
|
@ -157,9 +157,9 @@ class StringCompare
|
|||
*/
|
||||
public static function fuzzyMatch(string $s1, string $s2, float $phraseWeight = 0.5, float $wordWeight = 1, float $minWeight = 10, float $maxWeight = 1, float $lengthWeight = -0.3) : float
|
||||
{
|
||||
$phraseValue = valuePhrase($s1, $s2);
|
||||
$wordValue = valueWords($s1, $s2);
|
||||
$lengthValue = valueLength($s1, $s2);
|
||||
$phraseValue = self::valuePhrase($s1, $s2);
|
||||
$wordValue = self::valueWords($s1, $s2);
|
||||
$lengthValue = self::valueLength($s1, $s2);
|
||||
|
||||
return min($phraseValue * $phraseWeight, $wordValue * $wordWeight) * $minWeight
|
||||
+ max($phraseValue * $phraseWeight, $wordValue * $wordWeight) * $maxWeight
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ class StringUtils
|
|||
/**
|
||||
* Calculate string entropy
|
||||
*
|
||||
* @param string $string String to analyze.
|
||||
* @param string $value String to analyze.
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -359,10 +359,10 @@ class StringUtils
|
|||
{
|
||||
$entroy = 0.0;
|
||||
$size = mb_strlen($value);
|
||||
$countChars = self::mb_count_chars($value, 1);
|
||||
$countChars = self::mb_count_chars($value);
|
||||
|
||||
foreach ($countChars as $v) {
|
||||
$p = $v / $size;
|
||||
for ($i = 0; $i < $countChars; $i++) {
|
||||
$p = $value[$i] / $size;
|
||||
$entroy -= $p * log($p) / log(2);
|
||||
}
|
||||
|
||||
|
|
@ -372,13 +372,14 @@ class StringUtils
|
|||
/**
|
||||
* Count chars of utf-8 string.
|
||||
*
|
||||
* @param string $string String to count chars.
|
||||
* @param string $input String to count chars.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function mb_count_chars(string $input) {
|
||||
public static function mb_count_chars(string $input) : int
|
||||
{
|
||||
$l = mb_strlen($input, 'UTF-8');
|
||||
$unique = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TestUtils
|
|||
/**
|
||||
* Set private object member
|
||||
*
|
||||
* @param object $object Object to modify
|
||||
* @param object $obj Object to modify
|
||||
* @param string $name Member name to modify
|
||||
* @param mixed $value Value to set
|
||||
*
|
||||
|
|
@ -63,7 +63,7 @@ class TestUtils
|
|||
/**
|
||||
* Get private object member
|
||||
*
|
||||
* @param object $object Object to read
|
||||
* @param object $obj Object to read
|
||||
* @param string $name Member name to read
|
||||
*
|
||||
* @return mixed Returns the member variable value
|
||||
|
|
|
|||
|
|
@ -39,11 +39,7 @@ abstract class Iban extends ValidatorAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $value Iban to validate
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function isValid($value, array $constraints = null) : bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,11 +46,29 @@ class Ip extends ValidatorAbstract
|
|||
return filter_var($value, FILTER_VALIDATE_IP) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate IPv6
|
||||
*
|
||||
* @param mixed $value to validate
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function isValidIpv6($value) : bool
|
||||
{
|
||||
return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate IPv4
|
||||
*
|
||||
* @param mixed $value to validate
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function isValidIpv4($value) : bool
|
||||
{
|
||||
return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,13 @@ abstract class ValidatorAbstract implements ValidatorInterface
|
|||
return self::$error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset error information
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function resetError() /* : void */
|
||||
{
|
||||
self::$error = 0;
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class View extends ViewAbstract
|
|||
* @return string
|
||||
*
|
||||
* @throws InvalidModuleException Throws this exception if no data for the defined module could be found.
|
||||
* @throws InvalidTemplateException Throws this exception if no data for the defined theme could be found.
|
||||
* @throws InvalidThemeException Throws this exception if no data for the defined theme could be found.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ abstract class ViewAbstract implements \Serializable
|
|||
* @param int $order Order of view
|
||||
* @param bool $overwrite Overwrite existing view
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0 <d.eichhorn@oms.com>
|
||||
*/
|
||||
|
|
@ -231,16 +231,16 @@ abstract class ViewAbstract implements \Serializable
|
|||
/**
|
||||
* Get view/template response.
|
||||
*
|
||||
* @return string|array
|
||||
* @param array $data Data to pass to renderer
|
||||
*
|
||||
* @return array|string
|
||||
*
|
||||
* @since 1.0.0 <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function render(...$data)
|
||||
{
|
||||
$ob = '';
|
||||
|
||||
|
||||
$path = __DIR__ . '/../..' . $this->template . '.tpl.php';
|
||||
$ob = '';
|
||||
$path = __DIR__ . '/../..' . $this->template . '.tpl.php';
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new PathException($path);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user