mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-09 05:38:39 +00:00
Merge pull request #124 from Orange-Management/develop
Semi stable stage
This commit is contained in:
commit
7c24bdbbcc
|
|
@ -21,7 +21,10 @@ use phpOMS\Localization\NullLocalization;
|
||||||
use phpOMS\Validation\Network\Email;
|
use phpOMS\Validation\Network\Email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account manager class.
|
* Account class.
|
||||||
|
*
|
||||||
|
* The account class is the base model for accounts. This model contains the most common account
|
||||||
|
* information. This model is not comparable to a profile which contains much more information.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Account
|
* @package phpOMS\Account
|
||||||
|
|
@ -109,7 +112,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Permissions.
|
* Permissions.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var PermissionAbstract[]
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $permissions = [];
|
protected $permissions = [];
|
||||||
|
|
@ -125,7 +128,7 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Password.
|
* Password.
|
||||||
*
|
*
|
||||||
* @var Password
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $password = '';
|
protected $password = '';
|
||||||
|
|
@ -156,6 +159,8 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
*
|
||||||
|
* The constructor automatically sets the created date as well as the last activity to now.
|
||||||
*
|
*
|
||||||
* @param int $id Account id
|
* @param int $id Account id
|
||||||
*
|
*
|
||||||
|
|
@ -183,6 +188,8 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get localization.
|
* Get localization.
|
||||||
|
*
|
||||||
|
* Every account can have a different localization which can be accessed here.
|
||||||
*
|
*
|
||||||
* @return Localization
|
* @return Localization
|
||||||
*
|
*
|
||||||
|
|
@ -193,6 +200,35 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->l11n;
|
return $this->l11n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get groups.
|
||||||
|
*
|
||||||
|
* Every account can belong to multiple groups.
|
||||||
|
* These groups usually are used for permissions and categorize accounts.
|
||||||
|
*
|
||||||
|
* @return array Returns array of all groups
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getGroups() : array
|
||||||
|
{
|
||||||
|
return $this->groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add group.
|
||||||
|
*
|
||||||
|
* @param mixed $group Group to add
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addGroup($group) /* : void */
|
||||||
|
{
|
||||||
|
$this->groups[] = $group;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set localization.
|
* Set localization.
|
||||||
*
|
*
|
||||||
|
|
@ -207,6 +243,102 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
$this->l11n = $l11n;
|
$this->l11n = $l11n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set permissions.
|
||||||
|
*
|
||||||
|
* The method accepts an array of permissions. All existing permissions are replaced.
|
||||||
|
*
|
||||||
|
* @param PermissionAbstract[] $permissions
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setPermissions(array $permissions) /* : void */
|
||||||
|
{
|
||||||
|
$this->permissions = $permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add permissions.
|
||||||
|
*
|
||||||
|
* Adds permissions to the account
|
||||||
|
*
|
||||||
|
* @param PermissionAbstract[] $permissions Array of permissions to add to the account
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addPermissions(array $permissions) /* : void */
|
||||||
|
{
|
||||||
|
$this->permissions = array_merge($this->permissions, $permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add permission.
|
||||||
|
*
|
||||||
|
* Adds a single permission to the account
|
||||||
|
*
|
||||||
|
* @param PermissionAbstract $permission Permission to add to the account
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addPermission(PermissionAbstract $permission) /* : void */
|
||||||
|
{
|
||||||
|
$this->permissions[] = $permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get permissions.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getPermissions() : array
|
||||||
|
{
|
||||||
|
return $this->permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has permissions.
|
||||||
|
*
|
||||||
|
* Checks if the account has a permission defined
|
||||||
|
*
|
||||||
|
* @param int $permission Permission to check
|
||||||
|
* @param int $unit Unit Unit to check (null if all are acceptable)
|
||||||
|
* @param string $app App App to check (null if all are acceptable)
|
||||||
|
* @param int $module Module Module to check (null if all are acceptable)
|
||||||
|
* @param int $type Type (e.g. customer) (null if all are acceptable)
|
||||||
|
* @param int $element (e.g. customer id) (null if all are acceptable)
|
||||||
|
* @param int $component (e.g. address) (null if all are acceptable)
|
||||||
|
*
|
||||||
|
* @return bool Returns true if the account has the permission, false otherwise
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
$app = isset($app) ? strtolower($app) : $app;
|
||||||
|
|
||||||
|
foreach($this->permissions as $p) {
|
||||||
|
if(($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
|
||||||
|
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app))
|
||||||
|
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module))
|
||||||
|
&& ($p->getType() === $type || $p->getType() === null || !isset($type))
|
||||||
|
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element))
|
||||||
|
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component))
|
||||||
|
&& ($p->getPermission() | $permission) === $p->getPermission()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name.
|
* Get name.
|
||||||
*
|
*
|
||||||
|
|
@ -231,6 +363,20 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->name1;
|
return $this->name1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name1.
|
||||||
|
*
|
||||||
|
* @param string $name Name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setName1(string $name) /* : void */
|
||||||
|
{
|
||||||
|
$this->name1 = $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name2.
|
* Get name2.
|
||||||
*
|
*
|
||||||
|
|
@ -243,6 +389,20 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->name2;
|
return $this->name2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name2.
|
||||||
|
*
|
||||||
|
* @param string $name Name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setName2(string $name) /* : void */
|
||||||
|
{
|
||||||
|
$this->name2 = $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name3.
|
* Get name3.
|
||||||
*
|
*
|
||||||
|
|
@ -255,6 +415,20 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->name3;
|
return $this->name3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name3.
|
||||||
|
*
|
||||||
|
* @param string $name Name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setName3(string $name) /* : void */
|
||||||
|
{
|
||||||
|
$this->name3 = $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get email.
|
* Get email.
|
||||||
*
|
*
|
||||||
|
|
@ -267,6 +441,26 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->email;
|
return $this->email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set email.
|
||||||
|
*
|
||||||
|
* @param string $email Email
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException Exception is thrown if the provided string is not a valid email
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setEmail(string $email) /* : void */
|
||||||
|
{
|
||||||
|
if (!Email::isValid($email)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->email = mb_strtolower($email);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get status.
|
* Get status.
|
||||||
*
|
*
|
||||||
|
|
@ -281,6 +475,24 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->status;
|
return $this->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status.
|
||||||
|
*
|
||||||
|
* @param int $status Status
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setStatus(int $status) /* : void */
|
||||||
|
{
|
||||||
|
if (!AccountStatus::isValidValue($status)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get type.
|
* Get type.
|
||||||
*
|
*
|
||||||
|
|
@ -295,6 +507,24 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type.
|
||||||
|
*
|
||||||
|
* @param int $type Type
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setType(int $type) /* : void */
|
||||||
|
{
|
||||||
|
if (!AccountType::isValidValue($type)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get last activity.
|
* Get last activity.
|
||||||
*
|
*
|
||||||
|
|
@ -347,102 +577,6 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
$this->login = $name;
|
$this->login = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set name1.
|
|
||||||
*
|
|
||||||
* @param string $name Name
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setName1(string $name) /* : void */
|
|
||||||
{
|
|
||||||
$this->name1 = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set name2.
|
|
||||||
*
|
|
||||||
* @param string $name Name
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setName2(string $name) /* : void */
|
|
||||||
{
|
|
||||||
$this->name2 = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set name3.
|
|
||||||
*
|
|
||||||
* @param string $name Name
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setName3(string $name) /* : void */
|
|
||||||
{
|
|
||||||
$this->name3 = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set email.
|
|
||||||
*
|
|
||||||
* @param string $email Email
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setEmail(string $email) /* : void */
|
|
||||||
{
|
|
||||||
if (!Email::isValid($email)) {
|
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->email = mb_strtolower($email);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get status.
|
|
||||||
*
|
|
||||||
* @param int $status Status
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setStatus(int $status) /* : void */
|
|
||||||
{
|
|
||||||
if (!AccountStatus::isValidValue($status)) {
|
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->status = $status;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get type.
|
|
||||||
*
|
|
||||||
* @param int $type Type
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setType(int $type) /* : void */
|
|
||||||
{
|
|
||||||
if (!AccountType::isValidValue($type)) {
|
|
||||||
throw new \InvalidArgumentException();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->type = $type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update last activity.
|
* Update last activity.
|
||||||
*
|
*
|
||||||
|
|
@ -455,6 +589,18 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
$this->lastActive = new \DateTime('NOW');
|
$this->lastActive = new \DateTime('NOW');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get string representation.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return json_encode($this->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -476,18 +622,6 @@ class Account implements ArrayableInterface, \JsonSerializable
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string representation.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return json_encode($this->toArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Json serialize.
|
* Json serialize.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ use phpOMS\DataStorage\Session\SessionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account manager class.
|
* Account manager class.
|
||||||
|
*
|
||||||
|
* The account manager is used to manage multiple accounts.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Account
|
* @package phpOMS\Account
|
||||||
|
|
@ -47,14 +49,6 @@ class AccountManager implements \Countable
|
||||||
*/
|
*/
|
||||||
private $session = null;
|
private $session = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Database connection instance.
|
|
||||||
*
|
|
||||||
* @var ConnectionAbstract
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $connection = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticator.
|
* Authenticator.
|
||||||
*
|
*
|
||||||
|
|
@ -66,16 +60,14 @@ class AccountManager implements \Countable
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ConnectionAbstract $connection Database connection
|
|
||||||
* @param SessionInterface $session Session
|
* @param SessionInterface $session Session
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(ConnectionAbstract $connection, SessionInterface $session)
|
public function __construct(SessionInterface $session)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->auth = new Auth($this->connection, $this->session);
|
$this->auth = new Auth($this->session);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -102,6 +94,18 @@ class AccountManager implements \Countable
|
||||||
return $this->accounts[$id] ?? new NullAccount();
|
return $this->accounts[$id] ?? new NullAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the authentication manager
|
||||||
|
*
|
||||||
|
* @return Auth
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getAuth() : Auth
|
||||||
|
{
|
||||||
|
return $this->auth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add account.
|
* Add account.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class AccountStatus extends Enum
|
abstract class AccountStatus extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const ACTIVE = 1;
|
/* public */ const ACTIVE = 1;
|
||||||
/* public */ const INACTIVE = 2;
|
/* public */ const INACTIVE = 2;
|
||||||
/* public */ const TIMEOUT = 3;
|
/* public */ const TIMEOUT = 3;
|
||||||
/* public */ const BANNED = 4;
|
/* public */ const BANNED = 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
* Account type enum.
|
* Account type enum.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\DataStorage\Database
|
* @package phpOMS\Account
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract class AccountType extends Enum
|
abstract class AccountType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const USER = 0;
|
/* public */ const USER = 0;
|
||||||
/* public */ const GROUP = 1;
|
/* public */ const GROUP = 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,18 +191,6 @@ class Group implements ArrayableInterface, \JsonSerializable
|
||||||
return json_encode($this->toArray());
|
return json_encode($this->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Json serialize.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function jsonSerialize()
|
|
||||||
{
|
|
||||||
return $this->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -216,4 +204,16 @@ class Group implements ArrayableInterface, \JsonSerializable
|
||||||
'members' => $this->members,
|
'members' => $this->members,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Json serialize.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function jsonSerialize()
|
||||||
|
{
|
||||||
|
return $this->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,15 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
/**
|
/**
|
||||||
* Accept status enum.
|
* Accept status enum.
|
||||||
*
|
*
|
||||||
* @category Calendar
|
* @category Framework
|
||||||
* @package Modules
|
* @package phpOMS\Account
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract class GroupStatus extends Enum
|
abstract class GroupStatus extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const ACTIVE = 1;
|
/* public */ const ACTIVE = 1;
|
||||||
|
/* public */ const INACTIVE = 2;
|
||||||
/* public */ const INACTIVE = 2;
|
/* public */ const HIDDEN = 4;
|
||||||
|
|
||||||
/* public */ const HIDDEN = 4;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
351
Account/PermissionAbstract.php
Normal file
351
Account/PermissionAbstract.php
Normal file
|
|
@ -0,0 +1,351 @@
|
||||||
|
<?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\Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission class.
|
||||||
|
*
|
||||||
|
* This permission abstract is the basis for all permissions. Contrary to it's name it is not an
|
||||||
|
* abstract class and can be used directly if needed.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Account
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected $permission = PermissionType::NONE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get permission id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getId() : int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unit id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getUnit() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set unit id.
|
||||||
|
*
|
||||||
|
* @param int $unit Unit
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setUnit(int $unit = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->unit = $unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get app name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getApp() /* : ?string */
|
||||||
|
{
|
||||||
|
return $this->app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set app name.
|
||||||
|
*
|
||||||
|
* @param string $app App name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setApp(string $app = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getModule() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set module id.
|
||||||
|
*
|
||||||
|
* @param int $module Module
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setModule(int $module = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->module = $module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get providing module id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getFrom() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getType() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set type.
|
||||||
|
*
|
||||||
|
* @param int $type Type
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setType(int $type = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get element id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getElement() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set element id.
|
||||||
|
*
|
||||||
|
* @param int $element Element id
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setElement(int $element = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->element = $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get component id.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getComponent() /* : ?int */
|
||||||
|
{
|
||||||
|
return $this->component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set component id.
|
||||||
|
*
|
||||||
|
* @param int $component Component
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setComponent(int $component = null) /* : void */
|
||||||
|
{
|
||||||
|
$this->component = $component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get permission
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getPermission() : int
|
||||||
|
{
|
||||||
|
return $this->permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set permission.
|
||||||
|
*
|
||||||
|
* @param int $permission Permission
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function setPermission(int $permission = 0) /* : void */
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has permission.
|
||||||
|
*
|
||||||
|
* @param int $permission Permission
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function hasPermission(int $permission) : bool
|
||||||
|
{
|
||||||
|
return ($this->permission | $permission) === $this->permission;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
Account/PermissionType.php
Normal file
37
Account/PermissionType.php
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?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\Account;
|
||||||
|
|
||||||
|
use phpOMS\Stdlib\Base\Enum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Permission type enum.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Account
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract class PermissionType extends Enum
|
||||||
|
{
|
||||||
|
/* public */ const NONE = 1;
|
||||||
|
/* public */ const READ = 2;
|
||||||
|
/* public */ const CREATE = 4;
|
||||||
|
/* public */ const MODIFY = 8;
|
||||||
|
/* public */ const DELETE = 16;
|
||||||
|
/* public */ const PERMISSION = 32;
|
||||||
|
}
|
||||||
|
|
@ -35,14 +35,6 @@ class ApplicationAbstract
|
||||||
*/
|
*/
|
||||||
protected $appName = '';
|
protected $appName = '';
|
||||||
|
|
||||||
/**
|
|
||||||
* Config.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected $config = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database object.
|
* Database object.
|
||||||
*
|
*
|
||||||
|
|
@ -153,7 +145,7 @@ class ApplicationAbstract
|
||||||
*/
|
*/
|
||||||
public function __set($name, $value)
|
public function __set($name, $value)
|
||||||
{
|
{
|
||||||
if(!empty($this->$name) || $name === 'config') {
|
if(!empty($this->$name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,10 +165,6 @@ class ApplicationAbstract
|
||||||
*/
|
*/
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
if($name === 'config') {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->$name;
|
return $this->$name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class AssetType extends Enum
|
abstract class AssetType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const CSS = 0;
|
/* public */ const CSS = 0;
|
||||||
/* public */ const JS = 1;
|
/* public */ const JS = 1;
|
||||||
/* public */ const JSLATE = 2;
|
/* public */ const JSLATE = 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Auth;
|
namespace phpOMS\Auth;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
|
||||||
use phpOMS\DataStorage\Session\SessionInterface;
|
use phpOMS\DataStorage\Session\SessionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,26 +39,16 @@ class Auth
|
||||||
*/
|
*/
|
||||||
private $session = null;
|
private $session = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Database connection instance.
|
|
||||||
*
|
|
||||||
* @var ConnectionAbstract
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $connection = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ConnectionAbstract $connection Database connection
|
|
||||||
* @param SessionInterface $session Session
|
* @param SessionInterface $session Session
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(ConnectionAbstract $connection, SessionInterface $session)
|
public function __construct(SessionInterface $session)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->session = $session;
|
||||||
$this->session = $session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -73,11 +62,7 @@ class Auth
|
||||||
{
|
{
|
||||||
$uid = $this->session->get('UID');
|
$uid = $this->session->get('UID');
|
||||||
|
|
||||||
if (empty($uid)) {
|
return empty($uid) ? 0 : $uid;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $uid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,14 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class LoginReturnType extends Enum
|
abstract class LoginReturnType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const OK = 0; /* Everything is ok and the user got authed */
|
/* public */ const OK = 0; /* Everything is ok and the user got authed */
|
||||||
/* public */ const FAILURE = -1; /* Authentication resulted in a unexpected failure */
|
/* public */ const FAILURE = -1; /* Authentication resulted in a unexpected failure */
|
||||||
/* public */ const WRONG_PASSWORD = -2; /* Authentication with wrong password */
|
/* public */ const WRONG_PASSWORD = -2; /* Authentication with wrong password */
|
||||||
/* public */ const WRONG_USERNAME = -3; /* Authentication with unknown user */
|
/* public */ const WRONG_USERNAME = -3; /* Authentication with unknown user */
|
||||||
/* public */ const WRONG_PERMISSION = -4; /* User doesn't have permission to authenticate */
|
/* public */ const WRONG_PERMISSION = -4; /* User doesn't have permission to authenticate */
|
||||||
/* public */ const NOT_ACTIVATED = -5; /* The user is not activated yet */
|
/* public */ const NOT_ACTIVATED = -5; /* The user is not activated yet */
|
||||||
/* public */ const WRONG_INPUT_EXCEEDED = -6; /* Too many wrong logins recently */
|
/* public */ const WRONG_INPUT_EXCEEDED = -6; /* Too many wrong logins recently */
|
||||||
/* public */ const TIMEOUTED = -7; /* User received a timeout and can not log in until a certain date */
|
/* public */ const TIMEOUTED = -7; /* User received a timeout and can not log in until a certain date */
|
||||||
/* public */ const BANNED = -8; /* User is banned */
|
/* public */ const BANNED = -8; /* User is banned */
|
||||||
/* public */ const INACTIVE = -9; /* User is inactive */
|
/* public */ const INACTIVE = -9; /* User is inactive */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,51 @@ namespace phpOMS\Business\Finance;
|
||||||
|
|
||||||
class Depreciation
|
class Depreciation
|
||||||
{
|
{
|
||||||
|
public static function getLinearDepreciationRate(float $start, int $duration) : float
|
||||||
|
{
|
||||||
|
return $start / $duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLinearDepreciationResidualInT(float $start, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
return $start - self::getLinearDepreciationRate($start, $duration) * $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getArithmeticProgressivDepreciationRate(float $start, int $duration) : float
|
||||||
|
{
|
||||||
|
return $start / ($duration * ($duration+1) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getArithmeticProgressivDepreciationInT(float $start, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
return $t * self::getArithmeticProgressivDepreciationRate($start, $duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getArithmeticProgressivDepreciationResidualInT(float $start, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
return $start - self::getArithmeticProgressivDepreciationRate($start, $duration) * $t * ($t + 1) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeometicProgressivDepreciationRate(float $start, float $residual, int $duration) : float
|
||||||
|
{
|
||||||
|
return (1-pow($residual / $start, 1 / $duration));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeometicDegressivDepreciationInT(float $start, float $residual, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
return $start * (1 - self::getGeometicDegressivDepreciationRate($start, $residual, $duration)) ** $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeometicDegressivDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeometicProgressivDepreciationInT(float $start, float $residual, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
return $start * (1 - self::getGeometicProgressivDepreciationRate($start, $residual, $duration)) ** ($duration - $t + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getGeometicProgressivDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1197,14 +1197,14 @@ class FinanceFormulas
|
||||||
/**
|
/**
|
||||||
* Rate of Inflation
|
* Rate of Inflation
|
||||||
*
|
*
|
||||||
* @param float $oldCPI Consumer price index old
|
|
||||||
* @param float $newCPI Consumer price index new
|
* @param float $newCPI Consumer price index new
|
||||||
|
* @param float $oldCPI Consumer price index old
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function getRateOfOnflation(float $oldCPI, float $newCPI) : float
|
public static function getRateOfOnflation(float $newCPI, float $oldCPI) : float
|
||||||
{
|
{
|
||||||
return $newCPI / $oldCPI - 1;
|
return $newCPI / $oldCPI - 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1315,6 +1315,54 @@ class FinanceFormulas
|
||||||
return $P * $r * $t;
|
return $P * $r * $t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple Interest Rate
|
||||||
|
*
|
||||||
|
* @param float $I Interest
|
||||||
|
* @param float $P Principal
|
||||||
|
* @param int $t Time
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getSimpleInterestRate(float $I, float $P, int $t) : float
|
||||||
|
{
|
||||||
|
return $I / ($P * $t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple Interest Principal
|
||||||
|
*
|
||||||
|
* @param float $I Interest
|
||||||
|
* @param float $r Rate
|
||||||
|
* @param int $t Time
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getSimpleInterestPrincipal(float $I, float $r, int $t) : float
|
||||||
|
{
|
||||||
|
return $I / ($r * $t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple Interest Principal
|
||||||
|
*
|
||||||
|
* @param float $I Interest
|
||||||
|
* @param float $P Principal
|
||||||
|
* @param float $r Rate
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getSimpleInterestTime(float $I, float $P, float $r) : int
|
||||||
|
{
|
||||||
|
return (int) round($I / ($P * $r));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relative market share by share
|
* Relative market share by share
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Business\Marketing;
|
namespace phpOMS\Business\Marketing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Net Promoter Score
|
* Marketing Metrics
|
||||||
|
*
|
||||||
|
* This class provided basic marketing metric calculations
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Business
|
* @package phpOMS\Business
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,9 @@ namespace phpOMS\Business\Marketing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Net Promoter Score
|
* Net Promoter Score
|
||||||
|
*
|
||||||
|
* The net promoter score is a basic evaluation of the happiness of customers.
|
||||||
|
* Instead of customers the NPS can also be transferred to non-customers.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Business
|
* @package phpOMS\Business
|
||||||
|
|
@ -65,8 +68,8 @@ class NetPromoterScore {
|
||||||
*/
|
*/
|
||||||
public function getScore() : int
|
public function getScore() : int
|
||||||
{
|
{
|
||||||
$promoters = 0;
|
$promoters = 0;
|
||||||
$passives = 0;
|
$passives = 0;
|
||||||
$detractors = 0;
|
$detractors = 0;
|
||||||
|
|
||||||
foreach($this->scores as $score) {
|
foreach($this->scores as $score) {
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,13 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Business\Programming;
|
namespace phpOMS\Business\Programming;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Programming metrics
|
* Programming metrics
|
||||||
|
*
|
||||||
|
* This class provides basic programming metric calculations.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Business
|
* @package phpOMS\Business
|
||||||
|
|
@ -40,4 +44,22 @@ class Metrics {
|
||||||
{
|
{
|
||||||
return (int) sqrt($a*$a+$b*$b+$c*$c);
|
return (int) sqrt($a*$a+$b*$b+$c*$c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the C.R.A.P score
|
||||||
|
*
|
||||||
|
* @latex r = \sqrt{a^{2} + b^{2} + c^{2}}
|
||||||
|
*
|
||||||
|
* @param int $a Assignments
|
||||||
|
* @param int $b Branches
|
||||||
|
* @param int $c Conditionals
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function CRAP(int $complexity, float $coverage) : int
|
||||||
|
{
|
||||||
|
return (int) ($complexity ** 2 * (1 - $coverage) ** 3 + $complexity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,9 +12,14 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Business\Sales;
|
namespace phpOMS\Business\Sales;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Market share calculations (Zipf function)
|
* Market share calculations (Zipf function)
|
||||||
|
*
|
||||||
|
* This class can be used to calculate the market share based on a rank or vice versa
|
||||||
|
* the rank based on a marketshare in a Zipf distributed market.
|
||||||
*
|
*
|
||||||
* @category Framework
|
* @category Framework
|
||||||
* @package phpOMS\Business
|
* @package phpOMS\Business
|
||||||
|
|
@ -24,15 +29,15 @@ namespace phpOMS\Business\Sales;
|
||||||
*/
|
*/
|
||||||
class MarketShareEstimation {
|
class MarketShareEstimation {
|
||||||
/**
|
/**
|
||||||
* Calculate rank (r) based on marketshare (m)
|
* Calculate rank (r) based on market share (m)
|
||||||
*
|
*
|
||||||
* @latex r = \sqrt[s]{\frac{1}{m \times \sum_{n=1}^N{\frac{1}{n^{s}}}}}
|
* @latex r = \sqrt[s]{\frac{1}{m \times \sum_{n=1}^N{\frac{1}{n^{s}}}}}
|
||||||
*
|
*
|
||||||
* @param int $participants (p)
|
* @param int $participants The amount of existing participants in the market or compentitors (N)
|
||||||
* @param float $marketShare (m)
|
* @param float $marketShare The absolute own market share (m)
|
||||||
* @param float $modifier (s)
|
* @param float $modifier Distribution modifier (s)
|
||||||
*
|
*
|
||||||
* @return float
|
* @return int Returns the rank
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -47,15 +52,15 @@ class MarketShareEstimation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate marketshare (m) based on rank (r)
|
* Calculate market share (m) based on rank (r)
|
||||||
*
|
*
|
||||||
* @latex m = \frac{\frac{1}{r^{s}}}{\sum_{n=1}^N{\frac{1}{n^{s}}}}
|
* @latex m = \frac{\frac{1}{r^{s}}}{\sum_{n=1}^N{\frac{1}{n^{s}}}}
|
||||||
*
|
*
|
||||||
* @param int $participants (p)
|
* @param int $participants The amount of existing participants in the market or compentitors (N)
|
||||||
* @param int $rank (r)
|
* @param int $rank The absolute own rank in the market (r)
|
||||||
* @param float $modifier (s)
|
* @param float $modifier Distribution modifier (s)
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float Returns the Market share
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -104,12 +104,16 @@ class CachePool implements OptionsInterface
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function get(string $key) /* : ?CacheInterface */
|
public function get(string $key = '') /* : ?CacheInterface */
|
||||||
{
|
{
|
||||||
if (!isset($this->pool[$key])) {
|
if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(empty($key)) {
|
||||||
|
return reset($this->pool);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->pool[$key];
|
return $this->pool[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class FileCache implements CacheInterface
|
||||||
public function __construct(string $path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
if (!Directory::exists(File::parent($path))) {
|
if (!Directory::exists(File::parent($path))) {
|
||||||
Directory::create($path);
|
Directory::create($path, 0664, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cachePath = realpath($path);
|
$this->cachePath = realpath($path);
|
||||||
|
|
|
||||||
|
|
@ -127,9 +127,13 @@ class CookieJar
|
||||||
throw new LockException('CookieJar');
|
throw new LockException('CookieJar');
|
||||||
}
|
}
|
||||||
|
|
||||||
setcookie($id, '', time() - 3600);
|
if(!headers_sent()) {
|
||||||
|
setcookie($id, '', time() - 3600);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,42 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
||||||
return $this->status;
|
return $this->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get database name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getDatabase() : string
|
||||||
|
{
|
||||||
|
return $this->dbdata['database'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get database host.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getHost() : string
|
||||||
|
{
|
||||||
|
return $this->dbdata['host'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get database port.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getPort() : int
|
||||||
|
{
|
||||||
|
return (int) $this->dbdata['port'] ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get table prefix.
|
* Get table prefix.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ class ConnectionFactory
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
437
DataStorage/Database/DataMapperBaseAbstract.php
Normal file
437
DataStorage/Database/DataMapperBaseAbstract.php
Normal file
|
|
@ -0,0 +1,437 @@
|
||||||
|
<?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\Connection\ConnectionAbstract;
|
||||||
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 DataMapperBaseAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Database connection.
|
||||||
|
*
|
||||||
|
* @var ConnectionAbstract
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $db = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwriting extended values.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $overwrite = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary field name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $primaryField = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary field name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $createdAt = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $language_field = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Columns.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $columns = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relations.
|
||||||
|
*
|
||||||
|
* Relation is defined in a relation table
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $hasMany = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relations.
|
||||||
|
*
|
||||||
|
* Relation is defined in the model
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $hasOne = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relations.
|
||||||
|
*
|
||||||
|
* Relation is defined in current mapper
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $ownsOne = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relations.
|
||||||
|
*
|
||||||
|
* Relation is defined in current mapper
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $belongsTo = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $table = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fields to load.
|
||||||
|
*
|
||||||
|
* @var array[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $fields = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialized objects for cross reference to reduce initialization costs
|
||||||
|
*
|
||||||
|
* @var array[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $initObjects = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Highest mapper to know when to clear initialized objects
|
||||||
|
*
|
||||||
|
* @var DataMapperAbstract
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $parentMapper = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extended value collection.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $collection = [
|
||||||
|
'primaryField' => [],
|
||||||
|
'createdAt' => [],
|
||||||
|
'columns' => [],
|
||||||
|
'hasMany' => [],
|
||||||
|
'hasOne' => [],
|
||||||
|
'ownsOne' => [],
|
||||||
|
'table' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clone.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __clone()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set database connection.
|
||||||
|
*
|
||||||
|
* @param ConnectionAbstract $con Database connection
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function setConnection(ConnectionAbstract $con) /* : void */
|
||||||
|
{
|
||||||
|
self::$db = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get primary field.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getPrimaryField() : string
|
||||||
|
{
|
||||||
|
return static::$primaryField;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get main table.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getTable() : string
|
||||||
|
{
|
||||||
|
return static::$table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect values from extension.
|
||||||
|
*
|
||||||
|
* @param mixed $class Current extended mapper
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function extend($class) /* : void */
|
||||||
|
{
|
||||||
|
/* todo: have to implement this in the queries, so far not used */
|
||||||
|
self::$collection['primaryField'][] = $class::$primaryField;
|
||||||
|
self::$collection['createdAt'][] = $class::$createdAt;
|
||||||
|
self::$collection['columns'][] = $class::$columns;
|
||||||
|
self::$collection['hasMany'][] = $class::$hasMany;
|
||||||
|
self::$collection['hasOne'][] = $class::$hasOne;
|
||||||
|
self::$collection['ownsOne'][] = $class::$ownsOne;
|
||||||
|
self::$collection['table'][] = $class::$table;
|
||||||
|
|
||||||
|
if (($parent = get_parent_class($class)) !== false && !$class::$overwrite) {
|
||||||
|
self::extend($parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets all loaded mapper variables.
|
||||||
|
*
|
||||||
|
* This is used after one action is performed otherwise other models would use wrong settings.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function clear() /* : void */
|
||||||
|
{
|
||||||
|
self::$overwrite = true;
|
||||||
|
self::$primaryField = '';
|
||||||
|
self::$createdAt = '';
|
||||||
|
self::$columns = [];
|
||||||
|
self::$hasMany = [];
|
||||||
|
self::$hasOne = [];
|
||||||
|
self::$ownsOne = [];
|
||||||
|
self::$table = '';
|
||||||
|
self::$fields = [];
|
||||||
|
self::$collection = [
|
||||||
|
'primaryField' => [],
|
||||||
|
'createdAt' => [],
|
||||||
|
'columns' => [],
|
||||||
|
'hasOne' => [],
|
||||||
|
'ownsMany' => [],
|
||||||
|
'ownsOne' => [],
|
||||||
|
'table' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
// clear parent and objects
|
||||||
|
if(static::class === self::$parentMapper) {
|
||||||
|
self::$initObjects = [];
|
||||||
|
self::$parentMapper = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get created at column
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getCreatedAt() : string
|
||||||
|
{
|
||||||
|
return static::$createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get id of object
|
||||||
|
*
|
||||||
|
* @param Object $obj Model to create
|
||||||
|
* @param \ReflectionClass $reflectionClass Reflection class
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null)
|
||||||
|
{
|
||||||
|
$reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj));
|
||||||
|
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
|
||||||
|
|
||||||
|
if (!($isPublic = $reflectionProperty->isPublic())) {
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$objectId = $reflectionProperty->getValue($obj);
|
||||||
|
|
||||||
|
if (!$isPublic) {
|
||||||
|
$reflectionProperty->setAccessible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $objectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set id to model
|
||||||
|
*
|
||||||
|
* @param \ReflectionClass $reflectionClass Reflection class
|
||||||
|
* @param Object $obj Object to create
|
||||||
|
* @param mixed $objId Id to set
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function setObjectId(\ReflectionClass $reflectionClass, $obj, $objId) /* : void */
|
||||||
|
{
|
||||||
|
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
|
||||||
|
|
||||||
|
if (!($isPublic = $reflectionProperty->isPublic())) {
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
settype($objId, static::$columns[static::$primaryField]['type']);
|
||||||
|
$reflectionProperty->setValue($obj, $objId);
|
||||||
|
|
||||||
|
if (!$isPublic) {
|
||||||
|
$reflectionProperty->setAccessible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse value
|
||||||
|
*
|
||||||
|
* @param string $type Value type
|
||||||
|
* @param mixed $value Value to parse
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function parseValue(string $type, $value)
|
||||||
|
{
|
||||||
|
if (is_null($value)) {
|
||||||
|
return null;
|
||||||
|
} elseif ($type === 'DateTime') {
|
||||||
|
return $value->format('Y-m-d H:i:s');
|
||||||
|
} elseif ($type === 'Json' || $type === 'jsonSerializable') {
|
||||||
|
return json_encode($value);
|
||||||
|
} elseif ($type === 'Serializable') {
|
||||||
|
return $value->serialize();
|
||||||
|
} elseif ($value instanceof \JsonSerializable) {
|
||||||
|
return json_encode($value->jsonSerialize());
|
||||||
|
} elseif (is_object($value) && method_exists($value, 'getId')) {
|
||||||
|
return $value->getId();
|
||||||
|
} elseif ($type === 'int') {
|
||||||
|
return (int) $value;
|
||||||
|
} elseif ($type === 'string') {
|
||||||
|
return (string) $value;
|
||||||
|
} elseif ($type === 'float') {
|
||||||
|
return (float) $value;
|
||||||
|
} elseif ($type === 'bool') {
|
||||||
|
return (bool) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mapper specific builder
|
||||||
|
*
|
||||||
|
* @param Builder $query Query to fill
|
||||||
|
*
|
||||||
|
* @return Builder
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getQuery(Builder $query = null) : Builder
|
||||||
|
{
|
||||||
|
$query = $query ?? new Builder(self::$db);
|
||||||
|
$query->prefix(self::$db->getPrefix())
|
||||||
|
->select('*')
|
||||||
|
->from(static::$table);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the highest mapper of this request
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private static function setUpParentMapper() /* : void */
|
||||||
|
{
|
||||||
|
self::$parentMapper = static::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getColumnByMember(string $name) : string
|
||||||
|
{
|
||||||
|
foreach(static::$columns as $cName => $column) {
|
||||||
|
if($column['internal'] === $name) {
|
||||||
|
return $cName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw \Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\DataStorage\Database;
|
namespace phpOMS\DataStorage\Database;
|
||||||
|
|
||||||
|
use phpOMS\DataStorage\Database\Schema\Exception\TableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database exception factory.
|
* Database exception factory.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -77,10 +77,14 @@ class DatabasePool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function get(string $key = 'core') /* : ?ConnectionAbstract */
|
public function get(string $key = '') /* : ?ConnectionAbstract */
|
||||||
{
|
{
|
||||||
if (!isset($this->pool[$key])) {
|
if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) {
|
||||||
return null; /* todo: return nullconnection */
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(empty($key)) {
|
||||||
|
return reset($this->pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->pool[$key];
|
return $this->pool[$key];
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class DatabaseStatus extends 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_DATABASE = 1; /* Couldn't find database */
|
||||||
/* public */ const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
/* public */ const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
||||||
/* public */ const FAILURE = 3; /* Unknown failure */
|
/* public */ const FAILURE = 3; /* Unknown failure */
|
||||||
/* public */ const READONLY = 4; /* Database connection is in readonly (but ok) */
|
/* public */ const READONLY = 4; /* Database connection is in readonly (but ok) */
|
||||||
/* public */ const CLOSED = 5; /* Database connection closed */
|
/* public */ const CLOSED = 5; /* Database connection closed */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class DatabaseType extends Enum
|
abstract class DatabaseType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const MYSQL = 'mysql'; /* MySQL */
|
/* public */ const MYSQL = 'mysql'; /* MySQL */
|
||||||
/* public */ const SQLITE = 'sqlite'; /* SQLITE */
|
/* public */ const SQLITE = 'sqlite'; /* SQLITE */
|
||||||
/* public */ const PGSQL = 2; /* PostgreSQL */
|
/* public */ const PGSQL = 2; /* PostgreSQL */
|
||||||
/* public */ const ORACLE = 3; /* Oracle */
|
/* public */ const ORACLE = 3; /* Oracle */
|
||||||
/* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */
|
/* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace phpOMS\DataStorage\Database\Exception;
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class InvalidConnectionConfigException extends \RuntimeException
|
class InvalidConnectionConfigException extends \InvalidArgumentException
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\DataStorage\Database;
|
namespace phpOMS\DataStorage\Database;
|
||||||
|
|
||||||
use phpOMS\Utils\StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grammar.
|
* Grammar.
|
||||||
*
|
*
|
||||||
|
|
@ -79,7 +77,7 @@ abstract class GrammarAbstract
|
||||||
/**
|
/**
|
||||||
* Special keywords.
|
* Special keywords.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $specialKeywords = [
|
protected $specialKeywords = [
|
||||||
|
|
@ -170,6 +168,41 @@ abstract class GrammarAbstract
|
||||||
{
|
{
|
||||||
$expression = '';
|
$expression = '';
|
||||||
|
|
||||||
|
foreach ($elements as $key => $element) {
|
||||||
|
if (is_string($element) && $element !== '*') {
|
||||||
|
if(strpos($element, '.') === false) {
|
||||||
|
$prefix = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$expression .= $this->compileSystem($element, $prefix) . ', ';
|
||||||
|
} elseif (is_string($element) && $element === '*') {
|
||||||
|
$expression .= '*, ';
|
||||||
|
} elseif ($element instanceof \Closure) {
|
||||||
|
$expression .= $element() . ', ';
|
||||||
|
} elseif ($element instanceof BuilderAbstract) {
|
||||||
|
$expression .= $element->toSql() . ', ';
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtrim($expression, ', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expressionize elements.
|
||||||
|
*
|
||||||
|
* @param array $elements Elements
|
||||||
|
* @param string $prefix Prefix for table
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected function expressionizeTable(array $elements, string $prefix = '') : string
|
||||||
|
{
|
||||||
|
$expression = '';
|
||||||
|
|
||||||
foreach ($elements as $key => $element) {
|
foreach ($elements as $key => $element) {
|
||||||
if (is_string($element) && $element !== '*') {
|
if (is_string($element) && $element !== '*') {
|
||||||
$expression .= $this->compileSystem($element, $prefix) . ', ';
|
$expression .= $this->compileSystem($element, $prefix) . ', ';
|
||||||
|
|
@ -205,7 +238,7 @@ abstract class GrammarAbstract
|
||||||
$identifier = $this->systemIdentifier;
|
$identifier = $this->systemIdentifier;
|
||||||
|
|
||||||
foreach($this->specialKeywords as $keyword) {
|
foreach($this->specialKeywords as $keyword) {
|
||||||
if(StringUtils::startsWith($system, $keyword)) {
|
if($keyword === '' || strrpos($system, $keyword, -strlen($system)) !== false) {
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
$identifier = '';
|
$identifier = '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,22 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public $selects = [];
|
public $selects = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Columns.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public $updates = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stupid work around because value needs to be not null for it to work in Grammar.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public $deletes = [1];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Into.
|
* Into.
|
||||||
*
|
*
|
||||||
|
|
@ -69,6 +85,14 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public $values = [];
|
public $values = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Into columns.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public $sets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Distinct.
|
* Distinct.
|
||||||
*
|
*
|
||||||
|
|
@ -165,12 +189,6 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public $raw = '';
|
public $raw = '';
|
||||||
|
|
||||||
protected $unionLimit = null;
|
|
||||||
|
|
||||||
protected $unionOffset = null;
|
|
||||||
|
|
||||||
protected $unionOrders = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comparison OPERATORS.
|
* Comparison OPERATORS.
|
||||||
*
|
*
|
||||||
|
|
@ -312,7 +330,7 @@ class Builder extends BuilderAbstract
|
||||||
*/
|
*/
|
||||||
public function newQuery() : Builder
|
public function newQuery() : Builder
|
||||||
{
|
{
|
||||||
return new static($this->connection, $this->grammar);
|
return new static($this->connection, $this->isReadOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -352,7 +370,7 @@ class Builder extends BuilderAbstract
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->type = QueryType::RAW;
|
$this->type = QueryType::RAW;
|
||||||
$this->raw = $raw;
|
$this->raw = rtrim($raw, ';');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
@ -521,14 +539,9 @@ class Builder extends BuilderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function andWhere(Where $where) : Builder
|
public function andWhere($where, $operator = null, $values = null) : Builder
|
||||||
{
|
{
|
||||||
$this->wheres[][] = [
|
return $this->where($where, $operator, $values, 'and');
|
||||||
'column' => $where,
|
|
||||||
'boolean' => 'and',
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -540,14 +553,9 @@ class Builder extends BuilderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function orWhere(Where $where) : Builder
|
public function orWhere($where, $operator = null, $values = null) : Builder
|
||||||
{
|
{
|
||||||
$this->wheres[][] = [
|
return $this->where($where, $operator, $values, 'or');
|
||||||
'column' => $where,
|
|
||||||
'boolean' => 'or',
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -669,10 +677,14 @@ class Builder extends BuilderAbstract
|
||||||
public function orderBy($columns, $order = 'DESC') : Builder
|
public function orderBy($columns, $order = 'DESC') : Builder
|
||||||
{
|
{
|
||||||
if (is_string($columns) || $columns instanceof \Closure) {
|
if (is_string($columns) || $columns instanceof \Closure) {
|
||||||
$this->orders[] = ['column' => $columns, 'order' => $order];
|
if(!isset($this->orders[$order])) {
|
||||||
|
$this->orders[$order] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->orders[$order][] = $columns;
|
||||||
} elseif (is_array($columns)) {
|
} elseif (is_array($columns)) {
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($columns as $key => $column) {
|
||||||
$this->orders[] = ['column' => $column, 'order' => $order[$key]];
|
$this->orders[is_string($order) ? $order : $order[$key]][] = $column;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException();
|
||||||
|
|
@ -781,15 +793,6 @@ class Builder extends BuilderAbstract
|
||||||
return $this->select('COUNT(' . $table . ')');
|
return $this->select('COUNT(' . $table . ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if exists.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function exists()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select minimum.
|
* Select minimum.
|
||||||
*
|
*
|
||||||
|
|
@ -902,6 +905,39 @@ class Builder extends BuilderAbstract
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Values to insert.
|
||||||
|
*
|
||||||
|
* @param array $sets Values
|
||||||
|
*
|
||||||
|
* @return Builder
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function sets(...$sets) : Builder
|
||||||
|
{
|
||||||
|
$this->sets[] = $sets;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Values to insert.
|
||||||
|
*
|
||||||
|
* @param mixed $set Values
|
||||||
|
* @param string $type Data type to insert
|
||||||
|
*
|
||||||
|
* @return Builder
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function set($set, string $type = 'string') : Builder
|
||||||
|
{
|
||||||
|
$this->sets[key($set)] = current($set);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update columns.
|
* Update columns.
|
||||||
*
|
*
|
||||||
|
|
@ -911,7 +947,7 @@ class Builder extends BuilderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function update(...$columns) : Builder
|
public function update(...$tables) : Builder
|
||||||
{
|
{
|
||||||
if($this->isReadOnly) {
|
if($this->isReadOnly) {
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
|
@ -919,13 +955,28 @@ class Builder extends BuilderAbstract
|
||||||
|
|
||||||
$this->type = QueryType::UPDATE;
|
$this->type = QueryType::UPDATE;
|
||||||
|
|
||||||
foreach ($columns as $key => $column) {
|
foreach ($tables as $key => $table) {
|
||||||
$this->inserts[] = $column;
|
if (is_string($table) || $table instanceof \Closure) {
|
||||||
|
$this->updates[] = $table;
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete() : Builder
|
||||||
|
{
|
||||||
|
if($this->isReadOnly) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->type = QueryType::DELETE;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment value.
|
* Increment value.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,18 @@ class Grammar extends GrammarAbstract
|
||||||
'wheres',
|
'wheres',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update components.
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected $deleteComponents = [
|
||||||
|
'deletes',
|
||||||
|
'from',
|
||||||
|
'wheres',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Random components.
|
* Random components.
|
||||||
*
|
*
|
||||||
|
|
@ -111,10 +123,10 @@ class Grammar extends GrammarAbstract
|
||||||
$components = $this->insertComponents;
|
$components = $this->insertComponents;
|
||||||
break;
|
break;
|
||||||
case QueryType::UPDATE:
|
case QueryType::UPDATE:
|
||||||
$components = [];
|
$components = $this->updateComponents;
|
||||||
break;
|
break;
|
||||||
case QueryType::DELETE:
|
case QueryType::DELETE:
|
||||||
$components = [];
|
$components = $this->deleteComponents;
|
||||||
break;
|
break;
|
||||||
case QueryType::RANDOM:
|
case QueryType::RANDOM:
|
||||||
$components = $this->selectComponents;
|
$components = $this->selectComponents;
|
||||||
|
|
@ -157,6 +169,42 @@ class Grammar extends GrammarAbstract
|
||||||
return ($query->distinct ? 'SELECT DISTINCT ' : 'SELECT ') . $expression;
|
return ($query->distinct ? 'SELECT DISTINCT ' : 'SELECT ') . $expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile select.
|
||||||
|
*
|
||||||
|
* @param Builder $query Builder
|
||||||
|
* @param array $columns Columns
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected function compileUpdates(Builder $query, array $table) : string
|
||||||
|
{
|
||||||
|
$expression = $this->expressionizeTable($table, $query->getPrefix());
|
||||||
|
|
||||||
|
if ($expression === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'UPDATE ' . $expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile select.
|
||||||
|
*
|
||||||
|
* @param Builder $query Builder
|
||||||
|
* @param array $columns Columns
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected function compileDeletes(Builder $query, array $columns) : string
|
||||||
|
{
|
||||||
|
return 'DELETE';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile from.
|
* Compile from.
|
||||||
*
|
*
|
||||||
|
|
@ -169,7 +217,7 @@ class Grammar extends GrammarAbstract
|
||||||
*/
|
*/
|
||||||
protected function compileFrom(Builder $query, array $table) : string
|
protected function compileFrom(Builder $query, array $table) : string
|
||||||
{
|
{
|
||||||
$expression = $this->expressionizeTableColumn($table, $query->getPrefix());
|
$expression = $this->expressionizeTable($table, $query->getPrefix());
|
||||||
|
|
||||||
if ($expression === '') {
|
if ($expression === '') {
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -200,7 +248,7 @@ class Grammar extends GrammarAbstract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($expression == '') {
|
if ($expression === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,6 +288,9 @@ class Grammar extends GrammarAbstract
|
||||||
|
|
||||||
if (isset($element['value'])) {
|
if (isset($element['value'])) {
|
||||||
$expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix());
|
$expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix());
|
||||||
|
} else {
|
||||||
|
$operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT';
|
||||||
|
$expression .= ' ' . $operator . ' ' . $this->compileValue($element['value'], $query->getPrefix());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $expression;
|
return $expression;
|
||||||
|
|
@ -282,15 +333,17 @@ class Grammar extends GrammarAbstract
|
||||||
|
|
||||||
return '(' . rtrim($values, ', ') . ')';
|
return '(' . rtrim($values, ', ') . ')';
|
||||||
} elseif ($value instanceof \DateTime) {
|
} elseif ($value instanceof \DateTime) {
|
||||||
return $this->valueQuotes . $value->format('Y-m-d h:m:s') . $this->valueQuotes;
|
return $this->valueQuotes . $value->format('Y-m-d H:i:s') . $this->valueQuotes;
|
||||||
} elseif (is_null($value)) {
|
} elseif (is_null($value)) {
|
||||||
return 'NULL';
|
return 'NULL';
|
||||||
} elseif (is_bool($value)) {
|
} elseif (is_bool($value)) {
|
||||||
return (string) ((int) $value);
|
return (string) ((int) $value);
|
||||||
|
} elseif (is_float($value)) {
|
||||||
|
return (string) $value;
|
||||||
} elseif ($value instanceof Column) {
|
} elseif ($value instanceof Column) {
|
||||||
return $this->compileSystem($value->getColumn(), $prefix);
|
return $this->compileSystem($value->getColumn(), $prefix);
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException();
|
throw new \InvalidArgumentException(gettype($value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -366,11 +419,16 @@ class Grammar extends GrammarAbstract
|
||||||
{
|
{
|
||||||
$expression = '';
|
$expression = '';
|
||||||
|
|
||||||
foreach ($orders as $order) {
|
foreach ($orders as $key => $order) {
|
||||||
$expression .= $this->compileSystem($order['column'], $query->getPrefix()) . ' ' . $order['order'] . ', ';
|
foreach($order as $column) {
|
||||||
|
$expression .= $this->compileSystem($column, $query->getPrefix()) . ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
$expression = rtrim($expression, ', ');
|
||||||
|
$expression .= ' ' . $key . ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($expression == '') {
|
if ($expression === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +480,7 @@ class Grammar extends GrammarAbstract
|
||||||
$cols .= $this->compileSystem($column) . ', ';
|
$cols .= $this->compileSystem($column) . ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cols == '') {
|
if ($cols === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -447,10 +505,38 @@ class Grammar extends GrammarAbstract
|
||||||
$vals .= $this->compileValue($value) . ', ';
|
$vals .= $this->compileValue($value) . ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($vals == '') {
|
if ($vals === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'VALUES ' . rtrim($vals, ', ');
|
return 'VALUES ' . rtrim($vals, ', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile insert values.
|
||||||
|
*
|
||||||
|
* @param Builder $query Builder
|
||||||
|
* @param array $values Values
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected function compileSets(Builder $query, array $values) : string
|
||||||
|
{
|
||||||
|
$vals = '';
|
||||||
|
|
||||||
|
foreach ($values as $column => $value) {
|
||||||
|
// todo change expressionizeTableColumn to accept single column and create additionl for Columns
|
||||||
|
$expression = $this->expressionizeTableColumn([$column], $query->getPrefix());
|
||||||
|
|
||||||
|
$vals .= $expression . ' = ' . $this->compileValue($value) . ', ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($vals === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'SET ' . rtrim($vals, ', ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,11 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class RelationType extends Enum
|
abstract class RelationType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const NONE = 0;
|
/* public */ const NONE = 1;
|
||||||
/* public */ const NEWEST = 1;
|
/* public */ const NEWEST = 2;
|
||||||
/* public */ const BELONGS_TO = 2;
|
/* public */ const BELONGS_TO = 4;
|
||||||
/* public */ const OWNS_ONE = 4;
|
/* public */ const OWNS_ONE = 8;
|
||||||
/* public */ const HAS_MANY = 8;
|
/* public */ const HAS_MANY = 16;
|
||||||
/* public */ const ALL = 16;
|
/* public */ const ALL = 32;
|
||||||
/* public */ const REFERENCE = 32;
|
/* public */ const REFERENCE = 64;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,10 @@ class HttpSession implements SessionInterface
|
||||||
|
|
||||||
$this->inactivityInterval = $inactivityInterval;
|
$this->inactivityInterval = $inactivityInterval;
|
||||||
|
|
||||||
session_set_cookie_params($liftetime, '/', '', false, true);
|
if(session_status() !== PHP_SESSION_ACTIVE && !headers_sent()) {
|
||||||
session_start();
|
session_set_cookie_params($liftetime, '/', '', false, true);
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
if($this->inactivityInterval > 0 && ($this->inactivityInterval + ($_SESSION['lastActivity'] ?? 0) < time())) {
|
if($this->inactivityInterval > 0 && ($this->inactivityInterval + ($_SESSION['lastActivity'] ?? 0) < time())) {
|
||||||
$this->destroy();
|
$this->destroy();
|
||||||
|
|
|
||||||
|
|
@ -135,9 +135,7 @@ class Dispatcher
|
||||||
{
|
{
|
||||||
$views = [];
|
$views = [];
|
||||||
foreach ($controller as $controllerSingle) {
|
foreach ($controller as $controllerSingle) {
|
||||||
foreach ($controllerSingle as $c) {
|
$views += $this->dispatch($controllerSingle, ...$data);
|
||||||
$views += $this->dispatch($c, ...$data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $views;
|
return $views;
|
||||||
|
|
|
||||||
|
|
@ -1,40 +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\Html;
|
|
||||||
|
|
||||||
use phpOMS\Stdlib\Base\Enum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tag type enum.
|
|
||||||
*
|
|
||||||
* @category Framework
|
|
||||||
* @package phpOMS\Html
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @link http://orange-management.com
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
abstract class TagType extends Enum
|
|
||||||
{
|
|
||||||
/* public */ const INPUT = 0; /* <input> */
|
|
||||||
/* public */ const BUTTON = 1; /* <button> */
|
|
||||||
/* public */ const LINK = 2; /* <a> */
|
|
||||||
/* public */ const SYMMETRIC = 3; /* <span><div>... */
|
|
||||||
/* public */ const TEXTAREA = 4; /* <textarea> */
|
|
||||||
/* public */ const SELECT = 5; /* <select> */
|
|
||||||
/* public */ const LABEL = 6; /* <label> */
|
|
||||||
/* public */ const ULIST = 7; /* <ul> */
|
|
||||||
/* public */ const OLIST = 8; /* <ul> */
|
|
||||||
}
|
|
||||||
|
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Localization;
|
namespace phpOMS\Localization;
|
||||||
|
|
||||||
use phpOMS\Log\FileLogger;
|
use phpOMS\Log\FileLogger;
|
||||||
use phpOMS\Log\LoggerInterface;
|
|
||||||
use phpOMS\Module\ModuleAbstract;
|
use phpOMS\Module\ModuleAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,24 +38,13 @@ class L11nManager
|
||||||
*/
|
*/
|
||||||
private $language = [];
|
private $language = [];
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger.
|
|
||||||
*
|
|
||||||
* @var LoggerInterface
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $logger = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct.
|
* Construct.
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger Logger
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @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));
|
$this->loadLanguage($code, $module, $class::getLocalization($code, $theme));
|
||||||
|
|
||||||
if (!isset($this->language[$code][$module][$translation])) {
|
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';
|
return 'ERROR';
|
||||||
}
|
}
|
||||||
} catch(\Excpetion $e) {
|
} catch(\Exception $e) {
|
||||||
$this->logger->warning(FileLogger::MSG_FULL, [
|
FileLogger::getInstance()->warning(FileLogger::MSG_FULL, [
|
||||||
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.',
|
'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,8 @@ class Localization
|
||||||
*/
|
*/
|
||||||
public function setLanguage(string $language) /* : void */
|
public function setLanguage(string $language) /* : void */
|
||||||
{
|
{
|
||||||
|
$language = strtolower($language);
|
||||||
|
|
||||||
if (!ISO639x1Enum::isValidValue($language)) {
|
if (!ISO639x1Enum::isValidValue($language)) {
|
||||||
throw new InvalidEnumValue($language);
|
throw new InvalidEnumValue($language);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ namespace phpOMS\Log;
|
||||||
|
|
||||||
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
||||||
use phpOMS\System\File\Local\File;
|
use phpOMS\System\File\Local\File;
|
||||||
use phpOMS\System\File\PathException;
|
|
||||||
use phpOMS\Utils\StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging class.
|
* Logging class.
|
||||||
|
|
@ -44,7 +42,7 @@ class FileLogger implements LoggerInterface
|
||||||
* @var array
|
* @var array
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private $timings = [];
|
private static $timings = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance.
|
* Instance.
|
||||||
|
|
@ -152,6 +150,7 @@ class FileLogger implements LoggerInterface
|
||||||
* Closes the logging file
|
* Closes the logging file
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
|
|
@ -164,6 +163,7 @@ class FileLogger implements LoggerInterface
|
||||||
* Protect instance from getting copied from outside.
|
* Protect instance from getting copied from outside.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __clone()
|
private function __clone()
|
||||||
{
|
{
|
||||||
|
|
@ -174,16 +174,22 @@ class FileLogger implements LoggerInterface
|
||||||
*
|
*
|
||||||
* @param string $id the ID by which this time measurement gets identified
|
* @param string $id the ID by which this time measurement gets identified
|
||||||
*
|
*
|
||||||
* @return void
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function startTimeLog($id = '') /* : void */
|
public static function startTimeLog($id = '') : bool
|
||||||
{
|
{
|
||||||
|
if(isset(self::$timings[$id])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$mtime = explode(' ', microtime());
|
$mtime = explode(' ', microtime());
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
$mtime = $mtime[1] + $mtime[0];
|
||||||
|
|
||||||
$this->timings[$id] = ['start' => $mtime];
|
self::$timings[$id] = ['start' => $mtime];
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -195,29 +201,15 @@ class FileLogger implements LoggerInterface
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function endTimeLog($id = '') : int
|
public static function endTimeLog($id = '') : float
|
||||||
{
|
{
|
||||||
$mtime = explode(' ', microtime());
|
$mtime = explode(' ', microtime());
|
||||||
$mtime = $mtime[1] + $mtime[0];
|
$mtime = $mtime[1] + $mtime[0];
|
||||||
|
|
||||||
$this->timings[$id]['end'] = $mtime;
|
self::$timings[$id]['end'] = $mtime;
|
||||||
$this->timings[$id]['time'] = $mtime - $this->timings[$id]['start'];
|
self::$timings[$id]['time'] = $mtime - self::$timings[$id]['start'];
|
||||||
|
|
||||||
return $this->timings[$id]['time'];
|
return self::$timings[$id]['time'];
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sorts timings descending.
|
|
||||||
*
|
|
||||||
* @param array [float] &$timings the timing array to sort
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function timingSort(&$timings) /* : void */
|
|
||||||
{
|
|
||||||
uasort($timings, [$this, 'orderSort']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -261,25 +253,6 @@ class FileLogger implements LoggerInterface
|
||||||
return strtr($message, $replace);
|
return strtr($message, $replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sorts all timings descending.
|
|
||||||
*
|
|
||||||
* @param array $a
|
|
||||||
* @param array $b
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function orderSort($a, $b) : int
|
|
||||||
{
|
|
||||||
if ($a['time'] == $b['time']) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($a['time'] > $b['time']) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write to file.
|
* Write to file.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,622 +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\Business\Finance\Forecasting\ExponentialSmoothing;
|
|
||||||
|
|
||||||
use phpOMS\Business\Finance\Forecasting\SmoothingType;
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
|
||||||
use phpOMS\Math\Statistic\Forecast\Error;
|
|
||||||
|
|
||||||
class ExponentialSmoothing
|
|
||||||
{
|
|
||||||
private $data = [];
|
|
||||||
|
|
||||||
private $errors = [];
|
|
||||||
|
|
||||||
private $rmse = 0.0;
|
|
||||||
|
|
||||||
private $mse = 0.0;
|
|
||||||
|
|
||||||
private $mae = 0.0;
|
|
||||||
|
|
||||||
private $sse = 0.0;
|
|
||||||
|
|
||||||
public function __construct(array $data)
|
|
||||||
{
|
|
||||||
$this->data = $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRMSE() : float
|
|
||||||
{
|
|
||||||
return $this->rmse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMSE() : float
|
|
||||||
{
|
|
||||||
return $this->mse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMAE() : float
|
|
||||||
{
|
|
||||||
return $this->mae;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSSE() : float
|
|
||||||
{
|
|
||||||
return $this->sse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getErrors() : array
|
|
||||||
{
|
|
||||||
return $this->errors;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getForecast(int $future, int $trendType = TrendType::NONE, int $seasonalType = SeasonalType::NONE, int $cycle = 12, float $damping = 1) : array
|
|
||||||
{
|
|
||||||
$this->rmse = PHP_INT_MAX;
|
|
||||||
|
|
||||||
if($trendType === TrendType::ALL || $seasonalType === SeasonalType::ALL) {
|
|
||||||
$trends = [$trendType];
|
|
||||||
if($trendType === TrendType::ALL) {
|
|
||||||
$trends = [TrendType::NONE, TrendType::ADDITIVE, TrendType::MULTIPLICATIVE];
|
|
||||||
}
|
|
||||||
|
|
||||||
$seasonals = [$seasonalType];
|
|
||||||
if($seasonalType === SeasonalType::ALL) {
|
|
||||||
$seasonals = [SeasonalType::NONE, SeasonalType::ADDITIVE, SeasonalType::MULTIPLICATIVE];
|
|
||||||
}
|
|
||||||
|
|
||||||
$forecast = [];
|
|
||||||
$bestError = PHP_INT_MAX;
|
|
||||||
foreach($trends as $trend) {
|
|
||||||
foreach($seasonals as $seasonal) {
|
|
||||||
$tempForecast = $this->getForecast($future, $trend, $seasonal, $cycle, $damping);
|
|
||||||
|
|
||||||
if ($this->rmse < $bestError) {
|
|
||||||
$bestError = $this->rmse;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::NONE) {
|
|
||||||
return $this->getNoneNone($future);
|
|
||||||
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::ADDITIVE) {
|
|
||||||
return $this->getNoneAdditive($future, $cycle);
|
|
||||||
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
|
|
||||||
return $this->getNoneMultiplicative($future, $cycle);
|
|
||||||
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::NONE) {
|
|
||||||
return $this->getAdditiveNone($future, $damping);
|
|
||||||
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::ADDITIVE) {
|
|
||||||
return $this->getAdditiveAdditive($future, $cycle, $damping);
|
|
||||||
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
|
|
||||||
return $this->getAdditiveMultiplicative($future, $cycle, $damping);
|
|
||||||
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::NONE) {
|
|
||||||
return $this->getMultiplicativeNone($future, $damping);
|
|
||||||
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::ADDITIVE) {
|
|
||||||
return $this->getMultiplicativeAdditive($future, $cycle, $damping);
|
|
||||||
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
|
|
||||||
return $this->getMultiplicativeMultiplicative($future, $cycle, $damping);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function dampingSum(float $damping, int $length) : float
|
|
||||||
{
|
|
||||||
if(abs($damping - 1) < 0.001) {
|
|
||||||
return $length;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sum = 0;
|
|
||||||
for($i = 0; $i < $length; $i++) {
|
|
||||||
$sum += pow($damping, $i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNoneNone(int $future) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNoneAdditive(int $future, int $cycle) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i-1] - $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNoneMultiplicative(int $future, int $cycle) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i] / $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdditiveNone(int $future, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$trend = [$this->data[1] - $this->data[0]];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
|
|
||||||
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdditiveAdditive(int $future, int $cycle, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [1 / $cycle * array_sum(array_slice($this->data, 0, $cycle))];
|
|
||||||
$trend = [1 / $cycle];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
|
|
||||||
$sum = 0;
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
$trend[0] *= $sum;
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i-1] - $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
|
|
||||||
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i] + $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAdditiveMultiplicative(int $future, int $cycle, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [1 / $cycle * array_sum(array_slice($this->data, 0, $cycle))];
|
|
||||||
$trend = [1 / $cycle];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
|
|
||||||
$sum = 0;
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
$trend[0] *= $sum;
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i] / $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
|
|
||||||
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / ($level[$i-1] + $damping * $trend[$i-1]) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[] = ($level[$i] + $this->dampingSum($damping, $i) * $trend[$i-1]) * $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiplicativeNone(int $future, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$trend = [$this->data[1] / $this->data[0]];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
|
|
||||||
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i));
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiplicativeAdditive(int $future, int $cycle, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$trend = [1 / $cycle];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
|
|
||||||
$sum = 0;
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
$trend[0] *= $sum;
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i-1] - $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
|
|
||||||
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1] * pow($trend[$i-1], $damping)) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) + $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getMultiplicativeMultiplicative(int $future, int $cycle, float $damping) : array
|
|
||||||
{
|
|
||||||
$level = [$this->data[0]];
|
|
||||||
$trend = [1 / $cycle];
|
|
||||||
$dataLength = count($this->data) + $future;
|
|
||||||
$forecast = [];
|
|
||||||
$seasonal = [];
|
|
||||||
|
|
||||||
$sum = 0;
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
|
|
||||||
}
|
|
||||||
|
|
||||||
$trend[0] *= $sum;
|
|
||||||
|
|
||||||
for($i = 1; $i < $cycle+1; $i++) {
|
|
||||||
$seasonal[$i] = $this->data[$i] / $level[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha = 0.00;
|
|
||||||
while ($alpha < 1) {
|
|
||||||
$beta = 0.00;
|
|
||||||
|
|
||||||
while($beta < 1) {
|
|
||||||
$gamma = 0.00;
|
|
||||||
|
|
||||||
while($gamma < 1) {
|
|
||||||
$gamma_ = $gamma * (1 - $alpha);
|
|
||||||
$error = [];
|
|
||||||
$tempForecast = [];
|
|
||||||
|
|
||||||
for($i = 1; $i < $dataLength; $i++) {
|
|
||||||
$hm = (int) floor(($i-1) % $cycle) + 1;
|
|
||||||
|
|
||||||
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
|
|
||||||
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
|
|
||||||
$seasonal[$i+$cycle] = $gamma_*($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / ($level[$i-1] * pow($trend[$i-1], $damping)) + (1 - $gamma_) * $seasonal[$i];
|
|
||||||
|
|
||||||
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) * $seasonal[$i+$hm];
|
|
||||||
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tempRMSE = Error::getRootMeanSquaredError($error);
|
|
||||||
|
|
||||||
if ($tempRMSE < $this->rmse) {
|
|
||||||
$this->rmse = $tempRMSE;
|
|
||||||
$forecast = $tempForecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gamma += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$beta += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alpha += 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->errors = $error;
|
|
||||||
$this->mse = Error::getMeanSquaredError($error);
|
|
||||||
$this->mae = Error::getMeanAbsoulteError($error);
|
|
||||||
$this->sse = Error::getSumSquaredError($error);
|
|
||||||
|
|
||||||
return $forecast;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -227,7 +227,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function isOdd($a) : bool
|
public static function isOdd($a) : bool
|
||||||
{
|
{
|
||||||
return $a & 1;
|
return (bool) ($a & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -241,7 +241,7 @@ class Functions
|
||||||
*/
|
*/
|
||||||
public static function isEven($a) : bool
|
public static function isEven($a) : bool
|
||||||
{
|
{
|
||||||
return !($a & 1);
|
return !((bool) ($a & 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -254,7 +254,7 @@ class Functions
|
||||||
* @param mixed $length Circle size
|
* @param mixed $length Circle size
|
||||||
* @param mixed $start Start value
|
* @param mixed $start Start value
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int Lowest value is 0 and highest value is length - 1
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -40,34 +40,32 @@ final class MonotoneChain
|
||||||
public static function createConvexHull(array $points) : array
|
public static function createConvexHull(array $points) : array
|
||||||
{
|
{
|
||||||
if (($n = count($points)) > 1) {
|
if (($n = count($points)) > 1) {
|
||||||
$k = 0;
|
|
||||||
$h = [];
|
|
||||||
|
|
||||||
uasort($points, [self::class, 'sort']);
|
uasort($points, [self::class, 'sort']);
|
||||||
|
|
||||||
|
$k = 0;
|
||||||
|
$result = [];
|
||||||
|
|
||||||
// Lower hull
|
// Lower hull
|
||||||
for ($i = 0; $i < $n; ++$i) {
|
for ($i = 0; $i < $n; ++$i) {
|
||||||
while ($k >= 2 && self::cross($h[$k - 2], $h[$k - 1], $points[$i]) <= 0) {
|
while ($k >= 2 && self::cross($result[$k - 2], $result[$k - 1], $points[$i]) <= 0) {
|
||||||
$k--;
|
$k--;
|
||||||
}
|
}
|
||||||
|
|
||||||
$h[$k++] = $points[$i];
|
$result[$k++] = $points[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upper hull
|
// Upper hull
|
||||||
for ($i = $n - 2, $t = $k + 1; $i >= 0; $i--) {
|
for ($i = $n - 2, $t = $k+1; $i >= 0; $i--) {
|
||||||
while ($k >= $t && self::cross($h[$k - 2], $h[$k - 1], $points[$i]) <= 0) {
|
while ($k >= $t && self::cross($result[$k - 2], $result[$k - 1], $points[$i]) <= 0) {
|
||||||
$k--;
|
$k--;
|
||||||
}
|
}
|
||||||
|
|
||||||
$h[$k++] = $points[$i];
|
$result[$k++] = $points[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($k > 1) {
|
ksort($result);
|
||||||
$h = array_splice($h, $k - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $h;
|
return array_slice($result, 0, $k-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $points;
|
return $points;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +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\Matrix;
|
|
||||||
|
|
||||||
class Cholesky
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
105
Math/Matrix/CholeskyDecomposition.php
Normal file
105
Math/Matrix/CholeskyDecomposition.php
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
<?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 CholeskyDecomposition
|
||||||
|
{
|
||||||
|
private $L = [];
|
||||||
|
|
||||||
|
private $m = 0;
|
||||||
|
|
||||||
|
private $isSpd = true;
|
||||||
|
|
||||||
|
public function __construct(Matrix $M)
|
||||||
|
{
|
||||||
|
$this->L = $M->toArray();
|
||||||
|
$this->m = $M->getM();
|
||||||
|
|
||||||
|
for($i = 0; $i < $this->m; ++$i) {
|
||||||
|
for($j = $i; $j < $this->m; ++$j) {
|
||||||
|
for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
|
||||||
|
$sum -= $this->L[$i][$k] * $this->L[$j][$k];
|
||||||
|
}
|
||||||
|
if ($i == $j) {
|
||||||
|
if ($sum >= 0) {
|
||||||
|
$this->L[$i][$i] = sqrt($sum);
|
||||||
|
} else {
|
||||||
|
$this->isSpd = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($this->L[$i][$i] != 0) {
|
||||||
|
$this->L[$j][$i] = $sum / $this->L[$i][$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($k = $i+1; $k < $this->m; ++$k) {
|
||||||
|
$this->L[$i][$k] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSpd()
|
||||||
|
{
|
||||||
|
return $this->isSpd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getL()
|
||||||
|
{
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setMatrix($this->L);
|
||||||
|
|
||||||
|
return $matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function solve(Matrix $B)
|
||||||
|
{
|
||||||
|
if ($B->getM() !== $this->m) {
|
||||||
|
// invalid dimension
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isSpd) {
|
||||||
|
// is not positive definite
|
||||||
|
}
|
||||||
|
|
||||||
|
$X = $B->toArray();
|
||||||
|
$nx = $B->getN();
|
||||||
|
|
||||||
|
for ($k = 0; $k < $this->m; ++$k) {
|
||||||
|
for ($i = $k + 1; $i < $this->m; ++$i) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$k][$j] /= $this->L[$k][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($k = $this->m - 1; $k >= 0; --$k) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$k][$j] /= $this->L[$k][$k];
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < $k; ++$i) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Matrix($X, $this->m, $nx);
|
||||||
|
}
|
||||||
|
}
|
||||||
185
Math/Matrix/LUDecomposition.php
Normal file
185
Math/Matrix/LUDecomposition.php
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
<?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 LUDecomposition
|
||||||
|
{
|
||||||
|
private $LU = [];
|
||||||
|
|
||||||
|
private $m = 0;
|
||||||
|
private $n = 0;
|
||||||
|
|
||||||
|
private $pivSign = 1;
|
||||||
|
|
||||||
|
private $piv = [];
|
||||||
|
|
||||||
|
public function __construct(Matrix $M)
|
||||||
|
{
|
||||||
|
$this->LU = $M->toArray();
|
||||||
|
$this->m = $M->getM();
|
||||||
|
$this->n = $M->getN();
|
||||||
|
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
$this->piv[$i] = $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pivSign = 1;
|
||||||
|
$LUrowi = $LUcolj = [];
|
||||||
|
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
// Make a copy of the j-th column to localize references.
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
$LUcolj[$i] = &$this->LU[$i][$j];
|
||||||
|
}
|
||||||
|
// Apply previous transformations.
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
$LUrowi = $this->LU[$i];
|
||||||
|
// Most of the time is spent in the following dot product.
|
||||||
|
$kmax = min($i,$j);
|
||||||
|
$s = 0.0;
|
||||||
|
for ($k = 0; $k < $kmax; ++$k) {
|
||||||
|
$s += $LUrowi[$k] * $LUcolj[$k];
|
||||||
|
}
|
||||||
|
$LUrowi[$j] = $LUcolj[$i] -= $s;
|
||||||
|
}
|
||||||
|
// Find pivot and exchange if necessary.
|
||||||
|
$p = $j;
|
||||||
|
for ($i = $j+1; $i < $this->m; ++$i) {
|
||||||
|
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
|
||||||
|
$p = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($p != $j) {
|
||||||
|
for ($k = 0; $k < $this->n; ++$k) {
|
||||||
|
$t = $this->LU[$p][$k];
|
||||||
|
$this->LU[$p][$k] = $this->LU[$j][$k];
|
||||||
|
$this->LU[$j][$k] = $t;
|
||||||
|
}
|
||||||
|
$k = $this->piv[$p];
|
||||||
|
$this->piv[$p] = $this->piv[$j];
|
||||||
|
$this->piv[$j] = $k;
|
||||||
|
$this->pivSign = $this->pivSign * -1;
|
||||||
|
}
|
||||||
|
// Compute multipliers.
|
||||||
|
if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
|
||||||
|
for ($i = $j+1; $i < $this->m; ++$i) {
|
||||||
|
$this->LU[$i][$j] /= $this->LU[$j][$j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getL()
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($i > $j) {
|
||||||
|
$L[$i][$j] = $this->LU[$i][$j];
|
||||||
|
} elseif ($i == $j) {
|
||||||
|
$L[$i][$j] = 1.0;
|
||||||
|
} else {
|
||||||
|
$L[$i][$j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setMatrix($L);
|
||||||
|
|
||||||
|
return $matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getU()
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < $this->n; ++$i) {
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($i <= $j) {
|
||||||
|
$U[$i][$j] = $this->LU[$i][$j];
|
||||||
|
} else {
|
||||||
|
$U[$i][$j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setMatrix($U);
|
||||||
|
|
||||||
|
return $matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPivot()
|
||||||
|
{
|
||||||
|
return $this->piv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isNonsingular() : bool
|
||||||
|
{
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($this->LU[$j][$j] == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function det()
|
||||||
|
{
|
||||||
|
$d = $this->pivSign;
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
$d *= $this->LU[$j][$j];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function solve(Matrix $B)
|
||||||
|
{
|
||||||
|
if ($B->getM() !== $this->m) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isNonsingular()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
var_dump($this->piv);
|
||||||
|
|
||||||
|
$nx = $B->getM();
|
||||||
|
$X = $B->getMatrix($this->piv, 0, $nx-1);
|
||||||
|
|
||||||
|
// Solve L*Y = B(piv,:)
|
||||||
|
for ($k = 0; $k < $this->n; ++$k) {
|
||||||
|
for ($i = $k+1; $i < $this->n; ++$i) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solve U*X = Y;
|
||||||
|
for ($k = $this->n-1; $k >= 0; --$k) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X->A[$k][$j] /= $this->LU[$k][$k];
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < $k; ++$i) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $X;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(int $m, int $n = 1)
|
public function __construct(int $m = 1, int $n = 1)
|
||||||
{
|
{
|
||||||
$this->n = $n;
|
$this->n = $n;
|
||||||
$this->m = $m;
|
$this->m = $m;
|
||||||
|
|
@ -146,6 +146,18 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
return $this->matrix;
|
return $this->matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get matrix array.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function toArray() : array
|
||||||
|
{
|
||||||
|
return $this->matrix;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get matrix rank.
|
* Get matrix rank.
|
||||||
*
|
*
|
||||||
|
|
@ -171,10 +183,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
*/
|
*/
|
||||||
public function setMatrix(array $matrix) : Matrix
|
public function setMatrix(array $matrix) : Matrix
|
||||||
{
|
{
|
||||||
if ($this->m !== count($matrix) || $this->n !== count($matrix[0])) {
|
$this->m = count($matrix);
|
||||||
throw new InvalidDimensionException(count($matrix) . 'x' . count($matrix[0]));
|
$this->n = count($matrix[0] ?? 1);
|
||||||
}
|
|
||||||
|
|
||||||
$this->matrix = $matrix;
|
$this->matrix = $matrix;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
@ -491,16 +501,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
*/
|
*/
|
||||||
public function inverse(int $algorithm = InverseType::GAUSS_JORDAN) : Matrix
|
public function inverse(int $algorithm = InverseType::GAUSS_JORDAN) : Matrix
|
||||||
{
|
{
|
||||||
if ($this->n !== $this->m) {
|
return $this->solve(new IdentityMatrix($this->m, $this->m));
|
||||||
throw new InvalidDimensionException($this->m . 'x' . $this->n);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ($algorithm) {
|
|
||||||
case InverseType::GAUSS_JORDAN:
|
|
||||||
return $this->inverseGaussJordan();
|
|
||||||
default:
|
|
||||||
throw new \Exception('Inversion algorithm');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -561,9 +562,11 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
return $newMatrix;
|
return $newMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function solve($b, int $algorithm) : Matrix
|
public function solve(Matrix $B) : Matrix
|
||||||
{
|
{
|
||||||
return $this->gaussElimination($b);
|
$M = $this->m === $this->n ? new LUDecomposition($this) : new QRDecomposition($this);
|
||||||
|
|
||||||
|
return $M->solve($B);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function gaussElimination($b) : Matrix
|
private function gaussElimination($b) : Matrix
|
||||||
|
|
@ -671,18 +674,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
*/
|
*/
|
||||||
public function det() : float
|
public function det() : float
|
||||||
{
|
{
|
||||||
if ($this->n === 1) {
|
$L = new LUDecomposition($this);
|
||||||
return $this->matrix[0][0];
|
return $L->det();
|
||||||
}
|
|
||||||
|
|
||||||
$trianglize = $this->matrix;
|
|
||||||
$prod = $this->upperTrianglize($trianglize);
|
|
||||||
|
|
||||||
for ($i = 0; $i < $this->n; $i++) {
|
|
||||||
$prod *= $trianglize[$i][$i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $prod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -809,32 +802,4 @@ class Matrix implements \ArrayAccess, \Iterator
|
||||||
unset($this->matrix[$row][$offset - $row * $this->n]);
|
unset($this->matrix[$row][$offset - $row * $this->n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Decompose matrix using cholesky algorithm.
|
|
||||||
*
|
|
||||||
* @return Matrix
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function decompositionCholesky() : Matrix
|
|
||||||
{
|
|
||||||
$newMatrix = new Matrix($this->n, $this->n);
|
|
||||||
$newMatrixArr = $newMatrix->getMatrix();
|
|
||||||
|
|
||||||
for ($i = 0; $i < $this->n; $i++) {
|
|
||||||
for ($j = 0; $j < $i + 1; $j++) {
|
|
||||||
$temp = 0;
|
|
||||||
|
|
||||||
for ($c = 0; $c < $j; $c++) {
|
|
||||||
$temp += $newMatrixArr[$i][$c] * $newMatrixArr[$j][$c];
|
|
||||||
}
|
|
||||||
|
|
||||||
$newMatrixArr[$i][$j] = ($i == $j) ? sqrt($this->matrix[$i][$i] - $temp) : (1 / $newMatrixArr[$j][$j] * ($this->matrix[$i][$j] - $temp));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$newMatrix->setMatrix($newMatrixArr);
|
|
||||||
|
|
||||||
return $newMatrix;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
187
Math/Matrix/QRDecomposition.php
Normal file
187
Math/Matrix/QRDecomposition.php
Normal file
|
|
@ -0,0 +1,187 @@
|
||||||
|
<?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 QRDecomposition
|
||||||
|
{
|
||||||
|
private $QR = [];
|
||||||
|
|
||||||
|
private $m = 0;
|
||||||
|
private $n = 0;
|
||||||
|
|
||||||
|
private $Rdiag = [];
|
||||||
|
|
||||||
|
public function __construct(Matrix $M)
|
||||||
|
{
|
||||||
|
// Initialize.
|
||||||
|
$this->QR = $M->toArray();
|
||||||
|
$this->m = $M->getRowDimension();
|
||||||
|
$this->n = $M->getColumnDimension();
|
||||||
|
|
||||||
|
// Main loop.
|
||||||
|
for ($k = 0; $k < $this->n; ++$k) {
|
||||||
|
// Compute 2-norm of k-th column without under/overflow.
|
||||||
|
$nrm = 0.0;
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$nrm = hypo($nrm, $this->QR[$i][$k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($nrm != 0.0) {
|
||||||
|
// Form k-th Householder vector.
|
||||||
|
if ($this->QR[$k][$k] < 0) {
|
||||||
|
$nrm = -$nrm;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$this->QR[$i][$k] /= $nrm;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->QR[$k][$k] += 1.0;
|
||||||
|
// Apply transformation to remaining columns.
|
||||||
|
for ($j = $k+1; $j < $this->n; ++$j) {
|
||||||
|
$s = 0.0;
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$s += $this->QR[$i][$k] * $this->QR[$i][$j];
|
||||||
|
}
|
||||||
|
|
||||||
|
$s = -$s/$this->QR[$k][$k];
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$this->QR[$i][$j] += $s * $this->QR[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->Rdiag[$k] = -$nrm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFullRank() : bool
|
||||||
|
{
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($this->Rdiag[$j] == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getH()
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($i >= $j) {
|
||||||
|
$H[$i][$j] = $this->QR[$i][$j];
|
||||||
|
} else {
|
||||||
|
$H[$i][$j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setArray($H);
|
||||||
|
|
||||||
|
return $this->matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getR()
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < $this->n; ++$i) {
|
||||||
|
for ($j = 0; $j < $this->n; ++$j) {
|
||||||
|
if ($i < $j) {
|
||||||
|
$R[$i][$j] = $this->QR[$i][$j];
|
||||||
|
} elseif ($i == $j) {
|
||||||
|
$R[$i][$j] = $this->Rdiag[$i];
|
||||||
|
} else {
|
||||||
|
$R[$i][$j] = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setArray($R);
|
||||||
|
|
||||||
|
return $this->matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQ()
|
||||||
|
{
|
||||||
|
for ($k = $this->n-1; $k >= 0; --$k) {
|
||||||
|
for ($i = 0; $i < $this->m; ++$i) {
|
||||||
|
$Q[$i][$k] = 0.0;
|
||||||
|
}
|
||||||
|
$Q[$k][$k] = 1.0;
|
||||||
|
for ($j = $k; $j < $this->n; ++$j) {
|
||||||
|
if ($this->QR[$k][$k] != 0) {
|
||||||
|
$s = 0.0;
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$s += $this->QR[$i][$k] * $Q[$i][$j];
|
||||||
|
}
|
||||||
|
$s = -$s/$this->QR[$k][$k];
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$Q[$i][$j] += $s * $this->QR[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setArray($Q);
|
||||||
|
|
||||||
|
return $this->matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function solve(Matrix $B)
|
||||||
|
{
|
||||||
|
if ($B->getRowDimension() !== $this->m) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->isFullRank()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
$nx = $B->getColumnDimension();
|
||||||
|
$X = $B->getArrayCopy();
|
||||||
|
// Compute Y = transpose(Q)*B
|
||||||
|
for ($k = 0; $k < $this->n; ++$k) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$s = 0.0;
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$s += $this->QR[$i][$k] * $X[$i][$j];
|
||||||
|
}
|
||||||
|
$s = -$s/$this->QR[$k][$k];
|
||||||
|
for ($i = $k; $i < $this->m; ++$i) {
|
||||||
|
$X[$i][$j] += $s * $this->QR[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Solve R*X = Y;
|
||||||
|
for ($k = $this->n-1; $k >= 0; --$k) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$k][$j] /= $this->Rdiag[$k];
|
||||||
|
}
|
||||||
|
for ($i = 0; $i < $k; ++$i) {
|
||||||
|
for ($j = 0; $j < $nx; ++$j) {
|
||||||
|
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$matrix = new Matrix();
|
||||||
|
$matrix->setArray($X);
|
||||||
|
|
||||||
|
return $matrix->getMatrix(0, $this->n-1, 0, $nx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,13 +28,13 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class NumberType extends Enum
|
abstract class NumberType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const INTEGER = 1;
|
/* public */ const N_INTEGER = 0;
|
||||||
/* public */ const NATURAL = 21;
|
/* public */ const N_NATURAL = 1;
|
||||||
/* public */ const EVEN = 211;
|
/* public */ const N_EVEN = 2;
|
||||||
/* public */ const UNEVEN = 212;
|
/* public */ const N_UNEVEN = 4;
|
||||||
/* public */ const PRIME = 22;
|
/* public */ const N_PRIME = 8;
|
||||||
/* public */ const REAL = 3;
|
/* public */ const N_REAL = 16;
|
||||||
/* public */ const RATIONAL = 4;
|
/* public */ const N_RATIONAL = 32;
|
||||||
/* public */ const IRRATIONAL = 5;
|
/* public */ const N_IRRATIONAL = 64;
|
||||||
/* public */ const COMPLEX = 6;
|
/* public */ const N_COMPLEX = 128;
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +30,6 @@ class MultipleLinearRegression
|
||||||
$Y = new Matrix(count($y));
|
$Y = new Matrix(count($y));
|
||||||
$Y->setMatrix($y);
|
$Y->setMatrix($y);
|
||||||
|
|
||||||
|
|
||||||
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix();
|
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,22 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
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\Average;
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||||
use phpOMS\Math\Matrix\Exception\InvalidDimensionException;
|
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
|
abstract class RegressionAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,7 +155,35 @@ abstract class RegressionAbstract
|
||||||
return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x);
|
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
|
private function normalizeDictionary() : array
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,29 @@ abstract class HeaderAbstract
|
||||||
$this->l11n = new Localization();
|
$this->l11n = new Localization();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set header locked.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function lock() /* : void */
|
||||||
|
{
|
||||||
|
// todo: maybe pass session as member and make lock not static
|
||||||
|
self::$isLocked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is header locked?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function isLocked() : bool
|
||||||
|
{
|
||||||
|
return self::$isLocked;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Localization
|
* Get Localization
|
||||||
*
|
*
|
||||||
|
|
@ -81,11 +104,11 @@ abstract class HeaderAbstract
|
||||||
{
|
{
|
||||||
return $this->l11n;
|
return $this->l11n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set localization
|
* Set localization
|
||||||
*
|
*
|
||||||
* @param int $localization Localization
|
* @param Localization $l11n Localization
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -121,7 +144,6 @@ abstract class HeaderAbstract
|
||||||
{
|
{
|
||||||
$this->account = $account;
|
$this->account = $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set status code
|
* Set status code
|
||||||
|
|
@ -135,9 +157,18 @@ abstract class HeaderAbstract
|
||||||
public function setStatusCode(int $status) /* : void */
|
public function setStatusCode(int $status) /* : void */
|
||||||
{
|
{
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
$this->header->generate($status);
|
$this->generate($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate header based on status code.
|
||||||
|
*
|
||||||
|
* @param int $statusCode Status code
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
abstract public function generate(int $statusCode) /* : void */;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get status code
|
* Get status code
|
||||||
*
|
*
|
||||||
|
|
@ -149,7 +180,7 @@ abstract class HeaderAbstract
|
||||||
{
|
{
|
||||||
return $this->status;
|
return $this->status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get protocol version.
|
* Get protocol version.
|
||||||
*
|
*
|
||||||
|
|
@ -170,15 +201,6 @@ abstract class HeaderAbstract
|
||||||
*/
|
*/
|
||||||
abstract public function set(string $key, string $value, bool $overwrite = false);
|
abstract public function set(string $key, string $value, bool $overwrite = false);
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate header based on status code.
|
|
||||||
*
|
|
||||||
* @param int $statusCode Status code
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
abstract public function generate(int $statusCode) /* : void */;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get header by key.
|
* Get header by key.
|
||||||
*
|
*
|
||||||
|
|
@ -200,27 +222,4 @@ abstract class HeaderAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract public function has(string $key) : bool;
|
abstract public function has(string $key) : bool;
|
||||||
|
|
||||||
/**
|
|
||||||
* Set header locked.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function lock() /* : void */
|
|
||||||
{
|
|
||||||
// todo: maybe pass session as member and make lock not static
|
|
||||||
self::$isLocked = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is header locked?
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function isLocked() : bool
|
|
||||||
{
|
|
||||||
return self::$isLocked;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\Message\Http;
|
namespace phpOMS\Message\Http;
|
||||||
|
|
||||||
use phpOMS\Message\HeaderAbstract;
|
use phpOMS\Message\HeaderAbstract;
|
||||||
use phpOMS\DataStorage\LockExcpetion;
|
use phpOMS\DataStorage\LockException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response class.
|
* Response class.
|
||||||
|
|
@ -68,7 +68,7 @@ class Header extends HeaderAbstract
|
||||||
public function set(string $key, string $header, bool $overwrite = false) : bool
|
public function set(string $key, string $header, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
if (self::$isLocked) {
|
if (self::$isLocked) {
|
||||||
throw new LockExcpetion('HTTP header');
|
throw new LockException('HTTP header');
|
||||||
}
|
}
|
||||||
|
|
||||||
$key = strtolower($key);
|
$key = strtolower($key);
|
||||||
|
|
@ -76,7 +76,7 @@ class Header extends HeaderAbstract
|
||||||
if (!$overwrite && isset($this->header[$key])) {
|
if (!$overwrite && isset($this->header[$key])) {
|
||||||
return false;
|
return false;
|
||||||
} elseif ($overwrite || !isset($this->header[$key])) {
|
} elseif ($overwrite || !isset($this->header[$key])) {
|
||||||
if ($this->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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,14 +92,6 @@ class Header extends HeaderAbstract
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getProtocolVersion() : string
|
|
||||||
{
|
|
||||||
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is security header.
|
* Is security header.
|
||||||
*
|
*
|
||||||
|
|
@ -109,12 +101,22 @@ class Header extends HeaderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function isSecurityHeader(string $key) : bool
|
public static function isSecurityHeader(string $key) : bool
|
||||||
{
|
{
|
||||||
return $key === 'content-security-policy' ||
|
$key = strtolower($key);
|
||||||
$key === 'x-xss-protection' ||
|
|
||||||
$key === 'x-content-type-options' ||
|
return $key === 'content-security-policy'
|
||||||
$key === 'x-frame-options';
|
|| $key === 'x-xss-protection'
|
||||||
|
|| $key === 'x-content-type-options'
|
||||||
|
|| $key === 'x-frame-options';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getProtocolVersion() : string
|
||||||
|
{
|
||||||
|
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -127,34 +129,10 @@ class Header extends HeaderAbstract
|
||||||
public function getStatusCode() : int
|
public function getStatusCode() : int
|
||||||
{
|
{
|
||||||
if($this->status === 0) {
|
if($this->status === 0) {
|
||||||
$this->status = \http_response_code();
|
$this->status = (int) \http_response_code();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->status;
|
return parent::getStatusCode();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all pushed headers.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getHeaders() : array
|
|
||||||
{
|
|
||||||
return self::getAllHeaders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get pushed header by name.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getHeader(string $name) : string
|
|
||||||
{
|
|
||||||
return self::getAllHeaders()[$name] ?? '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -164,7 +142,7 @@ class Header extends HeaderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function getAllHeaders() : array
|
public static function getAllHeaders() : array
|
||||||
{
|
{
|
||||||
if (function_exists('getallheaders')) {
|
if (function_exists('getallheaders')) {
|
||||||
return getallheaders();
|
return getallheaders();
|
||||||
|
|
@ -183,7 +161,7 @@ class Header extends HeaderAbstract
|
||||||
/**
|
/**
|
||||||
* Remove header by ID.
|
* Remove header by ID.
|
||||||
*
|
*
|
||||||
* @param int $key Header key
|
* @param mixed $key Header key
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
|
|
@ -191,10 +169,10 @@ class Header extends HeaderAbstract
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function remove(int $key) : bool
|
public function remove($key) : bool
|
||||||
{
|
{
|
||||||
if (self::$isLocked) {
|
if (self::$isLocked) {
|
||||||
throw new \LockException('HTTP header');
|
throw new LockException('HTTP header');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->header[$key])) {
|
if (isset($this->header[$key])) {
|
||||||
|
|
@ -206,10 +184,20 @@ class Header extends HeaderAbstract
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getReasonPhrase() : string
|
||||||
|
{
|
||||||
|
$phrases = $this->get('Status');
|
||||||
|
|
||||||
|
return empty($phrases) ? '' : $phrases[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get header by name.
|
* Get header by name.
|
||||||
*
|
*
|
||||||
* @param int $key Header key
|
* @param string $key Header key
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
|
|
@ -219,19 +207,11 @@ class Header extends HeaderAbstract
|
||||||
{
|
{
|
||||||
return $this->header[strtolower($key)] ?? [];
|
return $this->header[strtolower($key)] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getReasonPhrase() : string
|
|
||||||
{
|
|
||||||
return $this->header->getHeader('Status');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if header is defined.
|
* Check if header is defined.
|
||||||
*
|
*
|
||||||
* @param int $key Header key
|
* @param string $key Header key
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
|
|
@ -341,22 +321,7 @@ class Header extends HeaderAbstract
|
||||||
*/
|
*/
|
||||||
private function generate407() /* : void */
|
private function generate407() /* : void */
|
||||||
{
|
{
|
||||||
|
\http_response_code(407);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate predefined header.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function generate500() /* : void */
|
|
||||||
{
|
|
||||||
$this->set('HTTP', 'HTTP/1.0 500 Internal Server Error');
|
|
||||||
$this->set('Status', 'Status: 500 Internal Server Error');
|
|
||||||
$this->set('Retry-After', 'Retry-After: 300');
|
|
||||||
\http_response_code(500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -373,4 +338,19 @@ class Header extends HeaderAbstract
|
||||||
$this->set('Retry-After', 'Retry-After: 300');
|
$this->set('Retry-After', 'Retry-After: 300');
|
||||||
\http_response_code(503);
|
\http_response_code(503);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate predefined header.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function generate500() /* : void */
|
||||||
|
{
|
||||||
|
$this->set('HTTP', 'HTTP/1.0 500 Internal Server Error');
|
||||||
|
$this->set('Status', 'Status: 500 Internal Server Error');
|
||||||
|
$this->set('Retry-After', 'Retry-After: 300');
|
||||||
|
\http_response_code(500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,27 +30,27 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class OSType extends Enum
|
abstract class OSType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const WINDOWS_81 = 'windows nt 6.3'; /* Windows 8.1 */
|
/* public */ const WINDOWS_81 = 'windows nt 6.3'; /* Windows 8.1 */
|
||||||
/* public */ const WINDOWS_8 = 'windows nt 6.2'; /* Windows 8 */
|
/* public */ const WINDOWS_8 = 'windows nt 6.2'; /* Windows 8 */
|
||||||
/* public */ const WINDOWS_7 = 'windows nt 6.1'; /* Windows 7 */
|
/* public */ const WINDOWS_7 = 'windows nt 6.1'; /* Windows 7 */
|
||||||
/* public */ const WINDOWS_VISTA = 'windows nt 6.0'; /* Windows Vista */
|
/* public */ const WINDOWS_VISTA = 'windows nt 6.0'; /* Windows Vista */
|
||||||
/* public */ const WINDOWS_SERVER = 'windows nt 5.2'; /* Windows Server 2003/XP x64 */
|
/* public */ const WINDOWS_SERVER = 'windows nt 5.2'; /* Windows Server 2003/XP x64 */
|
||||||
/* public */ const WINDOWS_XP = 'windows nt 5.1'; /* Windows XP */
|
/* public */ const WINDOWS_XP = 'windows nt 5.1'; /* Windows XP */
|
||||||
/* public */ const WINDOWS_XP_2 = 'windows xp'; /* Windows XP */
|
/* public */ const WINDOWS_XP_2 = 'windows xp'; /* Windows XP */
|
||||||
/* public */ const WINDOWS_2000 = 'windows nt 5.0'; /* Windows 2000 */
|
/* public */ const WINDOWS_2000 = 'windows nt 5.0'; /* Windows 2000 */
|
||||||
/* public */ const WINDOWS_ME = 'windows me'; /* Windows ME */
|
/* public */ const WINDOWS_ME = 'windows me'; /* Windows ME */
|
||||||
/* public */ const WINDOWS_98 = 'win98'; /* Windows 98 */
|
/* public */ const WINDOWS_98 = 'win98'; /* Windows 98 */
|
||||||
/* public */ const WINDOWS_95 = 'win95'; /* Windows 95 */
|
/* public */ const WINDOWS_95 = 'win95'; /* Windows 95 */
|
||||||
/* public */ const WINDOWS_311 = 'win16'; /* Windows 3.11 */
|
/* public */ const WINDOWS_311 = 'win16'; /* Windows 3.11 */
|
||||||
/* public */ const MAC_OS_X = 'macintosh'; /* Mac OS X */
|
/* public */ const MAC_OS_X = 'macintosh'; /* Mac OS X */
|
||||||
/* public */ const MAC_OS_X_2 = 'mac os x'; /* Mac OS X */
|
/* public */ const MAC_OS_X_2 = 'mac os x'; /* Mac OS X */
|
||||||
/* public */ const MAC_OS_9 = 'mac_powerpc'; /* Mac OS 9 */
|
/* public */ const MAC_OS_9 = 'mac_powerpc'; /* Mac OS 9 */
|
||||||
/* public */ const LINUX = 'linux'; /* Linux */
|
/* public */ const LINUX = 'linux'; /* Linux */
|
||||||
/* public */ const UBUNTU = 'ubuntu'; /* Ubuntu */
|
/* public */ const UBUNTU = 'ubuntu'; /* Ubuntu */
|
||||||
/* public */ const IPHONE = 'iphone'; /* IPhone */
|
/* public */ const IPHONE = 'iphone'; /* IPhone */
|
||||||
/* public */ const IPOD = 'ipod'; /* IPod */
|
/* public */ const IPOD = 'ipod'; /* IPod */
|
||||||
/* public */ const IPAD = 'ipad'; /* IPad */
|
/* public */ const IPAD = 'ipad'; /* IPad */
|
||||||
/* public */ const ANDROID = 'android'; /* Android */
|
/* public */ const ANDROID = 'android'; /* Android */
|
||||||
/* public */ const BLACKBERRY = 'blackberry'; /* Blackberry */
|
/* public */ const BLACKBERRY = 'blackberry'; /* Blackberry */
|
||||||
/* public */ const MOBILE = 'webos'; /* Mobile */
|
/* public */ const MOBILE = 'webos'; /* Mobile */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,50 +67,28 @@ class Request extends RequestAbstract
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param Localization $l11n Localization
|
|
||||||
* @param UriInterface $uri Uri
|
* @param UriInterface $uri Uri
|
||||||
|
* @param Localization $l11n Localization
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(Localization $l11n = null, UriInterface $uri = null)
|
public function __construct(UriInterface $uri = null, Localization $l11n = null)
|
||||||
{
|
{
|
||||||
$this->l11n = $l11n;
|
|
||||||
$this->uri = $uri;
|
|
||||||
$this->source = RequestSource::WEB;
|
|
||||||
$this->header = new Header();
|
$this->header = new Header();
|
||||||
|
$this->header->setL11n($l11n ?? new Localization());
|
||||||
|
|
||||||
|
$this->uri = $uri;
|
||||||
|
$this->source = RequestSource::WEB;
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create request from super globals.
|
|
||||||
*
|
|
||||||
* @param Localization $l11n Localization
|
|
||||||
*
|
|
||||||
* @return Request
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function createFromSuperglobals(Localization $l11n = null) : Request
|
|
||||||
{
|
|
||||||
return new self($l11n);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setUri(UriInterface $uri) /* : void */
|
|
||||||
{
|
|
||||||
$this->uri = $uri;
|
|
||||||
$this->data += $uri->getQueryArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init request.
|
* Init request.
|
||||||
*
|
*
|
||||||
* This is used in order to either initialize the current http request or a batch of GET requests
|
* 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
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -140,10 +118,10 @@ class Request extends RequestAbstract
|
||||||
*/
|
*/
|
||||||
private function initCurrentRequest() /* : void */
|
private function initCurrentRequest() /* : void */
|
||||||
{
|
{
|
||||||
$this->uri = new Http(Http::getCurrent());
|
$this->uri = new Http(Http::getCurrent());
|
||||||
$this->data = $_GET ?? [];
|
$this->data = $_GET ?? [];
|
||||||
$this->files = $_FILES ?? [];
|
$this->files = $_FILES ?? [];
|
||||||
$this->language = $this->loadRequestLanguage();
|
$this->header->getL11n()->setLanguage($this->loadRequestLanguage());
|
||||||
|
|
||||||
if (isset($_SERVER['CONTENT_TYPE'])) {
|
if (isset($_SERVER['CONTENT_TYPE'])) {
|
||||||
if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
|
if (strpos($_SERVER['CONTENT_TYPE'], 'application/json') !== false) {
|
||||||
|
|
@ -204,7 +182,7 @@ class Request extends RequestAbstract
|
||||||
*/
|
*/
|
||||||
private function setupUriBuilder() /* : void */
|
private function setupUriBuilder() /* : void */
|
||||||
{
|
{
|
||||||
UriFactory::setQuery('/lang', $this->l11n->getLanguage());
|
UriFactory::setQuery('/lang', $this->header->getL11n()->getLanguage());
|
||||||
|
|
||||||
// todo: flush previous
|
// todo: flush previous
|
||||||
foreach($this->data as $key => $value) {
|
foreach($this->data as $key => $value) {
|
||||||
|
|
@ -212,12 +190,25 @@ class Request extends RequestAbstract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create request from super globals.
|
||||||
|
*
|
||||||
|
* @return Request
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function createFromSuperglobals() : Request
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getLanguage() : string
|
public function setUri(UriInterface $uri) /* : void */
|
||||||
{
|
{
|
||||||
return $this->language;
|
parent::setUri($uri);
|
||||||
|
$this->data += $uri->getQueryArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -330,6 +321,7 @@ class Request extends RequestAbstract
|
||||||
if (!isset($this->os)) {
|
if (!isset($this->os)) {
|
||||||
$arr = OSType::getConstants();
|
$arr = OSType::getConstants();
|
||||||
$http_request_type = strtolower($_SERVER['HTTP_USER_AGENT']);
|
$http_request_type = strtolower($_SERVER['HTTP_USER_AGENT']);
|
||||||
|
|
||||||
foreach ($arr as $key => $val) {
|
foreach ($arr as $key => $val) {
|
||||||
if (stripos($http_request_type, $val)) {
|
if (stripos($http_request_type, $val)) {
|
||||||
$this->os = $val;
|
$this->os = $val;
|
||||||
|
|
@ -385,21 +377,6 @@ class Request extends RequestAbstract
|
||||||
|| ($_SERVER['SERVER_PORT'] ?? '') == $port;
|
|| ($_SERVER['SERVER_PORT'] ?? '') == $port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Stringify request.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
$lastElement = end($this->hash);
|
|
||||||
reset($this->hash);
|
|
||||||
|
|
||||||
return $lastElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class RequestMethod extends Enum
|
abstract class RequestMethod extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const GET = 'GET'; /* GET */
|
/* public */ const GET = 'GET'; /* GET */
|
||||||
/* public */ const POST = 'POST'; /* POST */
|
/* public */ const POST = 'POST'; /* POST */
|
||||||
/* public */ const PUT = 'PUT'; /* PUT */
|
/* public */ const PUT = 'PUT'; /* PUT */
|
||||||
/* public */ const DELETE = 'DELETE'; /* DELETE */
|
/* public */ const DELETE = 'DELETE'; /* DELETE */
|
||||||
/* public */ const HEAD = 'HEAD'; /* HEAD */
|
/* public */ const HEAD = 'HEAD'; /* HEAD */
|
||||||
/* public */ const TRACE = 'TRACE'; /* TRACE */
|
/* public */ const TRACE = 'TRACE'; /* TRACE */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,112 +29,58 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
abstract class RequestStatus extends Enum
|
abstract class RequestStatus extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const R_100 = 'Continue';
|
/* public */ const R_100 = 'Continue';
|
||||||
|
|
||||||
/* public */ const R_101 = 'Switching Protocols';
|
/* public */ const R_101 = 'Switching Protocols';
|
||||||
|
|
||||||
/* public */ const R_102 = 'Processing';
|
/* public */ const R_102 = 'Processing';
|
||||||
|
|
||||||
/* public */ const R_200 = 'OK';
|
/* public */ const R_200 = 'OK';
|
||||||
|
|
||||||
/* public */ const R_201 = 'Created';
|
/* public */ const R_201 = 'Created';
|
||||||
|
|
||||||
/* public */ const R_202 = 'Accepted';
|
/* public */ const R_202 = 'Accepted';
|
||||||
|
|
||||||
/* public */ const R_203 = 'Non-Authoritative Information';
|
/* public */ const R_203 = 'Non-Authoritative Information';
|
||||||
|
|
||||||
/* public */ const R_204 = 'No Content';
|
/* public */ const R_204 = 'No Content';
|
||||||
|
|
||||||
/* public */ const R_205 = 'Reset Content';
|
/* public */ const R_205 = 'Reset Content';
|
||||||
|
|
||||||
/* public */ const R_206 = 'Partial Content';
|
/* public */ const R_206 = 'Partial Content';
|
||||||
|
|
||||||
/* public */ const R_207 = 'Multi-Status';
|
/* public */ const R_207 = 'Multi-Status';
|
||||||
|
|
||||||
/* public */ const R_300 = 'Multiple Choices';
|
/* public */ const R_300 = 'Multiple Choices';
|
||||||
|
|
||||||
/* public */ const R_301 = 'Moved Permanently';
|
/* public */ const R_301 = 'Moved Permanently';
|
||||||
|
|
||||||
/* public */ const R_302 = 'Found';
|
/* public */ const R_302 = 'Found';
|
||||||
|
|
||||||
/* public */ const R_303 = 'See Other';
|
/* public */ const R_303 = 'See Other';
|
||||||
|
|
||||||
/* public */ const R_304 = 'Not Modified';
|
/* public */ const R_304 = 'Not Modified';
|
||||||
|
|
||||||
/* public */ const R_305 = 'Use Proxy';
|
/* public */ const R_305 = 'Use Proxy';
|
||||||
|
|
||||||
/* public */ const R_306 = 'Switch Proxy';
|
/* public */ const R_306 = 'Switch Proxy';
|
||||||
|
|
||||||
/* public */ const R_307 = 'Temporary Redirect';
|
/* public */ const R_307 = 'Temporary Redirect';
|
||||||
|
|
||||||
/* public */ const R_400 = 'Bad Request';
|
/* public */ const R_400 = 'Bad Request';
|
||||||
|
|
||||||
/* public */ const R_401 = 'Unauthorized';
|
/* public */ const R_401 = 'Unauthorized';
|
||||||
|
|
||||||
/* public */ const R_402 = 'Payment Required';
|
/* public */ const R_402 = 'Payment Required';
|
||||||
|
|
||||||
/* public */ const R_403 = 'Forbidden';
|
/* public */ const R_403 = 'Forbidden';
|
||||||
|
|
||||||
/* public */ const R_404 = 'Not Found';
|
/* public */ const R_404 = 'Not Found';
|
||||||
|
|
||||||
/* public */ const R_405 = 'Method Not Allowed';
|
/* public */ const R_405 = 'Method Not Allowed';
|
||||||
|
|
||||||
/* public */ const R_406 = 'Not Acceptable';
|
/* public */ const R_406 = 'Not Acceptable';
|
||||||
|
|
||||||
/* public */ const R_407 = 'Proxy Authentication Required';
|
/* public */ const R_407 = 'Proxy Authentication Required';
|
||||||
|
|
||||||
/* public */ const R_408 = 'Request Timeout';
|
/* public */ const R_408 = 'Request Timeout';
|
||||||
|
|
||||||
/* public */ const R_409 = 'Conflict';
|
/* public */ const R_409 = 'Conflict';
|
||||||
|
|
||||||
/* public */ const R_410 = 'Gone';
|
/* public */ const R_410 = 'Gone';
|
||||||
|
|
||||||
/* public */ const R_411 = 'Length Required';
|
/* public */ const R_411 = 'Length Required';
|
||||||
|
|
||||||
/* public */ const R_412 = 'Precondition Failed';
|
/* public */ const R_412 = 'Precondition Failed';
|
||||||
|
|
||||||
/* public */ const R_413 = 'Request Entity Too Large';
|
/* public */ const R_413 = 'Request Entity Too Large';
|
||||||
|
|
||||||
/* public */ const R_414 = 'Request-URI Too Long';
|
/* public */ const R_414 = 'Request-URI Too Long';
|
||||||
|
|
||||||
/* public */ const R_415 = 'Unsupported Media Type';
|
/* public */ const R_415 = 'Unsupported Media Type';
|
||||||
|
|
||||||
/* public */ const R_416 = 'Requested Range Not Satisfiable';
|
/* public */ const R_416 = 'Requested Range Not Satisfiable';
|
||||||
|
|
||||||
/* public */ const R_417 = 'Expectation Failed';
|
/* public */ const R_417 = 'Expectation Failed';
|
||||||
|
|
||||||
/* public */ const R_418 = 'I\'m a teapot';
|
/* public */ const R_418 = 'I\'m a teapot';
|
||||||
|
|
||||||
/* public */ const R_422 = 'Unprocessable Entity';
|
/* public */ const R_422 = 'Unprocessable Entity';
|
||||||
|
|
||||||
/* public */ const R_423 = 'Locked';
|
/* public */ const R_423 = 'Locked';
|
||||||
|
|
||||||
/* public */ const R_424 = 'Failed Dependency';
|
/* public */ const R_424 = 'Failed Dependency';
|
||||||
|
|
||||||
/* public */ const R_425 = 'Unordered Collection';
|
/* public */ const R_425 = 'Unordered Collection';
|
||||||
|
|
||||||
/* public */ const R_426 = 'Upgrade Required';
|
/* public */ const R_426 = 'Upgrade Required';
|
||||||
|
|
||||||
/* public */ const R_449 = 'Retry With';
|
/* public */ const R_449 = 'Retry With';
|
||||||
|
|
||||||
/* public */ const R_450 = 'Blocked by Windows Parental Controls';
|
/* public */ const R_450 = 'Blocked by Windows Parental Controls';
|
||||||
|
|
||||||
/* public */ const R_500 = 'Internal Server Error';
|
/* public */ const R_500 = 'Internal Server Error';
|
||||||
|
|
||||||
/* public */ const R_501 = 'Not Implemented';
|
/* public */ const R_501 = 'Not Implemented';
|
||||||
|
|
||||||
/* public */ const R_502 = 'Bad Gateway';
|
/* public */ const R_502 = 'Bad Gateway';
|
||||||
|
|
||||||
/* public */ const R_503 = 'Service Unavailable';
|
/* public */ const R_503 = 'Service Unavailable';
|
||||||
|
|
||||||
/* public */ const R_504 = 'Gateway Timeout';
|
/* public */ const R_504 = 'Gateway Timeout';
|
||||||
|
|
||||||
/* public */ const R_505 = 'HTTP Version Not Supported';
|
/* public */ const R_505 = 'HTTP Version Not Supported';
|
||||||
|
|
||||||
/* public */ const R_506 = 'Variant Also Negotiates';
|
/* public */ const R_506 = 'Variant Also Negotiates';
|
||||||
|
|
||||||
/* public */ const R_507 = 'Insufficient Storage';
|
/* public */ const R_507 = 'Insufficient Storage';
|
||||||
|
|
||||||
/* public */ const R_509 = 'Bandwidth Limit Exceeded';
|
/* public */ const R_509 = 'Bandwidth Limit Exceeded';
|
||||||
|
|
||||||
/* public */ const R_510 = 'Not Extended';
|
/* public */ const R_510 = 'Not Extended';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,112 +28,58 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
abstract class RequestStatusCode extends Enum
|
abstract class RequestStatusCode extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const R_100 = 100;
|
/* public */ const R_100 = 100;
|
||||||
|
|
||||||
/* public */ const R_101 = 101;
|
/* public */ const R_101 = 101;
|
||||||
|
|
||||||
/* public */ const R_102 = 102;
|
/* public */ const R_102 = 102;
|
||||||
|
|
||||||
/* public */ const R_200 = 200;
|
/* public */ const R_200 = 200;
|
||||||
|
|
||||||
/* public */ const R_201 = 201;
|
/* public */ const R_201 = 201;
|
||||||
|
|
||||||
/* public */ const R_202 = 202;
|
/* public */ const R_202 = 202;
|
||||||
|
|
||||||
/* public */ const R_203 = 203;
|
/* public */ const R_203 = 203;
|
||||||
|
|
||||||
/* public */ const R_204 = 204;
|
/* public */ const R_204 = 204;
|
||||||
|
|
||||||
/* public */ const R_205 = 205;
|
/* public */ const R_205 = 205;
|
||||||
|
|
||||||
/* public */ const R_206 = 206;
|
/* public */ const R_206 = 206;
|
||||||
|
|
||||||
/* public */ const R_207 = 207;
|
/* public */ const R_207 = 207;
|
||||||
|
|
||||||
/* public */ const R_300 = 300;
|
/* public */ const R_300 = 300;
|
||||||
|
|
||||||
/* public */ const R_301 = 301;
|
/* public */ const R_301 = 301;
|
||||||
|
|
||||||
/* public */ const R_302 = 302;
|
/* public */ const R_302 = 302;
|
||||||
|
|
||||||
/* public */ const R_303 = 303;
|
/* public */ const R_303 = 303;
|
||||||
|
|
||||||
/* public */ const R_304 = 304;
|
/* public */ const R_304 = 304;
|
||||||
|
|
||||||
/* public */ const R_305 = 305;
|
/* public */ const R_305 = 305;
|
||||||
|
|
||||||
/* public */ const R_306 = 306;
|
/* public */ const R_306 = 306;
|
||||||
|
|
||||||
/* public */ const R_307 = 307;
|
/* public */ const R_307 = 307;
|
||||||
|
|
||||||
/* public */ const R_400 = 400;
|
/* public */ const R_400 = 400;
|
||||||
|
|
||||||
/* public */ const R_401 = 401;
|
/* public */ const R_401 = 401;
|
||||||
|
|
||||||
/* public */ const R_402 = 402;
|
/* public */ const R_402 = 402;
|
||||||
|
|
||||||
/* public */ const R_403 = 403;
|
/* public */ const R_403 = 403;
|
||||||
|
|
||||||
/* public */ const R_404 = 404;
|
/* public */ const R_404 = 404;
|
||||||
|
|
||||||
/* public */ const R_405 = 405;
|
/* public */ const R_405 = 405;
|
||||||
|
|
||||||
/* public */ const R_406 = 406;
|
/* public */ const R_406 = 406;
|
||||||
|
|
||||||
/* public */ const R_407 = 407;
|
/* public */ const R_407 = 407;
|
||||||
|
|
||||||
/* public */ const R_408 = 408;
|
/* public */ const R_408 = 408;
|
||||||
|
|
||||||
/* public */ const R_409 = 409;
|
/* public */ const R_409 = 409;
|
||||||
|
|
||||||
/* public */ const R_410 = 410;
|
/* public */ const R_410 = 410;
|
||||||
|
|
||||||
/* public */ const R_411 = 411;
|
/* public */ const R_411 = 411;
|
||||||
|
|
||||||
/* public */ const R_412 = 412;
|
/* public */ const R_412 = 412;
|
||||||
|
|
||||||
/* public */ const R_413 = 413;
|
/* public */ const R_413 = 413;
|
||||||
|
|
||||||
/* public */ const R_414 = 414;
|
/* public */ const R_414 = 414;
|
||||||
|
|
||||||
/* public */ const R_415 = 415;
|
/* public */ const R_415 = 415;
|
||||||
|
|
||||||
/* public */ const R_416 = 416;
|
/* public */ const R_416 = 416;
|
||||||
|
|
||||||
/* public */ const R_417 = 417;
|
/* public */ const R_417 = 417;
|
||||||
|
|
||||||
/* public */ const R_418 = 418;
|
/* public */ const R_418 = 418;
|
||||||
|
|
||||||
/* public */ const R_422 = 422;
|
/* public */ const R_422 = 422;
|
||||||
|
|
||||||
/* public */ const R_423 = 423;
|
/* public */ const R_423 = 423;
|
||||||
|
|
||||||
/* public */ const R_424 = 424;
|
/* public */ const R_424 = 424;
|
||||||
|
|
||||||
/* public */ const R_425 = 425;
|
/* public */ const R_425 = 425;
|
||||||
|
|
||||||
/* public */ const R_426 = 426;
|
/* public */ const R_426 = 426;
|
||||||
|
|
||||||
/* public */ const R_449 = 449;
|
/* public */ const R_449 = 449;
|
||||||
|
|
||||||
/* public */ const R_450 = 450;
|
/* public */ const R_450 = 450;
|
||||||
|
|
||||||
/* public */ const R_500 = 500;
|
/* public */ const R_500 = 500;
|
||||||
|
|
||||||
/* public */ const R_501 = 501;
|
/* public */ const R_501 = 501;
|
||||||
|
|
||||||
/* public */ const R_502 = 502;
|
/* public */ const R_502 = 502;
|
||||||
|
|
||||||
/* public */ const R_503 = 503;
|
/* public */ const R_503 = 503;
|
||||||
|
|
||||||
/* public */ const R_504 = 504;
|
/* public */ const R_504 = 504;
|
||||||
|
|
||||||
/* public */ const R_505 = 505;
|
/* public */ const R_505 = 505;
|
||||||
|
|
||||||
/* public */ const R_506 = 506;
|
/* public */ const R_506 = 506;
|
||||||
|
|
||||||
/* public */ const R_507 = 507;
|
/* public */ const R_507 = 507;
|
||||||
|
|
||||||
/* public */ const R_509 = 509;
|
/* public */ const R_509 = 509;
|
||||||
|
|
||||||
/* public */ const R_510 = 510;
|
/* public */ const R_510 = 510;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,10 @@ class Response extends ResponseAbstract implements RenderableInterface
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct(Localization $l11n)
|
public function __construct(Localization $l11n = null)
|
||||||
{
|
{
|
||||||
$this->header = new Header();
|
$this->header = new Header();
|
||||||
$this->l11n = $l11n;
|
$this->header->setL11n($l11n ?? new Localization());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace phpOMS\Message\Mail;
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class MailAbstract
|
class EmailAbstract
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Host.
|
* Host.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Message;
|
namespace phpOMS\Message;
|
||||||
|
|
||||||
use phpOMS\Localization\Localization;
|
|
||||||
use phpOMS\Utils\ArrayUtils;
|
use phpOMS\Utils\ArrayUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,7 +71,9 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function set($key, $response, bool $overwrite = true) /* : void */
|
public function set($key, $response, bool $overwrite = true) /* : void */
|
||||||
{
|
{
|
||||||
$this->response = ArrayUtils::setArray((string) $key, $this->response, $response, ':', $overwrite);
|
// This is not working since the key kontains :: from http://
|
||||||
|
//$this->response = ArrayUtils::setArray((string) $key, $this->response, $response, ':', $overwrite);
|
||||||
|
$this->response[$key] = $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ class InfoManager
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function __construct($path)
|
public function __construct(string $path)
|
||||||
{
|
{
|
||||||
$this->path = realpath($path);
|
$this->path = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,8 +83,8 @@ class InfoManager
|
||||||
*/
|
*/
|
||||||
public function load() /* : void */
|
public function load() /* : void */
|
||||||
{
|
{
|
||||||
if ($this->path === false || !file_exists($this->path)) {
|
if (!file_exists($this->path)) {
|
||||||
throw new PathException((string) $this->path);
|
throw new PathException($this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info = json_decode(file_get_contents($this->path), true);
|
$this->info = json_decode(file_get_contents($this->path), true);
|
||||||
|
|
@ -99,7 +99,7 @@ class InfoManager
|
||||||
*/
|
*/
|
||||||
public function update() /* : void */
|
public function update() /* : void */
|
||||||
{
|
{
|
||||||
if ($this->path === false || !file_exists($this->path)) {
|
if (!file_exists($this->path)) {
|
||||||
throw new PathException((string) $this->path);
|
throw new PathException((string) $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class InstallerAbstract
|
||||||
/**
|
/**
|
||||||
* Init routes.
|
* Init routes.
|
||||||
*
|
*
|
||||||
* @param string $routePath Route Path
|
* @param string $modulePath Path to the module
|
||||||
* @param InfoManager $info Module info
|
* @param InfoManager $info Module info
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ abstract class ModuleAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
/* public */ const MODULE_NAME = '';
|
/* public */ const MODULE_NAME = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module path.
|
* Module path.
|
||||||
*
|
*
|
||||||
|
|
@ -41,6 +42,7 @@ abstract class ModuleAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
/* public */ const MODULE_PATH = __DIR__ . '/../../Modules';
|
/* public */ const MODULE_PATH = __DIR__ . '/../../Modules';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module version.
|
* Module version.
|
||||||
*
|
*
|
||||||
|
|
@ -48,6 +50,15 @@ abstract class ModuleAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
/* public */ const MODULE_VERSION = '1.0.0';
|
/* public */ const MODULE_VERSION = '1.0.0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module id.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
/* public */ const MODULE_ID = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receiving modules from?
|
* Receiving modules from?
|
||||||
*
|
*
|
||||||
|
|
@ -96,15 +107,6 @@ abstract class ModuleAbstract
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Install external.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function installExternal() /* : void */
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get language files.
|
* Get language files.
|
||||||
*
|
*
|
||||||
|
|
@ -160,16 +162,4 @@ abstract class ModuleAbstract
|
||||||
/** @noinspection PhpUndefinedFieldInspection */
|
/** @noinspection PhpUndefinedFieldInspection */
|
||||||
return static::$dependencies;
|
return static::$dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get event id prefix.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getEventId() : string
|
|
||||||
{
|
|
||||||
return static::class;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\Module;
|
namespace phpOMS\Module;
|
||||||
|
|
||||||
use phpOMS\ApplicationAbstract;
|
|
||||||
use phpOMS\Autoloader;
|
use phpOMS\Autoloader;
|
||||||
|
use phpOMS\ApplicationAbstract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModuleFactory class.
|
* ModuleFactory class.
|
||||||
|
|
@ -54,6 +54,7 @@ class ModuleFactory
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ class ModuleManager
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param ApplicationAbstract $app Application
|
* @param ApplicationAbstract $app Application
|
||||||
|
* @param string $modulePath Path to modules
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,80 +106,6 @@ class ModuleManager
|
||||||
$this->modulePath = $modulePath;
|
$this->modulePath = $modulePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get modules that run on this page.
|
|
||||||
*
|
|
||||||
* @param Request $request Request
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getRoutedModules(Request $request) : array
|
|
||||||
{
|
|
||||||
$files = $this->getUriLoad($request);
|
|
||||||
|
|
||||||
$modules = [];
|
|
||||||
if (isset($files[4])) {
|
|
||||||
foreach ($files[4] as $module) {
|
|
||||||
$modules[] = $module['module_load_file'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $modules;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get modules that run on this page.
|
|
||||||
*
|
|
||||||
* @param Request $request Request
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getUriLoad(Request $request) : array
|
|
||||||
{
|
|
||||||
if (!isset($this->uriLoad)) {
|
|
||||||
switch ($this->app->dbPool->get('core')->getType()) {
|
|
||||||
case DatabaseType::MYSQL:
|
|
||||||
$uriHash = $request->getHash();
|
|
||||||
$uriPdo = '';
|
|
||||||
|
|
||||||
$i = 1;
|
|
||||||
$c = count($uriHash);
|
|
||||||
for ($k = 0; $k < $c; $k++) {
|
|
||||||
$uriPdo .= ':pid' . $i . ',';
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$uriPdo = rtrim($uriPdo, ',');
|
|
||||||
|
|
||||||
/* TODO: make join in order to see if they are active */
|
|
||||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
|
||||||
'SELECT
|
|
||||||
`' . $this->app->dbPool->get('core')->prefix . 'module_load`.`module_load_type`, `' . $this->app->dbPool->get('core')->prefix . 'module_load`.*
|
|
||||||
FROM
|
|
||||||
`' . $this->app->dbPool->get('core')->prefix . 'module_load`
|
|
||||||
WHERE
|
|
||||||
`module_load_pid` IN(' . $uriPdo . ')'
|
|
||||||
);
|
|
||||||
|
|
||||||
$i = 1;
|
|
||||||
foreach ($uriHash as $hash) {
|
|
||||||
$sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sth->execute();
|
|
||||||
|
|
||||||
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->uriLoad;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get language files.
|
* Get language files.
|
||||||
*
|
*
|
||||||
|
|
@ -202,6 +129,58 @@ class ModuleManager
|
||||||
return $lang;
|
return $lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get modules that run on this page.
|
||||||
|
*
|
||||||
|
* @param Request $request Request
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getUriLoad(Request $request) : array
|
||||||
|
{
|
||||||
|
if (!isset($this->uriLoad)) {
|
||||||
|
switch ($this->app->dbPool->get('select')->getType()) {
|
||||||
|
case DatabaseType::MYSQL:
|
||||||
|
$uriHash = $request->getHash();
|
||||||
|
$uriPdo = '';
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
$c = count($uriHash);
|
||||||
|
|
||||||
|
for ($k = 0; $k < $c; $k++) {
|
||||||
|
$uriPdo .= ':pid' . $i . ',';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uriPdo = rtrim($uriPdo, ',');
|
||||||
|
|
||||||
|
/* TODO: make join in order to see if they are active */
|
||||||
|
$sth = $this->app->dbPool->get('select')->con->prepare(
|
||||||
|
'SELECT
|
||||||
|
`' . $this->app->dbPool->get('select')->prefix . 'module_load`.`module_load_type`, `' . $this->app->dbPool->get('select')->prefix . 'module_load`.*
|
||||||
|
FROM
|
||||||
|
`' . $this->app->dbPool->get('select')->prefix . 'module_load`
|
||||||
|
WHERE
|
||||||
|
`module_load_pid` IN(' . $uriPdo . ')'
|
||||||
|
);
|
||||||
|
|
||||||
|
$i = 1;
|
||||||
|
foreach ($uriHash as $hash) {
|
||||||
|
$sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sth->execute();
|
||||||
|
|
||||||
|
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->uriLoad;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all installed modules that are active (not just on this uri).
|
* Get all installed modules that are active (not just on this uri).
|
||||||
*
|
*
|
||||||
|
|
@ -212,9 +191,9 @@ class ModuleManager
|
||||||
public function getActiveModules() : array
|
public function getActiveModules() : array
|
||||||
{
|
{
|
||||||
if ($this->active === null) {
|
if ($this->active === null) {
|
||||||
switch ($this->app->dbPool->get('core')->getType()) {
|
switch ($this->app->dbPool->get('select')->getType()) {
|
||||||
case DatabaseType::MYSQL:
|
case DatabaseType::MYSQL:
|
||||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('core')->prefix . 'module` WHERE `module_active` = 1');
|
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_path` FROM `' . $this->app->dbPool->get('select')->prefix . 'module` WHERE `module_active` = 1');
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$this->active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
$this->active = $sth->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
break;
|
break;
|
||||||
|
|
@ -300,6 +279,74 @@ class ModuleManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all installed modules.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getInstalledModules() : array
|
||||||
|
{
|
||||||
|
if ($this->installed === null) {
|
||||||
|
switch ($this->app->dbPool->get('select')->getType()) {
|
||||||
|
case DatabaseType::MYSQL:
|
||||||
|
$sth = $this->app->dbPool->get('select')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('select')->prefix . 'module`');
|
||||||
|
$sth->execute();
|
||||||
|
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->installed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load info of module.
|
||||||
|
*
|
||||||
|
* @param string $module Module name
|
||||||
|
*
|
||||||
|
* @return InfoManager
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function loadInfo(string $module) : InfoManager
|
||||||
|
{
|
||||||
|
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json');
|
||||||
|
|
||||||
|
if ($path === false) {
|
||||||
|
throw new PathException($oldPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
$info = new InfoManager($path);
|
||||||
|
$info->load();
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate module.
|
||||||
|
*
|
||||||
|
* @param InfoManager $info Module info
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws InvalidModuleException Throws this exception in case the deactiviation doesn't exist
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function deactivateModule(InfoManager $info) /* : void */
|
||||||
|
{
|
||||||
|
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate';
|
||||||
|
|
||||||
|
if (!Autoloader::exists($class)) {
|
||||||
|
throw new InvalidModuleException($info->getDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var $class DeactivateAbstract */
|
||||||
|
$class::deactivate($this->app->dbPool, $info);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deactivate module.
|
* Deactivate module.
|
||||||
*
|
*
|
||||||
|
|
@ -335,6 +382,29 @@ class ModuleManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activate module.
|
||||||
|
*
|
||||||
|
* @param InfoManager $info Module info
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws InvalidModuleException Throws this exception in case the activation doesn't exist
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function activateModule(InfoManager $info) /* : void */
|
||||||
|
{
|
||||||
|
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate';
|
||||||
|
|
||||||
|
if (!Autoloader::exists($class)) {
|
||||||
|
throw new InvalidModuleException($info->getDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var $class ActivateAbstract */
|
||||||
|
$class::activate($this->app->dbPool, $info);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-init module.
|
* Re-init module.
|
||||||
*
|
*
|
||||||
|
|
@ -451,97 +521,6 @@ class ModuleManager
|
||||||
$class::install($this->modulePath, $this->app->dbPool, $info);
|
$class::install($this->modulePath, $this->app->dbPool, $info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Deactivate module.
|
|
||||||
*
|
|
||||||
* @param InfoManager $info Module info
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws InvalidModuleException Throws this exception in case the deactiviation doesn't exist
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function deactivateModule(InfoManager $info) /* : void */
|
|
||||||
{
|
|
||||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate';
|
|
||||||
|
|
||||||
if (!Autoloader::exists($class)) {
|
|
||||||
throw new InvalidModuleException($info->getDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var $class DeactivateAbstract */
|
|
||||||
$class::deactivate($this->app->dbPool, $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Activate module.
|
|
||||||
*
|
|
||||||
* @param InfoManager $info Module info
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws InvalidModuleException Throws this exception in case the activation doesn't exist
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function activateModule(InfoManager $info) /* : void */
|
|
||||||
{
|
|
||||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate';
|
|
||||||
|
|
||||||
if (!Autoloader::exists($class)) {
|
|
||||||
throw new InvalidModuleException($info->getDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var $class ActivateAbstract */
|
|
||||||
$class::activate($this->app->dbPool, $info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load info of module.
|
|
||||||
*
|
|
||||||
* @param string $module Module name
|
|
||||||
*
|
|
||||||
* @return InfoManager
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function loadInfo(string $module) : InfoManager
|
|
||||||
{
|
|
||||||
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json');
|
|
||||||
|
|
||||||
if ($path === false) {
|
|
||||||
throw new PathException($oldPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
$info = new InfoManager($path);
|
|
||||||
$info->load();
|
|
||||||
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all installed modules.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getInstalledModules() : array
|
|
||||||
{
|
|
||||||
if ($this->installed === null) {
|
|
||||||
switch ($this->app->dbPool->get('core')->getType()) {
|
|
||||||
case DatabaseType::MYSQL:
|
|
||||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_id`,`module_theme`,`module_version` FROM `' . $this->app->dbPool->get('core')->prefix . 'module`');
|
|
||||||
$sth->execute();
|
|
||||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->installed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Install providing.
|
* Install providing.
|
||||||
*
|
*
|
||||||
|
|
@ -563,6 +542,30 @@ class ModuleManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get module instance.
|
||||||
|
*
|
||||||
|
* @param string $module Module name
|
||||||
|
*
|
||||||
|
* @return \phpOMS\Module\ModuleAbstract
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function get(string $module) : ModuleAbstract
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (!isset($this->running[$module])) {
|
||||||
|
$this->initModule($module);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->running[$module];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize module.
|
* Initialize module.
|
||||||
*
|
*
|
||||||
|
|
@ -610,30 +613,6 @@ class ModuleManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get module instance.
|
|
||||||
*
|
|
||||||
* @param string $module Module name
|
|
||||||
*
|
|
||||||
* @return \phpOMS\Module\ModuleAbstract
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function get(string $module) : ModuleAbstract
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
if (!isset($this->running[$module])) {
|
|
||||||
$this->initModule($module);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->running[$module];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize all modules for a request.
|
* Initialize all modules for a request.
|
||||||
*
|
*
|
||||||
|
|
@ -651,4 +630,27 @@ class ModuleManager
|
||||||
$this->initModuleController($module);
|
$this->initModuleController($module);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get modules that run on this page.
|
||||||
|
*
|
||||||
|
* @param Request $request Request
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getRoutedModules(Request $request) : array
|
||||||
|
{
|
||||||
|
$files = $this->getUriLoad($request);
|
||||||
|
$modules = [];
|
||||||
|
|
||||||
|
if (isset($files[4])) {
|
||||||
|
foreach ($files[4] as $module) {
|
||||||
|
$modules[] = $module['module_load_file'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $modules;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
273
Module/PackageManager.php
Normal file
273
Module/PackageManager.php
Normal file
|
|
@ -0,0 +1,273 @@
|
||||||
|
<?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\Module;
|
||||||
|
|
||||||
|
use phpOMS\System\File\PathException;
|
||||||
|
use phpOMS\Utils\ArrayUtils;
|
||||||
|
use phpOMS\System\File\Local\File;
|
||||||
|
use phpOMS\System\File\Local\Directory;
|
||||||
|
use phpOMS\System\File\Local\LocalStorage;
|
||||||
|
use phpOMS\Utils\IO\Zip\Zip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Package Manager model.
|
||||||
|
*
|
||||||
|
* The package manager is responsible for handling installation and update packages for modules, frameworks and resources.
|
||||||
|
*
|
||||||
|
* @category Framework
|
||||||
|
* @package phpOMS\Account
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://orange-management.com
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class PackageManager
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* File path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $path = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $basePath = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $extractPath = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Info data.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private $info = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param string $path Package source path e.g. path after download.
|
||||||
|
* @param string basePath Path of the application
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function __construct(string $path, string $basePath)
|
||||||
|
{
|
||||||
|
$this->path = $path;
|
||||||
|
$this->basePath = $basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract package to temporary destination
|
||||||
|
*
|
||||||
|
* @param string $path Temporary extract path
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function extract(string $path) : bool
|
||||||
|
{
|
||||||
|
$this->extractPath = $path;
|
||||||
|
Zip::unpack($this->path, $this->extractPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load info data from path.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws PathException This exception is thrown in case the info file path doesn't exist.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function load() /* : void */
|
||||||
|
{
|
||||||
|
if(!file_exists($this->extractPath)) {
|
||||||
|
throw new PathException($this->extractPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info = json_decode(file_get_contents($this->extractPath . '/info.json'), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate package integrity
|
||||||
|
*
|
||||||
|
* @return bool Returns true if the package is authentic, false otherwise
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function isValid() : bool
|
||||||
|
{
|
||||||
|
return $this->authenticate(file_get_contents($this->extractPath . '/package.cert'), $this->hashFiles());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hash array of files
|
||||||
|
*
|
||||||
|
* @param array $files Files to hash
|
||||||
|
*
|
||||||
|
* @return string Hash value of files
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function hashFiles(array $files) : string
|
||||||
|
{
|
||||||
|
$files = Directory::list($this->extractPath . '/package');
|
||||||
|
$state = \sodium_crypto_generichash_init();
|
||||||
|
|
||||||
|
foreach($files as $file) {
|
||||||
|
if($file === 'package.cert') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
\sodium_crypto_generichash_update($state, file_get_contents($this->extractPath . '/package/' . $file));
|
||||||
|
}
|
||||||
|
|
||||||
|
return \sodium_crypto_generichash_final();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install package
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function install() /* : void */
|
||||||
|
{
|
||||||
|
if(!$this->isValid()) {
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->info as $key => $components) {
|
||||||
|
if(function_exists($this->{$key})) {
|
||||||
|
$this->{$key}($components);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move files
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function move($components)
|
||||||
|
{
|
||||||
|
foreach($components as $component) {
|
||||||
|
LocalStorage::move($this->basePath . '/' . $component['from'], $this->basePath . '/' . $component['to'], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy files
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function copy($components)
|
||||||
|
{
|
||||||
|
foreach($components as $component) {
|
||||||
|
if(StringUtils::startsWith($component['from'], 'Package/')) {
|
||||||
|
LocalStorage::copy($this->path . '/' . $component['from'], $this->basePath . '/' . $component['to'], true);
|
||||||
|
} else {
|
||||||
|
LocalStorage::copy($this->basePath . '/' . $component['from'], $this->basePath . '/' . $component['to'], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete files
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function delete($components)
|
||||||
|
{
|
||||||
|
foreach($components as $component) {
|
||||||
|
LocalStorage::delete($this->basePath . '/' . $component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute commands
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function execute($components)
|
||||||
|
{
|
||||||
|
foreach($components as $component) {
|
||||||
|
include $this->basePath . '/' . $component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleanup after installation
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function cleanup()
|
||||||
|
{
|
||||||
|
File::delete($this->path);
|
||||||
|
Directory::delete($this->extractPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authenticate package
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function authenticate(string $signedHash, string $rawHash) : bool
|
||||||
|
{
|
||||||
|
// https://3v4l.org/PN9Xl
|
||||||
|
$publicKey = 'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAjr73rerPRq3ZwWmrUKsN
|
||||||
|
Bjg8Wy5lnyWu9HCRQz0fix6grz+NOOsr4m/jazB2knfdtn7fi5XifbIbmrNJY8e6
|
||||||
|
musCJ0FTgJPVBqVk7XAFVSRe2gUaCPZrTPtfZ00C3cynjwTlxSdjNtU9N0ZAo17s
|
||||||
|
VWghH8ki4T2d5Mg1erGOtMJzp5yw47UHUa+KbxUmUV25WMcRYyi7+itD2xANF2AE
|
||||||
|
+PQZT1dSEU8++NI+zT6tXD/Orv5ikk0whoVqvo6duWejx5n5cpJB4EiMo4Q7epbw
|
||||||
|
9uMo9uIKqgQ9y3KdT36GBQkBErFf1dhf8KYJBGYMhO1UJE11dY3XrA7Ij1+zK+ai
|
||||||
|
duQHOc5EMClUGZQzCJAIU5lj4WEHQ4Lo0gop+fx9hzuBTDxdyOjWSJzkqyuWMkq3
|
||||||
|
zEpRBay785iaglaue9XDLee58wY+toiGLBfXe73gsbDqDSOll+cQYNjrronVN7sU
|
||||||
|
Dc2WyTIVW1Z8KFwK10D3SW0oEylCaGLtClyyihuW7JPu/8Or1Zjf87W82XTm31Fp
|
||||||
|
YkRgoEMDtVHZq0N2eHpLz1L8zKyT0ogZYN5eH5VlGrPcpwbAludNKlgAJ0hrgED1
|
||||||
|
9YsCBLwJQpFa4VZP7A5a/Qcw8EFAvNkgaPpBbAAtWoDbyOQsez6Jsdan/enfZ18+
|
||||||
|
LL7qOB5oFFM/pKlTIeVS+UsCAwEAAQ==';
|
||||||
|
$unsignedHash = \sodium_crypto_sign_open($signedHash, $publicKey);
|
||||||
|
|
||||||
|
return $unsignedHash === $rawHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,6 @@ interface SocketInterface
|
||||||
* @param int $port Port
|
* @param int $port Port
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
*/
|
||||||
public function create(string $ip, int $port);
|
public function create(string $ip, int $port);
|
||||||
|
|
||||||
|
|
@ -42,7 +41,6 @@ interface SocketInterface
|
||||||
* Close socket.
|
* Close socket.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
*/
|
||||||
public function close();
|
public function close();
|
||||||
|
|
||||||
|
|
@ -50,7 +48,6 @@ interface SocketInterface
|
||||||
* Run socket.
|
* Run socket.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
*/
|
||||||
public function run();
|
public function run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ use phpOMS\Validation\Finance\IbanEnum;
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @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
|
class Iban implements \Serializable
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get location id
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -111,6 +113,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get location type
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -120,12 +124,23 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set location type
|
||||||
|
*
|
||||||
|
* @param int $type Location type
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function setType(int $type) /* : void */
|
public function setType(int $type) /* : void */
|
||||||
{
|
{
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get postal or zip code
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -136,6 +151,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set postal or zip code
|
||||||
|
*
|
||||||
* @param string $postal
|
* @param string $postal
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -148,6 +165,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get city name
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -158,6 +177,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set city name
|
||||||
|
*
|
||||||
* @param string $city
|
* @param string $city
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -170,6 +191,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get country code
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -180,6 +203,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set country code
|
||||||
|
*
|
||||||
* @param string $country
|
* @param string $country
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -192,6 +217,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get address
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -202,6 +229,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set address
|
||||||
|
*
|
||||||
* @param string $address
|
* @param string $address
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -214,6 +243,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get state name
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -224,6 +255,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set state name
|
||||||
|
*
|
||||||
* @param string $state
|
* @param string $state
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
@ -236,6 +269,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get geo location
|
||||||
|
*
|
||||||
* @return float[]
|
* @return float[]
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -246,6 +281,8 @@ class Location implements \JsonSerializable, \Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Set geo location
|
||||||
|
*
|
||||||
* @param float[] $geo
|
* @param float[] $geo
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class SmartDateTime extends \DateTime
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @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());
|
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
|
* Test year if leap year in gregorian calendar
|
||||||
*
|
*
|
||||||
|
* @param int $year Year to check
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ interface ContainerInterface
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string;
|
public static function permission(string $path) : int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the parent path of the resource.
|
* Get the parent path of the resource.
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class ContentPutMode extends Enum
|
abstract class ContentPutMode extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const APPEND = 1;
|
/* public */ const APPEND = 1;
|
||||||
/* public */ const PREPEND = 2;
|
/* public */ const PREPEND = 2;
|
||||||
/* public */ const REPLACE = 4;
|
/* public */ const REPLACE = 4;
|
||||||
/* public */ const CREATE = 8;
|
/* public */ const CREATE = 8;
|
||||||
}
|
}
|
||||||
|
|
@ -30,14 +30,14 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class ExtensionType extends Enum
|
abstract class ExtensionType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const UNKNOWN = 1;
|
/* public */ const UNKNOWN = 1;
|
||||||
/* public */ const CODE = 2;
|
/* public */ const CODE = 2;
|
||||||
/* public */ const AUDIO = 4;
|
/* public */ const AUDIO = 4;
|
||||||
/* public */ const VIDEO = 8;
|
/* public */ const VIDEO = 8;
|
||||||
/* public */ const TEXT = 16;
|
/* public */ const TEXT = 16;
|
||||||
/* public */ const SPREADSHEET = 32;
|
/* public */ const SPREADSHEET = 32;
|
||||||
/* public */ const PDF = 64;
|
/* public */ const PDF = 64;
|
||||||
/* public */ const ARCHIVE = 128;
|
/* public */ const ARCHIVE = 128;
|
||||||
/* public */ const PRESENTATION = 256;
|
/* public */ const PRESENTATION = 256;
|
||||||
/* public */ const IMAGE = 512;
|
/* public */ const IMAGE = 512;
|
||||||
}
|
}
|
||||||
|
|
@ -26,21 +26,36 @@ namespace phpOMS\System\File;
|
||||||
*/
|
*/
|
||||||
class FileUtils
|
class FileUtils
|
||||||
{
|
{
|
||||||
/* public */ const CODE_EXTENSION = ['cpp', 'c', 'h', 'hpp', 'cs', 'css', 'htm', 'html', 'php', 'rb'];
|
/* public */ const CODE_EXTENSION = ['cpp', 'c', 'h', 'hpp', 'cs', 'css', 'htm', 'html', 'php', 'rb'];
|
||||||
/* public */ const TEXT_EXTENSION = ['doc', 'docx', 'txt', 'md', 'csv'];
|
/* public */ const TEXT_EXTENSION = ['doc', 'docx', 'txt', 'md', 'csv'];
|
||||||
/* public */ const PRESENTATION_EXTENSION = ['ppt', 'pptx'];
|
/* public */ const PRESENTATION_EXTENSION = ['ppt', 'pptx'];
|
||||||
/* public */ const PDF_EXTENSION = ['pdf'];
|
/* public */ const PDF_EXTENSION = ['pdf'];
|
||||||
/* public */ const ARCHIVE_EXTENSION = ['zip', '7z', 'rar'];
|
/* public */ const ARCHIVE_EXTENSION = ['zip', '7z', 'rar'];
|
||||||
/* public */ const AUDIO_EXTENSION = ['mp3', 'wav'];
|
/* public */ const AUDIO_EXTENSION = ['mp3', 'wav'];
|
||||||
/* public */ const VIDEO_EXTENSION = ['mp4'];
|
/* public */ const VIDEO_EXTENSION = ['mp4'];
|
||||||
/* public */ const SPREADSHEET_EXTENSION = ['xls', 'xlsm'];
|
/* public */ const SPREADSHEET_EXTENSION = ['xls', 'xlsm'];
|
||||||
/* public */ const IMAGE_EXTENSION = ['png', 'gif', 'jpg', 'jpeg', 'tiff', 'bmp'];
|
/* public */ const IMAGE_EXTENSION = ['png', 'gif', 'jpg', 'jpeg', 'tiff', 'bmp'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
private function __construct()
|
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
|
public static function getExtensionType(string $extension) : int
|
||||||
{
|
{
|
||||||
$extension = strtolower($extension);
|
$extension = strtolower($extension);
|
||||||
|
|
@ -67,4 +82,41 @@ class FileUtils
|
||||||
|
|
||||||
return ExtensionType::UNKNOWN;
|
return ExtensionType::UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make file path absolute
|
||||||
|
*
|
||||||
|
* @param string $origPath File path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function absolute(string $origPath) : string
|
||||||
|
{
|
||||||
|
if(!file_exists($origPath)) {
|
||||||
|
$startsWithSlash = strpos($origPath, '/') === 0 ? '/' : '';
|
||||||
|
|
||||||
|
$path = [];
|
||||||
|
$parts = explode('/', $origPath);
|
||||||
|
|
||||||
|
foreach($parts as $part) {
|
||||||
|
if (empty($part) || $part === '.') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($part !== '..') {
|
||||||
|
$path[] = $part;
|
||||||
|
} elseif (!empty($path)) {
|
||||||
|
array_pop($path);
|
||||||
|
} else {
|
||||||
|
throw new PathException($origPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $startsWithSlash . implode('/', $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return realpath($origPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +96,7 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement permission() method.
|
// TODO: Implement permission() method.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,9 +192,9 @@ class File extends FileAbstract implements FileInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
return self::parseFtpFileData($path)['permission'] ?? '';
|
return (int) self::parseFtpFileData($path)['permission'] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function parseFtpFileData(string $path) : array
|
private static function parseFtpFileData(string $path) : array
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,19 @@ class FtpStorage extends StorageAbstract
|
||||||
{
|
{
|
||||||
private $con = null;
|
private $con = null;
|
||||||
|
|
||||||
public function __construct(string $uri, int $port = 21, bool $mode = true, string $login = null, string $pass = null, bool $ssl = false)
|
private static $instance = null;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance() : StorageAbstract
|
||||||
{
|
{
|
||||||
$this->connect($uri, $port = 21, $mode, $login = null, $pass = null, $ssl = false);
|
if(!isset(self::$instance)) {
|
||||||
|
self::$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connect(string $uri, int $port = 21, bool $mode = true, string $login = null, string $pass = null, bool $ssl = false) : bool
|
public function connect(string $uri, int $port = 21, bool $mode = true, string $login = null, string $pass = null, bool $ssl = false) : bool
|
||||||
|
|
@ -87,7 +97,7 @@ class FtpStorage extends StorageAbstract
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement permission() method.
|
// TODO: Implement permission() method.
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +174,30 @@ class FtpStorage extends StorageAbstract
|
||||||
// TODO: Implement basename() method.
|
// TODO: Implement basename() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirname(string $path) : string
|
||||||
|
{
|
||||||
|
// TODO: Implement basename() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirpath(string $path) : string
|
||||||
|
{
|
||||||
|
// TODO: Implement basename() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function list(string $path, string $filter = '*') : array
|
||||||
|
{
|
||||||
|
// TODO: Implement basename() method.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all files in directorz.
|
* List all files in directory.
|
||||||
*
|
*
|
||||||
* @param string $path Path
|
* @param string $path Path
|
||||||
* @param string $filter Filter
|
* @param string $filter Filter
|
||||||
|
|
@ -79,10 +79,45 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function list(string $path, string $filter = '*') : array
|
public static function list(string $path, string $filter = '*') : array
|
||||||
{
|
{
|
||||||
$list = [];
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (glob($path . DIRECTORY_SEPARATOR . $filter) as $filename) {
|
$list = [];
|
||||||
$list[] = $filename;
|
$path = rtrim($path, '\\/');
|
||||||
|
|
||||||
|
foreach ($iterator = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST) as $item
|
||||||
|
) {
|
||||||
|
$list[] = str_replace('\\', '/', $iterator->getSubPathName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List all files by extension directory.
|
||||||
|
*
|
||||||
|
* @param string $path Path
|
||||||
|
* @param string $extension Extension
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function listByExtension(string $path, string $extension) : array
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
$path = rtrim($path, '\\/');
|
||||||
|
|
||||||
|
foreach ($iterator = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST) as $item
|
||||||
|
) {
|
||||||
|
if($item->getExtension() === $extension) {
|
||||||
|
$list[] = str_replace('\\', '/', $iterator->getSubPathName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
@ -121,6 +156,10 @@ 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)) {
|
||||||
|
throw new PathException($dir);
|
||||||
|
}
|
||||||
|
|
||||||
$countSize = 0;
|
$countSize = 0;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
|
|
@ -147,11 +186,16 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function count(string $path, bool $recursive = true, array $ignore = ['.', '..', 'cgi-bin',
|
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
|
||||||
'.DS_Store']) : int
|
|
||||||
{
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
$size = 0;
|
$size = 0;
|
||||||
$files = scandir($path);
|
$files = scandir($path);
|
||||||
|
$ignore[] = '.';
|
||||||
|
$ignore[] = '..';
|
||||||
|
|
||||||
foreach ($files as $t) {
|
foreach ($files as $t) {
|
||||||
if (in_array($t, $ignore)) {
|
if (in_array($t, $ignore)) {
|
||||||
|
|
@ -174,10 +218,6 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function delete(string $path) : bool
|
public static function delete(string $path) : bool
|
||||||
{
|
{
|
||||||
if (!file_exists($path) || !is_dir($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$files = scandir($path);
|
$files = scandir($path);
|
||||||
|
|
||||||
/* Removing . and .. */
|
/* Removing . and .. */
|
||||||
|
|
@ -185,10 +225,10 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
unset($files[0]);
|
unset($files[0]);
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (is_dir($file)) {
|
if (is_dir($path . '/' . $file)) {
|
||||||
self::delete($file);
|
self::delete($path . '/' . $file);
|
||||||
} else {
|
} else {
|
||||||
unlink($file);
|
unlink($path . '/' . $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -215,10 +255,7 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
public static function created(string $path) : \DateTime
|
public static function created(string $path) : \DateTime
|
||||||
{
|
{
|
||||||
if(!file_exists($path)) {
|
if(!file_exists($path)) {
|
||||||
$created = new \DateTime();
|
throw new PathException($path);
|
||||||
$created->setTimestamp(0);
|
|
||||||
|
|
||||||
return $created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$created = new \DateTime('now');
|
$created = new \DateTime('now');
|
||||||
|
|
@ -232,7 +269,14 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function changed(string $path) : \DateTime
|
public static function changed(string $path) : \DateTime
|
||||||
{
|
{
|
||||||
// TODO: Implement changed() method.
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = new \DateTime();
|
||||||
|
$changed->setTimestamp(filectime($path));
|
||||||
|
|
||||||
|
return $changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -240,15 +284,23 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function owner(string $path) : int
|
public static function owner(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement owner() method.
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileowner($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement permission() method.
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileperms($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -256,7 +308,32 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement copy() method.
|
if (!is_dir($from)) {
|
||||||
|
throw new PathException($from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$overwrite && file_exists($to)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($to)) {
|
||||||
|
self::create($to, 0644, true);
|
||||||
|
} elseif($overwrite && file_exists($to)) {
|
||||||
|
self::delete($to);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($iterator = new \RecursiveIteratorIterator(
|
||||||
|
new \RecursiveDirectoryIterator($from, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||||
|
\RecursiveIteratorIterator::SELF_FIRST) as $item
|
||||||
|
) {
|
||||||
|
if ($item->isDir()) {
|
||||||
|
mkdir($to . '/' . $iterator->getSubPathName());
|
||||||
|
} else {
|
||||||
|
copy($from . '/' . $iterator->getSubPathName(), $to . '/' . $iterator->getSubPathName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -264,7 +341,23 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
*/
|
*/
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement move() method.
|
if (!is_dir($from)) {
|
||||||
|
throw new PathException($from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$overwrite && file_exists($to)) {
|
||||||
|
return false;
|
||||||
|
} elseif($overwrite && file_exists($to)) {
|
||||||
|
self::delete($to);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!self::exists(self::parent($to))) {
|
||||||
|
self::create(self::parent($to), 0644, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename($from, $to);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -307,6 +400,10 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
public static function create(string $path, int $permission = 0644, bool $recursive = false) : bool
|
public static function create(string $path, int $permission = 0644, bool $recursive = false) : bool
|
||||||
{
|
{
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
|
if(!$recursive && !file_exists(self::parent($path))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
mkdir($path, $permission, $recursive);
|
mkdir($path, $permission, $recursive);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -414,6 +511,22 @@ class Directory extends FileAbstract implements DirectoryInterface
|
||||||
return basename($path);
|
return basename($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirname(string $path) : string
|
||||||
|
{
|
||||||
|
return basename($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirpath(string $path) : string
|
||||||
|
{
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool
|
public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool
|
||||||
{
|
{
|
||||||
// todo: create all else cases, right now all getting handled the same way which is wrong
|
|
||||||
$exists = file_exists($path);
|
$exists = file_exists($path);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
@ -75,11 +74,17 @@ class File extends FileAbstract implements FileInterface
|
||||||
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|
||||||
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
|
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
|
||||||
) {
|
) {
|
||||||
if (!Directory::exists(dirname($path))) {
|
if(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) {
|
||||||
Directory::create(dirname($path), 0644, true);
|
file_put_contents($path, file_get_contents($path) . $content);
|
||||||
}
|
} elseif(($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) {
|
||||||
|
file_put_contents($path, $content . file_get_contents($path));
|
||||||
|
} else {
|
||||||
|
if (!Directory::exists(dirname($path))) {
|
||||||
|
Directory::create(dirname($path), 0644, true);
|
||||||
|
}
|
||||||
|
|
||||||
file_put_contents($path, $content);
|
file_put_contents($path, $content);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -99,6 +104,14 @@ class File extends FileAbstract implements FileInterface
|
||||||
return file_get_contents($path);
|
return file_get_contents($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -204,7 +217,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path)) {
|
||||||
throw new PathException($path);
|
throw new PathException($path);
|
||||||
|
|
@ -246,7 +259,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
if (!file_exists($from)) {
|
if (!is_file($from)) {
|
||||||
throw new PathException($from);
|
throw new PathException($from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,6 +268,10 @@ class File extends FileAbstract implements FileInterface
|
||||||
Directory::create(dirname($to), 0644, true);
|
Directory::create(dirname($to), 0644, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($overwrite && file_exists($to)) {
|
||||||
|
unlink($to);
|
||||||
|
}
|
||||||
|
|
||||||
copy($from, $to);
|
copy($from, $to);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -268,7 +285,7 @@ class File extends FileAbstract implements FileInterface
|
||||||
*/
|
*/
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
if (!file_exists($from)) {
|
if (!is_file($from)) {
|
||||||
throw new PathException($from);
|
throw new PathException($from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,6 +294,10 @@ class File extends FileAbstract implements FileInterface
|
||||||
Directory::create(dirname($to), 0644, true);
|
Directory::create(dirname($to), 0644, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($overwrite && file_exists($to)) {
|
||||||
|
unlink($to);
|
||||||
|
}
|
||||||
|
|
||||||
rename($from, $to);
|
rename($from, $to);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\System\File\Local;
|
namespace phpOMS\System\File\Local;
|
||||||
use phpOMS\System\File\ContainerInterface;
|
use phpOMS\System\File\ContainerInterface;
|
||||||
use phpOMS\System\File\StorageAbstract;
|
use phpOMS\System\File\StorageAbstract;
|
||||||
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filesystem class.
|
* Filesystem class.
|
||||||
|
|
@ -30,12 +31,32 @@ use phpOMS\System\File\StorageAbstract;
|
||||||
*/
|
*/
|
||||||
class LocalStorage extends StorageAbstract
|
class LocalStorage extends StorageAbstract
|
||||||
{
|
{
|
||||||
|
private static $instance = null;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getInstance() : StorageAbstract
|
||||||
|
{
|
||||||
|
if(!isset(self::$instance)) {
|
||||||
|
self::$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getClassType(string $path) : string
|
||||||
|
{
|
||||||
|
return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function created(string $path) : \DateTime
|
public static function created(string $path) : \DateTime
|
||||||
{
|
{
|
||||||
// TODO: Implement created() method.
|
return self::getClassType($path)::created($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,7 +64,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function changed(string $path) : \DateTime
|
public static function changed(string $path) : \DateTime
|
||||||
{
|
{
|
||||||
// TODO: Implement changed() method.
|
return self::getClassType($path)::changed($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -51,15 +72,15 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function owner(string $path) : int
|
public static function owner(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement owner() method.
|
return self::getClassType($path)::owner($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public static function permission(string $path) : string
|
public static function permission(string $path) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement permission() method.
|
return self::getClassType($path)::permission($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -67,7 +88,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function parent(string $path) : string
|
public static function parent(string $path) : string
|
||||||
{
|
{
|
||||||
// TODO: Implement parent() method.
|
return self::getClassType($path)::parent($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,7 +96,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function create(string $path) : bool
|
public static function create(string $path) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement create() method.
|
return stripos($path, '.') === false ? Directory::create($path, 0644, true) : File::create($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -83,7 +104,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function delete(string $path) : bool
|
public static function delete(string $path) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement delete() method.
|
return self::getClassType($path)::delete($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -91,7 +112,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement copy() method.
|
return self::getClassType($from)::copy($from, $to, $overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -99,7 +120,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement move() method.
|
return self::getClassType($from)::move($from, $to, $overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,7 +128,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function size(string $path, bool $recursive = true) : int
|
public static function size(string $path, bool $recursive = true) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement size() method.
|
return self::getClassType($path)::size($path, $recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -115,7 +136,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function exists(string $path) : bool
|
public static function exists(string $path) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement exists() method.
|
return self::getClassType($path)::exists($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -123,7 +144,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function name(string $path) : string
|
public static function name(string $path) : string
|
||||||
{
|
{
|
||||||
// TODO: Implement name() method.
|
return self::getClassType($path)::name($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -131,7 +152,23 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function basename(string $path) : string
|
public static function basename(string $path) : string
|
||||||
{
|
{
|
||||||
// TODO: Implement basename() method.
|
return self::getClassType($path)::basename($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirname(string $path) : string
|
||||||
|
{
|
||||||
|
return self::getClassType($path)::dirname($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function dirpath(string $path) : string
|
||||||
|
{
|
||||||
|
return self::getClassType($path)::dirpath($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -139,237 +176,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
|
public static function count(string $path, bool $recursive = true, array $ignore = []) : int
|
||||||
{
|
{
|
||||||
// TODO: Implement count() method.
|
return self::getClassType($path)::count($path, $recursive, $ignore);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getCount(bool $recursive = false) : int
|
|
||||||
{
|
|
||||||
// TODO: Implement getCount() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getSize(bool $recursive = false) : int
|
|
||||||
{
|
|
||||||
// TODO: Implement getSize() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getName() : string
|
|
||||||
{
|
|
||||||
// TODO: Implement getName() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getPath() : string
|
|
||||||
{
|
|
||||||
// TODO: Implement getPath() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getParent() : ContainerInterface
|
|
||||||
{
|
|
||||||
// TODO: Implement getParent() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function createNode() : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement createNode() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function copyNode(string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement copyNode() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function moveNode(string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement moveNode() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function deleteNode() : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement deleteNode() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getCreatedAt() : \DateTime
|
|
||||||
{
|
|
||||||
// TODO: Implement getCreatedAt() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getChangedAt() : \DateTime
|
|
||||||
{
|
|
||||||
// TODO: Implement getChangedAt() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getOwner() : int
|
|
||||||
{
|
|
||||||
// TODO: Implement getOwner() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getPermission() : string
|
|
||||||
{
|
|
||||||
// TODO: Implement getPermission() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
// TODO: Implement index() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current element
|
|
||||||
* @link http://php.net/manual/en/iterator.current.php
|
|
||||||
* @return mixed Can return any type.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
// TODO: Implement current() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move forward to next element
|
|
||||||
* @link http://php.net/manual/en/iterator.next.php
|
|
||||||
* @return void Any returned value is ignored.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
// TODO: Implement next() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the key of the current element
|
|
||||||
* @link http://php.net/manual/en/iterator.key.php
|
|
||||||
* @return mixed scalar on success, or null on failure.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
// TODO: Implement key() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if current position is valid
|
|
||||||
* @link http://php.net/manual/en/iterator.valid.php
|
|
||||||
* @return boolean The return value will be casted to boolean and then evaluated.
|
|
||||||
* Returns true on success or false on failure.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
// TODO: Implement valid() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rewind the Iterator to the first element
|
|
||||||
* @link http://php.net/manual/en/iterator.rewind.php
|
|
||||||
* @return void Any returned value is ignored.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
// TODO: Implement rewind() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether a offset exists
|
|
||||||
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
|
|
||||||
* @param mixed $offset <p>
|
|
||||||
* An offset to check for.
|
|
||||||
* </p>
|
|
||||||
* @return boolean true on success or false on failure.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* The return value will be casted to boolean if non-boolean was returned.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function offsetExists($offset)
|
|
||||||
{
|
|
||||||
// TODO: Implement offsetExists() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Offset to retrieve
|
|
||||||
* @link http://php.net/manual/en/arrayaccess.offsetget.php
|
|
||||||
* @param mixed $offset <p>
|
|
||||||
* The offset to retrieve.
|
|
||||||
* </p>
|
|
||||||
* @return mixed Can return all value types.
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function offsetGet($offset)
|
|
||||||
{
|
|
||||||
// TODO: Implement offsetGet() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Offset to set
|
|
||||||
* @link http://php.net/manual/en/arrayaccess.offsetset.php
|
|
||||||
* @param mixed $offset <p>
|
|
||||||
* The offset to assign the value to.
|
|
||||||
* </p>
|
|
||||||
* @param mixed $value <p>
|
|
||||||
* The value to set.
|
|
||||||
* </p>
|
|
||||||
* @return void
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function offsetSet($offset, $value)
|
|
||||||
{
|
|
||||||
// TODO: Implement offsetSet() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Offset to unset
|
|
||||||
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
|
|
||||||
* @param mixed $offset <p>
|
|
||||||
* The offset to unset.
|
|
||||||
* </p>
|
|
||||||
* @return void
|
|
||||||
* @since 5.0.0
|
|
||||||
*/
|
|
||||||
public function offsetUnset($offset)
|
|
||||||
{
|
|
||||||
// TODO: Implement offsetUnset() method.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -377,7 +184,11 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function put(string $path, string $content, int $mode = 0) : bool
|
public static function put(string $path, string $content, int $mode = 0) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement put() method.
|
if(is_dir($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File::put($path, $content, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -385,23 +196,23 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function get(string $path) : string
|
public static function get(string $path) : string
|
||||||
{
|
{
|
||||||
// TODO: Implement get() method.
|
if(is_dir($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File::get($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function putContent(string $content, int $mode = 0) : bool
|
public static function list(string $path, string $filter = '*') : array
|
||||||
{
|
{
|
||||||
// TODO: Implement putContent() method.
|
if(is_file($path)) {
|
||||||
}
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return Directory::list($path, $filter);
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getContent() : string
|
|
||||||
{
|
|
||||||
// TODO: Implement getContent() method.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -409,23 +220,7 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function sanitize(string $path, string $replace = '') : string
|
public static function sanitize(string $path, string $replace = '') : string
|
||||||
{
|
{
|
||||||
// TODO: Implement sanitize() method.
|
return self::getClassType($path)::sanitize($path, $replace);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getNode(string $name)
|
|
||||||
{
|
|
||||||
// TODO: Implement getNode() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function addNode($file) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement addNode() method.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -433,7 +228,11 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function set(string $path, string $content) : bool
|
public static function set(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement set() method.
|
if(is_dir($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File::set($path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -441,7 +240,11 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function append(string $path, string $content) : bool
|
public static function append(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement append() method.
|
if(is_dir($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File::append($path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -449,7 +252,11 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function prepend(string $path, string $content) : bool
|
public static function prepend(string $path, string $content) : bool
|
||||||
{
|
{
|
||||||
// TODO: Implement prepend() method.
|
if(is_dir($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return File::prepend($path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -457,38 +264,10 @@ class LocalStorage extends StorageAbstract
|
||||||
*/
|
*/
|
||||||
public static function extension(string $path) : string
|
public static function extension(string $path) : string
|
||||||
{
|
{
|
||||||
// TODO: Implement extension() method.
|
if(is_dir($path)) {
|
||||||
}
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
return File::extension($path);
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setContent(string $content) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement setContent() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function appendContent(string $content) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement appendContent() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function prependContent(string $content) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement prependContent() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getExtension() : string
|
|
||||||
{
|
|
||||||
// TODO: Implement getExtension() method.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +40,7 @@ final class Storage
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -73,6 +74,7 @@ final class Storage
|
||||||
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
|
$env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
/** @var StorageAbstract $env */
|
||||||
$env = $env::getInstance();
|
$env = $env::getInstance();
|
||||||
|
|
||||||
self::$registered[$stg] = $env;
|
self::$registered[$stg] = $env;
|
||||||
|
|
|
||||||
|
|
@ -26,16 +26,8 @@ namespace phpOMS\System\File;
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
abstract class StorageAbstract
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Singleton instance.
|
|
||||||
*
|
|
||||||
* @var StorageAbstract
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected static $instance = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage type.
|
* Storage type.
|
||||||
*
|
*
|
||||||
|
|
@ -48,6 +40,7 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -62,13 +55,8 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
||||||
*/
|
*/
|
||||||
public static function getInstance() : StorageAbstract
|
public static function getInstance() : StorageAbstract
|
||||||
{
|
{
|
||||||
if(!isset(static::$instance)) {
|
return null;
|
||||||
static::$instance = new static();
|
|
||||||
}
|
|
||||||
|
|
||||||
return static::$instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get storage type.
|
* Get storage type.
|
||||||
*
|
*
|
||||||
|
|
@ -80,4 +68,124 @@ abstract class StorageAbstract implements DirectoryInterface, FileInterface
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function created(string $path) : \DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function changed(string $path) : \DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function owner(string $path) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function permission(string $path) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function parent(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function create(string $path) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function delete(string $path) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function size(string $path, bool $recursive = true) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function exists(string $path) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function name(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function basename(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function dirname(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function dirpath(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function list(string $path, string $filter = '*') : array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function count(string $path, bool $recursive = true, array $ignore = []) : int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function put(string $path, string $content, int $mode = 0) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function get(string $path) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function sanitize(string $path, string $replace = '') : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function set(string $path, string $content) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function append(string $path, string $content) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function prepend(string $path, string $content) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public abstract static function extension(string $path) : string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class SystemType extends Enum
|
abstract class SystemType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const UNKNOWN = 1;
|
/* public */ const UNKNOWN = 1;
|
||||||
/* public */ const WIN = 2;
|
/* public */ const WIN = 2;
|
||||||
/* public */ const LINUX = 3;
|
/* public */ const LINUX = 3;
|
||||||
/* public */ const OSX = 4;
|
/* public */ const OSX = 4;
|
||||||
}
|
}
|
||||||
|
|
@ -31,6 +31,7 @@ class SystemUtils
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ final class UnhandledHandler
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public static function exceptionHandler(\Throwable $e) /* : void */
|
public static function exceptionHandler(\Throwable $e) /* : void */
|
||||||
{
|
{
|
||||||
|
|
@ -60,12 +61,21 @@ final class UnhandledHandler
|
||||||
*/
|
*/
|
||||||
public static function errorHandler(int $errno, string $errstr, string $errfile, int $errline) : bool
|
public static function errorHandler(int $errno, string $errstr, string $errfile, int $errline) : bool
|
||||||
{
|
{
|
||||||
|
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||||
|
|
||||||
if (!(error_reporting() & $errno)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
|
||||||
$logger->error(FileLogger::MSG_FULL, [
|
$logger->error(FileLogger::MSG_FULL, [
|
||||||
'message' => 'Unhandled error',
|
'message' => 'Unhandled error',
|
||||||
'line' => $errline,
|
'line' => $errline,
|
||||||
|
|
@ -83,6 +93,7 @@ final class UnhandledHandler
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public static function shutdownHandler() /* : void */
|
public static function shutdownHandler() /* : void */
|
||||||
{
|
{
|
||||||
|
|
|
||||||
31
Uri/Http.php
31
Uri/Http.php
|
|
@ -158,7 +158,7 @@ class Http implements UriInterface
|
||||||
$this->path = substr($this->path, 0, -4);
|
$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'] ?? '';
|
$this->queryString = $url['query'] ?? '';
|
||||||
|
|
||||||
if (!empty($this->queryString)) {
|
if (!empty($this->queryString)) {
|
||||||
|
|
@ -278,19 +278,6 @@ class Http implements UriInterface
|
||||||
return $this->path . (!empty($query) ? '?' . $this->getQuery() : '');
|
return $this->path . (!empty($query) ? '?' . $this->getQuery() : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getPathElement(int $pos = null) : string
|
|
||||||
{
|
|
||||||
return explode('/', $this->path)[$pos];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPathElements() : array
|
|
||||||
{
|
|
||||||
return explode('/', $this->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -305,6 +292,22 @@ class Http implements UriInterface
|
||||||
return $this->queryString;
|
return $this->queryString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getPathElement(int $pos = null) : string
|
||||||
|
{
|
||||||
|
return explode('/', $this->path)[$pos] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getPathElements() : array
|
||||||
|
{
|
||||||
|
return explode('/', $this->path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ class UriFactory
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,15 @@ interface UriInterface
|
||||||
*/
|
*/
|
||||||
public function getPathElement(int $pos) : string;
|
public function getPathElement(int $pos) : string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get path elements.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getPathElements() : array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get query.
|
* Get query.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -28,19 +28,19 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class UriScheme extends Enum
|
abstract class UriScheme extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const HTTP = 0; /* Http */
|
/* public */ const HTTP = 0; /* Http */
|
||||||
/* public */ const FILE = 1; /* File */
|
/* public */ const FILE = 1; /* File */
|
||||||
/* public */ const MAILTO = 2; /* Mail */
|
/* public */ const MAILTO = 2; /* Mail */
|
||||||
/* public */ const FTP = 3; /* FTP */
|
/* public */ const FTP = 3; /* FTP */
|
||||||
/* public */ const HTTPS = 4; /* Https */
|
/* public */ const HTTPS = 4; /* Https */
|
||||||
/* public */ const IRC = 5; /* IRC */
|
/* public */ const IRC = 5; /* IRC */
|
||||||
/* public */ const TEL = 6; /* Telephone */
|
/* public */ const TEL = 6; /* Telephone */
|
||||||
/* public */ const TELNET = 7; /* Telnet */
|
/* public */ const TELNET = 7; /* Telnet */
|
||||||
/* public */ const SSH = 8; /* SSH */
|
/* public */ const SSH = 8; /* SSH */
|
||||||
/* public */ const SKYPE = 9; /* Skype */
|
/* public */ const SKYPE = 9; /* Skype */
|
||||||
/* public */ const SSL = 10; /* SSL */
|
/* public */ const SSL = 10; /* SSL */
|
||||||
/* public */ const NFS = 11; /* Network File System */
|
/* public */ const NFS = 11; /* Network File System */
|
||||||
/* public */ const GEO = 12; /* Geo location */
|
/* public */ const GEO = 12; /* Geo location */
|
||||||
/* public */ const MARKET = 13; /* Android Market */
|
/* public */ const MARKET = 13; /* Android Market */
|
||||||
/* public */ const ITMS = 14; /* iTunes */
|
/* public */ const ITMS = 14; /* iTunes */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class ArrayUtils
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -294,6 +295,7 @@ class ArrayUtils
|
||||||
// see collection collapse as alternative?!
|
// see collection collapse as alternative?!
|
||||||
$flat = [];
|
$flat = [];
|
||||||
$stack = array_values($array);
|
$stack = array_values($array);
|
||||||
|
|
||||||
while (!empty($stack)) {
|
while (!empty($stack)) {
|
||||||
$value = array_shift($stack);
|
$value = array_shift($stack);
|
||||||
|
|
||||||
|
|
@ -322,7 +324,6 @@ class ArrayUtils
|
||||||
{
|
{
|
||||||
$count = $count === 0 ? count($array) : $start + $count;
|
$count = $count === 0 ? count($array) : $start + $count;
|
||||||
$sum = 0;
|
$sum = 0;
|
||||||
|
|
||||||
$array = array_values($array);
|
$array = array_values($array);
|
||||||
|
|
||||||
for ($i = $start; $i <= $count - 1; $i++) {
|
for ($i = $start; $i <= $count - 1; $i++) {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*/
|
*/
|
||||||
abstract class AngleType extends Enum
|
abstract class AngleType extends Enum
|
||||||
{
|
{
|
||||||
/* public */ const DEGREE = 'º';
|
/* public */ const DEGREE = 'deg';
|
||||||
/* public */ const RADIAN = 'rad';
|
/* public */ const RADIAN = 'rad';
|
||||||
/* public */ const SECOND = 'arcsec';
|
/* public */ const SECOND = 'arcsec';
|
||||||
/* public */ const MINUTE = 'arcmin';
|
/* public */ const MINUTE = 'arcmin';
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ class Currency
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -97,7 +98,7 @@ class Currency
|
||||||
public static function getEcbEuroRates() : array
|
public static function getEcbEuroRates() : array
|
||||||
{
|
{
|
||||||
if (!isset(self::$ecbCurrencies)) {
|
if (!isset(self::$ecbCurrencies)) {
|
||||||
$request = new Request(new Localization(), new Http('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
$request = new Request(new Http('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
||||||
$request->setMethod(RequestMethod::GET);
|
$request->setMethod(RequestMethod::GET);
|
||||||
|
|
||||||
$xml = new \SimpleXMLElement(Rest::request($request));
|
$xml = new \SimpleXMLElement(Rest::request($request));
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class File
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ class Ip
|
||||||
{
|
{
|
||||||
/* public */ const IP_TABLE_ITERATIONS = 100;
|
/* public */ const IP_TABLE_ITERATIONS = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,15 @@ namespace phpOMS\Utils\Converter;
|
||||||
*/
|
*/
|
||||||
class Measurement
|
class Measurement
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert temperature.
|
* Convert temperature.
|
||||||
|
|
@ -88,7 +97,7 @@ class Measurement
|
||||||
$value = ($value - 273.15) * 1.5 - 100;
|
$value = ($value - 273.15) * 1.5 - 100;
|
||||||
break;
|
break;
|
||||||
case TemperatureType::NEWTON:
|
case TemperatureType::NEWTON:
|
||||||
$value = ($value - 273.15) / 0.33;
|
$value = ($value - 273.15) * 0.33;
|
||||||
break;
|
break;
|
||||||
case TemperatureType::ROMER:
|
case TemperatureType::ROMER:
|
||||||
$value = ($value - 273.15) * 0.525 + 7.5;
|
$value = ($value - 273.15) * 0.525 + 7.5;
|
||||||
|
|
@ -1221,7 +1230,7 @@ class Measurement
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function convertEnergie(float $value, string $from = EnergyPowerType::JOULS, string $to = EnergyPowerType::KILOWATT_HOUERS) : float
|
public static function convertEnergy(float $value, string $from = EnergyPowerType::JOULS, string $to = EnergyPowerType::KILOWATT_HOUERS) : float
|
||||||
{
|
{
|
||||||
switch ($from) {
|
switch ($from) {
|
||||||
case EnergyPowerType::JOULS:
|
case EnergyPowerType::JOULS:
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class Numeric
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +74,7 @@ class Numeric
|
||||||
$newOutput = 0;
|
$newOutput = 0;
|
||||||
|
|
||||||
for ($i = 1; $i <= $numberLen; $i++) {
|
for ($i = 1; $i <= $numberLen; $i++) {
|
||||||
$newOutput = bcadd($newOutput, bcmul(array_search($number[$i - 1], $fromBase), bcpow($fromLen, $numberLen - $i)));
|
$newOutput = bcadd((string) $newOutput, bcmul((string) array_search($number[$i - 1], $fromBase), bcpow((string) $fromLen, (string) ($numberLen - $i))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newOutput;
|
return $newOutput;
|
||||||
|
|
@ -86,8 +87,8 @@ class Numeric
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($base10 !== '0') {
|
while ($base10 !== '0') {
|
||||||
$newOutput = $toBase[bcmod($base10, $toLen)] . $newOutput;
|
$newOutput = $toBase[bcmod($base10, (string) $toLen)] . $newOutput;
|
||||||
$base10 = bcdiv($base10, $toLen, 0);
|
$base10 = bcdiv($base10, (string) $toLen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newOutput;
|
return $newOutput;
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user