diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..bf0824e59 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/Account/Account.php b/Account/Account.php index efed51bb9..82067d730 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -22,14 +21,13 @@ use phpOMS\Validation\Network\Email; /** * 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 + * 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. + * * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Account implements ArrayableInterface, \JsonSerializable @@ -136,7 +134,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Account type. * - * @var AccountType|int + * @var int * @since 1.0.0 */ protected $type = AccountType::USER; @@ -144,7 +142,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Account status. * - * @var AccountStatus|int + * @var int * @since 1.0.0 */ protected $status = AccountStatus::INACTIVE; @@ -159,7 +157,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Constructor. - * + * * The constructor automatically sets the created date as well as the last activity to now. * * @param int $id Account id @@ -168,10 +166,10 @@ class Account implements ArrayableInterface, \JsonSerializable */ public function __construct(int $id = 0) { - $this->createdAt = new \DateTime('now'); + $this->createdAt = new \DateTime('now'); $this->lastActive = new \DateTime('now'); - $this->id = $id; - $this->l11n = new NullLocalization(); + $this->id = $id; + $this->l11n = new NullLocalization(); } /** @@ -188,7 +186,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Get localization. - * + * * Every account can have a different localization which can be accessed here. * * @return Localization @@ -202,8 +200,8 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Get groups. - * - * Every account can belong to multiple 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 @@ -217,9 +215,9 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Add group. - * + * * @param mixed $group Group to add - * + * * @return void * * @since 1.0.0 @@ -245,7 +243,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Set permissions. - * + * * The method accepts an array of permissions. All existing permissions are replaced. * * @param PermissionAbstract[] $permissions @@ -261,7 +259,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Add permissions. - * + * * Adds permissions to the account * * @param PermissionAbstract[] $permissions Array of permissions to add to the account @@ -277,7 +275,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Add permission. - * + * * Adds a single permission to the account * * @param PermissionAbstract $permission Permission to add to the account @@ -293,7 +291,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Get permissions. - * + * * @return array * * @since 1.0.0 @@ -307,7 +305,7 @@ class Account implements ArrayableInterface, \JsonSerializable * 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) @@ -324,14 +322,15 @@ class Account implements ArrayableInterface, \JsonSerializable { $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()) { + 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; } } @@ -447,7 +446,7 @@ class Account implements ArrayableInterface, \JsonSerializable * @param string $email Email * * @return void - * + * * @throws \InvalidArgumentException Exception is thrown if the provided string is not a valid email * * @since 1.0.0 @@ -556,11 +555,17 @@ class Account implements ArrayableInterface, \JsonSerializable * * @return void * + * @throws \Exception + * * @since 1.0.0 */ public function generatePassword(string $password) /* : void */ { - $this->password = password_hash($password, PASSWORD_DEFAULT); + $this->password = \password_hash($password, \PASSWORD_DEFAULT); + + if ($this->password === false) { + throw new \Exception(); + } } /** @@ -625,7 +630,7 @@ class Account implements ArrayableInterface, \JsonSerializable /** * Json serialize. * - * @return string + * @return array * * @since 1.0.0 */ @@ -633,5 +638,4 @@ class Account implements ArrayableInterface, \JsonSerializable { return $this->toArray(); } - } diff --git a/Account/AccountManager.php b/Account/AccountManager.php index 8457c5e02..dc1817680 100644 --- a/Account/AccountManager.php +++ b/Account/AccountManager.php @@ -4,30 +4,27 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; use phpOMS\Auth\Auth; -use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Session\SessionInterface; /** * Account manager class. - * - * The account manager is used to manage multiple accounts. * - * @category Framework + * The account manager is used to manage multiple accounts. + * * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class AccountManager implements \Countable @@ -49,14 +46,6 @@ class AccountManager implements \Countable */ private $session = null; - /** - * Authenticator. - * - * @var Auth - * @since 1.0.0 - */ - private $auth = null; - /** * Constructor. * @@ -66,8 +55,7 @@ class AccountManager implements \Countable */ public function __construct(SessionInterface $session) { - $this->session = $session; - $this->auth = new Auth($this->session); + $this->session = $session; } /** @@ -82,7 +70,7 @@ class AccountManager implements \Countable public function get(int $id = 0) : Account { if ($id === 0) { - $account = new Account($this->auth->authenticate()); + $account = new Account(Auth::authenticate($this->session)); if (!isset($this->accounts[$account->getId()])) { $this->accounts[$account->getId()] = $account; @@ -94,18 +82,6 @@ class AccountManager implements \Countable 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. * @@ -157,5 +133,4 @@ class AccountManager implements \Countable { return count($this->accounts); } - } diff --git a/Account/AccountStatus.php b/Account/AccountStatus.php index ca92e63a9..b152ef3c7 100644 --- a/Account/AccountStatus.php +++ b/Account/AccountStatus.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Account status enum. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AccountStatus extends Enum diff --git a/Account/AccountType.php b/Account/AccountType.php index a4298d5dc..c299d4cf0 100644 --- a/Account/AccountType.php +++ b/Account/AccountType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Account type enum. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AccountType extends Enum diff --git a/Account/Group.php b/Account/Group.php index 46f58c16d..aff3c45d2 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -20,10 +19,9 @@ use phpOMS\Contract\ArrayableInterface; /** * Account group class. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Group implements ArrayableInterface, \JsonSerializable @@ -122,6 +120,8 @@ class Group implements ArrayableInterface, \JsonSerializable * Set group name. * * @param string $name Group name + * + * @return void * * @since 1.0.0 */ @@ -146,6 +146,8 @@ class Group implements ArrayableInterface, \JsonSerializable * Set group description. * * @param string $description Group description + * + * @return void * * @since 1.0.0 */ @@ -170,12 +172,19 @@ class Group implements ArrayableInterface, \JsonSerializable * Set group status. * * @param int $status Group status + * + * @return void + * + * @throws InvalidEnumValue * * @since 1.0.0 */ public function setStatus(int $status) /* : void */ { - // todo: check valid + if (!GroupStatus::isValidValue($status)) { + throw new InvalidEnumValue($status); + } + $this->status = $status; } @@ -208,7 +217,7 @@ class Group implements ArrayableInterface, \JsonSerializable /** * Json serialize. * - * @return string + * @return array * * @since 1.0.0 */ diff --git a/Account/GroupStatus.php b/Account/GroupStatus.php index 42c6ff1f1..566fa1bea 100644 --- a/Account/GroupStatus.php +++ b/Account/GroupStatus.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Accept status enum. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class GroupStatus extends Enum diff --git a/Account/NullAccount.php b/Account/NullAccount.php index 20d49d87e..af897696a 100644 --- a/Account/NullAccount.php +++ b/Account/NullAccount.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; /** * Null account class. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullAccount extends Account diff --git a/Account/PermissionAbstract.php b/Account/PermissionAbstract.php index 13a7312f6..d04f61caa 100644 --- a/Account/PermissionAbstract.php +++ b/Account/PermissionAbstract.php @@ -4,27 +4,25 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +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 + * @link http://website.orange-management.de * @since 1.0.0 */ class PermissionAbstract @@ -340,11 +338,11 @@ class PermissionAbstract * * @param int $permission Permission * - * @return void + * @return bool * * @since 1.0.0 */ - public function hasPermission(int $permission) : bool + public function hasPermission(int $permission) : bool { return ($this->permission | $permission) === $this->permission; } diff --git a/Account/PermissionType.php b/Account/PermissionType.php index 29d6059a1..0845ac1e9 100644 --- a/Account/PermissionType.php +++ b/Account/PermissionType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Account * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Account; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Permission type enum. * - * @category Framework * @package phpOMS\Account * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PermissionType extends Enum diff --git a/Algorithm/AlgorithmType.php b/Algorithm/AlgorithmType.php deleted file mode 100644 index ee1d0841d..000000000 --- a/Algorithm/AlgorithmType.php +++ /dev/null @@ -1,32 +0,0 @@ -costMaximum = $costMaximum; - } - - public function addPopulationItem(ItemInterface $item) : bool - { - if(isset($this->population[$item->getId()])) { - return false; - } - - $this->population[$item->getId()] = $item; - - return true; - } - - public function setPopulationItem(ItemInterface $item) /* : void */ - { - $this->population[$item->getId()] = $item; - } - - public function setCostCalculation(\Closure $callback) /* : void */ - { - - } - - public function setValueCalculation(\Closure $callback) /* : void */ - { - - } - - public function setTestPopulationBuilder(\Closure $callback) /* : void */ - { - - } - - public function pack(int $type) - { - switch($type) { - case AlgorithmType::BRUTEFORCE: - return $this->bruteforce(); - default: - throw new \Exception('Invalid algorithm type'); - } - } - - public function bruteforce() - { - } -} \ No newline at end of file diff --git a/Algorithm/Knappsack/ItemInterface.php b/Algorithm/Knappsack/ItemInterface.php deleted file mode 100644 index 0966fc09b..000000000 --- a/Algorithm/Knappsack/ItemInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -$name)) { + if (!empty($this->$name)) { return; } @@ -163,8 +179,8 @@ class ApplicationAbstract * * @since 1.0.0 */ - public function __get($name) - { - return $this->$name; + public function __get($name) + { + return $this->$name; } } diff --git a/Asset/AssetManager.php b/Asset/AssetManager.php index f6bb7ef07..92a6824d2 100644 --- a/Asset/AssetManager.php +++ b/Asset/AssetManager.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Asset * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Asset; /** * Asset manager class. * - * @category Framework * @package phpOMS\Asset * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class AssetManager implements \Countable @@ -115,5 +113,4 @@ class AssetManager implements \Countable { return count($this->assets); } - } diff --git a/Asset/AssetType.php b/Asset/AssetType.php index 825d958a8..39a4968b7 100644 --- a/Asset/AssetType.php +++ b/Asset/AssetType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Asset * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Asset; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Asset types enum. * - * @category Framework * @package phpOMS\Asset * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AssetType extends Enum diff --git a/Auth/Auth.php b/Auth/Auth.php index 0f1a06395..82e60cfd4 100644 --- a/Auth/Auth.php +++ b/Auth/Auth.php @@ -4,18 +4,16 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Auth * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Auth; -use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Session\SessionInterface; /** @@ -23,44 +21,35 @@ use phpOMS\DataStorage\Session\SessionInterface; * * Responsible for authenticating and initializing the connection * - * @category Framework * @package phpOMS\Auth * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Auth { - /** - * Session instance. - * - * @var SessionInterface - * @since 1.0.0 - */ - private $session = null; - /** * Constructor. * - * @param SessionInterface $session Session - * * @since 1.0.0 + * @codeCoverageIgnore */ - public function __construct(SessionInterface $session) + private function __construct() { - $this->session = $session; } /** * Authenticates user. * + * @param SessionInterface $session Session + * * @return int * * @since 1.0.0 */ - public function authenticate() : int + public static function authenticate(SessionInterface $session) : int { - $uid = $this->session->get('UID'); + $uid = $session->get('UID'); return empty($uid) ? 0 : $uid; } @@ -68,15 +57,14 @@ class Auth /** * Logout the given user. * - * @param int $uid User ID + * @param SessionInterface $session Session * * @return void * * @since 1.0.0 */ - public function logout(int $uid = null) /* : void */ + public static function logout(SessionInterface $session) /* : void */ { - // TODO: logout other users? If admin wants to kick a user for updates etc. - $this->session->remove('UID'); + $session->remove('UID'); } } diff --git a/Auth/LoginReturnType.php b/Auth/LoginReturnType.php index b18aa8db0..fe7f4062b 100644 --- a/Auth/LoginReturnType.php +++ b/Auth/LoginReturnType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Auth * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Auth; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * These are possible answers to authentications. * - * @category Framework * @package phpOMS\Auth * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class LoginReturnType extends Enum diff --git a/AutoloadException.php b/AutoloadException.php index e7ff43e8c..d11571527 100644 --- a/AutoloadException.php +++ b/AutoloadException.php @@ -4,24 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS; /** - * Permission exception class. + * Autoloader exception + * + * This exception is thrown if a file couldn't be autoloaded * - * @category Framework - * @package phpOMS\System\File + * @package phpOMS * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class AutoloadException extends \RuntimeException @@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Autoloader.php b/Autoloader.php index 8a67bc84d..445e7380c 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -4,26 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS; -spl_autoload_register('\phpOMS\Autoloader::default_autoloader'); +spl_autoload_register('\phpOMS\Autoloader::defaultAutoloader'); /** * Autoloader class. * - * @category Framework - * @package Framework + * @package phpOMS * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Autoloader @@ -34,7 +32,7 @@ class Autoloader * * @param string $class Class path * - * @example Autoloader::default_autoloader('\phpOMS\Autoloader') // void + * @example Autoloader::defaultAutoloader('\phpOMS\Autoloader') // void * * @return void * @@ -42,12 +40,12 @@ class Autoloader * * @since 1.0.0 */ - public static function default_autoloader(string $class) /* : void */ + public static function defaultAutoloader(string $class) /* : void */ { $class = ltrim($class, '\\'); $class = str_replace(['_', '\\'], '/', $class); - if(!file_exists($path = __DIR__ . '/../' . $class . '.php')) { + if (!file_exists($path = __DIR__ . '/../' . $class . '.php')) { return; } @@ -73,5 +71,4 @@ class Autoloader return file_exists(__DIR__ . '/../' . $class . '.php'); } - } diff --git a/Business/Finance/Depreciation.php b/Business/Finance/Depreciation.php index b6f89b96e..094809788 100644 --- a/Business/Finance/Depreciation.php +++ b/Business/Finance/Depreciation.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance; @@ -29,7 +28,7 @@ class Depreciation public static function getArithmeticProgressivDepreciationRate(float $start, int $duration) : float { - return $start / ($duration * ($duration+1) / 2); + return $start / ($duration * ($duration + 1) / 2); } public static function getArithmeticProgressivDepreciationInT(float $start, int $duration, int $t) : float @@ -44,7 +43,7 @@ class Depreciation public static function getGeometicProgressivDepreciationRate(float $start, float $residual, int $duration) : float { - return (1-pow($residual / $start, 1 / $duration)); + return (1 - pow($residual / $start, 1 / $duration)); } public static function getGeometicDegressivDepreciationInT(float $start, float $residual, int $duration, int $t) : float @@ -64,4 +63,4 @@ class Depreciation public static function getGeometicProgressivDepreciationResidualInT(float $start, float $residual, int $duration, int $t) : float { } -} \ No newline at end of file +} diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index c71c110ac..26e88cc3c 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance; @@ -21,11 +20,13 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Finance class. * - * @category Log - * @package Framework + * @package phpOMS\Business\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class FinanceFormulas { @@ -44,7 +45,7 @@ class FinanceFormulas */ public static function getAnnualPercentageYield(float $r, int $n) : float { - return pow(1 + $r / $n, $n) - 1; + return (float) pow(1 + $r / $n, $n) - 1; } /** @@ -61,7 +62,7 @@ class FinanceFormulas */ public static function getStateAnnualInterestRateOfAPY(float $apy, int $n) : float { - return (pow($apy + 1, 1 / $n) - 1) * $n; + return (float) (pow($apy + 1, 1 / $n) - 1) * $n; } /** @@ -112,7 +113,6 @@ class FinanceFormulas return $fva / ((pow(1 + $r, $n) - 1) / $r); } - /** * Annuity - Future Value w/ Continuous Compounding * @@ -754,6 +754,20 @@ class FinanceFormulas return log(2) / log(1 + $r); } + /** + * Get rate to dobule + * + * @param float $t Time in which to double investment + * + * @return float + * + * @since 1.0.0 + */ + public static function getDoublingRate(float $t) : float + { + return exp(log(2) / $t) - 1; + } + /** * Doubling Time - Continuous Compounding * @@ -896,7 +910,7 @@ class FinanceFormulas */ public static function getFutureValueFactor(float $r, int $n) : float { - return pow(1 + $r, $n); + return (float) pow(1 + $r, $n); } /** @@ -1392,5 +1406,4 @@ class FinanceFormulas { return $ownSales / $competitorSales; } - } diff --git a/Business/Finance/Forecasting/AR.php b/Business/Finance/Forecasting/AR.php index 33a693b69..d3c53325d 100644 --- a/Business/Finance/Forecasting/AR.php +++ b/Business/Finance/Forecasting/AR.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class AR { -} \ No newline at end of file +} diff --git a/Business/Finance/Forecasting/ARCH.php b/Business/Finance/Forecasting/ARCH.php index 4c9edf6f6..b49c2b33e 100644 --- a/Business/Finance/Forecasting/ARCH.php +++ b/Business/Finance/Forecasting/ARCH.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class ARCH { -} \ No newline at end of file +} diff --git a/Business/Finance/Forecasting/ARFIMA.php b/Business/Finance/Forecasting/ARFIMA.php index 0b674419e..4668eaf26 100644 --- a/Business/Finance/Forecasting/ARFIMA.php +++ b/Business/Finance/Forecasting/ARFIMA.php @@ -4,15 +4,14 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class ARFIMA { diff --git a/Business/Finance/Forecasting/ARIMA.php b/Business/Finance/Forecasting/ARIMA.php index 06155e65e..00de6c245 100644 --- a/Business/Finance/Forecasting/ARIMA.php +++ b/Business/Finance/Forecasting/ARIMA.php @@ -4,26 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; use phpOMS\Math\Statistic\Average; class ARIMA { private $data = []; + private $order = 0; public function __construct(array $data, int $order = 12) { - $this->data = $data; + $this->data = $data; $this->order = $order; if ($order !== 12 && $order !== 4) { @@ -162,4 +162,4 @@ class ARIMA return $data; } -} \ No newline at end of file +} diff --git a/Business/Finance/Forecasting/ARMA.php b/Business/Finance/Forecasting/ARMA.php index 69c6d0b5b..449efe32d 100644 --- a/Business/Finance/Forecasting/ARMA.php +++ b/Business/Finance/Forecasting/ARMA.php @@ -4,15 +4,14 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class ARMA { diff --git a/Business/Finance/Forecasting/ClassicalDecomposition.php b/Business/Finance/Forecasting/ClassicalDecomposition.php index b45aaa8c9..8a75a43f2 100644 --- a/Business/Finance/Forecasting/ClassicalDecomposition.php +++ b/Business/Finance/Forecasting/ClassicalDecomposition.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance\Forecasting; @@ -22,10 +21,9 @@ use phpOMS\Math\Statistic\Average; * * This can be used to simplify time series patterns for forecasts. * - * @category Framework - * @package phpOMS\Math\Finance\Forecasting + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @see https://www.otexts.org/fpp/6/1 * @since 1.0.0 */ @@ -174,7 +172,7 @@ class ClassicalDecomposition */ public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int { - return ($dataSize - $trendCycleComponents) / 2; + return (int) (($dataSize - $trendCycleComponents) / 2); } /** @@ -233,4 +231,4 @@ class ClassicalDecomposition return $remainderComponent; } -} \ No newline at end of file +} diff --git a/Business/Finance/Forecasting/ExponentialSmoothing/ErrorType.php b/Business/Finance/Forecasting/ExponentialSmoothing/ErrorType.php new file mode 100644 index 000000000..7925ce382 --- /dev/null +++ b/Business/Finance/Forecasting/ExponentialSmoothing/ErrorType.php @@ -0,0 +1,33 @@ +data = $data; + $this->data = $data; } - public function getRMSE() : float + public function getANN() { - return $this->rmse; } - public function getMSE() : float + public function getANA() { - return $this->mse; } - public function getMAE() : float + public function getANM() { - return $this->mae; } - public function getSSE() : float + public function getAAN() { - return $this->sse; } - public function getErrors() : array + public function getAAA() { - return $this->errors; } - public function getForecast(int $future, int $trendType = TrendType::NONE, int $seasonalType = SeasonalType::NONE, int $cycle = 12, float $damping = 1) : array + public function getAAM() { - $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 + public function getAMN() { - 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 + public function getAMA() { - $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 + public function getAMM() { - $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 + public function getMNN() { - $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 + public function getMNA() { - $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 + public function getMNM() { - $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 + public function getMAN() { - $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 + public function getMAA() { - $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 + public function getMAM() { - $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 + public function getMMN() { - $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; } -} \ No newline at end of file + public function getMMA() + { + } + + public function getMMM() + { + } +} diff --git a/Business/Finance/Forecasting/ExponentialSmoothing/SeasonalType.php b/Business/Finance/Forecasting/ExponentialSmoothing/SeasonalType.php index 22c8bd549..7c892b9d8 100644 --- a/Business/Finance/Forecasting/ExponentialSmoothing/SeasonalType.php +++ b/Business/Finance/Forecasting/ExponentialSmoothing/SeasonalType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing; @@ -20,16 +19,15 @@ use phpOMS\Stdlib\Base\Enum; /** * Smoothing enum. * - * @category Framework - * @package phpOMS\Html + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SeasonalType extends Enum { - /* public */ const ALL = 0; - /* public */ const NONE = 1; - /* public */ const ADDITIVE = 2; + /* public */ const ALL = 0; + /* public */ const NONE = 1; + /* public */ const ADDITIVE = 2; /* public */ const MULTIPLICATIVE = 4; } diff --git a/Business/Finance/Forecasting/ExponentialSmoothing/TrendType.php b/Business/Finance/Forecasting/ExponentialSmoothing/TrendType.php index 72413e498..85e3049cf 100644 --- a/Business/Finance/Forecasting/ExponentialSmoothing/TrendType.php +++ b/Business/Finance/Forecasting/ExponentialSmoothing/TrendType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing; @@ -20,16 +19,15 @@ use phpOMS\Stdlib\Base\Enum; /** * Smoothing enum. * - * @category Framework - * @package phpOMS\Html + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class TrendType extends Enum { - /* public */ const ALL = 0; - /* public */ const NONE = 1; - /* public */ const ADDITIVE = 2; + /* public */ const ALL = 0; + /* public */ const NONE = 1; + /* public */ const ADDITIVE = 2; /* public */ const MULTIPLICATIVE = 4; } diff --git a/Business/Finance/Forecasting/GARCH.php b/Business/Finance/Forecasting/GARCH.php index 07a3654b0..85bb73b26 100644 --- a/Business/Finance/Forecasting/GARCH.php +++ b/Business/Finance/Forecasting/GARCH.php @@ -4,15 +4,14 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class GARCH { diff --git a/Business/Finance/Forecasting/MA.php b/Business/Finance/Forecasting/MA.php index 4ec6a3103..1f26dbe1f 100644 --- a/Business/Finance/Forecasting/MA.php +++ b/Business/Finance/Forecasting/MA.php @@ -4,18 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class MA { } - diff --git a/Business/Finance/Forecasting/NAR.php b/Business/Finance/Forecasting/NAR.php index 7f499cfa7..a3e0515ff 100644 --- a/Business/Finance/Forecasting/NAR.php +++ b/Business/Finance/Forecasting/NAR.php @@ -4,18 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class NAR { } - diff --git a/Business/Finance/Forecasting/NMA.php b/Business/Finance/Forecasting/NMA.php index c8a67b716..ab1ed6e3a 100644 --- a/Business/Finance/Forecasting/NMA.php +++ b/Business/Finance/Forecasting/NMA.php @@ -4,18 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class NMA { } - diff --git a/Business/Finance/Forecasting/SARIMA.php b/Business/Finance/Forecasting/SARIMA.php index 53573e3c3..33163cb0a 100644 --- a/Business/Finance/Forecasting/SARIMA.php +++ b/Business/Finance/Forecasting/SARIMA.php @@ -4,18 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Business\Finance\Forecasting; +declare(strict_types = 1); +namespace phpOMS\Business\Finance\Forecasting; class SARIMA { } - diff --git a/Business/Finance/Forecasting/SmoothingType.php b/Business/Finance/Forecasting/SmoothingType.php index d14f75f2d..ac9ad0d06 100644 --- a/Business/Finance/Forecasting/SmoothingType.php +++ b/Business/Finance/Forecasting/SmoothingType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance\Forecasting; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Smoothing enum. * - * @category Framework - * @package phpOMS\Html + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SmoothingType extends Enum diff --git a/Business/Finance/Loan.php b/Business/Finance/Loan.php index 2938a44c5..94f63cb0d 100644 --- a/Business/Finance/Loan.php +++ b/Business/Finance/Loan.php @@ -4,25 +4,26 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance; /** * Finance class. * - * @category Log - * @package Framework + * @package phpOMS\Business\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class Loan { @@ -122,5 +123,4 @@ class Loan { return $loan / $collateral; } - } diff --git a/Business/Finance/Lorenzkurve.php b/Business/Finance/Lorenzkurve.php index fb1b15a56..440afc219 100644 --- a/Business/Finance/Lorenzkurve.php +++ b/Business/Finance/Lorenzkurve.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance; /** * Finance class. * - * @category Log - * @package Framework + * @package phpOMS\Business\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Lorenzkurve @@ -52,4 +50,4 @@ class Lorenzkurve return 2 * $sum1 / ($n * $sum2) - ($n + 1) / $n; } -} \ No newline at end of file +} diff --git a/Business/Finance/StockBonds.php b/Business/Finance/StockBonds.php index cae66824c..9b981a6a2 100644 --- a/Business/Finance/StockBonds.php +++ b/Business/Finance/StockBonds.php @@ -4,25 +4,26 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Finance; /** * Finance class. * - * @category Log - * @package Framework + * @package phpOMS\Business\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseParameterName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class StockBonds { @@ -368,7 +369,6 @@ class StockBonds */ public static function getZeroCouponBondEffectiveYield(float $F, float $PV, int $n) : float { - return pow($F / $PV, 1 / $n) - 1; + return (float) pow($F / $PV, 1 / $n) - 1; } - } diff --git a/Business/Marketing/Metrics.php b/Business/Marketing/Metrics.php index 7a0124756..302a050d9 100644 --- a/Business/Marketing/Metrics.php +++ b/Business/Marketing/Metrics.php @@ -4,32 +4,33 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Marketing * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Marketing; /** * Marketing Metrics - * + * * This class provided basic marketing metric calculations * - * @category Framework - * @package phpOMS\Business + * @package phpOMS\Business\Marketing * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class Metrics { +class Metrics +{ /** * Calculate customer retention - * + * + * @latex r = \frac{ce - cn}{cs} + * * @param int $ce Customer at the end of the period * @param int $cn New customers during period * @param int $cs Customers at the start of the period @@ -42,4 +43,4 @@ class Metrics { { return ($ce - $cn) / $cs; } -} \ No newline at end of file +} diff --git a/Business/Marketing/NetPromoterScore.php b/Business/Marketing/NetPromoterScore.php index 0c22eee8d..f44464ff5 100644 --- a/Business/Marketing/NetPromoterScore.php +++ b/Business/Marketing/NetPromoterScore.php @@ -4,30 +4,29 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Marketing * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Marketing; /** * Net Promoter Score - * - * The net promoter score is a basic evaluation of the happiness of customers. + * + * 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 - * @package phpOMS\Business + * @package phpOMS\Business\Marketing * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class NetPromoterScore { +class NetPromoterScore +{ /** * Score values * @@ -41,7 +40,8 @@ class NetPromoterScore { * * @since 1.0.0 */ - public function __construct() { + public function __construct() + { } @@ -72,10 +72,10 @@ class NetPromoterScore { $passives = 0; $detractors = 0; - foreach($this->scores as $score) { - if($score > 8) { + foreach ($this->scores as $score) { + if ($score > 8) { $promoters++; - } elseif($score > 6) { + } elseif ($score > 6) { $passives++; } else { $detractors++; @@ -99,8 +99,8 @@ class NetPromoterScore { public function countDetractors() : int { $count = 0; - foreach($this->scores as $score) { - if($score < 7) { + foreach ($this->scores as $score) { + if ($score < 7) { $count++; } } @@ -120,8 +120,8 @@ class NetPromoterScore { public function countPassives() : int { $count = 0; - foreach($this->scores as $score) { - if($score > 6 && $score < 9) { + foreach ($this->scores as $score) { + if ($score > 6 && $score < 9) { $count++; } } @@ -141,12 +141,12 @@ class NetPromoterScore { public function countPromoters() : int { $count = 0; - foreach($this->scores as $score) { - if($score > 8) { + foreach ($this->scores as $score) { + if ($score > 8) { $count++; } } return $count; } -} \ No newline at end of file +} diff --git a/Business/Programming/Metrics.php b/Business/Programming/Metrics.php index 04b1056ad..c621e46e0 100644 --- a/Business/Programming/Metrics.php +++ b/Business/Programming/Metrics.php @@ -4,29 +4,28 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Programming * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Programming; /** * Programming metrics - * + * * This class provides basic programming metric calculations. * - * @category Framework - * @package phpOMS\Business + * @package phpOMS\Business\Programming * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class Metrics { +class Metrics +{ /** * Calculate ABC metric score * @@ -42,24 +41,25 @@ class Metrics { */ public static function abcScore(int $a, int $b, int $c) : int { - 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}} + * @latex r = com^{2} \times (1 - cov)^{3} + com * - * @param int $a Assignments - * @param int $b Branches - * @param int $c Conditionals + * @param int $complexity Complexity + * @param float $coverage Coverage * * @return int * * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseMethodName) */ public static function CRAP(int $complexity, float $coverage) : int { return (int) ($complexity ** 2 * (1 - $coverage) ** 3 + $complexity); } -} \ No newline at end of file +} diff --git a/Business/Sales/MarketShareEstimation.php b/Business/Sales/MarketShareEstimation.php index b2b03079a..6acf18dcf 100644 --- a/Business/Sales/MarketShareEstimation.php +++ b/Business/Sales/MarketShareEstimation.php @@ -4,30 +4,29 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Business\Sales * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Business\Sales; /** * Market share calculations (Zipf function) - * - * This class can be used to calculate the market share based on a rank or vice versa + * + * 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 - * @package phpOMS\Business + * @package phpOMS\Business\Sales * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class MarketShareEstimation { +class MarketShareEstimation +{ /** * Calculate rank (r) based on market share (m) * @@ -44,13 +43,13 @@ class MarketShareEstimation { public static function getRankFromMarketShare(int $participants, float $marketShare, float $modifier = 1.0) : int { $sum = 0.0; - for($i = 0; $i < $participants; $i++) { - $sum += 1 / pow($i+1, $modifier); + for ($i = 0; $i < $participants; $i++) { + $sum += 1 / pow($i + 1, $modifier); } - + return (int) round(pow(1 / ($marketShare * $sum), 1 / $modifier)); } - + /** * Calculate market share (m) based on rank (r) * @@ -67,10 +66,10 @@ class MarketShareEstimation { public static function getMarketShareFromRank(int $participants, int $rank, float $modifier = 1.0) : float { $sum = 0.0; - for($i = 0; $i < $participants; $i++) { - $sum += 1 / pow($i+1, $modifier); + for ($i = 0; $i < $participants; $i++) { + $sum += 1 / pow($i + 1, $modifier); } - + return (1 / pow($rank, $modifier)) / $sum; } } diff --git a/Config/OptionsInterface.php b/Config/OptionsInterface.php index 67ad30553..edcfaccd2 100644 --- a/Config/OptionsInterface.php +++ b/Config/OptionsInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Config * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Config; /** * Options class. * - * @category Framework * @package phpOMS\Config * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface OptionsInterface @@ -73,5 +71,4 @@ interface OptionsInterface * @since 1.0.0 */ public function getOption($key); - } diff --git a/Config/OptionsTrait.php b/Config/OptionsTrait.php index 1bf3b2d5c..99d760e46 100644 --- a/Config/OptionsTrait.php +++ b/Config/OptionsTrait.php @@ -4,22 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Config * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Config; /** * Options trait. * - * @category Framework * @package phpOMS\Config + * @license OMS License 1.0 + * @link http://website.orange-management.de * @since 1.0.0 */ trait OptionsTrait @@ -54,7 +54,7 @@ trait OptionsTrait */ public function setOption($key, $value, bool $overwrite = true) : bool { - if ($overwrite || !array_key_exists($key, $this->options)) { + if ($overwrite || !isset($this->options[$key])) { $this->options[$key] = $value; return true; @@ -76,5 +76,4 @@ trait OptionsTrait return false; } - } diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index aa65eb9ca..f4a658188 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Config * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Config; @@ -24,10 +23,9 @@ use phpOMS\DataStorage\Database\Query\Builder; * * Responsible for providing a database/cache bound settings manger * - * @category Framework * @package phpOMS\Config * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SettingsAbstract implements OptionsInterface @@ -84,6 +82,7 @@ abstract class SettingsAbstract implements OptionsInterface * @return mixed Option value * * @since 1.0.0 + * @todo: don't db request if exists. check exists() */ public function get($columns) { @@ -110,10 +109,10 @@ abstract class SettingsAbstract implements OptionsInterface break; } - return $options; + return count($options) > 1 ? $options : reset($options); } catch (\PDOException $e) { $exception = DatabaseExceptionFactory::createException($e); - $message = DatabaseExceptionFactory::createExceptionMessage($e); + $message = DatabaseExceptionFactory::createExceptionMessage($e); throw new $exception($message); } @@ -134,7 +133,16 @@ abstract class SettingsAbstract implements OptionsInterface $this->setOptions($options); if ($store) { - // save to db + foreach ($this->options as $key => $option) { + $query = new Builder($this->connection); + $sql = $query->update($this->connection->prefix . static::$table) + ->set([static::$columns[1] => $option]) + ->where(static::$columns[0], '=', $key) + ->toSql(); + + $sth = $this->connection->con->prepare($sql); + $sth->execute(); + } } } } diff --git a/Console/CommandManager.php b/Console/CommandManager.php index f15e8d25f..f8c7a7500 100644 --- a/Console/CommandManager.php +++ b/Console/CommandManager.php @@ -4,22 +4,20 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Console; /** * CommandManager class. * - * @category Framework - * @package phpOMS\Socket + * @package Framework * @since 1.0.0 * * @todo : Hey, this looks like a copy of an event manager! @@ -128,5 +126,4 @@ class CommandManager implements \Countable { return $this->count; } - } diff --git a/Contract/ArrayableInterface.php b/Contract/ArrayableInterface.php index cd978587d..102687b2b 100644 --- a/Contract/ArrayableInterface.php +++ b/Contract/ArrayableInterface.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Contract * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Contract; @@ -20,10 +19,9 @@ namespace phpOMS\Contract; * * This stands always in combination with a jsonable instance. * - * @category Framework * @package phpOMS\Contract * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ArrayableInterface @@ -37,5 +35,4 @@ interface ArrayableInterface * @since 1.0.0 */ public function toArray() : array; - } diff --git a/Contract/RenderableInterface.php b/Contract/RenderableInterface.php index dcb9917e6..06849499a 100644 --- a/Contract/RenderableInterface.php +++ b/Contract/RenderableInterface.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Contract * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Contract; @@ -21,10 +20,9 @@ namespace phpOMS\Contract; * This is primarily used for classes that provide formatted output or output, * that get's rendered in third party applications. * - * @category Framework * @package phpOMS\Contract * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface RenderableInterface @@ -38,5 +36,4 @@ interface RenderableInterface * @since 1.0.0 */ public function render() : string; - } diff --git a/DataStorage/Cache/CacheFactory.php b/DataStorage/Cache/CacheFactory.php index daa5ef4c4..8dc23857a 100644 --- a/DataStorage/Cache/CacheFactory.php +++ b/DataStorage/Cache/CacheFactory.php @@ -4,28 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; -use phpOMS\DataStorage\Cache\CacheInterface; -use phpOMS\DataStorage\Cache\FileCache; - - /** * Database connection factory. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CacheFactory @@ -35,6 +29,7 @@ class CacheFactory * Constructor. * * @since 1.0.0 + * @codeCoverageIgnore */ private function __construct() { diff --git a/DataStorage/Cache/CacheInterface.php b/DataStorage/Cache/CacheInterface.php index 015c56123..fa226e42a 100644 --- a/DataStorage/Cache/CacheInterface.php +++ b/DataStorage/Cache/CacheInterface.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; + use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Cache interface. * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface CacheInterface @@ -39,7 +38,7 @@ interface CacheInterface * * @since 1.0.0 */ - public function set($key, $value, int $expire = -1) /* : void */; + public function set($key, $value, int $expire = -1); /* : void */ /** * Adding new data if it doesn't exist. @@ -109,7 +108,7 @@ interface CacheInterface * * @since 1.0.0 */ - public function setStatus(int $status) /* : void */; + public function setStatus(int $status); /* : void */ /** * Updating existing value/key. @@ -141,5 +140,4 @@ interface CacheInterface * @since 1.0.0 */ public function getThreshold() : int; - } diff --git a/DataStorage/Cache/CachePool.php b/DataStorage/Cache/CachePool.php index eef56b141..f8bfa3445 100644 --- a/DataStorage/Cache/CachePool.php +++ b/DataStorage/Cache/CachePool.php @@ -4,21 +4,18 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; use phpOMS\Config\OptionsInterface; use phpOMS\Config\OptionsTrait; -use phpOMS\DataStorage\Cache\CacheFactory; - /** * Cache class. @@ -26,10 +23,9 @@ use phpOMS\DataStorage\Cache\CacheFactory; * Responsible for caching scalar data types and arrays. * Caching HTML output and objects coming soon/is planned. * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CachePool implements OptionsInterface @@ -39,12 +35,11 @@ class CachePool implements OptionsInterface /** * MemCache instance. * - * @var \phpOMS\DataStorage\Cache\CacheInterface + * @var \phpOMS\DataStorage\Cache\CacheInterface[] * @since 1.0.0 */ private $pool = null; - /** * Constructor. * @@ -64,7 +59,7 @@ class CachePool implements OptionsInterface * * @since 1.0.0 */ - public function add(string $key = 'core', CacheInterface $cache) : bool + public function add(string $key, CacheInterface $cache) : bool { if (isset($this->pool[$key])) { return false; @@ -106,11 +101,11 @@ class CachePool implements OptionsInterface */ public function get(string $key = '') /* : ?CacheInterface */ { - if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) { + if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) { return null; } - if(empty($key)) { + if (empty($key)) { return reset($this->pool); } diff --git a/DataStorage/Cache/CacheStatus.php b/DataStorage/Cache/CacheStatus.php index ffb58806c..1d474215c 100644 --- a/DataStorage/Cache/CacheStatus.php +++ b/DataStorage/Cache/CacheStatus.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; @@ -22,15 +21,14 @@ use phpOMS\Stdlib\Base\Enum; * * Possible caching status * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class CacheStatus extends Enum { - /* public */ const ACTIVE = 0; + /* public */ const ACTIVE = 0; /* public */ const INACTIVE = 1; - /* public */ const ERROR = 2; + /* public */ const ERROR = 2; } diff --git a/DataStorage/Cache/CacheType.php b/DataStorage/Cache/CacheType.php index 35b12ac41..c922706f0 100644 --- a/DataStorage/Cache/CacheType.php +++ b/DataStorage/Cache/CacheType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; @@ -22,19 +21,18 @@ use phpOMS\Stdlib\Base\Enum; * * Possible caching types * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class CacheType extends Enum { - /* public */ const _INT = 0; /* Data is integer */ - /* public */ const _STRING = 1; /* Data is string */ - /* public */ const _ARRAY = 2; /* Data is array */ - /* public */ const _SERIALIZABLE = 3; /* Data is object */ - /* public */ const _FLOAT = 4; /* Data is float */ - /* public */ const _BOOL = 5; /* Data is bool */ + /* public */ const _INT = 0; /* Data is integer */ + /* public */ const _STRING = 1; /* Data is string */ + /* public */ const _ARRAY = 2; /* Data is array */ + /* public */ const _SERIALIZABLE = 3; /* Data is object */ + /* public */ const _FLOAT = 4; /* Data is float */ + /* public */ const _BOOL = 5; /* Data is bool */ /* public */ const _JSONSERIALIZABLE = 6; } diff --git a/DataStorage/Cache/FileCache.php b/DataStorage/Cache/FileCache.php index 236e882ea..750d0c725 100644 --- a/DataStorage/Cache/FileCache.php +++ b/DataStorage/Cache/FileCache.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; @@ -24,10 +23,9 @@ use phpOMS\System\File\Local\File; * * PHP Version 7.1 * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class FileCache implements CacheInterface @@ -108,7 +106,7 @@ class FileCache implements CacheInterface */ public function setStatus(int $status) /* : void */ { - if(!CacheStatus::isValidValue($status)) { + if (!CacheStatus::isValidValue($status)) { throw new InvalidEnumValue($status); } @@ -142,16 +140,14 @@ class FileCache implements CacheInterface */ public function set($key, $value, int $expire = -1) /* : void */ { - if($this->status !== CacheStatus::ACTIVE) { - return false; + if ($this->status !== CacheStatus::ACTIVE) { + return; } // todo: allow $key to contain / as char and create subdirectory if necessary. This is important for cleaner caching. $path = File::sanitize($key, self::SANITIZE); File::put($this->cachePath . '/' . trim($path, '/') . '.cache', $this->build($value, $expire)); - - return false; } /** @@ -159,12 +155,11 @@ class FileCache implements CacheInterface */ public function add($key, $value, int $expire = -1) : bool { - if($this->status !== CacheStatus::ACTIVE) { + if ($this->status !== CacheStatus::ACTIVE) { return false; } - $path = File::sanitize($key, self::SANITIZE); - $path = $this->cachePath . '/' . trim($path, '/') . '.cache'; + $path = $this->getPath($key); if (!File::exists($path)) { File::put($path, $this->build($value, $expire)); @@ -262,9 +257,9 @@ class FileCache implements CacheInterface private function getExpire(string $raw) : int { $expireStart = strpos($raw, self::DELIM); - $expireEnd = strpos($raw, self::DELIM, $expireStart+1); + $expireEnd = strpos($raw, self::DELIM, $expireStart + 1); - return (int) substr($raw, $expireStart+1, $expireEnd - ($expireStart+1)); + return (int) substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1)); } /** @@ -272,17 +267,16 @@ class FileCache implements CacheInterface */ public function get($key, int $expire = -1) { - if($this->status !== CacheStatus::ACTIVE) { + if ($this->status !== CacheStatus::ACTIVE) { return null; } - $name = File::sanitize($key, self::SANITIZE); - $path = $this->cachePath . '/' . trim($name, '/') . '.cache'; + $path = $this->getPath($key); - if(!File::exists($path)) { + if (!File::exists($path)) { return null; } - + $created = Directory::created($path)->getTimestamp(); $now = time(); @@ -291,11 +285,11 @@ class FileCache implements CacheInterface } $raw = File::get($path); - $type = $raw[0]; + $type = (int) $raw[0]; $expireStart = strpos($raw, self::DELIM); - $expireEnd = strpos($raw, self::DELIM, $expireStart+1); - $cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1)); + $expireEnd = strpos($raw, self::DELIM, $expireStart + 1); + $cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1)); if ($cacheExpire >= 0 && $created + $cacheExpire < $now) { $this->delete($key); @@ -303,6 +297,11 @@ class FileCache implements CacheInterface return null; } + return $this->parseValue($type, $raw, $expireEnd); + } + + private function parseValue(int $type, string $raw, int $expireEnd) + { $value = null; switch ($type) { @@ -324,7 +323,7 @@ class FileCache implements CacheInterface case CacheType::_SERIALIZABLE: case CacheType::_JSONSERIALIZABLE: $namespaceStart = strpos($raw, self::DELIM, $expireEnd); - $namespaceEnd = strpos($raw, self::DELIM, $namespaceStart+1); + $namespaceEnd = strpos($raw, self::DELIM, $namespaceStart + 1); $namespace = substr($raw, $namespaceStart, $namespaceEnd); $value = $namespace::unserialize(substr($raw, $namespaceEnd + 1)); @@ -339,12 +338,11 @@ class FileCache implements CacheInterface */ public function delete($key, int $expire = -1) : bool { - if($this->status !== CacheStatus::ACTIVE) { + if ($this->status !== CacheStatus::ACTIVE) { return false; } - $name = File::sanitize($key, self::SANITIZE); - $path = $this->cachePath . '/' . trim($name, '/') . '.cache'; + $path = $this->getPath($key); if ($expire < 0 && File::exists($path)) { File::delete($path); @@ -353,12 +351,12 @@ class FileCache implements CacheInterface } if ($expire >= 0) { - $created = Directory::created($name)->getTimestamp(); + $created = Directory::created(File::sanitize($key, self::SANITIZE))->getTimestamp(); $now = time(); $raw = file_get_contents($path); $expireStart = strpos($raw, self::DELIM); - $expireEnd = strpos($raw, self::DELIM, $expireStart+1); - $cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1)); + $expireEnd = strpos($raw, self::DELIM, $expireStart + 1); + $cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1)); if ($cacheExpire >= 0 && $created + $cacheExpire > $now) { File::delete($path); @@ -385,8 +383,7 @@ class FileCache implements CacheInterface foreach ($dir as $file) { if ($file instanceof File) { $created = $file->getCreatedAt()->getTimestamp(); - if ( - ($expire >= 0 && $created + $expire < $now) + if (($expire >= 0 && $created + $expire < $now) || ($expire < 0 && $created + $this->getExpire($file->getContent()) < $now) ) { File::delete($file->getPath()); @@ -402,12 +399,11 @@ class FileCache implements CacheInterface */ public function replace($key, $value, int $expire = -1) : bool { - if($this->status !== CacheStatus::ACTIVE) { + if ($this->status !== CacheStatus::ACTIVE) { return false; } - $name = File::sanitize($key, self::SANITIZE); - $path = $this->cachePath . '/' . trim($path, '/') . '.cache'; + $path = $this->getPath($key); if (File::exists($path)) { File::put($path, $this->build($value, $expire)); @@ -417,4 +413,10 @@ class FileCache implements CacheInterface return false; } + + private function getPath($key) : string + { + $path = File::sanitize($key, self::SANITIZE); + return $this->cachePath . '/' . trim($path, '/') . '.cache'; + } } diff --git a/DataStorage/Cache/MemCache.php b/DataStorage/Cache/MemCache.php index 4314263af..43649dd26 100644 --- a/DataStorage/Cache/MemCache.php +++ b/DataStorage/Cache/MemCache.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; /** * Memcache class. * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MemCache implements CacheInterface @@ -43,6 +41,8 @@ class MemCache implements CacheInterface */ private $threshold = 10; + private $status; + /** * Constructor. * @@ -50,7 +50,7 @@ class MemCache implements CacheInterface */ public function __construct() { - $this->memc = new self(); + $this->memc = null; } /** @@ -174,5 +174,4 @@ class MemCache implements CacheInterface $this->memc = null; } } - } diff --git a/DataStorage/Cache/MemCached.php b/DataStorage/Cache/MemCached.php new file mode 100644 index 000000000..e4d97d431 --- /dev/null +++ b/DataStorage/Cache/MemCached.php @@ -0,0 +1,176 @@ +memc = null; + } + + /** + * Adding server to server pool. + * + * @param mixed $data Server data array + * + * @return void + * + * @since 1.0.0 + */ + public function addServer($data) + { + $this->memc->addServer($data['host'], $data['port'], $data['timeout']); + } + + /** + * {@inheritdoc} + */ + public function set($key, $value, int $expire = -1) /* : void */ + { + $this->memc->set($key, $value, false, $expire); + } + + /** + * {@inheritdoc} + */ + public function add($key, $value, int $expire = -1) : bool + { + return $this->memc->add($key, $value, false, $expire); + } + + /** + * {@inheritdoc} + */ + public function get($key, int $expire = -1) + { + return $this->memc->get($key); + } + + /** + * {@inheritdoc} + */ + public function delete($key, int $expire = -1) : bool + { + $this->memc->delete($key); + } + + /** + * {@inheritdoc} + */ + public function flush(int $expire = 0) : bool + { + $this->memc->flush(); + + return true; + } + + /** + * {@inheritdoc} + */ + public function flushAll() : bool + { + $this->memc->flush(); + + return true; + } + + /** + * {@inheritdoc} + */ + public function replace($key, $value, int $expire = -1) : bool + { + $this->memc->replace($key, $value, false, $expire); + } + + /** + * {@inheritdoc} + */ + public function stats() : array + { + /** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */ + return $this->memc->getExtendedStats(); + } + + /** + * {@inheritdoc} + */ + public function getThreshold() : int + { + return $this->threshold; + } + + /** + * {@inheritdoc} + */ + public function setStatus(int $status) /* : void */ + { + $this->status = $status; + } + + /** + * Destructor. + * + * @since 1.0.0 + */ + public function __destruct() + { + $this->close(); + } + + /** + * Closing cache. + * + * @since 1.0.0 + */ + public function close() + { + if ($this->memc !== null) { + $this->memc->close(); + $this->memc = null; + } + } +} diff --git a/DataStorage/Cache/NullCache.php b/DataStorage/Cache/NullCache.php index 95b3a07e6..b7d9a4e73 100644 --- a/DataStorage/Cache/NullCache.php +++ b/DataStorage/Cache/NullCache.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; /** * Null cache class. * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullCache implements CacheInterface @@ -32,7 +30,6 @@ class NullCache implements CacheInterface */ public function set($key, $value, int $expire = -1) /* : void */ { - // TODO: Implement set() method. } /** @@ -40,7 +37,7 @@ class NullCache implements CacheInterface */ public function add($key, $value, int $expire = -1) : bool { - // TODO: Implement add() method. + return true; } /** @@ -48,7 +45,7 @@ class NullCache implements CacheInterface */ public function get($key, int $expire = -1) { - // TODO: Implement get() method. + return null; } /** @@ -56,7 +53,7 @@ class NullCache implements CacheInterface */ public function delete($key, int $expire = -1) : bool { - // TODO: Implement delete() method. + return true; } /** @@ -64,8 +61,6 @@ class NullCache implements CacheInterface */ public function flush(int $expire = 0) : bool { - // TODO: Implement flush() method. - return true; } @@ -74,8 +69,6 @@ class NullCache implements CacheInterface */ public function flushAll() : bool { - // TODO: Implement flush() method. - return true; } @@ -84,7 +77,7 @@ class NullCache implements CacheInterface */ public function replace($key, $value, int $expire = -1) : bool { - // TODO: Implement replace() method. + return true; } /** @@ -92,7 +85,7 @@ class NullCache implements CacheInterface */ public function stats() : array { - // TODO: Implement stats() method. + return []; } /** @@ -100,7 +93,7 @@ class NullCache implements CacheInterface */ public function getThreshold() : int { - // TODO: Implement getThreshold() method. + return 0; } /** @@ -108,6 +101,5 @@ class NullCache implements CacheInterface */ public function setStatus(int $status) /* : void */ { - // TODO: Implement setStatus() method. } } diff --git a/DataStorage/Cache/RedisCache.php b/DataStorage/Cache/RedisCache.php index 586ec294e..2e1e4c895 100644 --- a/DataStorage/Cache/RedisCache.php +++ b/DataStorage/Cache/RedisCache.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; @@ -20,10 +19,9 @@ namespace phpOMS\DataStorage\Cache; * * PHP Version 5.6 * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class RedisCache implements CacheInterface diff --git a/DataStorage/Cache/WinCache.php b/DataStorage/Cache/WinCache.php index cab734a1c..60ec759a4 100644 --- a/DataStorage/Cache/WinCache.php +++ b/DataStorage/Cache/WinCache.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cache; @@ -20,10 +19,9 @@ namespace phpOMS\DataStorage\Cache; * * PHP Version 5.6 * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class WinCache implements CacheInterface diff --git a/DataStorage/Cookie/CookieJar.php b/DataStorage/Cookie/CookieJar.php index 2124a8d4f..aba3f614b 100644 --- a/DataStorage/Cookie/CookieJar.php +++ b/DataStorage/Cookie/CookieJar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Cookie; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\LockException; /** * CookieJar class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CookieJar @@ -47,6 +45,8 @@ class CookieJar * Constructor. * * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ public function __construct() { @@ -122,12 +122,12 @@ class CookieJar */ public function delete(string $id) : bool { - if($this->remove($id)) { + if ($this->remove($id)) { if (self::$isLocked) { throw new LockException('CookieJar'); } - if(!headers_sent()) { + if (!headers_sent()) { setcookie($id, '', time() - 3600); return true; diff --git a/DataStorage/DataMapperInterface.php b/DataStorage/DataMapperInterface.php index 48aaf4925..8483d35c9 100644 --- a/DataStorage/DataMapperInterface.php +++ b/DataStorage/DataMapperInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage; @@ -22,10 +21,9 @@ use phpOMS\DataStorage\Database\Query\Builder; * * DB, Cache, Session * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface DataMapperInterface @@ -47,11 +45,11 @@ interface DataMapperInterface * * @param mixed $obj Object reference (gets filled with insert id) * - * @return int Status + * @return mixed * * @since 1.0.0 */ - public static function update($obj) : int; + public static function update($obj); /** * Delete data. @@ -129,5 +127,4 @@ interface DataMapperInterface * @since 1.0.0 */ public static function get($primaryKey); - } diff --git a/DataStorage/Database/BuilderAbstract.php b/DataStorage/Database/BuilderAbstract.php index 87a8702bb..587694171 100644 --- a/DataStorage/Database/BuilderAbstract.php +++ b/DataStorage/Database/BuilderAbstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; /** * Database query builder. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class BuilderAbstract @@ -60,6 +58,14 @@ abstract class BuilderAbstract */ protected $prefix = ''; + /** + * Raw. + * + * @var string + * @since 1.0.0 + */ + public $raw = ''; + /** * Set prefix. * diff --git a/DataStorage/Database/Connection/ConnectionAbstract.php b/DataStorage/Database/Connection/ConnectionAbstract.php index 90c3c88f4..340156ee8 100644 --- a/DataStorage/Database/Connection/ConnectionAbstract.php +++ b/DataStorage/Database/Connection/ConnectionAbstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar; * Handles the database connection. * Implementing wrapper functions for multiple databases is planned (far away). * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ConnectionAbstract implements ConnectionInterface @@ -65,15 +63,15 @@ abstract class ConnectionAbstract implements ConnectionInterface /** * Database type. * - * @var \phpOMS\DataStorage\Database\DatabaseType + * @var string * @since 1.0.0 */ - protected $type = null; + protected $type = 'undefined'; /** * Database status. * - * @var DatabaseStatus + * @var int * @since 1.0.0 */ protected $status = DatabaseStatus::CLOSED; @@ -202,5 +200,4 @@ abstract class ConnectionAbstract implements ConnectionInterface $this->con = null; $this->status = DatabaseStatus::CLOSED; } - } diff --git a/DataStorage/Database/Connection/ConnectionFactory.php b/DataStorage/Database/Connection/ConnectionFactory.php index 9448235bd..ca9fc9f2c 100644 --- a/DataStorage/Database/Connection/ConnectionFactory.php +++ b/DataStorage/Database/Connection/ConnectionFactory.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\DatabaseType; /** * Database connection factory. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ConnectionFactory @@ -57,10 +55,8 @@ class ConnectionFactory switch ($dbdata['db']) { case DatabaseType::MYSQL: return new MysqlConnection($dbdata); - break; case DatabaseType::SQLSRV: return new SqlServerConnection($dbdata); - break; default: throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.'); } diff --git a/DataStorage/Database/Connection/ConnectionInterface.php b/DataStorage/Database/Connection/ConnectionInterface.php index cd320bf30..f61209b5f 100644 --- a/DataStorage/Database/Connection/ConnectionInterface.php +++ b/DataStorage/Database/Connection/ConnectionInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar; /** * Database connection interface. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ConnectionInterface @@ -41,7 +39,7 @@ interface ConnectionInterface * * @since 1.0.0 */ - public function connect(array $dbdata) /* : void */; + public function connect(array $dbdata); /* : void */ /** * Get the database type. @@ -68,7 +66,7 @@ interface ConnectionInterface * * @since 1.0.0 */ - public function close() /* : void */; + public function close(); /* : void */ /** * Return grammar for this connection. @@ -87,5 +85,4 @@ interface ConnectionInterface * @since 1.0.0 */ public function getSchemaGrammar() : SchemaGrammar; - } diff --git a/DataStorage/Database/Connection/MysqlConnection.php b/DataStorage/Database/Connection/MysqlConnection.php index ad739724b..f74f3122d 100644 --- a/DataStorage/Database/Connection/MysqlConnection.php +++ b/DataStorage/Database/Connection/MysqlConnection.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -27,10 +26,9 @@ use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException; * Handles the database connection. * Implementing wrapper functions for multiple databases is planned (far away). * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MysqlConnection extends ConnectionAbstract @@ -59,33 +57,12 @@ class MysqlConnection extends ConnectionAbstract public function connect(array $dbdata = null) /* : void */ { $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; - - if(!isset($this->dbdata['db'])) { - throw new InvalidConnectionConfigException('db'); - } - if(!isset($this->dbdata['host'])) { - throw new InvalidConnectionConfigException('host'); - } - - if(!isset($this->dbdata['port'])) { - throw new InvalidConnectionConfigException('port'); - } - - if(!isset($this->dbdata['database'])) { - throw new InvalidConnectionConfigException('database'); - } - - if(!isset($this->dbdata['login'])) { - throw new InvalidConnectionConfigException('login'); - } - - if(!isset($this->dbdata['password'])) { - throw new InvalidConnectionConfigException('password'); + if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) { + throw new InvalidConnectionConfigException(json_encode($this->dbdata)); } $this->close(); - $this->prefix = $dbdata['prefix'] ?? ''; try { @@ -101,5 +78,4 @@ class MysqlConnection extends ConnectionAbstract $this->dbdata['password'] = '****'; } } - } diff --git a/DataStorage/Database/Connection/PostgresConnection.php b/DataStorage/Database/Connection/PostgresConnection.php index 60545b66f..2119aa688 100644 --- a/DataStorage/Database/Connection/PostgresConnection.php +++ b/DataStorage/Database/Connection/PostgresConnection.php @@ -4,18 +4,17 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; abstract class PostgresConnection extends \Exception { -} \ No newline at end of file +} diff --git a/DataStorage/Database/Connection/SQLiteConnection.php b/DataStorage/Database/Connection/SQLiteConnection.php index 007ef2b6d..8a1af206d 100644 --- a/DataStorage/Database/Connection/SQLiteConnection.php +++ b/DataStorage/Database/Connection/SQLiteConnection.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Query\Grammar\SqliteGrammar; * Handles the database connection. * Implementing wrapper functions for multiple databases is planned (far away). * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SqliteConnection extends ConnectionAbstract @@ -71,5 +69,4 @@ class SqliteConnection extends ConnectionAbstract $this->con = null; } } - } diff --git a/DataStorage/Database/Connection/SqlServerConnection.php b/DataStorage/Database/Connection/SqlServerConnection.php index 00bd23b30..132595ba9 100644 --- a/DataStorage/Database/Connection/SqlServerConnection.php +++ b/DataStorage/Database/Connection/SqlServerConnection.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Connection; @@ -26,10 +25,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGramma * Handles the database connection. * Implementing wrapper functions for multiple databases is planned (far away). * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SqlServerConnection extends ConnectionAbstract @@ -74,4 +72,4 @@ class SqlServerConnection extends ConnectionAbstract $this->dbdata['password'] = '****'; } } -} \ No newline at end of file +} diff --git a/DataStorage/Database/DataMapperAbstract.php b/DataStorage/Database/DataMapperAbstract.php index 16b370786..6c5dfc5fe 100644 --- a/DataStorage/Database/DataMapperAbstract.php +++ b/DataStorage/Database/DataMapperAbstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -26,10 +25,9 @@ use phpOMS\DataStorage\Database\Exception\InvalidMapperException; * * DB, Cache, Session * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class DataMapperAbstract implements DataMapperInterface @@ -72,7 +70,7 @@ class DataMapperAbstract implements DataMapperInterface * @var string * @since 1.0.0 */ - protected static $language_field = ''; + protected static $languageField = ''; /** * Columns. @@ -149,7 +147,7 @@ class DataMapperAbstract implements DataMapperInterface /** * Highest mapper to know when to clear initialized objects * - * @var DataMapperAbstract + * @var string * @since 1.0.0 */ protected static $parentMapper = null; @@ -182,7 +180,7 @@ class DataMapperAbstract implements DataMapperInterface /** * Clone. - * + * * @return void * * @since 1.0.0 @@ -196,7 +194,7 @@ class DataMapperAbstract implements DataMapperInterface * Set database connection. * * @param ConnectionAbstract $con Database connection - * + * * @return void * * @since 1.0.0 @@ -302,8 +300,8 @@ class DataMapperAbstract implements DataMapperInterface ]; // clear parent and objects - if(static::class === self::$parentMapper) { - self::$initObjects = []; + if (static::class === self::$parentMapper) { + //self::$initObjects = []; // todo: now all objects are cached for the whole request self::$parentMapper = null; } } @@ -323,12 +321,12 @@ class DataMapperAbstract implements DataMapperInterface $query = static::getQuery(); - foreach(static::$columns as $col) { - if(isset($col['autocomplete']) && $col['autocomplete']) { + foreach (static::$columns as $col) { + if (isset($col['autocomplete']) && $col['autocomplete']) { $query->where(static::$table . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR'); } } - + return static::getAllByQuery($query); } @@ -346,13 +344,11 @@ class DataMapperAbstract implements DataMapperInterface { self::extend(__CLASS__); - if($obj === null || - (is_object($obj) && strpos($className = get_class($obj), '\Null') !== false) - ) { + if (!isset($obj) || self::isNullObject($obj)) { return null; } - $reflectionClass = new \ReflectionClass($className); + $reflectionClass = new \ReflectionClass($obj); $objId = self::createModel($obj, $reflectionClass); self::setObjectId($reflectionClass, $obj, $objId); @@ -377,7 +373,7 @@ class DataMapperAbstract implements DataMapperInterface { self::extend(__CLASS__); - $objId = self::createModelArray($obj); + $objId = self::createModelArray($obj); settype($objId, static::$columns[static::$primaryField]['type']); $obj[static::$columns[static::$primaryField]['internal']] = $objId; @@ -503,9 +499,9 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - private static function getObjectId($obj, \ReflectionClass $reflectionClass = null) + private static function getObjectId($obj, \ReflectionClass $reflectionClass = null) { - $reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj)); + $reflectionClass = $reflectionClass ?? new \ReflectionClass($obj); $reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']); if (!($isPublic = $reflectionProperty->isPublic())) { @@ -594,7 +590,7 @@ class DataMapperAbstract implements DataMapperInterface } if (!isset($relReflectionClass)) { - $relReflectionClass = new \ReflectionClass(get_class($value)); + $relReflectionClass = new \ReflectionClass($value); } $primaryKey = $mapper::getObjectId($value, $relReflectionClass); @@ -633,8 +629,8 @@ class DataMapperAbstract implements DataMapperInterface /** * Create has many * - * @param array $obj Object to create - * @param mixed $objId Id to set + * @param array $obj Object to create + * @param mixed $objId Id to set * * @return void * @@ -652,8 +648,8 @@ class DataMapperAbstract implements DataMapperInterface } /** @var string $mapper */ - $mapper = static::$hasMany[$propertyName]['mapper']; - $objsIds = []; + $mapper = static::$hasMany[$propertyName]['mapper']; + $objsIds = []; foreach ($values as $key => &$value) { if (!is_object($value)) { @@ -689,10 +685,6 @@ class DataMapperAbstract implements DataMapperInterface private static function createHasOne(\ReflectionClass $reflectionClass, $obj) { throw new \Exception(); - - foreach (static::$hasOne as $propertyName => $rel) { - - } } /** @@ -825,8 +817,7 @@ class DataMapperAbstract implements DataMapperInterface private static function createRelationTable(string $propertyName, array $objsIds, $objId) { /** @var string $table */ - if ( - !empty($objsIds) + if (!empty($objsIds) && static::$hasMany[$propertyName]['table'] !== static::$table && static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table ) { @@ -916,8 +907,8 @@ class DataMapperAbstract implements DataMapperInterface } /** @var string $mapper */ - $mapper = static::$hasMany[$propertyName]['mapper']; - $relReflectionClass = null; + $mapper = static::$hasMany[$propertyName]['mapper']; + $relReflectionClass = null; $objsIds[$propertyName] = []; foreach ($values as $key => &$value) { @@ -926,10 +917,10 @@ class DataMapperAbstract implements DataMapperInterface $objsIds[$propertyName][$key] = $value; continue; - } - + } + if (!isset($relReflectionClass)) { - $relReflectionClass = new \ReflectionClass(get_class($value)); + $relReflectionClass = new \ReflectionClass($value); } $primaryKey = $mapper::getObjectId($value, $relReflectionClass); @@ -972,14 +963,11 @@ class DataMapperAbstract implements DataMapperInterface * * Deletes old entries and creates new ones * - * @param string $propertyName Property name to initialize * @param array $objsIds Object ids to insert * @param mixed $objId Model to reference * * @return mixed * - * @throws \Exception - * * @since 1.0.0 */ private static function updateRelationTable(array $objsIds, $objId) @@ -990,11 +978,11 @@ class DataMapperAbstract implements DataMapperInterface $removes = array_diff($many[$propertyName], array_keys($objsIds[$propertyName] ?? [])); $adds = array_diff(array_keys($objsIds[$propertyName] ?? []), $many[$propertyName]); - if(!empty($removes)) { + if (!empty($removes)) { self::deleteRelationTable($propertyName, $removes, $objId); } - if(!empty($adds)) { + if (!empty($adds)) { self::createRelationTable($propertyName, $adds, $objId); } } @@ -1014,8 +1002,7 @@ class DataMapperAbstract implements DataMapperInterface private static function deleteRelationTable(string $propertyName, array $objsIds, $objId) { /** @var string $table */ - if ( - !empty($objsIds) + if (!empty($objsIds) && static::$hasMany[$propertyName]['table'] !== static::$table && static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table ) { @@ -1152,19 +1139,26 @@ class DataMapperAbstract implements DataMapperInterface * @param mixed $obj Object reference (gets filled with insert id) * @param int $relations Create all relations as well * - * @return int + * @return mixed * * @since 1.0.0 */ - public static function update($obj, int $relations = RelationType::ALL) : int + public static function update($obj, int $relations = RelationType::ALL) { self::extend(__CLASS__); - $reflectionClass = new \ReflectionClass(get_class($obj)); + if (!isset($obj) || self::isNullObject($obj)) { + return null; + } + + $reflectionClass = new \ReflectionClass($obj); $objId = self::getObjectId($obj, $reflectionClass); $update = true; - if(empty($objId)) { + // todo: maybe don't remove obj and just update cache... ? since it might have to be loaded again + self::removeInitialized(static::class, $objId); + + if (empty($objId)) { $update = false; self::create($obj, $relations); } @@ -1172,8 +1166,8 @@ class DataMapperAbstract implements DataMapperInterface if ($relations === RelationType::ALL) { self::updateHasMany($reflectionClass, $obj, $objId); } - - if($update) { + + if ($update) { self::updateModel($obj, $objId, $reflectionClass); } @@ -1224,17 +1218,17 @@ class DataMapperAbstract implements DataMapperInterface $objsIds[$key] = $value; continue; - } - + } + if (!isset($relReflectionClass)) { - $relReflectionClass = new \ReflectionClass(get_class($value)); + $relReflectionClass = new \ReflectionClass($value); } $primaryKey = $mapper::getObjectId($value, $relReflectionClass); // already in db if (!empty($primaryKey)) { - if($relations === RelationType::ALL) { + if ($relations === RelationType::ALL) { $objsIds[$key] = $mapper::delete($value); } else { $objsIds[$key] = $primaryKey; @@ -1244,7 +1238,7 @@ class DataMapperAbstract implements DataMapperInterface } // todo: could be a problem, relation needs to be removed first?! - + } self::deleteRelationTable($propertyName, $objsIds, $objId); @@ -1322,7 +1316,7 @@ class DataMapperAbstract implements DataMapperInterface $properties = $reflectionClass->getProperties(); - if($relations === RelationType::ALL) { + if ($relations === RelationType::ALL) { foreach ($properties as $property) { $propertyName = $property->getName(); @@ -1336,7 +1330,7 @@ class DataMapperAbstract implements DataMapperInterface // todo: the order of deletion could be a problem. maybe looping through ownsOne and belongsTo first is better. // todo: support other relation types as well (belongsto, ownsone) = for better control - + foreach (static::$columns as $key => $column) { if ($relations === RelationType::ALL && isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) { self::deleteOwnsOne($propertyName, $property->getValue($obj)); @@ -1370,17 +1364,19 @@ class DataMapperAbstract implements DataMapperInterface { self::extend(__CLASS__); - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); $objId = self::getObjectId($obj, $reflectionClass); - if(empty($objId)) { + if (empty($objId)) { return null; } + self::removeInitialized(static::class, $objId); + if ($relations !== RelationType::NONE) { self::deleteHasMany($reflectionClass, $obj, $objId, $relations); } - + self::deleteModel($obj, $objId, $relations, $reflectionClass); return $objId; @@ -1468,15 +1464,16 @@ class DataMapperAbstract implements DataMapperInterface * * @param array[] $result Result set * @param mixed $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * * @since 1.0.0 */ - public static function populateManyToMany(array $result, &$obj) /* : void */ + public static function populateManyToMany(array $result, &$obj, int $depth = null) /* : void */ { // todo: maybe pass reflectionClass as optional parameter for performance increase - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); foreach ($result as $member => $values) { if (!empty($values) && $reflectionClass->hasProperty($member)) { @@ -1484,17 +1481,12 @@ class DataMapperAbstract implements DataMapperInterface $mapper = static::$hasMany[$member]['mapper']; $reflectionProperty = $reflectionClass->getProperty($member); - $values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? [])); - if(empty($values)) { - continue; - } - if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } - $objects = $mapper::get($values); - $reflectionProperty->setValue($obj, !is_array($objects) ? [$objects] : $objects); + $objects = $mapper::get($values, RelationType::ALL, null, $depth); + $reflectionProperty->setValue($obj, !is_array($objects) ? [$objects->getId() => $objects] : $objects); if (!$accessible) { $reflectionProperty->setAccessible(false); @@ -1508,24 +1500,20 @@ class DataMapperAbstract implements DataMapperInterface * * @param array[] $result Result set * @param array $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * * @since 1.0.0 */ - public static function populateManyToManyArray(array $result, array &$obj) /* : void */ + public static function populateManyToManyArray(array $result, array &$obj, int $depth = null) /* : void */ { foreach ($result as $member => $values) { if (!empty($values)) { /** @var string $mapper */ $mapper = static::$hasMany[$member]['mapper']; - $values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? [])); - if(empty($values)) { - continue; - } - - $objects = $mapper::getArray($values); + $objects = $mapper::getArray($values, RelationType::ALL, $depth); $obj[$member] = $objects; } } @@ -1535,6 +1523,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param mixed $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1542,9 +1531,9 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateHasOne(&$obj) /* : void */ + public static function populateHasOne(&$obj, int $depth = null) /* : void */ { - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); foreach (static::$hasOne as $member => $one) { // todo: is that if necessary? performance is suffering for sure! @@ -1557,13 +1546,15 @@ class DataMapperAbstract implements DataMapperInterface /** @var string $mapper */ $mapper = static::$hasOne[$member]['mapper']; + $id = $reflectionProperty->getValue($obj); - if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { - $value = self::$initObjects[$mapper][$id]; - } else { - $value = $mapper::get($reflectionProperty->getValue($obj)); + if (self::isNullObject($id)) { + continue; } - + + $id = is_object($id) ? self::getObjectId($id) : $id; + $value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth); + $reflectionProperty->setValue($obj, $value); if (!$accessible) { @@ -1577,6 +1568,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param array $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1584,19 +1576,12 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateHasOneArray(array &$obj) /* : void */ + public static function populateHasOneArray(array &$obj, int $depth = null) /* : void */ { foreach (static::$hasOne as $member => $one) { /** @var string $mapper */ - $mapper = static::$hasOne[$member]['mapper']; - - if(self::isInitialized($mapper, $obj['member'])) { - $value = self::$initObjects[$mapper][$obj['member']]; - } else { - $value = $mapper::getArray($obj[$member]); - } - - $obj[$member] = $value; + $mapper = static::$hasOne[$member]['mapper']; + $obj[$member] = self::getInitialized($mapper, $obj['member']) ?? $mapper::getArray($obj[$member], RelationType::ALL, $depth); } } @@ -1604,6 +1589,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param mixed $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1611,9 +1597,9 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateOwnsOne(&$obj) /* : void */ + public static function populateOwnsOne(&$obj, int $depth = null) /* : void */ { - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); foreach (static::$ownsOne as $member => $one) { // todo: is that if necessary? performance is suffering for sure! @@ -1626,13 +1612,15 @@ class DataMapperAbstract implements DataMapperInterface /** @var string $mapper */ $mapper = static::$ownsOne[$member]['mapper']; + $id = $reflectionProperty->getValue($obj); - if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { - $value = self::$initObjects[$mapper][$id]; - } else { - $value = $mapper::get($reflectionProperty->getValue($obj)); + if (self::isNullObject($id)) { + continue; } + $id = is_object($id) ? self::getObjectId($id) : $id; + $value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth); + $reflectionProperty->setValue($obj, $value); if (!$accessible) { @@ -1646,6 +1634,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param array $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1653,19 +1642,12 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateOwnsOneArray(array &$obj) /* : void */ + public static function populateOwnsOneArray(array &$obj, int $depth = null) /* : void */ { foreach (static::$ownsOne as $member => $one) { /** @var string $mapper */ - $mapper = static::$ownsOne[$member]['mapper']; - - if(self::isInitialized($mapper, $obj[$member])) { - $value = self::$initObjects[$mapper][$obj[$member]]; - } else { - $value = $mapper::getArray($obj[$member]); - } - - $obj[$member] = $value; + $mapper = static::$ownsOne[$member]['mapper']; + $obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::getArray($obj[$member], RelationType::ALL, $depth); } } @@ -1673,6 +1655,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param mixed $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1680,9 +1663,9 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateBelongsTo(&$obj) /* : void */ + public static function populateBelongsTo(&$obj, int $depth = null) /* : void */ { - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); foreach (static::$belongsTo as $member => $one) { // todo: is that if necessary? performance is suffering for sure! @@ -1695,13 +1678,15 @@ class DataMapperAbstract implements DataMapperInterface /** @var string $mapper */ $mapper = static::$belongsTo[$member]['mapper']; + $id = $reflectionProperty->getValue($obj); - if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { - $value = self::$initObjects[$mapper][$id]; - } else { - $value = $mapper::get($reflectionProperty->getValue($obj)); + if (self::isNullObject($id)) { + continue; } + $id = is_object($id) ? self::getObjectId($id) : $id; + $value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth); + $reflectionProperty->setValue($obj, $value); if (!$accessible) { @@ -1715,6 +1700,7 @@ class DataMapperAbstract implements DataMapperInterface * Populate data. * * @param array $obj Object to add the relations to + * @param int $depth Relation depth * * @return void * @@ -1722,19 +1708,12 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - public static function populateBelongsToArray(array &$obj) /* : void */ + public static function populateBelongsToArray(array &$obj, int $depth = null) /* : void */ { foreach (static::$belongsTo as $member => $one) { /** @var string $mapper */ - $mapper = static::$belongsTo[$member]['mapper']; - - if(self::isInitialized($mapper, $obj[$member])) { - $value = self::$initObjects[$mapper][$obj[$member]]; - } else { - $value = $mapper::get($obj[$member]); - } - - $obj[$member] = $value; + $mapper = static::$belongsTo[$member]['mapper']; + $obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::get($obj[$member], RelationType::ALL, null, $depth); } } @@ -1752,36 +1731,38 @@ class DataMapperAbstract implements DataMapperInterface */ public static function populateAbstract(array $result, $obj) { - $reflectionClass = new \ReflectionClass(get_class($obj)); + $reflectionClass = new \ReflectionClass($obj); foreach ($result as $column => $value) { - if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) { - $reflectionProperty = $reflectionClass->getProperty(static::$columns[$column]['internal']); + if (!isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) { + continue; + } - if (!($accessible = $reflectionProperty->isPublic())) { - $reflectionProperty->setAccessible(true); + $reflectionProperty = $reflectionClass->getProperty(static::$columns[$column]['internal']); + + if (!($accessible = $reflectionProperty->isPublic())) { + $reflectionProperty->setAccessible(true); + } + + if (in_array(static::$columns[$column]['type'], ['string', 'int', 'float', 'bool'])) { + if ($value !== null || $reflectionProperty->getValue($obj) !== null) { + settype($value, static::$columns[$column]['type']); } - if (in_array(static::$columns[$column]['type'], ['string', 'int', 'float', 'bool'])) { - if($value !== null || $reflectionProperty->getValue($obj) !== null) { - settype($value, static::$columns[$column]['type']); - } + $reflectionProperty->setValue($obj, $value); + } elseif (static::$columns[$column]['type'] === 'DateTime') { + $reflectionProperty->setValue($obj, new \DateTime($value ?? '')); + } elseif (static::$columns[$column]['type'] === 'Json') { + $reflectionProperty->setValue($obj, json_decode($value, true)); + } elseif (static::$columns[$column]['type'] === 'Serializable') { + $member = $reflectionProperty->getValue($obj); + $member->unserialize($value); + } else { + throw new \UnexpectedValueException('Value "' . static::$columns[$column]['type'] . '" is not supported.'); + } - $reflectionProperty->setValue($obj, $value); - } elseif (static::$columns[$column]['type'] === 'DateTime') { - $reflectionProperty->setValue($obj, new \DateTime($value ?? '')); - } elseif (static::$columns[$column]['type'] === 'Json') { - $reflectionProperty->setValue($obj, json_decode($value, true)); - } elseif (static::$columns[$column]['type'] === 'Serializable') { - $member = $reflectionProperty->getValue($obj); - $member->unserialize($value); - } else { - throw new \UnexpectedValueException('Value "' . static::$columns[$column]['type'] . '" is not supported.'); - } - - if (!$accessible) { - $reflectionProperty->setAccessible(false); - } + if (!$accessible) { + $reflectionProperty->setAccessible(false); } } @@ -1829,14 +1810,21 @@ class DataMapperAbstract implements DataMapperInterface * @param mixed $primaryKey Key * @param int $relations Load relations * @param mixed $fill Object to fill + * @param int $depth Relation depth * * @return mixed * + * @todo: implement language + * * @since 1.0.0 */ - public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null) + public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null, int $depth = null) { - if(!isset(self::$parentMapper)) { + if (isset($depth) && $depth < 1) { + return $primaryKey; + } + + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } @@ -1849,7 +1837,8 @@ class DataMapperAbstract implements DataMapperInterface $toFill = null; foreach ($primaryKey as $key => $value) { - if(self::isInitialized(static::class, $value)) { + if (self::isInitialized(static::class, $value)) { + $obj[$value] = self::$initObjects[static::class][$value]; continue; } @@ -1860,27 +1849,34 @@ class DataMapperAbstract implements DataMapperInterface $obj[$value] = self::populate(self::getRaw($value), $toFill); - if(method_exists($obj[$value], 'initialize')) { + if (method_exists($obj[$value], 'initialize')) { $obj[$value]->initialize(); } - self::addInitialized(static::class, $value); + self::addInitialized(static::class, $value, $obj[$value]); } - self::fillRelations($obj, $relations); + self::fillRelations($obj, $relations, isset($depth) ? --$depth : null); self::clear(); $countResulsts = count($obj); - if($countResulsts === 0) { + if ($countResulsts === 0) { return self::getNullModelObj(); - } elseif($countResulsts === 1) { + } elseif ($countResulsts === 1) { return reset($obj); } return $obj; } + /** + * Creates the current null object + * + * @return mixed + * + * @since 1.0.0 + */ private static function getNullModelObj() { $class = static::class; @@ -1898,14 +1894,19 @@ class DataMapperAbstract implements DataMapperInterface * * @param mixed $primaryKey Key * @param int $relations Load relations + * @param int $depth Relation depth * * @return mixed * * @since 1.0.0 */ - public static function getArray($primaryKey, int $relations = RelationType::ALL) : array + public static function getArray($primaryKey, int $relations = RelationType::ALL, int $depth = null) : array { - if(!isset(self::$parentMapper)) { + if (isset($depth) && $depth < 1) { + return $primaryKey; + } + + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } @@ -1915,16 +1916,17 @@ class DataMapperAbstract implements DataMapperInterface $obj = []; foreach ($primaryKey as $key => $value) { - if(self::isInitialized(static::class, $value)) { + if (self::isInitialized(static::class, $value)) { + $obj[$value] = self::$initObjects[static::class][$value]; continue; } $obj[$value] = self::populateAbstractArray(self::getRaw($value)); - self::addInitialized(static::class, $value); + self::addInitialized(static::class, $value, $obj[$value]); } - self::fillRelationsArray($obj, $relations); + self::fillRelationsArray($obj, $relations, isset($depth) ? --$depth : null); self::clear(); return count($obj) === 1 ? reset($obj) : $obj; @@ -1937,14 +1939,19 @@ class DataMapperAbstract implements DataMapperInterface * @param string $ref The field that defines the for * @param int $relations Load relations * @param mixed $fill Object to fill + * @param int $depth Relation depth * * @return mixed * * @since 1.0.0 */ - public static function getFor($refKey, string $ref, int $relations = RelationType::ALL, $fill = null) + public static function getFor($refKey, string $ref, int $relations = RelationType::ALL, $fill = null, int $depth = null) { - if(!isset(self::$parentMapper)) { + if (isset($depth) && $depth < 1) { + return $refKey; + } + + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } @@ -1956,20 +1963,20 @@ class DataMapperAbstract implements DataMapperInterface foreach ($refKey as $key => $value) { $toLoad = []; - if(isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) { + if (isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) { $toLoad = self::getHasManyPrimaryKeys($value, $ref); } else { $toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref)); } - $obj[$value] = self::get($toLoad, $relations, $fill); + $obj[$value] = self::get($toLoad, $relations, $fill, isset($depth) ? --$depth : null); } $countResulsts = count($obj); - if($countResulsts === 0) { + if ($countResulsts === 0) { return self::getNullModelObj(); - } elseif($countResulsts === 1) { + } elseif ($countResulsts === 1) { return reset($obj); } @@ -1990,7 +1997,7 @@ class DataMapperAbstract implements DataMapperInterface */ public static function getForArray($refKey, string $ref, int $relations = RelationType::ALL, $fill = null) { - if(!isset(self::$parentMapper)) { + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } @@ -2002,7 +2009,7 @@ class DataMapperAbstract implements DataMapperInterface foreach ($refKey as $key => $value) { $toLoad = []; - if(isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) { + if (isset(static::$hasMany[$ref]) && static::$hasMany[$ref]['src'] !== null) { $toLoad = self::getHasManyPrimaryKeys($value, $ref); } else { $toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref)); @@ -2018,20 +2025,25 @@ class DataMapperAbstract implements DataMapperInterface * Get object. * * @param int $relations Load relations + * @param int $depth Relation depth * @param string $lang Language * * @return array * * @since 1.0.0 */ - public static function getAll(int $relations = RelationType::ALL, string $lang = '') : array + public static function getAll(int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array { - if(!isset(self::$parentMapper)) { + if (isset($depth) && $depth < 1) { + return null; + } + + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } $obj = self::populateIterable(self::getAllRaw($lang)); - self::fillRelations($obj, $relations); + self::fillRelations($obj, $relations, isset($depth) ? --$depth : null); self::clear(); return $obj; @@ -2041,20 +2053,25 @@ class DataMapperAbstract implements DataMapperInterface * Get object. * * @param int $relations Load relations + * @param int $depth Relation depth * @param string $lang Language * * @return array * * @since 1.0.0 */ - public static function getAllArray(int $relations = RelationType::ALL, string $lang = '') : array + public static function getAllArray(int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array { - if(!isset(self::$parentMapper)) { + if (isset($depth) && $depth < 1) { + return null; + } + + if (!isset(self::$parentMapper)) { self::setUpParentMapper(); } $obj = self::populateIterableArray(self::getAllRaw($lang)); - self::fillRelationsArray($obj, $relations); + self::fillRelationsArray($obj, $relations, isset($depth) ? --$depth : null); self::clear(); return $obj; @@ -2085,14 +2102,19 @@ class DataMapperAbstract implements DataMapperInterface * @param int $limit Newest limit * @param Builder $query Pre-defined query * @param int $relations Load relations + * @param int $depth Relation depth * @param string $lang Language * * @return mixed * * @since 1.0.0 */ - public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, string $lang = '') : array + public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array { + if (isset($depth) && $depth < 1) { + return null; + } + self::extend(__CLASS__); $query = $query ?? new Builder(self::$db); @@ -2105,8 +2127,8 @@ class DataMapperAbstract implements DataMapperInterface $query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC'); } - if (!empty(self::$language_field) && !empty($lang)) { - $query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); + if (!empty(self::$languageField) && !empty($lang)) { + $query->where(static::$table . '.' . static::$languageField, '=', $lang, 'AND'); } $sth = self::$db->con->prepare($query->toSql()); @@ -2115,7 +2137,7 @@ class DataMapperAbstract implements DataMapperInterface $results = $sth->fetchAll(\PDO::FETCH_ASSOC); $obj = self::populateIterable(is_bool($results) ? [] : $results); - self::fillRelations($obj, $relations); + self::fillRelations($obj, $relations, isset($depth) ? --$depth : null); self::clear(); return $obj; @@ -2127,13 +2149,18 @@ class DataMapperAbstract implements DataMapperInterface * * @param Builder $query Query * @param int $relations Relations + * @param int $depth Relation depth * * @return array * * @since 1.0.0 */ - public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL) : array + public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL, int $depth = null) : array { + if (isset($depth) && $depth < 1) { + return null; + } + $sth = self::$db->con->prepare($query->toSql()); $sth->execute(); @@ -2141,7 +2168,7 @@ class DataMapperAbstract implements DataMapperInterface $results = is_bool($results) ? [] : $results; $obj = self::populateIterable($results); - self::fillRelations($obj, $relations); + self::fillRelations($obj, $relations, isset($depth) ? --$depth : null); self::clear(); return $obj; @@ -2152,13 +2179,18 @@ class DataMapperAbstract implements DataMapperInterface * * @param int $amount Amount of random models * @param int $relations Relations type + * @param int $depth Relation depth * * @return mixed * * @since 1.0.0 */ - public static function getRandom(int $amount = 1, int $relations = RelationType::ALL) + public static function getRandom(int $amount = 1, int $relations = RelationType::ALL, int $depth = null) { + if (isset($depth) && $depth < 1) { + return null; + } + $query = new Builder(self::$db); $query->prefix(self::$db->getPrefix()) ->random(static::$primaryField) @@ -2168,7 +2200,7 @@ class DataMapperAbstract implements DataMapperInterface $sth = self::$db->con->prepare($query->toSql()); $sth->execute(); - return self::get($sth->fetchAll(), $relations); + return self::get($sth->fetchAll(), $relations, null, $depth); } /** @@ -2176,36 +2208,47 @@ class DataMapperAbstract implements DataMapperInterface * * @param mixed $obj Objects to fill * @param int $relations Relations type + * @param int $depth Relation depth * * @return void * * @since 1.0.0 */ - public static function fillRelations(array &$obj, int $relations = RelationType::ALL) /* : void */ + public static function fillRelations(array &$obj, int $relations = RelationType::ALL, int $depth = null) /* : void */ { + if (isset($depth) && $depth < 1) { + return; + } + + if ($relations === RelationType::NONE) { + return; + } + $hasMany = !empty(static::$hasMany); $hasOne = !empty(static::$hasOne); $ownsOne = !empty(static::$ownsOne); $belongsTo = !empty(static::$belongsTo); - if ($relations !== RelationType::NONE && ($hasMany || $hasOne || $ownsOne || $belongsTo)) { - foreach ($obj as $key => $value) { - /* loading relations from relations table and populating them and then adding them to the object */ - if ($hasMany) { - self::populateManyToMany(self::getHasManyRaw($key, $relations), $obj[$key]); - } + if (!($hasMany || $hasOne || $ownsOne || $belongsTo)) { + return; + } - if ($hasOne) { - self::populateHasOne($obj[$key]); - } + foreach ($obj as $key => $value) { + /* loading relations from relations table and populating them and then adding them to the object */ + if ($hasMany) { + self::populateManyToMany(self::getHasManyRaw($key, $relations), $obj[$key], $depth); + } - if ($ownsOne) { - self::populateOwnsOne($obj[$key]); - } + if ($hasOne) { + self::populateHasOne($obj[$key], $depth); + } - if ($belongsTo) { - self::populateBelongsTo($obj[$key]); - } + if ($ownsOne) { + self::populateOwnsOne($obj[$key], $depth); + } + + if ($belongsTo) { + self::populateBelongsTo($obj[$key], $depth); } } } @@ -2215,36 +2258,47 @@ class DataMapperAbstract implements DataMapperInterface * * @param mixed $obj Objects to fill * @param int $relations Relations type + * @param int $depth Relation depth * * @return void * * @since 1.0.0 */ - public static function fillRelationsArray(array &$obj, int $relations = RelationType::ALL) /* : void */ + public static function fillRelationsArray(array &$obj, int $relations = RelationType::ALL, int $depth = null) /* : void */ { + if (isset($depth) && $depth < 1) { + return null; + } + + if ($relations !== RelationType::NONE) { + return; + } + $hasMany = !empty(static::$hasMany); $hasOne = !empty(static::$hasOne); $ownsOne = !empty(static::$ownsOne); $belongsTo = !empty(static::$belongsTo); - if ($relations !== RelationType::NONE && ($hasMany || $hasOne || $ownsOne || $belongsTo)) { - foreach ($obj as $key => $value) { - /* loading relations from relations table and populating them and then adding them to the object */ - if ($hasMany) { - self::populateManyToManyArray(self::getHasManyRaw($key, $relations), $obj[$key]); - } + if (!($hasMany || $hasOne || $ownsOne || $belongsTo)) { + return; + } - if ($hasOne) { - self::populateHasOneArray($obj[$key]); - } + foreach ($obj as $key => $value) { + /* loading relations from relations table and populating them and then adding them to the object */ + if ($hasMany) { + self::populateManyToManyArray(self::getHasManyRaw($key, $relations), $obj[$key], $depth); + } - if ($ownsOne) { - self::populateOwnsOneArray($obj[$key]); - } + if ($hasOne) { + self::populateHasOneArray($obj[$key], $depth); + } - if ($belongsTo) { - self::populateBelongsToArray($obj[$key]); - } + if ($ownsOne) { + self::populateOwnsOneArray($obj[$key], $depth); + } + + if ($belongsTo) { + self::populateBelongsToArray($obj[$key], $depth); } } } @@ -2336,8 +2390,8 @@ class DataMapperAbstract implements DataMapperInterface { $query = self::getQuery(); - if (!empty(self::$language_field) && !empty($lang)) { - $query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); + if (!empty(self::$languageField) && !empty($lang)) { + $query->where(static::$table . '.' . static::$languageField, '=', $lang, 'AND'); } $sth = self::$db->con->prepare($query->toSql()); @@ -2446,8 +2500,8 @@ class DataMapperAbstract implements DataMapperInterface public static function getByRequest(RequestAbstract $request) { if (!is_null($request->getData('id'))) { - $result = static::get($request->getData('id')); - } elseif (!is_null($filter = $request->getData('filter'))) { + $result = static::get((int) $request->getData('id')); + } elseif (!is_null($filter = ((string) $request->getData('filter')))) { $filter = strtolower($filter); if ($filter === 'all') { @@ -2457,8 +2511,8 @@ class DataMapperAbstract implements DataMapperInterface $result = static::get(json_decode($list, true)); } else { $limit = (int) ($request->getData('limit') ?? 1); - $from = !is_null($request->getData('from')) ? new \DateTime($request->getData('from')) : null; - $to = !is_null($request->getData('to')) ? new \DateTime($request->getData('to')) : null; + $from = !is_null($request->getData('from')) ? new \DateTime((string) $request->getData('from')) : null; + $to = !is_null($request->getData('to')) ? new \DateTime((string) $request->getData('to')) : null; $query = static::getQuery(); $query->limit($limit); @@ -2490,7 +2544,7 @@ class DataMapperAbstract implements DataMapperInterface */ private static function addInitialized(string $mapper, $id, $obj = null) /* : void */ { - if(!isset(self::$initObjects[$mapper])) { + if (!isset(self::$initObjects[$mapper])) { self::$initObjects[$mapper] = []; } @@ -2507,11 +2561,43 @@ class DataMapperAbstract implements DataMapperInterface * * @since 1.0.0 */ - private static function isInitialized($mapper, $id) : bool + private static function isInitialized(string $mapper, $id) : bool { return isset(self::$initObjects[$mapper]) && isset(self::$initObjects[$mapper][$id]); } + /** + * Get initialized object + * + * @param string $mapper Mapper name + * @param mixed $id Object id + * + * @return mixed + * + * @since 1.0.0 + */ + private static function getInitialized(string $mapper, $id) + { + return self::$initObjects[$mapper][$id] ?? null; + } + + /** + * Remove initialized object + * + * @param string $mapper Mapper name + * @param mixed $id Object id + * + * @return mixed + * + * @since 1.0.0 + */ + private static function removeInitialized(string $mapper, $id) + { + if (self::isInitialized($mapper, $id)) { + unset(self::$initObjects[$mapper][$id]); + } + } + /** * Define the highest mapper of this request * @@ -2543,7 +2629,7 @@ class DataMapperAbstract implements DataMapperInterface $sth = self::$db->con->prepare($query->toSql()); $sth->execute(); - + $results = $sth->fetchAll(\PDO::FETCH_ASSOC); return count($results) === 0; @@ -2555,19 +2641,33 @@ class DataMapperAbstract implements DataMapperInterface * @param string $name member name * * @return string - * + * * @throws \Exception Throws this exception if the member couldn't be found * * @since 1.0.0 */ private static function getColumnByMember(string $name) : string { - foreach(static::$columns as $cName => $column) { - if($column['internal'] === $name) { + foreach (static::$columns as $cName => $column) { + if ($column['internal'] === $name) { return $cName; } } throw new \Exception('Invalid member name'); } + + /** + * Test if object is null object + * + * @param object $obj Object to check + * + * @return bool + * + * @since 1.0.0 + */ + private static function isNullObject($obj) : bool + { + return is_object($obj) && strpos(get_class($obj), '\Null') !== false; + } } diff --git a/DataStorage/Database/DataMapperBaseAbstract.php b/DataStorage/Database/DataMapperBaseAbstract.php deleted file mode 100644 index 5974cd0a4..000000000 --- a/DataStorage/Database/DataMapperBaseAbstract.php +++ /dev/null @@ -1,437 +0,0 @@ - [], - '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(); - } -} diff --git a/DataStorage/Database/DatabaseExceptionFactory.php b/DataStorage/Database/DatabaseExceptionFactory.php index 99565eb00..3ad9de15a 100644 --- a/DataStorage/Database/DatabaseExceptionFactory.php +++ b/DataStorage/Database/DatabaseExceptionFactory.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\Schema\Exception\TableException; /** * Database exception factory. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class DatabaseExceptionFactory diff --git a/DataStorage/Database/DatabasePool.php b/DataStorage/Database/DatabasePool.php index 5f4751454..de1dfe5c1 100644 --- a/DataStorage/Database/DatabasePool.php +++ b/DataStorage/Database/DatabasePool.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionFactory; /** * Database pool handler. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class DatabasePool @@ -57,7 +55,7 @@ class DatabasePool * * @since 1.0.0 */ - public function add(string $key = 'core', ConnectionAbstract $db) : bool + public function add(string $key, ConnectionAbstract $db) : bool { if (isset($this->pool[$key])) { return false; @@ -79,11 +77,11 @@ class DatabasePool */ public function get(string $key = '') /* : ?ConnectionAbstract */ { - if((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) { + if ((!empty($key) && !isset($this->pool[$key])) || empty($this->pool)) { return null; } - if(empty($key)) { + if (empty($key)) { return reset($this->pool); } @@ -130,5 +128,4 @@ class DatabasePool return true; } - } diff --git a/DataStorage/Database/DatabaseStatus.php b/DataStorage/Database/DatabaseStatus.php index 1a1877a05..f9cdb61eb 100644 --- a/DataStorage/Database/DatabaseStatus.php +++ b/DataStorage/Database/DatabaseStatus.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * Possible database connection status * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class DatabaseStatus extends Enum diff --git a/DataStorage/Database/DatabaseType.php b/DataStorage/Database/DatabaseType.php index 2de4a65c0..b31e84bfb 100644 --- a/DataStorage/Database/DatabaseType.php +++ b/DataStorage/Database/DatabaseType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -22,17 +21,16 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class DatabaseType extends Enum { - /* public */ const MYSQL = 'mysql'; /* MySQL */ - /* public */ const SQLITE = 'sqlite'; /* SQLITE */ - /* public */ const PGSQL = 2; /* PostgreSQL */ - /* public */ const ORACLE = 3; /* Oracle */ - /* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */ + /* public */ const MYSQL = 'mysql'; /* MySQL */ + /* public */ const SQLITE = 'sqlite'; /* SQLITE */ + /* public */ const PGSQL = 2; /* PostgreSQL */ + /* public */ const ORACLE = 3; /* Oracle */ + /* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */ } diff --git a/DataStorage/Database/Exception/InvalidConnectionConfigException.php b/DataStorage/Database/Exception/InvalidConnectionConfigException.php index 5b1a3cef7..47aea45ab 100644 --- a/DataStorage/Database/Exception/InvalidConnectionConfigException.php +++ b/DataStorage/Database/Exception/InvalidConnectionConfigException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Exception; /** * Permission exception class. * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidConnectionConfigException extends \InvalidArgumentException @@ -31,12 +29,12 @@ class InvalidConnectionConfigException extends \InvalidArgumentException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ public function __construct(string $message = '', int $code = 0, \Exception $previous = null) { - parent::__construct('Missing config value for "'. $message .'".', $code, $previous); + parent::__construct('Missing config value for "' . $message . '".', $code, $previous); } } diff --git a/DataStorage/Database/Exception/InvalidDatabaseTypeException.php b/DataStorage/Database/Exception/InvalidDatabaseTypeException.php new file mode 100644 index 000000000..520cf6743 --- /dev/null +++ b/DataStorage/Database/Exception/InvalidDatabaseTypeException.php @@ -0,0 +1,40 @@ + $element) { if (is_string($element) && $element !== '*') { - if(strpos($element, '.') === false) { + if (strpos($element, '.') === false) { $prefix = ''; } @@ -236,26 +234,21 @@ abstract class GrammarAbstract { // todo: this is a bad way to handle select count(*) which doesn't need a prefix. Maybe remove prefixes in total? $identifier = $this->systemIdentifier; - - foreach($this->specialKeywords as $keyword) { - if($keyword === '' || strrpos($system, $keyword, -strlen($system)) !== false) { - $prefix = ''; + + foreach ($this->specialKeywords as $keyword) { + if (strrpos($system, $keyword, -strlen($system)) !== false) { + $prefix = ''; $identifier = ''; } } // todo: move remaining * test also here not just if .* but also if * (should be done in else?) - if (count($split = explode('.', $system)) == 2) { - if ($split[1] === '*') { - $system = $split[1]; - } else { - $system = $this->compileSystem($split[1]); - } + if (count($split = explode('.', $system)) === 2) { + $system = $split[1] === '*' ? $split[1] : $this->compileSystem($split[1]); return $this->compileSystem($prefix . $split[0]) . '.' . $system; - } else { - return $identifier . $prefix . $system . $identifier; } - } + return $identifier . $prefix . $system . $identifier; + } } diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index 996b6a15b..47adaffbc 100644 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; @@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; /** * Database query builder. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Builder extends BuilderAbstract @@ -64,7 +62,7 @@ class Builder extends BuilderAbstract /** * Into. * - * @var array + * @var string|\Closure * @since 1.0.0 */ public $into = null; @@ -152,7 +150,7 @@ class Builder extends BuilderAbstract /** * Offset. * - * @var array + * @var int * @since 1.0.0 */ public $offset = null; @@ -181,14 +179,6 @@ class Builder extends BuilderAbstract */ public $lock = false; - /** - * Raw query. - * - * @var bool - * @since 1.0.0 - */ - public $raw = ''; - /** * Comparison OPERATORS. * @@ -229,6 +219,7 @@ class Builder extends BuilderAbstract * Constructor. * * @param ConnectionAbstract $connection Database connection + * @param bool $readOnly Query is read only * * @since 1.0.0 */ @@ -352,21 +343,14 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \Exception + * * @since 1.0.0 */ public function raw(string $raw) : Builder { - if($this->isReadOnly) { - $test = strtolower($raw); - - if(strpos($test, 'insert') !== false - || strpos($test, 'update') !== false - || strpos($test, 'drop') !== false - || strpos($test, 'delete') !== false - || strpos($test, 'create') !== false - || strpos($test, 'alter') !== false) { - throw new \Exception(); - } + if (!$this->isValidReadOnly($raw)) { + throw new \Exception(); } $this->type = QueryType::RAW; @@ -375,6 +359,37 @@ class Builder extends BuilderAbstract return $this; } + /** + * Tests if a string contains a non read only component in case the builder is read only. + * If the builder is not read only it will always return true + * + * @param string $raw Raw query + * + * @return bool + * + * @since 1.0.0 + */ + private function isValidReadOnly($raw) : bool + { + if (!$this->isReadOnly) { + return true; + } + + $test = strtolower($raw); + + if (strpos($test, 'insert') !== false + || strpos($test, 'update') !== false + || strpos($test, 'drop') !== false + || strpos($test, 'delete') !== false + || strpos($test, 'create') !== false + || strpos($test, 'alter') !== false + ) { + return false; + } + + return true; + } + /** * Make raw column selection. * @@ -398,7 +413,7 @@ class Builder extends BuilderAbstract * * @since 1.0.0 */ - public function distinct(...$columns) : Builder + public function distinct() : Builder { $this->distinct = true; @@ -408,7 +423,7 @@ class Builder extends BuilderAbstract /** * From. * - * @param array $tables Tables + * @param string|array $tables Tables * * @return Builder * @@ -446,7 +461,7 @@ class Builder extends BuilderAbstract /** * Where. * - * @param string|array|\Closure $columns Columns + * @param Where|string|\Closure|array $columns Columns * @param string|array $operator Operator * @param mixed $values Values * @param string|array $boolean Boolean condition @@ -459,36 +474,31 @@ class Builder extends BuilderAbstract */ public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder { - // TODO: handle $value is null -> operator NULL if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) { throw new \InvalidArgumentException('Unknown operator.'); } - if (is_array($columns)) { - $i = 0; - foreach ($columns as $key => $column) { - if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) { - throw new \InvalidArgumentException('Unknown operator.'); - } + if (is_string($columns)) { + $columns = [$columns]; + $operator = [$operator]; + $values = [$values]; + $boolean = [$boolean]; + } - $this->wheres[self::getPublicColumnName($column)][] = [ - 'column' => $column, - 'operator' => $operator[$i], - 'value' => $values[$i], - 'boolean' => $boolean[$i], - ]; - - $i++; - } - } elseif (is_string($columns)) { - if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) { + $i = 0; + foreach ($columns as $key => $column) { + if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) { throw new \InvalidArgumentException('Unknown operator.'); } - $this->wheres[self::getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values, - 'boolean' => $boolean,]; - } else { - throw new \InvalidArgumentException(); + $this->wheres[self::getPublicColumnName($column)][] = [ + 'column' => $column, + 'operator' => $operator[$i], + 'value' => $values[$i], + 'boolean' => $boolean[$i], + ]; + + $i++; } return $this; @@ -523,7 +533,7 @@ class Builder extends BuilderAbstract */ public function getTableOfSystem($expression, string $systemIdentifier) /* : ?string */ { - if(($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) { + if (($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) { return null; } @@ -533,7 +543,9 @@ class Builder extends BuilderAbstract /** * Where and sub condition. * - * @param Where $where Where sub condition + * @param Where|string|\Closure|array $where Where sub condition + * @param mixed $operator Operator + * @param mixed $values Values * * @return Builder * @@ -547,7 +559,9 @@ class Builder extends BuilderAbstract /** * Where or sub condition. * - * @param Where $where Where sub condition + * @param Where|string|\Closure|array $where Where sub condition + * @param mixed $operator Operator + * @param mixed $values Values * * @return Builder * @@ -561,7 +575,7 @@ class Builder extends BuilderAbstract /** * Where in. * - * @param string|array|\Closure $column Column + * @param Where|string|\Closure|array $column Column * @param mixed $values Values * @param string $boolean Boolean condition * @@ -579,7 +593,7 @@ class Builder extends BuilderAbstract /** * Where null. * - * @param string|array|\Closure $column Column + * @param Where|string|\Closure|array $column Column * @param string $boolean Boolean condition * * @return Builder @@ -596,7 +610,7 @@ class Builder extends BuilderAbstract /** * Where not null. * - * @param string|array|\Closure $column Column + * @param Where|string|\Closure|array $column Column * @param string $boolean Boolean condition * * @return Builder @@ -677,7 +691,7 @@ class Builder extends BuilderAbstract public function orderBy($columns, $order = 'DESC') : Builder { if (is_string($columns) || $columns instanceof \Closure) { - if(!isset($this->orders[$order])) { + if (!isset($this->orders[$order])) { $this->orders[$order] = []; } @@ -696,7 +710,7 @@ class Builder extends BuilderAbstract /** * Offset. * - * @param int|\Closure $offset Offset + * @param int $offset Offset * * @return Builder * @@ -712,7 +726,7 @@ class Builder extends BuilderAbstract /** * Limit. * - * @param int|\Closure $limit Limit + * @param int $limit Limit * * @return Builder * @@ -726,7 +740,7 @@ class Builder extends BuilderAbstract } /** - * Limit. + * Union. * * @param string|\phpOMS\DataStorage\Database\Query\Builder $query Query * @@ -785,9 +799,13 @@ class Builder extends BuilderAbstract /** * Count results. * + * @param string $table Table to count the result set + * + * @return Builder + * * @since 1.0.0 */ - public function count(string $table = '*') + public function count(string $table = '*') : Builder { // todo: don't do this as string, create new object new Count(); this can get handled by the grammar parser WAY better return $this->select('COUNT(' . $table . ')'); @@ -836,11 +854,13 @@ class Builder extends BuilderAbstract * * @return Builder * + * @throws \Exception + * * @since 1.0.0 */ public function insert(...$columns) : Builder { - if($this->isReadOnly) { + if ($this->isReadOnly) { throw new \Exception(); } @@ -941,15 +961,17 @@ class Builder extends BuilderAbstract /** * Update columns. * - * @param array $columns Column names to update + * @param array $tables Column names to update * * @return Builder * + * @throws \Exception + * * @since 1.0.0 */ public function update(...$tables) : Builder { - if($this->isReadOnly) { + if ($this->isReadOnly) { throw new \Exception(); } @@ -968,7 +990,7 @@ class Builder extends BuilderAbstract public function delete() : Builder { - if($this->isReadOnly) { + if ($this->isReadOnly) { throw new \Exception(); } @@ -1098,46 +1120,50 @@ class Builder extends BuilderAbstract public function execute() { $sth = $this->connection->con->prepare($this->toSql()); - - foreach($this->binds as $key => $bind) { + + foreach ($this->binds as $key => $bind) { $type = self::getBindParamType($bind); - + $sth->bindParam($key, $bind, $type); } - + $sth->execute(); return $sth; } - + /** * Get bind parameter type. * + * @param mixed $value Value to bind + * * @return mixed * + * @throws \Exception + * * @since 1.0.0 */ public static function getBindParamType($value) { - if(is_int($value)) { - return PDO::PARAM_INT; - } elseif(is_string($value) || is_float($value)) { - return PDO::PARAM_STR; + if (is_int($value)) { + return \PDO::PARAM_INT; + } elseif (is_string($value) || is_float($value)) { + return \PDO::PARAM_STR; } - + throw new \Exception(); } public static function getPublicColumnName($column) : string { - if(is_string($column)) { + if (is_string($column)) { return $column; - } elseif($column instanceof Column) { + } elseif ($column instanceof Column) { return $column->getPublicName(); - } elseif($column instanceof \Closure) { + } elseif ($column instanceof \Closure) { return $column(); - } elseif($column instanceof \Serializable) { - return $column; + } elseif ($column instanceof \Serializable) { + return $column->serialize(); } throw new \Exception(); diff --git a/DataStorage/Database/Query/Column.php b/DataStorage/Database/Query/Column.php index 7c485668a..9e414f3c5 100644 --- a/DataStorage/Database/Query/Column.php +++ b/DataStorage/Database/Query/Column.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; /** * Database query builder. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Column @@ -63,5 +61,4 @@ class Column { $this->column = $column; } - } diff --git a/DataStorage/Database/Query/Expression.php b/DataStorage/Database/Query/Expression.php index 0a9946fb0..c1e114756 100644 --- a/DataStorage/Database/Query/Expression.php +++ b/DataStorage/Database/Query/Expression.php @@ -4,19 +4,17 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; - class Expression { -} \ No newline at end of file +} diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 3ba97ff75..1d03401bd 100644 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; @@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Query\Where; /** * Database query grammar. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Grammar extends GrammarAbstract @@ -115,29 +113,12 @@ class Grammar extends GrammarAbstract { $sql = []; - switch ($query->getType()) { - case QueryType::SELECT: - $components = $this->selectComponents; - break; - case QueryType::INSERT: - $components = $this->insertComponents; - break; - case QueryType::UPDATE: - $components = $this->updateComponents; - break; - case QueryType::DELETE: - $components = $this->deleteComponents; - break; - case QueryType::RANDOM: - $components = $this->selectComponents; - break; - case QueryType::RAW: - return [$query->raw]; - break; - default: - throw new \InvalidArgumentException('Unknown query type.'); + if ($query->getType() === QueryType::RAW) { + return [$query->raw]; } + $components = $this->getComponents($query->getType()); + /* Loop all possible query components and if they exist compile them. */ foreach ($components as $component) { if (isset($query->{$component}) && !empty($query->{$component})) { @@ -148,6 +129,35 @@ class Grammar extends GrammarAbstract return $sql; } + /** + * Get query components based on query type. + * + * @param int $type Query type + * + * @return array Array of components to build query + * + * @throws \InvalidArgumentException Throws this exception if the query type is undefined + * + * @since 1.0.0 + */ + private function getComponents(int $type) : array + { + switch ($type) { + case QueryType::SELECT: + return $components = $this->selectComponents; + case QueryType::INSERT: + return $components = $this->insertComponents; + case QueryType::UPDATE: + return $components = $this->updateComponents; + case QueryType::DELETE: + return $components = $this->deleteComponents; + case QueryType::RANDOM: + return $components = $this->selectComponents; + default: + throw new \InvalidArgumentException('Unknown query type.'); + } + } + /** * Compile select. * @@ -173,7 +183,7 @@ class Grammar extends GrammarAbstract * Compile select. * * @param Builder $query Builder - * @param array $columns Columns + * @param array $table Table * * @return string * @@ -182,7 +192,7 @@ class Grammar extends GrammarAbstract protected function compileUpdates(Builder $query, array $table) : string { $expression = $this->expressionizeTable($table, $query->getPrefix()); - + if ($expression === '') { return ''; } @@ -244,7 +254,7 @@ class Grammar extends GrammarAbstract foreach ($wheres as $key => $where) { foreach ($where as $key2 => $element) { $expression .= $this->compileWhereElement($element, $query, $first); - $first = false; + $first = false; } } @@ -270,7 +280,7 @@ class Grammar extends GrammarAbstract { $expression = ''; - if(!$first) { + if (!$first) { $expression = ' ' . strtoupper($element['boolean']) . ' '; } @@ -289,7 +299,7 @@ class Grammar extends GrammarAbstract if (isset($element['value'])) { $expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix()); } else { - $operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT'; + $operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT'; $expression .= ' ' . $operator . ' ' . $this->compileValue($element['value'], $query->getPrefix()); } @@ -317,7 +327,7 @@ class Grammar extends GrammarAbstract protected function compileValue($value, $prefix = '') : string { if (is_string($value)) { - if(strpos($value, ':') === 0) { + if (strpos($value, ':') === 0) { return $value; } @@ -420,11 +430,11 @@ class Grammar extends GrammarAbstract $expression = ''; foreach ($orders as $key => $order) { - foreach($order as $column) { + foreach ($order as $column) { $expression .= $this->compileSystem($column, $query->getPrefix()) . ', '; } - $expression = rtrim($expression, ', '); + $expression = rtrim($expression, ', '); $expression .= ' ' . $key . ', '; } diff --git a/DataStorage/Database/Query/Grammar/GrammarInterface.php b/DataStorage/Database/Query/Grammar/GrammarInterface.php index 1624f18bd..b43f4bc3e 100644 --- a/DataStorage/Database/Query/Grammar/GrammarInterface.php +++ b/DataStorage/Database/Query/Grammar/GrammarInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; diff --git a/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php b/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php index 00214fbb5..bb13fcde8 100644 --- a/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php +++ b/DataStorage/Database/Query/Grammar/MicrosoftGrammar.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; + use phpOMS\DataStorage\Database\Query\Builder; /** * Grammar class. * - * @category Framework - * @package phpOMS\DataStorage\Database\Query\Grammar + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MicrosoftGrammar extends Grammar diff --git a/DataStorage/Database/Query/Grammar/MysqlGrammar.php b/DataStorage/Database/Query/Grammar/MysqlGrammar.php index 082535a71..5664cc8e9 100644 --- a/DataStorage/Database/Query/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Query/Grammar/MysqlGrammar.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; + use phpOMS\DataStorage\Database\Query\Builder; /** * Grammar class. * - * @category Framework - * @package phpOMS\DataStorage\Database\Query\Grammar + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MysqlGrammar extends Grammar diff --git a/DataStorage/Database/Query/Grammar/OracleGrammar.php b/DataStorage/Database/Query/Grammar/OracleGrammar.php index df49c2ea4..2211c5f3b 100644 --- a/DataStorage/Database/Query/Grammar/OracleGrammar.php +++ b/DataStorage/Database/Query/Grammar/OracleGrammar.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; + use phpOMS\DataStorage\Database\Query\Builder; /** * Grammar class. * - * @category Framework - * @package phpOMS\DataStorage\Database\Query\Grammar + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class OracleGrammar extends Grammar diff --git a/DataStorage/Database/Query/Grammar/PostgresGrammar.php b/DataStorage/Database/Query/Grammar/PostgresGrammar.php index a29215e9f..6a8aae5cd 100644 --- a/DataStorage/Database/Query/Grammar/PostgresGrammar.php +++ b/DataStorage/Database/Query/Grammar/PostgresGrammar.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; + use phpOMS\DataStorage\Database\Query\Builder; /** * Grammar class. * - * @category Framework - * @package phpOMS\DataStorage\Database\Query\Grammar + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PostgresGrammar extends Grammar diff --git a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php index 80d950103..c2c53ccbe 100644 --- a/DataStorage/Database/Query/Grammar/SQLiteGrammar.php +++ b/DataStorage/Database/Query/Grammar/SQLiteGrammar.php @@ -4,25 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query\Grammar; + use phpOMS\DataStorage\Database\Query\Builder; /** * Grammar class. * - * @category Framework - * @package phpOMS\DataStorage\Database\Query\Grammar + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SqliteGrammar extends Grammar diff --git a/DataStorage/Database/Query/JoinType.php b/DataStorage/Database/Query/JoinType.php index 449a165cd..1d9bfdd01 100644 --- a/DataStorage/Database/Query/JoinType.php +++ b/DataStorage/Database/Query/JoinType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; @@ -20,23 +19,22 @@ use phpOMS\Stdlib\Base\Enum; /** * Query type enum. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class JoinType extends Enum { - /* public */ const JOIN = 'JOIN'; - /* public */ const LEFT_JOIN = 'LEFT JOIN'; - /* public */ const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN'; - /* public */ const LEFT_INNER_JOIN = 'LEFT INNER JOIN'; - /* public */ const RIGHT_JOIN = 'RIGHT JOIN'; + /* public */ const JOIN = 'JOIN'; + /* public */ const LEFT_JOIN = 'LEFT JOIN'; + /* public */ const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN'; + /* public */ const LEFT_INNER_JOIN = 'LEFT INNER JOIN'; + /* public */ const RIGHT_JOIN = 'RIGHT JOIN'; /* public */ const RIGHT_OUTER_JOIN = 'RIGHT OUTER JOIN'; /* public */ const RIGHT_INNER_JOIN = 'RIGHT INNER JOIN'; - /* public */ const OUTER_JOIN = 'OUTER JOIN'; - /* public */ const INNER_JOIN = 'INNER JOIN'; - /* public */ const CROSS_JOIN = 'CROSS JOIN'; - /* public */ const FULL_OUTER_JOIN = 'FULL OUTER JOIN'; + /* public */ const OUTER_JOIN = 'OUTER JOIN'; + /* public */ const INNER_JOIN = 'INNER JOIN'; + /* public */ const CROSS_JOIN = 'CROSS JOIN'; + /* public */ const FULL_OUTER_JOIN = 'FULL OUTER JOIN'; } diff --git a/DataStorage/Database/Query/QueryType.php b/DataStorage/Database/Query/QueryType.php index 40481343b..62d20fe00 100644 --- a/DataStorage/Database/Query/QueryType.php +++ b/DataStorage/Database/Query/QueryType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Query type enum. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class QueryType extends Enum @@ -33,5 +31,5 @@ abstract class QueryType extends Enum /* public */ const UPDATE = 2; /* public */ const DELETE = 3; /* public */ const RANDOM = 4; - /* public */ const RAW = 5; + /* public */ const RAW = 5; } diff --git a/DataStorage/Database/Query/Where.php b/DataStorage/Database/Query/Where.php index d2af3ccd0..bb17d3f5e 100644 --- a/DataStorage/Database/Query/Where.php +++ b/DataStorage/Database/Query/Where.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Query; /** * Database query builder. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Where diff --git a/DataStorage/Database/RelationType.php b/DataStorage/Database/RelationType.php index 2ce47c83c..46299ffc4 100644 --- a/DataStorage/Database/RelationType.php +++ b/DataStorage/Database/RelationType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RelationType extends Enum diff --git a/DataStorage/Database/Schema/Builder.php b/DataStorage/Database/Schema/Builder.php index c330dcf38..cf501672e 100644 --- a/DataStorage/Database/Schema/Builder.php +++ b/DataStorage/Database/Schema/Builder.php @@ -4,28 +4,25 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema; use phpOMS\DataStorage\Database\BuilderAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; -use phpOMS\DataStorage\Database\Query; /** * Database query builder. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Builder extends BuilderAbstract @@ -49,16 +46,16 @@ class Builder extends BuilderAbstract public function select(...$table) /* : void */ { - $this->type = QueryType::SELECT; + $this->type = QueryType::SELECT; $this->table += $table; - $this->table = array_unique($this->table); + $this->table = array_unique($this->table); } public function drop(...$table) { - $this->type = QueryType::DROP; + $this->type = QueryType::DROP; $this->drop += $table; - $this->drop = array_unique($this->drop); + $this->drop = array_unique($this->drop); } public function create(string $table) diff --git a/DataStorage/Database/Schema/Exception/TableException.php b/DataStorage/Database/Schema/Exception/TableException.php index b69bc0cc9..9f039b6ef 100644 --- a/DataStorage/Database/Schema/Exception/TableException.php +++ b/DataStorage/Database/Schema/Exception/TableException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Exception; /** * Path exception class. * - * @category System - * @package Framework + * @package System * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class TableException extends \PDOException @@ -31,7 +29,7 @@ class TableException extends \PDOException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/Database/Schema/Grammar/Grammar.php b/DataStorage/Database/Schema/Grammar/Grammar.php index 406c92f4d..e1daa4acc 100644 --- a/DataStorage/Database/Schema/Grammar/Grammar.php +++ b/DataStorage/Database/Schema/Grammar/Grammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; @@ -22,10 +21,9 @@ use phpOMS\DataStorage\Database\Schema\QueryType; /** * Database query grammar. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Grammar extends GrammarAbstract diff --git a/DataStorage/Database/Schema/Grammar/GrammarInterface.php b/DataStorage/Database/Schema/Grammar/GrammarInterface.php index b3dc4695e..114be6b8b 100644 --- a/DataStorage/Database/Schema/Grammar/GrammarInterface.php +++ b/DataStorage/Database/Schema/Grammar/GrammarInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; diff --git a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php index 53f4102c8..56b9b740a 100644 --- a/DataStorage/Database/Schema/Grammar/MysqlGrammar.php +++ b/DataStorage/Database/Schema/Grammar/MysqlGrammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\Query\Builder; /** * Database query grammar. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MysqlGrammar extends Grammar diff --git a/DataStorage/Database/Schema/Grammar/PostgresGrammar.php b/DataStorage/Database/Schema/Grammar/PostgresGrammar.php index fb6868741..bb96c6f9b 100644 --- a/DataStorage/Database/Schema/Grammar/PostgresGrammar.php +++ b/DataStorage/Database/Schema/Grammar/PostgresGrammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; diff --git a/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php b/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php index 864ea36cd..7c5457097 100644 --- a/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php +++ b/DataStorage/Database/Schema/Grammar/SQLiteGrammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; diff --git a/DataStorage/Database/Schema/Grammar/SqlServerGrammar.php b/DataStorage/Database/Schema/Grammar/SqlServerGrammar.php index c9ee5d5b8..c3a578351 100644 --- a/DataStorage/Database/Schema/Grammar/SqlServerGrammar.php +++ b/DataStorage/Database/Schema/Grammar/SqlServerGrammar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema\Grammar; diff --git a/DataStorage/Database/Schema/QueryType.php b/DataStorage/Database/Schema/QueryType.php index 98cbba489..c0eee8f5a 100644 --- a/DataStorage/Database/Schema/QueryType.php +++ b/DataStorage/Database/Schema/QueryType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Database\Schema; @@ -22,16 +21,15 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class QueryType extends Enum { /* public */ const SELECT = 0; /* public */ const CREATE = 1; - /* public */ const DROP = 2; - /* public */ const ALTER = 3; + /* public */ const DROP = 2; + /* public */ const ALTER = 3; } diff --git a/DataStorage/LockException.php b/DataStorage/LockException.php index b00a96209..67df0947b 100644 --- a/DataStorage/LockException.php +++ b/DataStorage/LockException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage; /** * Permission exception class. * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LockException extends \RuntimeException @@ -31,7 +29,7 @@ class LockException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/DataStorage/Session/ConsoleSession.php b/DataStorage/Session/ConsoleSession.php index 70b2a09f9..e76abc2f7 100644 --- a/DataStorage/Session/ConsoleSession.php +++ b/DataStorage/Session/ConsoleSession.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Session; /** * Console session class. * - * @category Framework - * @package phpOMS\DataStorage\Session + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ConsoleSession implements SessionInterface @@ -93,4 +91,10 @@ class ConsoleSession implements SessionInterface { } + /** + * {@inheritdoc} + */ + public function lock() + { + } } diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 8101b7553..fa132b018 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Session; @@ -22,11 +21,12 @@ use phpOMS\DataStorage\LockException; /** * Http session class. * - * @category Framework - * @package phpOMS\DataStorage\Session + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ class HttpSession implements SessionInterface { @@ -54,7 +54,7 @@ class HttpSession implements SessionInterface * @since 1.0.0 */ private $sid = null; - + /** * Inactivity Interval. * @@ -80,26 +80,30 @@ class HttpSession implements SessionInterface throw new LockException('HttpSession'); } + if (session_id()) { + session_write_close(); + } + if (!is_bool($sid)) { session_id($sid); } - + $this->inactivityInterval = $inactivityInterval; - if(session_status() !== PHP_SESSION_ACTIVE && !headers_sent()) { + if (session_status() !== PHP_SESSION_ACTIVE && !headers_sent()) { 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->sessionData = $_SESSION; - $_SESSION = null; + + $this->sessionData = $_SESSION; + $_SESSION = null; $this->sessionData['lastActivity'] = time(); - $this->sid = session_id(); - + $this->sid = session_id(); + $this->setCsrfProtection(); } @@ -112,12 +116,12 @@ class HttpSession implements SessionInterface { $this->set('UID', 0, false); - if (($CSRF = $this->get('CSRF')) === null) { - $CSRF = StringUtils::generateString(10, 16); - $this->set('CSRF', $CSRF, false); + if (($csrf = $this->get('CSRF')) === null) { + $csrf = StringUtils::generateString(10, 16); + $this->set('CSRF', $csrf, false); } - UriFactory::setQuery('$CSRF', $CSRF); + UriFactory::setQuery('$CSRF', $csrf); } /** @@ -143,11 +147,9 @@ class HttpSession implements SessionInterface } /** - * Lock session from further adjustments. - * - * @since 1.0.0 + * {@inheritdoc} */ - public function lock() + public function lock() /* : void */ { self::$isLocked = true; } @@ -169,7 +171,7 @@ class HttpSession implements SessionInterface */ public function save() /* : void */ { - if(!self::$isLocked) { + if (!self::$isLocked) { $_SESSION = $this->sessionData; session_write_close(); } @@ -204,7 +206,14 @@ class HttpSession implements SessionInterface { $this->sid = $sid; } - + + /** + * Destroy the current session. + * + * @return void + * + * @since 1.0.0 + */ private function destroy() /* : void */ { session_destroy(); @@ -221,5 +230,4 @@ class HttpSession implements SessionInterface { $this->save(); } - } diff --git a/DataStorage/Session/SessionInterface.php b/DataStorage/Session/SessionInterface.php index d69d2e427..3aa2e9449 100644 --- a/DataStorage/Session/SessionInterface.php +++ b/DataStorage/Session/SessionInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Session; @@ -20,10 +19,9 @@ namespace phpOMS\DataStorage\Session; * * Sessions can be used by http requests, console interaction and socket connections * - * @category Framework - * @package phpOMS\DataStorage\Cache + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface SessionInterface @@ -73,7 +71,7 @@ interface SessionInterface * * @since 1.0.0 */ - public function save() /* : void */; + public function save(); /* : void */ /** * @return int|string @@ -89,6 +87,14 @@ interface SessionInterface * * @since 1.0.0 */ - public function setSID($sid) /* : void */; + public function setSID($sid); /* : void */ + /** + * Lock session from further adjustments. + * + * @return void + * + * @since 1.0.0 + */ + public function lock(); /* : void */ } diff --git a/DataStorage/Session/SocketSession.php b/DataStorage/Session/SocketSession.php index 464068d6e..03317afe8 100644 --- a/DataStorage/Session/SocketSession.php +++ b/DataStorage/Session/SocketSession.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\DataStorage\Session; /** * Socket session class. * - * @category Framework - * @package phpOMS\DataStorage\Session + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SocketSession implements SessionInterface @@ -93,4 +91,10 @@ class SocketSession implements SessionInterface { } + /** + * {@inheritdoc} + */ + public function lock() + { + } } diff --git a/DataStorage/Web/Builder.php b/DataStorage/Web/Builder.php index cef7ce903..d2989c42a 100644 --- a/DataStorage/Web/Builder.php +++ b/DataStorage/Web/Builder.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Crawler; use phpOMs\DataStorage\Database\Query\Builder as DatabaseQueryBuilder; +use phpOMS\Localization\Localization; +use phpOMS\Message\Http\Rest; +use phpOMS\Uri\Http; /** * Array utils. * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Builder extends DatabaseQueryBuilder @@ -31,9 +32,9 @@ class Builder extends DatabaseQueryBuilder private function download($uri) { $finder = []; - $l11n = new Localization(); - - foreach($this->from as $from) { + $l11n = new Localization(); + + foreach ($this->from as $from) { $doc = new \DOMDocument(); $doc->loadHTML(Rest::request($l11n, new Http($from))); $finder[$from] = new \DomXPath($doc); @@ -41,33 +42,33 @@ class Builder extends DatabaseQueryBuilder return $finder; } - + public function get(string $xpath) { $nodes = $finder->query($xpath); } - + public function execute() { $finder = $this->download(); $result = []; - $table = null; + $table = null; - foreach($this->wheres as $column => $where) { - if($column === 'xpath') { + foreach ($this->wheres as $column => $where) { + if ($column === 'xpath') { $table = $this->createTable($finder->query($where['value'])); } } - foreach($this->columns as $column) { + foreach ($this->columns as $column) { } } private function createTable($node) : array { - if(strtolower($node->tagName) === 'table') { + if (strtolower($node->tagName) === 'table') { return $this->createTableFromTable(); - } elseif(strtolower($node->tagName) === 'li') { + } elseif (strtolower($node->tagName) === 'li') { return $this->createTableFromList(); } else { return $this->createTableFromContent(); @@ -85,13 +86,13 @@ class Builder extends DatabaseQueryBuilder private function createTableFromList($node) : array { - $table = []; + $table = []; $children = $node->childNodes; - foreach($children as $child) { + foreach ($children as $child) { $table[] = $child->asXML(); } - + return $table; } diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index ba8786ae8..c0da79424 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Dispatcher * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Dispatcher; @@ -22,10 +21,9 @@ use phpOMS\System\File\PathException; /** * Dispatcher class. * - * @category Framework * @package phpOMS\Dispatcher * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Dispatcher @@ -106,13 +104,17 @@ class Dispatcher { $views = []; $dispatch = explode(':', $controller); - $this->getController($dispatch[0]); + + if (!file_exists($path = __DIR__ . '/../../' . str_replace('\\', '/', $dispatch[0]) . '.php')) { + throw new PathException($path); + } if (($c = count($dispatch)) === 3) { /* Handling static functions */ $function = $dispatch[0] . '::' . $dispatch[2]; $views[$controller] = $function(...$data); } elseif ($c === 2) { + $this->getController($dispatch[0]); $views[$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}(...$data); } else { throw new \UnexpectedValueException('Unexpected function.'); @@ -170,13 +172,9 @@ class Dispatcher private function getController(string $controller) /* : object */ { if (!isset($this->controllers[$controller])) { - if (!file_exists($path = __DIR__ . '/../../' . str_replace('\\', '/', $controller) . '.php')) { - throw new PathException($path); - } - // If module controller use module manager for initialization - if(strpos('\Modules\Controller', $controller) === 0) { - $split = explode('\\', $controller); + if (strpos('\Modules\Controller', $controller) === 0) { + $split = explode('\\', $controller); $this->controllers[$controller] = $this->app->moduleManager->get($split[2]); } else { $this->controllers[$controller] = new $controller($this->app); diff --git a/Event/EventManager.php b/Event/EventManager.php index ecdd60481..eafbc5d56 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Event * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Event; /** * EventManager class. * - * @category Framework * @package phpOMS\Event * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 * * @todo : make cachable + database storable -> can reload user defined listeners (persistent events) @@ -89,7 +87,7 @@ class EventManager */ public function trigger(string $group, string $id = '', $data = null) : bool { - if(!isset($this->callbacks[$group])) { + if (!isset($this->callbacks[$group])) { return false; } @@ -102,7 +100,7 @@ class EventManager if ($this->callbacks[$group]['remove']) { $this->detach($group); - } elseif($this->callbacks[$group]['reset']) { + } elseif ($this->callbacks[$group]['reset']) { $this->reset($group); } @@ -123,7 +121,7 @@ class EventManager */ private function reset(string $group) /* : void */ { - foreach($this->groups[$group] as $id => $ok) { + foreach ($this->groups[$group] as $id => $ok) { $this->groups[$group][$id] = false; } } @@ -139,12 +137,12 @@ class EventManager */ private function hasOutstanding(string $group) : bool { - if(!isset($this->groups[$group])) { + if (!isset($this->groups[$group])) { return false; } - foreach($this->groups[$group] as $id => $ok) { - if(!$ok) { + foreach ($this->groups[$group] as $id => $ok) { + if (!$ok) { return true; } } @@ -208,5 +206,4 @@ class EventManager { return count($this->callbacks); } - } diff --git a/Localization/Default/Location/localization.sqlite b/Localization/Default/Location/localization.sqlite index 9f7cab4d4..b2cdedb9c 100644 Binary files a/Localization/Default/Location/localization.sqlite and b/Localization/Default/Location/localization.sqlite differ diff --git a/Localization/ISO3166CharEnum.php b/Localization/ISO3166CharEnum.php index 02cf06b0b..7e29f5118 100644 --- a/Localization/ISO3166CharEnum.php +++ b/Localization/ISO3166CharEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO3166CharEnum extends Enum @@ -277,4 +275,4 @@ class ISO3166CharEnum extends Enum /* public */ const _YEM = 'YEM'; /* public */ const _ZMB = 'ZMB'; /* public */ const _ZWE = 'ZWE'; -} \ No newline at end of file +} diff --git a/Localization/ISO3166NameEnum.php b/Localization/ISO3166NameEnum.php index f85eecfbe..70fd948ed 100644 --- a/Localization/ISO3166NameEnum.php +++ b/Localization/ISO3166NameEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country names ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO3166NameEnum extends Enum @@ -278,4 +276,4 @@ class ISO3166NameEnum extends Enum /* public */ const _ZMB = 'Zambia'; /* public */ const _ZWE = 'Zimbabwe'; /* public */ const _XKK = 'Kosovo'; -} \ No newline at end of file +} diff --git a/Localization/ISO3166NumEnum.php b/Localization/ISO3166NumEnum.php index 5ba84a9a7..deb6ae371 100644 --- a/Localization/ISO3166NumEnum.php +++ b/Localization/ISO3166NumEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO3166NumEnum extends Enum @@ -277,4 +275,4 @@ class ISO3166NumEnum extends Enum /* public */ const _YEM = '887'; /* public */ const _ZMB = '894'; /* public */ const _ZWE = '716'; -} \ No newline at end of file +} diff --git a/Localization/ISO3166TwoEnum.php b/Localization/ISO3166TwoEnum.php index 68a4162bc..97f53e050 100644 --- a/Localization/ISO3166TwoEnum.php +++ b/Localization/ISO3166TwoEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO3166TwoEnum extends Enum @@ -278,4 +276,4 @@ class ISO3166TwoEnum extends Enum /* public */ const _ZMB = 'ZM'; /* public */ const _ZWE = 'ZW'; /* public */ const _XKK = 'XK'; -} \ No newline at end of file +} diff --git a/Localization/ISO4217CharEnum.php b/Localization/ISO4217CharEnum.php index 03ce8bb89..a9cec523a 100644 --- a/Localization/ISO4217CharEnum.php +++ b/Localization/ISO4217CharEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Currency codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217CharEnum extends Enum diff --git a/Localization/ISO4217DecimalEnum.php b/Localization/ISO4217DecimalEnum.php index 416ee7aaa..2ae15f444 100644 --- a/Localization/ISO4217DecimalEnum.php +++ b/Localization/ISO4217DecimalEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Currency decimals ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217DecimalEnum extends Enum @@ -206,4 +204,4 @@ class ISO4217DecimalEnum extends Enum /* public */ const _YER = 2; /* public */ const _ZAR = 2; /* public */ const _ZMW = 2; -} \ No newline at end of file +} diff --git a/Localization/ISO4217Enum.php b/Localization/ISO4217Enum.php index 09cced948..844326f66 100644 --- a/Localization/ISO4217Enum.php +++ b/Localization/ISO4217Enum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Currency names ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217Enum extends Enum diff --git a/Localization/ISO4217NumEnum.php b/Localization/ISO4217NumEnum.php index b3c574bb7..ec53bf560 100644 --- a/Localization/ISO4217NumEnum.php +++ b/Localization/ISO4217NumEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Currency codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217NumEnum extends Enum @@ -206,4 +204,4 @@ class ISO4217NumEnum extends Enum /* public */ const _YER = '886'; /* public */ const _ZAR = '710'; /* public */ const _ZMW = '967'; -} \ No newline at end of file +} diff --git a/Localization/ISO4217SubUnitEnum.php b/Localization/ISO4217SubUnitEnum.php index 391b8ffc4..c175ecd3d 100644 --- a/Localization/ISO4217SubUnitEnum.php +++ b/Localization/ISO4217SubUnitEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Currency sub units ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217SubUnitEnum extends Enum @@ -182,4 +180,4 @@ class ISO4217SubUnitEnum extends Enum /* public */ const _ZAR = 100; /* public */ const _ZMK = 100; /* public */ const _ZWL = 100; -} \ No newline at end of file +} diff --git a/Localization/ISO4217SymbolEnum.php b/Localization/ISO4217SymbolEnum.php index c4ae80496..f124fb40f 100644 --- a/Localization/ISO4217SymbolEnum.php +++ b/Localization/ISO4217SymbolEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country symbols ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO4217SymbolEnum extends Enum @@ -137,4 +135,4 @@ class ISO4217SymbolEnum extends Enum /* public */ const _VND = '₫'; /* public */ const _YER = '﷼'; /* public */ const _ZWD = 'Z$'; -} \ No newline at end of file +} diff --git a/Localization/ISO639Enum.php b/Localization/ISO639Enum.php index 110c3216f..a356fb851 100644 --- a/Localization/ISO639Enum.php +++ b/Localization/ISO639Enum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Language name ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO639Enum extends Enum diff --git a/Localization/ISO639x1Enum.php b/Localization/ISO639x1Enum.php index f88b890cf..f472cd085 100644 --- a/Localization/ISO639x1Enum.php +++ b/Localization/ISO639x1Enum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Language codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO639x1Enum extends Enum diff --git a/Localization/ISO639x2Enum.php b/Localization/ISO639x2Enum.php index f5cb1cfed..d7a0ab867 100644 --- a/Localization/ISO639x2Enum.php +++ b/Localization/ISO639x2Enum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Language codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO639x2Enum extends Enum diff --git a/Localization/ISO8601EnumArray.php b/Localization/ISO8601EnumArray.php index 2524fb9d8..838f63761 100644 --- a/Localization/ISO8601EnumArray.php +++ b/Localization/ISO8601EnumArray.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -23,10 +22,9 @@ use phpOMS\Stdlib\Base\EnumArray; * Careful only (1) is considered as the ISO8601 standard. This file is only supposed to * contain all plausible datetime strings. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ISO8601EnumArray extends EnumArray diff --git a/Localization/L11nManager.php b/Localization/L11nManager.php index c4157e707..70d8bc063 100644 --- a/Localization/L11nManager.php +++ b/Localization/L11nManager.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -21,10 +20,9 @@ use phpOMS\Module\ModuleAbstract; /** * Localization class. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class L11nManager @@ -133,7 +131,7 @@ class L11nManager } elseif (isset($this->language[$language], $this->language[$language][$module])) { return $this->language[$language][$module]; } - + return []; } @@ -160,7 +158,7 @@ class L11nManager if (!isset($this->language[$code][$module][$translation])) { return 'ERROR'; } - } catch(\Exception $e) { + } catch (\Exception $e) { FileLogger::getInstance()->warning(FileLogger::MSG_FULL, [ 'message' => 'Undefined translation for \'' . $code . '/' . $module . '/' . $translation . '\'.', ]); diff --git a/Localization/Localization.php b/Localization/Localization.php index 3982f65a4..1bff75e75 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -22,10 +21,9 @@ use phpOMS\Utils\Converter\TemperatureType; /** * Localization class. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Localization @@ -221,7 +219,7 @@ class Localization public function setLanguage(string $language) /* : void */ { $language = strtolower($language); - + if (!ISO639x1Enum::isValidValue($language)) { throw new InvalidEnumValue($language); } @@ -364,4 +362,114 @@ class Localization { $this->temperature = $temperature; } + + /** + * @return array + * + * @since 1.0.0 + */ + public function getSpeed() : array + { + return $this->speed; + } + + /** + * @param array $speed + * + * @return array + * + * @since 1.0.0 + */ + public function setSpeed(array $speed) /* : void */ + { + $this->speed = $speed; + } + + /** + * @return array + * + * @since 1.0.0 + */ + public function getWeight() : array + { + return $this->weight; + } + + /** + * @param array $weight + * + * @return array + * + * @since 1.0.0 + */ + public function setWeight(array $weight) /* : void */ + { + $this->weight = $weight; + } + + /** + * @return array + * + * @since 1.0.0 + */ + public function getLength() : array + { + return $this->length; + } + + /** + * @param array $length + * + * @return array + * + * @since 1.0.0 + */ + public function setLength(array $length) /* : void */ + { + $this->length = $length; + } + + /** + * @return array + * + * @since 1.0.0 + */ + public function getArea() : array + { + return $this->area; + } + + /** + * @param array $area + * + * @return array + * + * @since 1.0.0 + */ + public function setArea(array $area) /* : void */ + { + $this->area = $area; + } + + /** + * @return array + * + * @since 1.0.0 + */ + public function getVolume() : array + { + return $this->volume; + } + + /** + * @param array $volume + * + * @return array + * + * @since 1.0.0 + */ + public function setVolume(array $volume) /* : void */ + { + $this->volume = $volume; + } } diff --git a/Localization/Money.php b/Localization/Money.php index 3d805fbe0..ccdf35dd3 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; /** * Money class. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Money implements \Serializable @@ -210,7 +208,7 @@ class Money implements \Serializable $this->value += $value; } elseif ($value instanceof Money) { $this->value += $value->getInt(); - } + } return $this; } @@ -244,7 +242,7 @@ class Money implements \Serializable $this->value -= $value; } elseif ($value instanceof Money) { $this->value -= $value->getInt(); - } + } return $this; } diff --git a/Localization/NullLocalization.php b/Localization/NullLocalization.php index 15d21810d..c76cdc661 100644 --- a/Localization/NullLocalization.php +++ b/Localization/NullLocalization.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; /** * Localization class. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullLocalization extends Localization diff --git a/Localization/PhoneEnum.php b/Localization/PhoneEnum.php index 9cc663db8..bae73640c 100644 --- a/Localization/PhoneEnum.php +++ b/Localization/PhoneEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Country codes ISO list. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PhoneEnum extends Enum diff --git a/Localization/TimeZoneEnumArray.php b/Localization/TimeZoneEnumArray.php index 0c5ea8276..f891a35ba 100644 --- a/Localization/TimeZoneEnumArray.php +++ b/Localization/TimeZoneEnumArray.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Localization; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\EnumArray; /** * PHP Time zones. * - * @category Framework - * @package phpOMS\Localization + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class TimeZoneEnumArray extends EnumArray diff --git a/Log/FileLogger.php b/Log/FileLogger.php index 4bdbe4461..6feff27b3 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Log * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Log; @@ -21,17 +20,18 @@ use phpOMS\System\File\Local\File; /** * Logging class. * - * @category Framework * @package phpOMS\Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ class FileLogger implements LoggerInterface { /* public */ const MSG_BACKTRACE = '{datetime}; {level}; {ip}; {message}; {backtrace}'; - /* public */ const MSG_FULL = '{datetime}; {level}; {ip}; {line}; {version}; {os}; {path}; {message}; {file}; {backtrace}'; - /* public */ const MSG_SIMPLE = '{datetime}; {level}; {ip}; {message};'; + /* public */ const MSG_FULL = '{datetime}; {level}; {ip}; {line}; {version}; {os}; {path}; {message}; {file}; {backtrace}'; + /* public */ const MSG_SIMPLE = '{datetime}; {level}; {ip}; {message};'; /** * Timing array. @@ -180,7 +180,7 @@ class FileLogger implements LoggerInterface */ public static function startTimeLog($id = '') : bool { - if(isset(self::$timings[$id])) { + if (isset(self::$timings[$id])) { return false; } @@ -197,7 +197,7 @@ class FileLogger implements LoggerInterface * * @param string $id the ID by which this time measurement gets identified * - * @return int The time measurement in ms + * @return float The time measurement in ms * * @since 1.0.0 */ @@ -265,7 +265,7 @@ class FileLogger implements LoggerInterface private function write(string $message) /* : void */ { $this->createFile(); - if(!is_writable($this->path)) { + if (!is_writable($this->path)) { return; } @@ -453,24 +453,26 @@ class FileLogger implements LoggerInterface { $levels = []; - if (file_exists($this->path)) { - $this->fp = fopen($this->path, 'r'); - fseek($this->fp, 0); + if (!file_exists($this->path)) { + return $levels; + } - while (($line = fgetcsv($this->fp, 0, ';')) !== false) { - $line[1] = trim($line[1]); + $this->fp = fopen($this->path, 'r'); + fseek($this->fp, 0); - if (!isset($levels[$line[1]])) { - $levels[$line[1]] = 0; - } + while (($line = fgetcsv($this->fp, 0, ';')) !== false) { + $line[1] = trim($line[1]); - $levels[$line[1]]++; + if (!isset($levels[$line[1]])) { + $levels[$line[1]] = 0; } - fseek($this->fp, 0, SEEK_END); - fclose($this->fp); + $levels[$line[1]]++; } + fseek($this->fp, 0, SEEK_END); + fclose($this->fp); + return $levels; } @@ -481,29 +483,31 @@ class FileLogger implements LoggerInterface * * @return array */ - public function getHighestPerpetrator(int $limit = 10) + public function getHighestPerpetrator(int $limit = 10) : array { $connection = []; - if (file_exists($this->path)) { - $this->fp = fopen($this->path, 'r'); - fseek($this->fp, 0); + if (!file_exists($this->path)) { + return $connection; + } - while (($line = fgetcsv($this->fp, 0, ';')) !== false) { - $line[2] = trim($line[2]); + $this->fp = fopen($this->path, 'r'); + fseek($this->fp, 0); - if (!isset($connection[$line[2]])) { - $connection[$line[2]] = 0; - } + while (($line = fgetcsv($this->fp, 0, ';')) !== false) { + $line[2] = trim($line[2]); - $connection[$line[2]]++; + if (!isset($connection[$line[2]])) { + $connection[$line[2]] = 0; } - fseek($this->fp, 0, SEEK_END); - fclose($this->fp); - asort($connection); + $connection[$line[2]]++; } + fseek($this->fp, 0, SEEK_END); + fclose($this->fp); + asort($connection); + return array_slice($connection, 0, $limit); } @@ -520,37 +524,38 @@ class FileLogger implements LoggerInterface $logs = []; $id = 0; - if (file_exists($this->path)) { - $this->fp = fopen($this->path, 'r'); - fseek($this->fp, 0); + if (!file_exists($this->path)) { + return $logs; + } - while (($line = fgetcsv($this->fp, 0, ';')) !== false) { - $id++; + $this->fp = fopen($this->path, 'r'); + fseek($this->fp, 0); - if ($offset > 0) { - $offset--; - continue; - } + while (($line = fgetcsv($this->fp, 0, ';')) !== false) { + $id++; - if ($limit <= 0) { - - reset($logs); - unset($logs[key($logs)]); - } - - foreach ($line as &$value) { - $value = trim($value); - } - - $logs[$id] = $line; - $limit--; - ksort($logs); + if ($offset > 0) { + $offset--; + continue; } - fseek($this->fp, 0, SEEK_END); - fclose($this->fp); + if ($limit <= 0) { + reset($logs); + unset($logs[key($logs)]); + } + + foreach ($line as &$value) { + $value = trim($value); + } + + $logs[$id] = $line; + $limit--; + ksort($logs); } + fseek($this->fp, 0, SEEK_END); + fclose($this->fp); + return $logs; } @@ -566,35 +571,36 @@ class FileLogger implements LoggerInterface $log = []; $current = 0; - if (file_exists($this->path)) { - $this->fp = fopen($this->path, 'r'); - fseek($this->fp, 0); + if (!file_exists($this->path)) { + return $log; + } - while (($line = fgetcsv($this->fp, 0, ';')) !== false && $current <= $id) { - $current++; + $this->fp = fopen($this->path, 'r'); + fseek($this->fp, 0); - if ($current < $id) { - continue; - } + while (($line = fgetcsv($this->fp, 0, ';')) !== false && $current <= $id) { + $current++; - $log['datetime'] = trim($line[0] ?? ''); - $log['level'] = trim($line[1] ?? ''); - $log['ip'] = trim($line[2] ?? ''); - $log['line'] = trim($line[3] ?? ''); - $log['version'] = trim($line[4] ?? ''); - $log['os'] = trim($line[5] ?? ''); - $log['path'] = trim($line[6] ?? ''); - $log['message'] = trim($line[7] ?? ''); - $log['file'] = trim($line[8] ?? ''); - $log['backtrace'] = trim($line[9] ?? ''); - - break; + if ($current < $id) { + continue; } - fseek($this->fp, 0, SEEK_END); - fclose($this->fp); + $log['datetime'] = trim($line[0] ?? ''); + $log['level'] = trim($line[1] ?? ''); + $log['ip'] = trim($line[2] ?? ''); + $log['line'] = trim($line[3] ?? ''); + $log['version'] = trim($line[4] ?? ''); + $log['os'] = trim($line[5] ?? ''); + $log['path'] = trim($line[6] ?? ''); + $log['message'] = trim($line[7] ?? ''); + $log['file'] = trim($line[8] ?? ''); + $log['backtrace'] = trim($line[9] ?? ''); + break; } + fseek($this->fp, 0, SEEK_END); + fclose($this->fp); + return $log; } diff --git a/Log/LogLevel.php b/Log/LogLevel.php index c12411d4d..195bc6540 100644 --- a/Log/LogLevel.php +++ b/Log/LogLevel.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Log * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Log; @@ -20,20 +19,19 @@ use phpOMS\Stdlib\Base\Enum; /** * Log level enum. * - * @category Framework * @package phpOMS\Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class LogLevel extends Enum { /* public */ const EMERGENCY = 'emergency'; - /* public */ const ALERT = 'alert'; - /* public */ const CRITICAL = 'critical'; - /* public */ const ERROR = 'error'; - /* public */ const WARNING = 'warning'; - /* public */ const NOTICE = 'notice'; - /* public */ const INFO = 'info'; - /* public */ const DEBUG = 'debug'; + /* public */ const ALERT = 'alert'; + /* public */ const CRITICAL = 'critical'; + /* public */ const ERROR = 'error'; + /* public */ const WARNING = 'warning'; + /* public */ const NOTICE = 'notice'; + /* public */ const INFO = 'info'; + /* public */ const DEBUG = 'debug'; } diff --git a/Log/LoggerInterface.php b/Log/LoggerInterface.php index 574763d69..ea6b800a4 100644 --- a/Log/LoggerInterface.php +++ b/Log/LoggerInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Log * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Log; /** * Logging interface. * - * @category Framework * @package phpOMS\Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface LoggerInterface @@ -35,7 +33,7 @@ interface LoggerInterface * * @return null */ - public function emergency(string $message, array $context = []) /* : void */; + public function emergency(string $message, array $context = []); /* : void */ /** * Action must be taken immediately. @@ -48,7 +46,7 @@ interface LoggerInterface * * @return null */ - public function alert(string $message, array $context = []) /* : void */; + public function alert(string $message, array $context = []); /* : void */ /** * Critical conditions. @@ -60,7 +58,7 @@ interface LoggerInterface * * @return null */ - public function critical(string $message, array $context = []) /* : void */; + public function critical(string $message, array $context = []); /* : void */ /** * Runtime errors that do not require immediate action but should typically @@ -71,7 +69,7 @@ interface LoggerInterface * * @return null */ - public function error(string $message, array $context = []) /* : void */; + public function error(string $message, array $context = []); /* : void */ /** * Exceptional occurrences that are not errors. @@ -84,7 +82,7 @@ interface LoggerInterface * * @return null */ - public function warning(string $message, array $context = []) /* : void */; + public function warning(string $message, array $context = []); /* : void */ /** * Normal but significant events. @@ -94,7 +92,7 @@ interface LoggerInterface * * @return null */ - public function notice(string $message, array $context = []) /* : void */; + public function notice(string $message, array $context = []); /* : void */ /** * Interesting events. @@ -106,7 +104,7 @@ interface LoggerInterface * * @return null */ - public function info(string $message, array $context = []) /* : void */; + public function info(string $message, array $context = []); /* : void */ /** * Detailed debug information. @@ -116,7 +114,7 @@ interface LoggerInterface * * @return null */ - public function debug(string $message, array $context = []) /* : void */; + public function debug(string $message, array $context = []); /* : void */ /** * Logs with an arbitrary level. @@ -127,5 +125,5 @@ interface LoggerInterface * * @return null */ - public function log(string $level, string $message, array $context = []) /* : void */; + public function log(string $level, string $message, array $context = []); /* : void */ } diff --git a/Math/Differential/FiniteDifference.php b/Math/Differential/FiniteDifference.php index 892c93f4e..c66795868 100644 --- a/Math/Differential/FiniteDifference.php +++ b/Math/Differential/FiniteDifference.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Differential; @@ -20,10 +19,9 @@ use phpOMS\Math\Parser\Evaluator; /** * Chi square distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class FiniteDifference diff --git a/Math/Exception/ZeroDevisionException.php b/Math/Exception/ZeroDevisionException.php index 74bad5cfd..303ba110d 100644 --- a/Math/Exception/ZeroDevisionException.php +++ b/Math/Exception/ZeroDevisionException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Exception; /** * Zero devision exception. * - * @category Framework - * @package phpOMS/Uri + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ZeroDevisionException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class ZeroDevisionException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Math/Functions/Fibunacci.php b/Math/Functions/Fibunacci.php index e886f9c4f..068ddd060 100644 --- a/Math/Functions/Fibunacci.php +++ b/Math/Functions/Fibunacci.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Functions; @@ -20,10 +19,9 @@ use phpOMS\Math\Number\Numbers; /** * Well known functions class. * - * @category Framework - * @package phpOMS\Math\Function + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Fibunacci @@ -53,20 +51,20 @@ class Fibunacci * * @since 1.0.0 */ - public static function fibunacci(int $n, int $start = 1) : int + public static function fib(int $n, int $start = 1) : int { if ($n < 3) { return $start; } - $old_1 = $start; - $old_2 = $start; - $fib = 0; + $old1 = $start; + $old2 = $start; + $fib = 0; for ($i = 2; $i < $n; $i++) { - $fib = $old_1 + $old_2; - $old_1 = $old_2; - $old_2 = $fib; + $fib = $old1 + $old2; + $old1 = $old2; + $old2 = $fib; } return $fib; @@ -85,4 +83,4 @@ class Fibunacci { return (int) (((1 + sqrt(5)) ** $n - (1 - sqrt(5)) ** $n) / (2 ** $n * sqrt(5))); } -} \ No newline at end of file +} diff --git a/Math/Functions/Functions.php b/Math/Functions/Functions.php index 564f52aa0..0ae2d8970 100644 --- a/Math/Functions/Functions.php +++ b/Math/Functions/Functions.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Functions; /** * Well known functions class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Functions @@ -107,7 +105,7 @@ class Functions $fact2 *= $d; } - return $fact / $fact2; + return (int) ($fact / $fact2); } /** @@ -250,16 +248,16 @@ class Functions * @example The relative fiscal month (August) in a company where the fiscal year starts in July. * @example 2 = getRelativeDegree(8, 12, 7); * - * @param mixed $value Value to get degree - * @param mixed $length Circle size - * @param mixed $start Start value + * @param int $value Value to get degree + * @param int $length Circle size + * @param int $start Start value * * @return int Lowest value is 0 and highest value is length - 1 * * @since 1.0.0 */ - public static function getRelativeDegree($value, $length, $start = 0) : int + public static function getRelativeDegree(int $value, int $length, int $start = 0) : int { - return abs(self::mod($value - $start, $length)); + return (int) abs(self::mod($value - $start, $length)); } } diff --git a/Math/Geometry/ConvexHull/MonotoneChain.php b/Math/Geometry/ConvexHull/MonotoneChain.php index 36d375c13..92d25d6a8 100644 --- a/Math/Geometry/ConvexHull/MonotoneChain.php +++ b/Math/Geometry/ConvexHull/MonotoneChain.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\ConvexHull; /** * Andrew's monotone chain convex hull algorithm class. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 * * @todo : implement vertice class or use vertice class used by graphs? May be usefull in order to give vertices IDs! @@ -42,7 +40,7 @@ final class MonotoneChain if (($n = count($points)) > 1) { uasort($points, [self::class, 'sort']); - $k = 0; + $k = 0; $result = []; // Lower hull @@ -55,7 +53,7 @@ final class MonotoneChain } // 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($result[$k - 2], $result[$k - 1], $points[$i]) <= 0) { $k--; } @@ -65,7 +63,7 @@ final class MonotoneChain ksort($result); - return array_slice($result, 0, $k-1); + return array_slice($result, 0, $k - 1); } return $points; @@ -101,4 +99,4 @@ final class MonotoneChain { return $a['x'] === $b['x'] ? $a['y'] - $b['y'] : $a['x'] - $b['x']; } -} \ No newline at end of file +} diff --git a/Math/Geometry/Shape/D2/Circle.php b/Math/Geometry/Shape/D2/Circle.php index 996785427..9d2630e8a 100644 --- a/Math/Geometry/Shape/D2/Circle.php +++ b/Math/Geometry/Shape/D2/Circle.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Circle shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Circle implements D2ShapeInterface @@ -77,6 +75,9 @@ class Circle implements D2ShapeInterface * @return float * * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseVariableName) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) */ public static function getRadiusByPerimeter(float $C) : float { diff --git a/Math/Geometry/Shape/D2/D2ShapeInterface.php b/Math/Geometry/Shape/D2/D2ShapeInterface.php index 47be0c709..3a12227e7 100644 --- a/Math/Geometry/Shape/D2/D2ShapeInterface.php +++ b/Math/Geometry/Shape/D2/D2ShapeInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; @@ -20,10 +19,9 @@ use phpOMS\Math\Geometry\Shape\ShapeInterface; /** * Shape interface. * - * @category Framework - * @package phpOMS\Math + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface D2ShapeInterface extends ShapeInterface diff --git a/Math/Geometry/Shape/D2/Ellipse.php b/Math/Geometry/Shape/D2/Ellipse.php index 289f1c297..d989ef3c0 100644 --- a/Math/Geometry/Shape/D2/Ellipse.php +++ b/Math/Geometry/Shape/D2/Ellipse.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Ellipse shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Ellipse implements D2ShapeInterface diff --git a/Math/Geometry/Shape/D2/Polygon.php b/Math/Geometry/Shape/D2/Polygon.php index d66af7210..aaa3696bc 100644 --- a/Math/Geometry/Shape/D2/Polygon.php +++ b/Math/Geometry/Shape/D2/Polygon.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Polygon class. * - * @category Framework - * @package phpOMS\Math + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Polygon implements D2ShapeInterface @@ -44,77 +42,18 @@ class Polygon implements D2ShapeInterface */ private $coord = []; - /** - * Polygon perimeter. - * - * @var float - * @since 1.0.0 - */ - private $perimeter = 0.0; - - /** - * Polygon surface. - * - * @var float - * @since 1.0.0 - */ - private $surface = 0.0; - - /** - * Interior angle sum of the polygon. - * - * @var int - * @since 1.0.0 - */ - private $interiorAngleSum = 0; - - /** - * Exterior angle sum of the polygon. - * - * @var float - * @since 1.0.0 - */ - private $exteriorAngleSum = 0.0; - - /** - * Polygon barycenter. - * - * @var float[] - * @since 1.0.0 - */ - private $barycenter = ['x' => 0.0, 'y' => 0.0]; - - /** - * Polygon edge length. - * - * @var float - * @since 1.0.0 - */ - private $edgeLength = 0.0; - - /** - * Polygon inner length. - * - * @var float - * @since 1.0.0 - */ - private $innerLength = 0.0; - - /** - * Polygon inner edge angular. - * - * @var int - * @since 1.0.0 - */ - private $innerEdgeAngular = 0; - /** * Constructor. * + * @param array[] $coord 2 Dimensional coordinate array where the indices are x and y + * + * @example Polygon([['x' => 1, 'y' => 2], ['x' => ...], ...]) + * * @since 1.0.0 */ - public function __construct() + public function __construct(array $coord) { + $this->coord = $coord; } /** @@ -128,7 +67,10 @@ class Polygon implements D2ShapeInterface */ public function pointInPolygon(array $point) : int { - return self::isPointInPolygon($point, $this->coord); + $coord = $this->coord; + $coord[] = $this->coord[0]; + + return self::isPointInPolygon($point, $coord); } /** @@ -137,8 +79,8 @@ class Polygon implements D2ShapeInterface * @param array $point Point location * @param array $polygon Polygon definition * - * @return int - * + * @return int -1 inside polygon 0 on vertice 1 outside + * * @link http://erich.realtimerendering.com/ptinpoly/ * @since 1.0.0 */ @@ -157,11 +99,11 @@ class Polygon implements D2ShapeInterface } // Inside or ontop? - $countIntersect = 0; - $polygon_count = count($polygon); + $countIntersect = 0; + $polygonCount = count($polygon); // todo: return based on highest possibility not by first match - for ($i = 1; $i < $polygon_count; $i++) { + for ($i = 1; $i < $polygonCount; $i++) { $vertex1 = $polygon[$i - 1]; $vertex2 = $polygon[$i]; @@ -182,27 +124,13 @@ class Polygon implements D2ShapeInterface } } - if ($countIntersect % 2 != 0) { + if ($countIntersect % 2 !== 0) { return -1; } return 1; } - /** - * Is point on vertex? - * - * @param array $point Point location - * - * @return bool - * - * @since 1.0.0 - */ - public function onVertex(array $point) : bool - { - return self::isOnVertex($point, $this->coord); - } - /** * Is point on vertex? * @@ -225,47 +153,23 @@ class Polygon implements D2ShapeInterface } /** - * Set polygon coordinates. + * Get interior angle sum * - * @param array[] $coord Coordinates - * - * @return void + * @return int * * @since 1.0.0 */ - public function setCoordinates($coord) /* : void */ - { - $this->coord = $coord; - } - - /** - * Set polygon coordinate. - * - * @param int $i Index - * @param int|float $x X coordinate - * @param int|float $y Y coordinate - * - * @return void - * - * @since 1.0.0 - */ - public function setCoordinate($i, $x, $y) /* : void */ - { - $this->coord[$i] = ['x' => $x, 'y' => $y]; - } - - /** - * {@inheritdoc} - */ public function getInteriorAngleSum() : int { - $this->interiorAngleSum = (count($this->coord) - 2) * 180; - - return $this->interiorAngleSum; + return (count($this->coord) - 2) * 180; } /** - * {@inheritdoc} + * Get exterior angle sum + * + * @return int + * + * @since 1.0.0 */ public function getExteriorAngleSum() { @@ -273,121 +177,85 @@ class Polygon implements D2ShapeInterface } /** - * {@inheritdoc} - */ - public function getInteriorAngleSumFormula() - { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getExteriorAngleSumFormula() - { - return ''; - } - - /** - * {@inheritdoc} + * Get surface area + * + * @return float + * + * @since 1.0.0 */ public function getSurface() : float { - $this->surface = 0.0; - $count = count($this->coord); + return (float) abs($this->getSignedSurface()); + } - for ($i = 0; $i < $count - 2; $i++) { - $this->surface += $this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']; + /** + * Get signed surface area + * + * @return float + * + * @since 1.0.0 + */ + private function getSignedSurface() : float + { + $count = count($this->coord); + $surface = 0; + + for ($i = 0; $i < $count - 1; $i++) { + $surface += $this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']; } - $this->surface /= 2; - $this->surface = abs($this->surface); + $surface += $this->coord[$count - 1]['x'] * $this->coord[0]['y'] - $this->coord[0]['x'] * $this->coord[$count - 1]['y']; + $surface /= 2; - return $this->surface; + return $surface; } /** - * {@inheritdoc} - */ - public function setSurface($surface) /* : void */ - { - $this->reset(); - - $this->surface = $surface; - } - - /** - * {@inheritdoc} - */ - public function reset() /* : void */ - { - $this->coord = []; - $this->barycenter = ['x' => 0.0, 'y' => 0.0]; - $this->perimeter = 0.0; - $this->surface = 0.0; - $this->interiorAngleSum = 0; - $this->edgeLength = 0.0; - $this->innerLength = 0.0; - $this->innerEdgeAngular = 0; - } - - /** - * {@inheritdoc} - */ - public function getSurfaceFormula() - { - return ''; - } - - /** - * {@inheritdoc} + * Get perimeter + * + * @return float + * + * @since 1.0.0 */ public function getPerimeter() : float { - $count = count($this->coord); - $this->perimeter = sqrt(($this->coord[0]['x'] - $this->coord[$count - 1]['x']) ** 2 + ($this->coord[0]['y'] - $this->coord[$count - 1]['y']) ** 2); + $count = count($this->coord); + $perimeter = sqrt(($this->coord[0]['x'] - $this->coord[$count - 1]['x']) ** 2 + ($this->coord[0]['y'] - $this->coord[$count - 1]['y']) ** 2); - for ($i = 0; $i < $count - 2; $i++) { - $this->perimeter += sqrt(($this->coord[$i + 1]['x'] - $this->coord[$i]['x']) ** 2 + ($this->coord[$i + 1]['y'] - $this->coord[$i]['y']) ** 2); + for ($i = 0; $i < $count - 1; $i++) { + $perimeter += sqrt(($this->coord[$i + 1]['x'] - $this->coord[$i]['x']) ** 2 + ($this->coord[$i + 1]['y'] - $this->coord[$i]['y']) ** 2); } - return $this->perimeter; + return $perimeter; } /** - * {@inheritdoc} + * Get barycenter + * + * @return array + * + * @since 1.0.0 */ - public function setPerimeter($perimeter) /* : void */ + public function getBarycenter() : array { - $this->reset(); + $barycenter = ['x' => 0, 'y' => 0]; + $count = count($this->coord); - $this->perimeter = $perimeter; - } - - /** - * {@inheritdoc} - */ - public function getPerimeterFormula() - { - return ''; - } - - /** - * {@inheritdoc} - */ - public function getBarycenter() - { - $this->barycenter['x'] = 0; - $this->barycenter['y'] = 0; - - $count = count($this->coord); - - for ($i = 0; $i < $count - 2; $i++) { - $mult = ($this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']); - $this->barycenter['x'] += ($this->coord[$i]['x'] + $this->coord[$i + 1]['x']) * $mult; - $this->barycenter['y'] += ($this->coord[$i]['y'] + $this->coord[$i + 1]['y']) * $mult; + for ($i = 0; $i < $count - 1; $i++) { + $mult = ($this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']); + $barycenter['x'] += ($this->coord[$i]['x'] + $this->coord[$i + 1]['x']) * $mult; + $barycenter['y'] += ($this->coord[$i]['y'] + $this->coord[$i + 1]['y']) * $mult; } - return $this->barycenter; + $mult = ($this->coord[$count - 1]['x'] * $this->coord[0]['y'] - $this->coord[0]['x'] * $this->coord[$count - 1]['y']); + $barycenter['x'] += ($this->coord[$count - 1]['x'] + $this->coord[0]['x']) * $mult; + $barycenter['y'] += ($this->coord[$count - 1]['y'] + $this->coord[0]['y']) * $mult; + + $surface = $this->getSignedSurface(); + + $barycenter['x'] = 1 / (6 * $surface) * $barycenter['x']; + $barycenter['y'] = 1 / (6 * $surface) * $barycenter['y']; + + return $barycenter; } } diff --git a/Math/Geometry/Shape/D2/Quadrilateral.php b/Math/Geometry/Shape/D2/Quadrilateral.php index a2eb21912..96959ee7d 100644 --- a/Math/Geometry/Shape/D2/Quadrilateral.php +++ b/Math/Geometry/Shape/D2/Quadrilateral.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Geometry\Shape\D2; +declare(strict_types = 1); +namespace phpOMS\Math\Geometry\Shape\D2; class Quadrilateral implements D2ShapeInterface { -} \ No newline at end of file +} diff --git a/Math/Geometry/Shape/D2/Rectangle.php b/Math/Geometry/Shape/D2/Rectangle.php index 05d43d330..1240007d5 100644 --- a/Math/Geometry/Shape/D2/Rectangle.php +++ b/Math/Geometry/Shape/D2/Rectangle.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Rectangle shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Rectangle implements D2ShapeInterface diff --git a/Math/Geometry/Shape/D2/Trapezoid.php b/Math/Geometry/Shape/D2/Trapezoid.php index a0943ea2b..86abe6f40 100644 --- a/Math/Geometry/Shape/D2/Trapezoid.php +++ b/Math/Geometry/Shape/D2/Trapezoid.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Trapezoid shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Trapezoid implements D2ShapeInterface diff --git a/Math/Geometry/Shape/D2/Triangle.php b/Math/Geometry/Shape/D2/Triangle.php index 4493d196b..1c8840f85 100644 --- a/Math/Geometry/Shape/D2/Triangle.php +++ b/Math/Geometry/Shape/D2/Triangle.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D2; /** * Triangle shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Triangle implements D2ShapeInterface diff --git a/Math/Geometry/Shape/D3/Cone.php b/Math/Geometry/Shape/D3/Cone.php index 2dc80e45e..07de187c4 100644 --- a/Math/Geometry/Shape/D3/Cone.php +++ b/Math/Geometry/Shape/D3/Cone.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Cone shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Cone implements D3ShapeInterface @@ -81,6 +79,9 @@ class Cone implements D3ShapeInterface * @return float * * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseVariableName) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) */ public static function getHeightFromVolume(float $V, float $r) : float { diff --git a/Math/Geometry/Shape/D3/Cuboid.php b/Math/Geometry/Shape/D3/Cuboid.php index 35ce4f6ae..431558bcc 100644 --- a/Math/Geometry/Shape/D3/Cuboid.php +++ b/Math/Geometry/Shape/D3/Cuboid.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Cuboid shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Cuboid implements D3ShapeInterface diff --git a/Math/Geometry/Shape/D3/Cylinder.php b/Math/Geometry/Shape/D3/Cylinder.php index 2062250e0..a626cb53e 100644 --- a/Math/Geometry/Shape/D3/Cylinder.php +++ b/Math/Geometry/Shape/D3/Cylinder.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Cylinder shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Cylinder implements D3ShapeInterface diff --git a/Math/Geometry/Shape/D3/D3ShapeInterface.php b/Math/Geometry/Shape/D3/D3ShapeInterface.php index af28edc99..31ddfa36a 100644 --- a/Math/Geometry/Shape/D3/D3ShapeInterface.php +++ b/Math/Geometry/Shape/D3/D3ShapeInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; @@ -20,10 +19,9 @@ use phpOMS\Math\Geometry\Shape\ShapeInterface; /** * Shape interface. * - * @category Framework - * @package phpOMS\Math + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface D3ShapeInterface extends ShapeInterface diff --git a/Math/Geometry/Shape/D3/Prism.php b/Math/Geometry/Shape/D3/Prism.php index f6ba669a5..69c103d78 100644 --- a/Math/Geometry/Shape/D3/Prism.php +++ b/Math/Geometry/Shape/D3/Prism.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Geometry\Shape\D3; +declare(strict_types = 1); +namespace phpOMS\Math\Geometry\Shape\D3; class Prism implements D3ShapeInterface { -} \ No newline at end of file +} diff --git a/Math/Geometry/Shape/D3/RectangularPyramid.php b/Math/Geometry/Shape/D3/RectangularPyramid.php index 2c437a905..2fead397a 100644 --- a/Math/Geometry/Shape/D3/RectangularPyramid.php +++ b/Math/Geometry/Shape/D3/RectangularPyramid.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Rectangular pyramid shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class RectangularPyramid implements D3ShapeInterface diff --git a/Math/Geometry/Shape/D3/Sphere.php b/Math/Geometry/Shape/D3/Sphere.php index 334e872b6..efe8795cd 100644 --- a/Math/Geometry/Shape/D3/Sphere.php +++ b/Math/Geometry/Shape/D3/Sphere.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Sphere shape. * - * @category Framework - * @package phpOMS\Math\Geometry\Shape + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Sphere implements D3ShapeInterface @@ -118,7 +116,7 @@ class Sphere implements D3ShapeInterface */ public static function getRadiusByVolume(float $v) : float { - return pow($v * 3 / (4 * pi()), 1 / 3); + return (float) pow($v * 3 / (4 * pi()), 1 / 3); } /** @@ -143,6 +141,9 @@ class Sphere implements D3ShapeInterface * @return float * * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseVariableName) + * @SuppressWarnings(PHPMD.CamelCaseParameterName) */ public static function getRadiusBySurface(float $S) : float { diff --git a/Math/Geometry/Shape/D3/Tetrahedron.php b/Math/Geometry/Shape/D3/Tetrahedron.php index e50351841..ddf4f4c33 100644 --- a/Math/Geometry/Shape/D3/Tetrahedron.php +++ b/Math/Geometry/Shape/D3/Tetrahedron.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape\D3; /** * Tetraedron shape. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Tetrahedron implements D3ShapeInterface diff --git a/Math/Geometry/Shape/ShapeInterface.php b/Math/Geometry/Shape/ShapeInterface.php index 8e336e504..0a658608b 100644 --- a/Math/Geometry/Shape/ShapeInterface.php +++ b/Math/Geometry/Shape/ShapeInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Geometry\Shape; /** * Shape interface. * - * @category Framework - * @package phpOMS\Math + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ShapeInterface diff --git a/Math/Integral/Gauss.php b/Math/Integral/Gauss.php index 5618df6ba..a2c020d86 100644 --- a/Math/Integral/Gauss.php +++ b/Math/Integral/Gauss.php @@ -4,18 +4,17 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Integral; class Gauss { -} \ No newline at end of file +} diff --git a/Math/Matrix/CholeskyDecomposition.php b/Math/Matrix/CholeskyDecomposition.php index db2fad264..27cea1958 100644 --- a/Math/Matrix/CholeskyDecomposition.php +++ b/Math/Matrix/CholeskyDecomposition.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Matrix; @@ -21,43 +20,48 @@ class CholeskyDecomposition private $m = 0; + /** + * Is symmetric positive definite + */ private $isSpd = true; + // see http://www.aip.de/groups/soe/local/numres/bookfpdf/f2-9.pdf 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) { + 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 ($i === $j) { if ($sum >= 0) { $this->L[$i][$i] = sqrt($sum); } else { $this->isSpd = false; } } else { - if ($this->L[$i][$i] != 0) { + if ($this->L[$i][$i] !== 0) { $this->L[$j][$i] = $sum / $this->L[$i][$i]; } } } - for ($k = $i+1; $k < $this->m; ++$k) { + for ($k = $i + 1; $k < $this->m; ++$k) { $this->L[$i][$k] = 0.0; } } } - public function isSpd() + public function isSpd() : bool { return $this->isSpd; } - public function getL() + public function getL() : Matrix { $matrix = new Matrix(); $matrix->setMatrix($this->L); @@ -65,41 +69,44 @@ class CholeskyDecomposition return $matrix; } - public function solve(Matrix $B) + public function solve(Matrix $B) : Matrix { if ($B->getM() !== $this->m) { - // invalid dimension + throw new \Exception(); } if (!$this->isSpd) { - // is not positive definite + throw new \Exception(); } - $X = $B->toArray(); - $nx = $B->getN(); + $X = $B->toArray(); + $n = $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]; + // Solve L*Y = B; + for ($k = 0; $k < $this->m; $k++) { + for ($j = 0; $j < $n; $j++) { + for ($i = 0; $i < $k; $i++) { + $X[$k][$j] -= $X[$i][$j] * $this->L[$k][$i]; } - } - 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]; + // Solve L'*X = Y; + for ($k = $this->m - 1; $k >= 0; $k--) { + for ($j = 0; $j < $n; $j++) { + for ($i = $k + 1; $i < $this->m; $i++) { + $X[$k][$j] -= $X[$i][$j] * $this->L[$i][$k]; } + + $X[$k][$j] /= $this->L[$k][$k]; } } - return new Matrix($X, $this->m, $nx); + $solution = new Matrix(); + $solution->setMatrix($X); + + return $solution; } -} \ No newline at end of file +} diff --git a/Math/Matrix/EigenvalueDecomposition.php b/Math/Matrix/EigenvalueDecomposition.php index e69de29bb..db05ab1f4 100644 --- a/Math/Matrix/EigenvalueDecomposition.php +++ b/Math/Matrix/EigenvalueDecomposition.php @@ -0,0 +1,19 @@ +n = $n; - $this->m = $n; + parent::__construct($n, $n); for ($i = 0; $i < $n; $i++) { - $this->matrix[$i] = array_fill(0, $n, 0); $this->matrix[$i][$i] = 1; } } -} \ No newline at end of file +} diff --git a/Math/Matrix/InverseType.php b/Math/Matrix/InverseType.php index d58908585..8a1942c9f 100644 --- a/Math/Matrix/InverseType.php +++ b/Math/Matrix/InverseType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Matrix; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Inverse type enum. * - * @category Framework - * @package phpOMS\Math\Matrix + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class InverseType extends Enum diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php index 2924ec455..df142551b 100644 --- a/Math/Matrix/LUDecomposition.php +++ b/Math/Matrix/LUDecomposition.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Matrix; @@ -37,87 +36,88 @@ class LUDecomposition } $this->pivSign = 1; - $LUrowi = $LUcolj = []; + $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; + $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) { + 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]; + $t = $this->LU[$p][$k]; $this->LU[$p][$k] = $this->LU[$j][$k]; $this->LU[$j][$k] = $t; } - $k = $this->piv[$p]; + + $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) { + for ($i = $j + 1; $i < $this->m; ++$i) { $this->LU[$i][$j] /= $this->LU[$j][$j]; } } } } - public function getL() + public function getL() : Matrix { $L = [[]]; 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; - } - } + 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() + public function getU() : Matrix { $U = [[]]; 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; - } - } - } - + 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); @@ -132,15 +132,15 @@ class LUDecomposition public function isNonsingular() : bool { for ($j = 0; $j < $this->n; ++$j) { - if ($this->LU[$j][$j] == 0) { - return false; - } + if ($this->LU[$j][$j] == 0) { + return false; + } } - + return true; } - public function det() + public function det() { $d = $this->pivSign; for ($j = 0; $j < $this->n; ++$j) { @@ -150,38 +150,44 @@ class LUDecomposition return $d; } - public function solve(Matrix $B) + public function solve(Matrix $B) : Matrix { if ($B->getM() !== $this->m) { + throw new \Exception(); } if (!$this->isNonsingular()) { + throw new \Exception(); } - $nx = $B->getM(); - $X = $B->getMatrix($this->piv, 0, $nx-1); + $n = $B->getN(); + $X = $B->getMatrix($this->piv, 0, $n - 1); + // todo: fix get extract // 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]; + for ($i = $k + 1; $i < $this->n; ++$i) { + for ($j = 0; $j < $n; ++$j) { + $X[$i][$j] -= $X[$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 ($k = $this->n - 1; $k >= 0; --$k) { + for ($j = 0; $j < $n; ++$j) { + $X[$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]; + for ($j = 0; $j < $n; ++$j) { + $X[$i][$j] -= $X[$k][$j] * $this->LU[$i][$k]; } } } - return $X; + $solution = new Matrix(); + $solution->setMatrix($X); + + return $solution; } -} \ No newline at end of file +} diff --git a/Math/Matrix/Matrix.php b/Math/Matrix/Matrix.php index c1ef2e473..c680ace61 100644 --- a/Math/Matrix/Matrix.php +++ b/Math/Matrix/Matrix.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Matrix; @@ -20,10 +19,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Matrix class * - * @category Framework - * @package phpOMS\Math\Matrix + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Matrix implements \ArrayAccess, \Iterator @@ -175,7 +173,7 @@ class Matrix implements \ArrayAccess, \Iterator * * @param array $matrix Matrix * - * @return Matrix + * @return Matrix * * @throws \Exception * @@ -183,8 +181,8 @@ class Matrix implements \ArrayAccess, \Iterator */ public function setMatrix(array $matrix) : Matrix { - $this->m = count($matrix); - $this->n = count($matrix[0] ?? 1); + $this->m = count($matrix); + $this->n = count($matrix[0] ?? 1); $this->matrix = $matrix; return $this; @@ -197,7 +195,7 @@ class Matrix implements \ArrayAccess, \Iterator * * @return Matrix * - * @throws \Exception + * @throws \InvalidArgumentException * * @since 1.0.0 */ @@ -209,7 +207,7 @@ class Matrix implements \ArrayAccess, \Iterator return $this->add(-$value); } - throw new \Exception('Type'); + throw new \InvalidArgumentException('Type'); } /** @@ -219,7 +217,7 @@ class Matrix implements \ArrayAccess, \Iterator * * @return Matrix * - * @throws \Exception + * @throws \InvalidArgumentException * * @since 1.0.0 */ @@ -231,7 +229,7 @@ class Matrix implements \ArrayAccess, \Iterator return $this->addScalar($value); } - throw new \Exception(); + throw new \InvalidArgumentException(); } /** @@ -324,7 +322,7 @@ class Matrix implements \ArrayAccess, \Iterator * * @return Matrix * - * @throws \Exception + * @throws \InvalidArgumentException * * @since 1.0.0 */ @@ -336,7 +334,7 @@ class Matrix implements \ArrayAccess, \Iterator return $this->multScalar($value); } - throw new \Exception('Type'); + throw new \InvalidArgumentException('Type'); } /** @@ -553,7 +551,6 @@ class Matrix implements \ArrayAccess, \Iterator return $newMatrix; } - public function diagonalize() : Matrix { $newMatrix = new Matrix($this->m, $this->n); @@ -569,34 +566,34 @@ class Matrix implements \ArrayAccess, \Iterator return $M->solve($B); } - private function gaussElimination($b) : Matrix + private function gaussElimination($b) : Matrix { - $mDim = count($b); + $mDim = count($b); $matrix = $this->matrix; - for($col = 0; $col < $mDim; $col++) { - $j = $col; + for ($col = 0; $col < $mDim; $col++) { + $j = $col; $max = $matrix[$j][$j]; for ($i = $col + 1; $i < $mDim; $i++) { $temp = abs($matrix[$i][$col]); if ($temp > $max) { - $j = $i; + $j = $i; $max = $temp; } } - - if($col != $j) { - $temp = $matrix[$col]; + + if ($col != $j) { + $temp = $matrix[$col]; $matrix[$col] = $matrix[$j]; - $matrix[$j] = $temp; - - $temp = $b[$col]; + $matrix[$j] = $temp; + + $temp = $b[$col]; $b[$col] = $b[$j]; - $b[$j] = $temp; + $b[$j] = $temp; } - + for ($i = $col + 1; $i < $mDim; $i++) { $temp = $matrix[$i][$col] / $matrix[$col][$col]; @@ -605,7 +602,7 @@ class Matrix implements \ArrayAccess, \Iterator } $matrix[$i][$col] = 0; - $b[$i] -= $temp * $b[$col]; + $b[$i] -= $temp * $b[$col]; } } @@ -679,10 +676,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * Return the current element - * @link http://php.net/manual/en/iterator.current.php - * @return mixed Can return any type. - * @since 5.0.0 + * {@inheritdoc} */ public function current() { @@ -690,13 +684,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * Offset to retrieve - * @link http://php.net/manual/en/arrayaccess.offsetget.php - * @param mixed $offset
- * The offset to retrieve. - *
- * @return mixed Can return all value types. - * @since 5.0.0 + * {@inheritdoc} */ public function offsetGet($offset) { @@ -706,10 +694,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * 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 + * {@inheritdoc} */ public function next() { @@ -717,10 +702,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * 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 + * {@inheritdoc} */ public function key() { @@ -728,11 +710,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * 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 + * {@inheritdoc} */ public function valid() { @@ -740,16 +718,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * Whether a offset exists - * @link http://php.net/manual/en/arrayaccess.offsetexists.php - * @param mixed $offset- * An offset to check for. - *
- * @return boolean true on success or false on failure. - * - *- * The return value will be casted to boolean if non-boolean was returned. - * @since 5.0.0 + * {@inheritdoc} */ public function offsetExists($offset) { @@ -759,10 +728,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * 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 + * {@inheritdoc} */ public function rewind() { @@ -770,16 +736,7 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * Offset to set - * @link http://php.net/manual/en/arrayaccess.offsetset.php - * @param mixed $offset
- * The offset to assign the value to. - *
- * @param mixed $value- * The value to set. - *
- * @return void - * @since 5.0.0 + * {@inheritdoc} */ public function offsetSet($offset, $value) { @@ -788,18 +745,11 @@ class Matrix implements \ArrayAccess, \Iterator } /** - * Offset to unset - * @link http://php.net/manual/en/arrayaccess.offsetunset.php - * @param mixed $offset- * The offset to unset. - *
- * @return void - * @since 5.0.0 + * {@inheritdoc} */ public function offsetUnset($offset) { $row = (int) ($offset / $this->m); unset($this->matrix[$row][$offset - $row * $this->n]); } - -} \ No newline at end of file +} diff --git a/Math/Matrix/QRDecomposition.php b/Math/Matrix/QRDecomposition.php index bdbb71e84..ff4157b66 100644 --- a/Math/Matrix/QRDecomposition.php +++ b/Math/Matrix/QRDecomposition.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Matrix; @@ -27,56 +26,56 @@ class QRDecomposition public function __construct(Matrix $M) { // Initialize. - $this->QR = $M->toArray(); - $this->m = $M->getRowDimension(); + $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]); + + // 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; + + 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; + + 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) { + + $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]; + 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]; - } - } - } - + + $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; - } + if ($this->Rdiag[$j] == 0) { + return false; + } } - - return true; + + return true; } public function getH() @@ -84,15 +83,15 @@ class QRDecomposition $H = [[]]; 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; - } - } + 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); @@ -104,17 +103,17 @@ class QRDecomposition $R = [[]]; 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; - } - } + 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); @@ -125,33 +124,33 @@ class QRDecomposition { $Q = [[]]; - for ($k = $this->n-1; $k >= 0; --$k) { - for ($i = 0; $i < $this->m; ++$i) { - $Q[$i][$k] = 0.0; + 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]; - } - } - } - } - + + $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) + public function solve(Matrix $B) : Matrix { if ($B->getRowDimension() !== $this->m) { } @@ -168,20 +167,20 @@ class QRDecomposition for ($i = $k; $i < $this->m; ++$i) { $s += $this->QR[$i][$k] * $X[$i][$j]; } - $s = -$s/$this->QR[$k][$k]; + $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 ($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]; + $X[$i][$j] -= $X[$k][$j] * $this->QR[$i][$k]; } } } @@ -189,6 +188,6 @@ class QRDecomposition $matrix = new Matrix(); $matrix->setArray($X); - return $matrix->getMatrix(0, $this->n-1, 0, $nx); + return $matrix; } -} \ No newline at end of file +} diff --git a/Math/Matrix/SingularValueDecomposition.php b/Math/Matrix/SingularValueDecomposition.php index e69de29bb..af851b98b 100644 --- a/Math/Matrix/SingularValueDecomposition.php +++ b/Math/Matrix/SingularValueDecomposition.php @@ -0,0 +1,19 @@ += 0; } -} \ No newline at end of file +} diff --git a/Math/Number/NumberType.php b/Math/Number/NumberType.php index 8aac5675a..b37a848d6 100644 --- a/Math/Number/NumberType.php +++ b/Math/Number/NumberType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Number; @@ -20,21 +19,20 @@ use phpOMS\Stdlib\Base\Enum; /** * Number type enum. * - * @category Framework - * @package Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class NumberType extends Enum { - /* public */ const N_INTEGER = 0; - /* public */ const N_NATURAL = 1; - /* public */ const N_EVEN = 2; - /* public */ const N_UNEVEN = 4; - /* public */ const N_PRIME = 8; - /* public */ const N_REAL = 16; - /* public */ const N_RATIONAL = 32; + /* public */ const N_INTEGER = 0; + /* public */ const N_NATURAL = 1; + /* public */ const N_EVEN = 2; + /* public */ const N_UNEVEN = 4; + /* public */ const N_PRIME = 8; + /* public */ const N_REAL = 16; + /* public */ const N_RATIONAL = 32; /* public */ const N_IRRATIONAL = 64; - /* public */ const N_COMPLEX = 128; -} \ No newline at end of file + /* public */ const N_COMPLEX = 128; +} diff --git a/Math/Number/Numbers.php b/Math/Number/Numbers.php index c82304bf7..ea8bdfc1b 100644 --- a/Math/Number/Numbers.php +++ b/Math/Number/Numbers.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Number; /** * Numbers class. * - * @category Framework - * @package Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Numbers @@ -45,7 +43,7 @@ class Numbers } } - return $sum == $n; + return $sum === $n; } /** @@ -59,7 +57,7 @@ class Numbers */ public static function isSelfdescribing(int $n) : bool { - $n = (string) $n; + $n = (string) $n; $split = str_split($n); foreach ($split as $place => $value) { @@ -108,4 +106,4 @@ class Numbers return $count; } -} \ No newline at end of file +} diff --git a/Math/Number/OperationInterface.php b/Math/Number/OperationInterface.php index 0e6082435..0bc992678 100644 --- a/Math/Number/OperationInterface.php +++ b/Math/Number/OperationInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Number; /** * Basic operation interface. * - * @category Framework - * @package phpOMS\Account + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface OperationInterface @@ -89,4 +87,4 @@ interface OperationInterface * @since 1.0.0 */ public function abs(); -} \ No newline at end of file +} diff --git a/Math/Number/Prime.php b/Math/Number/Prime.php index a8e5ad977..a138aaef7 100644 --- a/Math/Number/Prime.php +++ b/Math/Number/Prime.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Number; /** * Well known functions class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Prime @@ -169,4 +167,4 @@ class Prime return true; } -} \ No newline at end of file +} diff --git a/Math/Numerics/Interpolation/CubicSplineInterpolation.php b/Math/Numerics/Interpolation/CubicSplineInterpolation.php index 84f1b5a01..d4bdebbbf 100644 --- a/Math/Numerics/Interpolation/CubicSplineInterpolation.php +++ b/Math/Numerics/Interpolation/CubicSplineInterpolation.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Numerics\Interpolation; /** * Web module interface. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CubicSplineInterpolation diff --git a/Math/Numerics/Interpolation/LinearInterpolation.php b/Math/Numerics/Interpolation/LinearInterpolation.php index 6ef4109b8..8b642c405 100644 --- a/Math/Numerics/Interpolation/LinearInterpolation.php +++ b/Math/Numerics/Interpolation/LinearInterpolation.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Numerics\Interpolation; /** * Web module interface. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LinearInterpolation diff --git a/Math/Numerics/Interpolation/PolynomialInterpolation.php b/Math/Numerics/Interpolation/PolynomialInterpolation.php index b9caea664..e90380e38 100644 --- a/Math/Numerics/Interpolation/PolynomialInterpolation.php +++ b/Math/Numerics/Interpolation/PolynomialInterpolation.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Numerics\Interpolation; /** * Web module interface. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PolynomialInterpolation diff --git a/Math/Optimization/GeneticAlgorithmInterface.php b/Math/Optimization/GeneticAlgorithmInterface.php index 6705ea7ee..bd810504b 100644 --- a/Math/Optimization/GeneticAlgorithmInterface.php +++ b/Math/Optimization/GeneticAlgorithmInterface.php @@ -4,29 +4,27 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization; /** * Web module interface. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface GeneticAlgorithmInterface { - public function mutate($a); + public function mutate($a); - public function unfitness($a, $b); + public function unfitness($a, $b); } diff --git a/Math/Optimization/Graph/Dijkstra.php b/Math/Optimization/Graph/Dijkstra.php index 49ca19e1f..1d9b901ee 100644 --- a/Math/Optimization/Graph/Dijkstra.php +++ b/Math/Optimization/Graph/Dijkstra.php @@ -4,15 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Graph; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Graph; + +use phpOMS\Stdlib\Graph\Graph; class Dijkstra { @@ -82,4 +83,4 @@ class Dijkstra return $path; } -} \ No newline at end of file +} diff --git a/Math/Optimization/Graph/EdgeInterface.php b/Math/Optimization/Graph/EdgeInterface.php index 937648621..ac4717a60 100644 --- a/Math/Optimization/Graph/EdgeInterface.php +++ b/Math/Optimization/Graph/EdgeInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\Graph; /** * Graph class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface EdgeInterface @@ -71,4 +69,4 @@ interface EdgeInterface * @since 1.0.0 */ public function setVertices(VerticeInterface $a, VerticeInterface $b); -} \ No newline at end of file +} diff --git a/Math/Optimization/Graph/FloydWarshall.php b/Math/Optimization/Graph/FloydWarshall.php index 1257aabe9..cb9b9db20 100644 --- a/Math/Optimization/Graph/FloydWarshall.php +++ b/Math/Optimization/Graph/FloydWarshall.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Graph; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Graph; class FloydWarshall { -} \ No newline at end of file +} diff --git a/Math/Optimization/Graph/NullEdge.php b/Math/Optimization/Graph/NullEdge.php index 27c324783..ae4539cfc 100644 --- a/Math/Optimization/Graph/NullEdge.php +++ b/Math/Optimization/Graph/NullEdge.php @@ -4,28 +4,25 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\Graph; - /** * Graph class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullEdge { -} \ No newline at end of file +} diff --git a/Math/Optimization/Graph/NullVertice.php b/Math/Optimization/Graph/NullVertice.php index 19cb5c5f0..b55d07e9a 100644 --- a/Math/Optimization/Graph/NullVertice.php +++ b/Math/Optimization/Graph/NullVertice.php @@ -4,28 +4,25 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\Graph; - /** * Graph class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullVertice { -} \ No newline at end of file +} diff --git a/Math/Optimization/Graph/VerticeInterface.php b/Math/Optimization/Graph/VerticeInterface.php index 4724b5ceb..20c453869 100644 --- a/Math/Optimization/Graph/VerticeInterface.php +++ b/Math/Optimization/Graph/VerticeInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\Graph; /** * Graph class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface VerticeInterface diff --git a/Math/Optimization/Knappsack/Backpack.php b/Math/Optimization/Knappsack/Backpack.php index eb15addd1..ddf12f207 100644 --- a/Math/Optimization/Knappsack/Backpack.php +++ b/Math/Optimization/Knappsack/Backpack.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class Backpack { -} \ No newline at end of file +} diff --git a/Math/Optimization/Knappsack/BruteForce.php b/Math/Optimization/Knappsack/BruteForce.php index 8887394d1..a5256b521 100644 --- a/Math/Optimization/Knappsack/BruteForce.php +++ b/Math/Optimization/Knappsack/BruteForce.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class BruteForce { -} \ No newline at end of file +} diff --git a/Math/Optimization/Knappsack/GA.php b/Math/Optimization/Knappsack/GA.php index c01faddf3..c2e1f5e86 100644 --- a/Math/Optimization/Knappsack/GA.php +++ b/Math/Optimization/Knappsack/GA.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class GA { -} \ No newline at end of file +} diff --git a/Math/Optimization/Knappsack/Item.php b/Math/Optimization/Knappsack/Item.php index 2b396d108..7a4efc7f9 100644 --- a/Math/Optimization/Knappsack/Item.php +++ b/Math/Optimization/Knappsack/Item.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class Item { -} \ No newline at end of file +} diff --git a/Math/Optimization/Knappsack/ItemPool.php b/Math/Optimization/Knappsack/ItemPool.php index 676ad5780..0bce63059 100644 --- a/Math/Optimization/Knappsack/ItemPool.php +++ b/Math/Optimization/Knappsack/ItemPool.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class ItemPool { -} \ No newline at end of file +} diff --git a/Math/Optimization/Knappsack/Population.php b/Math/Optimization/Knappsack/Population.php index eeb6f279c..88c5f44d2 100644 --- a/Math/Optimization/Knappsack/Population.php +++ b/Math/Optimization/Knappsack/Population.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\Knappsack; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\Knappsack; class Population { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/BruteForce.php b/Math/Optimization/ShiftScheduling/BruteForce.php index 2e23e980f..6f25fb820 100644 --- a/Math/Optimization/ShiftScheduling/BruteForce.php +++ b/Math/Optimization/ShiftScheduling/BruteForce.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class BruteForce { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/GA.php b/Math/Optimization/ShiftScheduling/GA.php index 86560a2b3..39b8992dd 100644 --- a/Math/Optimization/ShiftScheduling/GA.php +++ b/Math/Optimization/ShiftScheduling/GA.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class GA { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/Population.php b/Math/Optimization/ShiftScheduling/Population.php index ab8bad8c1..aef949866 100644 --- a/Math/Optimization/ShiftScheduling/Population.php +++ b/Math/Optimization/ShiftScheduling/Population.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class Population { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/Workday.php b/Math/Optimization/ShiftScheduling/Workday.php index 482bd43b0..d695b6362 100644 --- a/Math/Optimization/ShiftScheduling/Workday.php +++ b/Math/Optimization/ShiftScheduling/Workday.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class Workday { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/Worker.php b/Math/Optimization/ShiftScheduling/Worker.php index 2dae946b4..9a6877ecd 100644 --- a/Math/Optimization/ShiftScheduling/Worker.php +++ b/Math/Optimization/ShiftScheduling/Worker.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class Worker { -} \ No newline at end of file +} diff --git a/Math/Optimization/ShiftScheduling/WorkerPool.php b/Math/Optimization/ShiftScheduling/WorkerPool.php index 64bb3fadd..24037d4ed 100644 --- a/Math/Optimization/ShiftScheduling/WorkerPool.php +++ b/Math/Optimization/ShiftScheduling/WorkerPool.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Optimization\ShiftScheduling; +declare(strict_types = 1); +namespace phpOMS\Math\Optimization\ShiftScheduling; class WorkerPool { -} \ No newline at end of file +} diff --git a/Math/Optimization/TSP/BruteForce.php b/Math/Optimization/TSP/BruteForce.php index 16a67e3ec..b5ad1c488 100644 --- a/Math/Optimization/TSP/BruteForce.php +++ b/Math/Optimization/TSP/BruteForce.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; /** * TSP solution with brute force. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class BruteForce diff --git a/Math/Optimization/TSP/City.php b/Math/Optimization/TSP/City.php index d2e45f0f7..7b9a39092 100644 --- a/Math/Optimization/TSP/City.php +++ b/Math/Optimization/TSP/City.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; @@ -20,10 +19,9 @@ use phpOMS\Math\Geometry\Shape\D3\Sphere; /** * City class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class City @@ -61,7 +59,7 @@ class City * * @since 1.0.0 */ - public function __construct(float $lat, float $long, string $name) + public function __construct(float $lat = 0, float $long = 0, string $name = '') { $this->long = $long; $this->lat = $lat; @@ -107,7 +105,7 @@ class City } /** - * Distance to city + * Distance to city in meter * * @param City $city City * diff --git a/Math/Optimization/TSP/CityPool.php b/Math/Optimization/TSP/CityPool.php index 3a3ede868..dcd3ea4a0 100644 --- a/Math/Optimization/TSP/CityPool.php +++ b/Math/Optimization/TSP/CityPool.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; /** * City pool. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CityPool implements \Countable diff --git a/Math/Optimization/TSP/GA.php b/Math/Optimization/TSP/GA.php index 0cb2a85b6..d88668406 100644 --- a/Math/Optimization/TSP/GA.php +++ b/Math/Optimization/TSP/GA.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; /** * TSP solution by genetic algorithm. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class GA @@ -94,9 +92,9 @@ class GA $newPopulation->set($i, $child); } - $count = $newPopulation->count(); + $count2 = $newPopulation->count(); - for ($i = $shift; $i < $count; $i++) { + for ($i = $shift; $i < $count2; $i++) { $this->mutate($newPopulation->get($i)); } @@ -115,7 +113,7 @@ class GA private function tournamentSelection(Population $population) : Tour { $tournament = new Population($this->cityPool, self::TOURNAMENT, false); - $populationSize = $population->count(); + $populationSize = $population->count() - 1; for ($i = 0; $i < self::TOURNAMENT; $i++) { $tournament->add($population->get(mt_rand(0, $populationSize))); @@ -138,8 +136,8 @@ class GA { $child = new Tour($this->cityPool, false); - $start = mt_rand(0, $tour1->count()); - $end = mt_rand(0, $tour1->count()); + $start = mt_rand(0, $tour1->count() - 1); + $end = mt_rand(0, $tour1->count() - 1); $count = $child->count(); /* $tour1->count() ???!!!! */ @@ -182,7 +180,7 @@ class GA for ($pos1 = 0; $pos1 < $count; $pos1++) { if (mt_rand(0, 1000) < self::MUTATION) { - $pos2 = mt_rand(0, $tour->count()); + $pos2 = mt_rand(0, $tour->count() - 1); /* Could be same pos! */ $city1 = $tour->getCity($pos1); @@ -194,5 +192,4 @@ class GA } } } - } diff --git a/Math/Optimization/TSP/Population.php b/Math/Optimization/TSP/Population.php index 52e9bb0a3..bfec067ff 100644 --- a/Math/Optimization/TSP/Population.php +++ b/Math/Optimization/TSP/Population.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; /** * Population class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Population implements \Countable diff --git a/Math/Optimization/TSP/Tour.php b/Math/Optimization/TSP/Tour.php index a3b719603..c5d3ac5a0 100644 --- a/Math/Optimization/TSP/Tour.php +++ b/Math/Optimization/TSP/Tour.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Optimization\TSP; /** * Tour class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Tour implements \Countable diff --git a/Math/Parser/Evaluator.php b/Math/Parser/Evaluator.php index ce78cc437..ada029e9a 100644 --- a/Math/Parser/Evaluator.php +++ b/Math/Parser/Evaluator.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Parser; /** * Shape interface. * - * @category Framework - * @package phpOMS\Math + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Evaluator diff --git a/Math/Statistic/Average.php b/Math/Statistic/Average.php index afd73e357..d93953aac 100644 --- a/Math/Statistic/Average.php +++ b/Math/Statistic/Average.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic; @@ -21,26 +20,25 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Average class. * - * @category Framework - * @package phpOMS\Math\Statistic + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Average { - /* public */ const MA3 = [1 / 3, 1 / 3]; - /* public */ const MA5 = [0.2, 0.2, 0.2]; + /* public */ const MA3 = [1 / 3, 1 / 3]; + /* public */ const MA5 = [0.2, 0.2, 0.2]; /* public */ const MA2x12 = [5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 0.42]; - /* public */ const MA3x3 = [1 / 3, 2 / 9, 1 / 9]; - /* public */ const MA3x5 = [0.2, 0.2, 2 / 15, 4 / 6]; - /* public */ const MAS15 = [0.231, 0.209, 0.144, 2 / 3, 0.009, -0.016, -0.019, -0.009]; - /* public */ const MAS21 = [0.171, 0.163, 0.134, 0.37, 0.51, 0.017, -0.006, -0.014, -0.014, -0.009, -0.003]; - /* public */ const MAH5 = [0.558, 0.294, -0.73]; - /* public */ const MAH9 = [0.330, 0.267, 0.119, -0.010, -0.041]; - /* public */ const MAH13 = [0.240, 0.214, 0.147, 0.66, 0, -0.028, -0.019]; - /* public */ const MAH23 = [0.148, 0.138, 0.122, 0.097, 0.068, 0.039, 0.013, -0.005, -0.015, -0.016, -0.011, -0.004]; + /* public */ const MA3x3 = [1 / 3, 2 / 9, 1 / 9]; + /* public */ const MA3x5 = [0.2, 0.2, 2 / 15, 4 / 6]; + /* public */ const MAS15 = [0.231, 0.209, 0.144, 2 / 3, 0.009, -0.016, -0.019, -0.009]; + /* public */ const MAS21 = [0.171, 0.163, 0.134, 0.37, 0.51, 0.017, -0.006, -0.014, -0.014, -0.009, -0.003]; + /* public */ const MAH5 = [0.558, 0.294, -0.73]; + /* public */ const MAH9 = [0.330, 0.267, 0.119, -0.010, -0.041]; + /* public */ const MAH13 = [0.240, 0.214, 0.147, 0.66, 0, -0.028, -0.019]; + /* public */ const MAH23 = [0.148, 0.138, 0.122, 0.097, 0.068, 0.039, 0.013, -0.005, -0.015, -0.016, -0.011, -0.004]; /** * Average change. @@ -185,12 +183,12 @@ class Average * * @since 1.0.0 */ - public static function mode($values) + public static function mode(array $values) { $count = array_count_values($values); $best = max($count); - return array_keys($count, $best); + return (float) (array_keys($count, $best)[0] ?? 0.0); } /** @@ -243,7 +241,7 @@ class Average throw new ZeroDevisionException(); } - return pow(array_product($values), 1 / $count); + return (float) pow(array_product($values), 1 / $count); } /** diff --git a/Math/Statistic/Basic.php b/Math/Statistic/Basic.php index 090e01cae..f20cd242d 100644 --- a/Math/Statistic/Basic.php +++ b/Math/Statistic/Basic.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic; /** * Basic statistic functions. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Basic @@ -41,6 +39,7 @@ class Basic public static function freaquency(array $values) : array { $freaquency = []; + $sum = 1; if (!($isArray = is_array(reset($values)))) { $sum = array_sum($values); diff --git a/Math/Statistic/Correlation.php b/Math/Statistic/Correlation.php index 509118b66..041d73ac4 100644 --- a/Math/Statistic/Correlation.php +++ b/Math/Statistic/Correlation.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic; /** * Correlation. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Correlation diff --git a/Math/Statistic/Forecast/Error.php b/Math/Statistic/Forecast/Error.php index 43792db3c..4f8589ebb 100644 --- a/Math/Statistic/Forecast/Error.php +++ b/Math/Statistic/Forecast/Error.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast; @@ -22,10 +21,9 @@ use phpOMS\Math\Statistic\MeasureOfDispersion; /** * Basic forecast functions. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Error @@ -452,4 +450,4 @@ class Error return $sum; } -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/ForecastIntervalMultiplier.php b/Math/Statistic/Forecast/ForecastIntervalMultiplier.php index a8bddc0fa..87db7dfc9 100644 --- a/Math/Statistic/Forecast/ForecastIntervalMultiplier.php +++ b/Math/Statistic/Forecast/ForecastIntervalMultiplier.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Prediction interval multiplier. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ForecastIntervalMultiplier extends Enum diff --git a/Math/Statistic/Forecast/Forecasts.php b/Math/Statistic/Forecast/Forecasts.php index 6f7765c72..b1f11637d 100644 --- a/Math/Statistic/Forecast/Forecasts.php +++ b/Math/Statistic/Forecast/Forecasts.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast; /** * Address type enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Forecasts @@ -41,4 +39,4 @@ class Forecasts { return [$forecast - $interval * $standardDeviation, $forecast + $interval * $standardDeviation]; } -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php index 09cffb4d0..3f07d39f4 100644 --- a/Math/Statistic/Forecast/Regression/LevelLevelRegression.php +++ b/Math/Statistic/Forecast/Regression/LevelLevelRegression.php @@ -4,35 +4,39 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast\Regression; /** * Regression class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LevelLevelRegression extends RegressionAbstract { + /** + * {@inheritdoc} + */ public static function getSlope(float $b1, float $y, float $x) : float { return $b1; } + /** + * {@inheritdoc} + */ public static function getElasticity(float $b1, float $y, float $x): float { return $b1 * $y / $x; } -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/LevelLogRegression.php b/Math/Statistic/Forecast/Regression/LevelLogRegression.php index 94cd2d309..969553006 100644 --- a/Math/Statistic/Forecast/Regression/LevelLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LevelLogRegression.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast\Regression; @@ -20,10 +19,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Regression class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LevelLogRegression extends RegressionAbstract @@ -44,14 +42,19 @@ class LevelLogRegression extends RegressionAbstract return parent::getRegression($x, $y); } + /** + * {@inheritdoc} + */ public static function getSlope(float $b1, float $y, float $x) : float { return $b1 / $x; } + /** + * {@inheritdoc} + */ public static function getElasticity(float $b1, float $y, float $x): float { return $b1 / $x; } - -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/LogLevelRegression.php b/Math/Statistic/Forecast/Regression/LogLevelRegression.php index c7e99a0ef..eebd46c4b 100644 --- a/Math/Statistic/Forecast/Regression/LogLevelRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLevelRegression.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast\Regression; @@ -20,10 +19,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Regression class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LogLevelRegression extends RegressionAbstract @@ -44,14 +42,19 @@ class LogLevelRegression extends RegressionAbstract return parent::getRegression($x, $y); } + /** + * {@inheritdoc} + */ public static function getSlope(float $b1, float $y, float $x) : float { return $b1 * $y; } + /** + * {@inheritdoc} + */ public static function getElasticity(float $b1, float $y, float $x): float { return $b1 * $x; } - -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/LogLogRegression.php b/Math/Statistic/Forecast/Regression/LogLogRegression.php index fb0f20680..240abf9cb 100644 --- a/Math/Statistic/Forecast/Regression/LogLogRegression.php +++ b/Math/Statistic/Forecast/Regression/LogLogRegression.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast\Regression; @@ -20,10 +19,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Regression class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LogLogRegression extends RegressionAbstract @@ -45,14 +43,19 @@ class LogLogRegression extends RegressionAbstract return parent::getRegression($x, $y); } + /** + * {@inheritdoc} + */ public static function getSlope(float $b1, float $y, float $x) : float { return $b1 * $y / $x; } + /** + * {@inheritdoc} + */ public static function getElasticity(float $b1, float $y, float $x): float { return $b1; } - -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php index ad4781be4..6ef7e510c 100644 --- a/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php +++ b/Math/Statistic/Forecast/Regression/MultipleLinearRegression.php @@ -4,15 +4,14 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Statistic\Forecast\Regression; +declare(strict_types = 1); +namespace phpOMS\Math\Statistic\Forecast\Regression; use phpOMS\Math\Matrix\Matrix; @@ -33,11 +32,17 @@ class MultipleLinearRegression return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->getMatrix(); } + /** + * {@inheritdoc} + */ public static function getVariance() : float { } + /** + * {@inheritdoc} + */ public static function getPredictionInterval() : array { } -} \ No newline at end of file +} diff --git a/Math/Statistic/Forecast/Regression/RegressionAbstract.php b/Math/Statistic/Forecast/Regression/RegressionAbstract.php index 8c4068702..9462f3784 100644 --- a/Math/Statistic/Forecast/Regression/RegressionAbstract.php +++ b/Math/Statistic/Forecast/Regression/RegressionAbstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic\Forecast\Regression; use phpOMS\Math\Statistic\Average; @@ -22,10 +21,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Regression abstract class. * - * @category Framework - * @package phpOMS\Math\Statistic + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RegressionAbstract @@ -186,4 +184,4 @@ abstract class RegressionAbstract { return 0.0; } -} \ No newline at end of file +} diff --git a/Math/Statistic/MeasureOfDispersion.php b/Math/Statistic/MeasureOfDispersion.php index b74d931ec..48d3584d7 100644 --- a/Math/Statistic/MeasureOfDispersion.php +++ b/Math/Statistic/MeasureOfDispersion.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Statistic; @@ -21,10 +20,9 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; /** * Measure of dispersion. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MeasureOfDispersion @@ -194,6 +192,7 @@ class MeasureOfDispersion */ public static function getIQR(array $x) : float { + return 0.0; } /** @@ -237,5 +236,4 @@ class MeasureOfDispersion return $sum / count($x); } - } diff --git a/Math/Stochastic/Distribution/BernoulliDistribution.php b/Math/Stochastic/Distribution/BernoulliDistribution.php index 6a6e8dcae..76c6c501b 100644 --- a/Math/Stochastic/Distribution/BernoulliDistribution.php +++ b/Math/Stochastic/Distribution/BernoulliDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Bernulli distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class BernoulliDistribution diff --git a/Math/Stochastic/Distribution/BetaDistribution.php b/Math/Stochastic/Distribution/BetaDistribution.php index e3e9a5598..6fad5e480 100644 --- a/Math/Stochastic/Distribution/BetaDistribution.php +++ b/Math/Stochastic/Distribution/BetaDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class BetaDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/BinomialDistribution.php b/Math/Stochastic/Distribution/BinomialDistribution.php index 1dbb1bb74..aa2c8d980 100644 --- a/Math/Stochastic/Distribution/BinomialDistribution.php +++ b/Math/Stochastic/Distribution/BinomialDistribution.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; @@ -20,10 +19,9 @@ use phpOMS\Math\Functions\Functions; /** * Binomial distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class BinomialDistribution @@ -67,7 +65,7 @@ class BinomialDistribution */ public static function getMgf(int $n, float $t, float $p) : float { - return pow(1 - $p + $p * exp($t), $n); + return (float) pow(1 - $p + $p * exp($t), $n); } /** diff --git a/Math/Stochastic/Distribution/CauchyDistribution.php b/Math/Stochastic/Distribution/CauchyDistribution.php index 91347b973..6af567f27 100644 --- a/Math/Stochastic/Distribution/CauchyDistribution.php +++ b/Math/Stochastic/Distribution/CauchyDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Cauchy distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class CauchyDistribution diff --git a/Math/Stochastic/Distribution/ChiSquaredDistribution.php b/Math/Stochastic/Distribution/ChiSquaredDistribution.php index 0a7afa1d8..a970c10cd 100644 --- a/Math/Stochastic/Distribution/ChiSquaredDistribution.php +++ b/Math/Stochastic/Distribution/ChiSquaredDistribution.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; @@ -20,10 +19,9 @@ use phpOMS\Math\Functions\Functions; /** * Chi squared distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ChiSquaredDistribution @@ -101,7 +99,7 @@ class ChiSquaredDistribution $sum += ($dataset[$i] - $expected[$i]) * ($dataset[$i] - $expected[$i]) / $expected[$i]; } - $P = null; + $p = null; if ($df === 0) { $df = self::getDegreesOfFreedom($dataset); @@ -113,14 +111,14 @@ class ChiSquaredDistribution foreach (self::TABLE[$df] as $key => $value) { if ($value > $sum) { - $P = $key; + $p = $key; break; } } - $P = 1 - ($P ?? key(end(self::TABLE[$df]))); + $p = 1 - ($p ?? key(end(self::TABLE[$df]))); - return ['P' => $P, 'H0' => ($P > $significance), 'df' => $df]; + return ['P' => $p, 'H0' => ($p > $significance), 'df' => $df]; } /** @@ -159,7 +157,7 @@ class ChiSquaredDistribution throw new \Exception('Out of bounds'); } - return 1 / (pow(2, $df / 2) * (Functions::getGammaInteger((int) $df / 2))) * pow($x, $df / 2 - 1) * exp(-$x / 2); + return 1 / (pow(2, $df / 2) * (Functions::getGammaInteger((int) ($df / 2)))) * pow($x, $df / 2 - 1) * exp(-$x / 2); } /** @@ -236,7 +234,7 @@ class ChiSquaredDistribution throw new \Exception('Out of bounds'); } - return pow(1 - 2 * $t, -$df / 2); + return (float) pow(1 - 2 * $t, -$df / 2); } /** diff --git a/Math/Stochastic/Distribution/ExponentialDistribution.php b/Math/Stochastic/Distribution/ExponentialDistribution.php index 237c62eb7..8dd995a28 100644 --- a/Math/Stochastic/Distribution/ExponentialDistribution.php +++ b/Math/Stochastic/Distribution/ExponentialDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Exponential distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ExponentialDistribution @@ -107,7 +105,7 @@ class ExponentialDistribution */ public static function getVariance(float $lambda) : float { - return pow($lambda, -2); + return (float) pow($lambda, -2); } /** diff --git a/Math/Stochastic/Distribution/FDistribution.php b/Math/Stochastic/Distribution/FDistribution.php index df308127b..4f68672f1 100644 --- a/Math/Stochastic/Distribution/FDistribution.php +++ b/Math/Stochastic/Distribution/FDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class FDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/GammaDistribution.php b/Math/Stochastic/Distribution/GammaDistribution.php index 10fc9d628..6594f7416 100644 --- a/Math/Stochastic/Distribution/GammaDistribution.php +++ b/Math/Stochastic/Distribution/GammaDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class GammaDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/GeometricDistribution.php b/Math/Stochastic/Distribution/GeometricDistribution.php index 15ac256bd..2fa5e73fe 100644 --- a/Math/Stochastic/Distribution/GeometricDistribution.php +++ b/Math/Stochastic/Distribution/GeometricDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Geometric distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class GeometricDistribution @@ -38,7 +36,7 @@ class GeometricDistribution */ public static function getPmf(float $p, int $k) : float { - return pow(1 - $p, $k - 1) * $p; + return (float) pow(1 - $p, $k - 1) * $p; } /** diff --git a/Math/Stochastic/Distribution/HypergeometricDistribution.php b/Math/Stochastic/Distribution/HypergeometricDistribution.php index c7df59a02..8b9f4580e 100644 --- a/Math/Stochastic/Distribution/HypergeometricDistribution.php +++ b/Math/Stochastic/Distribution/HypergeometricDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class HypergeometricDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/LaplaceDistribution.php b/Math/Stochastic/Distribution/LaplaceDistribution.php index 61b32d8dd..5e8ae4db3 100644 --- a/Math/Stochastic/Distribution/LaplaceDistribution.php +++ b/Math/Stochastic/Distribution/LaplaceDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Laplace distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LaplaceDistribution diff --git a/Math/Stochastic/Distribution/LogDistribution.php b/Math/Stochastic/Distribution/LogDistribution.php index f1c3749af..4316c70f0 100644 --- a/Math/Stochastic/Distribution/LogDistribution.php +++ b/Math/Stochastic/Distribution/LogDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class LogDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/LogNormalDistribution.php b/Math/Stochastic/Distribution/LogNormalDistribution.php index 5aa64e3db..56273cb41 100644 --- a/Math/Stochastic/Distribution/LogNormalDistribution.php +++ b/Math/Stochastic/Distribution/LogNormalDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class LogNormalDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/LogisticDistribution.php b/Math/Stochastic/Distribution/LogisticDistribution.php index 482364c66..753c8b09f 100644 --- a/Math/Stochastic/Distribution/LogisticDistribution.php +++ b/Math/Stochastic/Distribution/LogisticDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class LogisticDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/NormalDistribution.php b/Math/Stochastic/Distribution/NormalDistribution.php index 6a8c45631..94db96e3a 100644 --- a/Math/Stochastic/Distribution/NormalDistribution.php +++ b/Math/Stochastic/Distribution/NormalDistribution.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Normal distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NormalDistribution @@ -132,11 +130,11 @@ class NormalDistribution * * @param float $sig * - * @return float + * @return array * * @since 1.0.0 */ - public static function getFisherInformation(float $sig) : float + public static function getFisherInformation(float $sig) : array { return [[1 / $sig ** 2, 0], [0, 1 / (2 * $sig ** 4)]]; } diff --git a/Math/Stochastic/Distribution/ParetoDistribution.php b/Math/Stochastic/Distribution/ParetoDistribution.php index 7464a7c1f..ecfec6ae2 100644 --- a/Math/Stochastic/Distribution/ParetoDistribution.php +++ b/Math/Stochastic/Distribution/ParetoDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class ParetoDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/PoissonDistribution.php b/Math/Stochastic/Distribution/PoissonDistribution.php index e901576fa..fa40d2c69 100644 --- a/Math/Stochastic/Distribution/PoissonDistribution.php +++ b/Math/Stochastic/Distribution/PoissonDistribution.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; @@ -20,10 +19,9 @@ use phpOMS\Math\Functions\Functions; /** * Well known functions class. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PoissonDistribution @@ -148,7 +146,7 @@ class PoissonDistribution */ public static function getSkewness(float $lambda) : float { - return pow($lambda, -1 / 2); + return (float) pow($lambda, -1 / 2); } /** @@ -162,7 +160,7 @@ class PoissonDistribution */ public static function getFisherInformation(float $lambda) : float { - return pow($lambda, -1); + return (float) pow($lambda, -1); } /** @@ -176,7 +174,7 @@ class PoissonDistribution */ public static function getExKurtosis(float $lambda) : float { - return pow($lambda, -1); + return (float) pow($lambda, -1); } public static function getRandom() diff --git a/Math/Stochastic/Distribution/TDistribution.php b/Math/Stochastic/Distribution/TDistribution.php index 19f51ae9e..841e80c34 100644 --- a/Math/Stochastic/Distribution/TDistribution.php +++ b/Math/Stochastic/Distribution/TDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class TDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/Distribution/UniformDistributionContinuous.php b/Math/Stochastic/Distribution/UniformDistributionContinuous.php index cc90f439d..05e174304 100644 --- a/Math/Stochastic/Distribution/UniformDistributionContinuous.php +++ b/Math/Stochastic/Distribution/UniformDistributionContinuous.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Uniform (continuous) distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class UniformDistributionContinuous diff --git a/Math/Stochastic/Distribution/UniformDistributionDiscrete.php b/Math/Stochastic/Distribution/UniformDistributionDiscrete.php index 93fbe39a6..60b401a29 100644 --- a/Math/Stochastic/Distribution/UniformDistributionDiscrete.php +++ b/Math/Stochastic/Distribution/UniformDistributionDiscrete.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic\Distribution; /** * Uniform (discrete) distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class UniformDistributionDiscrete diff --git a/Math/Stochastic/Distribution/WeibullDistribution.php b/Math/Stochastic/Distribution/WeibullDistribution.php index 9b7e8296e..d36679322 100644 --- a/Math/Stochastic/Distribution/WeibullDistribution.php +++ b/Math/Stochastic/Distribution/WeibullDistribution.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Math\Stochastic\Distribution; +declare(strict_types = 1); +namespace phpOMS\Math\Stochastic\Distribution; class WeibullDistribution { -} \ No newline at end of file +} diff --git a/Math/Stochastic/NaiveBayesFilter.php b/Math/Stochastic/NaiveBayesFilter.php index e16a98450..4a186b9cc 100644 --- a/Math/Stochastic/NaiveBayesFilter.php +++ b/Math/Stochastic/NaiveBayesFilter.php @@ -4,54 +4,53 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Math\Stochastic; + /** * Bernulli distribution. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NaiveBayesFilter { private $dict = []; - + public function __construct() { } - + public function trainMatch($matched) /* : void */ { } - + public function trainMismatch($mismatch) /* : void */ { } - + public function match($toMatch) : float { $normalizedDict = $this->normalizeDictionary(); $n = 0.0; - foreach($toMatch as $element) { - if(isset($normalizedDict[$element])) { - $n += log(1-$normalizedDict[$element]['match'] / $normalizedDict[$element]['total']) - log($normalizedDict[$element]['match'] / $normalizedDict[$element]['total']); + foreach ($toMatch as $element) { + if (isset($normalizedDict[$element])) { + $n += log(1 - $normalizedDict[$element]['match'] / $normalizedDict[$element]['total']) - log($normalizedDict[$element]['match'] / $normalizedDict[$element]['total']); } } - - return 1 / (1+exp($n)); + + return 1 / (1 + exp($n)); } - + private function normalizeDictionary() : array { return $this->dict; diff --git a/Message/HeaderAbstract.php b/Message/HeaderAbstract.php index dc7881e8b..a77ad74d6 100644 --- a/Message/HeaderAbstract.php +++ b/Message/HeaderAbstract.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; @@ -20,10 +19,9 @@ use phpOMS\Localization\Localization; /** * Response class. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class HeaderAbstract @@ -35,7 +33,7 @@ abstract class HeaderAbstract * @since 1.0.0 */ protected static $isLocked = false; - + /** * Localization. * @@ -43,7 +41,7 @@ abstract class HeaderAbstract * @since 1.0.0 */ protected $l11n = null; - + /** * Account. * @@ -51,7 +49,7 @@ abstract class HeaderAbstract * @since 1.0.0 */ protected $account = 0; - + /** * Response status. * @@ -69,7 +67,7 @@ abstract class HeaderAbstract { $this->l11n = new Localization(); } - + /** * Set header locked. * @@ -80,7 +78,7 @@ abstract class HeaderAbstract // todo: maybe pass session as member and make lock not static self::$isLocked = true; } - + /** * Is header locked? * @@ -109,7 +107,7 @@ abstract class HeaderAbstract * Set localization * * @param Localization $l11n Localization - * + * * @return void * * @since 1.0.0 @@ -135,7 +133,7 @@ abstract class HeaderAbstract * Set account id * * @param int $account Account id - * + * * @return void * * @since 1.0.0 @@ -144,12 +142,12 @@ abstract class HeaderAbstract { $this->account = $account; } - + /** * Set status code * * @param int $status Status code - * + * * @return void * * @since 1.0.0 @@ -167,7 +165,7 @@ abstract class HeaderAbstract * * @since 1.0.0 */ - abstract public function generate(int $statusCode) /* : void */; + abstract public function generate(int $statusCode); /* : void */ /** * Get status code diff --git a/Message/Http/BrowserType.php b/Message/Http/BrowserType.php index 1fa9b75dd..933e45f61 100644 --- a/Message/Http/BrowserType.php +++ b/Message/Http/BrowserType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -22,23 +21,22 @@ use phpOMS\Stdlib\Base\Enum; * * Browser types can be used for statistics or in order to deliver browser specific content. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class BrowserType extends Enum { - /* public */ const IE = 'msie'; /* Internet Explorer */ - /* public */ const EDGE = 'edge'; /* Internet Explorer Edge 20+ */ - /* public */ const FIREFOX = 'firefox'; /* Firefox */ - /* public */ const SAFARI = 'safari'; /* Safari */ - /* public */ const CHROME = 'chrome'; /* Chrome */ - /* public */ const OPERA = 'opera'; /* Opera */ - /* public */ const NETSCAPE = 'netscape'; /* Netscape */ - /* public */ const MAXTHON = 'maxthon'; /* Maxthon */ + /* public */ const IE = 'msie'; /* Internet Explorer */ + /* public */ const EDGE = 'edge'; /* Internet Explorer Edge 20+ */ + /* public */ const FIREFOX = 'firefox'; /* Firefox */ + /* public */ const SAFARI = 'safari'; /* Safari */ + /* public */ const CHROME = 'chrome'; /* Chrome */ + /* public */ const OPERA = 'opera'; /* Opera */ + /* public */ const NETSCAPE = 'netscape'; /* Netscape */ + /* public */ const MAXTHON = 'maxthon'; /* Maxthon */ /* public */ const KONQUEROR = 'konqueror'; /* Konqueror */ - /* public */ const HANDHELD = 'mobile'; /* Handheld Browser */ - /* public */ const BLINK = 'blink'; /* Blink Browser */ + /* public */ const HANDHELD = 'mobile'; /* Handheld Browser */ + /* public */ const BLINK = 'blink'; /* Blink Browser */ } diff --git a/Message/Http/Header.php b/Message/Http/Header.php index b5d9e4330..32d0fc2df 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -21,11 +20,12 @@ use phpOMS\DataStorage\LockException; /** * Response class. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ class Header extends HeaderAbstract { @@ -71,18 +71,18 @@ class Header extends HeaderAbstract throw new LockException('HTTP header'); } + if (self::isSecurityHeader($key) && isset($this->header[$key])) { + throw new \Exception('Cannot change security headers.'); + } + $key = strtolower($key); if (!$overwrite && isset($this->header[$key])) { return false; - } elseif ($overwrite || !isset($this->header[$key])) { - if (self::isSecurityHeader($key) && isset($this->header[$key])) { - throw new \Exception('Cannot change security headers.'); - } - - unset($this->header[$key]); } + unset($this->header[$key]); + if (!isset($this->header[$key])) { $this->header[$key] = []; } @@ -91,7 +91,7 @@ class Header extends HeaderAbstract return true; } - + /** * Is security header. * @@ -128,10 +128,10 @@ class Header extends HeaderAbstract */ public function getStatusCode() : int { - if($this->status === 0) { + if ($this->status === 0) { $this->status = (int) \http_response_code(); } - + return parent::getStatusCode(); } @@ -148,12 +148,12 @@ class Header extends HeaderAbstract return getallheaders(); } - $headers = []; - foreach ($_SERVER as $name => $value) { - if (substr($name, 0, 5) == 'HTTP_') { - $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; - } - } + $headers = []; + foreach ($_SERVER as $name => $value) { + if (substr($name, 0, 5) == 'HTTP_') { + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } return $headers; } diff --git a/Message/Http/OSType.php b/Message/Http/OSType.php index 3c5c76f66..64478ca5c 100644 --- a/Message/Http/OSType.php +++ b/Message/Http/OSType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * OS Types which could be useful in order to create statistics or deliver OS specific content. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class OSType extends Enum diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 53eb4408e..a0c18c21b 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -26,11 +25,12 @@ use phpOMS\Uri\UriInterface; /** * Request class. * - * @category Framework - * @package phpOMS\Request + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ class Request extends RequestAbstract { @@ -76,6 +76,7 @@ class Request extends RequestAbstract { $this->header = new Header(); $this->header->setL11n($l11n ?? new Localization()); + $this->setMethod(RequestMethod::GET); $this->uri = $uri; $this->source = RequestSource::WEB; @@ -100,11 +101,10 @@ class Request extends RequestAbstract $this->initCurrentRequest(); $this->lock(); $this->cleanupGlobals(); + $this->setupUriBuilder(); } $this->data = array_change_key_case($this->data, CASE_LOWER); - - $this->setupUriBuilder(); } /** @@ -118,9 +118,9 @@ class Request extends RequestAbstract */ private function initCurrentRequest() /* : void */ { - $this->uri = new Http(Http::getCurrent()); - $this->data = $_GET ?? []; - $this->files = $_FILES ?? []; + $this->uri = new Http(Http::getCurrent()); + $this->data = $_GET ?? []; + $this->files = $_FILES ?? []; $this->header->getL11n()->setLanguage($this->loadRequestLanguage()); if (isset($_SERVER['CONTENT_TYPE'])) { @@ -148,7 +148,7 @@ class Request extends RequestAbstract */ private function loadRequestLanguage() : string { - if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { return 'EN'; } @@ -185,7 +185,7 @@ class Request extends RequestAbstract UriFactory::setQuery('/lang', $this->header->getL11n()->getLanguage()); // todo: flush previous - foreach($this->data as $key => $value) { + foreach ($this->data as $key => $value) { UriFactory::setQuery('?' . $key, $value); } } @@ -227,8 +227,8 @@ class Request extends RequestAbstract public function createRequestHashs(int $start = 0) /* : void */ { $this->hash = []; - $pathArray = $this->uri->getPathElements(); - + $pathArray = $this->uri->getPathElements(); + foreach ($pathArray as $key => $path) { $paths = []; for ($i = $start; $i < $key + 1; $i++) { @@ -281,13 +281,14 @@ class Request extends RequestAbstract public function getBrowser() : string { if (!isset($this->browser)) { - $arr = BrowserType::getConstants(); - $http_request_type = strtolower($_SERVER['HTTP_USER_AGENT']); + $arr = BrowserType::getConstants(); + $httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); foreach ($arr as $key => $val) { - if (stripos($http_request_type, $val)) { + if (stripos($httpUserAgent, $val)) { $this->browser = $val; - break; + + return $this->browser; } } } @@ -319,13 +320,14 @@ class Request extends RequestAbstract public function getOS() : string { if (!isset($this->os)) { - $arr = OSType::getConstants(); - $http_request_type = strtolower($_SERVER['HTTP_USER_AGENT']); - + $arr = OSType::getConstants(); + $httpUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); + foreach ($arr as $key => $val) { - if (stripos($http_request_type, $val)) { + if (stripos($httpUserAgent, $val)) { $this->os = $val; - break; + + return $this->os; } } } @@ -370,8 +372,7 @@ class Request extends RequestAbstract throw new \OutOfRangeException('Value "' . $port . '" is out of range.'); } - return - (!empty($_SERVER['HTTPS'] ?? '') && ($_SERVER['HTTPS'] ?? '') !== 'off') + return (!empty($_SERVER['HTTPS'] ?? '') && ($_SERVER['HTTPS'] ?? '') !== 'off') || (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https') || (($_SERVER['HTTP_X_FORWARDED_SSL'] ?? '') === 'on') || ($_SERVER['SERVER_PORT'] ?? '') == $port; diff --git a/Message/Http/RequestMethod.php b/Message/Http/RequestMethod.php index d68d133cf..ee41ab8f4 100644 --- a/Message/Http/RequestMethod.php +++ b/Message/Http/RequestMethod.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -20,18 +19,17 @@ use phpOMS\Stdlib\Base\Enum; /** * Request method enum. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RequestMethod extends Enum { - /* public */ const GET = 'GET'; /* GET */ - /* public */ const POST = 'POST'; /* POST */ - /* public */ const PUT = 'PUT'; /* PUT */ - /* public */ const DELETE = 'DELETE'; /* DELETE */ - /* public */ const HEAD = 'HEAD'; /* HEAD */ - /* public */ const TRACE = 'TRACE'; /* TRACE */ + /* public */ const GET = 'GET'; /* GET */ + /* public */ const POST = 'POST'; /* POST */ + /* public */ const PUT = 'PUT'; /* PUT */ + /* public */ const DELETE = 'DELETE'; /* DELETE */ + /* public */ const HEAD = 'HEAD'; /* HEAD */ + /* public */ const TRACE = 'TRACE'; /* TRACE */ } diff --git a/Message/Http/RequestStatus.php b/Message/Http/RequestStatus.php index 0a573911a..bd502f7e9 100644 --- a/Message/Http/RequestStatus.php +++ b/Message/Http/RequestStatus.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Request status enum. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RequestStatus extends Enum diff --git a/Message/Http/RequestStatusCode.php b/Message/Http/RequestStatusCode.php index 2d45d292c..9d684d6d4 100644 --- a/Message/Http/RequestStatusCode.php +++ b/Message/Http/RequestStatusCode.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; use phpOMS\Stdlib\Base\Enum; @@ -19,10 +18,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Request status enum. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RequestStatusCode extends Enum diff --git a/Message/Http/Response.php b/Message/Http/Response.php index a1576e4ce..a260e86cd 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; @@ -24,10 +23,9 @@ use phpOMS\Views\View; /** * Response class. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Response extends ResponseAbstract implements RenderableInterface @@ -106,8 +104,8 @@ class Response extends ResponseAbstract implements RenderableInterface { $types = $this->header->get('Content-Type'); - foreach($types as $type) { - if(stripos($type, MimeType::M_JSON) !== false) { + foreach ($types as $type) { + if (stripos($type, MimeType::M_JSON) !== false) { return $this->jsonSerialize(); } } @@ -148,8 +146,8 @@ class Response extends ResponseAbstract implements RenderableInterface } $types = $this->header->get('Content-Type'); - - if(stripos($types[0], MimeType::M_HTML) !== false) { + + if (stripos($types[0], MimeType::M_HTML) !== false) { return trim(preg_replace('/(\s{2,}|\n|\t)(?![^<>]*<\/pre>)/', ' ', $render)); } diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index 9feff40d1..5ef83c57b 100644 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Http; /** * Rest request class. * - * @category Framework - * @package phpOMS\Request + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Rest diff --git a/Message/Mail/EmailAbstract.php b/Message/Mail/EmailAbstract.php index 7ec52fb59..0f3a59e9d 100644 --- a/Message/Mail/EmailAbstract.php +++ b/Message/Mail/EmailAbstract.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Mail; /** * Mail class. * - * @category Framework - * @package phpOMS\Message\Mail + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class EmailAbstract @@ -32,7 +30,7 @@ class EmailAbstract * @var string * @since 1.0.0 */ - private $host = ''; + protected $host = ''; /** * Port. @@ -40,7 +38,7 @@ class EmailAbstract * @var int * @since 1.0.0 */ - private $port = 25; + protected $port = 25; /** * Use ssl. @@ -48,7 +46,7 @@ class EmailAbstract * @var bool * @since 1.0.0 */ - private $ssl = false; + protected $ssl = false; /** * Mailbox base. @@ -56,7 +54,7 @@ class EmailAbstract * @var string * @since 1.0.0 */ - private $mailbox = ''; + protected $mailbox = ''; /** * Timeout. @@ -64,7 +62,7 @@ class EmailAbstract * @var int * @since 1.0.0 */ - private $timeout = 30; + protected $timeout = 30; /** * Construct @@ -78,10 +76,10 @@ class EmailAbstract */ public function __construct(string $host = 'localhost', int $port = 25, int $timeout = 30, bool $ssl = false) { - $this->host = $host; - $this->port = $port; + $this->host = $host; + $this->port = $port; $this->timeout = $timeout; - $this->ssl = $ssl; + $this->ssl = $ssl; imap_timeout(IMAP_OPENTIMEOUT, $timeout); imap_timeout(IMAP_READTIMEOUT, $timeout); @@ -92,21 +90,21 @@ class EmailAbstract /** * Decode * - * @param string $host Content to decode + * @param string $content Content to decode * @param int $encoding Encoding type * + * @return string + * * @since 1.0.0 */ public static function decode(string $content, int $encoding) { if ($encoding == 3) { return imap_base64($content); + } elseif ($encoding == 1) { + return imap_8bit($content); } else { - if ($encoding == 1) { - return imap_8bit($content); - } else { - return imap_qprint($content); - } + return imap_qprint($content); } } @@ -127,7 +125,7 @@ class EmailAbstract */ public function disconnect() { - if(!isset($this->con)) { + if (!isset($this->con)) { imap_close($this->con); $this->con = null; } @@ -138,7 +136,7 @@ class EmailAbstract * * @param string $user Username * @param string $pass Password - * + * * @return void * * @since 1.0.0 @@ -148,7 +146,7 @@ class EmailAbstract $this->mailbox = substr($this->mailbox, 0, -1) . ($this->ssl ? '/ssl/validate-cert' : '/novalidate-cert') . '}'; // /novalidate-cert - if(!isset($this->con)) { + if (!isset($this->con)) { $this->con = imap_open($this->mailbox . 'INBOX', $user, $pass); } } @@ -410,7 +408,7 @@ class EmailAbstract /** * Create mailbox - * + * * @param string $mailbox Mailbox to create * * @return bool @@ -424,7 +422,7 @@ class EmailAbstract /** * Rename mailbox - * + * * @param string $old Old mailbox name * @param string $new New mailbox name * @@ -439,7 +437,7 @@ class EmailAbstract /** * Delete mailbox - * + * * @param string $mailbox Mailbox to delete * * @return bool @@ -453,7 +451,7 @@ class EmailAbstract /** * Check message to delete - * + * * @param int $id Message id * * @return bool @@ -467,7 +465,7 @@ class EmailAbstract /** * Delete all marked messages - * + * * @return bool * * @since 1.0.0 @@ -479,7 +477,7 @@ class EmailAbstract /** * Check message to delete - * + * * @param int $length Amount of message overview * @param int $start Start index of the overview for pagination * @@ -489,8 +487,8 @@ class EmailAbstract */ public function getMessageOverview(int $length = 0, int $start = 1) : array { - if($length === 0) { - $info = imap_check($this->con); + if ($length === 0) { + $info = imap_check($this->con); $length = $info->Nmsgs; } @@ -499,7 +497,7 @@ class EmailAbstract /** * Count messages - * + * * @return int * * @since 1.0.0 @@ -511,7 +509,7 @@ class EmailAbstract /** * Get message header - * + * * @param int $id Message id * * @return string diff --git a/Message/Mail/Imap.php b/Message/Mail/Imap.php index 4e19db672..73c351196 100644 --- a/Message/Mail/Imap.php +++ b/Message/Mail/Imap.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Mail; /** * Imap mail class. * - * @category Framework - * @package phpOMS\Message\Mail + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Imap extends EmailAbstract @@ -46,7 +44,7 @@ class Imap extends EmailAbstract * * @param string $user Username * @param string $pass Password - * + * * @return void * * @since 1.0.0 diff --git a/Message/Mail/Mail.php b/Message/Mail/Mail.php index bc52fb4c5..c81ca4f91 100644 --- a/Message/Mail/Mail.php +++ b/Message/Mail/Mail.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Mail; /** * Mail class. * - * @category Framework - * @package phpOMS\Message\Mail + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Mail @@ -223,5 +221,4 @@ class Mail { $this->encoding = $encoding; } - } diff --git a/Message/Mail/Nntp.php b/Message/Mail/Nntp.php index a0a905d23..86d7dc32a 100644 --- a/Message/Mail/Nntp.php +++ b/Message/Mail/Nntp.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Mail; /** * Imap mail class. * - * @category Framework - * @package phpOMS\Message\Mail + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Nntp extends EmailAbstract @@ -46,7 +44,7 @@ class Nntp extends EmailAbstract * * @param string $user Username * @param string $pass Password - * + * * @return void * * @since 1.0.0 diff --git a/Message/Mail/Pop3.php b/Message/Mail/Pop3.php index 38830a32d..c9b87dac4 100644 --- a/Message/Mail/Pop3.php +++ b/Message/Mail/Pop3.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message\Mail; /** * Imap mail class. * - * @category Framework - * @package phpOMS\Message\Mail + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Pop3 extends EmailAbstract @@ -46,7 +44,7 @@ class Pop3 extends EmailAbstract * * @param string $user Username * @param string $pass Password - * + * * @return void * * @since 1.0.0 diff --git a/Message/MessageInterface.php b/Message/MessageInterface.php index 071b36133..32dc4561d 100644 --- a/Message/MessageInterface.php +++ b/Message/MessageInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; /** * Message interface. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface MessageInterface diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 8c2edfff5..149ea4b55 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -4,19 +4,17 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; -use phpOMS\Localization\Localization; use phpOMS\Uri\UriInterface; /** @@ -24,10 +22,9 @@ use phpOMS\Uri\UriInterface; * * @property mixed request * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RequestAbstract implements MessageInterface @@ -75,7 +72,7 @@ abstract class RequestAbstract implements MessageInterface /** * Request type. * - * @var \phpOMS\Message\RequestSource + * @var int * @since 1.0.0 */ protected $source = RequestSource::UNDEFINED; @@ -201,11 +198,17 @@ abstract class RequestAbstract implements MessageInterface } /** - * {@inheritdoc} + * Get data. + * + * @param mixed $key Data key + * + * @return mixed + * + * @since 1.0.0 */ public function getData($key = null) { - if(!isset($key)) { + if (!isset($key)) { return $this->data; } @@ -214,6 +217,20 @@ abstract class RequestAbstract implements MessageInterface return $this->data[$key] ?? null; } + /** + * Check if has data. + * + * @param mixed $key Data key + * + * @return bool + * + * @since 1.0.0 + */ + public function hasData($key) : bool + { + return isset($this->data[$key]); + } + /** * Set request data. * @@ -266,7 +283,7 @@ abstract class RequestAbstract implements MessageInterface /** * {@inheritdoc} */ - public abstract function getOrigin() : string; + abstract public function getOrigin() : string; /** * {@inheritdoc} diff --git a/Message/RequestSource.php b/Message/RequestSource.php index 3b30da6df..a32d3a1b8 100644 --- a/Message/RequestSource.php +++ b/Message/RequestSource.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; @@ -20,16 +19,15 @@ use phpOMS\Stdlib\Base\Enum; /** * Request source enum. * - * @category Request * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class RequestSource extends Enum { - /* public */ const WEB = 0; /* This is a http request */ - /* public */ const CONSOLE = 1; /* Request is a console command */ - /* public */ const SOCKET = 2; /* Request through socket connection */ - /* public */ const UNDEFINED = 3; /* Request through socket connection */ + /* public */ const WEB = 0; /* This is a http request */ + /* public */ const CONSOLE = 1; /* Request is a console command */ + /* public */ const SOCKET = 2; /* Request through socket connection */ + /* public */ const UNDEFINED = 3; } diff --git a/Message/ResponseAbstract.php b/Message/ResponseAbstract.php index a721adc5b..a54745877 100644 --- a/Message/ResponseAbstract.php +++ b/Message/ResponseAbstract.php @@ -4,26 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; -use phpOMS\Utils\ArrayUtils; - /** * Response abstract class. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable diff --git a/Message/ResponseType.php b/Message/ResponseType.php index 5681897b8..cf31a6d8d 100644 --- a/Message/ResponseType.php +++ b/Message/ResponseType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; @@ -20,15 +19,14 @@ use phpOMS\Stdlib\Base\Enum; /** * Request type enum. * - * @category Framework * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ResponseType extends Enum { - /* public */ const HTTP = 0; /* HTTP */ - /* public */ const SOCKET = 1; /* Socket */ + /* public */ const HTTP = 0; /* HTTP */ + /* public */ const SOCKET = 1; /* Socket */ /* public */ const CONSOLE = 2; /* Console */ } diff --git a/Message/Socket/Request.php b/Message/Socket/Request.php index e44169e2b..d193044ec 100644 --- a/Message/Socket/Request.php +++ b/Message/Socket/Request.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Message\Socket; +declare(strict_types = 1); +namespace phpOMS\Message\Socket; class Request { -} \ No newline at end of file +} diff --git a/Message/Socket/Response.php b/Message/Socket/Response.php index df4a9bfcd..8f8b9512e 100644 --- a/Message/Socket/Response.php +++ b/Message/Socket/Response.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); - namespace phpOMS\Message\Socket; +declare(strict_types = 1); +namespace phpOMS\Message\Socket; class Response { -} \ No newline at end of file +} diff --git a/Message/UploadedFileInterface.php b/Message/UploadedFileInterface.php index 2ab08acb7..af65d982b 100644 --- a/Message/UploadedFileInterface.php +++ b/Message/UploadedFileInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Message; /** * Upload interface. * - * @category Framework - * @package phpOMS\Response + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface UploadedFileInterface diff --git a/Model/Html/Head.php b/Model/Html/Head.php index 250d10f80..a71212288 100644 --- a/Model/Html/Head.php +++ b/Model/Html/Head.php @@ -4,30 +4,28 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Model\Html; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; - +use phpOMS\Localization\ISO639x1Enum; /** * Head class. * * Responsible for handling everything that's going on in the * - * @category Framework - * @package phpOMS/Model + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Head implements RenderableInterface @@ -39,7 +37,7 @@ class Head implements RenderableInterface * @var string * @since 1.0.0 */ - private $language = ''; + private $language = ISO639x1Enum::_EN; /** * Page title. @@ -166,6 +164,18 @@ class Head implements RenderableInterface $this->language = $language; } + /** + * Get page language. + * + * @return string + * + * @since 1.0.0 + */ + public function getLanguage() : string + { + return $this->language; + } + /** * Get the evaluated contents of the object. * @@ -175,12 +185,10 @@ class Head implements RenderableInterface */ public function render() : string { - $head = ''; - if ($this->hasContent) { - $head .= $this->meta->render(); - $head .= $this->renderStyle(); - $head .= $this->renderScript(); - } + $head = ''; + $head .= $this->meta->render(); + $head .= $this->renderStyle(); + $head .= $this->renderScript(); return $head; } diff --git a/Model/Html/Meta.php b/Model/Html/Meta.php index 1725be601..efcbe5133 100644 --- a/Model/Html/Meta.php +++ b/Model/Html/Meta.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Model\Html; @@ -20,10 +19,9 @@ use phpOMS\Contract\RenderableInterface; /** * Meta class. * - * @category Framework - * @package phpOMS/Model + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Meta implements RenderableInterface @@ -43,7 +41,7 @@ class Meta implements RenderableInterface * @var string * @since 1.0.0 */ - private $author = null; + private $author = ''; /** * Charset. @@ -51,7 +49,7 @@ class Meta implements RenderableInterface * @var string * @since 1.0.0 */ - private $charset = null; + private $charset = ''; /** * Description. @@ -59,15 +57,7 @@ class Meta implements RenderableInterface * @var string * @since 1.0.0 */ - private $description = null; - - /** - * Language. - * - * @var string - * @since 1.0.0 - */ - private $language = 'en'; + private $description = ''; /** * Add keyword. @@ -175,41 +165,15 @@ class Meta implements RenderableInterface $this->description = $description; } - /** - * Get language. - * - * @return string Language - * - * @since 1.0.0 - */ - public function getLanguage() : string - { - return $this->language; - } - - /** - * Set language. - * - * @param string $language Language - * - * @return void - * - * @since 1.0.0 - */ - public function setLanguage(string $language) /* : void */ - { - $this->language = $language; - } - /** * {@inheritdoc} */ public function render() : string { return (count($this->keywords) > 0 ? '"' : '') - . (isset($this->author) ? '' : '') - . (isset($this->description) ? '' : '') - . (isset($this->charset) ? '' : '') + . (!empty($this->author) ? '' : '') + . (!empty($this->description) ? '' : '') + . (!empty($this->charset) ? '' : '') . ''; } } diff --git a/Module/ActivateAbstract.php b/Module/ActivateAbstract.php deleted file mode 100644 index 91957ea00..000000000 --- a/Module/ActivateAbstract.php +++ /dev/null @@ -1,93 +0,0 @@ -getDirectory() . '/Admin/Routes/http.php'); - self::activateInDatabase($dbPool, $info); - } - - /** - * Install routes. - * - * @param string $destRoutePath Destination route path - * @param string $srcRoutePath Source route path - * - * @return void - * - * @since 1.0.0 - */ - private static function activateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ - { - // todo: remove route - } - - /** - * Deactivate module in database. - * - * @param DatabasePool $dbPool Database instance - * @param InfoManager $info Module info - * - * @return void - * - * @since 1.0.0 - */ - public static function activateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ - { - switch ($dbPool->get()->getType()) { - case DatabaseType::MYSQL: - $dbPool->get()->con->beginTransaction(); - - $sth = $dbPool->get()->con->prepare( - 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' - ); - - $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); - $sth->bindValue(':active', 1, \PDO::PARAM_INT); - $sth->execute(); - - $dbPool->get()->con->commit(); - - break; - } - } -} diff --git a/Module/ConsoleInterface.php b/Module/ConsoleInterface.php index e84fad460..b89f1b36e 100644 --- a/Module/ConsoleInterface.php +++ b/Module/ConsoleInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; /** * Console module interface. * - * @category Module * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ConsoleInterface diff --git a/Module/DeactivateAbstract.php b/Module/DeactivateAbstract.php deleted file mode 100644 index 1e3f3b763..000000000 --- a/Module/DeactivateAbstract.php +++ /dev/null @@ -1,93 +0,0 @@ -getDirectory() . '/Admin/Routes/http.php'); - self::deactivateInDatabase($dbPool, $info); - } - - /** - * Install routes. - * - * @param string $destRoutePath Destination route path - * @param string $srcRoutePath Source route path - * - * @return void - * - * @since 1.0.0 - */ - private static function deactivateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ - { - // todo: remove route - } - - /** - * Deactivate module in database. - * - * @param DatabasePool $dbPool Database instance - * @param InfoManager $info Module info - * - * @return void - * - * @since 1.0.0 - */ - public static function deactivateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ - { - switch ($dbPool->get()->getType()) { - case DatabaseType::MYSQL: - $dbPool->get()->con->beginTransaction(); - - $sth = $dbPool->get()->con->prepare( - 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' - ); - - $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); - $sth->bindValue(':active', 0, \PDO::PARAM_INT); - $sth->execute(); - - $dbPool->get()->con->commit(); - - break; - } - } -} diff --git a/Module/Exception/InvalidModuleException.php b/Module/Exception/InvalidModuleException.php index 0ffdab349..702dd394f 100644 --- a/Module/Exception/InvalidModuleException.php +++ b/Module/Exception/InvalidModuleException.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module\Exception; /** * Zero devision exception. * - * @category Framework - * @package phpOMS/Uri + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidModuleException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class InvalidModuleException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Module/Exception/InvalidThemeException.php b/Module/Exception/InvalidThemeException.php index bfe872281..e2c31f84e 100644 --- a/Module/Exception/InvalidThemeException.php +++ b/Module/Exception/InvalidThemeException.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module\Exception; /** * Zero devision exception. * - * @category Framework - * @package phpOMS/Uri + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidThemeException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class InvalidThemeException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Module/InfoManager.php b/Module/InfoManager.php index f7ff08fef..f5087cb81 100644 --- a/Module/InfoManager.php +++ b/Module/InfoManager.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; @@ -23,10 +22,9 @@ use phpOMS\Utils\ArrayUtils; * * Handling the info files for modules * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InfoManager diff --git a/Module/InstallerAbstract.php b/Module/InstallerAbstract.php index 8dbf6e88b..2394cf644 100644 --- a/Module/InstallerAbstract.php +++ b/Module/InstallerAbstract.php @@ -4,18 +4,18 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\Exception\InvalidDatabaseTypeException; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\System\File\Local\Directory; use phpOMS\System\File\PathException; @@ -25,10 +25,9 @@ use phpOMS\Utils\Parser\Php\ArrayParser; /** * Installer Abstract class. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InstallerAbstract @@ -81,6 +80,8 @@ class InstallerAbstract $dbPool->get()->con->commit(); break; + default: + throw new InvalidDatabaseTypeException($dbPool->get()->getType()); } } @@ -115,7 +116,7 @@ class InstallerAbstract private static function activate(DatabasePool $dbPool, InfoManager $info) /* : void */ { /** @var ActivateAbstract $class */ - $class = '\Modules\\' . $info->getDirectory() . '\Admin\Activate'; + $class = '\Modules\\' . $info->getDirectory() . '\Admin\Status'; $class::activate($dbPool, $info); } @@ -201,5 +202,4 @@ class InstallerAbstract } } } - } diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 8e4aa87dc..7864b19c8 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; /** * Module abstraction class. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ModuleAbstract @@ -76,7 +74,7 @@ abstract class ModuleAbstract /** * Dependencies. * - * @var string + * @var string[] * @since 1.0.0 */ protected static $dependencies = []; diff --git a/Module/ModuleFactory.php b/Module/ModuleFactory.php index 338d2852d..c16bc1070 100644 --- a/Module/ModuleFactory.php +++ b/Module/ModuleFactory.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; @@ -23,10 +22,9 @@ use phpOMS\ApplicationAbstract; * * Responsible for initializing modules as singletons * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ModuleFactory @@ -75,7 +73,7 @@ class ModuleFactory $class = '\\Modules\\' . $module . '\\Controller'; if (!isset(self::$loaded[$module])) { - if(Autoloader::exists($class) !== false) { + if (Autoloader::exists($class) !== false) { try { $obj = new $class($app); self::$loaded[$module] = $obj; diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index 9af363de9..4e3b7da16 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -4,21 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; use phpOMS\ApplicationAbstract; use phpOMS\Autoloader; use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\Exception\InvalidDatabaseTypeException; use phpOMS\Message\Http\Request; +use phpOMS\Message\RequestAbstract; use phpOMS\System\File\PathException; use phpOMS\Module\Exception\InvalidModuleException; @@ -27,10 +28,9 @@ use phpOMS\Module\Exception\InvalidModuleException; * * General module functionality such as listings and initialization. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ModuleManager @@ -102,20 +102,20 @@ class ModuleManager */ public function __construct(ApplicationAbstract $app, string $modulePath = '') { - $this->app = $app; + $this->app = $app; $this->modulePath = $modulePath; } /** * Get language files. * - * @param Request $request Request + * @param RequestAbstract $request Request * * @return array * * @since 1.0.0 */ - public function getLanguageFiles(Request $request) : array + public function getLanguageFiles(RequestAbstract $request) : array { $files = $this->getUriLoad($request); @@ -132,13 +132,13 @@ class ModuleManager /** * Get modules that run on this page. * - * @param Request $request Request + * @param RequestAbstract $request Request * * @return array * * @since 1.0.0 */ - public function getUriLoad(Request $request) : array + public function getUriLoad(RequestAbstract $request) : array { if (!isset($this->uriLoad)) { switch ($this->app->dbPool->get('select')->getType()) { @@ -148,7 +148,7 @@ class ModuleManager $i = 1; $c = count($uriHash); - + for ($k = 0; $k < $c; $k++) { $uriPdo .= ':pid' . $i . ','; $i++; @@ -175,6 +175,9 @@ class ModuleManager $sth->execute(); $this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP); + break; + default: + throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType()); } } @@ -184,25 +187,34 @@ class ModuleManager /** * Get all installed modules that are active (not just on this uri). * + * @param bool $useCache Use Cache or load new + * * @return array * * @since 1.0.0 */ - public function getActiveModules() : array + public function getActiveModules(bool $useCache = true) : array { - if ($this->active === null) { + if ($this->active === null || !$useCache) { switch ($this->app->dbPool->get('select')->getType()) { case DatabaseType::MYSQL: $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(); $this->active = $sth->fetchAll(\PDO::FETCH_COLUMN); break; + default: + throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType()); } } return $this->active; } + public function isActive(string $module) : bool + { + return in_array($module, $this->getActiveModules(false)); + } + /** * Get all modules in the module directory. * @@ -242,59 +254,29 @@ class ModuleManager */ public function getAvailableModules() : array { - } - - /** - * Deactivate module. - * - * @param string $module Module name - * - * @return bool - * - * @since 1.0.0 - */ - public function deactivate(string $module) : bool - { - $installed = $this->getInstalledModules(); - - if (isset($installed[$module])) { - return false; - } - - try { - $info = $this->loadInfo($module); - - $this->deactivateModule($info); - - return true; - } catch (PathException $e) { - // todo: handle module doesn't exist or files are missing - //echo $e->getMessage(); - - return false; - } catch (\Exception $e) { - //echo $e->getMessage(); - - return false; - } + return []; } /** * Get all installed modules. * + * @param bool $useCache Use Cache + * * @return array * * @since 1.0.0 */ - public function getInstalledModules() : array + public function getInstalledModules(bool $useCache = true) : array { - if ($this->installed === null) { + if ($this->installed === null || !$useCache) { 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; + default: + throw new InvalidDatabaseTypeException($this->app->dbPool->get('select')->getType()); } } @@ -324,6 +306,41 @@ class ModuleManager return $info; } + /** + * Deactivate module. + * + * @param string $module Module name + * + * @return bool + * + * @since 1.0.0 + */ + public function deactivate(string $module) : bool + { + $installed = $this->getInstalledModules(false); + + if (!isset($installed[$module])) { + return false; + } + + try { + $info = $this->loadInfo($module); + + $this->deactivateModule($info); + + return true; + } catch (PathException $e) { + // todo: handle module doesn't exist or files are missing + //echo $e->getMessage(); + + return false; + } catch (\Exception $e) { + //echo $e->getMessage(); + + return false; + } + } + /** * Deactivate module. * @@ -337,7 +354,7 @@ class ModuleManager */ private function deactivateModule(InfoManager $info) /* : void */ { - $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Deactivate'; + $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Status'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); @@ -358,9 +375,9 @@ class ModuleManager */ public function activate(string $module) : bool { - $installed = $this->getInstalledModules(); + $installed = $this->getInstalledModules(false); - if (isset($installed[$module])) { + if (!isset($installed[$module])) { return false; } @@ -395,7 +412,7 @@ class ModuleManager */ private function activateModule(InfoManager $info) /* : void */ { - $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Activate'; + $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Status'; if (!Autoloader::exists($class)) { throw new InvalidModuleException($info->getDirectory()); @@ -410,15 +427,15 @@ class ModuleManager * * @param string $module Module name * - * @return bool + * @return void * * @throws InvalidModuleException Throws this exception in case the installer doesn't exist * * @since 1.0.0 */ - public function reInit(string $module) : bool + public function reInit(string $module) /* : void */ { - $info = $this->loadInfo($module); + $info = $this->loadInfo($module); $class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer'; if (!Autoloader::exists($class)) { @@ -440,7 +457,7 @@ class ModuleManager */ public function install(string $module) : bool { - $installed = $this->getInstalledModules(); + $installed = $this->getInstalledModules(false); if (isset($installed[$module])) { return false; @@ -471,13 +488,8 @@ class ModuleManager return true; } catch (PathException $e) { - // todo: handle module doesn't exist or files are missing - //echo $e->getMessage(); - return false; } catch (\Exception $e) { - //echo $e->getMessage(); - return false; } } @@ -537,8 +549,7 @@ class ModuleManager { if (file_exists($this->modulePath . '/' . $from . '/Admin/Install/' . $for . '.php')) { $class = '\\Modules\\' . $from . '\\Admin\\Install\\' . $for; - /** @var $class InstallerAbstract */ - $class::install($this->modulePath, $this->app->dbPool, null); + $class::install($this->modulePath, $this->app->dbPool); } } @@ -626,7 +637,7 @@ class ModuleManager { $toInit = $this->getRoutedModules($request); - foreach($toInit as $module) { + foreach ($toInit as $module) { $this->initModuleController($module); } } diff --git a/Module/ModuleStatus.php b/Module/ModuleStatus.php new file mode 100644 index 000000000..b9cb9f600 --- /dev/null +++ b/Module/ModuleStatus.php @@ -0,0 +1,30 @@ +path = $path; + $this->path = $path; $this->basePath = $basePath; } /** * Extract package to temporary destination - * + * * @param string $path Temporary extract path - * - * @return bool + * + * @return void * * @since 1.0.0 */ - public function extract(string $path) : bool + public function extract(string $path) /* : void */ { $this->extractPath = $path; Zip::unpack($this->path, $this->extractPath); @@ -107,7 +105,7 @@ class PackageManager */ public function load() /* : void */ { - if(!file_exists($this->extractPath)) { + if (!file_exists($this->extractPath)) { throw new PathException($this->extractPath); } @@ -116,7 +114,7 @@ class PackageManager /** * Validate package integrity - * + * * @return bool Returns true if the package is authentic, false otherwise * * @since 1.0.0 @@ -128,21 +126,19 @@ class PackageManager /** * 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 + private function hashFiles() : string { $files = Directory::list($this->extractPath . '/package'); $state = \sodium_crypto_generichash_init(); - foreach($files as $file) { - if($file === 'package.cert') { - continue; + foreach ($files as $file) { + if ($file === 'package.cert') { + continue; } \sodium_crypto_generichash_update($state, file_get_contents($this->extractPath . '/package/' . $file)); @@ -153,19 +149,21 @@ class PackageManager /** * Install package - * + * * @return void * + * @throws \Exception + * * @since 1.0.0 */ public function install() /* : void */ { - if(!$this->isValid()) { + if (!$this->isValid()) { throw new \Exception(); } - foreach($this->info as $key => $components) { - if(function_exists($this->{$key})) { + foreach ($this->info as $key => $components) { + if (function_exists($this->{$key})) { $this->{$key}($components); } } @@ -173,29 +171,33 @@ class PackageManager /** * Move files - * + * + * @param mixed $components Component data + * * @return void * * @since 1.0.0 */ private function move($components) { - foreach($components as $component) { + foreach ($components as $component) { LocalStorage::move($this->basePath . '/' . $component['from'], $this->basePath . '/' . $component['to'], true); } } /** * Copy files - * + * + * @param mixed $components Component data + * * @return void * * @since 1.0.0 */ private function copy($components) { - foreach($components as $component) { - if(StringUtils::startsWith($component['from'], 'Package/')) { + 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); @@ -205,40 +207,44 @@ class PackageManager /** * Delete files - * + * + * @param mixed $components Component data + * * @return void * * @since 1.0.0 */ private function delete($components) { - foreach($components as $component) { + foreach ($components as $component) { LocalStorage::delete($this->basePath . '/' . $component); } } /** * Execute commands - * + * + * @param mixed $components Component data + * * @return void * * @since 1.0.0 */ - private function execute($components) + private function execute($components) { - foreach($components as $component) { + foreach ($components as $component) { include $this->basePath . '/' . $component; } } /** * Cleanup after installation - * + * * @return void * * @since 1.0.0 */ - public function cleanup() + public function cleanup() { File::delete($this->path); Directory::delete($this->extractPath); @@ -246,7 +252,10 @@ class PackageManager /** * Authenticate package - * + * + * @param string $signedHash Hash to authenticate + * @param string $rawHash Hash to compare against + * * @return bool * * @since 1.0.0 @@ -270,4 +279,4 @@ class PackageManager return $unsignedHash === $rawHash; } -} \ No newline at end of file +} diff --git a/Module/SocketInterface.php b/Module/SocketInterface.php index 7a81858a2..55b7c44dd 100644 --- a/Module/SocketInterface.php +++ b/Module/SocketInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; /** * Socket module interface. * - * @category Module * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface SocketInterface diff --git a/Module/StatusAbstract.php b/Module/StatusAbstract.php new file mode 100644 index 000000000..b4c9083f1 --- /dev/null +++ b/Module/StatusAbstract.php @@ -0,0 +1,157 @@ +getDirectory() . '/Admin/Routes/http.php'); + self::activateInDatabase($dbPool, $info); + } + + /** + * Install routes. + * + * @param string $destRoutePath Destination route path + * @param string $srcRoutePath Source route path + * + * @return void + * + * @since 1.0.0 + */ + private static function activateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ + { + // todo: remove route + } + + /** + * Deactivate module in database. + * + * @param DatabasePool $dbPool Database instance + * @param InfoManager $info Module info + * + * @return void + * + * @since 1.0.0 + */ + public static function activateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ + { + switch ($dbPool->get()->getType()) { + case DatabaseType::MYSQL: + $dbPool->get()->con->beginTransaction(); + + $sth = $dbPool->get()->con->prepare( + 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' + ); + + $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); + $sth->bindValue(':active', 1, \PDO::PARAM_INT); + $sth->execute(); + + $dbPool->get()->con->commit(); + + break; + default: + throw new InvalidDatabaseTypeException($dbPool->get()->getType()); + } + } + + /** + * Deactivate module. + * + * @param DatabasePool $dbPool Database instance + * @param InfoManager $info Module info + * + * @return void + * + * @since 1.0.0 + */ + public static function deactivate(DatabasePool $dbPool, InfoManager $info) /* : void */ + { + self::deactivateRoutes(__DIR__ . '/../../Web/Routes.php', __DIR__ . '/../../Modules/' . $info->getDirectory() . '/Admin/Routes/http.php'); + self::deactivateInDatabase($dbPool, $info); + } + + /** + * Install routes. + * + * @param string $destRoutePath Destination route path + * @param string $srcRoutePath Source route path + * + * @return void + * + * @since 1.0.0 + */ + private static function deactivateRoutes(string $destRoutePath, string $srcRoutePath) /* : void */ + { + // todo: remove route + } + + /** + * Deactivate module in database. + * + * @param DatabasePool $dbPool Database instance + * @param InfoManager $info Module info + * + * @return void + * + * @since 1.0.0 + */ + public static function deactivateInDatabase(DatabasePool $dbPool, InfoManager $info) /* : void */ + { + switch ($dbPool->get()->getType()) { + case DatabaseType::MYSQL: + $dbPool->get()->con->beginTransaction(); + + $sth = $dbPool->get()->con->prepare( + 'UPDATE `' . $dbPool->get()->prefix . 'module` SET `module_active` = :active WHERE `module_id` = :internal;' + ); + + $sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT); + $sth->bindValue(':active', 0, \PDO::PARAM_INT); + $sth->execute(); + + $dbPool->get()->con->commit(); + + break; + default: + throw new InvalidDatabaseTypeException($dbPool->get()->getType()); + } + } +} diff --git a/Module/UninstallAbstract.php b/Module/UninstallAbstract.php index 8bce9306f..c04eddf0d 100644 --- a/Module/UninstallAbstract.php +++ b/Module/UninstallAbstract.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\DatabasePool; /** * Installer Abstract class. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class UninstallAbstract diff --git a/Module/UpdateAbstract.php b/Module/UpdateAbstract.php index 2bc826f9f..3523ded9e 100644 --- a/Module/UpdateAbstract.php +++ b/Module/UpdateAbstract.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; @@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\DatabasePool; /** * Installer Abstract class. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class UpdateAbstract diff --git a/Module/WebInterface.php b/Module/WebInterface.php index f1e95509f..2eea229c7 100644 --- a/Module/WebInterface.php +++ b/Module/WebInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package Framework * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Module; /** * Web module interface. * - * @category Framework - * @package phpOMS\Module + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface WebInterface diff --git a/Pattern/Mediator.php b/Pattern/Mediator.php deleted file mode 100644 index 97eda8ce4..000000000 --- a/Pattern/Mediator.php +++ /dev/null @@ -1,84 +0,0 @@ -sock]; - //if(socket_select($read, $write = null, $except = null, 0) < 1) { + //if (socket_select($read, $write = null, $except = null, 0) < 1) { // error // socket_last_error(); // socket_strerror(socket_last_error()); diff --git a/Socket/Client/ClientConnection.php b/Socket/Client/ClientConnection.php index 8897cbf68..e3f97799c 100644 --- a/Socket/Client/ClientConnection.php +++ b/Socket/Client/ClientConnection.php @@ -4,32 +4,30 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Client; /** * Client socket class. * - * @category Framework - * @package phpOMS\Socket\Client + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ClientConnection { - private $id = 0; - private $socket = null; + private $id = 0; + private $socket = null; private $handshake = false; - private $pid = null; + private $pid = null; private $connected = true; public function __construct($id, $socket) diff --git a/Socket/Client/NullClientConnection.php b/Socket/Client/NullClientConnection.php index 531405d99..5963d562d 100644 --- a/Socket/Client/NullClientConnection.php +++ b/Socket/Client/NullClientConnection.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Client; /** * Client socket class. * - * @category Framework - * @package phpOMS\Socket\Client + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullClientConnection extends ClientConnection diff --git a/Socket/CommandManager.php b/Socket/CommandManager.php index 3d3462358..ae2b608f7 100644 --- a/Socket/CommandManager.php +++ b/Socket/CommandManager.php @@ -4,22 +4,20 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket; /** * CommandManager class. * - * @category Framework - * @package phpOMS\Socket + * @package Framework * @since 1.0.0 * * @todo : Hey, this looks like a copy of an event manager! diff --git a/Socket/Packets/Header.php b/Socket/Packets/Header.php index 2e28616e8..c1381c1a6 100644 --- a/Socket/Packets/Header.php +++ b/Socket/Packets/Header.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Packets; @@ -20,10 +19,9 @@ namespace phpOMS\Socket\Packets; * * Parsing/serializing arrays to and from php file * - * @category System - * @package Framework + * @package System * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Header implements \Serializable @@ -103,9 +101,9 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function getType() + public function getType() : int { - return $this->type; + return (int) $this->type; } /** @@ -115,7 +113,7 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function setType($type) /* : void */ + public function setType(int $type) /* : void */ { $this->type = $type; } @@ -125,7 +123,7 @@ class Header implements \Serializable * * @since 1.0.0 */ - public function getSubtype() + public function getSubtype() : int { return $this->subtype; } diff --git a/Socket/Packets/PacketAbstract.php b/Socket/Packets/PacketAbstract.php index 8a9455db2..c4ce5eba7 100644 --- a/Socket/Packets/PacketAbstract.php +++ b/Socket/Packets/PacketAbstract.php @@ -4,27 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Packets; - /** * Server class. * * Parsing/serializing arrays to and from php file * - * @category System - * @package Framework + * @package System * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PacketAbstract implements \Serializable diff --git a/Socket/Packets/PacketManager.php b/Socket/Packets/PacketManager.php index 4753c2684..df29e2ca0 100644 --- a/Socket/Packets/PacketManager.php +++ b/Socket/Packets/PacketManager.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Packets; @@ -23,10 +22,9 @@ use phpOMS\Socket\Server\ClientManager; * * Parsing/serializing arrays to and from php file * - * @category System - * @package Framework + * @package System * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PacketManager diff --git a/Socket/Packets/PacketType.php b/Socket/Packets/PacketType.php index 62011fde1..d5694e2fa 100644 --- a/Socket/Packets/PacketType.php +++ b/Socket/Packets/PacketType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Packets; @@ -20,23 +19,22 @@ use phpOMS\Stdlib\Base\Enum; /** * Packet type enum. * - * @category Framework - * @package phpOMS\Socket\Packets + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PacketType extends Enum { - /* public */ const CONNECT = 0; /* Client connection (server/sender) */ + /* public */ const CONNECT = 0; /* Client connection (server/sender) */ /* public */ const DISCONNECT = 1; /* Client disconnection (server/sender) */ - /* public */ const KICK = 2; /* Kick (server/client/sender) */ - /* public */ const PING = 3; /* Ping (server/sender) */ - /* public */ const HELP = 4; /* Help (server/sender) */ - /* public */ const RESTART = 5; /* Restart server (server/all clients/client) */ - /* public */ const MSG = 6; /* Message (server/sender/client/all clients?) */ - /* public */ const LOGIN = 7; /* Login (server/sender) */ - /* public */ const LOGOUT = 8; /* Logout (server/sender) */ - /* public */ const ACCMODIFY = 9; /* Account modification (server/sender (admin)/user) */ - /* public */ const MODULE = 999999999; /* Module packet ??? */ + /* public */ const KICK = 2; /* Kick (server/client/sender) */ + /* public */ const PING = 3; /* Ping (server/sender) */ + /* public */ const HELP = 4; /* Help (server/sender) */ + /* public */ const RESTART = 5; /* Restart server (server/all clients/client) */ + /* public */ const MSG = 6; /* Message (server/sender/client/all clients?) */ + /* public */ const LOGIN = 7; /* Login (server/sender) */ + /* public */ const LOGOUT = 8; /* Logout (server/sender) */ + /* public */ const CMD = 9; /* Other command */ + /* public */ const MODULE = 999999999; /* Module packet ??? */ } diff --git a/Socket/Server/ClientManager.php b/Socket/Server/ClientManager.php index 4b1f2a732..50d76944e 100644 --- a/Socket/Server/ClientManager.php +++ b/Socket/Server/ClientManager.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Server; diff --git a/Socket/Server/Server.php b/Socket/Server/Server.php index eacdcdd9c..61998d258 100644 --- a/Socket/Server/Server.php +++ b/Socket/Server/Server.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket\Server; @@ -23,10 +22,9 @@ use phpOMS\Socket\SocketAbstract; /** * Server class. * - * @category Framework - * @package phpOMS\Socket\Server + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Server extends SocketAbstract @@ -226,7 +224,7 @@ class Server extends SocketAbstract { $this->app->logger->debug('Connecting client...'); $this->clientManager->add($client = new ClientConnection(uniqid(), $socket)); - $this->conn[$client->getId()] = $socket; + $this->conn[$client->getId()] = $socket; $this->app->logger->debug('Connected client.'); } diff --git a/Socket/SocketAbstract.php b/Socket/SocketAbstract.php index 973b495a7..5a2601842 100644 --- a/Socket/SocketAbstract.php +++ b/Socket/SocketAbstract.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket; /** * Socket class. * - * @category Socket - * @package Framework + * @package Socket * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SocketAbstract implements SocketInterface diff --git a/Socket/SocketInterface.php b/Socket/SocketInterface.php index 1640a5329..1f8804285 100644 --- a/Socket/SocketInterface.php +++ b/Socket/SocketInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket; /** * Socket class. * - * @category Socket - * @package Framework + * @package Socket * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface SocketInterface diff --git a/Socket/SocketType.php b/Socket/SocketType.php index 94008f57d..dd6239b55 100644 --- a/Socket/SocketType.php +++ b/Socket/SocketType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Socket; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Socket type enum. * - * @category Framework - * @package phpOMS\Socket + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SocketType extends Enum diff --git a/Stdlib/Base/Address.php b/Stdlib/Base/Address.php index 58192c2d4..284416088 100644 --- a/Stdlib/Base/Address.php +++ b/Stdlib/Base/Address.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; /** * Address class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Address implements \JsonSerializable diff --git a/Stdlib/Base/AddressType.php b/Stdlib/Base/AddressType.php index f33b460ba..709ae90a0 100644 --- a/Stdlib/Base/AddressType.php +++ b/Stdlib/Base/AddressType.php @@ -4,33 +4,31 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; /** * Address type enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AddressType extends Enum { - /* public */ const HOME = 1; + /* public */ const HOME = 1; /* public */ const BUSINESS = 2; /* public */ const SHIPPING = 3; - /* public */ const BILLING = 4; - /* public */ const WORK = 5; + /* public */ const BILLING = 4; + /* public */ const WORK = 5; /* public */ const CONTRACT = 6; - /* public */ const OTHER = 7; + /* public */ const OTHER = 7; } diff --git a/Stdlib/Base/Enum.php b/Stdlib/Base/Enum.php index abaaed0d1..64146c552 100644 --- a/Stdlib/Base/Enum.php +++ b/Stdlib/Base/Enum.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; @@ -20,10 +19,9 @@ namespace phpOMS\Stdlib\Base; * * Replacing the SplEnum class and providing basic enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class Enum @@ -140,4 +138,20 @@ abstract class Enum return count(self::getConstants()); } + /** + * Check if flag is set + * + * This only works for binary flags. + * + * @param int $flags Set flags + * @param int $checkForFlag Check if this flag is part of the set flags + * + * @return bool + * + * @since 1.0.0 + */ + public static function hasFlag(int $flags, int $checkForFlag) : bool + { + return ($flags & $checkForFlag) === $checkForFlag; + } } diff --git a/Stdlib/Base/EnumArray.php b/Stdlib/Base/EnumArray.php index 76637b2c9..c04a45bce 100644 --- a/Stdlib/Base/EnumArray.php +++ b/Stdlib/Base/EnumArray.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; @@ -20,10 +19,9 @@ namespace phpOMS\Stdlib\Base; * * Replacing the SplEnum class and providing basic enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class EnumArray @@ -99,5 +97,4 @@ abstract class EnumArray return $constants[$key]; } - } diff --git a/Stdlib/Base/ExactFloat.php b/Stdlib/Base/ExactFloat.php index 07f1cfc0e..b523e49f0 100644 --- a/Stdlib/Base/ExactFloat.php +++ b/Stdlib/Base/ExactFloat.php @@ -4,114 +4,28 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; class ExactFloat { - - private static $length = 0; - - public static function setLength($length) /* : void */ - { - self::$length = (int) $length; - } - public static function sum($a, $b, $length = null) { - $length = $length ?? self::$length; - $split_a = explode('.', $a) + ['0', '0']; - $split_b = explode('.', $b) + ['0', '0']; + } - $sign_a = '+'; - $sign_b = '+'; - $sign_sum = ''; + public static function add($a, $b, $length = null) + { + } - $decimals = [0, 0]; - $decimals[0] = (int) $split_a[0] + (int) $split_b[0]; - - /* Get sign and length */ - $len_a = strlen($split_a[1]); - - if ($a[0] === '-') { - $sign_a = '-'; - } - - $len_b = strlen($split_b[1]); - - if ($b[0] === '-') { - $sign_b = '-'; - } - - /* Pad to same length */ - $len_max = max($len_a, $len_b); - - $val_a = (int) ($sign_a . str_pad($split_a[1], $len_max, '0')); - $val_b = (int) ($sign_b . str_pad($split_b[1], $len_max, '0')); - - $temp_sum = $val_a + $val_b; - - if ($sign_a === '+' && $sign_b === '+') { - if (strlen((string) $temp_sum) > $len_max) { - $decimals[0]++; - $decimals[1] = (int) substr((string) $temp_sum, 1); - } - } elseif ($sign_a === '+' && $sign_b === '-') { - // todo: keep 0.5 in mind maybe decimals0--?!?!?! most likely not - if ((int) $split_a[0] > (int) $split_b[0]) { - if ($val_a < $val_b) { - $temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum; - } - } else { - if ($val_a > $val_b) { - $temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum; - } - } - - $decimals[1] = (int) ltrim((string) $temp_sum, '-'); - } elseif ($sign_a === '-' && $sign_b === '+') { - if ((int) $split_a[0] < (int) $split_b[0]) { - if ($val_a > $val_b) { - $temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum; - } - } else { - if ($val_a < $val_b) { - $temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum; - } - } - - $decimals[1] = (int) ltrim((string) $temp_sum, '-'); - } elseif ($sign_a === '-' && $sign_b === '-') { - if (strlen((string) $temp_sum) > $len_max + 1) { - $decimals[0]--; - $decimals[1] = (int) substr((string) $temp_sum, 2); - } - - if ($decimals[0] === 0) { - $sign_sum = '-'; - } - } - - /* Too short */ - $str_sum = str_pad((string) $decimals[1], $length, '0'); - - /* Too long */ - /* TODO: handle rounding, carefull with e.g. 1.99995 -> 2.00 */ - if ($sign_sum === '-') { - $str_sum = substr($str_sum, 0, $length + 1); - } else { - $str_sum = substr($str_sum, 0, $length); - } - - return $sign_sum . $decimals[0] . ($length > 0 ? '.' . $str_sum : ''); + public static function sub($a, $b, $length = null) + { } public static function mult($a, $b, $length = null) diff --git a/Stdlib/Base/Exception/InvalidEnumName.php b/Stdlib/Base/Exception/InvalidEnumName.php index a15dfa205..d676a69fe 100644 --- a/Stdlib/Base/Exception/InvalidEnumName.php +++ b/Stdlib/Base/Exception/InvalidEnumName.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base\Exception; @@ -20,10 +19,9 @@ namespace phpOMS\Stdlib\Base\Exception; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidEnumName extends \UnexpectedValueException @@ -34,7 +32,7 @@ class InvalidEnumName extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ @@ -42,5 +40,4 @@ class InvalidEnumName extends \UnexpectedValueException { parent::__construct('The enum name "' . $message . '" is not valid.', $code, $previous); } - } diff --git a/Stdlib/Base/Exception/InvalidEnumValue.php b/Stdlib/Base/Exception/InvalidEnumValue.php index fb2a8ef2f..1f7a9b385 100644 --- a/Stdlib/Base/Exception/InvalidEnumValue.php +++ b/Stdlib/Base/Exception/InvalidEnumValue.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base\Exception; @@ -20,10 +19,9 @@ namespace phpOMS\Stdlib\Base\Exception; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidEnumValue extends \UnexpectedValueException @@ -32,15 +30,14 @@ class InvalidEnumValue extends \UnexpectedValueException /** * Constructor. * - * @param string $message Exception message + * @param mixed $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ - public function __construct(string $message, int $code = 0, \Exception $previous = null) + public function __construct($message, int $code = 0, \Exception $previous = null) { parent::__construct('The enum value "' . $message . '" is not valid.', $code, $previous); } - } diff --git a/Stdlib/Base/Iban.php b/Stdlib/Base/Iban.php index 917cece85..21744ccc4 100644 --- a/Stdlib/Base/Iban.php +++ b/Stdlib/Base/Iban.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; @@ -20,10 +19,9 @@ use phpOMS\Validation\Finance\IbanEnum; /** * Iban class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Iban implements \Serializable @@ -286,4 +284,4 @@ class Iban implements \Serializable { $this->parse($serialized); } -} \ No newline at end of file +} diff --git a/Stdlib/Base/Location.php b/Stdlib/Base/Location.php index c26de4f17..63348d527 100644 --- a/Stdlib/Base/Location.php +++ b/Stdlib/Base/Location.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; /** * Location class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Location implements \JsonSerializable, \Serializable diff --git a/Stdlib/Base/NullLocation.php b/Stdlib/Base/NullLocation.php index 060c35d83..8a416858f 100644 --- a/Stdlib/Base/NullLocation.php +++ b/Stdlib/Base/NullLocation.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; /** * Location class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class NullLocation extends Location diff --git a/Stdlib/Base/PhoneType.php b/Stdlib/Base/PhoneType.php index f099ce37a..5f527e84b 100644 --- a/Stdlib/Base/PhoneType.php +++ b/Stdlib/Base/PhoneType.php @@ -4,30 +4,28 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; /** * Address type enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PhoneType extends Enum { - /* public */ const HOME = 1; + /* public */ const HOME = 1; /* public */ const BUSINESS = 2; - /* public */ const MOBILE = 3; - /* public */ const WORK = 4; + /* public */ const MOBILE = 3; + /* public */ const WORK = 4; } diff --git a/Stdlib/Base/SmartDateTime.php b/Stdlib/Base/SmartDateTime.php index bcba717e2..755f0179d 100644 --- a/Stdlib/Base/SmartDateTime.php +++ b/Stdlib/Base/SmartDateTime.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Base; @@ -22,10 +21,9 @@ use phpOMS\Math\Functions\Functions; * * Providing smarter datetimes * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SmartDateTime extends \DateTime @@ -46,14 +44,6 @@ class SmartDateTime extends \DateTime */ /* public */ const TIMEZONE = 'UTC'; - /** - * {@inheritdoc} - */ - public function __construct($time = 'now', $timezone = null) - { - parent::__construct($time, $timezone); - } - /** * Create object from DateTime * @@ -102,24 +92,24 @@ class SmartDateTime extends \DateTime */ public function smartModify(int $y, int $m = 0, int $d = 0, int $calendar = CAL_GREGORIAN) : SmartDateTime { - $y_change = (int) floor(((int) $this->format('m') - 1 + $m) / 12); - $y_change = ((int) $this->format('m') - 1 + $m) < 0 && ((int) $this->format('m') - 1 + $m) % 12 === 0 ? $y_change - 1 : $y_change; - $y_new = (int) $this->format('Y') + $y + $y_change; - $m_new = ((int) $this->format('m') + $m) % 12; - $m_new = $m_new === 0 ? 12 : $m_new < 0 ? 12 + $m_new : $m_new; - $d_month_old = cal_days_in_month($calendar, (int) $this->format('m'), (int) $this->format('Y')); - $d_month_new = cal_days_in_month($calendar, $m_new, $y_new); - $d_old = (int) $this->format('d'); + $yearChange = (int) floor(((int) $this->format('m') - 1 + $m) / 12); + $yearChange = ((int) $this->format('m') - 1 + $m) < 0 && ((int) $this->format('m') - 1 + $m) % 12 === 0 ? $yearChange - 1 : $yearChange; + $yearNew = (int) $this->format('Y') + $y + $yearChange; + $monthNew = ((int) $this->format('m') + $m) % 12; + $monthNew = $monthNew === 0 ? 12 : $monthNew < 0 ? 12 + $monthNew : $monthNew; + $dayMonthOld = cal_days_in_month($calendar, (int) $this->format('m'), (int) $this->format('Y')); + $dayMonthNew = cal_days_in_month($calendar, $monthNew, $yearNew); + $dayOld = (int) $this->format('d'); - if ($d_old > $d_month_new) { - $d_new = $d_month_new; - } elseif ($d_old < $d_month_new && $d_old === $d_month_old) { - $d_new = $d_month_new; + if ($dayOld > $dayMonthNew) { + $dayNew = $dayMonthNew; + } elseif ($dayOld < $dayMonthNew && $dayOld === $dayMonthOld) { + $dayNew = $dayMonthNew; } else { - $d_new = $d_old; + $dayNew = $dayOld; } - $this->setDate($y_new, $m_new, $d_new); + $this->setDate($yearNew, $monthNew, $dayNew); if ($d !== 0) { $this->modify($d . ' day'); @@ -230,20 +220,9 @@ class SmartDateTime extends \DateTime */ public static function getDayOfWeek(int $y, int $m, int $d) : int { - $w = 1; - $y = ($y - 1) % 400 + 1; - $ly = ($y - 1) / 4; - $ly = $ly - ($y - 1) / 100; - $ly = $ly + ($y - 1) / 400; - $ry = $y - 1 - $ly; - $w = $w + $ry; - $w = $w + 2 * $ly; - $w = $w + date("z", mktime(0, 0, 0, $m, $d, $y)) + 1; - $w = ($w - 1) % 7 + 1; - - return $w === 7 ? 0 : $w; + return (int) date('w', strtotime($d . '-' . $m . '-' . $y)); } - + /** * Get day of week * @@ -268,33 +247,34 @@ class SmartDateTime extends \DateTime public function getMonthCalendar(int $weekStartsWith = 0) : array { $days = []; - + // get day of first day in month $firstDay = $this->getFirstDayOfMonth(); - + // calculate difference to $weekStartsWith $diffToWeekStart = Functions::mod($firstDay - $weekStartsWith, 7); $diffToWeekStart = $diffToWeekStart === 0 ? 7 : $diffToWeekStart; // get days of previous month - $previousMonth = $this->createModify(0, -1); + $previousMonth = $this->createModify(0, -1); $daysPreviousMonth = $previousMonth->getDaysOfMonth(); - + // add difference to $weekStartsWith counting backwards from days of previous month (reorder so that lowest value first) - for($i = $daysPreviousMonth - $diffToWeekStart; $i < $daysPreviousMonth; $i++) { - $days[] = new \DateTime($previousMonth->format('Y') . '-' . $previousMonth->format('m') . '-' . ($i+1)); + for ($i = $daysPreviousMonth - $diffToWeekStart; $i < $daysPreviousMonth; $i++) { + $days[] = new \DateTime($previousMonth->format('Y') . '-' . $previousMonth->format('m') . '-' . ($i + 1)); } - + // add normal count of current days $daysMonth = $this->getDaysOfMonth(); - for($i = 1; $i <= $daysMonth; $i++) { + for ($i = 1; $i <= $daysMonth; $i++) { $days[] = new \DateTime($this->format('Y') . '-' . $this->format('m') . '-' . ($i)); } - + // add remaining days to next month (7*6 - difference+count of current month) $remainingDays = 42 - $diffToWeekStart - $daysMonth; - $nextMonth = $this->createModify(0, 1); - for($i = 1; $i <= $remainingDays; $i++) { + $nextMonth = $this->createModify(0, 1); + + for ($i = 1; $i <= $remainingDays; $i++) { $days[] = new \DateTime($nextMonth->format('Y') . '-' . $nextMonth->format('m') . '-' . ($i)); } diff --git a/Stdlib/Collection/Collection.php b/Stdlib/Collection/Collection.php deleted file mode 100644 index d5b23ab53..000000000 --- a/Stdlib/Collection/Collection.php +++ /dev/null @@ -1,726 +0,0 @@ -collection = $data; - } - - /** - * Turn collection to array. - * - * @return array Collection array representation - * - * @since 1.0.0 - */ - public function toArray() : array - { - return $this->collection; - } - - /** - * Json serialize. - * - * @return string - * - * @since 1.0.0 - */ - public function jsonSerialize() - { - return $this->collection; - } - - /** - * Get average of collection data. - * - * @param mixed $filter Filter for average calculation - * - * @return mixed - * - * @since 1.0.0 - */ - public function avg($filter = null) - { - return $this->sum($filter) / $this->count(); - } - - /** - * Get sum of collection data. - * - * @param mixed $filter Filter for sum calculation - * - * @return mixed - * - * @since 1.0.0 - */ - public function sum($filter = null) - { - $sum = 0; - - if (!isset($filter)) { - foreach ($this->collection as $key => $value) { - if (is_numeric($value)) { - $sum += $value; - } elseif ($value instanceof Collection) { - $sum += $value->sum(); - } - } - } elseif (is_string($filter)) { - foreach ($this->collection as $key => $value) { - if (isset($value[$filter]) && is_numeric($value[$filter])) { - $sum += $value[$filter]; - } - } - } elseif ($filter instanceof \Closure) { - $sum = $filter($this->collection); - } - - return $sum; - } - - /** - * Get collection count. - * - * @return int - * - * @since 1.0.0 - */ - public function count() - { - return count($this->collection); - } - - /** - * Chunk collection. - * - * Creates new collection in the specified size. - * - * @param int $size Chunk size - * - * @return Collection[] - * - * @since 1.0.0 - */ - public function chunk(int $size) : array - { - $arrays = array_chunk($this->collection, $size); - $collections = []; - - foreach($arrays as $array) { - $collections[] = new self($array); - } - - return $collections; - } - - /** - * Collapse collection. - * - * @return Collection - * - * @since 1.0.0 - */ - public function collapse() : Collection - { - $return = []; - - return new self(array_walk_recursive($this->collection, function ($a) use (&$return) { - $return[] = $a; - })); - } - - public function combine(array $values) : Collection - { - foreach ($this->collection as $key => $value) { - if (is_int($key) && is_string($value)) { - $this->collection[$value] = current($values); - unset($this->collection[$key]); - } elseif (is_string($key) && is_string($value)) { - $this->collection[$key] = [$value, current($values)]; - } elseif (is_array($value)) { - $this->collection[$key][] = current($values); - } else { - continue; - } - - next($values); - } - - return $this; - } - - /** - * Check if collection contains a value. - * - * @param string|int|float|\Closure $find Needle - * - * @return bool - * - * @since 1.0.0 - */ - public function contains($find) : bool - { - foreach ($this->collection as $key => $value) { - if (is_string($find) && ((is_string($value) && $find === $value) || (is_array($value) && in_array($find, $value)))) { - return true; - } elseif ($find instanceof \Closure) { - $result = $find($value, $key); - - if ($result) { - return true; - } - } - } - - return false; - } - - /** - * Diff of collection. - * - * @param Collection|array $compare To compare with - * - * @return array - * - * @since 1.0.0 - */ - public function diff($compare) : array - { - $diff = []; - - foreach ($this->collection as $key => $value) { - if ($value !== current($compare)) { - $diff[] = $value; - } - - next($compare); - } - - return $diff; - } - - public function diffKeys(array $compare) - { - $diff = []; - - foreach ($this->collection as $key => $value) { - if ($key !== current($compare)) { - $diff = $key; - } - - next($compare); - } - - return $diff; - } - - /** - * Get collection that contains every n-th element. - * - * @param int $n Every n-th element - * - * @return Collection - * - * @since 1.0.0 - */ - public function every(int $n) : Collection - { - $values = array_values($this->collection); - $keys = array_keys($this->collection); - $count = count($values); - - $new = []; - for ($i = 0; $i < $count; $i += $n) { - $new[$keys[$i]] = $values[$i]; - } - - return new self($new); - } - - public function get($key) - { - if (!isset($this->collection[$key])) { - if (is_int($key) && $key < $this->count()) { - return $this->collection[array_keys($this->collection)[$key]]; - } - } else { - return $this->collection[$key]; - } - - return null; - } - - public function except($filter) : Collection - { - if (!is_array($filter)) { - $filter = [$filter]; - } - - $new = []; - for ($i = 0; $i < $this->count(); $i++) { - - if (!in_array($this->get($i), $filter)) { - $new[] = $this->get($i); - } - } - - return new self($new); - } - - public function filter($filter) : Collection - { - $new = []; - foreach ($this->collection as $key => $value) { - if ($filter($key, $value)) { - $new[$key] = $value; - } - } - - return new self($new); - } - - public function first(\Closure $filter = null) - { - foreach ($this->collection as $key => $value) { - if (!isset($filter) || $filter($key, $value)) { - return $value; - } - } - - return null; - } - - public function flatten() : Collection - { - return new self(ArrayUtils::arrayFlatten($this->collection)); - } - - public function flip() : Collection - { - return new self(array_flip($this->collection)); - } - - public function groupBy($filter) : Collection - { - $new = []; - foreach ($this->collection as $key => $value) { - if (is_string($filter)) { - $group = $filter; - } elseif ($filter instanceof \Closure) { - $group = $filter($value, $key); - } else { - throw new \Exception(); - } - - $new[$value[$group]][] = $value; - } - - return new self($new); - } - - public function last(\Closure $filter = null) - { - $collection = array_reverse($this->collection, true); - foreach ($collection as $key => $value) { - if (!isset($filter) || $filter($key, $value)) { - return $value; - } - } - - return null; - } - - public function sort() : Collection - { - return new self(arsort($this->collection)); - } - - public function sortBy($filter) : Collection - { - return new self(uasort($this->collection, $filter)); - } - - public function reverse() : Collection - { - return new self(array_reverse($this->collection)); - } - - public function map($filter) : Collection - { - $new = []; - foreach ($this->collection as $key => $value) { - $new[$key] = $filter($value, $key); - } - - return new self($new); - } - - public function remove($key) : Collection - { - if ($key instanceof \Closure) { - foreach ($this->collection as $index => $value) { - if ($key($value, $index)) { - unset($this->collection[$index]); - } - } - } elseif (is_scalar($key)) { - unset($this->collection[$key]); - } - - return $this; - } - - public function has($key) : bool - { - return isset($this->collection[$key]); - } - - public function implode(string $delim, $key) : string - { - $implode = ''; - foreach ($this->collection as $colKey => $value) { - if (!isset($key) && is_scalar($value)) { - $implode .= $value . $delim; - } elseif (isset($key)) { - $implode .= $value[$key] . $delim; - } - } - - return rtrim($implode, $delim); - } - - public function intersect(array $values) : Collection - { - $new = []; - foreach ($this->collection as $key => $value) { - if (in_array($value, $values)) { - $new[] = $value; - } - } - - return new self($new); - } - - public function isEmpty() : bool - { - return empty($this->collection); - } - - public function keys() : array - { - return array_keys($this->collection); - } - - public function max($key = null) - { - $max = null; - foreach ($this->collection as $index => $value) { - if (isset($key) && is_array($value)) { - $value = $value[$index]; - } - - if (!isset($max) || $value > $max) { - $max = $value; - } - } - - return $max; - } - - public function min($key = null) - { - $min = null; - foreach ($this->collection as $index => $value) { - if (isset($key) && is_array($value)) { - $value = $value[$index]; - } - - if (!isset($min) || $value > $min) { - $min = $value; - } - } - - return $min; - } - - public function only(array $filter) : Collection - { - $new = []; - foreach ($filter as $key => $value) { - $new[$value] = $this->collection[$value]; - } - - return new self($new); - } - - public function pluck(string $id) : Collection - { - $new = []; - foreach ($this->collection as $key => $value) { - $new[] = $value[$id]; - } - - return new self($new); - } - - public function merge(array $merge) : Collection - { - return new self(array_merge($this->collection, $merge)); - } - - public function pop() - { - return array_pop($this->collection); - } - - public function prepend(...$element) : Collection - { - $this->collection = array_merge($element, $this->collection); - - return $this; - } - - public function pull($key) - { - $value = $this->collection[$key]; - unset($this->collection[$key]); - - return $value; - } - - public function put($key, $value) : Collection - { - $this->collection[$key] = $value; - - return $this; - } - - public function random() - { - $i = mt_rand(0, $this->count() - 1); - - return $this->get($i); - } - - public function reduce($callback, $start = 0) - { - $total = $start; - foreach ($this->collection as $key => $value) { - $total = $callback($total, $value, $key); - } - - return $total; - } - - public function search($filter, bool $strict = true) /* : void */ - { - if (is_scalar($filter)) { - array_search($filter, $this->collection, $strict); - } else { - foreach ($this->collection as $key => $value) { - if ($filter($value, $key)) { - return $key; - } - } - } - - return null; - } - - public function shift() : Collection - { - return new self(array_shift($this->collection)); - } - - public function shuffle() : Collection - { - return new self(shuffle($this->collection)); - } - - public function slice(int $offset, int $length) : Collection - { - return new self(array_slice($this->collection, $offset, $length)); - } - - public function splice(int $offset, int $length) : Collection - { - return new self(array_splice($this->collection, $offset, $length)); - } - - public function push($value) : Collection - { - $this->collection[] = $value; - - return $this; - } - - /** - * 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() - { - return current($this->collection); - } - - /** - * Offset to retrieve - * - * @param mixed $offset The offset to retrieve. - * - * @return mixed Can return all value types. - * - * @throws \Exception - * - * @link http://php.net/manual/en/arrayaccess.offsetget.php - * - * @since 1.0.0 - */ - public function offsetGet($offset) - { - if(!isset($this->collection[$offset])) { - throw new \Exception('Invalid offset'); - } - - return $this->collection[$offset]; - } - - /** - * 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() - { - next($this->collection); - } - - /** - * 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() - { - return key($this->collection); - } - - /** - * 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() - { - return isset($this->collection[key($this->collection)]); - } - - /** - * Whether a offset exists - * @link http://php.net/manual/en/arrayaccess.offsetexists.php - * @param mixed $offset- * An offset to check for. - *
- * @return boolean true on success or false on failure. - * - *- * The return value will be casted to boolean if non-boolean was returned. - * @since 5.0.0 - */ - public function offsetExists($offset) - { - return isset($this->collection[$offset]); - } - - /** - * 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() - { - rewind($this->collection); - } - - /** - * Offset to set - * @link http://php.net/manual/en/arrayaccess.offsetset.php - * @param mixed $offset
- * The offset to assign the value to. - *
- * @param mixed $value- * The value to set. - *
- * @return void - * @since 5.0.0 - */ - public function offsetSet($offset, $value) - { - $this->collection[$offset] = $value; - } - - /** - * Offset to unset - * @link http://php.net/manual/en/arrayaccess.offsetunset.php - * @param mixed $offset- * The offset to unset. - *
- * @return void - * @since 5.0.0 - */ - public function offsetUnset($offset) - { - if(isset($this->collection[$offset])) { - unset($this->collection[$offset]); - } - } -} \ No newline at end of file diff --git a/Stdlib/Graph/BinaryTree.php b/Stdlib/Graph/BinaryTree.php index bd8f5f233..fbbdf1739 100644 --- a/Stdlib/Graph/BinaryTree.php +++ b/Stdlib/Graph/BinaryTree.php @@ -4,122 +4,120 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Graph; /** * Tree class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 * * @todo : there is a bug with Hungary ibans since they have two k (checksums) in their definition */ class BinaryTree extends Tree { - public static function invert($list) : BinaryTree - { - if (empty($list->getNodes())) { - return $list; - } + public static function invert($list) : BinaryTree + { + if (empty($list->getNodes())) { + return $list; + } - $left = $list->getLeft(); - $list->setLeft($list->invert($list->nodes[1])); - $list->setRight($list->invert($left)); + $left = $list->getLeft(); + $list->setLeft($list->invert($list->nodes[1])); + $list->setRight($list->invert($left)); - return $list; - } + return $list; + } - /** + /** * Get left node of a node. * * @param Node $base Tree node - * - * @return Node Left node + * + * @return Node Left node * * @since 1.0.0 */ - public function getLeft(Node $base) - { - $neighbors = $base->getNeighbors($base); + public function getLeft(Node $base) + { + $neighbors = $base->getNeighbors($base); - // todo: index can be wrong, see setLeft/setRight - return $neighbors[0] ?? null; - } + // todo: index can be wrong, see setLeft/setRight + return $neighbors[0] ?? null; + } - /** + /** * Get right node of a node. * * @param Node $base Tree node - * - * @return Node Right node + * + * @return Node Right node * * @since 1.0.0 */ - public function getRight(Node $base) - { - $neighbors = $this->getNeighbors($base); + public function getRight(Node $base) + { + $neighbors = $this->getNeighbors($base); - // todo: index can be wrong, see setLeft/setRight - return $neighbors[1] ?? null; - } + // todo: index can be wrong, see setLeft/setRight + return $neighbors[1] ?? null; + } - /** + /** * Set left node of node. * * @param Node $base Base node * @param Node $left Left node - * - * @return BinaryTree + * + * @return BinaryTree * * @since 1.0.0 */ - public function setLeft(Node $base, Node $left) : BinaryTree - { - if($this->getLeft($base) === null) { - $this->addNodeRelative($base, $left); - // todo: doesn't know that this is left - // todo: maybe need to add numerics to edges? - } else { - // todo: replace node - } + public function setLeft(Node $base, Node $left) : BinaryTree + { + if ($this->getLeft($base) === null) { + $this->addNodeRelative($base, $left); + // todo: doesn't know that this is left + // todo: maybe need to add numerics to edges? + } else { + // todo: replace node + } - return $this; - } + return $this; + } - /** + /** * Set right node of node. * * @param Node $base Base node * @param Node $right Right node - * - * @return BinaryTree + * + * @return BinaryTree * * @since 1.0.0 */ - public function setRight(Node $base, Node $right) /* : void */ - { - if($this->getRight($base) === null) { - $this->addNodeRelative($base, $right); - // todo: doesn't know that this is right - // todo: maybe need to add numerics to edges? - } else { - // todo: replace node - } - } + public function setRight(Node $base, Node $right) /* : void */ + { + if ($this->getRight($base) === null) { + $this->addNodeRelative($base, $right); + // todo: doesn't know that this is right + // todo: maybe need to add numerics to edges? + } else { + // todo: replace node + } + } - /** + /** * Perform action on tree in in-order. * * @param Node $node Tree node @@ -127,42 +125,42 @@ class BinaryTree extends Tree * * @since 1.0.0 */ - public function inOrder(Node $node, \Closure $callback) - { - $this->inOrder($this->getLeft($node), $callback); - $callback($node); - $this->inOrder($this->getRight($node), $callback); - } + public function inOrder(Node $node, \Closure $callback) + { + $this->inOrder($this->getLeft($node), $callback); + $callback($node); + $this->inOrder($this->getRight($node), $callback); + } - /** + /** * Get nodes in vertical order. * * @param Node $node Tree node * @param int $horizontalDistance Horizontal distance - * @param Node[] &$order Ordered nodes by horizontal distance + * @param Node[] &$order Ordered nodes by horizontal distance * * @since 1.0.0 */ - private function getVerticalOrder(Node $node, int $horizontalDistance = 0, array &$order) - { - if(!isset($order[$horizontalDistance])) { - $order[$horizontalDistance] = []; - } + private function getVerticalOrder(Node $node, int $horizontalDistance = 0, array &$order) + { + if (!isset($order[$horizontalDistance])) { + $order[$horizontalDistance] = []; + } - $order[$horizontalDistance][] = $node; - $left = $this->getLeft($node); - $right = $this->getRight($node); + $order[$horizontalDistance][] = $node; + $left = $this->getLeft($node); + $right = $this->getRight($node); - if(isset($left)) { - $this->getVerticalOrder($left, $horizontalDistance-1, $order); - } + if (isset($left)) { + $this->getVerticalOrder($left, $horizontalDistance - 1, $order); + } - if(isset($right)) { - $this->getVerticalOrder($right, $horizontalDistance+1, $order); - } - } + if (isset($right)) { + $this->getVerticalOrder($right, $horizontalDistance + 1, $order); + } + } - /** + /** * Perform action on tree in vertical-order. * * @param Node $node Tree node @@ -170,45 +168,45 @@ class BinaryTree extends Tree * * @since 1.0.0 */ - public function verticalOrder(Node $node, \Closure $callback) - { - $order = []; - $this->getVerticalOrder($node, 0, $order); + public function verticalOrder(Node $node, \Closure $callback) + { + $order = []; + $this->getVerticalOrder($node, 0, $order); - foreach($order as $level) { - foreach($level as $node) { - $callback($node); - } - } - } + foreach ($order as $level) { + foreach ($level as $node) { + $callback($node); + } + } + } - /** + /** * Check if tree is symmetric. * * @param Node $node1 Tree node1 * @param Node $node2 Tree node2 (optional, can be different tree) - * - * @return bool True if tree is symmetric, false if tree is not symmetric + * + * @return bool True if tree is symmetric, false if tree is not symmetric * * @since 1.0.0 */ - public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool - { - if(!isset($node1) && !isset($node2)) { - return true; - } + public function isSymmetric(Node $node1 = null, Node $node2 = null) : bool + { + if (!isset($node1) && !isset($node2)) { + return true; + } - $left1 = $this->getLeft($node1); - $right1 = $this->getRight($node1); + $left1 = $this->getLeft($node1); + $right1 = $this->getRight($node1); - $left2 = isset($node2) ? $this->getLeft($node1) : $this->getLeft($node2); - $right2 = isset($node2) ? $this->getRight($node1) : $this->getRight($node2); + $left2 = isset($node2) ? $this->getLeft($node1) : $this->getLeft($node2); + $right2 = isset($node2) ? $this->getRight($node1) : $this->getRight($node2); - // todo: compare values? true symmetry requires the values to be the same - if(isset($node1, $node2)) { - return $this->isSymmetric($left1, $right2) && $this->isSymmetric($right1, $left2); - } + // todo: compare values? true symmetry requires the values to be the same + if (isset($node1, $node2)) { + return $this->isSymmetric($left1, $right2) && $this->isSymmetric($right1, $left2); + } - return false; - } -} \ No newline at end of file + return false; + } +} diff --git a/Stdlib/Graph/Edge.php b/Stdlib/Graph/Edge.php index 3ce06ca2d..74377b8c3 100644 --- a/Stdlib/Graph/Edge.php +++ b/Stdlib/Graph/Edge.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Graph; /** * Tree class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Edge @@ -32,14 +30,14 @@ class Edge private $directed = false; - public function __construct(Node $node1, Node $node2, bool $directed = false) + public function __construct(Node $node1, Node $node2, bool $directed = false) { - $this->node1 = $node1; - $this->node2 = $node2; + $this->node1 = $node1; + $this->node2 = $node2; $this->directed = $directed; } - public function getNodes() : array + public function getNodes() : array { return [$this->node1, $this->node2]; } @@ -48,4 +46,4 @@ class Edge { return $this->directed; } -} \ No newline at end of file +} diff --git a/Stdlib/Graph/Graph.php b/Stdlib/Graph/Graph.php index 78fbddada..4746620ad 100644 --- a/Stdlib/Graph/Graph.php +++ b/Stdlib/Graph/Graph.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Graph; /** * Tree class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Graph @@ -463,4 +461,4 @@ class Graph // todo: implement return true; } -} \ No newline at end of file +} diff --git a/Stdlib/Graph/Node.php b/Stdlib/Graph/Node.php index 507b2caa3..33ef1f46b 100644 --- a/Stdlib/Graph/Node.php +++ b/Stdlib/Graph/Node.php @@ -4,28 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Graph; /** * Tree class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 * * @todo : there is a bug with Hungary ibans since they have two k (checksums) in their definition */ class Node { -} \ No newline at end of file +} diff --git a/Stdlib/Graph/Tree.php b/Stdlib/Graph/Tree.php index 7c6a439af..17d76e9fa 100644 --- a/Stdlib/Graph/Tree.php +++ b/Stdlib/Graph/Tree.php @@ -4,48 +4,46 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Graph; /** * Tree class. * - * @category Framework - * @package phpOMS\Datatypes + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Tree extends Graph { - /** + /** * Root node. * * @var Node * @since 1.0.0 */ - private $root = null; + private $root = null; - /** + /** * Constructor. * * @since 1.0.0 */ - public function __construct() - { - $root = new Node(); - parent::addNode($root); - } + public function __construct() + { + $root = new Node(); + parent::addNode($root); + } - /** + /** * Add a note relative to a node. * * @param Node $base Base node @@ -55,15 +53,15 @@ class Tree extends Graph * * @since 1.0.0 */ - public function addRelativeNode(Node $base, Node $node) : Tree - { - parent::addNode($node); - parent::addEdge(new Edge($base, $node)); + public function addRelativeNode(Node $base, Node $node) : Tree + { + parent::addNode($node); + parent::addEdge(new Edge($base, $node)); - return $this; - } + return $this; + } - /** + /** * Get maximum tree depth. * * @param Node $node Tree node @@ -72,25 +70,25 @@ class Tree extends Graph * * @since 1.0.0 */ - public function getMaxDepth(Node $node = null) : int - { - $currentNode = $node ?? $this->root; + public function getMaxDepth(Node $node = null) : int + { + $currentNode = $node ?? $this->root; - if(!isset($currentNode)) { - return 0; - } + if (!isset($currentNode)) { + return 0; + } - $depth = 1; - $neighbors = $this->getNeighbors($currentNode); + $depth = 1; + $neighbors = $this->getNeighbors($currentNode); - foreach($neighbors as $neighbor) { - $depth = max($depth, $depth + $this->getMaxDepth($neighbor)); - } + foreach ($neighbors as $neighbor) { + $depth = max($depth, $depth + $this->getMaxDepth($neighbor)); + } - return $depth; - } + return $depth; + } - /** + /** * Get minimum tree path. * * @param Node $node Tree node @@ -99,27 +97,27 @@ class Tree extends Graph * * @since 1.0.0 */ - public function getMinDepth(Node $node = null) : int - { - $currentNode = $node ?? $this->root; + public function getMinDepth(Node $node = null) : int + { + $currentNode = $node ?? $this->root; - if(!isset($currentNode)) { - return 0; - } + if (!isset($currentNode)) { + return 0; + } - $depth = []; - $neighbors = $this->getNeighbors($currentNode); + $depth = []; + $neighbors = $this->getNeighbors($currentNode); - foreach($neighbors as $neighbor) { - $depth[] = $this->getMaxDepth($neighbor); - } + foreach ($neighbors as $neighbor) { + $depth[] = $this->getMaxDepth($neighbor); + } - $depth = empty($depth) ? 0 : $depth; + $depth = empty($depth) ? 0 : $depth; - return min($depth) + 1; - } + return min($depth) + 1; + } - /** + /** * Perform task on tree nodes in level order. * * @param Node $node Tree node @@ -129,17 +127,17 @@ class Tree extends Graph * * @since 1.0.0 */ - public function levelOrder(Node $node, \Closure $callback) - { - $depth = $this->getMaxDepth(); + public function levelOrder(Node $node, \Closure $callback) + { + $depth = $this->getMaxDepth(); - for($i = 1; $i < $depth; $i++) { - $nodes = $this->getLevel($i); - callback($nodes); - } - } + for ($i = 1; $i < $depth; $i++) { + $nodes = $this->getLevel($i); + callback($nodes); + } + } - /** + /** * Check if node is leaf. * * @param Node $node Tree node @@ -148,12 +146,12 @@ class Tree extends Graph * * @since 1.0.0 */ - public function isLeaf(Node $node) : bool - { - return count($this->getEdgesOfNode($node)) === 1; - } + public function isLeaf(Node $node) : bool + { + return count($this->getEdgesOfNode($node)) === 1; + } - /** + /** * Get all nodes of a specific level. * * @param int $level Level to retrieve @@ -163,24 +161,24 @@ class Tree extends Graph * * @since 1.0.0 */ - public function getLevelNodes(int $level, Node $node) : array - { - --$level; - $neighbors = $this->getNeighbors($node); - $nodes = []; + public function getLevelNodes(int $level, Node $node) : array + { + --$level; + $neighbors = $this->getNeighbors($node); + $nodes = []; - if($level === 1) { - return $neighbors; - } + if ($level === 1) { + return $neighbors; + } - foreach($neighbors as $neighbor) { - array_merge($nodes, $this->getLevelNodes($level, $neighbor)); - } + foreach ($neighbors as $neighbor) { + array_merge($nodes, $this->getLevelNodes($level, $neighbor)); + } - return $nodes; - } + return $nodes; + } - /** + /** * Check if the tree is full. * * @param int $type Child nodes per non-leaf node @@ -189,24 +187,24 @@ class Tree extends Graph * * @since 1.0.0 */ - public function isFull(int $type) : bool - { - if(count($this->edges) % $type !== 0) { - return false; - } + public function isFull(int $type) : bool + { + if (count($this->edges) % $type !== 0) { + return false; + } - foreach($this->nodes as $node) { - $neighbors = count($this->getNeighbors($node)); + foreach ($this->nodes as $node) { + $neighbors = count($this->getNeighbors($node)); - if($neighbors !== $type && $neighbors !== 0) { - return false; - } - } + if ($neighbors !== $type && $neighbors !== 0) { + return false; + } + } - return true; - } + return true; + } - /** + /** * Perform action on tree in pre-order. * * @param Node $node Tree node @@ -214,21 +212,22 @@ class Tree extends Graph * * @since 1.0.0 */ - public function preOrder(Node $node, \Closure $callback) { - if(count($this->nodes) === 0) { - return; - } + public function preOrder(Node $node, \Closure $callback) + { + if (count($this->nodes) === 0) { + return; + } - $callback($node); - $neighbors = $this->getNeighbors($node); + $callback($node); + $neighbors = $this->getNeighbors($node); - foreach($neighbors as $neighbor) { - // todo: get neighbors needs to return in ordered way - $this->preOrder($neighbor, $callback); - } - } - - /** + foreach ($neighbors as $neighbor) { + // todo: get neighbors needs to return in ordered way + $this->preOrder($neighbor, $callback); + } + } + + /** * Perform action on tree in post-order. * * @param Node $node Tree node @@ -236,18 +235,19 @@ class Tree extends Graph * * @since 1.0.0 */ - public function postOrder(Node $node, \Closure $callback) { - if(count($this->nodes) === 0) { - return; - } - - $neighbors = $this->getNeighbors($node); + public function postOrder(Node $node, \Closure $callback) + { + if (count($this->nodes) === 0) { + return; + } - foreach($neighbors as $neighbor) { - // todo: get neighbors needs to return in ordered way - $this->postOrder($neighbor, $callback); - } + $neighbors = $this->getNeighbors($node); - $callback($node); - } -} \ No newline at end of file + foreach ($neighbors as $neighbor) { + // todo: get neighbors needs to return in ordered way + $this->postOrder($neighbor, $callback); + } + + $callback($node); + } +} diff --git a/Stdlib/Map/KeyType.php b/Stdlib/Map/KeyType.php index 13f304d68..246888cf4 100644 --- a/Stdlib/Map/KeyType.php +++ b/Stdlib/Map/KeyType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Map; @@ -20,14 +19,13 @@ use phpOMS\Stdlib\Base\Enum; /** * Account type enum. * - * @category Framework - * @package phpOMS\Stdlib + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class KeyType extends Enum { - /* public */ const SINGLE = 0; + /* public */ const SINGLE = 0; /* public */ const MULTIPLE = 1; } diff --git a/Stdlib/Map/MultiMap.php b/Stdlib/Map/MultiMap.php index 8874296f1..5477d02dc 100644 --- a/Stdlib/Map/MultiMap.php +++ b/Stdlib/Map/MultiMap.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Map; @@ -20,10 +19,9 @@ use phpOMS\Utils\Permutation; /** * Multimap utils. * - * @category Framework - * @package phpOMS\Stdlib + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class MultiMap implements \Countable @@ -92,7 +90,7 @@ class MultiMap implements \Countable $inserted = false; if ($this->keyType !== KeyType::SINGLE) { - $keys = [implode($keys, ':')]; + $keys = [implode(':', $keys)]; } foreach ($keys as $key) { @@ -186,14 +184,14 @@ class MultiMap implements \Countable $keys = Permutation::permut($key); foreach ($keys as $key => $value) { - $key = implode($value, ':'); + $key = implode(':', $value); if (isset($this->keys[$key])) { return $this->values[$this->keys[$key]]; } } } else { - $key = implode($key, ':'); + $key = implode(':', $key); } } @@ -235,12 +233,12 @@ class MultiMap implements \Countable $permutation = Permutation::permut($key); foreach ($permutation as $permut) { - if ($this->set(implode($permut, ':'), $value)) { + if ($this->set(implode(':', $permut), $value)) { return true; } } } else { - return $this->set(implode($key, ':'), $value); + return $this->set(implode(':', $key), $value); } return false; @@ -280,9 +278,9 @@ class MultiMap implements \Countable { if ($this->keyType === KeyType::MULTIPLE && is_array($key)) { return $this->removeMultiple($key); - } else { - return $this->removeSingle($key); } + + return $this->removeSingle($key); } /** @@ -296,19 +294,22 @@ class MultiMap implements \Countable */ private function removeMultiple($key) : bool { - if ($this->orderType === OrderType::LOOSE) { - $keys = Permutation::permut($key); - - $removed = false; - - foreach ($keys as $key => $value) { - $removed |= $this->remove(implode($value, ':')); - } - - return $removed; - } else { - return $this->remove(implode($key, ':')); + if ($this->orderType !== OrderType::LOOSE) { + return $this->remove(implode(':', $key)); } + + $keys = Permutation::permut($key); + $found = true; + + foreach ($keys as $key => $value) { + $allFound = $this->remove(implode(':', $value)); + + if (!$allFound) { + $found = false; + } + } + + return $found; } /** @@ -403,12 +404,12 @@ class MultiMap implements \Countable $removed = false; foreach ($keys as $key => $value) { - $removed |= $this->removeKey(implode($value, ':')); + $removed |= $this->removeKey(implode(':', $value)); } return $removed; } else { - return $this->removeKey(implode($key, ':')); + return $this->removeKey(implode(':', $key)); } } diff --git a/Stdlib/Map/OrderType.php b/Stdlib/Map/OrderType.php index 1dd55d46f..e50cb596a 100644 --- a/Stdlib/Map/OrderType.php +++ b/Stdlib/Map/OrderType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Map; @@ -20,14 +19,13 @@ use phpOMS\Stdlib\Base\Enum; /** * Account type enum. * - * @category Framework - * @package phpOMS\Stdlib + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class OrderType extends Enum { - /* public */ const LOOSE = 0; + /* public */ const LOOSE = 0; /* public */ const STRICT = 1; } diff --git a/Stdlib/Queue/PriorityMode.php b/Stdlib/Queue/PriorityMode.php index 977190f08..5ca9fac6d 100644 --- a/Stdlib/Queue/PriorityMode.php +++ b/Stdlib/Queue/PriorityMode.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Queue; @@ -20,18 +19,17 @@ use phpOMS\Stdlib\Base\Enum; /** * Account type enum. * - * @category Framework - * @package phpOMS\Stdlib + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PriorityMode extends Enum { - /* public */ const FIFO = 1; - /* public */ const LIFO = 2; + /* public */ const FIFO = 1; + /* public */ const LIFO = 2; /* public */ const EARLIEST_DEADLINE = 4; - /* public */ const SHORTEST_JOB = 8; - /* public */ const HIGHEST = 16; - /* public */ const LOWEST = 32; + /* public */ const SHORTEST_JOB = 8; + /* public */ const HIGHEST = 16; + /* public */ const LOWEST = 32; } diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index c2e91e9f3..bf0d94c30 100644 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Stdlib\Queue; /** * Priority queue class. * - * @category Framework - * @package phpOMS\Stdlib + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PriorityQueue implements \Countable, \Serializable @@ -192,11 +190,9 @@ class PriorityQueue implements \Countable, \Serializable * * @param string $data Data to unserialze * - * @return array - * * @since 1.0.0 */ - public function unserialize($data) : array + public function unserialize($data) { $this->queue = json_decode($data); $this->count = count($this->queue); diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index 403f4e1c0..bfb62064c 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -20,10 +19,9 @@ namespace phpOMS\System\File; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ContainerInterface @@ -33,7 +31,7 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return \DateTime + * @return \DateTime * * @since 1.0.0 */ @@ -44,7 +42,7 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return \DateTime + * @return \DateTime * * @since 1.0.0 */ @@ -55,7 +53,7 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return int + * @return int * * @since 1.0.0 */ @@ -66,7 +64,7 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return string Permissions (e.g. 0644); + * @return int Permissions (e.g. 0755); * * @since 1.0.0 */ @@ -79,7 +77,7 @@ interface ContainerInterface * * @param string $path Path of the resource * - * @return string + * @return string * * @since 1.0.0 */ @@ -193,7 +191,7 @@ interface ContainerInterface /** * Get amount of sub-resources. * - * A file will always return 1 as it doesn't have any sub-resources. + * A file will always return 1 as it doesn't have any sub-resources. * * @param bool $recursive Should count also sub-sub-resources * @@ -237,7 +235,7 @@ interface ContainerInterface * * The parent resource path is always a directory. * - * @return ContainerInterface + * @return ContainerInterface * * @since 1.0.0 */ @@ -288,7 +286,7 @@ interface ContainerInterface /** * Get the datetime when the resource got created. * - * @return \DateTime + * @return \DateTime * * @since 1.0.0 */ @@ -297,7 +295,7 @@ interface ContainerInterface /** * Get the datetime when the resource got last modified. * - * @return \DateTime + * @return \DateTime * * @since 1.0.0 */ @@ -306,7 +304,7 @@ interface ContainerInterface /** * Get the owner id of the resource. * - * @return int + * @return int * * @since 1.0.0 */ @@ -315,11 +313,11 @@ interface ContainerInterface /** * Get the permissions id of the resource. * - * @return string Permissions (e.g. 0644); + * @return int Permissions (e.g. 0755); * * @since 1.0.0 */ - public function getPermission() : string; + public function getPermission() : int; /** * (Re-)Initialize resource diff --git a/System/File/ContentPutMode.php b/System/File/ContentPutMode.php index a7af7c67a..21adfb3cc 100644 --- a/System/File/ContentPutMode.php +++ b/System/File/ContentPutMode.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -22,16 +21,15 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ContentPutMode extends Enum { - /* public */ const APPEND = 1; - /* public */ const PREPEND = 2; - /* public */ const REPLACE = 4; - /* public */ const CREATE = 8; -} \ No newline at end of file + /* public */ const APPEND = 1; + /* public */ const PREPEND = 2; + /* public */ const REPLACE = 4; + /* public */ const CREATE = 8; +} diff --git a/System/File/DirectoryInterface.php b/System/File/DirectoryInterface.php index bf6b52978..4e9f6c4f3 100644 --- a/System/File/DirectoryInterface.php +++ b/System/File/DirectoryInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -20,10 +19,9 @@ namespace phpOMS\System\File; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface DirectoryInterface extends ContainerInterface, \Iterator, \ArrayAccess diff --git a/System/File/ExtensionType.php b/System/File/ExtensionType.php index 7d034ee66..36dac82b8 100644 --- a/System/File/ExtensionType.php +++ b/System/File/ExtensionType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ExtensionType extends Enum @@ -40,4 +38,4 @@ abstract class ExtensionType extends Enum /* public */ const ARCHIVE = 128; /* public */ const PRESENTATION = 256; /* public */ const IMAGE = 512; -} \ No newline at end of file +} diff --git a/System/File/FileInterface.php b/System/File/FileInterface.php index 3788fa189..139201c0a 100644 --- a/System/File/FileInterface.php +++ b/System/File/FileInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -20,23 +19,22 @@ namespace phpOMS\System\File; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface FileInterface extends ContainerInterface { - /** + /** * Save content to file. * * @param string $path File path to save the content to * @param string $content Content to save in file * @param int $mode Mode (overwrite, append) * - * @return bool + * @return bool * * @since 1.0.0 */ @@ -106,13 +104,13 @@ interface FileInterface extends ContainerInterface */ public static function extension(string $path) : string; - /** + /** * Save content to file. * * @param string $content Content to save in file * @param int $mode Mode (overwrite, append) * - * @return bool + * @return bool * * @since 1.0.0 */ diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index d1bd645b9..07116bd34 100644 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; /** * Path exception class. * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class FileUtils @@ -42,7 +40,7 @@ class FileUtils * @since 1.0.0 * @codeCoverageIgnore */ - private function __construct() + private function __construct() { } @@ -60,23 +58,23 @@ class FileUtils { $extension = strtolower($extension); - if(in_array($extension, self::CODE_EXTENSION)) { + if (in_array($extension, self::CODE_EXTENSION)) { return ExtensionType::CODE; - } elseif(in_array($extension, self::TEXT_EXTENSION)) { + } elseif (in_array($extension, self::TEXT_EXTENSION)) { return ExtensionType::TEXT; - } elseif(in_array($extension, self::PRESENTATION_EXTENSION)) { + } elseif (in_array($extension, self::PRESENTATION_EXTENSION)) { return ExtensionType::PRESENTATION; - } elseif(in_array($extension, self::PDF_EXTENSION)) { + } elseif (in_array($extension, self::PDF_EXTENSION)) { return ExtensionType::PDF; - } elseif(in_array($extension, self::ARCHIVE_EXTENSION)) { + } elseif (in_array($extension, self::ARCHIVE_EXTENSION)) { return ExtensionType::ARCHIVE; - } elseif(in_array($extension, self::AUDIO_EXTENSION)) { + } elseif (in_array($extension, self::AUDIO_EXTENSION)) { return ExtensionType::AUDIO; - } elseif(in_array($extension, self::VIDEO_EXTENSION)) { + } elseif (in_array($extension, self::VIDEO_EXTENSION)) { return ExtensionType::VIDEO; - } elseif(in_array($extension, self::IMAGE_EXTENSION)) { + } elseif (in_array($extension, self::IMAGE_EXTENSION)) { return ExtensionType::IMAGE; - } elseif(in_array($extension, self::SPREADSHEET_EXTENSION)) { + } elseif (in_array($extension, self::SPREADSHEET_EXTENSION)) { return ExtensionType::SPREADSHEET; } @@ -94,17 +92,17 @@ class FileUtils */ public static function absolute(string $origPath) : string { - if(!file_exists($origPath)) { + if (!file_exists($origPath)) { $startsWithSlash = strpos($origPath, '/') === 0 ? '/' : ''; - $path = []; + $path = []; $parts = explode('/', $origPath); - foreach($parts as $part) { + foreach ($parts as $part) { if (empty($part) || $part === '.') { continue; } - + if ($part !== '..') { $path[] = $part; } elseif (!empty($path)) { @@ -113,10 +111,10 @@ class FileUtils throw new PathException($origPath); } } - + return $startsWithSlash . implode('/', $path); } return realpath($origPath); } -} \ No newline at end of file +} diff --git a/System/File/Ftp/Directory.php b/System/File/Ftp/Directory.php index 1bb4e144b..4ba9e45cb 100644 --- a/System/File/Ftp/Directory.php +++ b/System/File/Ftp/Directory.php @@ -4,37 +4,75 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Ftp; use phpOMS\System\File\ContainerInterface; use phpOMS\System\File\DirectoryInterface; -use phpOMS\System\File\PathException; -use phpOMS\Utils\StringUtils; use phpOMS\System\File\Local\FileAbstract; use phpOMS\System\File\Local\Directory as DirectoryLocal; +use phpOMS\System\File\Local\File as LocalFile; +use phpOMS\Uri\Http; /** * Filesystem class. * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class Directory extends FileAbstract implements DirectoryInterface { + public static function ftpConnect(Http $http) + { + $con = ftp_connect($http->getBase() . $http->getPath(), $http->getPort()); + + ftp_login($con, $http->getUser(), $http->getPass()); + ftp_chdir($con, $http->getPath()); // todo: is this required ? + + return $con; + } + + public static function ftpExists($con, string $path) + { + $list = ftp_nlist($con, LocalFile::parent($path)); + + return in_array(LocalFile::name($path), $list); + } + + public static function ftpCreate($con, string $path, int $permission, bool $recursive) + { + $parts = explode('/', $path); + ftp_chdir($con, '/' . $parts[0]); + + foreach ($parts as $part) { + if (self::ftpExists($con, $part)) { + ftp_mkdir($con, $part); + ftp_chdir($con, $part); + ftp_chmod($con, $permission, $part); + } + } + } + + /** + * Directory nodes (files and directories). + * + * @var FileAbstract[] + * @since 1.0.0 + */ + private $nodes = []; + /** * {@inheritdoc} */ @@ -135,7 +173,7 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public static function create(string $path, string $permission = '0644', bool $recursive = false) : bool + public static function create(string $path, int $permission = 0755, bool $recursive = false) : bool { } @@ -176,8 +214,8 @@ class Directory extends FileAbstract implements DirectoryInterface public function addNode($file) : bool { - $this->count += $file->getCount(); - $this->size += $file->getSize(); + $this->count += $file->getCount(); + $this->size += $file->getSize(); $this->nodes[$file->getName()] = $file; return $file->createNode(); @@ -300,4 +338,4 @@ class Directory extends FileAbstract implements DirectoryInterface { // TODO: Implement offsetGet() method. } -} \ No newline at end of file +} diff --git a/System/File/Ftp/File.php b/System/File/Ftp/File.php index 94378dbce..259f265fe 100644 --- a/System/File/Ftp/File.php +++ b/System/File/Ftp/File.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Ftp; @@ -19,76 +18,124 @@ use phpOMS\System\File\ContainerInterface; use phpOMS\System\File\ContentPutMode; use phpOMS\System\File\FileInterface; use phpOMS\System\File\PathException; -use phpOMS\System\File\Local\File as FileLocal; use phpOMS\System\File\Local\FileAbstract; -use phpOMS\System\File\Local\Directory as DirectoryLocal; +use phpOMS\System\File\Local\Directory as LocalDirectory; +use phpOMS\System\File\Local\File as LocalFile; +use phpOMS\Uri\Http; /** * Filesystem class. * - * Performing operations on the file system + * Performing operations on the file system. * - * @category Framework - * @package phpOMS\System\File + * All static implementations require a path/uri in the following form: ftp://user:pass@domain.com/path/subpath... + * + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class File extends FileAbstract implements FileInterface { /** - * {@inheritdoc} + * Ftp connection + * + * @var resource + * @since 1.0.0 */ - public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool + private $con = null; + + /** + * Ftp connection uri. + * + * @var Http + * @since 1.0.0 + */ + private $uri = null; + + public function __construct(string $path) { - // todo: create all else cases, right now all getting handled the same way which is wrong - $current = ftp_pwd($con); - if(!ftp_chdir($con, File::dirpath($path))) { - return false; - } + $this->uri = new Http($path); + $this->con = self::ftpConnect($this->uri); + } - $exists = self::exists($path); - $result = false; + public static function ftpConnect(Http $http) + { + $con = ftp_connect($http->getBase() . $http->getPath(), $http->getPort()); - if ( - (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) - || (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) - || (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists) - || (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE) - ) { - if (!Directory::exists(dirname($path))) { - Directory::create(dirname($path), 0644, true); - } + ftp_login($con, $http->getUser(), $http->getPass()); + ftp_chdir($con, $http->getPath()); // todo: is this required ? - $stream = fopen('data://temp,' . $content, 'r'); - ftp_fput($path, $content); - fclose($stream); + return $con; + } - $result = true; - } + public static function ftpExists($con, string $path) + { + $list = ftp_nlist($con, LocalFile::dirpath($path)); - ftp_chdir($current); - - return $result; + return in_array(LocalFile::basename($path), $list); } /** * {@inheritdoc} */ - public static function get(string $path) : /* ? */string + public static function put(string $path, string $content, int $mode = ContentPutMode::REPLACE | ContentPutMode::CREATE) : bool { - $temp = fopen('php://temp', 'r+'); + $http = new Http($path); + $con = self::ftpConnect($http); - $current = ftp_pwd($con); - if(ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) { + if (ftp_pwd($con) !== $http->getPath()) { + return false; + } + + $exists = self::ftpExists($con, $http->getPath()); + + if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) + || (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) + || (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists) + || (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE)) + ) { + if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) { + file_put_contents($path, file_get_contents($path) . $content, 0, stream_context_create(['ftp' => ['overwrite' => true]])); + } elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) { + file_put_contents($path, $content . file_get_contents($path), 0, stream_context_create(['ftp' => ['overwrite' => true]])); + } else { + if (!Directory::ftpExists($con, dirname($path))) { + Directory::ftpCreate($con, dirname($path), 0755, true); + } + + file_put_contents($path, $content, 0, stream_context_create(['ftp' => ['overwrite' => true]])); + } + + ftp_close($con); + + return true; + } + + ftp_close($con); + + return false; + } + + /** + * {@inheritdoc} + */ + public static function get(string $path) : string + { + $temp = fopen('php://temp', 'r+'); + $http = new Http($path); + $content = ''; + $con = self::ftpConnect($http); + + if (ftp_chdir($con, File::dirpath($path)) && ftp_fget($con, $temp, $path, FTP_BINARY, 0)) { rewind($temp); $content = stream_get_contents($temp); } fclose($temp); - ftp_chdir($current); - return $content ?? null; + return $content; } /** @@ -120,18 +167,13 @@ class File extends FileAbstract implements FileInterface */ public static function exists(string $path) : bool { - - if(($current = ftp_pwd($con)) !== LocalFile::dirpath($path)) { - if(!ftp_chdir($con, $path)) { - return false; - } - } + $http = new Http($path); + $con = self::ftpConnect($http); + $exists = self::ftpExists($con, $http->getPath()); - $list = ftp_nlist($con, $path); + fclose($con); - ftp_chdir($con, $current); - - return in_array($path, $list); + return $exists; } /** @@ -163,9 +205,14 @@ class File extends FileAbstract implements FileInterface */ public static function changed(string $path) : \DateTime { + $http = new Http($path); + $con = self::ftpConnect($http); $changed = new \DateTime(); - $changed->setTimestamp(ftp_mdtm($con, $path)); - + + $changed->setTimestamp(ftp_mdtm($con, $http->getPath())); + + fclose($con); + return $changed; } @@ -174,11 +221,18 @@ class File extends FileAbstract implements FileInterface */ public static function size(string $path, bool $recursive = true) : int { - if (!self::exists($path)) { + $http = new Http($path); + $con = self::ftpConnect($http); + + if (!self::exists($http->getPath())) { throw new PathException($path); } - return ftp_size($con, $path); + $size = ftp_size($con, $http->getPath()); + + fclose($con); + + return $size; } /** @@ -186,7 +240,13 @@ class File extends FileAbstract implements FileInterface */ public static function owner(string $path) : int { - return self::parseFtpFileData($path)['user'] ?? ''; + $http = new Http($path); + $con = self::ftpConnect($http); + $owner = self::parseFtpFileData($con, $path)['user'] ?? ''; + + fclose($con); + + return (int) $owner; } /** @@ -194,58 +254,64 @@ class File extends FileAbstract implements FileInterface */ public static function permission(string $path) : int { - return (int) self::parseFtpFileData($path)['permission'] ?? 0; + $http = new Http($path); + $con = self::ftpConnect($http); + $permission = (int) self::parseFtpFileData($con, $path)['permission'] ?? 0; + + fclose($con); + + return $permission; } - private static function parseFtpFileData(string $path) : array + private static function parseFtpFileData($con, string $path) : array { - $items = []; + $items = []; - if (is_array($files = ftp_rawlist($con, self::dirpath($path)))) { - foreach ($files as $fileData) { - if(strpos($fileData, self::name($path)) !== false) { - $chunks = preg_split("/\s+/", $fileData); + if (is_array($files = ftp_rawlist($con, LocalFile::dirpath($path)))) { + foreach ($files as $fileData) { + if (strpos($fileData, self::name($path)) !== false) { + $chunks = preg_split("/\s+/", $fileData); - $items['permission'] = $chungs[0]; - $items['user'] = $chungs[2]; - $items['group'] = $chungs[3]; - $items['size'] = $chungs[4]; - $items['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file'; + $items['permission'] = $chunks[0]; + $items['user'] = $chunks[2]; + $items['group'] = $chunks[3]; + $items['size'] = $chunks[4]; + $items['type'] = $chunks[0][0] === 'd' ? 'directory' : 'file'; break; } - } - } + } + } - return $items; + return $items; } /** * Gets the directory name of a file. - * + * * @param string $path Path of the file to get the directory name for. - * + * * @return string Returns the directory name of the file. * * @since 1.0.0 */ public static function dirname(string $path) : string { - return FileLocal::dirname($path); + return LocalFile::dirname($path); } /** * Gets the directory path of a file. - * + * * @param string $path Path of the file to get the directory name for. - * + * * @return string Returns the directory name of the file. * * @since 1.0.0 */ public static function dirpath(string $path) : string { - return FileLocal::dirpath($path); + return LocalFile::dirpath($path); } /** @@ -253,9 +319,11 @@ class File extends FileAbstract implements FileInterface */ public static function copy(string $from, string $to, bool $overwrite = false) : bool { - if(($src = self::get($from)) === false) { + // todo: handle different ftp connections AND local to ftp + + if (($src = self::get($from)) === false) { return false; - } + } return self::put($to, $src, $overwrite ? ContentPutMode::REPLACE : ContentPutMode::CREATE); } @@ -265,18 +333,27 @@ class File extends FileAbstract implements FileInterface */ public static function move(string $from, string $to, bool $overwrite = false) : bool { - if (!self::exists($from)) { + // todo: handle different ftp connections AND local to ftp + $http = new Http($to); + $con = self::ftpConnect($http); + + if (!self::ftpExists($con, $from)) { throw new PathException($from); } if ($overwrite || !self::exists($to)) { if (!Directory::exists(dirname($to))) { - Directory::create(dirname($to), 0644, true); + Directory::create(dirname($to), 0755, true); } - return ftp_rename($con, $from, $to); + $rename = ftp_rename($con, $from, $to); + fclose($con); + + return $rename; } + fclose($con); + return false; } @@ -285,11 +362,15 @@ class File extends FileAbstract implements FileInterface */ public static function delete(string $path) : bool { - if (!self::exists($path)) { + $http = new Http($path); + $con = self::ftpConnect($http); + + if (!self::ftpExists($con, $path)) { return false; } ftp_delete($con, $path); + fclose($con); return true; } @@ -307,7 +388,7 @@ class File extends FileAbstract implements FileInterface */ public static function name(string $path) : string { - return FileLocal::name($path); + return LocalFile::name($path); } /** @@ -315,7 +396,7 @@ class File extends FileAbstract implements FileInterface */ public static function basename(string $path) : string { - return FileLocal::basename($path); + return LocalFile::basename($path); } /** @@ -323,7 +404,7 @@ class File extends FileAbstract implements FileInterface */ public static function extension(string $path) : string { - return FileLocal::extension($path); + return LocalFile::extension($path); } /** @@ -337,7 +418,7 @@ class File extends FileAbstract implements FileInterface */ public function getParent() : ContainerInterface { - // TODO: Implement getParent() method. + // todo adjust http link and self(); } /** @@ -349,7 +430,7 @@ class File extends FileAbstract implements FileInterface */ public function createNode() : bool { - // TODO: Implement createNode() method. + return self::ftpCreate($this->con, $this->uri->getPath(), 0755, true); } /** @@ -480,4 +561,4 @@ class File extends FileAbstract implements FileInterface { // TODO: Implement getExtension() method. } -} \ No newline at end of file +} diff --git a/System/File/Ftp/FtpStorage.php b/System/File/Ftp/FtpStorage.php index 7aad853e1..f94ea4240 100644 --- a/System/File/Ftp/FtpStorage.php +++ b/System/File/Ftp/FtpStorage.php @@ -4,436 +4,51 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Ftp; -use phpOMS\System\File\ContainerInterface; + use phpOMS\System\File\StorageAbstract; +use phpOMS\System\File\PathException; /** * Filesystem class. * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class FtpStorage extends StorageAbstract { - private $con = null; - private static $instance = null; - public function __construct() { - + public function __construct() + { + } public static function getInstance() : StorageAbstract { - if(!isset(self::$instance)) { + 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 + protected static function getClassType(string $path) : string { - if($ssl) { - $this->con = ftp_connect($uri, $port); - } else { - $this->con = ftp_ssl_connect($uri, $port); - } - - ftp_pasv($this->con, $mode); - - if(isset($login, $pass)) { - ftp_login($this->con, $login, $pass); - } - } - - public function __destruct() - { - if(isset($this->con)) { - ftp_close($this->con); - $this->con = null; - } - } - - /** - * {@inheritdoc} - */ - public static function created(string $path) : \DateTime - { - // TODO: Implement created() method. - } - - /** - * {@inheritdoc} - */ - public static function changed(string $path) : \DateTime - { - // TODO: Implement changed() method. - } - - /** - * {@inheritdoc} - */ - public static function owner(string $path) : int - { - // TODO: Implement owner() method. - } - - /** - * {@inheritdoc} - */ - public static function permission(string $path) : int - { - // TODO: Implement permission() method. - } - - /** - * {@inheritdoc} - */ - public static function parent(string $path) : string - { - // TODO: Implement parent() method. - } - - /** - * {@inheritdoc} - */ - public static function create(string $path) : bool - { - // TODO: Implement create() method. - } - - /** - * {@inheritdoc} - */ - public static function delete(string $path) : bool - { - // TODO: Implement delete() method. - } - - /** - * {@inheritdoc} - */ - public static function copy(string $from, string $to, bool $overwrite = false) : bool - { - // TODO: Implement copy() method. - } - - /** - * {@inheritdoc} - */ - public static function move(string $from, string $to, bool $overwrite = false) : bool - { - // TODO: Implement move() method. - } - - /** - * {@inheritdoc} - */ - public static function size(string $path, bool $recursive = true) : int - { - // TODO: Implement size() method. - } - - /** - * {@inheritdoc} - */ - public static function exists(string $path) : bool - { - // TODO: Implement exists() method. - } - - /** - * {@inheritdoc} - */ - public static function name(string $path) : string - { - // TODO: Implement name() method. - } - - /** - * {@inheritdoc} - */ - public static function basename(string $path) : string - { - // 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} - */ - public static function count(string $path, bool $recursive = true, array $ignore = []) : int - { - // TODO: Implement count() method. - } - - /** - * {@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- * An offset to check for. - *
- * @return boolean true on success or false on failure. - * - *- * 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
- * The offset to retrieve. - *
- * @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- * The offset to assign the value to. - *
- * @param mixed $value- * The value to set. - *
- * @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- * The offset to unset. - *
- * @return void - * @since 5.0.0 - */ - public function offsetUnset($offset) - { - // TODO: Implement offsetUnset() method. + return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class; } /** @@ -441,7 +56,11 @@ class FtpStorage extends StorageAbstract */ 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); } /** @@ -449,47 +68,31 @@ class FtpStorage extends StorageAbstract */ public static function get(string $path) : string { - // TODO: Implement get() method. + if (is_dir($path)) { + throw new PathException($path); + } + + return File::get($path); } /** * {@inheritdoc} */ - public function putContent(string $content, int $mode = 0) : bool + public static function create(string $path) : bool { - // TODO: Implement putContent() method. + return stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path); } /** * {@inheritdoc} */ - public function getContent() : string + public static function list(string $path, string $filter = '*') : array { - // TODO: Implement getContent() method. - } + if (is_file($path)) { + throw new PathException($path); + } - /** - * {@inheritdoc} - */ - public static function sanitize(string $path, string $replace = '') : string - { - // TODO: Implement sanitize() method. - } - - /** - * {@inheritdoc} - */ - public function getNode(string $name) - { - // TODO: Implement getNode() method. - } - - /** - * {@inheritdoc} - */ - public function addNode($file) : bool - { - // TODO: Implement addNode() method. + return Directory::list($path, $filter); } /** @@ -497,7 +100,11 @@ class FtpStorage extends StorageAbstract */ 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); } /** @@ -505,7 +112,11 @@ class FtpStorage extends StorageAbstract */ 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); } /** @@ -513,7 +124,11 @@ class FtpStorage extends StorageAbstract */ 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); } /** @@ -521,38 +136,10 @@ class FtpStorage extends StorageAbstract */ public static function extension(string $path) : string { - // TODO: Implement extension() method. - } + if (is_dir($path)) { + throw new PathException($path); + } - /** - * {@inheritdoc} - */ - public function setContent(string $content) : bool - { - // TODO: Implement setContent() method. + return File::extension($path); } - - /** - * {@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. - } -} \ No newline at end of file +} diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index 25f1c2aea..e5abffb63 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Local; @@ -25,10 +24,9 @@ use phpOMS\Utils\StringUtils; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Directory extends FileAbstract implements DirectoryInterface @@ -115,7 +113,7 @@ class Directory extends FileAbstract implements DirectoryInterface new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item ) { - if($item->getExtension() === $extension) { + if ($item->getExtension() === $extension) { $list[] = str_replace('\\', '/', $iterator->getSubPathName()); } } @@ -144,8 +142,8 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function addNode($file) : bool { - $this->count += $file->getCount(); - $this->size += $file->getSize(); + $this->count += $file->getCount(); + $this->size += $file->getSize(); $this->nodes[$file->getName()] = $file; return $file->createNode(); @@ -156,27 +154,23 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function size(string $dir, bool $recursive = true) : int { - if (!file_exists($dir)) { + if (!file_exists($dir) || !is_readable($dir)) { throw new PathException($dir); } - $countSize = 0; - $count = 0; + $countSize = 0; + $directories = scandir($dir); - if (is_readable($dir)) { - $dir_array = scandir($dir); + foreach ($directories as $key => $filename) { + if ($filename === ".." || $filename === ".") { + continue; + } - foreach ($dir_array as $key => $filename) { - if ($filename != ".." && $filename != ".") { - if (is_dir($dir . "/" . $filename) && $recursive) { - $countSize += self::size($dir . "/" . $filename, $recursive); - } else { - if (is_file($dir . "/" . $filename)) { - $countSize += filesize($dir . "/" . $filename); - $count++; - } - } - } + $path = $dir . "/" . $filename; + if (is_dir($path) && $recursive) { + $countSize += self::size($path, $recursive); + } elseif (is_file($path)) { + $countSize += filesize($path); } } @@ -192,8 +186,8 @@ class Directory extends FileAbstract implements DirectoryInterface throw new PathException($path); } - $size = 0; - $files = scandir($path); + $size = 0; + $files = scandir($path); $ignore[] = '.'; $ignore[] = '..'; @@ -254,7 +248,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public static function created(string $path) : \DateTime { - if(!file_exists($path)) { + if (!file_exists($path)) { throw new PathException($path); } @@ -312,14 +306,12 @@ class Directory extends FileAbstract implements DirectoryInterface throw new PathException($from); } - if(!$overwrite && file_exists($to)) { - return false; - } - if (!file_exists($to)) { - self::create($to, 0644, true); - } elseif($overwrite && file_exists($to)) { + self::create($to, 0755, true); + } elseif ($overwrite && file_exists($to)) { self::delete($to); + } else { + return false; } foreach ($iterator = new \RecursiveIteratorIterator( @@ -347,12 +339,12 @@ class Directory extends FileAbstract implements DirectoryInterface if (!$overwrite && file_exists($to)) { return false; - } elseif($overwrite && file_exists($to)) { + } elseif ($overwrite && file_exists($to)) { self::delete($to); } if (!self::exists(self::parent($to))) { - self::create(self::parent($to), 0644, true); + self::create(self::parent($to), 0755, true); } rename($from, $to); @@ -397,10 +389,10 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public static function create(string $path, int $permission = 0644, bool $recursive = false) : bool + public static function create(string $path, int $permission = 0755, bool $recursive = false) : bool { if (!file_exists($path)) { - if(!$recursive && !file_exists(self::parent($path))) { + if (!$recursive && !file_exists(self::parent($path))) { return false; } @@ -419,7 +411,7 @@ class Directory extends FileAbstract implements DirectoryInterface { if (isset($this->nodes[$name])) { $this->count -= $this->nodes[$name]->getCount(); - $this->size -= $this->nodes[$name]->getSize(); + $this->size -= $this->nodes[$name]->getSize(); unset($this->nodes[$name]); @@ -540,7 +532,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function getParent() : ContainerInterface { - // TODO: Implement getParent() method. + return new self(self::parent($this->path)); } /** @@ -548,7 +540,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function copyNode(string $to, bool $overwrite = false) : bool { - // TODO: Implement copyNode() method. + return self::copy($this->path, $to, $overwrite); } /** @@ -556,7 +548,7 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function moveNode(string $to, bool $overwrite = false) : bool { - // TODO: Implement moveNode() method. + return self::move($this->path, $to, $overwrite); } /** @@ -564,20 +556,16 @@ class Directory extends FileAbstract implements DirectoryInterface */ public function deleteNode() : bool { - // TODO: Implement deleteNode() method. + return self::delete($this->path); + + // todo: remove from node list } /** - * Offset to retrieve - * @link http://php.net/manual/en/arrayaccess.offsetget.php - * @param mixed $offset- * The offset to retrieve. - *
- * @return mixed Can return all value types. - * @since 5.0.0 + * {@inheritdoc} */ public function offsetGet($offset) { // TODO: Implement offsetGet() method. } -} \ No newline at end of file +} diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 6cd2954fe..f410cb902 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Local; @@ -25,10 +24,9 @@ use phpOMS\System\File\PathException; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class File extends FileAbstract implements FileInterface @@ -68,19 +66,18 @@ class File extends FileAbstract implements FileInterface { $exists = file_exists($path); - if ( - (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) - || (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) - || (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists) - || (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE) + if ((ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) + || (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) + || (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists) + || (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE)) ) { - if(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) { + if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) { file_put_contents($path, file_get_contents($path) . $content); - } elseif(($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) { + } elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) { file_put_contents($path, $content . file_get_contents($path)); } else { if (!Directory::exists(dirname($path))) { - Directory::create(dirname($path), 0644, true); + Directory::create(dirname($path), 0755, true); } file_put_contents($path, $content); @@ -169,10 +166,7 @@ class File extends FileAbstract implements FileInterface throw new PathException($path); } - $created = new \DateTime(); - $created->setTimestamp(filemtime($path)); - - return $created; + return self::createFileTime(filemtime($path)); } /** @@ -184,10 +178,24 @@ class File extends FileAbstract implements FileInterface throw new PathException($path); } - $changed = new \DateTime(); - $changed->setTimestamp(filectime($path)); + return self::createFileTime(filectime($path)); + } - return $changed; + /** + * Create file time. + * + * @param int $time Time of the file + * + * @return \DateTime + * + * @since 1.0.0 + */ + private static function createFileTime(int $time) : \DateTime + { + $fileTime = new \DateTime(); + $fileTime->setTimestamp($time); + + return $fileTime; } /** @@ -228,9 +236,9 @@ class File extends FileAbstract implements FileInterface /** * Gets the directory name of a file. - * + * * @param string $path Path of the file to get the directory name for. - * + * * @return string Returns the directory name of the file. * * @since 1.0.0 @@ -242,9 +250,9 @@ class File extends FileAbstract implements FileInterface /** * Gets the directory path of a file. - * + * * @param string $path Path of the file to get the directory name for. - * + * * @return string Returns the directory name of the file. * * @since 1.0.0 @@ -265,10 +273,10 @@ class File extends FileAbstract implements FileInterface if ($overwrite || !file_exists($to)) { if (!Directory::exists(dirname($to))) { - Directory::create(dirname($to), 0644, true); + Directory::create(dirname($to), 0755, true); } - if($overwrite && file_exists($to)) { + if ($overwrite && file_exists($to)) { unlink($to); } @@ -285,25 +293,13 @@ class File extends FileAbstract implements FileInterface */ public static function move(string $from, string $to, bool $overwrite = false) : bool { - if (!is_file($from)) { - throw new PathException($from); + $result = self::copy($from, $to, $overwrite); + + if (!$result) { + return false; } - if ($overwrite || !file_exists($to)) { - if (!Directory::exists(dirname($to))) { - Directory::create(dirname($to), 0644, true); - } - - if($overwrite && file_exists($to)) { - unlink($to); - } - - rename($from, $to); - - return true; - } - - return false; + return self::delete($from); } /** @@ -322,7 +318,7 @@ class File extends FileAbstract implements FileInterface /** * Gets the directory name of a file. - * + * * @return string Returns the directory name of the file. * * @since 1.0.0 @@ -334,7 +330,7 @@ class File extends FileAbstract implements FileInterface /** * Gets the directory path of a file. - * + * * @return string Returns the directory path of the file. * * @since 1.0.0 @@ -359,13 +355,13 @@ class File extends FileAbstract implements FileInterface { if (!file_exists($path)) { if (!Directory::exists(dirname($path))) { - Directory::create(dirname($path), 0644, true); + Directory::create(dirname($path), 0755, true); } - if(!is_writable(dirname($path))) { + if (!is_writable(dirname($path))) { return false; } - + touch($path); return true; @@ -429,7 +425,7 @@ class File extends FileAbstract implements FileInterface */ public function getParent() : ContainerInterface { - // TODO: Implement getParent() method. + return new Directory(self::parent($this->path)); } /** @@ -437,7 +433,7 @@ class File extends FileAbstract implements FileInterface */ public function copyNode(string $to, bool $overwrite = false) : bool { - // TODO: Implement copyNode() method. + return self::copy($this->path, $to, $overwrite); } /** @@ -445,7 +441,7 @@ class File extends FileAbstract implements FileInterface */ public function moveNode(string $to, bool $overwrite = false) : bool { - // TODO: Implement moveNode() method. + return self::move($this->path, $to, $overwrite); } /** @@ -453,7 +449,7 @@ class File extends FileAbstract implements FileInterface */ public function deleteNode() : bool { - // TODO: Implement deleteNode() method. + return self::delete($this->path); } /** @@ -461,7 +457,7 @@ class File extends FileAbstract implements FileInterface */ public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool { - // TODO: Implement putContent() method. + return self::put($this->path, $content, $mode); } /** @@ -489,4 +485,4 @@ class File extends FileAbstract implements FileInterface return $extension[1] ?? ''; } -} \ No newline at end of file +} diff --git a/System/File/Local/FileAbstract.php b/System/File/Local/FileAbstract.php index 46a81b8ab..69179492b 100644 --- a/System/File/Local/FileAbstract.php +++ b/System/File/Local/FileAbstract.php @@ -4,16 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Local; + use phpOMS\System\File\ContainerInterface; /** @@ -21,10 +21,9 @@ use phpOMS\System\File\ContainerInterface; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class FileAbstract implements ContainerInterface @@ -88,10 +87,10 @@ abstract class FileAbstract implements ContainerInterface /** * Permission. * - * @var string + * @var int * @since 1.0.0 */ - protected $permission = 0644; + protected $permission = 0755; /** * Constructor. @@ -176,7 +175,7 @@ abstract class FileAbstract implements ContainerInterface /** * {@inheritdoc} */ - public function getPermission() : string + public function getPermission() : int { return $this->permission; } @@ -191,4 +190,4 @@ abstract class FileAbstract implements ContainerInterface $this->owner = fileowner($this->path); $this->permission = (int) substr(sprintf('%o', fileperms($this->path)), -4); } -} \ No newline at end of file +} diff --git a/System/File/Local/LocalStorage.php b/System/File/Local/LocalStorage.php index ea248c7f5..4f3e2e4c8 100644 --- a/System/File/Local/LocalStorage.php +++ b/System/File/Local/LocalStorage.php @@ -4,17 +4,16 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File\Local; -use phpOMS\System\File\ContainerInterface; + use phpOMS\System\File\StorageAbstract; use phpOMS\System\File\PathException; @@ -23,168 +22,66 @@ use phpOMS\System\File\PathException; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LocalStorage extends StorageAbstract { + /** + * Storage instance. + * + * @var LocalStorage + * @since 1.0.0 + */ private static $instance = null; - public function __construct() { - + /** + * Constructor. + * + * @since 1.0.0 + */ + public function __construct() + { } + /** + * Get instance. + * + * @return StorageAbstract + * + * @since 1.0.0 + */ public static function getInstance() : StorageAbstract { - if(!isset(self::$instance)) { + if (!isset(self::$instance)) { self::$instance = new self(); } return self::$instance; } - private static function getClassType(string $path) : string + /** + * Get the internal class type (directory or file) based on path. + * + * @param string $path Path to the directory or file + * + * @return string Class namespace + * + * @since 1.0.0 + */ + protected static function getClassType(string $path) : string { return is_dir($path) || (!is_file($path) && stripos($path, '.') === false) ? Directory::class : File::class; } - /** - * {@inheritdoc} - */ - public static function created(string $path) : \DateTime - { - return self::getClassType($path)::created($path); - } - - /** - * {@inheritdoc} - */ - public static function changed(string $path) : \DateTime - { - return self::getClassType($path)::changed($path); - } - - /** - * {@inheritdoc} - */ - public static function owner(string $path) : int - { - return self::getClassType($path)::owner($path); - } - - /** - * {@inheritdoc} - */ - public static function permission(string $path) : int - { - return self::getClassType($path)::permission($path); - } - - /** - * {@inheritdoc} - */ - public static function parent(string $path) : string - { - return self::getClassType($path)::parent($path); - } - - /** - * {@inheritdoc} - */ - public static function create(string $path) : bool - { - return stripos($path, '.') === false ? Directory::create($path, 0644, true) : File::create($path); - } - - /** - * {@inheritdoc} - */ - public static function delete(string $path) : bool - { - return self::getClassType($path)::delete($path); - } - - /** - * {@inheritdoc} - */ - public static function copy(string $from, string $to, bool $overwrite = false) : bool - { - return self::getClassType($from)::copy($from, $to, $overwrite); - } - - /** - * {@inheritdoc} - */ - public static function move(string $from, string $to, bool $overwrite = false) : bool - { - return self::getClassType($from)::move($from, $to, $overwrite); - } - - /** - * {@inheritdoc} - */ - public static function size(string $path, bool $recursive = true) : int - { - return self::getClassType($path)::size($path, $recursive); - } - - /** - * {@inheritdoc} - */ - public static function exists(string $path) : bool - { - return self::getClassType($path)::exists($path); - } - - /** - * {@inheritdoc} - */ - public static function name(string $path) : string - { - return self::getClassType($path)::name($path); - } - - /** - * {@inheritdoc} - */ - public static function basename(string $path) : string - { - 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); - } - - /** - * {@inheritdoc} - */ - public static function count(string $path, bool $recursive = true, array $ignore = []) : int - { - return self::getClassType($path)::count($path, $recursive, $ignore); - } - /** * {@inheritdoc} */ public static function put(string $path, string $content, int $mode = 0) : bool { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } @@ -196,7 +93,7 @@ class LocalStorage extends StorageAbstract */ public static function get(string $path) : string { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } @@ -208,7 +105,7 @@ class LocalStorage extends StorageAbstract */ public static function list(string $path, string $filter = '*') : array { - if(is_file($path)) { + if (is_file($path)) { throw new PathException($path); } @@ -218,9 +115,9 @@ class LocalStorage extends StorageAbstract /** * {@inheritdoc} */ - public static function sanitize(string $path, string $replace = '') : string + public static function create(string $path) : bool { - return self::getClassType($path)::sanitize($path, $replace); + return stripos($path, '.') === false ? Directory::create($path, 0755, true) : File::create($path); } /** @@ -228,7 +125,7 @@ class LocalStorage extends StorageAbstract */ public static function set(string $path, string $content) : bool { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } @@ -240,7 +137,7 @@ class LocalStorage extends StorageAbstract */ public static function append(string $path, string $content) : bool { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } @@ -252,7 +149,7 @@ class LocalStorage extends StorageAbstract */ public static function prepend(string $path, string $content) : bool { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } @@ -264,10 +161,10 @@ class LocalStorage extends StorageAbstract */ public static function extension(string $path) : string { - if(is_dir($path)) { + if (is_dir($path)) { throw new PathException($path); } return File::extension($path); } -} \ No newline at end of file +} diff --git a/System/File/PathException.php b/System/File/PathException.php index 5962a5a60..7f28d91bd 100644 --- a/System/File/PathException.php +++ b/System/File/PathException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; /** * Path exception class. * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PathException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class PathException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/System/File/PermissionException.php b/System/File/PermissionException.php index b42c4f98e..be4891068 100644 --- a/System/File/PermissionException.php +++ b/System/File/PermissionException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; /** * Permission exception class. * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class PermissionException extends \RuntimeException @@ -31,7 +29,7 @@ class PermissionException extends \RuntimeException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/System/File/Storage.php b/System/File/Storage.php index f9e3ab017..85e8ab87a 100644 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -20,10 +19,9 @@ namespace phpOMS\System\File; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class Storage @@ -35,7 +33,7 @@ final class Storage * @since 1.0.0 */ private static $registered = []; - + /** * Constructor. * @@ -44,7 +42,7 @@ final class Storage */ private function __construct() { - + } /** @@ -61,9 +59,9 @@ final class Storage public static function env(string $env = 'local') : StorageAbstract { if (isset(self::$registered[$env])) { - if(is_string(self::$registered[$env])) { + if (is_string(self::$registered[$env])) { $env = self::$registered[$env]::getInstance(); - } elseif(self::$registered[$env] instanceof StorageAbstract || self::$registered[$env] instanceof ContainerInterface) { + } elseif (self::$registered[$env] instanceof StorageAbstract || self::$registered[$env] instanceof ContainerInterface) { $env = self::$registered[$env]; } else { throw new \Exception('Invalid type'); @@ -78,7 +76,7 @@ final class Storage $env = $env::getInstance(); self::$registered[$stg] = $env; - } catch(\Throwable $e) { + } catch (\Throwable $e) { throw new \Exception(); } } diff --git a/System/File/StorageAbstract.php b/System/File/StorageAbstract.php index 215930f6c..307ce7616 100644 --- a/System/File/StorageAbstract.php +++ b/System/File/StorageAbstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System\File; @@ -20,10 +19,9 @@ namespace phpOMS\System\File; * * Performing operations on the file system * - * @category Framework - * @package phpOMS\System\File + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class StorageAbstract @@ -72,120 +70,128 @@ abstract class StorageAbstract /** * {@inheritdoc} */ - public abstract static function created(string $path) : \DateTime; + public static function created(string $path) : \DateTime + { + return static::getClassType($path)::created($path); + } /** * {@inheritdoc} */ - public abstract static function changed(string $path) : \DateTime; + public static function changed(string $path) : \DateTime + { + return static::getClassType($path)::changed($path); + } /** * {@inheritdoc} */ - public abstract static function owner(string $path) : int; + public static function owner(string $path) : int + { + return static::getClassType($path)::owner($path); + } /** * {@inheritdoc} */ - public abstract static function permission(string $path) : int; + public static function permission(string $path) : int + { + return static::getClassType($path)::permission($path); + } /** * {@inheritdoc} */ - public abstract static function parent(string $path) : string; + public static function parent(string $path) : string + { + return static::getClassType($path)::parent($path); + } /** * {@inheritdoc} */ - public abstract static function create(string $path) : bool; + public static function delete(string $path) : bool + { + return static::getClassType($path)::delete($path); + } /** * {@inheritdoc} */ - public abstract static function delete(string $path) : bool; + public static function copy(string $from, string $to, bool $overwrite = false) : bool + { + return static::getClassType($from)::copy($from, $to, $overwrite); + } /** * {@inheritdoc} */ - public abstract static function copy(string $from, string $to, bool $overwrite = false) : bool; + public static function move(string $from, string $to, bool $overwrite = false) : bool + { + return static::getClassType($from)::move($from, $to, $overwrite); + } /** * {@inheritdoc} */ - public abstract static function move(string $from, string $to, bool $overwrite = false) : bool; + public static function size(string $path, bool $recursive = true) : int + { + return static::getClassType($path)::size($path, $recursive); + } /** * {@inheritdoc} */ - public abstract static function size(string $path, bool $recursive = true) : int; + public static function exists(string $path) : bool + { + return static::getClassType($path)::exists($path); + } /** * {@inheritdoc} */ - public abstract static function exists(string $path) : bool; + public static function name(string $path) : string + { + return static::getClassType($path)::name($path); + } /** * {@inheritdoc} */ - public abstract static function name(string $path) : string; + public static function basename(string $path) : string + { + return static::getClassType($path)::basename($path); + } /** * {@inheritdoc} */ - public abstract static function basename(string $path) : string; + public static function dirname(string $path) : string + { + return static::getClassType($path)::dirname($path); + } /** * {@inheritdoc} */ - public abstract static function dirname(string $path) : string; + public static function dirpath(string $path) : string + { + return static::getClassType($path)::dirpath($path); + } /** * {@inheritdoc} */ - public abstract static function dirpath(string $path) : string; + public static function count(string $path, bool $recursive = true, array $ignore = []) : int + { + return static::getClassType($path)::count($path, $recursive, $ignore); + } /** * {@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; + public static function sanitize(string $path, string $replace = '') : string + { + return static::getClassType($path)::sanitize($path, $replace); + } } diff --git a/System/MimeType.php b/System/MimeType.php index 1d52aad06..49ab1743d 100644 --- a/System/MimeType.php +++ b/System/MimeType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System; @@ -22,998 +21,997 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class MimeType extends Enum { - /* public */ const M_3DML = 'text/vnd.in3d.3dml'; - /* public */ const M_3DS = 'image/x-3ds'; - /* public */ const M_3G2 = 'video/3gpp2'; - /* public */ const M_3GP = 'video/3gpp'; - /* public */ const M_7Z = 'application/x-7z-compressed'; - /* public */ const M_AAB = 'application/x-authorware-bin'; - /* public */ const M_AAC = 'audio/x-aac'; - /* public */ const M_AAM = 'application/x-authorware-map'; - /* public */ const M_AAS = 'application/x-authorware-seg'; - /* public */ const M_ABW = 'application/x-abiword'; - /* public */ const M_AC = 'application/pkix-attr-cert'; - /* public */ const M_ACC = 'application/vnd.americandynamics.acc'; - /* public */ const M_ACE = 'application/x-ace-compressed'; - /* public */ const M_ACU = 'application/vnd.acucobol'; - /* public */ const M_ACUTC = 'application/vnd.acucorp'; - /* public */ const M_ADP = 'audio/adpcm'; - /* public */ const M_AEP = 'application/vnd.audiograph'; - /* public */ const M_AFM = 'application/x-font-type1'; - /* public */ const M_AFP = 'application/vnd.ibm.modcap'; - /* public */ const M_AHEAD = 'application/vnd.ahead.space'; - /* public */ const M_AI = 'application/postscript'; - /* public */ const M_AIF = 'audio/x-aiff'; - /* public */ const M_AIFC = 'audio/x-aiff'; - /* public */ const M_AIFF = 'audio/x-aiff'; - /* public */ const M_AIR = 'application/vnd.adobe.air-application-installer-package+zip'; - /* public */ const M_AIT = 'application/vnd.dvb.ait'; - /* public */ const M_AMI = 'application/vnd.amiga.ami'; - /* public */ const M_APK = 'application/vnd.android.package-archive'; - /* public */ const M_APPCACHE = 'text/cache-manifest'; - /* public */ const M_APR = 'application/vnd.lotus-approach'; - /* public */ const M_APS = 'application/postscript'; - /* public */ const M_ARC = 'application/x-freearc'; - /* public */ const M_ASC = 'application/pgp-signature'; - /* public */ const M_ASF = 'video/x-ms-asf'; - /* public */ const M_ASM = 'text/x-asm'; - /* public */ const M_ASO = 'application/vnd.accpac.simply.aso'; - /* public */ const M_ASX = 'video/x-ms-asf'; - /* public */ const M_ATC = 'application/vnd.acucorp'; - /* public */ const M_ATOM = 'application/atom+xml'; - /* public */ const M_ATOMCAT = 'application/atomcat+xml'; - /* public */ const M_ATOMSVC = 'application/atomsvc+xml'; - /* public */ const M_ATX = 'application/vnd.antix.game-component'; - /* public */ const M_AU = 'audio/basic'; - /* public */ const M_AVI = 'video/x-msvideo'; - /* public */ const M_AW = 'application/applixware'; - /* public */ const M_AZF = 'application/vnd.airzip.filesecure.azf'; - /* public */ const M_AZS = 'application/vnd.airzip.filesecure.azs'; - /* public */ const M_AZW = 'application/vnd.amazon.ebook'; - /* public */ const M_BAT = 'application/x-msdownload'; - /* public */ const M_BCPIO = 'application/x-bcpio'; - /* public */ const M_BDF = 'application/x-font-bdf'; - /* public */ const M_BDM = 'application/vnd.syncml.dm+wbxml'; - /* public */ const M_BED = 'application/vnd.realvnc.bed'; - /* public */ const M_BH2 = 'application/vnd.fujitsu.oasysprs'; - /* public */ const M_BIN = 'application/octet-stream'; - /* public */ const M_BLB = 'application/x-blorb'; - /* public */ const M_BLORB = 'application/x-blorb'; - /* public */ const M_BMI = 'application/vnd.bmi'; - /* public */ const M_BMP = 'image/bmp'; - /* public */ const M_BOOK = 'application/vnd.framemaker'; - /* public */ const M_BOX = 'application/vnd.previewsystems.box'; - /* public */ const M_BOZ = 'application/x-bzip2'; - /* public */ const M_BPK = 'application/octet-stream'; - /* public */ const M_BTIF = 'image/prs.btif'; - /* public */ const M_BZ = 'application/x-bzip'; - /* public */ const M_BZ2 = 'application/x-bzip2'; - /* public */ const M_C = 'text/x-c'; - /* public */ const M_C11AMC = 'application/vnd.cluetrust.cartomobile-config'; - /* public */ const M_C11AMZ = 'application/vnd.cluetrust.cartomobile-config-pkg'; - /* public */ const M_C4D = 'application/vnd.clonk.c4group'; - /* public */ const M_C4F = 'application/vnd.clonk.c4group'; - /* public */ const M_C4G = 'application/vnd.clonk.c4group'; - /* public */ const M_C4P = 'application/vnd.clonk.c4group'; - /* public */ const M_C4U = 'application/vnd.clonk.c4group'; - /* public */ const M_CAB = 'application/vnd.ms-cab-compressed'; - /* public */ const M_CAF = 'audio/x-caf'; - /* public */ const M_CAP = 'application/vnd.tcpdump.pcap'; - /* public */ const M_CAR = 'application/vnd.curl.car'; - /* public */ const M_CAT = 'application/vnd.ms-pki.seccat'; - /* public */ const M_CB7 = 'application/x-cbr'; - /* public */ const M_CBA = 'application/x-cbr'; - /* public */ const M_CBR = 'application/x-cbr'; - /* public */ const M_CBT = 'application/x-cbr'; - /* public */ const M_CBZ = 'application/x-cbr'; - /* public */ const M_CC = 'text/x-c'; - /* public */ const M_CCT = 'application/x-director'; - /* public */ const M_CCXML = 'application/ccxml+xml'; - /* public */ const M_CDBCMSG = 'application/vnd.contact.cmsg'; - /* public */ const M_CDF = 'application/x-netcdf'; - /* public */ const M_CDKEY = 'application/vnd.mediastation.cdkey'; - /* public */ const M_CDMIA = 'application/cdmi-capability'; - /* public */ const M_CDMIC = 'application/cdmi-container'; - /* public */ const M_CDMID = 'application/cdmi-domain'; - /* public */ const M_CDMIO = 'application/cdmi-object'; - /* public */ const M_CDMIQ = 'application/cdmi-queue'; - /* public */ const M_CDX = 'chemical/x-cdx'; - /* public */ const M_CDXML = 'application/vnd.chemdraw+xml'; - /* public */ const M_CDY = 'application/vnd.cinderella'; - /* public */ const M_CER = 'application/pkix-cert'; - /* public */ const M_CFS = 'application/x-cfs-compressed'; - /* public */ const M_CGM = 'image/cgm'; - /* public */ const M_CHAT = 'application/x-chat'; - /* public */ const M_CHM = 'application/vnd.ms-htmlhelp'; - /* public */ const M_CHRT = 'application/vnd.kde.kchart'; - /* public */ const M_CIF = 'chemical/x-cif'; - /* public */ const M_CII = 'application/vnd.anser-web-certificate-issue-initiation'; - /* public */ const M_CIL = 'application/vnd.ms-artgalry'; - /* public */ const M_CLA = 'application/vnd.claymore'; - /* public */ const M_CLASS = 'application/java-vm'; - /* public */ const M_CLKK = 'application/vnd.crick.clicker.keyboard'; - /* public */ const M_CLKP = 'application/vnd.crick.clicker.palette'; - /* public */ const M_CLKT = 'application/vnd.crick.clicker.template'; - /* public */ const M_CLKW = 'application/vnd.crick.clicker.wordbank'; - /* public */ const M_CLKX = 'application/vnd.crick.clicker'; - /* public */ const M_CLP = 'application/x-msclip'; - /* public */ const M_CMC = 'application/vnd.cosmocaller'; - /* public */ const M_CMDF = 'chemical/x-cmdf'; - /* public */ const M_CML = 'chemical/x-cml'; - /* public */ const M_CMP = 'application/vnd.yellowriver-custom-menu'; - /* public */ const M_CMX = 'image/x-cmx'; - /* public */ const M_COD = 'application/vnd.rim.cod'; - /* public */ const M_COM = 'application/x-msdownload'; - /* public */ const M_CONF = 'text/plain'; - /* public */ const M_CPIO = 'application/x-cpio'; - /* public */ const M_CPP = 'text/x-c'; - /* public */ const M_CPT = 'application/mac-compactpro'; - /* public */ const M_CRD = 'application/x-mscardfile'; - /* public */ const M_CRL = 'application/pkix-crl'; - /* public */ const M_CRT = 'application/x-x509-ca-cert'; - /* public */ const M_CSH = 'application/x-csh'; - /* public */ const M_CSML = 'chemical/x-csml'; - /* public */ const M_CSP = 'application/vnd.commonspace'; - /* public */ const M_CSS = 'text/css'; - /* public */ const M_CST = 'application/x-director'; - /* public */ const M_CSV = 'text/csv'; - /* public */ const M_CU = 'application/cu-seeme'; - /* public */ const M_CURL = 'text/vnd.curl'; - /* public */ const M_CWW = 'application/prs.cww'; - /* public */ const M_CXT = 'application/x-director'; - /* public */ const M_CXX = 'text/x-c'; - /* public */ const M_DAE = 'model/vnd.collada+xml'; - /* public */ const M_DAF = 'application/vnd.mobius.daf'; - /* public */ const M_DART = 'application/vnd.dart'; - /* public */ const M_DATALESS = 'application/vnd.fdsn.seed'; - /* public */ const M_DAVMOUNT = 'application/davmount+xml'; - /* public */ const M_DBK = 'application/docbook+xml'; - /* public */ const M_DCR = 'application/x-director'; - /* public */ const M_DCURL = 'text/vnd.curl.dcurl'; - /* public */ const M_DD2 = 'application/vnd.oma.dd2+xml'; - /* public */ const M_DDD = 'application/vnd.fujixerox.ddd'; - /* public */ const M_DEB = 'application/x-debian-package'; - /* public */ const M_DEF = 'text/plain'; - /* public */ const M_DEPLOY = 'application/octet-stream'; - /* public */ const M_DER = 'application/x-x509-ca-cert'; - /* public */ const M_DFAC = 'application/vnd.dreamfactory'; - /* public */ const M_DGC = 'application/x-dgc-compressed'; - /* public */ const M_DIC = 'text/x-c'; - /* public */ const M_DIR = 'application/x-director'; - /* public */ const M_DIS = 'application/vnd.mobius.dis'; - /* public */ const M_DIST = 'application/octet-stream'; - /* public */ const M_DISTZ = 'application/octet-stream'; - /* public */ const M_DJV = 'image/vnd.djvu'; - /* public */ const M_DJVU = 'image/vnd.djvu'; - /* public */ const M_DLL = 'application/x-msdownload'; - /* public */ const M_DMG = 'application/x-apple-diskimage'; - /* public */ const M_DMP = 'application/vnd.tcpdump.pcap'; - /* public */ const M_DMS = 'application/octet-stream'; - /* public */ const M_DNA = 'application/vnd.dna'; - /* public */ const M_DOC = 'application/msword'; - /* public */ const M_DOCM = 'application/vnd.ms-word.document.macroenabled.12'; - /* public */ const M_DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; - /* public */ const M_DOT = 'application/msword'; - /* public */ const M_DOTM = 'application/vnd.ms-word.template.macroenabled.12'; - /* public */ const M_DOTX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; - /* public */ const M_DP = 'application/vnd.osgi.dp'; - /* public */ const M_DPG = 'application/vnd.dpgraph'; - /* public */ const M_DRA = 'audio/vnd.dra'; - /* public */ const M_DSC = 'text/prs.lines.tag'; - /* public */ const M_DSSC = 'application/dssc+der'; - /* public */ const M_DTB = 'application/x-dtbook+xml'; - /* public */ const M_DTD = 'application/xml-dtd'; - /* public */ const M_DTS = 'audio/vnd.dts'; - /* public */ const M_DTSHD = 'audio/vnd.dts.hd'; - /* public */ const M_DUMP = 'application/octet-stream'; - /* public */ const M_DVB = 'video/vnd.dvb.file'; - /* public */ const M_DVI = 'application/x-dvi'; - /* public */ const M_DWF = 'model/vnd.dwf'; - /* public */ const M_DWG = 'image/vnd.dwg'; - /* public */ const M_DXF = 'image/vnd.dxf'; - /* public */ const M_DXP = 'application/vnd.spotfire.dxp'; - /* public */ const M_DXR = 'application/x-director'; + /* public */ const M_3DML = 'text/vnd.in3d.3dml'; + /* public */ const M_3DS = 'image/x-3ds'; + /* public */ const M_3G2 = 'video/3gpp2'; + /* public */ const M_3GP = 'video/3gpp'; + /* public */ const M_7Z = 'application/x-7z-compressed'; + /* public */ const M_AAB = 'application/x-authorware-bin'; + /* public */ const M_AAC = 'audio/x-aac'; + /* public */ const M_AAM = 'application/x-authorware-map'; + /* public */ const M_AAS = 'application/x-authorware-seg'; + /* public */ const M_ABW = 'application/x-abiword'; + /* public */ const M_AC = 'application/pkix-attr-cert'; + /* public */ const M_ACC = 'application/vnd.americandynamics.acc'; + /* public */ const M_ACE = 'application/x-ace-compressed'; + /* public */ const M_ACU = 'application/vnd.acucobol'; + /* public */ const M_ACUTC = 'application/vnd.acucorp'; + /* public */ const M_ADP = 'audio/adpcm'; + /* public */ const M_AEP = 'application/vnd.audiograph'; + /* public */ const M_AFM = 'application/x-font-type1'; + /* public */ const M_AFP = 'application/vnd.ibm.modcap'; + /* public */ const M_AHEAD = 'application/vnd.ahead.space'; + /* public */ const M_AI = 'application/postscript'; + /* public */ const M_AIF = 'audio/x-aiff'; + /* public */ const M_AIFC = 'audio/x-aiff'; + /* public */ const M_AIFF = 'audio/x-aiff'; + /* public */ const M_AIR = 'application/vnd.adobe.air-application-installer-package+zip'; + /* public */ const M_AIT = 'application/vnd.dvb.ait'; + /* public */ const M_AMI = 'application/vnd.amiga.ami'; + /* public */ const M_APK = 'application/vnd.android.package-archive'; + /* public */ const M_APPCACHE = 'text/cache-manifest'; + /* public */ const M_APR = 'application/vnd.lotus-approach'; + /* public */ const M_APS = 'application/postscript'; + /* public */ const M_ARC = 'application/x-freearc'; + /* public */ const M_ASC = 'application/pgp-signature'; + /* public */ const M_ASF = 'video/x-ms-asf'; + /* public */ const M_ASM = 'text/x-asm'; + /* public */ const M_ASO = 'application/vnd.accpac.simply.aso'; + /* public */ const M_ASX = 'video/x-ms-asf'; + /* public */ const M_ATC = 'application/vnd.acucorp'; + /* public */ const M_ATOM = 'application/atom+xml'; + /* public */ const M_ATOMCAT = 'application/atomcat+xml'; + /* public */ const M_ATOMSVC = 'application/atomsvc+xml'; + /* public */ const M_ATX = 'application/vnd.antix.game-component'; + /* public */ const M_AU = 'audio/basic'; + /* public */ const M_AVI = 'video/x-msvideo'; + /* public */ const M_AW = 'application/applixware'; + /* public */ const M_AZF = 'application/vnd.airzip.filesecure.azf'; + /* public */ const M_AZS = 'application/vnd.airzip.filesecure.azs'; + /* public */ const M_AZW = 'application/vnd.amazon.ebook'; + /* public */ const M_BAT = 'application/x-msdownload'; + /* public */ const M_BCPIO = 'application/x-bcpio'; + /* public */ const M_BDF = 'application/x-font-bdf'; + /* public */ const M_BDM = 'application/vnd.syncml.dm+wbxml'; + /* public */ const M_BED = 'application/vnd.realvnc.bed'; + /* public */ const M_BH2 = 'application/vnd.fujitsu.oasysprs'; + /* public */ const M_BIN = 'application/octet-stream'; + /* public */ const M_BLB = 'application/x-blorb'; + /* public */ const M_BLORB = 'application/x-blorb'; + /* public */ const M_BMI = 'application/vnd.bmi'; + /* public */ const M_BMP = 'image/bmp'; + /* public */ const M_BOOK = 'application/vnd.framemaker'; + /* public */ const M_BOX = 'application/vnd.previewsystems.box'; + /* public */ const M_BOZ = 'application/x-bzip2'; + /* public */ const M_BPK = 'application/octet-stream'; + /* public */ const M_BTIF = 'image/prs.btif'; + /* public */ const M_BZ = 'application/x-bzip'; + /* public */ const M_BZ2 = 'application/x-bzip2'; + /* public */ const M_C = 'text/x-c'; + /* public */ const M_C11AMC = 'application/vnd.cluetrust.cartomobile-config'; + /* public */ const M_C11AMZ = 'application/vnd.cluetrust.cartomobile-config-pkg'; + /* public */ const M_C4D = 'application/vnd.clonk.c4group'; + /* public */ const M_C4F = 'application/vnd.clonk.c4group'; + /* public */ const M_C4G = 'application/vnd.clonk.c4group'; + /* public */ const M_C4P = 'application/vnd.clonk.c4group'; + /* public */ const M_C4U = 'application/vnd.clonk.c4group'; + /* public */ const M_CAB = 'application/vnd.ms-cab-compressed'; + /* public */ const M_CAF = 'audio/x-caf'; + /* public */ const M_CAP = 'application/vnd.tcpdump.pcap'; + /* public */ const M_CAR = 'application/vnd.curl.car'; + /* public */ const M_CAT = 'application/vnd.ms-pki.seccat'; + /* public */ const M_CB7 = 'application/x-cbr'; + /* public */ const M_CBA = 'application/x-cbr'; + /* public */ const M_CBR = 'application/x-cbr'; + /* public */ const M_CBT = 'application/x-cbr'; + /* public */ const M_CBZ = 'application/x-cbr'; + /* public */ const M_CC = 'text/x-c'; + /* public */ const M_CCT = 'application/x-director'; + /* public */ const M_CCXML = 'application/ccxml+xml'; + /* public */ const M_CDBCMSG = 'application/vnd.contact.cmsg'; + /* public */ const M_CDF = 'application/x-netcdf'; + /* public */ const M_CDKEY = 'application/vnd.mediastation.cdkey'; + /* public */ const M_CDMIA = 'application/cdmi-capability'; + /* public */ const M_CDMIC = 'application/cdmi-container'; + /* public */ const M_CDMID = 'application/cdmi-domain'; + /* public */ const M_CDMIO = 'application/cdmi-object'; + /* public */ const M_CDMIQ = 'application/cdmi-queue'; + /* public */ const M_CDX = 'chemical/x-cdx'; + /* public */ const M_CDXML = 'application/vnd.chemdraw+xml'; + /* public */ const M_CDY = 'application/vnd.cinderella'; + /* public */ const M_CER = 'application/pkix-cert'; + /* public */ const M_CFS = 'application/x-cfs-compressed'; + /* public */ const M_CGM = 'image/cgm'; + /* public */ const M_CHAT = 'application/x-chat'; + /* public */ const M_CHM = 'application/vnd.ms-htmlhelp'; + /* public */ const M_CHRT = 'application/vnd.kde.kchart'; + /* public */ const M_CIF = 'chemical/x-cif'; + /* public */ const M_CII = 'application/vnd.anser-web-certificate-issue-initiation'; + /* public */ const M_CIL = 'application/vnd.ms-artgalry'; + /* public */ const M_CLA = 'application/vnd.claymore'; + /* public */ const M_CLASS = 'application/java-vm'; + /* public */ const M_CLKK = 'application/vnd.crick.clicker.keyboard'; + /* public */ const M_CLKP = 'application/vnd.crick.clicker.palette'; + /* public */ const M_CLKT = 'application/vnd.crick.clicker.template'; + /* public */ const M_CLKW = 'application/vnd.crick.clicker.wordbank'; + /* public */ const M_CLKX = 'application/vnd.crick.clicker'; + /* public */ const M_CLP = 'application/x-msclip'; + /* public */ const M_CMC = 'application/vnd.cosmocaller'; + /* public */ const M_CMDF = 'chemical/x-cmdf'; + /* public */ const M_CML = 'chemical/x-cml'; + /* public */ const M_CMP = 'application/vnd.yellowriver-custom-menu'; + /* public */ const M_CMX = 'image/x-cmx'; + /* public */ const M_COD = 'application/vnd.rim.cod'; + /* public */ const M_COM = 'application/x-msdownload'; + /* public */ const M_CONF = 'text/plain'; + /* public */ const M_CPIO = 'application/x-cpio'; + /* public */ const M_CPP = 'text/x-c'; + /* public */ const M_CPT = 'application/mac-compactpro'; + /* public */ const M_CRD = 'application/x-mscardfile'; + /* public */ const M_CRL = 'application/pkix-crl'; + /* public */ const M_CRT = 'application/x-x509-ca-cert'; + /* public */ const M_CSH = 'application/x-csh'; + /* public */ const M_CSML = 'chemical/x-csml'; + /* public */ const M_CSP = 'application/vnd.commonspace'; + /* public */ const M_CSS = 'text/css'; + /* public */ const M_CST = 'application/x-director'; + /* public */ const M_CSV = 'text/csv'; + /* public */ const M_CU = 'application/cu-seeme'; + /* public */ const M_CURL = 'text/vnd.curl'; + /* public */ const M_CWW = 'application/prs.cww'; + /* public */ const M_CXT = 'application/x-director'; + /* public */ const M_CXX = 'text/x-c'; + /* public */ const M_DAE = 'model/vnd.collada+xml'; + /* public */ const M_DAF = 'application/vnd.mobius.daf'; + /* public */ const M_DART = 'application/vnd.dart'; + /* public */ const M_DATALESS = 'application/vnd.fdsn.seed'; + /* public */ const M_DAVMOUNT = 'application/davmount+xml'; + /* public */ const M_DBK = 'application/docbook+xml'; + /* public */ const M_DCR = 'application/x-director'; + /* public */ const M_DCURL = 'text/vnd.curl.dcurl'; + /* public */ const M_DD2 = 'application/vnd.oma.dd2+xml'; + /* public */ const M_DDD = 'application/vnd.fujixerox.ddd'; + /* public */ const M_DEB = 'application/x-debian-package'; + /* public */ const M_DEF = 'text/plain'; + /* public */ const M_DEPLOY = 'application/octet-stream'; + /* public */ const M_DER = 'application/x-x509-ca-cert'; + /* public */ const M_DFAC = 'application/vnd.dreamfactory'; + /* public */ const M_DGC = 'application/x-dgc-compressed'; + /* public */ const M_DIC = 'text/x-c'; + /* public */ const M_DIR = 'application/x-director'; + /* public */ const M_DIS = 'application/vnd.mobius.dis'; + /* public */ const M_DIST = 'application/octet-stream'; + /* public */ const M_DISTZ = 'application/octet-stream'; + /* public */ const M_DJV = 'image/vnd.djvu'; + /* public */ const M_DJVU = 'image/vnd.djvu'; + /* public */ const M_DLL = 'application/x-msdownload'; + /* public */ const M_DMG = 'application/x-apple-diskimage'; + /* public */ const M_DMP = 'application/vnd.tcpdump.pcap'; + /* public */ const M_DMS = 'application/octet-stream'; + /* public */ const M_DNA = 'application/vnd.dna'; + /* public */ const M_DOC = 'application/msword'; + /* public */ const M_DOCM = 'application/vnd.ms-word.document.macroenabled.12'; + /* public */ const M_DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + /* public */ const M_DOT = 'application/msword'; + /* public */ const M_DOTM = 'application/vnd.ms-word.template.macroenabled.12'; + /* public */ const M_DOTX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; + /* public */ const M_DP = 'application/vnd.osgi.dp'; + /* public */ const M_DPG = 'application/vnd.dpgraph'; + /* public */ const M_DRA = 'audio/vnd.dra'; + /* public */ const M_DSC = 'text/prs.lines.tag'; + /* public */ const M_DSSC = 'application/dssc+der'; + /* public */ const M_DTB = 'application/x-dtbook+xml'; + /* public */ const M_DTD = 'application/xml-dtd'; + /* public */ const M_DTS = 'audio/vnd.dts'; + /* public */ const M_DTSHD = 'audio/vnd.dts.hd'; + /* public */ const M_DUMP = 'application/octet-stream'; + /* public */ const M_DVB = 'video/vnd.dvb.file'; + /* public */ const M_DVI = 'application/x-dvi'; + /* public */ const M_DWF = 'model/vnd.dwf'; + /* public */ const M_DWG = 'image/vnd.dwg'; + /* public */ const M_DXF = 'image/vnd.dxf'; + /* public */ const M_DXP = 'application/vnd.spotfire.dxp'; + /* public */ const M_DXR = 'application/x-director'; /* public */ const M_ECELP4800 = 'audio/vnd.nuera.ecelp4800'; /* public */ const M_ECELP7470 = 'audio/vnd.nuera.ecelp7470'; /* public */ const M_ECELP9600 = 'audio/vnd.nuera.ecelp9600'; - /* public */ const M_ECMA = 'application/ecmascript'; - /* public */ const M_EDM = 'application/vnd.novadigm.edm'; - /* public */ const M_EDX = 'application/vnd.novadigm.edx'; - /* public */ const M_EFIF = 'application/vnd.picsel'; - /* public */ const M_EI6 = 'application/vnd.pg.osasli'; - /* public */ const M_ELC = 'application/octet-stream'; - /* public */ const M_EMF = 'application/x-msmetafile'; - /* public */ const M_EML = 'message/rfc822'; - /* public */ const M_EMMA = 'application/emma+xml'; - /* public */ const M_EMZ = 'application/x-msmetafile'; - /* public */ const M_EOL = 'audio/vnd.digital-winds'; - /* public */ const M_EOT = 'application/vnd.ms-fontobject'; - /* public */ const M_EPS = 'application/postscript'; - /* public */ const M_EPUB = 'application/epub+zip'; - /* public */ const M_ES3 = 'application/vnd.eszigno3+xml'; - /* public */ const M_ESA = 'application/vnd.osgi.subsystem'; - /* public */ const M_ESF = 'application/vnd.epson.esf'; - /* public */ const M_ET3 = 'application/vnd.eszigno3+xml'; - /* public */ const M_ETX = 'text/x-setext'; - /* public */ const M_EVA = 'application/x-eva'; - /* public */ const M_EVY = 'application/x-envoy'; - /* public */ const M_EXE = 'application/x-msdownload'; - /* public */ const M_EXI = 'application/exi'; - /* public */ const M_EXT = 'application/vnd.novadigm.ext'; - /* public */ const M_EZ = 'application/andrew-inset'; - /* public */ const M_EZ2 = 'application/vnd.ezpix-album'; - /* public */ const M_EZ3 = 'application/vnd.ezpix-package'; - /* public */ const M_F = 'text/x-fortran'; - /* public */ const M_F4V = 'video/x-f4v'; - /* public */ const M_F77 = 'text/x-fortran'; - /* public */ const M_F90 = 'text/x-fortran'; - /* public */ const M_FBS = 'image/vnd.fastbidsheet'; - /* public */ const M_FCDT = 'application/vnd.adobe.formscentral.fcdt'; - /* public */ const M_FCS = 'application/vnd.isac.fcs'; - /* public */ const M_FDF = 'application/vnd.fdf'; + /* public */ const M_ECMA = 'application/ecmascript'; + /* public */ const M_EDM = 'application/vnd.novadigm.edm'; + /* public */ const M_EDX = 'application/vnd.novadigm.edx'; + /* public */ const M_EFIF = 'application/vnd.picsel'; + /* public */ const M_EI6 = 'application/vnd.pg.osasli'; + /* public */ const M_ELC = 'application/octet-stream'; + /* public */ const M_EMF = 'application/x-msmetafile'; + /* public */ const M_EML = 'message/rfc822'; + /* public */ const M_EMMA = 'application/emma+xml'; + /* public */ const M_EMZ = 'application/x-msmetafile'; + /* public */ const M_EOL = 'audio/vnd.digital-winds'; + /* public */ const M_EOT = 'application/vnd.ms-fontobject'; + /* public */ const M_EPS = 'application/postscript'; + /* public */ const M_EPUB = 'application/epub+zip'; + /* public */ const M_ES3 = 'application/vnd.eszigno3+xml'; + /* public */ const M_ESA = 'application/vnd.osgi.subsystem'; + /* public */ const M_ESF = 'application/vnd.epson.esf'; + /* public */ const M_ET3 = 'application/vnd.eszigno3+xml'; + /* public */ const M_ETX = 'text/x-setext'; + /* public */ const M_EVA = 'application/x-eva'; + /* public */ const M_EVY = 'application/x-envoy'; + /* public */ const M_EXE = 'application/x-msdownload'; + /* public */ const M_EXI = 'application/exi'; + /* public */ const M_EXT = 'application/vnd.novadigm.ext'; + /* public */ const M_EZ = 'application/andrew-inset'; + /* public */ const M_EZ2 = 'application/vnd.ezpix-album'; + /* public */ const M_EZ3 = 'application/vnd.ezpix-package'; + /* public */ const M_F = 'text/x-fortran'; + /* public */ const M_F4V = 'video/x-f4v'; + /* public */ const M_F77 = 'text/x-fortran'; + /* public */ const M_F90 = 'text/x-fortran'; + /* public */ const M_FBS = 'image/vnd.fastbidsheet'; + /* public */ const M_FCDT = 'application/vnd.adobe.formscentral.fcdt'; + /* public */ const M_FCS = 'application/vnd.isac.fcs'; + /* public */ const M_FDF = 'application/vnd.fdf'; /* public */ const M_FE_LAUNCH = 'application/vnd.denovo.fcselayout-link'; - /* public */ const M_FG5 = 'application/vnd.fujitsu.oasysgp'; - /* public */ const M_FGD = 'application/x-director'; - /* public */ const M_FH = 'image/x-freehand'; - /* public */ const M_FH4 = 'image/x-freehand'; - /* public */ const M_FH5 = 'image/x-freehand'; - /* public */ const M_FH7 = 'image/x-freehand'; - /* public */ const M_FHC = 'image/x-freehand'; - /* public */ const M_FIG = 'application/x-xfig'; - /* public */ const M_FLAC = 'audio/x-flac'; - /* public */ const M_FLI = 'video/x-fli'; - /* public */ const M_FLO = 'application/vnd.micrografx.flo'; - /* public */ const M_FLV = 'video/x-flv'; - /* public */ const M_FLW = 'application/vnd.kde.kivio'; - /* public */ const M_FLX = 'text/vnd.fmi.flexstor'; - /* public */ const M_FLY = 'text/vnd.fly'; - /* public */ const M_FM = 'application/vnd.framemaker'; - /* public */ const M_FNC = 'application/vnd.frogans.fnc'; - /* public */ const M_FOR = 'text/x-fortran'; - /* public */ const M_FPX = 'image/vnd.fpx'; - /* public */ const M_FRAME = 'application/vnd.framemaker'; - /* public */ const M_FSC = 'application/vnd.fsc.weblaunch'; - /* public */ const M_FST = 'image/vnd.fst'; - /* public */ const M_FTC = 'application/vnd.fluxtime.clip'; - /* public */ const M_FTI = 'application/vnd.anser-web-funds-transfer-initiation'; - /* public */ const M_FVT = 'video/vnd.fvt'; - /* public */ const M_FXP = 'application/vnd.adobe.fxp'; - /* public */ const M_FXPL = 'application/vnd.adobe.fxp'; - /* public */ const M_FZS = 'application/vnd.fuzzysheet'; - /* public */ const M_G2W = 'application/vnd.geoplan'; - /* public */ const M_G3 = 'image/g3fax'; - /* public */ const M_G3W = 'application/vnd.geospace'; - /* public */ const M_GAC = 'application/vnd.groove-account'; - /* public */ const M_GAM = 'application/x-tads'; - /* public */ const M_GBR = 'application/rpki-ghostbusters'; - /* public */ const M_GCA = 'application/x-gca-compressed'; - /* public */ const M_GDL = 'model/vnd.gdl'; - /* public */ const M_GEO = 'application/vnd.dynageo'; - /* public */ const M_GEX = 'application/vnd.geometry-explorer'; - /* public */ const M_GGB = 'application/vnd.geogebra.file'; - /* public */ const M_GGT = 'application/vnd.geogebra.tool'; - /* public */ const M_GHF = 'application/vnd.groove-help'; - /* public */ const M_GIF = 'image/gif'; - /* public */ const M_GIM = 'application/vnd.groove-identity-message'; - /* public */ const M_GML = 'application/gml+xml'; - /* public */ const M_GMX = 'application/vnd.gmx'; - /* public */ const M_GNUMERIC = 'application/x-gnumeric'; - /* public */ const M_GPH = 'application/vnd.flographit'; - /* public */ const M_GPX = 'application/gpx+xml'; - /* public */ const M_GQF = 'application/vnd.grafeq'; - /* public */ const M_GQS = 'application/vnd.grafeq'; - /* public */ const M_GRAM = 'application/srgs'; - /* public */ const M_GRAMPS = 'application/x-gramps-xml'; - /* public */ const M_GRE = 'application/vnd.geometry-explorer'; - /* public */ const M_GRV = 'application/vnd.groove-injector'; - /* public */ const M_GRXML = 'application/srgs+xml'; - /* public */ const M_GSF = 'application/x-font-ghostscript'; - /* public */ const M_GTAR = 'application/x-gtar'; - /* public */ const M_GTM = 'application/vnd.groove-tool-message'; - /* public */ const M_GTW = 'model/vnd.gtw'; - /* public */ const M_GV = 'text/vnd.graphviz'; - /* public */ const M_GXF = 'application/gxf'; - /* public */ const M_GXT = 'application/vnd.geonext'; - /* public */ const M_GZ = 'application/x-gzip'; - /* public */ const M_H = 'text/x-c'; - /* public */ const M_H261 = 'video/h261'; - /* public */ const M_H263 = 'video/h263'; - /* public */ const M_H264 = 'video/h264'; - /* public */ const M_HAL = 'application/vnd.hal+xml'; - /* public */ const M_HBCI = 'application/vnd.hbci'; - /* public */ const M_HDF = 'application/x-hdf'; - /* public */ const M_HH = 'text/x-c'; - /* public */ const M_HLP = 'application/winhlp'; - /* public */ const M_HPGL = 'application/vnd.hp-hpgl'; - /* public */ const M_HPID = 'application/vnd.hp-hpid'; - /* public */ const M_HPS = 'application/vnd.hp-hps'; - /* public */ const M_HQX = 'application/mac-binhex40'; - /* public */ const M_HTKE = 'application/vnd.kenameaapp'; - /* public */ const M_HTM = 'text/html'; - /* public */ const M_HTML = 'text/html'; - /* public */ const M_HVD = 'application/vnd.yamaha.hv-dic'; - /* public */ const M_HVP = 'application/vnd.yamaha.hv-voice'; - /* public */ const M_HVS = 'application/vnd.yamaha.hv-script'; - /* public */ const M_I2G = 'application/vnd.intergeo'; - /* public */ const M_ICC = 'application/vnd.iccprofile'; - /* public */ const M_ICE = 'x-conference/x-cooltalk'; - /* public */ const M_ICM = 'application/vnd.iccprofile'; - /* public */ const M_ICO = 'image/x-icon'; - /* public */ const M_ICS = 'text/calendar'; - /* public */ const M_IEF = 'image/ief'; - /* public */ const M_IFB = 'text/calendar'; - /* public */ const M_IFM = 'application/vnd.shana.informed.formdata'; - /* public */ const M_IGES = 'model/iges'; - /* public */ const M_IGL = 'application/vnd.igloader'; - /* public */ const M_IGM = 'application/vnd.insors.igm'; - /* public */ const M_IGS = 'model/iges'; - /* public */ const M_IGX = 'application/vnd.micrografx.igx'; - /* public */ const M_IIF = 'application/vnd.shana.informed.interchange'; - /* public */ const M_IMP = 'application/vnd.accpac.simply.imp'; - /* public */ const M_IMS = 'application/vnd.ms-ims'; - /* public */ const M_IN = 'text/plain'; - /* public */ const M_INK = 'application/inkml+xml'; - /* public */ const M_INKML = 'application/inkml+xml'; - /* public */ const M_INSTALL = 'application/x-install-instructions'; - /* public */ const M_IOTA = 'application/vnd.astraea-software.iota'; - /* public */ const M_IPFIX = 'application/ipfix'; - /* public */ const M_IPK = 'application/vnd.shana.informed.package'; - /* public */ const M_IRM = 'application/vnd.ibm.rights-management'; - /* public */ const M_IRP = 'application/vnd.irepository.package+xml'; - /* public */ const M_ISO = 'application/x-iso9660-image'; - /* public */ const M_ITP = 'application/vnd.shana.informed.formtemplate'; - /* public */ const M_IVP = 'application/vnd.immervision-ivp'; - /* public */ const M_IVU = 'application/vnd.immervision-ivu'; - /* public */ const M_JAD = 'text/vnd.sun.j2me.app-descriptor'; - /* public */ const M_JAM = 'application/vnd.jam'; - /* public */ const M_JAR = 'application/java-archive'; - /* public */ const M_JAVA = 'text/x-java-source'; - /* public */ const M_JISP = 'application/vnd.jisp'; - /* public */ const M_JLT = 'application/vnd.hp-jlyt'; - /* public */ const M_JNLP = 'application/x-java-jnlp-file'; - /* public */ const M_JODA = 'application/vnd.joost.joda-archive'; - /* public */ const M_JPE = 'image/jpeg'; - /* public */ const M_JPEG = 'image/jpeg'; - /* public */ const M_JPG = 'image/jpeg'; - /* public */ const M_JPGM = 'video/jpm'; - /* public */ const M_JPGV = 'video/jpeg'; - /* public */ const M_JPM = 'video/jpm'; - /* public */ const M_JS = 'application/javascript'; - /* public */ const M_JSON = 'application/json'; - /* public */ const M_JSONML = 'application/jsonml+json'; - /* public */ const M_KAR = 'audio/midi'; - /* public */ const M_KARBON = 'application/vnd.kde.karbon'; - /* public */ const M_KFO = 'application/vnd.kde.kformula'; - /* public */ const M_KIA = 'application/vnd.kidspiration'; - /* public */ const M_KML = 'application/vnd.google-earth.kml+xml'; - /* public */ const M_KMZ = 'application/vnd.google-earth.kmz'; - /* public */ const M_KNE = 'application/vnd.kinar'; - /* public */ const M_KNP = 'application/vnd.kinar'; - /* public */ const M_KON = 'application/vnd.kde.kontour'; - /* public */ const M_KPR = 'application/vnd.kde.kpresenter'; - /* public */ const M_KPT = 'application/vnd.kde.kpresenter'; - /* public */ const M_KPXX = 'application/vnd.ds-keypoint'; - /* public */ const M_KSP = 'application/vnd.kde.kspread'; - /* public */ const M_KTR = 'application/vnd.kahootz'; - /* public */ const M_KTX = 'image/ktx'; - /* public */ const M_KTZ = 'application/vnd.kahootz'; - /* public */ const M_KWD = 'application/vnd.kde.kword'; - /* public */ const M_KWT = 'application/vnd.kde.kword'; - /* public */ const M_LASXML = 'application/vnd.las.las+xml'; - /* public */ const M_LATEX = 'application/x-latex'; - /* public */ const M_LBD = 'application/vnd.llamagraphics.life-balance.desktop'; - /* public */ const M_LBE = 'application/vnd.llamagraphics.life-balance.exchange+xml'; - /* public */ const M_LES = 'application/vnd.hhe.lesson-player'; - /* public */ const M_LHA = 'application/x-lzh-compressed'; - /* public */ const M_LINK66 = 'application/vnd.route66.link66+xml'; - /* public */ const M_LIST = 'text/plain'; - /* public */ const M_LIST3820 = 'application/vnd.ibm.modcap'; - /* public */ const M_LISTAFP = 'application/vnd.ibm.modcap'; - /* public */ const M_LNK = 'application/x-ms-shortcut'; - /* public */ const M_LOG = 'text/plain'; - /* public */ const M_LOSTXML = 'application/lost+xml'; - /* public */ const M_LRF = 'application/octet-stream'; - /* public */ const M_LRM = 'application/vnd.ms-lrm'; - /* public */ const M_LTF = 'application/vnd.frogans.ltf'; - /* public */ const M_LVP = 'audio/vnd.lucent.voice'; - /* public */ const M_LWP = 'application/vnd.lotus-wordpro'; - /* public */ const M_LZH = 'application/x-lzh-compressed'; - /* public */ const M_M13 = 'application/x-msmediaview'; - /* public */ const M_M14 = 'application/x-msmediaview'; - /* public */ const M_M1V = 'video/mpeg'; - /* public */ const M_M21 = 'application/mp21'; - /* public */ const M_M2A = 'audio/mpeg'; - /* public */ const M_M2V = 'video/mpeg'; - /* public */ const M_M3A = 'audio/mpeg'; - /* public */ const M_M3U = 'audio/x-mpegurl'; - /* public */ const M_M3U8 = 'application/vnd.apple.mpegurl'; - /* public */ const M_M4A = 'audio/mp4'; - /* public */ const M_M4U = 'video/vnd.mpegurl'; - /* public */ const M_M4V = 'video/x-m4v'; - /* public */ const M_MA = 'application/mathematica'; - /* public */ const M_MADS = 'application/mads+xml'; - /* public */ const M_MAG = 'application/vnd.ecowin.chart'; - /* public */ const M_MAKER = 'application/vnd.framemaker'; - /* public */ const M_MAN = 'text/troff'; - /* public */ const M_MAR = 'application/octet-stream'; - /* public */ const M_MATHML = 'application/mathml+xml'; - /* public */ const M_MB = 'application/mathematica'; - /* public */ const M_MBK = 'application/vnd.mobius.mbk'; - /* public */ const M_MBOX = 'application/mbox'; - /* public */ const M_MC1 = 'application/vnd.medcalcdata'; - /* public */ const M_MCD = 'application/vnd.mcd'; - /* public */ const M_MCURL = 'text/vnd.curl.mcurl'; - /* public */ const M_MDB = 'application/x-msaccess'; - /* public */ const M_MDI = 'image/vnd.ms-modi'; - /* public */ const M_ME = 'text/troff'; - /* public */ const M_MESH = 'model/mesh'; - /* public */ const M_META4 = 'application/metalink4+xml'; - /* public */ const M_METALINK = 'application/metalink+xml'; - /* public */ const M_METS = 'application/mets+xml'; - /* public */ const M_MFM = 'application/vnd.mfmp'; - /* public */ const M_MFT = 'application/rpki-manifest'; - /* public */ const M_MGP = 'application/vnd.osgeo.mapguide.package'; - /* public */ const M_MGZ = 'application/vnd.proteus.magazine'; - /* public */ const M_MID = 'audio/midi'; - /* public */ const M_MIDI = 'audio/midi'; - /* public */ const M_MIE = 'application/x-mie'; - /* public */ const M_MIF = 'application/vnd.mif'; - /* public */ const M_MIME = 'message/rfc822'; - /* public */ const M_MJ2 = 'video/mj2'; - /* public */ const M_MJP2 = 'video/mj2'; - /* public */ const M_MK3D = 'video/x-matroska'; - /* public */ const M_MKA = 'audio/x-matroska'; - /* public */ const M_MKS = 'video/x-matroska'; - /* public */ const M_MKV = 'video/x-matroska'; - /* public */ const M_MLP = 'application/vnd.dolby.mlp'; - /* public */ const M_MMD = 'application/vnd.chipnuts.karaoke-mmd'; - /* public */ const M_MMF = 'application/vnd.smaf'; - /* public */ const M_MMR = 'image/vnd.fujixerox.edmics-mmr'; - /* public */ const M_MNG = 'video/x-mng'; - /* public */ const M_MNY = 'application/x-msmoney'; - /* public */ const M_MOBI = 'application/x-mobipocket-ebook'; - /* public */ const M_MODS = 'application/mods+xml'; - /* public */ const M_MOV = 'video/quicktime'; - /* public */ const M_MOVIE = 'video/x-sgi-movie'; - /* public */ const M_MP2 = 'audio/mpeg'; - /* public */ const M_MP21 = 'application/mp21'; - /* public */ const M_MP2A = 'audio/mpeg'; - /* public */ const M_MP3 = 'audio/mpeg'; - /* public */ const M_MP4 = 'video/mp4'; - /* public */ const M_MP4A = 'audio/mp4'; - /* public */ const M_MP4S = 'application/mp4'; - /* public */ const M_MP4V = 'video/mp4'; - /* public */ const M_MPC = 'application/vnd.mophun.certificate'; - /* public */ const M_MPE = 'video/mpeg'; - /* public */ const M_MPEG = 'video/mpeg'; - /* public */ const M_MPG = 'video/mpeg'; - /* public */ const M_MPG4 = 'video/mp4'; - /* public */ const M_MPGA = 'audio/mpeg'; - /* public */ const M_MPKG = 'application/vnd.apple.installer+xml'; - /* public */ const M_MPM = 'application/vnd.blueice.multipass'; - /* public */ const M_MPN = 'application/vnd.mophun.application'; - /* public */ const M_MPP = 'application/vnd.ms-project'; - /* public */ const M_MPT = 'application/vnd.ms-project'; - /* public */ const M_MPY = 'application/vnd.ibm.minipay'; - /* public */ const M_MQY = 'application/vnd.mobius.mqy'; - /* public */ const M_MRC = 'application/marc'; - /* public */ const M_MRCX = 'application/marcxml+xml'; - /* public */ const M_MS = 'text/troff'; - /* public */ const M_MSCML = 'application/mediaservercontrol+xml'; - /* public */ const M_MSEED = 'application/vnd.fdsn.mseed'; - /* public */ const M_MSEQ = 'application/vnd.mseq'; - /* public */ const M_MSF = 'application/vnd.epson.msf'; - /* public */ const M_MSH = 'model/mesh'; - /* public */ const M_MSI = 'application/x-msdownload'; - /* public */ const M_MSL = 'application/vnd.mobius.msl'; - /* public */ const M_MSTY = 'application/vnd.muvee.style'; - /* public */ const M_MTS = 'model/vnd.mts'; - /* public */ const M_MUS = 'application/vnd.musician'; - /* public */ const M_MUSICXML = 'application/vnd.recordare.musicxml+xml'; - /* public */ const M_MVB = 'application/x-msmediaview'; - /* public */ const M_MWF = 'application/vnd.mfer'; - /* public */ const M_MXF = 'application/mxf'; - /* public */ const M_MXL = 'application/vnd.recordare.musicxml'; - /* public */ const M_MXML = 'application/xv+xml'; - /* public */ const M_MXS = 'application/vnd.triscape.mxs'; - /* public */ const M_MXU = 'video/vnd.mpegurl'; - /* public */ const M_N_GAGE = 'application/vnd.nokia.n-gage.symbian.install'; - /* public */ const M_N3 = 'text/n3'; - /* public */ const M_NB = 'application/mathematica'; - /* public */ const M_NBP = 'application/vnd.wolfram.player'; - /* public */ const M_NC = 'application/x-netcdf'; - /* public */ const M_NCX = 'application/x-dtbncx+xml'; - /* public */ const M_NFO = 'text/x-nfo'; - /* public */ const M_NGDAT = 'application/vnd.nokia.n-gage.data'; - /* public */ const M_NITF = 'application/vnd.nitf'; - /* public */ const M_NLU = 'application/vnd.neurolanguage.nlu'; - /* public */ const M_NML = 'application/vnd.enliven'; - /* public */ const M_NND = 'application/vnd.noblenet-directory'; - /* public */ const M_NNS = 'application/vnd.noblenet-sealer'; - /* public */ const M_NNW = 'application/vnd.noblenet-web'; - /* public */ const M_NPX = 'image/vnd.net-fpx'; - /* public */ const M_NSC = 'application/x-conference'; - /* public */ const M_NSF = 'application/vnd.lotus-notes'; - /* public */ const M_NTF = 'application/vnd.nitf'; - /* public */ const M_NZB = 'application/x-nzb'; - /* public */ const M_OA2 = 'application/vnd.fujitsu.oasys2'; - /* public */ const M_OA3 = 'application/vnd.fujitsu.oasys3'; - /* public */ const M_OAS = 'application/vnd.fujitsu.oasys'; - /* public */ const M_OBD = 'application/x-msbinder'; - /* public */ const M_OBJ = 'application/x-tgif'; - /* public */ const M_ODA = 'application/oda'; - /* public */ const M_ODB = 'application/vnd.oasis.opendocument.database'; - /* public */ const M_ODC = 'application/vnd.oasis.opendocument.chart'; - /* public */ const M_ODF = 'application/vnd.oasis.opendocument.formula'; - /* public */ const M_ODFT = 'application/vnd.oasis.opendocument.formula-template'; - /* public */ const M_ODG = 'application/vnd.oasis.opendocument.graphics'; - /* public */ const M_ODI = 'application/vnd.oasis.opendocument.image'; - /* public */ const M_ODM = 'application/vnd.oasis.opendocument.text-master'; - /* public */ const M_ODP = 'application/vnd.oasis.opendocument.presentation'; - /* public */ const M_ODS = 'application/vnd.oasis.opendocument.spreadsheet'; - /* public */ const M_ODT = 'application/vnd.oasis.opendocument.text'; - /* public */ const M_OGA = 'audio/ogg'; - /* public */ const M_OGG = 'audio/ogg'; - /* public */ const M_OGV = 'video/ogg'; - /* public */ const M_OGX = 'application/ogg'; - /* public */ const M_OMDOC = 'application/omdoc+xml'; - /* public */ const M_ONEPKG = 'application/onenote'; - /* public */ const M_ONETMP = 'application/onenote'; - /* public */ const M_ONETOC = 'application/onenote'; - /* public */ const M_ONETOC2 = 'application/onenote'; - /* public */ const M_OPF = 'application/oebps-package+xml'; - /* public */ const M_OPML = 'text/x-opml'; - /* public */ const M_OPRC = 'application/vnd.palm'; - /* public */ const M_ORG = 'application/vnd.lotus-organizer'; - /* public */ const M_OSF = 'application/vnd.yamaha.openscoreformat'; - /* public */ const M_OSFPVG = 'application/vnd.yamaha.openscoreformat.osfpvg+xml'; - /* public */ const M_OTC = 'application/vnd.oasis.opendocument.chart-template'; - /* public */ const M_OTF = 'application/x-font-otf'; - /* public */ const M_OTG = 'application/vnd.oasis.opendocument.graphics-template'; - /* public */ const M_OTH = 'application/vnd.oasis.opendocument.text-web'; - /* public */ const M_OTI = 'application/vnd.oasis.opendocument.image-template'; - /* public */ const M_OTP = 'application/vnd.oasis.opendocument.presentation-template'; - /* public */ const M_OTS = 'application/vnd.oasis.opendocument.spreadsheet-template'; - /* public */ const M_OTT = 'application/vnd.oasis.opendocument.text-template'; - /* public */ const M_OXPS = 'application/oxps'; - /* public */ const M_OXT = 'application/vnd.openofficeorg.extension'; - /* public */ const M_P = 'text/x-pascal'; - /* public */ const M_P10 = 'application/pkcs10'; - /* public */ const M_P12 = 'application/x-pkcs12'; - /* public */ const M_P7B = 'application/x-pkcs7-certificates'; - /* public */ const M_P7C = 'application/pkcs7-mime'; - /* public */ const M_P7M = 'application/pkcs7-mime'; - /* public */ const M_P7R = 'application/x-pkcs7-certreqresp'; - /* public */ const M_P7S = 'application/pkcs7-signature'; - /* public */ const M_P8 = 'application/pkcs8'; - /* public */ const M_PAS = 'text/x-pascal'; - /* public */ const M_PAW = 'application/vnd.pawaafile'; - /* public */ const M_PBD = 'application/vnd.powerbuilder6'; - /* public */ const M_PBM = 'image/x-portable-bitmap'; - /* public */ const M_PCAP = 'application/vnd.tcpdump.pcap'; - /* public */ const M_PCF = 'application/x-font-pcf'; - /* public */ const M_PCL = 'application/vnd.hp-pcl'; - /* public */ const M_PCLXL = 'application/vnd.hp-pclxl'; - /* public */ const M_PCT = 'image/x-pict'; - /* public */ const M_PCURL = 'application/vnd.curl.pcurl'; - /* public */ const M_PCX = 'image/x-pcx'; - /* public */ const M_PDB = 'application/vnd.palm'; - /* public */ const M_PDF = 'application/pdf'; - /* public */ const M_PFA = 'application/x-font-type1'; - /* public */ const M_PFB = 'application/x-font-type1'; - /* public */ const M_PFM = 'application/x-font-type1'; - /* public */ const M_PFR = 'application/font-tdpfr'; - /* public */ const M_PFX = 'application/x-pkcs12'; - /* public */ const M_PGM = 'image/x-portable-graymap'; - /* public */ const M_PGN = 'application/x-chess-pgn'; - /* public */ const M_PGP = 'application/pgp-encrypted'; - /* public */ const M_PHP = 'application/x-php'; - /* public */ const M_PHP3 = 'application/x-php'; - /* public */ const M_PHP4 = 'application/x-php'; - /* public */ const M_PHP5 = 'application/x-php'; - /* public */ const M_PIC = 'image/x-pict'; - /* public */ const M_PKG = 'application/octet-stream'; - /* public */ const M_PKI = 'application/pkixcmp'; - /* public */ const M_PKIPATH = 'application/pkix-pkipath'; - /* public */ const M_PLB = 'application/vnd.3gpp.pic-bw-large'; - /* public */ const M_PLC = 'application/vnd.mobius.plc'; - /* public */ const M_PLF = 'application/vnd.pocketlearn'; - /* public */ const M_PLS = 'application/pls+xml'; - /* public */ const M_PML = 'application/vnd.ctc-posml'; - /* public */ const M_PNG = 'image/png'; - /* public */ const M_PNM = 'image/x-portable-anymap'; - /* public */ const M_PORTPKG = 'application/vnd.macports.portpkg'; - /* public */ const M_POT = 'application/vnd.ms-powerpoint'; - /* public */ const M_POTM = 'application/vnd.ms-powerpoint.template.macroenabled.12'; - /* public */ const M_POTX = 'application/vnd.openxmlformats-officedocument.presentationml.template'; - /* public */ const M_PPAM = 'application/vnd.ms-powerpoint.addin.macroenabled.12'; - /* public */ const M_PPD = 'application/vnd.cups-ppd'; - /* public */ const M_PPM = 'image/x-portable-pixmap'; - /* public */ const M_PPS = 'application/vnd.ms-powerpoint'; - /* public */ const M_PPSM = 'application/vnd.ms-powerpoint.slideshow.macroenabled.12'; - /* public */ const M_PPSX = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; - /* public */ const M_PPT = 'application/vnd.ms-powerpoint'; - /* public */ const M_PPTM = 'application/vnd.ms-powerpoint.presentation.macroenabled.12'; - /* public */ const M_PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; - /* public */ const M_PQA = 'application/vnd.palm'; - /* public */ const M_PRC = 'application/x-mobipocket-ebook'; - /* public */ const M_PRE = 'application/vnd.lotus-freelance'; - /* public */ const M_PRF = 'application/pics-rules'; - /* public */ const M_PS = 'application/postscript'; - /* public */ const M_PSB = 'application/vnd.3gpp.pic-bw-small'; - /* public */ const M_PSD = 'image/vnd.adobe.photoshop'; - /* public */ const M_PSF = 'application/x-font-linux-psf'; - /* public */ const M_PSKCXML = 'application/pskc+xml'; - /* public */ const M_PTID = 'application/vnd.pvi.ptid1'; - /* public */ const M_PUB = 'application/x-mspublisher'; - /* public */ const M_PVB = 'application/vnd.3gpp.pic-bw-var'; - /* public */ const M_PWN = 'application/vnd.3m.post-it-notes'; - /* public */ const M_PYA = 'audio/vnd.ms-playready.media.pya'; - /* public */ const M_PYV = 'video/vnd.ms-playready.media.pyv'; - /* public */ const M_QAM = 'application/vnd.epson.quickanime'; - /* public */ const M_QBO = 'application/vnd.intu.qbo'; - /* public */ const M_QFX = 'application/vnd.intu.qfx'; - /* public */ const M_QPS = 'application/vnd.publishare-delta-tree'; - /* public */ const M_QT = 'video/quicktime'; - /* public */ const M_QWD = 'application/vnd.quark.quarkxpress'; - /* public */ const M_QWT = 'application/vnd.quark.quarkxpress'; - /* public */ const M_QXB = 'application/vnd.quark.quarkxpress'; - /* public */ const M_QXD = 'application/vnd.quark.quarkxpress'; - /* public */ const M_QXL = 'application/vnd.quark.quarkxpress'; - /* public */ const M_QXT = 'application/vnd.quark.quarkxpress'; - /* public */ const M_RA = 'audio/x-pn-realaudio'; - /* public */ const M_RAM = 'audio/x-pn-realaudio'; - /* public */ const M_RAR = 'application/x-rar-compressed'; - /* public */ const M_RAS = 'image/x-cmu-raster'; + /* public */ const M_FG5 = 'application/vnd.fujitsu.oasysgp'; + /* public */ const M_FGD = 'application/x-director'; + /* public */ const M_FH = 'image/x-freehand'; + /* public */ const M_FH4 = 'image/x-freehand'; + /* public */ const M_FH5 = 'image/x-freehand'; + /* public */ const M_FH7 = 'image/x-freehand'; + /* public */ const M_FHC = 'image/x-freehand'; + /* public */ const M_FIG = 'application/x-xfig'; + /* public */ const M_FLAC = 'audio/x-flac'; + /* public */ const M_FLI = 'video/x-fli'; + /* public */ const M_FLO = 'application/vnd.micrografx.flo'; + /* public */ const M_FLV = 'video/x-flv'; + /* public */ const M_FLW = 'application/vnd.kde.kivio'; + /* public */ const M_FLX = 'text/vnd.fmi.flexstor'; + /* public */ const M_FLY = 'text/vnd.fly'; + /* public */ const M_FM = 'application/vnd.framemaker'; + /* public */ const M_FNC = 'application/vnd.frogans.fnc'; + /* public */ const M_FOR = 'text/x-fortran'; + /* public */ const M_FPX = 'image/vnd.fpx'; + /* public */ const M_FRAME = 'application/vnd.framemaker'; + /* public */ const M_FSC = 'application/vnd.fsc.weblaunch'; + /* public */ const M_FST = 'image/vnd.fst'; + /* public */ const M_FTC = 'application/vnd.fluxtime.clip'; + /* public */ const M_FTI = 'application/vnd.anser-web-funds-transfer-initiation'; + /* public */ const M_FVT = 'video/vnd.fvt'; + /* public */ const M_FXP = 'application/vnd.adobe.fxp'; + /* public */ const M_FXPL = 'application/vnd.adobe.fxp'; + /* public */ const M_FZS = 'application/vnd.fuzzysheet'; + /* public */ const M_G2W = 'application/vnd.geoplan'; + /* public */ const M_G3 = 'image/g3fax'; + /* public */ const M_G3W = 'application/vnd.geospace'; + /* public */ const M_GAC = 'application/vnd.groove-account'; + /* public */ const M_GAM = 'application/x-tads'; + /* public */ const M_GBR = 'application/rpki-ghostbusters'; + /* public */ const M_GCA = 'application/x-gca-compressed'; + /* public */ const M_GDL = 'model/vnd.gdl'; + /* public */ const M_GEO = 'application/vnd.dynageo'; + /* public */ const M_GEX = 'application/vnd.geometry-explorer'; + /* public */ const M_GGB = 'application/vnd.geogebra.file'; + /* public */ const M_GGT = 'application/vnd.geogebra.tool'; + /* public */ const M_GHF = 'application/vnd.groove-help'; + /* public */ const M_GIF = 'image/gif'; + /* public */ const M_GIM = 'application/vnd.groove-identity-message'; + /* public */ const M_GML = 'application/gml+xml'; + /* public */ const M_GMX = 'application/vnd.gmx'; + /* public */ const M_GNUMERIC = 'application/x-gnumeric'; + /* public */ const M_GPH = 'application/vnd.flographit'; + /* public */ const M_GPX = 'application/gpx+xml'; + /* public */ const M_GQF = 'application/vnd.grafeq'; + /* public */ const M_GQS = 'application/vnd.grafeq'; + /* public */ const M_GRAM = 'application/srgs'; + /* public */ const M_GRAMPS = 'application/x-gramps-xml'; + /* public */ const M_GRE = 'application/vnd.geometry-explorer'; + /* public */ const M_GRV = 'application/vnd.groove-injector'; + /* public */ const M_GRXML = 'application/srgs+xml'; + /* public */ const M_GSF = 'application/x-font-ghostscript'; + /* public */ const M_GTAR = 'application/x-gtar'; + /* public */ const M_GTM = 'application/vnd.groove-tool-message'; + /* public */ const M_GTW = 'model/vnd.gtw'; + /* public */ const M_GV = 'text/vnd.graphviz'; + /* public */ const M_GXF = 'application/gxf'; + /* public */ const M_GXT = 'application/vnd.geonext'; + /* public */ const M_GZ = 'application/x-gzip'; + /* public */ const M_H = 'text/x-c'; + /* public */ const M_H261 = 'video/h261'; + /* public */ const M_H263 = 'video/h263'; + /* public */ const M_H264 = 'video/h264'; + /* public */ const M_HAL = 'application/vnd.hal+xml'; + /* public */ const M_HBCI = 'application/vnd.hbci'; + /* public */ const M_HDF = 'application/x-hdf'; + /* public */ const M_HH = 'text/x-c'; + /* public */ const M_HLP = 'application/winhlp'; + /* public */ const M_HPGL = 'application/vnd.hp-hpgl'; + /* public */ const M_HPID = 'application/vnd.hp-hpid'; + /* public */ const M_HPS = 'application/vnd.hp-hps'; + /* public */ const M_HQX = 'application/mac-binhex40'; + /* public */ const M_HTKE = 'application/vnd.kenameaapp'; + /* public */ const M_HTM = 'text/html'; + /* public */ const M_HTML = 'text/html'; + /* public */ const M_HVD = 'application/vnd.yamaha.hv-dic'; + /* public */ const M_HVP = 'application/vnd.yamaha.hv-voice'; + /* public */ const M_HVS = 'application/vnd.yamaha.hv-script'; + /* public */ const M_I2G = 'application/vnd.intergeo'; + /* public */ const M_ICC = 'application/vnd.iccprofile'; + /* public */ const M_ICE = 'x-conference/x-cooltalk'; + /* public */ const M_ICM = 'application/vnd.iccprofile'; + /* public */ const M_ICO = 'image/x-icon'; + /* public */ const M_ICS = 'text/calendar'; + /* public */ const M_IEF = 'image/ief'; + /* public */ const M_IFB = 'text/calendar'; + /* public */ const M_IFM = 'application/vnd.shana.informed.formdata'; + /* public */ const M_IGES = 'model/iges'; + /* public */ const M_IGL = 'application/vnd.igloader'; + /* public */ const M_IGM = 'application/vnd.insors.igm'; + /* public */ const M_IGS = 'model/iges'; + /* public */ const M_IGX = 'application/vnd.micrografx.igx'; + /* public */ const M_IIF = 'application/vnd.shana.informed.interchange'; + /* public */ const M_IMP = 'application/vnd.accpac.simply.imp'; + /* public */ const M_IMS = 'application/vnd.ms-ims'; + /* public */ const M_IN = 'text/plain'; + /* public */ const M_INK = 'application/inkml+xml'; + /* public */ const M_INKML = 'application/inkml+xml'; + /* public */ const M_INSTALL = 'application/x-install-instructions'; + /* public */ const M_IOTA = 'application/vnd.astraea-software.iota'; + /* public */ const M_IPFIX = 'application/ipfix'; + /* public */ const M_IPK = 'application/vnd.shana.informed.package'; + /* public */ const M_IRM = 'application/vnd.ibm.rights-management'; + /* public */ const M_IRP = 'application/vnd.irepository.package+xml'; + /* public */ const M_ISO = 'application/x-iso9660-image'; + /* public */ const M_ITP = 'application/vnd.shana.informed.formtemplate'; + /* public */ const M_IVP = 'application/vnd.immervision-ivp'; + /* public */ const M_IVU = 'application/vnd.immervision-ivu'; + /* public */ const M_JAD = 'text/vnd.sun.j2me.app-descriptor'; + /* public */ const M_JAM = 'application/vnd.jam'; + /* public */ const M_JAR = 'application/java-archive'; + /* public */ const M_JAVA = 'text/x-java-source'; + /* public */ const M_JISP = 'application/vnd.jisp'; + /* public */ const M_JLT = 'application/vnd.hp-jlyt'; + /* public */ const M_JNLP = 'application/x-java-jnlp-file'; + /* public */ const M_JODA = 'application/vnd.joost.joda-archive'; + /* public */ const M_JPE = 'image/jpeg'; + /* public */ const M_JPEG = 'image/jpeg'; + /* public */ const M_JPG = 'image/jpeg'; + /* public */ const M_JPGM = 'video/jpm'; + /* public */ const M_JPGV = 'video/jpeg'; + /* public */ const M_JPM = 'video/jpm'; + /* public */ const M_JS = 'application/javascript'; + /* public */ const M_JSON = 'application/json'; + /* public */ const M_JSONML = 'application/jsonml+json'; + /* public */ const M_KAR = 'audio/midi'; + /* public */ const M_KARBON = 'application/vnd.kde.karbon'; + /* public */ const M_KFO = 'application/vnd.kde.kformula'; + /* public */ const M_KIA = 'application/vnd.kidspiration'; + /* public */ const M_KML = 'application/vnd.google-earth.kml+xml'; + /* public */ const M_KMZ = 'application/vnd.google-earth.kmz'; + /* public */ const M_KNE = 'application/vnd.kinar'; + /* public */ const M_KNP = 'application/vnd.kinar'; + /* public */ const M_KON = 'application/vnd.kde.kontour'; + /* public */ const M_KPR = 'application/vnd.kde.kpresenter'; + /* public */ const M_KPT = 'application/vnd.kde.kpresenter'; + /* public */ const M_KPXX = 'application/vnd.ds-keypoint'; + /* public */ const M_KSP = 'application/vnd.kde.kspread'; + /* public */ const M_KTR = 'application/vnd.kahootz'; + /* public */ const M_KTX = 'image/ktx'; + /* public */ const M_KTZ = 'application/vnd.kahootz'; + /* public */ const M_KWD = 'application/vnd.kde.kword'; + /* public */ const M_KWT = 'application/vnd.kde.kword'; + /* public */ const M_LASXML = 'application/vnd.las.las+xml'; + /* public */ const M_LATEX = 'application/x-latex'; + /* public */ const M_LBD = 'application/vnd.llamagraphics.life-balance.desktop'; + /* public */ const M_LBE = 'application/vnd.llamagraphics.life-balance.exchange+xml'; + /* public */ const M_LES = 'application/vnd.hhe.lesson-player'; + /* public */ const M_LHA = 'application/x-lzh-compressed'; + /* public */ const M_LINK66 = 'application/vnd.route66.link66+xml'; + /* public */ const M_LIST = 'text/plain'; + /* public */ const M_LIST3820 = 'application/vnd.ibm.modcap'; + /* public */ const M_LISTAFP = 'application/vnd.ibm.modcap'; + /* public */ const M_LNK = 'application/x-ms-shortcut'; + /* public */ const M_LOG = 'text/plain'; + /* public */ const M_LOSTXML = 'application/lost+xml'; + /* public */ const M_LRF = 'application/octet-stream'; + /* public */ const M_LRM = 'application/vnd.ms-lrm'; + /* public */ const M_LTF = 'application/vnd.frogans.ltf'; + /* public */ const M_LVP = 'audio/vnd.lucent.voice'; + /* public */ const M_LWP = 'application/vnd.lotus-wordpro'; + /* public */ const M_LZH = 'application/x-lzh-compressed'; + /* public */ const M_M13 = 'application/x-msmediaview'; + /* public */ const M_M14 = 'application/x-msmediaview'; + /* public */ const M_M1V = 'video/mpeg'; + /* public */ const M_M21 = 'application/mp21'; + /* public */ const M_M2A = 'audio/mpeg'; + /* public */ const M_M2V = 'video/mpeg'; + /* public */ const M_M3A = 'audio/mpeg'; + /* public */ const M_M3U = 'audio/x-mpegurl'; + /* public */ const M_M3U8 = 'application/vnd.apple.mpegurl'; + /* public */ const M_M4A = 'audio/mp4'; + /* public */ const M_M4U = 'video/vnd.mpegurl'; + /* public */ const M_M4V = 'video/x-m4v'; + /* public */ const M_MA = 'application/mathematica'; + /* public */ const M_MADS = 'application/mads+xml'; + /* public */ const M_MAG = 'application/vnd.ecowin.chart'; + /* public */ const M_MAKER = 'application/vnd.framemaker'; + /* public */ const M_MAN = 'text/troff'; + /* public */ const M_MAR = 'application/octet-stream'; + /* public */ const M_MATHML = 'application/mathml+xml'; + /* public */ const M_MB = 'application/mathematica'; + /* public */ const M_MBK = 'application/vnd.mobius.mbk'; + /* public */ const M_MBOX = 'application/mbox'; + /* public */ const M_MC1 = 'application/vnd.medcalcdata'; + /* public */ const M_MCD = 'application/vnd.mcd'; + /* public */ const M_MCURL = 'text/vnd.curl.mcurl'; + /* public */ const M_MDB = 'application/x-msaccess'; + /* public */ const M_MDI = 'image/vnd.ms-modi'; + /* public */ const M_ME = 'text/troff'; + /* public */ const M_MESH = 'model/mesh'; + /* public */ const M_META4 = 'application/metalink4+xml'; + /* public */ const M_METALINK = 'application/metalink+xml'; + /* public */ const M_METS = 'application/mets+xml'; + /* public */ const M_MFM = 'application/vnd.mfmp'; + /* public */ const M_MFT = 'application/rpki-manifest'; + /* public */ const M_MGP = 'application/vnd.osgeo.mapguide.package'; + /* public */ const M_MGZ = 'application/vnd.proteus.magazine'; + /* public */ const M_MID = 'audio/midi'; + /* public */ const M_MIDI = 'audio/midi'; + /* public */ const M_MIE = 'application/x-mie'; + /* public */ const M_MIF = 'application/vnd.mif'; + /* public */ const M_MIME = 'message/rfc822'; + /* public */ const M_MJ2 = 'video/mj2'; + /* public */ const M_MJP2 = 'video/mj2'; + /* public */ const M_MK3D = 'video/x-matroska'; + /* public */ const M_MKA = 'audio/x-matroska'; + /* public */ const M_MKS = 'video/x-matroska'; + /* public */ const M_MKV = 'video/x-matroska'; + /* public */ const M_MLP = 'application/vnd.dolby.mlp'; + /* public */ const M_MMD = 'application/vnd.chipnuts.karaoke-mmd'; + /* public */ const M_MMF = 'application/vnd.smaf'; + /* public */ const M_MMR = 'image/vnd.fujixerox.edmics-mmr'; + /* public */ const M_MNG = 'video/x-mng'; + /* public */ const M_MNY = 'application/x-msmoney'; + /* public */ const M_MOBI = 'application/x-mobipocket-ebook'; + /* public */ const M_MODS = 'application/mods+xml'; + /* public */ const M_MOV = 'video/quicktime'; + /* public */ const M_MOVIE = 'video/x-sgi-movie'; + /* public */ const M_MP2 = 'audio/mpeg'; + /* public */ const M_MP21 = 'application/mp21'; + /* public */ const M_MP2A = 'audio/mpeg'; + /* public */ const M_MP3 = 'audio/mpeg'; + /* public */ const M_MP4 = 'video/mp4'; + /* public */ const M_MP4A = 'audio/mp4'; + /* public */ const M_MP4S = 'application/mp4'; + /* public */ const M_MP4V = 'video/mp4'; + /* public */ const M_MPC = 'application/vnd.mophun.certificate'; + /* public */ const M_MPE = 'video/mpeg'; + /* public */ const M_MPEG = 'video/mpeg'; + /* public */ const M_MPG = 'video/mpeg'; + /* public */ const M_MPG4 = 'video/mp4'; + /* public */ const M_MPGA = 'audio/mpeg'; + /* public */ const M_MPKG = 'application/vnd.apple.installer+xml'; + /* public */ const M_MPM = 'application/vnd.blueice.multipass'; + /* public */ const M_MPN = 'application/vnd.mophun.application'; + /* public */ const M_MPP = 'application/vnd.ms-project'; + /* public */ const M_MPT = 'application/vnd.ms-project'; + /* public */ const M_MPY = 'application/vnd.ibm.minipay'; + /* public */ const M_MQY = 'application/vnd.mobius.mqy'; + /* public */ const M_MRC = 'application/marc'; + /* public */ const M_MRCX = 'application/marcxml+xml'; + /* public */ const M_MS = 'text/troff'; + /* public */ const M_MSCML = 'application/mediaservercontrol+xml'; + /* public */ const M_MSEED = 'application/vnd.fdsn.mseed'; + /* public */ const M_MSEQ = 'application/vnd.mseq'; + /* public */ const M_MSF = 'application/vnd.epson.msf'; + /* public */ const M_MSH = 'model/mesh'; + /* public */ const M_MSI = 'application/x-msdownload'; + /* public */ const M_MSL = 'application/vnd.mobius.msl'; + /* public */ const M_MSTY = 'application/vnd.muvee.style'; + /* public */ const M_MTS = 'model/vnd.mts'; + /* public */ const M_MUS = 'application/vnd.musician'; + /* public */ const M_MUSICXML = 'application/vnd.recordare.musicxml+xml'; + /* public */ const M_MVB = 'application/x-msmediaview'; + /* public */ const M_MWF = 'application/vnd.mfer'; + /* public */ const M_MXF = 'application/mxf'; + /* public */ const M_MXL = 'application/vnd.recordare.musicxml'; + /* public */ const M_MXML = 'application/xv+xml'; + /* public */ const M_MXS = 'application/vnd.triscape.mxs'; + /* public */ const M_MXU = 'video/vnd.mpegurl'; + /* public */ const M_N_GAGE = 'application/vnd.nokia.n-gage.symbian.install'; + /* public */ const M_N3 = 'text/n3'; + /* public */ const M_NB = 'application/mathematica'; + /* public */ const M_NBP = 'application/vnd.wolfram.player'; + /* public */ const M_NC = 'application/x-netcdf'; + /* public */ const M_NCX = 'application/x-dtbncx+xml'; + /* public */ const M_NFO = 'text/x-nfo'; + /* public */ const M_NGDAT = 'application/vnd.nokia.n-gage.data'; + /* public */ const M_NITF = 'application/vnd.nitf'; + /* public */ const M_NLU = 'application/vnd.neurolanguage.nlu'; + /* public */ const M_NML = 'application/vnd.enliven'; + /* public */ const M_NND = 'application/vnd.noblenet-directory'; + /* public */ const M_NNS = 'application/vnd.noblenet-sealer'; + /* public */ const M_NNW = 'application/vnd.noblenet-web'; + /* public */ const M_NPX = 'image/vnd.net-fpx'; + /* public */ const M_NSC = 'application/x-conference'; + /* public */ const M_NSF = 'application/vnd.lotus-notes'; + /* public */ const M_NTF = 'application/vnd.nitf'; + /* public */ const M_NZB = 'application/x-nzb'; + /* public */ const M_OA2 = 'application/vnd.fujitsu.oasys2'; + /* public */ const M_OA3 = 'application/vnd.fujitsu.oasys3'; + /* public */ const M_OAS = 'application/vnd.fujitsu.oasys'; + /* public */ const M_OBD = 'application/x-msbinder'; + /* public */ const M_OBJ = 'application/x-tgif'; + /* public */ const M_ODA = 'application/oda'; + /* public */ const M_ODB = 'application/vnd.oasis.opendocument.database'; + /* public */ const M_ODC = 'application/vnd.oasis.opendocument.chart'; + /* public */ const M_ODF = 'application/vnd.oasis.opendocument.formula'; + /* public */ const M_ODFT = 'application/vnd.oasis.opendocument.formula-template'; + /* public */ const M_ODG = 'application/vnd.oasis.opendocument.graphics'; + /* public */ const M_ODI = 'application/vnd.oasis.opendocument.image'; + /* public */ const M_ODM = 'application/vnd.oasis.opendocument.text-master'; + /* public */ const M_ODP = 'application/vnd.oasis.opendocument.presentation'; + /* public */ const M_ODS = 'application/vnd.oasis.opendocument.spreadsheet'; + /* public */ const M_ODT = 'application/vnd.oasis.opendocument.text'; + /* public */ const M_OGA = 'audio/ogg'; + /* public */ const M_OGG = 'audio/ogg'; + /* public */ const M_OGV = 'video/ogg'; + /* public */ const M_OGX = 'application/ogg'; + /* public */ const M_OMDOC = 'application/omdoc+xml'; + /* public */ const M_ONEPKG = 'application/onenote'; + /* public */ const M_ONETMP = 'application/onenote'; + /* public */ const M_ONETOC = 'application/onenote'; + /* public */ const M_ONETOC2 = 'application/onenote'; + /* public */ const M_OPF = 'application/oebps-package+xml'; + /* public */ const M_OPML = 'text/x-opml'; + /* public */ const M_OPRC = 'application/vnd.palm'; + /* public */ const M_ORG = 'application/vnd.lotus-organizer'; + /* public */ const M_OSF = 'application/vnd.yamaha.openscoreformat'; + /* public */ const M_OSFPVG = 'application/vnd.yamaha.openscoreformat.osfpvg+xml'; + /* public */ const M_OTC = 'application/vnd.oasis.opendocument.chart-template'; + /* public */ const M_OTF = 'application/x-font-otf'; + /* public */ const M_OTG = 'application/vnd.oasis.opendocument.graphics-template'; + /* public */ const M_OTH = 'application/vnd.oasis.opendocument.text-web'; + /* public */ const M_OTI = 'application/vnd.oasis.opendocument.image-template'; + /* public */ const M_OTP = 'application/vnd.oasis.opendocument.presentation-template'; + /* public */ const M_OTS = 'application/vnd.oasis.opendocument.spreadsheet-template'; + /* public */ const M_OTT = 'application/vnd.oasis.opendocument.text-template'; + /* public */ const M_OXPS = 'application/oxps'; + /* public */ const M_OXT = 'application/vnd.openofficeorg.extension'; + /* public */ const M_P = 'text/x-pascal'; + /* public */ const M_P10 = 'application/pkcs10'; + /* public */ const M_P12 = 'application/x-pkcs12'; + /* public */ const M_P7B = 'application/x-pkcs7-certificates'; + /* public */ const M_P7C = 'application/pkcs7-mime'; + /* public */ const M_P7M = 'application/pkcs7-mime'; + /* public */ const M_P7R = 'application/x-pkcs7-certreqresp'; + /* public */ const M_P7S = 'application/pkcs7-signature'; + /* public */ const M_P8 = 'application/pkcs8'; + /* public */ const M_PAS = 'text/x-pascal'; + /* public */ const M_PAW = 'application/vnd.pawaafile'; + /* public */ const M_PBD = 'application/vnd.powerbuilder6'; + /* public */ const M_PBM = 'image/x-portable-bitmap'; + /* public */ const M_PCAP = 'application/vnd.tcpdump.pcap'; + /* public */ const M_PCF = 'application/x-font-pcf'; + /* public */ const M_PCL = 'application/vnd.hp-pcl'; + /* public */ const M_PCLXL = 'application/vnd.hp-pclxl'; + /* public */ const M_PCT = 'image/x-pict'; + /* public */ const M_PCURL = 'application/vnd.curl.pcurl'; + /* public */ const M_PCX = 'image/x-pcx'; + /* public */ const M_PDB = 'application/vnd.palm'; + /* public */ const M_PDF = 'application/pdf'; + /* public */ const M_PFA = 'application/x-font-type1'; + /* public */ const M_PFB = 'application/x-font-type1'; + /* public */ const M_PFM = 'application/x-font-type1'; + /* public */ const M_PFR = 'application/font-tdpfr'; + /* public */ const M_PFX = 'application/x-pkcs12'; + /* public */ const M_PGM = 'image/x-portable-graymap'; + /* public */ const M_PGN = 'application/x-chess-pgn'; + /* public */ const M_PGP = 'application/pgp-encrypted'; + /* public */ const M_PHP = 'application/x-php'; + /* public */ const M_PHP3 = 'application/x-php'; + /* public */ const M_PHP4 = 'application/x-php'; + /* public */ const M_PHP5 = 'application/x-php'; + /* public */ const M_PIC = 'image/x-pict'; + /* public */ const M_PKG = 'application/octet-stream'; + /* public */ const M_PKI = 'application/pkixcmp'; + /* public */ const M_PKIPATH = 'application/pkix-pkipath'; + /* public */ const M_PLB = 'application/vnd.3gpp.pic-bw-large'; + /* public */ const M_PLC = 'application/vnd.mobius.plc'; + /* public */ const M_PLF = 'application/vnd.pocketlearn'; + /* public */ const M_PLS = 'application/pls+xml'; + /* public */ const M_PML = 'application/vnd.ctc-posml'; + /* public */ const M_PNG = 'image/png'; + /* public */ const M_PNM = 'image/x-portable-anymap'; + /* public */ const M_PORTPKG = 'application/vnd.macports.portpkg'; + /* public */ const M_POT = 'application/vnd.ms-powerpoint'; + /* public */ const M_POTM = 'application/vnd.ms-powerpoint.template.macroenabled.12'; + /* public */ const M_POTX = 'application/vnd.openxmlformats-officedocument.presentationml.template'; + /* public */ const M_PPAM = 'application/vnd.ms-powerpoint.addin.macroenabled.12'; + /* public */ const M_PPD = 'application/vnd.cups-ppd'; + /* public */ const M_PPM = 'image/x-portable-pixmap'; + /* public */ const M_PPS = 'application/vnd.ms-powerpoint'; + /* public */ const M_PPSM = 'application/vnd.ms-powerpoint.slideshow.macroenabled.12'; + /* public */ const M_PPSX = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; + /* public */ const M_PPT = 'application/vnd.ms-powerpoint'; + /* public */ const M_PPTM = 'application/vnd.ms-powerpoint.presentation.macroenabled.12'; + /* public */ const M_PPTX = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + /* public */ const M_PQA = 'application/vnd.palm'; + /* public */ const M_PRC = 'application/x-mobipocket-ebook'; + /* public */ const M_PRE = 'application/vnd.lotus-freelance'; + /* public */ const M_PRF = 'application/pics-rules'; + /* public */ const M_PS = 'application/postscript'; + /* public */ const M_PSB = 'application/vnd.3gpp.pic-bw-small'; + /* public */ const M_PSD = 'image/vnd.adobe.photoshop'; + /* public */ const M_PSF = 'application/x-font-linux-psf'; + /* public */ const M_PSKCXML = 'application/pskc+xml'; + /* public */ const M_PTID = 'application/vnd.pvi.ptid1'; + /* public */ const M_PUB = 'application/x-mspublisher'; + /* public */ const M_PVB = 'application/vnd.3gpp.pic-bw-var'; + /* public */ const M_PWN = 'application/vnd.3m.post-it-notes'; + /* public */ const M_PYA = 'audio/vnd.ms-playready.media.pya'; + /* public */ const M_PYV = 'video/vnd.ms-playready.media.pyv'; + /* public */ const M_QAM = 'application/vnd.epson.quickanime'; + /* public */ const M_QBO = 'application/vnd.intu.qbo'; + /* public */ const M_QFX = 'application/vnd.intu.qfx'; + /* public */ const M_QPS = 'application/vnd.publishare-delta-tree'; + /* public */ const M_QT = 'video/quicktime'; + /* public */ const M_QWD = 'application/vnd.quark.quarkxpress'; + /* public */ const M_QWT = 'application/vnd.quark.quarkxpress'; + /* public */ const M_QXB = 'application/vnd.quark.quarkxpress'; + /* public */ const M_QXD = 'application/vnd.quark.quarkxpress'; + /* public */ const M_QXL = 'application/vnd.quark.quarkxpress'; + /* public */ const M_QXT = 'application/vnd.quark.quarkxpress'; + /* public */ const M_RA = 'audio/x-pn-realaudio'; + /* public */ const M_RAM = 'audio/x-pn-realaudio'; + /* public */ const M_RAR = 'application/x-rar-compressed'; + /* public */ const M_RAS = 'image/x-cmu-raster'; /* public */ const M_RCPROFILE = 'application/vnd.ipunplugged.rcprofile'; - /* public */ const M_RDF = 'application/rdf+xml'; - /* public */ const M_RDZ = 'application/vnd.data-vision.rdz'; - /* public */ const M_REP = 'application/vnd.businessobjects'; - /* public */ const M_RES = 'application/x-dtbresource+xml'; - /* public */ const M_RGB = 'image/x-rgb'; - /* public */ const M_RIF = 'application/reginfo+xml'; - /* public */ const M_RIP = 'audio/vnd.rip'; - /* public */ const M_RIS = 'application/x-research-info-systems'; - /* public */ const M_RL = 'application/resource-lists+xml'; - /* public */ const M_RLC = 'image/vnd.fujixerox.edmics-rlc'; - /* public */ const M_RLD = 'application/resource-lists-diff+xml'; - /* public */ const M_RM = 'application/vnd.rn-realmedia'; - /* public */ const M_RMI = 'audio/midi'; - /* public */ const M_RMP = 'audio/x-pn-realaudio-plugin'; - /* public */ const M_RMS = 'application/vnd.jcp.javame.midlet-rms'; - /* public */ const M_RMVB = 'application/vnd.rn-realmedia-vbr'; - /* public */ const M_RNC = 'application/relax-ng-compact-syntax'; - /* public */ const M_ROA = 'application/rpki-roa'; - /* public */ const M_ROFF = 'text/troff'; - /* public */ const M_RP9 = 'application/vnd.cloanto.rp9'; - /* public */ const M_RPSS = 'application/vnd.nokia.radio-presets'; - /* public */ const M_RPST = 'application/vnd.nokia.radio-preset'; - /* public */ const M_RQ = 'application/sparql-query'; - /* public */ const M_RS = 'application/rls-services+xml'; - /* public */ const M_RSD = 'application/rsd+xml'; - /* public */ const M_RSS = 'application/rss+xml'; - /* public */ const M_RTF = 'application/rtf'; - /* public */ const M_RTX = 'text/richtext'; - /* public */ const M_S = 'text/x-asm'; - /* public */ const M_S3M = 'audio/s3m'; - /* public */ const M_SAF = 'application/vnd.yamaha.smaf-audio'; - /* public */ const M_SBML = 'application/sbml+xml'; - /* public */ const M_SC = 'application/vnd.ibm.secure-container'; - /* public */ const M_SCD = 'application/x-msschedule'; - /* public */ const M_SCM = 'application/vnd.lotus-screencam'; - /* public */ const M_SCQ = 'application/scvp-cv-request'; - /* public */ const M_SCS = 'application/scvp-cv-response'; - /* public */ const M_SCURL = 'text/vnd.curl.scurl'; - /* public */ const M_SDA = 'application/vnd.stardivision.draw'; - /* public */ const M_SDC = 'application/vnd.stardivision.calc'; - /* public */ const M_SDD = 'application/vnd.stardivision.impress'; - /* public */ const M_SDKD = 'application/vnd.solent.sdkm+xml'; - /* public */ const M_SDKM = 'application/vnd.solent.sdkm+xml'; - /* public */ const M_SDP = 'application/sdp'; - /* public */ const M_SDW = 'application/vnd.stardivision.writer'; - /* public */ const M_SEE = 'application/vnd.seemail'; - /* public */ const M_SEED = 'application/vnd.fdsn.seed'; - /* public */ const M_SEMA = 'application/vnd.sema'; - /* public */ const M_SEMD = 'application/vnd.semd'; - /* public */ const M_SEMF = 'application/vnd.semf'; - /* public */ const M_SER = 'application/java-serialized-object'; - /* public */ const M_SETPAY = 'application/set-payment-initiation'; - /* public */ const M_SETREG = 'application/set-registration-initiation'; + /* public */ const M_RDF = 'application/rdf+xml'; + /* public */ const M_RDZ = 'application/vnd.data-vision.rdz'; + /* public */ const M_REP = 'application/vnd.businessobjects'; + /* public */ const M_RES = 'application/x-dtbresource+xml'; + /* public */ const M_RGB = 'image/x-rgb'; + /* public */ const M_RIF = 'application/reginfo+xml'; + /* public */ const M_RIP = 'audio/vnd.rip'; + /* public */ const M_RIS = 'application/x-research-info-systems'; + /* public */ const M_RL = 'application/resource-lists+xml'; + /* public */ const M_RLC = 'image/vnd.fujixerox.edmics-rlc'; + /* public */ const M_RLD = 'application/resource-lists-diff+xml'; + /* public */ const M_RM = 'application/vnd.rn-realmedia'; + /* public */ const M_RMI = 'audio/midi'; + /* public */ const M_RMP = 'audio/x-pn-realaudio-plugin'; + /* public */ const M_RMS = 'application/vnd.jcp.javame.midlet-rms'; + /* public */ const M_RMVB = 'application/vnd.rn-realmedia-vbr'; + /* public */ const M_RNC = 'application/relax-ng-compact-syntax'; + /* public */ const M_ROA = 'application/rpki-roa'; + /* public */ const M_ROFF = 'text/troff'; + /* public */ const M_RP9 = 'application/vnd.cloanto.rp9'; + /* public */ const M_RPSS = 'application/vnd.nokia.radio-presets'; + /* public */ const M_RPST = 'application/vnd.nokia.radio-preset'; + /* public */ const M_RQ = 'application/sparql-query'; + /* public */ const M_RS = 'application/rls-services+xml'; + /* public */ const M_RSD = 'application/rsd+xml'; + /* public */ const M_RSS = 'application/rss+xml'; + /* public */ const M_RTF = 'application/rtf'; + /* public */ const M_RTX = 'text/richtext'; + /* public */ const M_S = 'text/x-asm'; + /* public */ const M_S3M = 'audio/s3m'; + /* public */ const M_SAF = 'application/vnd.yamaha.smaf-audio'; + /* public */ const M_SBML = 'application/sbml+xml'; + /* public */ const M_SC = 'application/vnd.ibm.secure-container'; + /* public */ const M_SCD = 'application/x-msschedule'; + /* public */ const M_SCM = 'application/vnd.lotus-screencam'; + /* public */ const M_SCQ = 'application/scvp-cv-request'; + /* public */ const M_SCS = 'application/scvp-cv-response'; + /* public */ const M_SCURL = 'text/vnd.curl.scurl'; + /* public */ const M_SDA = 'application/vnd.stardivision.draw'; + /* public */ const M_SDC = 'application/vnd.stardivision.calc'; + /* public */ const M_SDD = 'application/vnd.stardivision.impress'; + /* public */ const M_SDKD = 'application/vnd.solent.sdkm+xml'; + /* public */ const M_SDKM = 'application/vnd.solent.sdkm+xml'; + /* public */ const M_SDP = 'application/sdp'; + /* public */ const M_SDW = 'application/vnd.stardivision.writer'; + /* public */ const M_SEE = 'application/vnd.seemail'; + /* public */ const M_SEED = 'application/vnd.fdsn.seed'; + /* public */ const M_SEMA = 'application/vnd.sema'; + /* public */ const M_SEMD = 'application/vnd.semd'; + /* public */ const M_SEMF = 'application/vnd.semf'; + /* public */ const M_SER = 'application/java-serialized-object'; + /* public */ const M_SETPAY = 'application/set-payment-initiation'; + /* public */ const M_SETREG = 'application/set-registration-initiation'; /* public */ const M_SFD_HDSTX = 'application/vnd.hydrostatix.sof-data'; - /* public */ const M_SFS = 'application/vnd.spotfire.sfs'; - /* public */ const M_SFV = 'text/x-sfv'; - /* public */ const M_SGI = 'image/sgi'; - /* public */ const M_SGL = 'application/vnd.stardivision.writer-global'; - /* public */ const M_SGM = 'text/sgml'; - /* public */ const M_SGML = 'text/sgml'; - /* public */ const M_SH = 'application/x-sh'; - /* public */ const M_SHAR = 'application/x-shar'; - /* public */ const M_SHF = 'application/shf+xml'; - /* public */ const M_SID = 'image/x-mrsid-image'; - /* public */ const M_SIG = 'application/pgp-signature'; - /* public */ const M_SIL = 'audio/silk'; - /* public */ const M_SILO = 'model/mesh'; - /* public */ const M_SIS = 'application/vnd.symbian.install'; - /* public */ const M_SISX = 'application/vnd.symbian.install'; - /* public */ const M_SIT = 'application/x-stuffit'; - /* public */ const M_SITX = 'application/x-stuffitx'; - /* public */ const M_SKD = 'application/vnd.koan'; - /* public */ const M_SKM = 'application/vnd.koan'; - /* public */ const M_SKP = 'application/vnd.koan'; - /* public */ const M_SKT = 'application/vnd.koan'; - /* public */ const M_SLDM = 'application/vnd.ms-powerpoint.slide.macroenabled.12'; - /* public */ const M_SLDX = 'application/vnd.openxmlformats-officedocument.presentationml.slide'; - /* public */ const M_SLT = 'application/vnd.epson.salt'; - /* public */ const M_SM = 'application/vnd.stepmania.stepchart'; - /* public */ const M_SMF = 'application/vnd.stardivision.math'; - /* public */ const M_SMI = 'application/smil+xml'; - /* public */ const M_SMIL = 'application/smil+xml'; - /* public */ const M_SMV = 'video/x-smv'; - /* public */ const M_SMZIP = 'application/vnd.stepmania.package'; - /* public */ const M_SND = 'audio/basic'; - /* public */ const M_SNF = 'application/x-font-snf'; - /* public */ const M_SO = 'application/octet-stream'; - /* public */ const M_SPC = 'application/x-pkcs7-certificates'; - /* public */ const M_SPF = 'application/vnd.yamaha.smaf-phrase'; - /* public */ const M_SPL = 'application/x-futuresplash'; - /* public */ const M_SPOT = 'text/vnd.in3d.spot'; - /* public */ const M_SPP = 'application/scvp-vp-response'; - /* public */ const M_SPQ = 'application/scvp-vp-request'; - /* public */ const M_SPX = 'audio/ogg'; - /* public */ const M_SQL = 'application/x-sql'; - /* public */ const M_SRC = 'application/x-wais-source'; - /* public */ const M_SRT = 'application/x-subrip'; - /* public */ const M_SRU = 'application/sru+xml'; - /* public */ const M_SRX = 'application/sparql-results+xml'; - /* public */ const M_SSDL = 'application/ssdl+xml'; - /* public */ const M_SSE = 'application/vnd.kodak-descriptor'; - /* public */ const M_SSF = 'application/vnd.epson.ssf'; - /* public */ const M_SSML = 'application/ssml+xml'; - /* public */ const M_ST = 'application/vnd.sailingtracker.track'; - /* public */ const M_STC = 'application/vnd.sun.xml.calc.template'; - /* public */ const M_STD = 'application/vnd.sun.xml.draw.template'; - /* public */ const M_STF = 'application/vnd.wt.stf'; - /* public */ const M_STI = 'application/vnd.sun.xml.impress.template'; - /* public */ const M_STK = 'application/hyperstudio'; - /* public */ const M_STL = 'application/vnd.ms-pki.stl'; - /* public */ const M_STR = 'application/vnd.pg.format'; - /* public */ const M_STW = 'application/vnd.sun.xml.writer.template'; - /* public */ const M_SUB = 'text/vnd.dvb.subtitle'; - /* public */ const M_SUS = 'application/vnd.sus-calendar'; - /* public */ const M_SUSP = 'application/vnd.sus-calendar'; - /* public */ const M_SV4CPIO = 'application/x-sv4cpio'; - /* public */ const M_SV4CRC = 'application/x-sv4crc'; - /* public */ const M_SVC = 'application/vnd.dvb.service'; - /* public */ const M_SVD = 'application/vnd.svd'; - /* public */ const M_SVG = 'image/svg+xml'; - /* public */ const M_SVGZ = 'image/svg+xml'; - /* public */ const M_SWA = 'application/x-director'; - /* public */ const M_SWF = 'application/x-shockwave-flash'; - /* public */ const M_SWI = 'application/vnd.aristanetworks.swi'; - /* public */ const M_SXC = 'application/vnd.sun.xml.calc'; - /* public */ const M_SXD = 'application/vnd.sun.xml.draw'; - /* public */ const M_SXG = 'application/vnd.sun.xml.writer.global'; - /* public */ const M_SXI = 'application/vnd.sun.xml.impress'; - /* public */ const M_SXM = 'application/vnd.sun.xml.math'; - /* public */ const M_SXW = 'application/vnd.sun.xml.writer'; - /* public */ const M_T = 'text/troff'; - /* public */ const M_T3 = 'application/x-t3vm-image'; - /* public */ const M_TAGLET = 'application/vnd.mynfc'; - /* public */ const M_TAO = 'application/vnd.tao.intent-module-archive'; - /* public */ const M_TAR = 'application/x-tar'; - /* public */ const M_TCAP = 'application/vnd.3gpp2.tcap'; - /* public */ const M_TCL = 'application/x-tcl'; - /* public */ const M_TEACHER = 'application/vnd.smart.teacher'; - /* public */ const M_TEI = 'application/tei+xml'; + /* public */ const M_SFS = 'application/vnd.spotfire.sfs'; + /* public */ const M_SFV = 'text/x-sfv'; + /* public */ const M_SGI = 'image/sgi'; + /* public */ const M_SGL = 'application/vnd.stardivision.writer-global'; + /* public */ const M_SGM = 'text/sgml'; + /* public */ const M_SGML = 'text/sgml'; + /* public */ const M_SH = 'application/x-sh'; + /* public */ const M_SHAR = 'application/x-shar'; + /* public */ const M_SHF = 'application/shf+xml'; + /* public */ const M_SID = 'image/x-mrsid-image'; + /* public */ const M_SIG = 'application/pgp-signature'; + /* public */ const M_SIL = 'audio/silk'; + /* public */ const M_SILO = 'model/mesh'; + /* public */ const M_SIS = 'application/vnd.symbian.install'; + /* public */ const M_SISX = 'application/vnd.symbian.install'; + /* public */ const M_SIT = 'application/x-stuffit'; + /* public */ const M_SITX = 'application/x-stuffitx'; + /* public */ const M_SKD = 'application/vnd.koan'; + /* public */ const M_SKM = 'application/vnd.koan'; + /* public */ const M_SKP = 'application/vnd.koan'; + /* public */ const M_SKT = 'application/vnd.koan'; + /* public */ const M_SLDM = 'application/vnd.ms-powerpoint.slide.macroenabled.12'; + /* public */ const M_SLDX = 'application/vnd.openxmlformats-officedocument.presentationml.slide'; + /* public */ const M_SLT = 'application/vnd.epson.salt'; + /* public */ const M_SM = 'application/vnd.stepmania.stepchart'; + /* public */ const M_SMF = 'application/vnd.stardivision.math'; + /* public */ const M_SMI = 'application/smil+xml'; + /* public */ const M_SMIL = 'application/smil+xml'; + /* public */ const M_SMV = 'video/x-smv'; + /* public */ const M_SMZIP = 'application/vnd.stepmania.package'; + /* public */ const M_SND = 'audio/basic'; + /* public */ const M_SNF = 'application/x-font-snf'; + /* public */ const M_SO = 'application/octet-stream'; + /* public */ const M_SPC = 'application/x-pkcs7-certificates'; + /* public */ const M_SPF = 'application/vnd.yamaha.smaf-phrase'; + /* public */ const M_SPL = 'application/x-futuresplash'; + /* public */ const M_SPOT = 'text/vnd.in3d.spot'; + /* public */ const M_SPP = 'application/scvp-vp-response'; + /* public */ const M_SPQ = 'application/scvp-vp-request'; + /* public */ const M_SPX = 'audio/ogg'; + /* public */ const M_SQL = 'application/x-sql'; + /* public */ const M_SRC = 'application/x-wais-source'; + /* public */ const M_SRT = 'application/x-subrip'; + /* public */ const M_SRU = 'application/sru+xml'; + /* public */ const M_SRX = 'application/sparql-results+xml'; + /* public */ const M_SSDL = 'application/ssdl+xml'; + /* public */ const M_SSE = 'application/vnd.kodak-descriptor'; + /* public */ const M_SSF = 'application/vnd.epson.ssf'; + /* public */ const M_SSML = 'application/ssml+xml'; + /* public */ const M_ST = 'application/vnd.sailingtracker.track'; + /* public */ const M_STC = 'application/vnd.sun.xml.calc.template'; + /* public */ const M_STD = 'application/vnd.sun.xml.draw.template'; + /* public */ const M_STF = 'application/vnd.wt.stf'; + /* public */ const M_STI = 'application/vnd.sun.xml.impress.template'; + /* public */ const M_STK = 'application/hyperstudio'; + /* public */ const M_STL = 'application/vnd.ms-pki.stl'; + /* public */ const M_STR = 'application/vnd.pg.format'; + /* public */ const M_STW = 'application/vnd.sun.xml.writer.template'; + /* public */ const M_SUB = 'text/vnd.dvb.subtitle'; + /* public */ const M_SUS = 'application/vnd.sus-calendar'; + /* public */ const M_SUSP = 'application/vnd.sus-calendar'; + /* public */ const M_SV4CPIO = 'application/x-sv4cpio'; + /* public */ const M_SV4CRC = 'application/x-sv4crc'; + /* public */ const M_SVC = 'application/vnd.dvb.service'; + /* public */ const M_SVD = 'application/vnd.svd'; + /* public */ const M_SVG = 'image/svg+xml'; + /* public */ const M_SVGZ = 'image/svg+xml'; + /* public */ const M_SWA = 'application/x-director'; + /* public */ const M_SWF = 'application/x-shockwave-flash'; + /* public */ const M_SWI = 'application/vnd.aristanetworks.swi'; + /* public */ const M_SXC = 'application/vnd.sun.xml.calc'; + /* public */ const M_SXD = 'application/vnd.sun.xml.draw'; + /* public */ const M_SXG = 'application/vnd.sun.xml.writer.global'; + /* public */ const M_SXI = 'application/vnd.sun.xml.impress'; + /* public */ const M_SXM = 'application/vnd.sun.xml.math'; + /* public */ const M_SXW = 'application/vnd.sun.xml.writer'; + /* public */ const M_T = 'text/troff'; + /* public */ const M_T3 = 'application/x-t3vm-image'; + /* public */ const M_TAGLET = 'application/vnd.mynfc'; + /* public */ const M_TAO = 'application/vnd.tao.intent-module-archive'; + /* public */ const M_TAR = 'application/x-tar'; + /* public */ const M_TCAP = 'application/vnd.3gpp2.tcap'; + /* public */ const M_TCL = 'application/x-tcl'; + /* public */ const M_TEACHER = 'application/vnd.smart.teacher'; + /* public */ const M_TEI = 'application/tei+xml'; /* public */ const M_TEICORPUS = 'application/tei+xml'; - /* public */ const M_TEX = 'application/x-tex'; - /* public */ const M_TEXI = 'application/x-texinfo'; - /* public */ const M_TEXINFO = 'application/x-texinfo'; - /* public */ const M_TEXT = 'text/plain'; - /* public */ const M_TFI = 'application/thraud+xml'; - /* public */ const M_TFM = 'application/x-tex-tfm'; - /* public */ const M_TGA = 'image/x-tga'; - /* public */ const M_THMX = 'application/vnd.ms-officetheme'; - /* public */ const M_TIF = 'image/tiff'; - /* public */ const M_TIFF = 'image/tiff'; - /* public */ const M_TMO = 'application/vnd.tmobile-livetv'; - /* public */ const M_TORRENT = 'application/x-bittorrent'; - /* public */ const M_TPL = 'application/vnd.groove-tool-template'; - /* public */ const M_TPT = 'application/vnd.trid.tpt'; - /* public */ const M_TR = 'text/troff'; - /* public */ const M_TRA = 'application/vnd.trueapp'; - /* public */ const M_TRM = 'application/x-msterminal'; - /* public */ const M_TSD = 'application/timestamped-data'; - /* public */ const M_TSV = 'text/tab-separated-values'; - /* public */ const M_TTC = 'application/x-font-ttf'; - /* public */ const M_TTF = 'application/x-font-ttf'; - /* public */ const M_TTL = 'text/turtle'; - /* public */ const M_TWD = 'application/vnd.simtech-mindmapper'; - /* public */ const M_TWDS = 'application/vnd.simtech-mindmapper'; - /* public */ const M_TXD = 'application/vnd.genomatix.tuxedo'; - /* public */ const M_TXF = 'application/vnd.mobius.txf'; - /* public */ const M_TXT = 'text/plain'; - /* public */ const M_U32 = 'application/x-authorware-bin'; - /* public */ const M_UDEB = 'application/x-debian-package'; - /* public */ const M_UFD = 'application/vnd.ufdl'; - /* public */ const M_UFDL = 'application/vnd.ufdl'; - /* public */ const M_ULX = 'application/x-glulx'; - /* public */ const M_UMJ = 'application/vnd.umajin'; - /* public */ const M_UNITYWEB = 'application/vnd.unity'; - /* public */ const M_UOML = 'application/vnd.uoml+xml'; - /* public */ const M_URI = 'text/uri-list'; - /* public */ const M_URIS = 'text/uri-list'; - /* public */ const M_URLS = 'text/uri-list'; - /* public */ const M_USTAR = 'application/x-ustar'; - /* public */ const M_UTZ = 'application/vnd.uiq.theme'; - /* public */ const M_UU = 'text/x-uuencode'; - /* public */ const M_UVA = 'audio/vnd.dece.audio'; - /* public */ const M_UVD = 'application/vnd.dece.data'; - /* public */ const M_UVF = 'application/vnd.dece.data'; - /* public */ const M_UVG = 'image/vnd.dece.graphic'; - /* public */ const M_UVH = 'video/vnd.dece.hd'; - /* public */ const M_UVI = 'image/vnd.dece.graphic'; - /* public */ const M_UVM = 'video/vnd.dece.mobile'; - /* public */ const M_UVP = 'video/vnd.dece.pd'; - /* public */ const M_UVS = 'video/vnd.dece.sd'; - /* public */ const M_UVT = 'application/vnd.dece.ttml+xml'; - /* public */ const M_UVU = 'video/vnd.uvvu.mp4'; - /* public */ const M_UVV = 'video/vnd.dece.video'; - /* public */ const M_UVVA = 'audio/vnd.dece.audio'; - /* public */ const M_UVVD = 'application/vnd.dece.data'; - /* public */ const M_UVVF = 'application/vnd.dece.data'; - /* public */ const M_UVVG = 'image/vnd.dece.graphic'; - /* public */ const M_UVVH = 'video/vnd.dece.hd'; - /* public */ const M_UVVI = 'image/vnd.dece.graphic'; - /* public */ const M_UVVM = 'video/vnd.dece.mobile'; - /* public */ const M_UVVP = 'video/vnd.dece.pd'; - /* public */ const M_UVVS = 'video/vnd.dece.sd'; - /* public */ const M_UVVT = 'application/vnd.dece.ttml+xml'; - /* public */ const M_UVVU = 'video/vnd.uvvu.mp4'; - /* public */ const M_UVVV = 'video/vnd.dece.video'; - /* public */ const M_UVVX = 'application/vnd.dece.unspecified'; - /* public */ const M_UVVZ = 'application/vnd.dece.zip'; - /* public */ const M_UVX = 'application/vnd.dece.unspecified'; - /* public */ const M_UVZ = 'application/vnd.dece.zip'; - /* public */ const M_VCARD = 'text/vcard'; - /* public */ const M_VCD = 'application/x-cdlink'; - /* public */ const M_VCF = 'text/x-vcard'; - /* public */ const M_VCG = 'application/vnd.groove-vcard'; - /* public */ const M_VCS = 'text/x-vcalendar'; - /* public */ const M_VCX = 'application/vnd.vcx'; - /* public */ const M_VIS = 'application/vnd.visionary'; - /* public */ const M_VIV = 'video/vnd.vivo'; - /* public */ const M_VOB = 'video/x-ms-vob'; - /* public */ const M_VOR = 'application/vnd.stardivision.writer'; - /* public */ const M_VOX = 'application/x-authorware-bin'; - /* public */ const M_VRML = 'model/vrml'; - /* public */ const M_VSD = 'application/vnd.visio'; - /* public */ const M_VSF = 'application/vnd.vsf'; - /* public */ const M_VSS = 'application/vnd.visio'; - /* public */ const M_VST = 'application/vnd.visio'; - /* public */ const M_VSW = 'application/vnd.visio'; - /* public */ const M_VTU = 'model/vnd.vtu'; - /* public */ const M_VXML = 'application/voicexml+xml'; - /* public */ const M_W3D = 'application/x-director'; - /* public */ const M_WAD = 'application/x-doom'; - /* public */ const M_WAV = 'audio/x-wav'; - /* public */ const M_WAX = 'audio/x-ms-wax'; - /* public */ const M_WBMP = 'image/vnd.wap.wbmp'; - /* public */ const M_WBS = 'application/vnd.criticaltools.wbs+xml'; - /* public */ const M_WBXML = 'application/vnd.wap.wbxml'; - /* public */ const M_WCM = 'application/vnd.ms-works'; - /* public */ const M_WDB = 'application/vnd.ms-works'; - /* public */ const M_WDP = 'image/vnd.ms-photo'; - /* public */ const M_WEBA = 'audio/webm'; - /* public */ const M_WEBM = 'video/webm'; - /* public */ const M_WEBP = 'image/webp'; - /* public */ const M_WG = 'application/vnd.pmi.widget'; - /* public */ const M_WGT = 'application/widget'; - /* public */ const M_WKS = 'application/vnd.ms-works'; - /* public */ const M_WM = 'video/x-ms-wm'; - /* public */ const M_WMA = 'audio/x-ms-wma'; - /* public */ const M_WMD = 'application/x-ms-wmd'; - /* public */ const M_WMF = 'application/x-msmetafile'; - /* public */ const M_WML = 'text/vnd.wap.wml'; - /* public */ const M_WMLC = 'application/vnd.wap.wmlc'; - /* public */ const M_WMLS = 'text/vnd.wap.wmlscript'; - /* public */ const M_WMLSC = 'application/vnd.wap.wmlscriptc'; - /* public */ const M_WMV = 'video/x-ms-wmv'; - /* public */ const M_WMX = 'video/x-ms-wmx'; - /* public */ const M_WMZ = 'application/x-msmetafile'; - /* public */ const M_WOFF = 'application/font-woff'; - /* public */ const M_WPD = 'application/vnd.wordperfect'; - /* public */ const M_WPL = 'application/vnd.ms-wpl'; - /* public */ const M_WPS = 'application/vnd.ms-works'; - /* public */ const M_WQD = 'application/vnd.wqd'; - /* public */ const M_WRI = 'application/x-mswrite'; - /* public */ const M_WRL = 'model/vrml'; - /* public */ const M_WSDL = 'application/wsdl+xml'; - /* public */ const M_WSPOLICY = 'application/wspolicy+xml'; - /* public */ const M_WTB = 'application/vnd.webturbo'; - /* public */ const M_WVX = 'video/x-ms-wvx'; - /* public */ const M_X32 = 'application/x-authorware-bin'; - /* public */ const M_X3D = 'model/x3d+xml'; - /* public */ const M_X3DB = 'model/x3d+binary'; - /* public */ const M_X3DBZ = 'model/x3d+binary'; - /* public */ const M_X3DV = 'model/x3d+vrml'; - /* public */ const M_X3DVZ = 'model/x3d+vrml'; - /* public */ const M_X3DZ = 'model/x3d+xml'; - /* public */ const M_XAML = 'application/xaml+xml'; - /* public */ const M_XAP = 'application/x-silverlight-app'; - /* public */ const M_XAR = 'application/vnd.xara'; - /* public */ const M_XBAP = 'application/x-ms-xbap'; - /* public */ const M_XBD = 'application/vnd.fujixerox.docuworks.binder'; - /* public */ const M_XBM = 'image/x-xbitmap'; - /* public */ const M_XDF = 'application/xcap-diff+xml'; - /* public */ const M_XDM = 'application/vnd.syncml.dm+xml'; - /* public */ const M_XDP = 'application/vnd.adobe.xdp+xml'; - /* public */ const M_XDSSC = 'application/dssc+xml'; - /* public */ const M_XDW = 'application/vnd.fujixerox.docuworks'; - /* public */ const M_XENC = 'application/xenc+xml'; - /* public */ const M_XER = 'application/patch-ops-error+xml'; - /* public */ const M_XFDF = 'application/vnd.adobe.xfdf'; - /* public */ const M_XFDL = 'application/vnd.xfdl'; - /* public */ const M_XHT = 'application/xhtml+xml'; - /* public */ const M_XHTML = 'application/xhtml+xml'; - /* public */ const M_XHVML = 'application/xv+xml'; - /* public */ const M_XIF = 'image/vnd.xiff'; - /* public */ const M_XLA = 'application/vnd.ms-excel'; - /* public */ const M_XLAM = 'application/vnd.ms-excel.addin.macroenabled.12'; - /* public */ const M_XLC = 'application/vnd.ms-excel'; - /* public */ const M_XLF = 'application/x-xliff+xml'; - /* public */ const M_XLM = 'application/vnd.ms-excel'; - /* public */ const M_XLS = 'application/vnd.ms-excel'; - /* public */ const M_XLSB = 'application/vnd.ms-excel.sheet.binary.macroenabled.12'; - /* public */ const M_XLSM = 'application/vnd.ms-excel.sheet.macroenabled.12'; - /* public */ const M_XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; - /* public */ const M_XLT = 'application/vnd.ms-excel'; - /* public */ const M_XLTM = 'application/vnd.ms-excel.template.macroenabled.12'; - /* public */ const M_XLTX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; - /* public */ const M_XLW = 'application/vnd.ms-excel'; - /* public */ const M_XM = 'audio/xm'; - /* public */ const M_XML = 'application/xml'; - /* public */ const M_XO = 'application/vnd.olpc-sugar'; - /* public */ const M_XOP = 'application/xop+xml'; - /* public */ const M_XPI = 'application/x-xpinstall'; - /* public */ const M_XPL = 'application/xproc+xml'; - /* public */ const M_XPM = 'image/x-xpixmap'; - /* public */ const M_XPR = 'application/vnd.is-xpr'; - /* public */ const M_XPS = 'application/vnd.ms-xpsdocument'; - /* public */ const M_XPW = 'application/vnd.intercon.formnet'; - /* public */ const M_XPX = 'application/vnd.intercon.formnet'; - /* public */ const M_XSL = 'application/xml'; - /* public */ const M_XSLT = 'application/xslt+xml'; - /* public */ const M_XSM = 'application/vnd.syncml+xml'; - /* public */ const M_XSPF = 'application/xspf+xml'; - /* public */ const M_XUL = 'application/vnd.mozilla.xul+xml'; - /* public */ const M_XVM = 'application/xv+xml'; - /* public */ const M_XVML = 'application/xv+xml'; - /* public */ const M_XWD = 'image/x-xwindowdump'; - /* public */ const M_XYZ = 'chemical/x-xyz'; - /* public */ const M_XZ = 'application/x-xz'; - /* public */ const M_YANG = 'application/yang'; - /* public */ const M_YIN = 'application/yin+xml'; - /* public */ const M_Z1 = 'application/x-zmachine'; - /* public */ const M_Z2 = 'application/x-zmachine'; - /* public */ const M_Z3 = 'application/x-zmachine'; - /* public */ const M_Z4 = 'application/x-zmachine'; - /* public */ const M_Z5 = 'application/x-zmachine'; - /* public */ const M_Z6 = 'application/x-zmachine'; - /* public */ const M_Z7 = 'application/x-zmachine'; - /* public */ const M_Z8 = 'application/x-zmachine'; - /* public */ const M_ZAZ = 'application/vnd.zzazz.deck+xml'; - /* public */ const M_ZIP = 'application/zip'; - /* public */ const M_ZIR = 'application/vnd.zul'; - /* public */ const M_ZIRZ = 'application/vnd.zul'; - /* public */ const M_ZMM = 'application/vnd.handheld-entertainment+xml'; - /* public */ const M_123 = 'application/vnd.lotus-1-2-3'; + /* public */ const M_TEX = 'application/x-tex'; + /* public */ const M_TEXI = 'application/x-texinfo'; + /* public */ const M_TEXINFO = 'application/x-texinfo'; + /* public */ const M_TEXT = 'text/plain'; + /* public */ const M_TFI = 'application/thraud+xml'; + /* public */ const M_TFM = 'application/x-tex-tfm'; + /* public */ const M_TGA = 'image/x-tga'; + /* public */ const M_THMX = 'application/vnd.ms-officetheme'; + /* public */ const M_TIF = 'image/tiff'; + /* public */ const M_TIFF = 'image/tiff'; + /* public */ const M_TMO = 'application/vnd.tmobile-livetv'; + /* public */ const M_TORRENT = 'application/x-bittorrent'; + /* public */ const M_TPL = 'application/vnd.groove-tool-template'; + /* public */ const M_TPT = 'application/vnd.trid.tpt'; + /* public */ const M_TR = 'text/troff'; + /* public */ const M_TRA = 'application/vnd.trueapp'; + /* public */ const M_TRM = 'application/x-msterminal'; + /* public */ const M_TSD = 'application/timestamped-data'; + /* public */ const M_TSV = 'text/tab-separated-values'; + /* public */ const M_TTC = 'application/x-font-ttf'; + /* public */ const M_TTF = 'application/x-font-ttf'; + /* public */ const M_TTL = 'text/turtle'; + /* public */ const M_TWD = 'application/vnd.simtech-mindmapper'; + /* public */ const M_TWDS = 'application/vnd.simtech-mindmapper'; + /* public */ const M_TXD = 'application/vnd.genomatix.tuxedo'; + /* public */ const M_TXF = 'application/vnd.mobius.txf'; + /* public */ const M_TXT = 'text/plain'; + /* public */ const M_U32 = 'application/x-authorware-bin'; + /* public */ const M_UDEB = 'application/x-debian-package'; + /* public */ const M_UFD = 'application/vnd.ufdl'; + /* public */ const M_UFDL = 'application/vnd.ufdl'; + /* public */ const M_ULX = 'application/x-glulx'; + /* public */ const M_UMJ = 'application/vnd.umajin'; + /* public */ const M_UNITYWEB = 'application/vnd.unity'; + /* public */ const M_UOML = 'application/vnd.uoml+xml'; + /* public */ const M_URI = 'text/uri-list'; + /* public */ const M_URIS = 'text/uri-list'; + /* public */ const M_URLS = 'text/uri-list'; + /* public */ const M_USTAR = 'application/x-ustar'; + /* public */ const M_UTZ = 'application/vnd.uiq.theme'; + /* public */ const M_UU = 'text/x-uuencode'; + /* public */ const M_UVA = 'audio/vnd.dece.audio'; + /* public */ const M_UVD = 'application/vnd.dece.data'; + /* public */ const M_UVF = 'application/vnd.dece.data'; + /* public */ const M_UVG = 'image/vnd.dece.graphic'; + /* public */ const M_UVH = 'video/vnd.dece.hd'; + /* public */ const M_UVI = 'image/vnd.dece.graphic'; + /* public */ const M_UVM = 'video/vnd.dece.mobile'; + /* public */ const M_UVP = 'video/vnd.dece.pd'; + /* public */ const M_UVS = 'video/vnd.dece.sd'; + /* public */ const M_UVT = 'application/vnd.dece.ttml+xml'; + /* public */ const M_UVU = 'video/vnd.uvvu.mp4'; + /* public */ const M_UVV = 'video/vnd.dece.video'; + /* public */ const M_UVVA = 'audio/vnd.dece.audio'; + /* public */ const M_UVVD = 'application/vnd.dece.data'; + /* public */ const M_UVVF = 'application/vnd.dece.data'; + /* public */ const M_UVVG = 'image/vnd.dece.graphic'; + /* public */ const M_UVVH = 'video/vnd.dece.hd'; + /* public */ const M_UVVI = 'image/vnd.dece.graphic'; + /* public */ const M_UVVM = 'video/vnd.dece.mobile'; + /* public */ const M_UVVP = 'video/vnd.dece.pd'; + /* public */ const M_UVVS = 'video/vnd.dece.sd'; + /* public */ const M_UVVT = 'application/vnd.dece.ttml+xml'; + /* public */ const M_UVVU = 'video/vnd.uvvu.mp4'; + /* public */ const M_UVVV = 'video/vnd.dece.video'; + /* public */ const M_UVVX = 'application/vnd.dece.unspecified'; + /* public */ const M_UVVZ = 'application/vnd.dece.zip'; + /* public */ const M_UVX = 'application/vnd.dece.unspecified'; + /* public */ const M_UVZ = 'application/vnd.dece.zip'; + /* public */ const M_VCARD = 'text/vcard'; + /* public */ const M_VCD = 'application/x-cdlink'; + /* public */ const M_VCF = 'text/x-vcard'; + /* public */ const M_VCG = 'application/vnd.groove-vcard'; + /* public */ const M_VCS = 'text/x-vcalendar'; + /* public */ const M_VCX = 'application/vnd.vcx'; + /* public */ const M_VIS = 'application/vnd.visionary'; + /* public */ const M_VIV = 'video/vnd.vivo'; + /* public */ const M_VOB = 'video/x-ms-vob'; + /* public */ const M_VOR = 'application/vnd.stardivision.writer'; + /* public */ const M_VOX = 'application/x-authorware-bin'; + /* public */ const M_VRML = 'model/vrml'; + /* public */ const M_VSD = 'application/vnd.visio'; + /* public */ const M_VSF = 'application/vnd.vsf'; + /* public */ const M_VSS = 'application/vnd.visio'; + /* public */ const M_VST = 'application/vnd.visio'; + /* public */ const M_VSW = 'application/vnd.visio'; + /* public */ const M_VTU = 'model/vnd.vtu'; + /* public */ const M_VXML = 'application/voicexml+xml'; + /* public */ const M_W3D = 'application/x-director'; + /* public */ const M_WAD = 'application/x-doom'; + /* public */ const M_WAV = 'audio/x-wav'; + /* public */ const M_WAX = 'audio/x-ms-wax'; + /* public */ const M_WBMP = 'image/vnd.wap.wbmp'; + /* public */ const M_WBS = 'application/vnd.criticaltools.wbs+xml'; + /* public */ const M_WBXML = 'application/vnd.wap.wbxml'; + /* public */ const M_WCM = 'application/vnd.ms-works'; + /* public */ const M_WDB = 'application/vnd.ms-works'; + /* public */ const M_WDP = 'image/vnd.ms-photo'; + /* public */ const M_WEBA = 'audio/webm'; + /* public */ const M_WEBM = 'video/webm'; + /* public */ const M_WEBP = 'image/webp'; + /* public */ const M_WG = 'application/vnd.pmi.widget'; + /* public */ const M_WGT = 'application/widget'; + /* public */ const M_WKS = 'application/vnd.ms-works'; + /* public */ const M_WM = 'video/x-ms-wm'; + /* public */ const M_WMA = 'audio/x-ms-wma'; + /* public */ const M_WMD = 'application/x-ms-wmd'; + /* public */ const M_WMF = 'application/x-msmetafile'; + /* public */ const M_WML = 'text/vnd.wap.wml'; + /* public */ const M_WMLC = 'application/vnd.wap.wmlc'; + /* public */ const M_WMLS = 'text/vnd.wap.wmlscript'; + /* public */ const M_WMLSC = 'application/vnd.wap.wmlscriptc'; + /* public */ const M_WMV = 'video/x-ms-wmv'; + /* public */ const M_WMX = 'video/x-ms-wmx'; + /* public */ const M_WMZ = 'application/x-msmetafile'; + /* public */ const M_WOFF = 'application/font-woff'; + /* public */ const M_WPD = 'application/vnd.wordperfect'; + /* public */ const M_WPL = 'application/vnd.ms-wpl'; + /* public */ const M_WPS = 'application/vnd.ms-works'; + /* public */ const M_WQD = 'application/vnd.wqd'; + /* public */ const M_WRI = 'application/x-mswrite'; + /* public */ const M_WRL = 'model/vrml'; + /* public */ const M_WSDL = 'application/wsdl+xml'; + /* public */ const M_WSPOLICY = 'application/wspolicy+xml'; + /* public */ const M_WTB = 'application/vnd.webturbo'; + /* public */ const M_WVX = 'video/x-ms-wvx'; + /* public */ const M_X32 = 'application/x-authorware-bin'; + /* public */ const M_X3D = 'model/x3d+xml'; + /* public */ const M_X3DB = 'model/x3d+binary'; + /* public */ const M_X3DBZ = 'model/x3d+binary'; + /* public */ const M_X3DV = 'model/x3d+vrml'; + /* public */ const M_X3DVZ = 'model/x3d+vrml'; + /* public */ const M_X3DZ = 'model/x3d+xml'; + /* public */ const M_XAML = 'application/xaml+xml'; + /* public */ const M_XAP = 'application/x-silverlight-app'; + /* public */ const M_XAR = 'application/vnd.xara'; + /* public */ const M_XBAP = 'application/x-ms-xbap'; + /* public */ const M_XBD = 'application/vnd.fujixerox.docuworks.binder'; + /* public */ const M_XBM = 'image/x-xbitmap'; + /* public */ const M_XDF = 'application/xcap-diff+xml'; + /* public */ const M_XDM = 'application/vnd.syncml.dm+xml'; + /* public */ const M_XDP = 'application/vnd.adobe.xdp+xml'; + /* public */ const M_XDSSC = 'application/dssc+xml'; + /* public */ const M_XDW = 'application/vnd.fujixerox.docuworks'; + /* public */ const M_XENC = 'application/xenc+xml'; + /* public */ const M_XER = 'application/patch-ops-error+xml'; + /* public */ const M_XFDF = 'application/vnd.adobe.xfdf'; + /* public */ const M_XFDL = 'application/vnd.xfdl'; + /* public */ const M_XHT = 'application/xhtml+xml'; + /* public */ const M_XHTML = 'application/xhtml+xml'; + /* public */ const M_XHVML = 'application/xv+xml'; + /* public */ const M_XIF = 'image/vnd.xiff'; + /* public */ const M_XLA = 'application/vnd.ms-excel'; + /* public */ const M_XLAM = 'application/vnd.ms-excel.addin.macroenabled.12'; + /* public */ const M_XLC = 'application/vnd.ms-excel'; + /* public */ const M_XLF = 'application/x-xliff+xml'; + /* public */ const M_XLM = 'application/vnd.ms-excel'; + /* public */ const M_XLS = 'application/vnd.ms-excel'; + /* public */ const M_XLSB = 'application/vnd.ms-excel.sheet.binary.macroenabled.12'; + /* public */ const M_XLSM = 'application/vnd.ms-excel.sheet.macroenabled.12'; + /* public */ const M_XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + /* public */ const M_XLT = 'application/vnd.ms-excel'; + /* public */ const M_XLTM = 'application/vnd.ms-excel.template.macroenabled.12'; + /* public */ const M_XLTX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; + /* public */ const M_XLW = 'application/vnd.ms-excel'; + /* public */ const M_XM = 'audio/xm'; + /* public */ const M_XML = 'application/xml'; + /* public */ const M_XO = 'application/vnd.olpc-sugar'; + /* public */ const M_XOP = 'application/xop+xml'; + /* public */ const M_XPI = 'application/x-xpinstall'; + /* public */ const M_XPL = 'application/xproc+xml'; + /* public */ const M_XPM = 'image/x-xpixmap'; + /* public */ const M_XPR = 'application/vnd.is-xpr'; + /* public */ const M_XPS = 'application/vnd.ms-xpsdocument'; + /* public */ const M_XPW = 'application/vnd.intercon.formnet'; + /* public */ const M_XPX = 'application/vnd.intercon.formnet'; + /* public */ const M_XSL = 'application/xml'; + /* public */ const M_XSLT = 'application/xslt+xml'; + /* public */ const M_XSM = 'application/vnd.syncml+xml'; + /* public */ const M_XSPF = 'application/xspf+xml'; + /* public */ const M_XUL = 'application/vnd.mozilla.xul+xml'; + /* public */ const M_XVM = 'application/xv+xml'; + /* public */ const M_XVML = 'application/xv+xml'; + /* public */ const M_XWD = 'image/x-xwindowdump'; + /* public */ const M_XYZ = 'chemical/x-xyz'; + /* public */ const M_XZ = 'application/x-xz'; + /* public */ const M_YANG = 'application/yang'; + /* public */ const M_YIN = 'application/yin+xml'; + /* public */ const M_Z1 = 'application/x-zmachine'; + /* public */ const M_Z2 = 'application/x-zmachine'; + /* public */ const M_Z3 = 'application/x-zmachine'; + /* public */ const M_Z4 = 'application/x-zmachine'; + /* public */ const M_Z5 = 'application/x-zmachine'; + /* public */ const M_Z6 = 'application/x-zmachine'; + /* public */ const M_Z7 = 'application/x-zmachine'; + /* public */ const M_Z8 = 'application/x-zmachine'; + /* public */ const M_ZAZ = 'application/vnd.zzazz.deck+xml'; + /* public */ const M_ZIP = 'application/zip'; + /* public */ const M_ZIR = 'application/vnd.zul'; + /* public */ const M_ZIRZ = 'application/vnd.zul'; + /* public */ const M_ZMM = 'application/vnd.handheld-entertainment+xml'; + /* public */ const M_123 = 'application/vnd.lotus-1-2-3'; } diff --git a/System/OperatingSystem.php b/System/OperatingSystem.php index 97ee9766b..98bd26635 100644 --- a/System/OperatingSystem.php +++ b/System/OperatingSystem.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System; /** * Operating system class. * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class OperatingSystem @@ -35,14 +33,14 @@ final class OperatingSystem */ public static function getSystem() : int { - if(stristr(PHP_OS, 'DAR') !== false) { + if (stristr(PHP_OS, 'DAR') !== false) { return SystemType::OSX; - } elseif(stristr(PHP_OS, 'WIN') !== false) { + } elseif (stristr(PHP_OS, 'WIN') !== false) { return SystemType::WIN; - } elseif(stristr(PHP_OS, 'LINUX') !== false) { + } elseif (stristr(PHP_OS, 'LINUX') !== false) { return SystemType::LINUX; - } + } return SystemType::UNKNOWN; } -} \ No newline at end of file +} diff --git a/System/SystemType.php b/System/SystemType.php index 24aa27dd2..dd18e822a 100644 --- a/System/SystemType.php +++ b/System/SystemType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System; @@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum; * * Database types that are supported by the application * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SystemType extends Enum @@ -34,4 +32,4 @@ abstract class SystemType extends Enum /* public */ const WIN = 2; /* public */ const LINUX = 3; /* public */ const OSX = 4; -} \ No newline at end of file +} diff --git a/System/SystemUtils.php b/System/SystemUtils.php index b487aa92b..2524eeed2 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\System; /** * System utils * - * @category Framework - * @package phpOMS\System + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class SystemUtils @@ -46,10 +44,13 @@ class SystemUtils */ public static function getRAM() : int { - $mem = null; + $mem = 0; if (stristr(PHP_OS, 'WIN')) { + $mem = null; exec('wmic memorychip get capacity', $mem); + + /** @var array $mem */ $mem = array_sum($mem) / 1024; } elseif (stristr(PHP_OS, 'LINUX')) { $fh = fopen('/proc/meminfo', 'r'); @@ -62,6 +63,7 @@ class SystemUtils break; } } + fclose($fh); } @@ -77,19 +79,19 @@ class SystemUtils */ public static function getRAMUsage() : int { - $memusage = 0; + $memUsage = 0; if (stristr(PHP_OS, 'LINUX')) { $free = shell_exec('free'); $free = (string) trim($free); - $free_arr = explode("\n", $free); - $mem = explode(" ", $free_arr[1]); + $freeArr = explode("\n", $free); + $mem = explode(" ", $freeArr[1]); $mem = array_filter($mem); $mem = array_merge($mem); - $memusage = $mem[2] / $mem[1] * 100; + $memUsage = $mem[2] / $mem[1] * 100; } - return (int) $memusage; + return (int) $memUsage; } /** @@ -101,15 +103,16 @@ class SystemUtils */ public static function getCpuUsage() : int { - $cpuusage = 0; + $cpuUsage = 0; if (stristr(PHP_OS, 'WIN') !== false) { - exec('wmic cpu get LoadPercentage', $cpuusage); - $cpuusage = $cpuusage[1]; + $cpuUsage = null; + exec('wmic cpu get LoadPercentage', $cpuUsage); + $cpuUsage = $cpuUsage[1]; } elseif (stristr(PHP_OS, 'LINUX') !== false) { - $cpuusage = \sys_getloadavg()[0] * 100; + $cpuUsage = \sys_getloadavg()[0] * 100; } - return (int) $cpuusage; + return (int) $cpuUsage; } } diff --git a/UnhandledHandler.php b/UnhandledHandler.php index c7595be84..2b9646afd 100644 --- a/UnhandledHandler.php +++ b/UnhandledHandler.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS; @@ -20,7 +19,6 @@ use phpOMS\Log\FileLogger; /** * Default exception and error handler. * - * @category Web * @package Web * @since 1.0.0 */ @@ -89,7 +87,7 @@ final class UnhandledHandler /** * Shutdown handler. - * + * * @return void * * @since 1.0.0 diff --git a/Uri/Http.php b/Uri/Http.php index c410ecbe4..19f41172a 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Uri * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Uri; @@ -22,11 +21,12 @@ use phpOMS\Utils\StringUtils; * * Used in order to create and evaluate a uri * - * @category Framework - * @package phpOMS/Uri + * @package phpOMS\Uri * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.Superglobals) */ class Http implements UriInterface { @@ -158,7 +158,7 @@ class Http implements UriInterface $this->path = substr($this->path, 0, -4); } - $this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; + $this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; $this->queryString = $url['query'] ?? ''; if (!empty($this->queryString)) { @@ -193,11 +193,7 @@ class Http implements UriInterface } /** - * Get root path. - * - * @return string - * - * @since 1.0.0 + * {@inheritdoc} */ public function getRootPath() : string { @@ -238,11 +234,7 @@ class Http implements UriInterface } /** - * Get password. - * - * @return string - * - * @since 1.0.0 + * {@inheritdoc} */ public function getPass() : string { @@ -256,7 +248,7 @@ class Http implements UriInterface { return $this->path; } - + /** * Get path offset. * @@ -281,9 +273,9 @@ class Http implements UriInterface /** * {@inheritdoc} */ - public function getQuery(string $key = null) /* : ?string */ + public function getQuery(string $key = null) : string { - if(isset($key)) { + if (isset($key)) { $key = strtolower($key); return $this->query[$key] ?? ''; @@ -305,7 +297,7 @@ class Http implements UriInterface */ public function getPathElements() : array { - return explode('/', $this->path); + return explode('/', $this->path); } /** @@ -345,15 +337,12 @@ class Http implements UriInterface */ public function getAuthority() : string { - return ($this->getUser() !== '' ? $this->getUser() . '@' : '') . $this->host . (isset($this->port) && $this->port !== 0 ? ':' . $this->port : ''); + return ($this->getUser() !== '' ? $this->getUser() . '@' : '') . $this->host + . (isset($this->port) && $this->port !== 0 ? ':' . $this->port : ''); } /** - * Get user. - * - * @return string - * - * @since 1.0.0 + * {@inheritdoc} */ public function getUser() : string { diff --git a/Uri/InvalidUriException.php b/Uri/InvalidUriException.php index 9da6c3316..4a45e37cc 100644 --- a/Uri/InvalidUriException.php +++ b/Uri/InvalidUriException.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Uri * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Uri; /** * Uri exception. * - * @category Framework - * @package phpOMS/Uri + * @package phpOMS\Uri * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidUriException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class InvalidUriException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 1e08c1d75..6bb91431b 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Uri * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Uri; @@ -20,10 +19,9 @@ namespace phpOMS\Uri; * * Used in order to create a uri * - * @category Framework - * @package phpOMS/Uri + * @package phpOMS\Uri * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class UriFactory @@ -90,7 +88,7 @@ class UriFactory * * @since 1.0.0 */ - public static function clearAll() : bool + public static function clearAll() : bool { self::$uri = []; @@ -120,7 +118,7 @@ class UriFactory self::setQuery(':pass', $uri->getPass()); $data = $uri->getQueryArray(); - foreach($data as $key => $value) { + foreach ($data as $key => $value) { self::setQuery('?' . $key, $value); } } @@ -134,9 +132,9 @@ class UriFactory * * @since 1.0.0 */ - public static function clear(string $key) : bool + public static function clear(string $key) : bool { - if(isset(self::$uri[$key])) { + if (isset(self::$uri[$key])) { unset(self::$uri[$key]); return true; @@ -154,12 +152,12 @@ class UriFactory * * @since 1.0.0 */ - public static function clearLike(string $pattern) : bool + public static function clearLike(string $pattern) : bool { $success = false; - foreach(self::$uri as $key => $value) { - if(((bool) preg_match('~^' . $pattern . '$~', $key))) { + foreach (self::$uri as $key => $value) { + if (((bool) preg_match('~^' . $pattern . '$~', $key))) { unset(self::$uri[$key]); $success = true; } @@ -187,7 +185,6 @@ class UriFactory $full = $parts[1]; $pars = explode('&', $full); $comps = []; - $spl = null; $length = count($pars); for ($i = 0; $i < $length; $i++) { diff --git a/Uri/UriInterface.php b/Uri/UriInterface.php index 50617e95c..99bf00bfe 100644 --- a/Uri/UriInterface.php +++ b/Uri/UriInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Uri * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Uri; /** * Uri interface. * - * @category Framework - * @package phpOMS/Uri + * @package phpOMS\Uri * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface UriInterface @@ -92,6 +90,44 @@ interface UriInterface */ public function getPath() : string; + /** + * Get user. + * + * @return string + * + * @since 1.0.0 + */ + public function getUser() : string; + + /** + * Get password. + * + * @return string + * + * @since 1.0.0 + */ + public function getPass() : string; + + /** + * Get root path. + * + * @return string + * + * @since 1.0.0 + */ + public function getRootPath() : string; + + /** + * Set root path. + * + * @param string $uri Uri + * + * @return void + * + * @since 1.0.0 + */ + public function setRootPath(string $root); /* : void */ + /** * Get path element. * @@ -117,11 +153,20 @@ interface UriInterface * * @param string $key Query key * - * @return string|array + * @return string * * @since 1.0.0 */ - public function getQuery(string $key = null); + public function getQuery(string $key = null) : string; + + /** + * Get query array. + * + * @return array + * + * @since 1.0.0 + */ + public function getQueryArray() : array; /** * Get fragment. @@ -168,5 +213,5 @@ interface UriInterface * * @since 1.0.0 */ - public function set(string $uri); + public function set(string $uri); /* : void */ } diff --git a/Uri/UriScheme.php b/Uri/UriScheme.php index 1f8f6df2d..19fb6de6b 100644 --- a/Uri/UriScheme.php +++ b/Uri/UriScheme.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Uri * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Uri; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Uri scheme. * - * @category Framework - * @package phpOMS/Uri + * @package phpOMS\Uri * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class UriScheme extends Enum diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php index a618f65fe..ab93a4a6e 100644 --- a/Utils/ArrayUtils.php +++ b/Utils/ArrayUtils.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; /** * Array utils. * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ArrayUtils @@ -97,16 +95,14 @@ class ArrayUtils if ($overwrite) { $current = $value; + } elseif (is_array($current) && !is_array($value)) { + $current[] = $value; + } elseif (is_array($current) && is_array($value)) { + $current = array_merge($current, $value); + } elseif (is_scalar($current) && $current !== null) { + $current = [$current, $value]; } else { - if (is_array($current) && !is_array($value)) { - $current[] = $value; - } elseif (is_array($current) && is_array($value)) { - $current += $value; - } elseif (is_scalar($current) && $current !== null) { - $current = [$current, $value]; - } else { - $current = $value; - } + $current = $value; } return $data; @@ -156,7 +152,7 @@ class ArrayUtils $found = self::inArrayRecursive($needle, $item); if ($found) { - break; + return true; } } } @@ -176,8 +172,8 @@ class ArrayUtils */ public static function anyInArray(array $needles, array $haystack) : bool { - foreach($needles as $needle) { - if(in_array($needle, $haystack)) { + foreach ($needles as $needle) { + if (in_array($needle, $haystack)) { return true; } } @@ -197,8 +193,8 @@ class ArrayUtils */ public static function allInArray(array $needles, array $haystack) : bool { - foreach($needles as $needle) { - if(!in_array($needle, $haystack)) { + foreach ($needles as $needle) { + if (!in_array($needle, $haystack)) { return false; } } @@ -268,7 +264,7 @@ class ArrayUtils * * @since 1.0.0 */ - public static function arrayToCSV(array $data, string $delimiter = ';', string $enclosure = '"', string $escape = '\\') : string + public static function arrayToCsv(array $data, string $delimiter = ';', string $enclosure = '"', string $escape = '\\') : string { $outstream = fopen('php://memory', 'r+'); /** @noinspection PhpMethodParametersCountMismatchInspection */ diff --git a/Utils/Barcode/Aztec.php b/Utils/Barcode/Aztec.php index c54bbc73b..0ec1e96c0 100644 --- a/Utils/Barcode/Aztec.php +++ b/Utils/Barcode/Aztec.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Aztec class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Aztec diff --git a/Utils/Barcode/C128Abstract.php b/Utils/Barcode/C128Abstract.php index 135f055f1..c77afc5e4 100644 --- a/Utils/Barcode/C128Abstract.php +++ b/Utils/Barcode/C128Abstract.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; @@ -20,11 +19,13 @@ use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Code 128 abstract class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ abstract class C128Abstract { @@ -78,6 +79,16 @@ abstract class C128Abstract */ protected $dimension = ['width' => 0, 'height' => 0]; + /** + * Barcode dimension. + * + * @todo : Implement! + * + * @var int + * @since 1.0.0 + */ + protected $margin = 10; + /** * Content to encrypt. * @@ -94,14 +105,6 @@ abstract class C128Abstract */ protected $showText = true; - /** - * Margin for barcode (padding). - * - * @var int[] - * @since 1.0.0 - */ - protected $margin = ['top' => 0, 'right' => 4, 'bottom' => 0, 'left' => 4]; - /** * Background color. * @@ -130,7 +133,7 @@ abstract class C128Abstract * * @since 1.0.0 */ - public function __construct(string $content = '', int $width = 20, int $height = 20, int $orientation = OrientationType::HORIZONTAL) + public function __construct(string $content = '', int $width = 100, int $height = 20, int $orientation = OrientationType::HORIZONTAL) { $this->content = $content; $this->setDimension($width, $height); @@ -159,6 +162,18 @@ abstract class C128Abstract $this->dimension['height'] = $height; } + /** + * Set barcode margins + * + * @param int $margin Barcode margin + * + * @since 1.0.0 + */ + public function setMargin(int $margin) /* : void */ + { + $this->margin = $margin; + } + /** * Set barcode orientation * @@ -210,7 +225,41 @@ abstract class C128Abstract { $codeString = static::$CODE_START . $this->generateCodeString() . static::$CODE_END; - return $this->createImage($codeString, 20); + return $this->createImage($codeString); + } + + /** + * Save to file + * + * @param string $file File path/name + * + * @return void + * + * @since 1.0.0 + */ + public function saveToPngFile(string $file) /* : void */ + { + $res = $this->get(); + + imagepng($res, $file); + imagedestroy($res); + } + + /** + * Save to file + * + * @param string $file File path/name + * + * @return void + * + * @since 1.0.0 + */ + public function saveToJpgFile(string $file) /* : void */ + { + $res = $this->get(); + + imagejpeg($res, $file); + imagedestroy($res); } /** @@ -229,13 +278,12 @@ abstract class C128Abstract $checksum = static::$CHECKSUM; for ($pos = 1; $pos <= $length; $pos++) { - $activeKey = substr($this->content, ($pos - 1), 1); + $activeKey = substr($this->content, ($pos - 1), 1); $codeString .= static::$CODEARRAY[$activeKey]; - $checksum += $values[$activeKey] * $pos; + $checksum += $values[$activeKey] * $pos; } $codeString .= static::$CODEARRAY[$keys[($checksum - (intval($checksum / 103) * 103))]]; - $codeString = static::$CODE_START . $codeString . static::$CODE_END; return $codeString; } @@ -244,40 +292,42 @@ abstract class C128Abstract * Create barcode image * * @param string $codeString Code string to render - * @param int $codeLength Barcode length (based on $codeString) * * @return mixed * * @since 1.0.0 */ - protected function createImage(string $codeString, int $codeLength = 20) + protected function createImage(string $codeString) { - for ($i = 1; $i <= strlen($codeString); $i++) { - $codeLength = $codeLength + (int) (substr($codeString, ($i - 1), 1)); - } - - if ($this->orientation === OrientationType::HORIZONTAL) { - $imgWidth = max($codeLength, $this->dimension['width']); - $imgHeight = $this->dimension['height']; - } else { - $imgWidth = $this->dimension['width']; - $imgHeight = max($codeLength, $this->dimension['height']); - } - - $image = imagecreate($imgWidth, $imgHeight); - $black = imagecolorallocate($image, 0, 0, 0); - $white = imagecolorallocate($image, 255, 255, 255); - $location = 0; - $length = strlen($codeString); + $dimensions = $this->calculateDimensions($codeString); + $image = imagecreate($dimensions['width'], $dimensions['height']); + $black = imagecolorallocate($image, 0, 0, 0); + $white = imagecolorallocate($image, 255, 255, 255); + $location = 0; + $length = strlen($codeString); imagefill($image, 0, 0, $white); for ($position = 1; $position <= $length; $position++) { $cur_size = $location + (int) (substr($codeString, ($position - 1), 1)); if ($this->orientation === OrientationType::HORIZONTAL) { - imagefilledrectangle($image, $location, 0, $cur_size, $imgHeight, ($position % 2 == 0 ? $white : $black)); + imagefilledrectangle( + $image, + $location + $this->margin, + 0 + $this->margin, + $cur_size + $this->margin, + $dimensions['height'] - $this->margin, + ($position % 2 == 0 ? $white : $black) + ); } else { - imagefilledrectangle($image, 0, $location, $imgWidth, $cur_size, ($position % 2 == 0 ? $white : $black)); + imagefilledrectangle( + $image, + 0 + $this->margin, + $location + $this->margin, + $dimensions['width'] - $this->margin, + $cur_size + $this->margin, + ($position % 2 == 0 ? $white : $black) + ); } $location = $cur_size; @@ -285,4 +335,50 @@ abstract class C128Abstract return $image; } + + /** + * Calculate the code length for image dimensions + * + * @param string $codeString Code string to render + * + * @return int Length of the code + * + * @since 1.0.0 + */ + private function calculateCodeLength(string $codeString) : int + { + $codeLength = 0; + $length = strlen($codeString); + + for ($i = 1; $i <= $length; $i++) { + $codeLength = $codeLength + (int) (substr($codeString, ($i - 1), 1)); + } + + return $codeLength; + } + + /** + * Calculate the code dimensions + * + * @param string $codeString Code string to render + * + * @return array + * + * @since 1.0.0 + */ + private function calculateDimensions(string $codeString) : array + { + $codeLength = $this->calculateCodeLength($codeString); + $dimensions = ['width' => 0, 'height' => 0]; + + if ($this->orientation === OrientationType::HORIZONTAL) { + $dimensions['width'] = $codeLength + $this->margin * 2; + $dimensions['height'] = $this->dimension['height']; + } else { + $dimensions['width'] = $this->dimension['width']; + $dimensions['height'] = $codeLength + $this->margin; + } + + return $dimensions; + } } diff --git a/Utils/Barcode/C128a.php b/Utils/Barcode/C128a.php index b3d953750..ed987013e 100644 --- a/Utils/Barcode/C128a.php +++ b/Utils/Barcode/C128a.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Code 128a class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class C128a extends C128Abstract { @@ -79,22 +80,6 @@ class C128a extends C128Abstract */ protected static $CODE_END = '2331112'; - /** - * Constructor - * - * @param string $content Content to encrypt - * @param int $size Barcode height - * @param int $orientation Orientation of the barcode - * - * @todo : add mirror parameter - * - * @since 1.0.0 - */ - public function __construct(string $content = '', int $size = 20, int $orientation = OrientationType::HORIZONTAL) - { - parent::__construct(strtoupper($content), $size, $orientation); - } - /** * Set content to encrypt * diff --git a/Utils/Barcode/C128b.php b/Utils/Barcode/C128b.php index 7b2464130..664610b37 100644 --- a/Utils/Barcode/C128b.php +++ b/Utils/Barcode/C128b.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Code 128b class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class C128b extends C128Abstract { diff --git a/Utils/Barcode/C128c.php b/Utils/Barcode/C128c.php index 243b734b6..3e46398c2 100644 --- a/Utils/Barcode/C128c.php +++ b/Utils/Barcode/C128c.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Code 128c class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class C128c extends C128Abstract { @@ -102,7 +103,7 @@ class C128c extends C128Abstract } $codeString .= self::$CODEARRAY[$activeKey]; - $checksum += $values[$activeKey] * $checkPos; + $checksum += $values[$activeKey] * $checkPos; $checkPos++; } diff --git a/Utils/Barcode/C25.php b/Utils/Barcode/C25.php index 642e70253..58ebfd372 100644 --- a/Utils/Barcode/C25.php +++ b/Utils/Barcode/C25.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Code 25 class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class C25 extends C128Abstract { @@ -65,20 +66,21 @@ class C25 extends C128Abstract * Constructor * * @param string $content Content to encrypt - * @param int $size Barcode height + * @param int $width Barcode width + * @param int $height Barcode height * @param int $orientation Orientation of the barcode * * @todo : add mirror parameter * * @since 1.0.0 */ - public function __construct(string $content = '', int $size = 20, int $orientation = OrientationType::HORIZONTAL) + public function __construct(string $content = '', int $width = 100, int $height = 20, int $orientation = OrientationType::HORIZONTAL) { if (!ctype_digit($content)) { throw new \InvalidArgumentException($content); } - parent::__construct($content, $size, $orientation); + parent::__construct($content, $width, $height, $orientation); } /** diff --git a/Utils/Barcode/C39.php b/Utils/Barcode/C39.php index c09e3c7ba..2bb44c75a 100644 --- a/Utils/Barcode/C39.php +++ b/Utils/Barcode/C39.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Code 39 class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class C39 extends C128Abstract { @@ -60,22 +61,6 @@ class C39 extends C128Abstract */ protected static $CODE_END = '121121211'; - /** - * Constructor - * - * @param string $content Content to encrypt - * @param int $size Barcode height - * @param int $orientation Orientation of the barcode - * - * @todo : add mirror parameter - * - * @since 1.0.0 - */ - public function __construct(string $content = '', int $size = 20, int $orientation = OrientationType::HORIZONTAL) - { - parent::__construct(strtoupper($content), $size, $orientation); - } - /** * Set content to encrypt * diff --git a/Utils/Barcode/Codebar.php b/Utils/Barcode/Codebar.php index 841d0f264..25998868f 100644 --- a/Utils/Barcode/Codebar.php +++ b/Utils/Barcode/Codebar.php @@ -4,25 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Codebar class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCasePropertyName) + * @SuppressWarnings(PHPMD.CamelCaseVariableName) */ class Codebar extends C128Abstract { @@ -61,22 +62,6 @@ class Codebar extends C128Abstract */ protected static $CODE_END = '1122121'; - /** - * Constructor - * - * @param string $content Content to encrypt - * @param int $size Barcode height - * @param int $orientation Orientation of the barcode - * - * @todo : add mirror parameter - * - * @since 1.0.0 - */ - public function __construct(string $content = '', int $size = 20, int $orientation = OrientationType::HORIZONTAL) - { - parent::__construct(strtoupper($content), $size, $orientation); - } - /** * Set content to encrypt * diff --git a/Utils/Barcode/Datamatrix.php b/Utils/Barcode/Datamatrix.php index 0cd822e88..50fa61058 100644 --- a/Utils/Barcode/Datamatrix.php +++ b/Utils/Barcode/Datamatrix.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Aztec class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Datamatrix diff --git a/Utils/Barcode/HIBCC.php b/Utils/Barcode/HIBCC.php index 3c20394e3..b02443524 100644 --- a/Utils/Barcode/HIBCC.php +++ b/Utils/Barcode/HIBCC.php @@ -4,35 +4,40 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Aztec class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class HIBCC { private $identifier = ''; + private $productId = ''; + private $measureOfUnit = 0; + private $dateFormat = ''; + private $expirationDate = null; + private $productionDate = null; + private $lot = ''; + private $checkValue = 0; public function __construct() @@ -100,12 +105,12 @@ class HIBCC return $this->productionDate; } - public function setLOT(string $lot) /* : void */ + public function setLot(string $lot) /* : void */ { $this->lot = $lot; } - public function getLOT() : string + public function getLot() : string { return $this->lot; } @@ -115,15 +120,13 @@ class HIBCC return $this->checkValue; } - public function getPrimaryDI() : string + public function getPrimaryDi() : string { return ''; } - public function getSecondaryDI() : string + public function getSecondaryDi() : string { return ''; } - - } diff --git a/Utils/Barcode/OrientationType.php b/Utils/Barcode/OrientationType.php index 38bc5ebb1..e4a083105 100644 --- a/Utils/Barcode/OrientationType.php +++ b/Utils/Barcode/OrientationType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; @@ -20,14 +19,13 @@ use phpOMS\Stdlib\Base\Enum; /** * Account type enum. * - * @category Framework - * @package phpOMS\DataStorage\Database + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class OrientationType extends Enum { /* public */ const HORIZONTAL = 0; - /* public */ const VERTICAL = 1; + /* public */ const VERTICAL = 1; } diff --git a/Utils/Barcode/QR.php b/Utils/Barcode/QR.php index d93397a09..c82595007 100644 --- a/Utils/Barcode/QR.php +++ b/Utils/Barcode/QR.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Barcode; /** * Aztec class. * - * @category Log - * @package Framework + * @package Log * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class QR diff --git a/Utils/ColorUtils.php b/Utils/ColorUtils.php index 51f9a797c..608604816 100644 --- a/Utils/ColorUtils.php +++ b/Utils/ColorUtils.php @@ -4,81 +4,27 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; /** * Color class for color operations. * - * @category Framework - * @package phpOMS\Asset + * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ColorUtils { - /** - * Creates a 3 point gradient based on a input value. - * - * @param int $value Value to represent by color - * @param int[] $start Gradient start - * @param int[] $stop Gradient stop - * @param int[] $end Gradient end - * - * @return array - * - * @since 1.0.0 - */ - public static function getRGBGradient(int $value, array $start, array $stop, array $end) : array - { - $diff = []; - $gradient = []; - - if ($value <= $stop[0]) { - if ($value < $start[0]) { - $value = $start[0]; - } - } else { - if ($value > $end[0]) { - $value = $end[0]; - } - - $start = $stop; - $stop = $end; - } - - $diff[0] = $stop[0] - $start[0]; - $diff[1] = $stop[1] - $start[1]; - $diff[2] = $stop[2] - $start[2]; - $diff[3] = $stop[3] - $start[3]; - - $gradient['r'] = $start[1] + ($value - $start[0]) / ($diff[0]) * $diff[1]; - $gradient['g'] = $start[2] + ($value - $start[0]) / ($diff[0]) * $diff[2]; - $gradient['b'] = $start[3] + ($value - $start[0]) / ($diff[0]) * $diff[3]; - - foreach ($gradient as &$color) { - if ($color > 255) { - $color = 255; - } elseif ($color < 0) { - $color = 0; - } else { - $color = (int) $color; - } - } - - return $gradient; - } - /** * Convert int to rgb * @@ -98,4 +44,22 @@ class ColorUtils return $rgb; } + + /** + * Convert rgb to int + * + * @param array $rgb Int rgb array + * + * @return int + * + * @since 1.0.0 + */ + public static function rgbToInt(array $rgb) : int + { + $i = (255 & $rgb['r']) << 16; + $i += (255 & $rgb['g']) << 8; + $i += (255 & $rgb['b']); + + return $i; + } } diff --git a/Utils/Compression/CompressionInterface.php b/Utils/Compression/CompressionInterface.php index 9368cd280..d67d2c2ae 100644 --- a/Utils/Compression/CompressionInterface.php +++ b/Utils/Compression/CompressionInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Compression; /** * Compression Interface * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface CompressionInterface @@ -47,4 +45,4 @@ interface CompressionInterface * @since 1.0.0 */ public function decompress(string $compressed) : string; -} \ No newline at end of file +} diff --git a/Utils/Compression/LZW.php b/Utils/Compression/LZW.php index d50504208..80e58b98f 100644 --- a/Utils/Compression/LZW.php +++ b/Utils/Compression/LZW.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Compression; /** * LZW compression class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LZW implements CompressionInterface @@ -32,7 +30,6 @@ class LZW implements CompressionInterface */ public function compress(string $source) : string { - $wc = ''; $w = ''; $dictionary = []; $result = []; @@ -86,19 +83,17 @@ class LZW implements CompressionInterface if ($dictionary[$k]) { $entry = $dictionary[$k]; - } else { - if ($k !== $dictSize) { - throw new \Exception('Wrong dictionary size!' . $k . '.' . $dictSize); - } - + } elseif ($k === $dictSize) { $entry = $w . $w[0]; + } else { + throw new \Exception('Wrong dictionary size!' . $k . '.' . $dictSize); } - $result .= $entry; + $result .= $entry; $dictionary[$dictSize++] = $w . $entry[0]; $w = $entry; } return $result; } -} \ No newline at end of file +} diff --git a/Utils/Converter/AngleType.php b/Utils/Converter/AngleType.php index 21137e848..49f353a13 100644 --- a/Utils/Converter/AngleType.php +++ b/Utils/Converter/AngleType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,22 +19,21 @@ use phpOMS\Stdlib\Base\Enum; /** * Speed type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AngleType extends Enum { - /* public */ const DEGREE = 'deg'; - /* public */ const RADIAN = 'rad'; - /* public */ const SECOND = 'arcsec'; - /* public */ const MINUTE = 'arcmin'; - /* public */ const MILLIRADIAN_US = 'mil (us ww2)'; - /* public */ const MILLIRADIAN_UK = 'mil (uk)'; + /* public */ const DEGREE = 'deg'; + /* public */ const RADIAN = 'rad'; + /* public */ const SECOND = 'arcsec'; + /* public */ const MINUTE = 'arcmin'; + /* public */ const MILLIRADIAN_US = 'mil (us ww2)'; + /* public */ const MILLIRADIAN_UK = 'mil (uk)'; /* public */ const MILLIRADIAN_USSR = 'mil (ussr)'; /* public */ const MILLIRADIAN_NATO = 'mil (nato)'; - /* public */ const GRADIAN = 'g'; - /* public */ const CENTRAD = 'crad'; + /* public */ const GRADIAN = 'g'; + /* public */ const CENTRAD = 'crad'; } diff --git a/Utils/Converter/AreaType.php b/Utils/Converter/AreaType.php index d499dbb92..c8cac87d2 100644 --- a/Utils/Converter/AreaType.php +++ b/Utils/Converter/AreaType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,25 +19,24 @@ use phpOMS\Stdlib\Base\Enum; /** * Area type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class AreaType extends Enum { - /* public */ const SQUARE_FEET = 'ft'; - /* public */ const SQUARE_METERS = 'm'; - /* public */ const SQUARE_KILOMETERS = 'km'; - /* public */ const SQUARE_MILES = 'mi'; - /* public */ const SQUARE_YARDS = 'yd'; - /* public */ const SQUARE_INCHES = 'in'; + /* public */ const SQUARE_FEET = 'ft'; + /* public */ const SQUARE_METERS = 'm'; + /* public */ const SQUARE_KILOMETERS = 'km'; + /* public */ const SQUARE_MILES = 'mi'; + /* public */ const SQUARE_YARDS = 'yd'; + /* public */ const SQUARE_INCHES = 'in'; /* public */ const SQUARE_MICROINCHES = 'muin'; /* public */ const SQUARE_CENTIMETERS = 'cm'; - /* public */ const SQUARE_MILIMETERS = 'mm'; + /* public */ const SQUARE_MILIMETERS = 'mm'; /* public */ const SQUARE_MICROMETERS = 'micron'; - /* public */ const SQUARE_DECIMETERS = 'dm'; - /* public */ const HECTARES = 'ha'; - /* public */ const ACRES = 'ac'; + /* public */ const SQUARE_DECIMETERS = 'dm'; + /* public */ const HECTARES = 'ha'; + /* public */ const ACRES = 'ac'; } diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 06be05c61..cd6217982 100644 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -19,16 +18,14 @@ use phpOMS\Localization\ISO4217CharEnum; use phpOMS\Message\Http\Rest; use phpOMS\Message\Http\Request; use phpOMS\Message\Http\RequestMethod; -use phpOMS\Localization\Localization; use phpOMS\Uri\Http; /** * Currency converter. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Currency @@ -99,18 +96,18 @@ class Currency { if (!isset(self::$ecbCurrencies)) { $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)); if (!isset($xml->Cube)) { throw new \Exception('Invalid xml path'); - - } - $node = $xml->Cube->Cube->Cube; + } + + $node = $xml->Cube->Cube->Cube; self::$ecbCurrencies = []; - + foreach ($node as $key => $value) { self::$ecbCurrencies[strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate']; } diff --git a/Utils/Converter/EnergyPowerType.php b/Utils/Converter/EnergyPowerType.php index caaa22def..3768f3fe9 100644 --- a/Utils/Converter/EnergyPowerType.php +++ b/Utils/Converter/EnergyPowerType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,21 +19,20 @@ use phpOMS\Stdlib\Base\Enum; /** * Speed type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class EnergyPowerType extends Enum { /* public */ const KILOWATT_HOUERS = 'kWh'; /* public */ const MEGAWATT_HOUERS = 'MWh'; - /* public */ const KILOTONS = 'kt'; - /* public */ const JOULS = 'J'; - /* public */ const CALORIES = 'Cal'; - /* public */ const BTU = 'BTU'; - /* public */ const KILOJOULS = 'kJ'; - /* public */ const THERMEC = 'thmEC'; - /* public */ const NEWTON_METERS = 'Nm'; + /* public */ const KILOTONS = 'kt'; + /* public */ const JOULS = 'J'; + /* public */ const CALORIES = 'Cal'; + /* public */ const BTU = 'BTU'; + /* public */ const KILOJOULS = 'kJ'; + /* public */ const THERMEC = 'thmEC'; + /* public */ const NEWTON_METERS = 'Nm'; } diff --git a/Utils/Converter/File.php b/Utils/Converter/File.php index 14430409c..c4931903d 100644 --- a/Utils/Converter/File.php +++ b/Utils/Converter/File.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; /** * File converter. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class File diff --git a/Utils/Converter/FileSizeType.php b/Utils/Converter/FileSizeType.php index 36c68c59e..c937336c0 100644 --- a/Utils/Converter/FileSizeType.php +++ b/Utils/Converter/FileSizeType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,22 +19,21 @@ use phpOMS\Stdlib\Base\Enum; /** * File size type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class FileSizeType extends Enum { /* public */ const TERRABYTE = 'TB'; - /* public */ const GIGABYTE = 'GB'; - /* public */ const MEGABYTE = 'MB'; - /* public */ const KILOBYTE = 'KB'; - /* public */ const BYTE = 'B'; - /* public */ const TERRABIT = 'tbit'; - /* public */ const GIGABIT = 'gbit'; - /* public */ const MEGABIT = 'mbit'; - /* public */ const KILOBIT = 'kbit'; - /* public */ const BIT = 'bit'; + /* public */ const GIGABYTE = 'GB'; + /* public */ const MEGABYTE = 'MB'; + /* public */ const KILOBYTE = 'KB'; + /* public */ const BYTE = 'B'; + /* public */ const TERRABIT = 'tbit'; + /* public */ const GIGABIT = 'gbit'; + /* public */ const MEGABIT = 'mbit'; + /* public */ const KILOBIT = 'kbit'; + /* public */ const BIT = 'bit'; } diff --git a/Utils/Converter/Ip.php b/Utils/Converter/Ip.php index 87fa6c88e..25c5cb9bf 100644 --- a/Utils/Converter/Ip.php +++ b/Utils/Converter/Ip.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; /** * Ip converter. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Ip @@ -38,10 +36,17 @@ class Ip { } + /** + * Convert ip to float + * + * @param string $ip IP + * + * @since 1.0.0 + */ public static function ip2Float(string $ip) : float { $split = explode('.', $ip); return $split[0] * (256 ** 3) + $split[1] * (256 ** 2) + $split[2] * (256 ** 1) + $split[3]; } -} \ No newline at end of file +} diff --git a/Utils/Converter/LengthType.php b/Utils/Converter/LengthType.php index bfda7cd3c..a36dc2e29 100644 --- a/Utils/Converter/LengthType.php +++ b/Utils/Converter/LengthType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,33 +19,32 @@ use phpOMS\Stdlib\Base\Enum; /** * Length type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class LengthType extends Enum { - /* public */ const MILES = 'mi'; - /* public */ const METERS = 'm'; - /* public */ const MICROMETER = 'micron'; - /* public */ const CENTIMETERS = 'cm'; - /* public */ const MILLIMETERS = 'mm'; - /* public */ const KILOMETERS = 'km'; - /* public */ const CHAINS = 'ch'; - /* public */ const FEET = 'ft'; - /* public */ const FURLONGS = 'fur'; - /* public */ const MICROINCH = 'muin'; - /* public */ const INCHES = 'in'; - /* public */ const YARDS = 'yd'; - /* public */ const PARSECS = 'pc'; - /* public */ const UK_NAUTICAL_MILES = 'uk nmi'; - /* public */ const US_NAUTICAL_MILES = 'us nmi'; + /* public */ const MILES = 'mi'; + /* public */ const METERS = 'm'; + /* public */ const MICROMETER = 'micron'; + /* public */ const CENTIMETERS = 'cm'; + /* public */ const MILLIMETERS = 'mm'; + /* public */ const KILOMETERS = 'km'; + /* public */ const CHAINS = 'ch'; + /* public */ const FEET = 'ft'; + /* public */ const FURLONGS = 'fur'; + /* public */ const MICROINCH = 'muin'; + /* public */ const INCHES = 'in'; + /* public */ const YARDS = 'yd'; + /* public */ const PARSECS = 'pc'; + /* public */ const UK_NAUTICAL_MILES = 'uk nmi'; + /* public */ const US_NAUTICAL_MILES = 'us nmi'; /* public */ const UK_NAUTICAL_LEAGUES = 'uk nl'; - /* public */ const NAUTICAL_LEAGUES = 'nl'; - /* public */ const UK_LEAGUES = 'uk lg'; - /* public */ const US_LEAGUES = 'us lg'; - /* public */ const LIGHTYEARS = 'ly'; - /* public */ const DECIMETERS = 'dm'; + /* public */ const NAUTICAL_LEAGUES = 'nl'; + /* public */ const UK_LEAGUES = 'uk lg'; + /* public */ const US_LEAGUES = 'us lg'; + /* public */ const LIGHTYEARS = 'ly'; + /* public */ const DECIMETERS = 'dm'; } diff --git a/Utils/Converter/Measurement.php b/Utils/Converter/Measurement.php index 8975cf0b2..02c644fec 100644 --- a/Utils/Converter/Measurement.php +++ b/Utils/Converter/Measurement.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; /** * Measurement converter. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Measurement @@ -50,33 +48,7 @@ class Measurement public static function convertTemperature(float $value, string $from = TemperatureType::FAHRENHEIT, string $to = TemperatureType::CELSIUS) : float { // to kelving - switch ($from) { - case TemperatureType::KELVIN: - break; - case TemperatureType::CELSIUS: - $value += 273.15; - break; - case TemperatureType::FAHRENHEIT: - $value = ($value - 32) / 1.8 + 273.5; - break; - case TemperatureType::REAUMUR: - $value = $value / 0.8 + 273.15; - break; - case TemperatureType::RANKINE: - $value = ($value - 491.67) / 1.8 + 273.15; - break; - case TemperatureType::DELISLE: - $value = ($value + 100) / 1.5 + 273.15; - break; - case TemperatureType::NEWTON: - $value = $value / 0.33 + 273.15; - break; - case TemperatureType::ROMER: - $value = ($value - 7.5) / 0.525 + 273.15; - break; - default: - throw new \InvalidArgumentException('Temperature not supported'); - } + $value = self::normalizeTemperature($value, $from); switch ($to) { case TemperatureType::KELVIN: @@ -109,6 +81,49 @@ class Measurement return $value; } + /** + * Convert temperature. + * + * @param float $value Value to convert + * @param string $from Input temperature + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeTemperature(float $value, string $from) : float + { + switch ($from) { + case TemperatureType::KELVIN: + break; + case TemperatureType::CELSIUS: + $value += 273.15; + break; + case TemperatureType::FAHRENHEIT: + $value = ($value - 32) / 1.8 + 273.5; + break; + case TemperatureType::REAUMUR: + $value = $value / 0.8 + 273.15; + break; + case TemperatureType::RANKINE: + $value = ($value - 491.67) / 1.8 + 273.15; + break; + case TemperatureType::DELISLE: + $value = ($value + 100) / 1.5 + 273.15; + break; + case TemperatureType::NEWTON: + $value = $value / 0.33 + 273.15; + break; + case TemperatureType::ROMER: + $value = ($value - 7.5) / 0.525 + 273.15; + break; + default: + throw new \InvalidArgumentException('Temperature not supported'); + } + + return $value; + } + /** * Convert weight. * @@ -123,51 +138,7 @@ class Measurement public static function convertWeight(float $value, string $from = WeightType::GRAM, string $to = WeightType::KILOGRAM) : float { // to gram - switch ($from) { - case WeightType::GRAM: - break; - case WeightType::MICROGRAM: - $value /= 1000000; - break; - case WeightType::MILLIGRAM: - $value /= 1000; - break; - case WeightType::KILOGRAM: - $value *= 1000; - break; - case WeightType::METRIC_TONS: - $value *= 1000000; - break; - case WeightType::STONES: - $value /= 0.15747 * 1000; - break; - case WeightType::OUNCES: - $value /= 0.035274; - break; - case WeightType::POUNDS: - $value /= 0.0022046; - break; - case WeightType::GRAIN: - $value /= 15.432; - break; - case WeightType::CARAT: - $value /= 5.0; - break; - case WeightType::LONG_TONS: - $value /= 9.8420653e-07; - break; - case WeightType::SHORT_TONS: - $value /= 1.1023113e-06; - break; - case WeightType::TROY_POUNDS: - $value /= 0.0026792; - break; - case WeightType::TROY_OUNCES: - $value /= 0.032151; - break; - default: - throw new \InvalidArgumentException('Weight not supported'); - } + $value = self::normalizeWeight($value, $from); switch ($to) { case WeightType::GRAM: @@ -218,6 +189,67 @@ class Measurement return $value; } + /** + * Convert weight. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeWeight(float $value, string $from) : float + { + switch ($from) { + case WeightType::GRAM: + break; + case WeightType::MICROGRAM: + $value /= 1000000; + break; + case WeightType::MILLIGRAM: + $value /= 1000; + break; + case WeightType::KILOGRAM: + $value *= 1000; + break; + case WeightType::METRIC_TONS: + $value *= 1000000; + break; + case WeightType::STONES: + $value /= 0.15747 * 1000; + break; + case WeightType::OUNCES: + $value /= 0.035274; + break; + case WeightType::POUNDS: + $value /= 0.0022046; + break; + case WeightType::GRAIN: + $value /= 15.432; + break; + case WeightType::CARAT: + $value /= 5.0; + break; + case WeightType::LONG_TONS: + $value /= 9.8420653e-07; + break; + case WeightType::SHORT_TONS: + $value /= 1.1023113e-06; + break; + case WeightType::TROY_POUNDS: + $value /= 0.0026792; + break; + case WeightType::TROY_OUNCES: + $value /= 0.032151; + break; + default: + throw new \InvalidArgumentException('Weight not supported'); + } + + return $value; + } + /** * Convert length. * @@ -232,72 +264,7 @@ class Measurement public static function convertLength(float $value, string $from = LengthType::METERS, string $to = LengthType::KILOMETERS) : float { // to meter - switch ($from) { - case LengthType::METERS: - break; - case LengthType::MILES: - $value /= 0.00062137; - break; - case LengthType::MICROMETER: - $value /= 1000000; - break; - case LengthType::CENTIMETERS: - $value /= 100; - break; - case LengthType::MILLIMETERS: - $value /= 1000; - break; - case LengthType::KILOMETERS: - $value *= 1000; - break; - case LengthType::CHAINS: - $value /= 0.049710; - break; - case LengthType::FEET: - $value /= 3.2808; - break; - case LengthType::FURLONGS: - $value /= 0.0049710; - break; - case LengthType::MICROINCH: - $value /= 39370000; - break; - case LengthType::INCHES: - $value /= 39.370; - break; - case LengthType::YARDS: - $value /= 1.0936; - break; - case LengthType::PARSECS: - $value /= 3.2407793e-17; - break; - case LengthType::UK_NAUTICAL_MILES: - $value /= 0.00053961; - break; - case LengthType::US_NAUTICAL_MILES: - $value /= 0.00053996; - break; - case LengthType::UK_NAUTICAL_LEAGUES: - $value /= 0.00017987; - break; - case LengthType::UK_LEAGUES: - $value /= 0.00020700; - break; - case LengthType::US_LEAGUES: - $value /= 0.00020712; - break; - case LengthType::NAUTICAL_LEAGUES: - $value /= 0.00017999; - break; - case LengthType::LIGHTYEARS: - $value /= 1.0570008e-16; - break; - case LengthType::DECIMETERS: - $value /= 10; - break; - default: - throw new \InvalidArgumentException('Length not supported'); - } + $value = self::normalizeLength($value, $from); switch ($to) { case LengthType::METERS: @@ -369,6 +336,88 @@ class Measurement return $value; } + /** + * Convert length. + * + * @param float $value Value to convert + * @param string $from Input length + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeLength(float $value, string $from) : float + { + switch ($from) { + case LengthType::METERS: + break; + case LengthType::MILES: + $value /= 0.00062137; + break; + case LengthType::MICROMETER: + $value /= 1000000; + break; + case LengthType::CENTIMETERS: + $value /= 100; + break; + case LengthType::MILLIMETERS: + $value /= 1000; + break; + case LengthType::KILOMETERS: + $value *= 1000; + break; + case LengthType::CHAINS: + $value /= 0.049710; + break; + case LengthType::FEET: + $value /= 3.2808; + break; + case LengthType::FURLONGS: + $value /= 0.0049710; + break; + case LengthType::MICROINCH: + $value /= 39370000; + break; + case LengthType::INCHES: + $value /= 39.370; + break; + case LengthType::YARDS: + $value /= 1.0936; + break; + case LengthType::PARSECS: + $value /= 3.2407793e-17; + break; + case LengthType::UK_NAUTICAL_MILES: + $value /= 0.00053961; + break; + case LengthType::US_NAUTICAL_MILES: + $value /= 0.00053996; + break; + case LengthType::UK_NAUTICAL_LEAGUES: + $value /= 0.00017987; + break; + case LengthType::UK_LEAGUES: + $value /= 0.00020700; + break; + case LengthType::US_LEAGUES: + $value /= 0.00020712; + break; + case LengthType::NAUTICAL_LEAGUES: + $value /= 0.00017999; + break; + case LengthType::LIGHTYEARS: + $value /= 1.0570008e-16; + break; + case LengthType::DECIMETERS: + $value /= 10; + break; + default: + throw new \InvalidArgumentException('Length not supported'); + } + + return $value; + } + /** * Convert area. * @@ -383,48 +432,7 @@ class Measurement public static function convertArea(float $value, string $from = AreaType::SQUARE_METERS, string $to = AreaType::SQUARE_KILOMETERS) : float { // to square meter - switch ($from) { - case AreaType::SQUARE_METERS: - break; - case AreaType::SQUARE_FEET: - $value /= 10.764; - break; - case AreaType::SQUARE_KILOMETERS: - $value *= 1000000; - break; - case AreaType::SQUARE_MILES: - $value /= 3.8610216e-07; - break; - case AreaType::SQUARE_YARDS: - $value /= 1.1960; - break; - case AreaType::SQUARE_INCHES: - $value /= 1550; - break; - case AreaType::SQUARE_MICROINCHES: - $value /= 1.550031e+15; - break; - case AreaType::SQUARE_CENTIMETERS: - $value /= 10000; - break; - case AreaType::SQUARE_MILIMETERS: - $value /= 1000000; - break; - case AreaType::SQUARE_MICROMETERS: - $value /= 1000000000000; - break; - case AreaType::SQUARE_DECIMETERS: - $value /= 100; - break; - case AreaType::HECTARES: - $value *= 10000; - break; - case AreaType::ACRES: - $value /= 0.00024711; - break; - default: - throw new \InvalidArgumentException('Area not supported'); - } + $value = self::normalizeArea($value, $from); switch ($to) { case AreaType::SQUARE_METERS: @@ -472,6 +480,64 @@ class Measurement return $value; } + /** + * Convert area. + * + * @param float $value Value to convert + * @param string $from Input length + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeArea(float $value, string $from) : float + { + switch ($from) { + case AreaType::SQUARE_METERS: + break; + case AreaType::SQUARE_FEET: + $value /= 10.764; + break; + case AreaType::SQUARE_KILOMETERS: + $value *= 1000000; + break; + case AreaType::SQUARE_MILES: + $value /= 3.8610216e-07; + break; + case AreaType::SQUARE_YARDS: + $value /= 1.1960; + break; + case AreaType::SQUARE_INCHES: + $value /= 1550; + break; + case AreaType::SQUARE_MICROINCHES: + $value /= 1.550031e+15; + break; + case AreaType::SQUARE_CENTIMETERS: + $value /= 10000; + break; + case AreaType::SQUARE_MILIMETERS: + $value /= 1000000; + break; + case AreaType::SQUARE_MICROMETERS: + $value /= 1000000000000; + break; + case AreaType::SQUARE_DECIMETERS: + $value /= 100; + break; + case AreaType::HECTARES: + $value *= 10000; + break; + case AreaType::ACRES: + $value /= 0.00024711; + break; + default: + throw new \InvalidArgumentException('Area not supported'); + } + + return $value; + } + /** * Convert volume. * @@ -486,123 +552,7 @@ class Measurement public static function convertVolume(float $value, string $from = VolumeType::LITER, string $to = VolumeType::LITER) : float { // to square meter - switch ($from) { - case VolumeType::LITER: - break; - case VolumeType::US_GALLON_LIQUID: - $value /= 0.26417; - break; - case VolumeType::UK_GALLON: - $value /= 0.21997; - break; - case VolumeType::US_PINT_LIQUID: - $value /= 2.1134; - break; - case VolumeType::UK_PINT: - $value /= 1.7598; - break; - case VolumeType::CENTILITER: - $value /= 100; - break; - case VolumeType::MILLILITER: - $value /= 1000; - break; - case VolumeType::CUBIC_METER: - $value *= 1000; - break; - case VolumeType::UK_BARREL: - $value /= 0.0061103; - break; - case VolumeType::US_GALLON_DRY: - $value /= 0.22702; - break; - case VolumeType::CUBIC_FEET: - $value /= 0.035315; - break; - case VolumeType::US_QUARTS_LIQUID: - $value /= 1.0567; - break; - case VolumeType::US_QUARTS_DRY: - $value /= 0.90808; - break; - case VolumeType::UK_QUARTS: - $value /= 0.87988; - break; - case VolumeType::US_PINT_DRY: - $value /= 1.8162; - break; - case VolumeType::US_CUP: - $value /= 4.2268; - break; - case VolumeType::CAN_CUP: - $value /= 4.3994; - break; - case VolumeType::METRIC_CUP: - $value /= 4; - break; - case VolumeType::US_GILL: - $value /= 8.4535; - break; - case VolumeType::US_TABLESPOON: - $value /= 67.628; - break; - case VolumeType::UK_TABLESPOON: - $value /= 70.390; - break; - case VolumeType::METRIC_TABLESPOON: - $value /= 66.667; - break; - case VolumeType::US_TEASPOON: - $value /= 202.88; - break; - case VolumeType::UK_TEASPOON: - $value /= 281.56; - break; - case VolumeType::METRIC_TEASPOON: - $value /= 200; - break; - case VolumeType::US_OUNCES: - $value /= 33.814; - break; - case VolumeType::UK_OUNCES: - $value /= 35.195; - break; - case VolumeType::CUBIC_INCH: - $value /= 61.024; - break; - case VolumeType::CUBIC_CENTIMETER: - $value /= 1000; - break; - case VolumeType::CUBIC_MILLIMETER: - $value /= 1000000; - break; - case VolumeType::MICROLITER: - $value /= 1000000; - break; - case VolumeType::KILOLITER: - $value /= 1000; - break; - case VolumeType::UK_GILL: - $value /= 7.0390; - break; - case VolumeType::CUBIC_YARD: - $value /= 0.0013080; - break; - case VolumeType::US_BARREL_DRY: - $value /= 0.0086485; - break; - case VolumeType::US_BARREL_LIQUID: - $value /= 0.0083864; - break; - case VolumeType::US_BARREL_OIL: - $value /= 0.0062898; - break; - case VolumeType::US_BARREL_FEDERAL: - $value /= 0.0085217; - break; - default: - throw new \InvalidArgumentException('Volume not supported'); - } + $value = self::normalizeVolume($value, $from); switch ($to) { case VolumeType::LITER: @@ -725,6 +675,139 @@ class Measurement return $value; } + /** + * Convert volume. + * + * @param float $value Value to convert + * @param string $from Input volume + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeVolume(float $value, string $from) : float + { + switch ($from) { + case VolumeType::LITER: + break; + case VolumeType::US_GALLON_LIQUID: + $value /= 0.26417; + break; + case VolumeType::UK_GALLON: + $value /= 0.21997; + break; + case VolumeType::US_PINT_LIQUID: + $value /= 2.1134; + break; + case VolumeType::UK_PINT: + $value /= 1.7598; + break; + case VolumeType::CENTILITER: + $value /= 100; + break; + case VolumeType::MILLILITER: + $value /= 1000; + break; + case VolumeType::CUBIC_METER: + $value *= 1000; + break; + case VolumeType::UK_BARREL: + $value /= 0.0061103; + break; + case VolumeType::US_GALLON_DRY: + $value /= 0.22702; + break; + case VolumeType::CUBIC_FEET: + $value /= 0.035315; + break; + case VolumeType::US_QUARTS_LIQUID: + $value /= 1.0567; + break; + case VolumeType::US_QUARTS_DRY: + $value /= 0.90808; + break; + case VolumeType::UK_QUARTS: + $value /= 0.87988; + break; + case VolumeType::US_PINT_DRY: + $value /= 1.8162; + break; + case VolumeType::US_CUP: + $value /= 4.2268; + break; + case VolumeType::CAN_CUP: + $value /= 4.3994; + break; + case VolumeType::METRIC_CUP: + $value /= 4; + break; + case VolumeType::US_GILL: + $value /= 8.4535; + break; + case VolumeType::US_TABLESPOON: + $value /= 67.628; + break; + case VolumeType::UK_TABLESPOON: + $value /= 70.390; + break; + case VolumeType::METRIC_TABLESPOON: + $value /= 66.667; + break; + case VolumeType::US_TEASPOON: + $value /= 202.88; + break; + case VolumeType::UK_TEASPOON: + $value /= 281.56; + break; + case VolumeType::METRIC_TEASPOON: + $value /= 200; + break; + case VolumeType::US_OUNCES: + $value /= 33.814; + break; + case VolumeType::UK_OUNCES: + $value /= 35.195; + break; + case VolumeType::CUBIC_INCH: + $value /= 61.024; + break; + case VolumeType::CUBIC_CENTIMETER: + $value /= 1000; + break; + case VolumeType::CUBIC_MILLIMETER: + $value /= 1000000; + break; + case VolumeType::MICROLITER: + $value /= 1000000; + break; + case VolumeType::KILOLITER: + $value /= 1000; + break; + case VolumeType::UK_GILL: + $value /= 7.0390; + break; + case VolumeType::CUBIC_YARD: + $value /= 0.0013080; + break; + case VolumeType::US_BARREL_DRY: + $value /= 0.0086485; + break; + case VolumeType::US_BARREL_LIQUID: + $value /= 0.0083864; + break; + case VolumeType::US_BARREL_OIL: + $value /= 0.0062898; + break; + case VolumeType::US_BARREL_FEDERAL: + $value /= 0.0085217; + break; + default: + throw new \InvalidArgumentException('Volume not supported'); + } + + return $value; + } + /** * Convert speed. * @@ -739,111 +822,7 @@ class Measurement public static function convertSpeed(float $value, string $from = SpeedType::KILOMETERS_PER_HOUR, string $to = SpeedType::KILOMETERS_PER_HOUR) : float { // to kph - switch ($from) { - case SpeedType::KILOMETERS_PER_HOUR: - break; - case SpeedType::MILES_PER_DAY: - $value = $value / 24 * 1.60934; - break; - case SpeedType::MILES_PER_HOUR: - $value *= 1.60934; - break; - case SpeedType::MILES_PER_MINUTE: - $value *= 60 * 1.60934; - break; - case SpeedType::MILES_PER_SECOND: - $value *= 60 * 60 * 1.60934; - break; - case SpeedType::KILOMETERS_PER_DAY: - $value /= 24; - break; - case SpeedType::KILOMETERS_PER_MINUTE: - $value *= 60; - break; - case SpeedType::KILOMETERS_PER_SECOND: - $value *= 60 * 60; - break; - case SpeedType::METERS_PER_DAY: - $value = $value / 24 / 1000; - break; - case SpeedType::METERS_PER_HOUR: - $value /= 1000; - break; - case SpeedType::METERS_PER_MINUTE: - $value *= 60 / 1000; - break; - case SpeedType::METERS_PER_SECOND: - $value *= 60 * 60 / 1000; - break; - case SpeedType::CENTIMETERS_PER_DAY: - $value = $value / 24 / 100000; - break; - case SpeedType::CENTIMETERS_PER_HOUR: - $value /= 100000; - break; - case SpeedType::CENTIMETERS_PER_MINUTES: - $value *= 60 / 100000; - break; - case SpeedType::CENTIMETERS_PER_SECOND: - $value *= 60 * 60 / 100000; - break; - case SpeedType::MILLIMETERS_PER_DAY: - $value = $value / 24 / 1000000; - break; - case SpeedType::MILLIMETERS_PER_HOUR: - $value /= 1000000; - break; - case SpeedType::MILLIMETERS_PER_MINUTE: - $value *= 60 / 1000000; - break; - case SpeedType::MILLIMETERS_PER_SECOND: - $value *= 60 * 60 / 1000000; - break; - case SpeedType::YARDS_PER_DAY: - $value = $value / 24 * 0.0009144; - break; - case SpeedType::YARDS_PER_HOUR: - $value *= 0.0009144; - break; - case SpeedType::YARDS_PER_MINUTE: - $value *= 60 * 0.0009144; - break; - case SpeedType::YARDS_PER_SECOND: - $value *= 60 * 60 * 0.0009144; - break; - case SpeedType::INCHES_PER_DAY: - $value = $value / 24 * 0.0000254; - break; - case SpeedType::INCHES_PER_HOUR: - $value *= 0.0000254; - break; - case SpeedType::INCHES_PER_MINUTE: - $value *= 60 * 0.0000254; - break; - case SpeedType::INCHES_PER_SECOND: - $value *= 60 * 60 * 0.0000254; - break; - case SpeedType::FEET_PER_DAY: - $value = $value / 24 * 0.0003048; - break; - case SpeedType::FEET_PER_HOUR: - $value *= 0.0003048; - break; - case SpeedType::FEET_PER_MINUTE: - $value *= 60 * 0.0003048; - break; - case SpeedType::FEET_PER_SECOND: - $value *= 60 * 60 * 0.0003048; - break; - case SpeedType::MACH: - $value *= 1225.044; - break; - case SpeedType::KNOTS: - $value *= 1.852; - break; - default: - throw new \InvalidArgumentException('Speed not supported'); - } + $value = self::normalizeSpeed($value, $from); switch ($to) { case SpeedType::KILOMETERS_PER_HOUR: @@ -954,6 +933,127 @@ class Measurement return $value; } + /** + * Convert speed. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeSpeed(float $value, string $from) : float + { + switch ($from) { + case SpeedType::KILOMETERS_PER_HOUR: + break; + case SpeedType::MILES_PER_DAY: + $value = $value / 24 * 1.60934; + break; + case SpeedType::MILES_PER_HOUR: + $value *= 1.60934; + break; + case SpeedType::MILES_PER_MINUTE: + $value *= 60 * 1.60934; + break; + case SpeedType::MILES_PER_SECOND: + $value *= 60 * 60 * 1.60934; + break; + case SpeedType::KILOMETERS_PER_DAY: + $value /= 24; + break; + case SpeedType::KILOMETERS_PER_MINUTE: + $value *= 60; + break; + case SpeedType::KILOMETERS_PER_SECOND: + $value *= 60 * 60; + break; + case SpeedType::METERS_PER_DAY: + $value = $value / 24 / 1000; + break; + case SpeedType::METERS_PER_HOUR: + $value /= 1000; + break; + case SpeedType::METERS_PER_MINUTE: + $value *= 60 / 1000; + break; + case SpeedType::METERS_PER_SECOND: + $value *= 60 * 60 / 1000; + break; + case SpeedType::CENTIMETERS_PER_DAY: + $value = $value / 24 / 100000; + break; + case SpeedType::CENTIMETERS_PER_HOUR: + $value /= 100000; + break; + case SpeedType::CENTIMETERS_PER_MINUTES: + $value *= 60 / 100000; + break; + case SpeedType::CENTIMETERS_PER_SECOND: + $value *= 60 * 60 / 100000; + break; + case SpeedType::MILLIMETERS_PER_DAY: + $value = $value / 24 / 1000000; + break; + case SpeedType::MILLIMETERS_PER_HOUR: + $value /= 1000000; + break; + case SpeedType::MILLIMETERS_PER_MINUTE: + $value *= 60 / 1000000; + break; + case SpeedType::MILLIMETERS_PER_SECOND: + $value *= 60 * 60 / 1000000; + break; + case SpeedType::YARDS_PER_DAY: + $value = $value / 24 * 0.0009144; + break; + case SpeedType::YARDS_PER_HOUR: + $value *= 0.0009144; + break; + case SpeedType::YARDS_PER_MINUTE: + $value *= 60 * 0.0009144; + break; + case SpeedType::YARDS_PER_SECOND: + $value *= 60 * 60 * 0.0009144; + break; + case SpeedType::INCHES_PER_DAY: + $value = $value / 24 * 0.0000254; + break; + case SpeedType::INCHES_PER_HOUR: + $value *= 0.0000254; + break; + case SpeedType::INCHES_PER_MINUTE: + $value *= 60 * 0.0000254; + break; + case SpeedType::INCHES_PER_SECOND: + $value *= 60 * 60 * 0.0000254; + break; + case SpeedType::FEET_PER_DAY: + $value = $value / 24 * 0.0003048; + break; + case SpeedType::FEET_PER_HOUR: + $value *= 0.0003048; + break; + case SpeedType::FEET_PER_MINUTE: + $value *= 60 * 0.0003048; + break; + case SpeedType::FEET_PER_SECOND: + $value *= 60 * 60 * 0.0003048; + break; + case SpeedType::MACH: + $value *= 1225.044; + break; + case SpeedType::KNOTS: + $value *= 1.852; + break; + default: + throw new \InvalidArgumentException('Speed not supported'); + } + + return $value; + } + /** * Convert speed. * @@ -968,36 +1068,7 @@ class Measurement public static function convertTime(float $value, string $from = TimeType::SECONDS, string $to = TimeType::HOURS) : float { // to seconds - switch ($from) { - case TimeType::SECONDS: - break; - case TimeType::MINUTES: - $value *= 60; - break; - case TimeType::MILLISECONDS: - $value /= 1000; - break; - case TimeType::HOURS: - $value /= 3600; - break; - case TimeType::DAYS: - $value /= 3600 * 24; - break; - case TimeType::WEEKS: - $value /= 3600 * 24 * 7; - break; - case TimeType::MONTH: - $value /= 3600 * 24 * 30; - break; - case TimeType::QUARTER: - $value /= 3600 * 24 * 90; - break; - case TimeType::YEAR: - $value /= 3600 * 24 * 365; - break; - default: - throw new \InvalidArgumentException('Size not supported'); - } + $value = self::normalizeTime($value, $from); switch ($to) { case TimeType::SECONDS: @@ -1033,6 +1104,52 @@ class Measurement return $value; } + /** + * Convert speed. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeTime(float $value, string $from) : float + { + switch ($from) { + case TimeType::SECONDS: + break; + case TimeType::MINUTES: + $value *= 60; + break; + case TimeType::MILLISECONDS: + $value /= 1000; + break; + case TimeType::HOURS: + $value /= 3600; + break; + case TimeType::DAYS: + $value /= 3600 * 24; + break; + case TimeType::WEEKS: + $value /= 3600 * 24 * 7; + break; + case TimeType::MONTH: + $value /= 3600 * 24 * 30; + break; + case TimeType::QUARTER: + $value /= 3600 * 24 * 90; + break; + case TimeType::YEAR: + $value /= 3600 * 24 * 365; + break; + default: + throw new \InvalidArgumentException('Size not supported'); + } + + return $value; + } + /** * Convert speed. * @@ -1047,39 +1164,7 @@ class Measurement public static function convertAngle(float $value, string $from = AngleType::DEGREE, string $to = AngleType::DEGREE) : float { // to degree - switch ($from) { - case AngleType::DEGREE: - break; - case AngleType::RADIAN: - $value *= 57.296; - break; - case AngleType::SECOND: - $value *= 0.00027778; - break; - case AngleType::MINUTE: - $value *= 0.016667; - break; - case AngleType::MILLIRADIAN_US: - $value *= 0.09; - break; - case AngleType::MILLIRADIAN_UK: - $value *= 0.057296; - break; - case AngleType::MILLIRADIAN_USSR: - $value *= 0.057143; - break; - case AngleType::MILLIRADIAN_NATO: - $value *= 0.056250; - break; - case AngleType::GRADIAN: - $value *= 0.09; - break; - case AngleType::CENTRAD: - $value *= 0.57296; - break; - default: - throw new \InvalidArgumentException('Angle not supported'); - } + $value = self::normalizeAngle($value, $from); switch ($to) { case AngleType::DEGREE: @@ -1118,6 +1203,55 @@ class Measurement return $value; } + /** + * Convert speed. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeAngle(float $value, string $from) : float + { + switch ($from) { + case AngleType::DEGREE: + break; + case AngleType::RADIAN: + $value *= 57.296; + break; + case AngleType::SECOND: + $value *= 0.00027778; + break; + case AngleType::MINUTE: + $value *= 0.016667; + break; + case AngleType::MILLIRADIAN_US: + $value *= 0.09; + break; + case AngleType::MILLIRADIAN_UK: + $value *= 0.057296; + break; + case AngleType::MILLIRADIAN_USSR: + $value *= 0.057143; + break; + case AngleType::MILLIRADIAN_NATO: + $value *= 0.056250; + break; + case AngleType::GRADIAN: + $value *= 0.09; + break; + case AngleType::CENTRAD: + $value *= 0.57296; + break; + default: + throw new \InvalidArgumentException('Angle not supported'); + } + + return $value; + } + /** * Convert speed. * @@ -1132,47 +1266,7 @@ class Measurement public static function convertPressure(float $value, string $from = PressureType::PASCALS, string $to = PressureType::BAR) : float { // to pascals - switch ($from) { - case PressureType::PASCALS: - break; - case PressureType::BAR: - $value *= 100000; - break; - case PressureType::POUND_PER_SQUARE_INCH: - $value /= 0.00014504; - break; - case PressureType::ATMOSPHERES: - $value *= 101325; - break; - case PressureType::INCHES_OF_MERCURY: - $value /= 0.00029530; - break; - case PressureType::INCHES_OF_WATER: - $value /= 0.0040146; - break; - case PressureType::MILLIMETERS_OF_WATER: - $value /= 0.10197; - break; - case PressureType::MILLIMETERS_OF_MERCURY: - $value /= 0.0075006; - break; - case PressureType::MILLIBAR: - $value *= 100; - break; - case PressureType::KILOGRAM_PER_SQUARE_METER: - $value /= 0.10197; - break; - case PressureType::NEWTONS_PER_METER_SQUARED: - break; - case PressureType::POUNDS_PER_SQUARE_FOOT: - $value /= 0.020885; - break; - case PressureType::TORRS: - $value /= 0.0075006; - break; - default: - throw new \InvalidArgumentException('Size not supported'); - } + $value = self::normalizePressure($value, $from); switch ($to) { case PressureType::PASCALS: @@ -1219,6 +1313,63 @@ class Measurement return $value; } + /** + * Convert speed. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizePressure(float $value, string $from) : float + { + switch ($from) { + case PressureType::PASCALS: + break; + case PressureType::BAR: + $value *= 100000; + break; + case PressureType::POUND_PER_SQUARE_INCH: + $value /= 0.00014504; + break; + case PressureType::ATMOSPHERES: + $value *= 101325; + break; + case PressureType::INCHES_OF_MERCURY: + $value /= 0.00029530; + break; + case PressureType::INCHES_OF_WATER: + $value /= 0.0040146; + break; + case PressureType::MILLIMETERS_OF_WATER: + $value /= 0.10197; + break; + case PressureType::MILLIMETERS_OF_MERCURY: + $value /= 0.0075006; + break; + case PressureType::MILLIBAR: + $value *= 100; + break; + case PressureType::KILOGRAM_PER_SQUARE_METER: + $value /= 0.10197; + break; + case PressureType::NEWTONS_PER_METER_SQUARED: + break; + case PressureType::POUNDS_PER_SQUARE_FOOT: + $value /= 0.020885; + break; + case PressureType::TORRS: + $value /= 0.0075006; + break; + default: + throw new \InvalidArgumentException('Size not supported'); + } + + return $value; + } + /** * Convert speed. * @@ -1232,35 +1383,7 @@ class Measurement */ public static function convertEnergy(float $value, string $from = EnergyPowerType::JOULS, string $to = EnergyPowerType::KILOWATT_HOUERS) : float { - switch ($from) { - case EnergyPowerType::JOULS: - break; - case EnergyPowerType::KILOWATT_HOUERS: - $value /= 0.00000027778; - break; - case EnergyPowerType::MEGAWATT_HOUERS: - $value /= 0.00000000027778; - break; - case EnergyPowerType::KILOTONS: - $value /= 0.00000000000023901; - break; - case EnergyPowerType::CALORIES: - $value /= 0.00023885; - break; - case EnergyPowerType::BTU: - $value /= 0.00094782; - break; - case EnergyPowerType::KILOJOULS: - $value /= 0.0010000; - break; - case EnergyPowerType::THERMEC: - $value /= 0.0000000094782; - break; - case EnergyPowerType::NEWTON_METERS: - break; - default: - throw new \InvalidArgumentException('Energy not supported'); - } + $value = self::normalizeEnergy($value, $from); switch ($to) { case EnergyPowerType::JOULS: @@ -1295,6 +1418,51 @@ class Measurement return $value; } + /** + * Convert speed. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeEnergy(float $value, string $from) : float + { + switch ($from) { + case EnergyPowerType::JOULS: + break; + case EnergyPowerType::KILOWATT_HOUERS: + $value /= 0.00000027778; + break; + case EnergyPowerType::MEGAWATT_HOUERS: + $value /= 0.00000000027778; + break; + case EnergyPowerType::KILOTONS: + $value /= 0.00000000000023901; + break; + case EnergyPowerType::CALORIES: + $value /= 0.00023885; + break; + case EnergyPowerType::BTU: + $value /= 0.00094782; + break; + case EnergyPowerType::KILOJOULS: + $value /= 0.0010000; + break; + case EnergyPowerType::THERMEC: + $value /= 0.0000000094782; + break; + case EnergyPowerType::NEWTON_METERS: + break; + default: + throw new \InvalidArgumentException('Energy not supported'); + } + + return $value; + } + /** * File size. * @@ -1309,39 +1477,7 @@ class Measurement public static function convertFileSize(float $value, string $from = FileSizeType::BYTE, string $to = FileSizeType::MEGABYTE) : float { // to byte - switch ($from) { - case FileSizeType::BYTE: - break; - case FileSizeType::KILOBYTE: - $value *= 1000; - break; - case FileSizeType::MEGABYTE: - $value *= 1000000; - break; - case FileSizeType::GIGABYTE: - $value *= 1000000000; - break; - case FileSizeType::TERRABYTE: - $value *= 1000000000000; - break; - case FileSizeType::BIT: - $value /= 8; - break; - case FileSizeType::KILOBIT: - $value /= 0.008; - break; - case FileSizeType::MEGABIT: - $value /= 0.000008; - break; - case FileSizeType::GIGABIT: - $value /= 8e-9; - break; - case FileSizeType::TERRABIT: - $value /= 8e-12; - break; - default: - throw new \InvalidArgumentException('Size not supported'); - } + $value = self::normalizeFileSize($value, $from); switch ($to) { case FileSizeType::BYTE: @@ -1379,4 +1515,53 @@ class Measurement return $value; } + + /** + * File size. + * + * @param float $value Value to convert + * @param string $from Input weight + * + * @return float + * + * @since 1.0.0 + */ + private static function normalizeFileSize(float $value, string $from) : float + { + switch ($from) { + case FileSizeType::BYTE: + break; + case FileSizeType::KILOBYTE: + $value *= 1000; + break; + case FileSizeType::MEGABYTE: + $value *= 1000000; + break; + case FileSizeType::GIGABYTE: + $value *= 1000000000; + break; + case FileSizeType::TERRABYTE: + $value *= 1000000000000; + break; + case FileSizeType::BIT: + $value /= 8; + break; + case FileSizeType::KILOBIT: + $value /= 0.008; + break; + case FileSizeType::MEGABIT: + $value /= 0.000008; + break; + case FileSizeType::GIGABIT: + $value /= 8e-9; + break; + case FileSizeType::TERRABIT: + $value /= 8e-12; + break; + default: + throw new \InvalidArgumentException('Size not supported'); + } + + return $value; + } } diff --git a/Utils/Converter/Numeric.php b/Utils/Converter/Numeric.php index c77e628b0..20b206f54 100644 --- a/Utils/Converter/Numeric.php +++ b/Utils/Converter/Numeric.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; /** * Numeric converter. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Numeric @@ -33,7 +31,11 @@ class Numeric * @var array * @since 1.0.0 */ - /* public */ const ROMANS = ['M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1]; + /* public */ const ROMANS = [ + 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, + 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, + 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1 + ]; /** * Constructor. @@ -74,7 +76,13 @@ class Numeric $newOutput = 0; for ($i = 1; $i <= $numberLen; $i++) { - $newOutput = bcadd((string) $newOutput, bcmul((string) array_search($number[$i - 1], $fromBase), bcpow((string) $fromLen, (string) ($numberLen - $i)))); + $newOutput = bcadd( + (string) $newOutput, + bcmul( + (string) array_search($number[$i - 1], $fromBase), + bcpow((string) $fromLen, (string) ($numberLen - $i)) + ) + ); } return $newOutput; @@ -138,7 +146,7 @@ class Numeric foreach (self::ROMANS as $key => $value) { while (strpos($roman, $key) === 0) { $result += $value; - $roman = substr($roman, strlen($key)); + $roman = substr($roman, strlen($key)); } } @@ -161,7 +169,7 @@ class Numeric $alpha = ''; for ($i = 1; $number >= 0 && $i < 10; $i++) { - $alpha = chr(0x41 + ($number % pow(26, $i) / pow(26, $i - 1))) . $alpha; + $alpha = chr(0x41 + ($number % pow(26, $i) / pow(26, $i - 1))) . $alpha; $number -= pow(26, $i); } diff --git a/Utils/Converter/PressureType.php b/Utils/Converter/PressureType.php index 554b10c22..911467236 100644 --- a/Utils/Converter/PressureType.php +++ b/Utils/Converter/PressureType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,25 +19,24 @@ use phpOMS\Stdlib\Base\Enum; /** * Speed type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class PressureType extends Enum { - /* public */ const PASCALS = 'Pa'; - /* public */ const BAR = 'bar'; - /* public */ const POUND_PER_SQUARE_INCH = 'psi'; - /* public */ const ATMOSPHERES = 'atm'; - /* public */ const INCHES_OF_MERCURY = 'inHg'; - /* public */ const INCHES_OF_WATER = 'inH20'; - /* public */ const MILLIMETERS_OF_WATER = 'mmH20'; - /* public */ const MILLIMETERS_OF_MERCURY = 'mmHg'; - /* public */ const MILLIBAR = 'mbar'; + /* public */ const PASCALS = 'Pa'; + /* public */ const BAR = 'bar'; + /* public */ const POUND_PER_SQUARE_INCH = 'psi'; + /* public */ const ATMOSPHERES = 'atm'; + /* public */ const INCHES_OF_MERCURY = 'inHg'; + /* public */ const INCHES_OF_WATER = 'inH20'; + /* public */ const MILLIMETERS_OF_WATER = 'mmH20'; + /* public */ const MILLIMETERS_OF_MERCURY = 'mmHg'; + /* public */ const MILLIBAR = 'mbar'; /* public */ const KILOGRAM_PER_SQUARE_METER = 'kg/m2'; /* public */ const NEWTONS_PER_METER_SQUARED = 'N/m2'; - /* public */ const POUNDS_PER_SQUARE_FOOT = 'psf'; - /* public */ const TORRS = 'Torr'; + /* public */ const POUNDS_PER_SQUARE_FOOT = 'psf'; + /* public */ const TORRS = 'Torr'; } diff --git a/Utils/Converter/SpeedType.php b/Utils/Converter/SpeedType.php index 4f7affa01..6ef6d81db 100644 --- a/Utils/Converter/SpeedType.php +++ b/Utils/Converter/SpeedType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,46 +19,45 @@ use phpOMS\Stdlib\Base\Enum; /** * Speed type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class SpeedType extends Enum { - /* public */ const MILES_PER_DAY = 'mpd'; - /* public */ const MILES_PER_HOUR = 'mph'; - /* public */ const MILES_PER_MINUTE = 'mpm'; - /* public */ const MILES_PER_SECOND = 'mps'; - /* public */ const KILOMETERS_PER_DAY = 'kpd'; - /* public */ const KILOMETERS_PER_HOUR = 'kph'; - /* public */ const KILOMETERS_PER_MINUTE = 'kpm'; - /* public */ const KILOMETERS_PER_SECOND = 'kps'; - /* public */ const METERS_PER_DAY = 'md'; - /* public */ const METERS_PER_HOUR = 'mh'; - /* public */ const METERS_PER_MINUTE = 'mm'; - /* public */ const METERS_PER_SECOND = 'ms'; - /* public */ const CENTIMETERS_PER_DAY = 'cpd'; - /* public */ const CENTIMETERS_PER_HOUR = 'cph'; + /* public */ const MILES_PER_DAY = 'mpd'; + /* public */ const MILES_PER_HOUR = 'mph'; + /* public */ const MILES_PER_MINUTE = 'mpm'; + /* public */ const MILES_PER_SECOND = 'mps'; + /* public */ const KILOMETERS_PER_DAY = 'kpd'; + /* public */ const KILOMETERS_PER_HOUR = 'kph'; + /* public */ const KILOMETERS_PER_MINUTE = 'kpm'; + /* public */ const KILOMETERS_PER_SECOND = 'kps'; + /* public */ const METERS_PER_DAY = 'md'; + /* public */ const METERS_PER_HOUR = 'mh'; + /* public */ const METERS_PER_MINUTE = 'mm'; + /* public */ const METERS_PER_SECOND = 'ms'; + /* public */ const CENTIMETERS_PER_DAY = 'cpd'; + /* public */ const CENTIMETERS_PER_HOUR = 'cph'; /* public */ const CENTIMETERS_PER_MINUTES = 'cpm'; - /* public */ const CENTIMETERS_PER_SECOND = 'cps'; - /* public */ const MILLIMETERS_PER_DAY = 'mmpd'; - /* public */ const MILLIMETERS_PER_HOUR = 'mmph'; - /* public */ const MILLIMETERS_PER_MINUTE = 'mmpm'; - /* public */ const MILLIMETERS_PER_SECOND = 'mmps'; - /* public */ const YARDS_PER_DAY = 'ypd'; - /* public */ const YARDS_PER_HOUR = 'yph'; - /* public */ const YARDS_PER_MINUTE = 'ypm'; - /* public */ const YARDS_PER_SECOND = 'yps'; - /* public */ const INCHES_PER_DAY = 'ind'; - /* public */ const INCHES_PER_HOUR = 'inh'; - /* public */ const INCHES_PER_MINUTE = 'inm'; - /* public */ const INCHES_PER_SECOND = 'ins'; - /* public */ const FEET_PER_DAY = 'ftd'; - /* public */ const FEET_PER_HOUR = 'fth'; - /* public */ const FEET_PER_MINUTE = 'ftm'; - /* public */ const FEET_PER_SECOND = 'fts'; - /* public */ const MACH = 'mach'; - /* public */ const KNOTS = 'knots'; + /* public */ const CENTIMETERS_PER_SECOND = 'cps'; + /* public */ const MILLIMETERS_PER_DAY = 'mmpd'; + /* public */ const MILLIMETERS_PER_HOUR = 'mmph'; + /* public */ const MILLIMETERS_PER_MINUTE = 'mmpm'; + /* public */ const MILLIMETERS_PER_SECOND = 'mmps'; + /* public */ const YARDS_PER_DAY = 'ypd'; + /* public */ const YARDS_PER_HOUR = 'yph'; + /* public */ const YARDS_PER_MINUTE = 'ypm'; + /* public */ const YARDS_PER_SECOND = 'yps'; + /* public */ const INCHES_PER_DAY = 'ind'; + /* public */ const INCHES_PER_HOUR = 'inh'; + /* public */ const INCHES_PER_MINUTE = 'inm'; + /* public */ const INCHES_PER_SECOND = 'ins'; + /* public */ const FEET_PER_DAY = 'ftd'; + /* public */ const FEET_PER_HOUR = 'fth'; + /* public */ const FEET_PER_MINUTE = 'ftm'; + /* public */ const FEET_PER_SECOND = 'fts'; + /* public */ const MACH = 'mach'; + /* public */ const KNOTS = 'knots'; } diff --git a/Utils/Converter/TemperatureType.php b/Utils/Converter/TemperatureType.php index a79f8d6e7..310123028 100644 --- a/Utils/Converter/TemperatureType.php +++ b/Utils/Converter/TemperatureType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,20 +19,19 @@ use phpOMS\Stdlib\Base\Enum; /** * Temperature type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class TemperatureType extends Enum { - /* public */ const CELSIUS = 'celsius'; + /* public */ const CELSIUS = 'celsius'; /* public */ const FAHRENHEIT = 'fahrenheit'; - /* public */ const KELVIN = 'kelvin'; - /* public */ const REAUMUR = 'reaumur'; - /* public */ const RANKINE = 'rankine'; - /* public */ const DELISLE = 'delisle'; - /* public */ const NEWTON = 'newton'; - /* public */ const ROMER = 'romer'; + /* public */ const KELVIN = 'kelvin'; + /* public */ const REAUMUR = 'reaumur'; + /* public */ const RANKINE = 'rankine'; + /* public */ const DELISLE = 'delisle'; + /* public */ const NEWTON = 'newton'; + /* public */ const ROMER = 'romer'; } diff --git a/Utils/Converter/TimeType.php b/Utils/Converter/TimeType.php index 5dc8080a6..2bd2ecb78 100644 --- a/Utils/Converter/TimeType.php +++ b/Utils/Converter/TimeType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,21 +19,20 @@ use phpOMS\Stdlib\Base\Enum; /** * Time type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class TimeType extends Enum { /* public */ const MILLISECONDS = 'ms'; - /* public */ const SECONDS = 's'; - /* public */ const MINUTES = 'i'; - /* public */ const HOURS = 'h'; - /* public */ const DAYS = 'd'; - /* public */ const WEEKS = 'w'; - /* public */ const MONTH = 'm'; - /* public */ const QUARTER = 'q'; - /* public */ const YEAR = 'y'; + /* public */ const SECONDS = 's'; + /* public */ const MINUTES = 'i'; + /* public */ const HOURS = 'h'; + /* public */ const DAYS = 'd'; + /* public */ const WEEKS = 'w'; + /* public */ const MONTH = 'm'; + /* public */ const QUARTER = 'q'; + /* public */ const YEAR = 'y'; } diff --git a/Utils/Converter/VolumeType.php b/Utils/Converter/VolumeType.php index 738e7346d..7e1e39eba 100644 --- a/Utils/Converter/VolumeType.php +++ b/Utils/Converter/VolumeType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,50 +19,49 @@ use phpOMS\Stdlib\Base\Enum; /** * Volume type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class VolumeType extends Enum { - /* public */ const UK_GALLON = 'UK gal'; - /* public */ const US_GALLON_LIQUID = 'US gal lqd'; - /* public */ const US_GALLON_DRY = 'US gal dry'; - /* public */ const UK_PINT = 'pt'; - /* public */ const US_PINT_LIQUID = 'US pt lqd'; - /* public */ const US_PINT_DRY = 'US pt dry'; - /* public */ const US_QUARTS_LIQUID = 'US qt lqd'; - /* public */ const US_QUARTS_DRY = 'US qt dry'; - /* public */ const UK_QUARTS = 'UK qt dry'; - /* public */ const US_GILL = 'US gi'; - /* public */ const UK_GILL = 'UK gi'; - /* public */ const LITER = 'L'; - /* public */ const MICROLITER = 'mul'; - /* public */ const MILLILITER = 'mL'; - /* public */ const CENTILITER = 'cl'; - /* public */ const KILOLITER = 'kl'; - /* public */ const UK_BARREL = 'UK bbl'; - /* public */ const US_BARREL_DRY = 'US bbl dry'; - /* public */ const US_BARREL_LIQUID = 'US bbl lqd'; - /* public */ const US_BARREL_OIL = 'US bbl oil'; + /* public */ const UK_GALLON = 'UK gal'; + /* public */ const US_GALLON_LIQUID = 'US gal lqd'; + /* public */ const US_GALLON_DRY = 'US gal dry'; + /* public */ const UK_PINT = 'pt'; + /* public */ const US_PINT_LIQUID = 'US pt lqd'; + /* public */ const US_PINT_DRY = 'US pt dry'; + /* public */ const US_QUARTS_LIQUID = 'US qt lqd'; + /* public */ const US_QUARTS_DRY = 'US qt dry'; + /* public */ const UK_QUARTS = 'UK qt dry'; + /* public */ const US_GILL = 'US gi'; + /* public */ const UK_GILL = 'UK gi'; + /* public */ const LITER = 'L'; + /* public */ const MICROLITER = 'mul'; + /* public */ const MILLILITER = 'mL'; + /* public */ const CENTILITER = 'cl'; + /* public */ const KILOLITER = 'kl'; + /* public */ const UK_BARREL = 'UK bbl'; + /* public */ const US_BARREL_DRY = 'US bbl dry'; + /* public */ const US_BARREL_LIQUID = 'US bbl lqd'; + /* public */ const US_BARREL_OIL = 'US bbl oil'; /* public */ const US_BARREL_FEDERAL = 'US bbl fed'; - /* public */ const US_OUNCES = 'us fl oz'; - /* public */ const UK_OUNCES = 'uk fl oz'; - /* public */ const US_TEASPOON = 'US tsp'; - /* public */ const UK_TEASPOON = 'UK tsp'; - /* public */ const METRIC_TEASPOON = 'Metric tsp'; - /* public */ const US_TABLESPOON = 'US tblsp'; - /* public */ const UK_TABLESPOON = 'UK tblsp'; + /* public */ const US_OUNCES = 'us fl oz'; + /* public */ const UK_OUNCES = 'uk fl oz'; + /* public */ const US_TEASPOON = 'US tsp'; + /* public */ const UK_TEASPOON = 'UK tsp'; + /* public */ const METRIC_TEASPOON = 'Metric tsp'; + /* public */ const US_TABLESPOON = 'US tblsp'; + /* public */ const UK_TABLESPOON = 'UK tblsp'; /* public */ const METRIC_TABLESPOON = 'Metric tblsp'; - /* public */ const US_CUP = 'US cup'; - /* public */ const CAN_CUP = 'Can cup'; - /* public */ const METRIC_CUP = 'Metric cup'; - /* public */ const CUBIC_CENTIMETER = 'cm'; - /* public */ const CUBIC_MILLIMETER = 'mm'; - /* public */ const CUBIC_METER = 'm'; - /* public */ const CUBIC_INCH = 'in'; - /* public */ const CUBIC_FEET = 'ft'; - /* public */ const CUBIC_YARD = 'yd'; + /* public */ const US_CUP = 'US cup'; + /* public */ const CAN_CUP = 'Can cup'; + /* public */ const METRIC_CUP = 'Metric cup'; + /* public */ const CUBIC_CENTIMETER = 'cm'; + /* public */ const CUBIC_MILLIMETER = 'mm'; + /* public */ const CUBIC_METER = 'm'; + /* public */ const CUBIC_INCH = 'in'; + /* public */ const CUBIC_FEET = 'ft'; + /* public */ const CUBIC_YARD = 'yd'; } diff --git a/Utils/Converter/WeightType.php b/Utils/Converter/WeightType.php index b0c3ad8f2..748131069 100644 --- a/Utils/Converter/WeightType.php +++ b/Utils/Converter/WeightType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Converter; @@ -20,26 +19,25 @@ use phpOMS\Stdlib\Base\Enum; /** * Weight type enum. * - * @category Framework - * @package phpOMS\Utils\Converter + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class WeightType extends Enum { - /* public */ const MICROGRAM = 'mg'; - /* public */ const MILLIGRAM = 'mug'; - /* public */ const GRAM = 'g'; - /* public */ const KILOGRAM = 'kg'; + /* public */ const MICROGRAM = 'mg'; + /* public */ const MILLIGRAM = 'mug'; + /* public */ const GRAM = 'g'; + /* public */ const KILOGRAM = 'kg'; /* public */ const METRIC_TONS = 't'; - /* public */ const POUNDS = 'lb'; - /* public */ const OUNCES = 'oz'; - /* public */ const STONES = 'st'; - /* public */ const GRAIN = 'gr'; - /* public */ const CARAT = 'ct'; - /* public */ const LONG_TONS = 'uk t'; - /* public */ const SHORT_TONS = 'us ton'; + /* public */ const POUNDS = 'lb'; + /* public */ const OUNCES = 'oz'; + /* public */ const STONES = 'st'; + /* public */ const GRAIN = 'gr'; + /* public */ const CARAT = 'ct'; + /* public */ const LONG_TONS = 'uk t'; + /* public */ const SHORT_TONS = 'us ton'; /* public */ const TROY_POUNDS = 't lb'; /* public */ const TROY_OUNCES = 't oz'; } diff --git a/Utils/EDI/AnsiX12/Component/BEG.php b/Utils/EDI/AnsiX12/Component/BEG.php deleted file mode 100644 index efbdc0101..000000000 --- a/Utils/EDI/AnsiX12/Component/BEG.php +++ /dev/null @@ -1,30 +0,0 @@ -invoiceDate = $invoiceDate; - } - - public function getInvoiceDate() : string - { - return $this->invoiceDate->format('Ymd'); - } - - public function setInvoiceNumber(string $invoice) /* : void */ - { - if(strlen($invoice) < 1 || strlen($invoice) > 22) { - throw new \Exception(); - } - - $this->invoice = $invoice; - } - - public function getInvoiceNumber() : string - { - return $this->invoice; - } - - public function setPurchaseDate(\DateTime $purchaseDate) /* : void */ - { - $this->purchaseDate = $purchaseDate; - } - - public function getPurchaseDate() : string - { - return $this->purchaseDate->format('Ymd'); - } - - public function setPurchaseNumber(string $purchase) /* : void */ - { - if(strlen($purchase) < 1 || strlen($purchase) > 22) { - throw new \Exception(); - } - - $this->purchase = $purchase; - } - - public function getPurchaseNumber() : string - { - return $this->purchase; - } - - public function setTransactionTypeCode(int $code) /* : void */ - { - if($code < 10 || $code > 99) { - throw new \Exception(); - } - - $this->transactionTypeCode = $code; - } - - public function getTransactionTypeCode() : string - { - return str_pad((string) $this->transactionTypeCode, 2, '0', STR_PAD_LEFT); - } -} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/Component/GE.php b/Utils/EDI/AnsiX12/Component/GE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/GS.php b/Utils/EDI/AnsiX12/Component/GS.php deleted file mode 100644 index 82b0ab789..000000000 --- a/Utils/EDI/AnsiX12/Component/GS.php +++ /dev/null @@ -1,176 +0,0 @@ -date = new \DateTime(); - } - - public function getFunctionalGroupHeader() : string - { - return $this->functionalGroupHeader; - } - - public function getFunctionalIdentifierCode() : string - { - return $this->functionalIdentifierCode; - } - - public function setFunctionalIdentifierCode(string $code) /* : void */ - { - if(!FunctionalIdentifierCode::isValidValue($code)) { - throw \Exception(); - } - - $this->functionalIdentifierCode = $code; - } - - public function getApplicationSenderCode() : string - { - return str_pad((string) $this->applicationSenderCode, 2, '0', STR_PAD_LEFT); - } - - public function setApplicationSenderCode(string $code) /* : void */ - { - if(strlen($code) < 2 || strlen($code) > 15) { - throw new \Exception(); - } - - $this->applicationSenderCode = $code; - } - - public function getApplicationReceiverCode() : string - { - return str_pad((string) $this->applicationReceiverCode, 2, '0', STR_PAD_LEFT); - } - - public function setApplicationReceiverCode(string $code) /* : void */ - { - if(strlen($code) < 2 || strlen($code) > 15) { - throw new \Exception(); - } - - $this->applicationReceiverCode = $code; - } - - public function setDate(\DateTime $date) /* : void */ - { - $this->date = $date; - } - - public function getDate() : string - { - return $this->date->format('d:m:y'); - } - - public function getTime() : string - { - return $this->date->format('d:m:y'); - } - - public function getGroupControlNumber() : int - { - return $this->groupControlNumber; - } - - public function setGroupControlNumber(int $number) /* : void */ - { - if($number < 0) { - throw new \Exception(); - } - - $this->groupControlNumber = $number; - } - - public function getResponsibleAgencyCode() : int - { - return $this->responsibleAgencyCode; - } - - public function setResponsibleAgencyCode(int $code) /* : void */ - { - if($code < 0 || $code > 99) { - throw new \Exception(); - } - - $this->responsibleAgencyCode = $code; - } - - public function getVersion() : string - { - return $this->version; - } - - public function setVersion(string $version) /* : void */ - { - $this->version = $version; - } - - public function serialize() - { - return $this->functionalGroupHeader . '*' - . $this->getFunctionalIdentifierCode() . '*' - . $this->getApplicationSenderCode() . '*' - . $this->getApplicationReceiverCode() . '*' - . $this->getDate() . '*' - . $this->getTime() . '*' - . $this->getGroupControlNumber() . '*' - . $this->getResponsibleAgencyCode() . '*' - . $this->getVersion() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; - } - - public function unserialize($raw) - { - $split = explode($raw); - - $this->setFunctionalGroupHeader(trim($split[0])); - $this->setFunctionalIdentifierCode(trim($split[1])); - $this->setApplicationSenderCode(trim($split[2])); - $this->setApplicationReceiverCode(trim($split[3])); - $this->setDate(new \DateTime(trim($split[4]) . '-' . trim($split[5]))); - $this->setGroupControlNumber(trim($split[6])); - $this->setResponsibleAgencyCode((int) trim($split[7])); - $this->setVersion(trim($split[8])); - } -} diff --git a/Utils/EDI/AnsiX12/Component/IEA.php b/Utils/EDI/AnsiX12/Component/IEA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/ISA.php b/Utils/EDI/AnsiX12/Component/ISA.php deleted file mode 100644 index 0c537d6b4..000000000 --- a/Utils/EDI/AnsiX12/Component/ISA.php +++ /dev/null @@ -1,427 +0,0 @@ -'; - - private $interchangeControlHeader = 'ISA'; - - /** - * Code to identify the type of information in the Authorization Information. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Authorization Information available - * - * @var int - * @since 1.0.0 - */ - private $authorizationInformationQualifier = 0; - - - /** - * Information used for additional identification or authorization of the interchange - * sender or the data in the interchange; the type of information is set by the Authorization - * Information Qualifier. - * - * Req: M - * Type: AN - * Min/Max: 10/10 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $authorizationInformation = ''; - - /** - * Code to identify the type of information in the Security Information. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Security Information available - * - * @var int - * @since 1.0.0 - */ - private $securityInformationQualifer = 0; - - /** - * This is used for identifying the security information about the interchange - * sender or the data in the interchange; the type of information is set by the Security - * Information Qualifier. - * - * Req: M - * Type: AN - * Min/Max: 10/10 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $securityInformation = ''; - - /** - * Qualifier to designate the system/method of code structure used to designate - * the sender or receiver ID element being qualifiedn. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Security Information available - * - * @var int - * @since 1.0.0 - */ - private $interchangeIdQualifier = 0; - - /** - * Interchange Sender - * - * Req: M - * Type: AN - * Min/Max: 15/15 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $interchangeSender = ''; - - /** - * DateTime of the interchange - * - * Req: M - * Type: DTM - * Usage: Must - * - * @var \DateTime - * @since 1.0.0 - */ - private $interchangeDateTime = null; - - /** - * Code to identify the agency responsible for the control standard used by the - * message that is enclosed by the interchange header and trailer. - * - * Req: M - * Type: ID - * Min/Max: 1/1 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $interchangeControlStandardId = ''; - - /** - * Code specifying the version number of the interchange control segments. - * - * Req: M - * Type: ID - * Min/Max: 5/5 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $interchangeControlVersionNumber = 401; - - /** - * A control number assigned by the interchange sender. - * - * Req: M - * Type: int - * Min/Max: 9/9 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $interchangeControlNumber = 0; - - /** - * Code sent by the sender to request an interchange acknowledgment. - * - * Req: M - * Type: bool - * Min/Max: 1/1 - * Usage: Must - * - * @var bool - * @since 1.0.0 - */ - private $acknowledgementRequested = false; - - /** - * Code to indicate whether data enclosed by this interchange envelope is test, - * production or information. - * - * Req: M - * Type: ID - * Min/Max: 1/1 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $usageIndicator = 'T'; - - public function setInterchangeControlHeader(string $header) /* : void */ - { - $this->interchangeControlHeader = $header; - } - - public function setAuthorizationInformationQualifier(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->authorizationInformationQualifier = $qualifier; - } - - public function getAuthorizationInformationQualifier() : string - { - return str_pad((string) $this->authorizationInformationQualifier, 2, '0', STR_PAD_LEFT); - } - - public function setAuthorizationInformation(string $information) /* : void */ - { - if(strlen($information) > 10) { - throw new \Exception(); - } - - $this->authorizationInformation = $information; - } - - public function getAuthorizationInformation() : string - { - return str_pad((string) $this->authorizationInformation, 10, ' ', STR_PAD_RIGHT); - } - - public function setSecurityInformationQualifer(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->securityInformationQualifer = $qualifier; - } - - public function getSecurityInformationQualifer() : string - { - return str_pad((string) $this->securityInformationQualifer, 2, '0', STR_PAD_LEFT); - } - - public function setSecurityInformation(string $information) /* : void */ - { - if(strlen($information) > 10) { - throw new \Exception(); - } - - $this->securityInformation = $information; - } - - public function getSecurityInformation() : string - { - return str_pad((string) $this->securityInformation, 10, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeIdQualifier(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->interchangeIdQualifier = $qualifier; - } - - public function getInterchangeIdQualifier() : string - { - return str_pad((string) $this->interchangeIdQualifier, 2, '0', STR_PAD_LEFT); - } - - - public function setInterchangeSender(string $information) /* : void */ - { - if(strlen($information) > 15) { - throw new \Exception(); - } - - $this->interchangeSender = $information; - } - - public function getInterchangeSender() : string - { - return str_pad((string) $this->interchangeSender, 15, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeReceiver(string $information) /* : void */ - { - if(strlen($information) > 15) { - throw new \Exception(); - } - - $this->interchangeReceiver = $information; - } - - public function getInterchangeReceiver() : string - { - return str_pad((string) $this->interchangeReceiver, 15, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeDatetime(\DateTime $interchange) /* : void */ - { - $this->interchangeDateTime = $interchange; - } - - public function getInterchangeDate() : string - { - return $this->interchangeDateTime->format('d:m:y'); - } - - public function getInterchangeTime() : string - { - return $this->interchangeDateTime->format('H:i'); - } - - public function setInterchangeControlStandardId(string $id) /* : void */ - { - if(strlen($id) !== 1) { - throw new \Exception(); - } - - $this->interchangeControlStandardId = $id; - } - - public function getInterchangeControlStandardId() : string - { - return $this->interchangeControlStandardId; - } - - public function setInterchangeControlVersionNumber(int $version) /* : void */ - { - if($version > 99999) { - throw new \Exception(); - } - - $this->interchangeControlVersionNumber = $version; - } - - public function getInterchangeControlVersionNumber() : string - { - return str_pad((string) $this->interchangeControlVersionNumber, 5, '0', STR_PAD_LEFT); - } - - public function setInterchangeControlNumber(int $number) /* : void */ - { - if($number > 999999999) { - throw new \Exception(); - } - - $this->interchangeControlNumber = $number; - } - - public function getInterchangeControlNumber() : string - { - return str_pad((string) $this->interchangeControlNumber, 9, '0', STR_PAD_LEFT); - } - - public function setAcknowledgmentRequested(bool $ack) /* : void */ - { - $this->acknowledgmentRequested = $ack; - } - - public function getAcknowledgmentRequested() : string - { - return (string) $this->acknowledgmentRequested; - } - - public function setUsageUndicator(string $id) /* : void */ - { - if(strlen($id) !== 1) { - throw new \Exception(); - } - - $this->usageIndicator = $id; - } - - public function getUsageUndicator() : string - { - return $this->usageIndicator; - } - - public function serialize() - { - return $this->interchangeControlHeader . '*' - . $this->getAuthorizationInformationQualifier() . '*' - . $this->getAuthorizationInformation() . '*' - . $this->getSecurityInformationQualifer() . '*' - . $this->getSecurityInformation() . '*' - . $this->getInterchangeIdQualifier() . '*' - . $this->getInterchangeSender() . '*' - . $this->getInterchangeIdQualifier() . '*' - . $this->getInterchangeReceiver() . '*' - . $this->getInterchangeDate() . '*' - . $this->getInterchangeTime() . '*' - . $this->getInterchangeControlStandardId() . '*' - . $this->getInterchangeControlVersionNumber() . '*' - . $this->getInterchangeControlNumber() . '*' - . $this->getAcknowledgmentRequested() . '*' - . $this->getUsageUndicator() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; - } - - public function unserialize($raw) - { - $split = explode('*', $raw); - - $this->setInterchangeControlHeader(trim($split[0])); - $this->setAuthorizationInformationQualifier((int) trim($split[1])); - $this->setAuthorizationInformation(trim($split[2])); - $this->setSecurityInformationQualifer((int) trim($split[3])); - $this->setSecurityInformation(trim($split[4])); - $this->setInterchangeIdQualifier((int) trim($split[5])); - $this->setInterchangeSender(trim($split[6])); - $this->setInterchangeReceiver(trim($split[8])); - $this->setInterchangeDatetime(new \DateTime(trim($split[9]) . '-' . trim($split[10]))); - $this->setInterchangeControlStandardId(trim($split[11])); - $this->setInterchangeControlVersionNumber((int) trim($split[12])); - $this->setInterchangeControlNumber((int) trim($split[13])); - $this->setAcknowledgmentRequested((bool) $split[14]); - $this->setUsageUndicator($split[15]); - } -} diff --git a/Utils/EDI/AnsiX12/Component/IT1.php b/Utils/EDI/AnsiX12/Component/IT1.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/ITD.php b/Utils/EDI/AnsiX12/Component/ITD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/MAN.php b/Utils/EDI/AnsiX12/Component/MAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/N1.php b/Utils/EDI/AnsiX12/Component/N1.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/N2.php b/Utils/EDI/AnsiX12/Component/N2.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/N3.php b/Utils/EDI/AnsiX12/Component/N3.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/N4.php b/Utils/EDI/AnsiX12/Component/N4.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/PER.php b/Utils/EDI/AnsiX12/Component/PER.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/PID.php b/Utils/EDI/AnsiX12/Component/PID.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/PO1.php b/Utils/EDI/AnsiX12/Component/PO1.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/REF.php b/Utils/EDI/AnsiX12/Component/REF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/SAC.php b/Utils/EDI/AnsiX12/Component/SAC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/SCH.php b/Utils/EDI/AnsiX12/Component/SCH.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/SE.php b/Utils/EDI/AnsiX12/Component/SE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/ST.php b/Utils/EDI/AnsiX12/Component/ST.php deleted file mode 100644 index a82ee7897..000000000 --- a/Utils/EDI/AnsiX12/Component/ST.php +++ /dev/null @@ -1,82 +0,0 @@ -transactionSetIdentifierCode = $idCode; - } - - public function setTransactionSetIdentifierCode(int $idCode) - { - if($idCode < 100 || $idCode > 999) { - throw new \Exception(); - } - - $this->transactionSetIdentifierCode = $idCode; - } - - public function getTransactionSetIdentifierCode() : int - { - return $this->transactionSetIdentifierCode; - } - - public function setTransactionSetControlNumber(string $controlNumber) - { - if(strlen($controlNumber) < 4 || strlen($controlNumber) > 9) { - throw new \Exception(); - } - - $this->transactionSetControlNumber = $controlNumber; - } - - public function getTransactionSetControlNumber() : string - { - return str_pad((string) $this->transactionSetControlNumber, 9, '0', STR_PAD_LEFT); - } - - public function serialize() - { - return self::IDENTIFIER . '*' - . $this->getTransactionSetIdentifierCode() . '*' - . $this->getTransactionSetControlNumber() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; - } - - public function unserialize($raw) - { - $split = explode('*', $raw); - - $this->setTransactionSetIdentifierCode((int) $split[1]); - $this->setTransactionSetControlNumber(substr($split[2], -1)); - } -} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/Component/TD5.php b/Utils/EDI/AnsiX12/Component/TD5.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/Component/TDS.php b/Utils/EDI/AnsiX12/Component/TDS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/AnsiX12/EDIAbstract.php b/Utils/EDI/AnsiX12/EDIAbstract.php deleted file mode 100644 index df3f8576c..000000000 --- a/Utils/EDI/AnsiX12/EDIAbstract.php +++ /dev/null @@ -1,41 +0,0 @@ -header = new Header(); - } -} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/FunctionalGroupHeader.php b/Utils/EDI/AnsiX12/FunctionalGroupHeader.php deleted file mode 100644 index d5a2b585a..000000000 --- a/Utils/EDI/AnsiX12/FunctionalGroupHeader.php +++ /dev/null @@ -1,176 +0,0 @@ -date = new \DateTime(); - } - - public function getFunctionalGroupHeader() : string - { - return $this->functionalGroupHeader; - } - - public function getFunctionalIdentifierCode() : string - { - return $this->functionalIdentifierCode; - } - - public function setFunctionalIdentifierCode(string $code) /* : void */ - { - if(!FunctionalIdentifierCode::isValidValue($code)) { - throw \Exception(); - } - - $this->functionalIdentifierCode = $code; - } - - public function getApplicationSenderCode() : string - { - return str_pad((string) $this->applicationSenderCode, 2, '0', STR_PAD_LEFT); - } - - public function setApplicationSenderCode(string $code) /* : void */ - { - if(strlen($code) < 2 || strlen($code) > 15) { - throw new \Exception(); - } - - $this->applicationSenderCode = $code; - } - - public function getApplicationReceiverCode() : string - { - return str_pad((string) $this->applicationReceiverCode, 2, '0', STR_PAD_LEFT); - } - - public function setApplicationReceiverCode(string $code) /* : void */ - { - if(strlen($code) < 2 || strlen($code) > 15) { - throw new \Exception(); - } - - $this->applicationReceiverCode = $code; - } - - public function setDate(\DateTime $date) /* : void */ - { - $this->date = $date; - } - - public function getDate() : string - { - return $this->date->format('d:m:y'); - } - - public function getTime() : string - { - return $this->date->format('d:m:y'); - } - - public function getGroupControlNumber() : int - { - return $this->groupControlNumber; - } - - public function setGroupControlNumber(int $number) /* : void */ - { - if($number < 0) { - throw new \Exception(); - } - - $this->groupControlNumber = $number; - } - - public function getResponsibleAgencyCode() : int - { - return $this->responsibleAgencyCode; - } - - public function setResponsibleAgencyCode(int $code) /* : void */ - { - if($code < 0 || $code > 99) { - throw new \Exception(); - } - - $this->responsibleAgencyCode = $code; - } - - public function getVersion() : string - { - return $this->version; - } - - public function setVersion(string $version) /* : void */ - { - $this->version = $version; - } - - public function serialize() - { - return $this->functionalGroupHeader . '*' - . $this->getFunctionalIdentifierCode() . '*' - . $this->getApplicationSenderCode() . '*' - . $this->getApplicationReceiverCode() . '*' - . $this->getDate() . '*' - . $this->getTime() . '*' - . $this->getGroupControlNumber() . '*' - . $this->getResponsibleAgencyCode() . '*' - . $this->getVersion() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; - } - - public function unserialize($raw) - { - $split = explode($raw); - - $this->setFunctionalGroupHeader(trim($split[0])); - $this->setFunctionalIdentifierCode(trim($split[1])); - $this->setApplicationSenderCode(trim($split[2])); - $this->setApplicationReceiverCode(trim($split[3])); - $this->setDate(new \DateTime(trim($split[4]) . '-' . trim($split[5]))); - $this->setGroupControlNumber(trim($split[6])); - $this->setResponsibleAgencyCode((int) trim($split[7])); - $this->setVersion(trim($split[8])); - } -} diff --git a/Utils/EDI/AnsiX12/Header.php b/Utils/EDI/AnsiX12/Header.php deleted file mode 100644 index 5bb602420..000000000 --- a/Utils/EDI/AnsiX12/Header.php +++ /dev/null @@ -1,38 +0,0 @@ -interchangeControlHeader = new InterchangeControlHeader(); - $this->functionalGroupHeader = new FunctionalGroupHeader(); - } -} diff --git a/Utils/EDI/AnsiX12/InterchangeControlHeader.php b/Utils/EDI/AnsiX12/InterchangeControlHeader.php deleted file mode 100644 index fcfd74f95..000000000 --- a/Utils/EDI/AnsiX12/InterchangeControlHeader.php +++ /dev/null @@ -1,427 +0,0 @@ -'; - - private $interchangeControlHeader = InterchangeControlHeader::ISA; - - /** - * Code to identify the type of information in the Authorization Information. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Authorization Information available - * - * @var int - * @since 1.0.0 - */ - private $authorizationInformationQualifier = 0; - - - /** - * Information used for additional identification or authorization of the interchange - * sender or the data in the interchange; the type of information is set by the Authorization - * Information Qualifier. - * - * Req: M - * Type: AN - * Min/Max: 10/10 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $authorizationInformation = ''; - - /** - * Code to identify the type of information in the Security Information. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Security Information available - * - * @var int - * @since 1.0.0 - */ - private $securityInformationQualifer = 0; - - /** - * This is used for identifying the security information about the interchange - * sender or the data in the interchange; the type of information is set by the Security - * Information Qualifier. - * - * Req: M - * Type: AN - * Min/Max: 10/10 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $securityInformation = ''; - - /** - * Qualifier to designate the system/method of code structure used to designate - * the sender or receiver ID element being qualifiedn. - * - * Req: M - * Type: ID - * Min/Max: 2/2 - * Usage: Must - * - * 00 = No Security Information available - * - * @var int - * @since 1.0.0 - */ - private $interchangeIdQualifier = 0; - - /** - * Interchange Sender - * - * Req: M - * Type: AN - * Min/Max: 15/15 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $interchangeSender = ''; - - /** - * DateTime of the interchange - * - * Req: M - * Type: DTM - * Usage: Must - * - * @var \DateTime - * @since 1.0.0 - */ - private $interchangeDateTime = null; - - /** - * Code to identify the agency responsible for the control standard used by the - * message that is enclosed by the interchange header and trailer. - * - * Req: M - * Type: ID - * Min/Max: 1/1 - * Usage: Must - * - * @var string - * @since 1.0.0 - */ - private $interchangeControlStandardId = ''; - - /** - * Code specifying the version number of the interchange control segments. - * - * Req: M - * Type: ID - * Min/Max: 5/5 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $interchangeControlVersionNumber = 401; - - /** - * A control number assigned by the interchange sender. - * - * Req: M - * Type: int - * Min/Max: 9/9 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $interchangeControlNumber = 0; - - /** - * Code sent by the sender to request an interchange acknowledgment. - * - * Req: M - * Type: bool - * Min/Max: 1/1 - * Usage: Must - * - * @var bool - * @since 1.0.0 - */ - private $acknowledgementRequested = false; - - /** - * Code to indicate whether data enclosed by this interchange envelope is test, - * production or information. - * - * Req: M - * Type: ID - * Min/Max: 1/1 - * Usage: Must - * - * @var int - * @since 1.0.0 - */ - private $usageIndicator = 'T'; - - public function setInterchangeControlHeader(string $header) /* : void */ - { - $this->interchangeControlHeader = $header; - } - - public function setAuthorizationInformationQualifier(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->authorizationInformationQualifier = $qualifier; - } - - public function getAuthorizationInformationQualifier() : string - { - return str_pad((string) $this->authorizationInformationQualifier, 2, '0', STR_PAD_LEFT); - } - - public function setAuthorizationInformation(string $information) /* : void */ - { - if(strlen($information) > 10) { - throw new \Exception(); - } - - $this->authorizationInformation = $information; - } - - public function getAuthorizationInformation() : string - { - return str_pad((string) $this->authorizationInformation, 10, ' ', STR_PAD_RIGHT); - } - - public function setSecurityInformationQualifer(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->securityInformationQualifer = $qualifier; - } - - public function getSecurityInformationQualifer() : string - { - return str_pad((string) $this->securityInformationQualifer, 2, '0', STR_PAD_LEFT); - } - - public function setSecurityInformation(string $information) /* : void */ - { - if(strlen($information) > 10) { - throw new \Exception(); - } - - $this->securityInformation = $information; - } - - public function getSecurityInformation() : string - { - return str_pad((string) $this->securityInformation, 10, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeIdQualifier(int $qualifer) /* : void */ - { - if($qualifer > 99) { - throw new \Exception(); - } - - $this->interchangeIdQualifier = $qualifier; - } - - public function getInterchangeIdQualifier() : string - { - return str_pad((string) $this->interchangeIdQualifier, 2, '0', STR_PAD_LEFT); - } - - - public function setInterchangeSender(string $information) /* : void */ - { - if(strlen($information) > 15) { - throw new \Exception(); - } - - $this->interchangeSender = $information; - } - - public function getInterchangeSender() : string - { - return str_pad((string) $this->interchangeSender, 15, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeReceiver(string $information) /* : void */ - { - if(strlen($information) > 15) { - throw new \Exception(); - } - - $this->interchangeReceiver = $information; - } - - public function getInterchangeReceiver() : string - { - return str_pad((string) $this->interchangeReceiver, 15, ' ', STR_PAD_RIGHT); - } - - public function setInterchangeDatetime(\DateTime $interchange) /* : void */ - { - $this->interchangeDateTime = $interchange; - } - - public function getInterchangeDate() : string - { - return $this->interchangeDateTime->format('d:m:y'); - } - - public function getInterchangeTime() : string - { - return $this->interchangeDateTime->format('H:i'); - } - - public function setInterchangeControlStandardId(string $id) /* : void */ - { - if(strlen($id) !== 1) { - throw new \Exception(); - } - - $this->interchangeControlStandardId = $id; - } - - public function getInterchangeControlStandardId() : string - { - return $this->interchangeControlStandardId; - } - - public function setInterchangeControlVersionNumber(int $version) /* : void */ - { - if($version > 99999) { - throw new \Exception(); - } - - $this->interchangeControlVersionNumber = $version; - } - - public function getInterchangeControlVersionNumber() : string - { - return str_pad((string) $this->interchangeControlVersionNumber, 5, '0', STR_PAD_LEFT); - } - - public function setInterchangeControlNumber(int $number) /* : void */ - { - if($number > 999999999) { - throw new \Exception(); - } - - $this->interchangeControlNumber = $number; - } - - public function getInterchangeControlNumber() : string - { - return str_pad((string) $this->interchangeControlNumber, 9, '0', STR_PAD_LEFT); - } - - public function setAcknowledgmentRequested(bool $ack) /* : void */ - { - $this->acknowledgmentRequested = $ack; - } - - public function getAcknowledgmentRequested() : string - { - return (string) $this->acknowledgmentRequested; - } - - public function setUsageUndicator(string $id) /* : void */ - { - if(strlen($id) !== 1) { - throw new \Exception(); - } - - $this->usageIndicator = $id; - } - - public function getUsageUndicator() : string - { - return $this->usageIndicator; - } - - public function serialize() - { - return $this->interchangeControlHeader . '*' - . $this->getAuthorizationInformationQualifier() . '*' - . $this->getAuthorizationInformation() . '*' - . $this->getSecurityInformationQualifer() . '*' - . $this->getSecurityInformation() . '*' - . $this->getInterchangeIdQualifier() . '*' - . $this->getInterchangeSender() . '*' - . $this->getInterchangeIdQualifier() . '*' - . $this->getInterchangeReceiver() . '*' - . $this->getInterchangeDate() . '*' - . $this->getInterchangeTime() . '*' - . $this->getInterchangeControlStandardId() . '*' - . $this->getInterchangeControlVersionNumber() . '*' - . $this->getInterchangeControlNumber() . '*' - . $this->getAcknowledgmentRequested() . '*' - . $this->getUsageUndicator() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; - } - - public function unserialize($raw) - { - $split = explode($raw); - - $this->setInterchangeControlHeader(trim($split[0])); - $this->setAuthorizationInformationQualifier((int) trim($split[1])); - $this->setAuthorizationInformation(trim($split[2])); - $this->setSecurityInformationQualifer((int) trim($split[3])); - $this->setSecurityInformation(trim($split[4])); - $this->setInterchangeIdQualifier((int) trim($split[5])); - $this->setInterchangeSender(trim($split[6])); - $this->setInterchangeReceiver(trim($split[8])); - $this->setInterchangeDatetime(new \DateTime(trim($split[9]) . '-' . trim($split[10]))); - $this->setInterchangeControlStandardId(trim($split[11])); - $this->setInterchangeControlVersionNumber((int) trim($split[12])); - $this->setInterchangeControlNumber((int) trim($split[13])); - $this->setAcknowledgmentRequested((bool) $split[14]); - $this->setUsageUndicator($split[15]); - } -} diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php deleted file mode 100644 index aa115c032..000000000 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php +++ /dev/null @@ -1,58 +0,0 @@ -interchangeControlHeader = new ISA(); - $this->functionalGroupHeader = new GS(); - - $this->heading = new EDI850Heading(); - $this->detail = new EDI850Detail(); - $this->summary = new EDI850Summary(); - - $this->functionalGroupTrailer = new GE(); - $this->interchangeControlTrailer = new IEA(); - } -} diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php deleted file mode 100644 index 2cdade6a8..000000000 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Detail.php +++ /dev/null @@ -1,44 +0,0 @@ -headingTransactionSetHeader = new ST(850); - $this->headingBeginningSegmentPO = new BEG(); - } -} diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php deleted file mode 100644 index 9eb92e10f..000000000 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Summary.php +++ /dev/null @@ -1,36 +0,0 @@ -transactionSetIdentifierCode; - } - - public function setTransactionIdentifierCode(int $code) /* : void */ - { - $this->transactionSetIdentifierCode = $code; - } - - public function getTransactionSetControlNumber() : string - { - return str_pad((string) $this->transactionSetControlNumber, 9, '0', STR_PAD_LEFT); - } - - public function setTransactionSetControlNumber(string $number) /* : void */ - { - if(strlen($number) < 4 || strlen($number) > 9) { - throw new \Exception(); - } - - $this->transactionSetControlNumber = $number; - } - - public function unserialize($raw) - { - $split = explode($raw); - - $this->setTransactionSetIdentifierCode((int) trim($split[1])); - $this->setTransactionSetControlNumber(trim($split[2])); - } - - public function serialize() - { - return self::IDENTIFIER . '*' - . $this->getTransactionSetIdentifierCode() . '*' - . $this->getTransactionSetControlNumber(); - } -} diff --git a/Utils/EDI/Edifact/APERAK.php b/Utils/EDI/Edifact/APERAK.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/AUTHOR.php b/Utils/EDI/Edifact/AUTHOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BALANC.php b/Utils/EDI/Edifact/BALANC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BANSTA.php b/Utils/EDI/Edifact/BANSTA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BAPLIE.php b/Utils/EDI/Edifact/BAPLIE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BAPLTE.php b/Utils/EDI/Edifact/BAPLTE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BERMAN.php b/Utils/EDI/Edifact/BERMAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BMISRM.php b/Utils/EDI/Edifact/BMISRM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BOPBNK.php b/Utils/EDI/Edifact/BOPBNK.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BOPCUS.php b/Utils/EDI/Edifact/BOPCUS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BOPDIR.php b/Utils/EDI/Edifact/BOPDIR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BOPINF.php b/Utils/EDI/Edifact/BOPINF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/BUSCRD.php b/Utils/EDI/Edifact/BUSCRD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CALINF.php b/Utils/EDI/Edifact/CALINF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CASINT.php b/Utils/EDI/Edifact/CASINT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CASRES.php b/Utils/EDI/Edifact/CASRES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CHACCO.php b/Utils/EDI/Edifact/CHACCO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CLASET.php b/Utils/EDI/Edifact/CLASET.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CNTCND.php b/Utils/EDI/Edifact/CNTCND.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COACSU.php b/Utils/EDI/Edifact/COACSU.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COARRI.php b/Utils/EDI/Edifact/COARRI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CODECO.php b/Utils/EDI/Edifact/CODECO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CODENO.php b/Utils/EDI/Edifact/CODENO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COEDOR.php b/Utils/EDI/Edifact/COEDOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COHAOR.php b/Utils/EDI/Edifact/COHAOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COLREQ.php b/Utils/EDI/Edifact/COLREQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COMDIS.php b/Utils/EDI/Edifact/COMDIS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONAPW.php b/Utils/EDI/Edifact/CONAPW.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONDPV.php b/Utils/EDI/Edifact/CONDPV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONDRA.php b/Utils/EDI/Edifact/CONDRA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONDRO.php b/Utils/EDI/Edifact/CONDRO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONEST.php b/Utils/EDI/Edifact/CONEST.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONITT.php b/Utils/EDI/Edifact/CONITT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONPVA.php b/Utils/EDI/Edifact/CONPVA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONQVA.php b/Utils/EDI/Edifact/CONQVA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONRPW.php b/Utils/EDI/Edifact/CONRPW.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONTEN.php b/Utils/EDI/Edifact/CONTEN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CONWQD.php b/Utils/EDI/Edifact/CONWQD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COPARN.php b/Utils/EDI/Edifact/COPARN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COPAYM.php b/Utils/EDI/Edifact/COPAYM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COPINO.php b/Utils/EDI/Edifact/COPINO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COPRAR.php b/Utils/EDI/Edifact/COPRAR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COREOR.php b/Utils/EDI/Edifact/COREOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COSTCO.php b/Utils/EDI/Edifact/COSTCO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/COSTOR.php b/Utils/EDI/Edifact/COSTOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CREADV.php b/Utils/EDI/Edifact/CREADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CREEXT.php b/Utils/EDI/Edifact/CREEXT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CREMUL.php b/Utils/EDI/Edifact/CREMUL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSCAR.php b/Utils/EDI/Edifact/CUSCAR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSDEC.php b/Utils/EDI/Edifact/CUSDEC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSEXP.php b/Utils/EDI/Edifact/CUSEXP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSPED.php b/Utils/EDI/Edifact/CUSPED.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSREP.php b/Utils/EDI/Edifact/CUSREP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/CUSRES.php b/Utils/EDI/Edifact/CUSRES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/AJT.php b/Utils/EDI/Edifact/Components/AJT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/ALC.php b/Utils/EDI/Edifact/Components/ALC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/ALI.php b/Utils/EDI/Edifact/Components/ALI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/APR.php b/Utils/EDI/Edifact/Components/APR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/BGM.php b/Utils/EDI/Edifact/Components/BGM.php deleted file mode 100644 index f3f8fb7fa..000000000 --- a/Utils/EDI/Edifact/Components/BGM.php +++ /dev/null @@ -1,47 +0,0 @@ -type = $type; - $this->version = $version; - $this->subersion = $subersion; - $this->un = $un; - $this->bdewVersion = $bdewVersion; - } -} diff --git a/Utils/EDI/Edifact/Components/CAV.php b/Utils/EDI/Edifact/Components/CAV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/CCI.php b/Utils/EDI/Edifact/Components/CCI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/CNT.php b/Utils/EDI/Edifact/Components/CNT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/COM.php b/Utils/EDI/Edifact/Components/COM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/CTA.php b/Utils/EDI/Edifact/Components/CTA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/CUX.php b/Utils/EDI/Edifact/Components/CUX.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/DGS.php b/Utils/EDI/Edifact/Components/DGS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/DOC.php b/Utils/EDI/Edifact/Components/DOC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/EQD.php b/Utils/EDI/Edifact/Components/EQD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/FII.php b/Utils/EDI/Edifact/Components/FII.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/FTX.php b/Utils/EDI/Edifact/Components/FTX.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/GEI.php b/Utils/EDI/Edifact/Components/GEI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/GIN.php b/Utils/EDI/Edifact/Components/GIN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/GIR.php b/Utils/EDI/Edifact/Components/GIR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/GIS.php b/Utils/EDI/Edifact/Components/GIS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/HAN.php b/Utils/EDI/Edifact/Components/HAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/IMD.php b/Utils/EDI/Edifact/Components/IMD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/INP.php b/Utils/EDI/Edifact/Components/INP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/LIN.php b/Utils/EDI/Edifact/Components/LIN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/LOC.php b/Utils/EDI/Edifact/Components/LOC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/MEA.php b/Utils/EDI/Edifact/Components/MEA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/MOA.php b/Utils/EDI/Edifact/Components/MOA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/MTD.php b/Utils/EDI/Edifact/Components/MTD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/NAD.php b/Utils/EDI/Edifact/Components/NAD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PAC.php b/Utils/EDI/Edifact/Components/PAC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PAI.php b/Utils/EDI/Edifact/Components/PAI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PAT.php b/Utils/EDI/Edifact/Components/PAT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PCD.php b/Utils/EDI/Edifact/Components/PCD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PCI.php b/Utils/EDI/Edifact/Components/PCI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PGI.php b/Utils/EDI/Edifact/Components/PGI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PIA.php b/Utils/EDI/Edifact/Components/PIA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PRI.php b/Utils/EDI/Edifact/Components/PRI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/PYT.php b/Utils/EDI/Edifact/Components/PYT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/QTY.php b/Utils/EDI/Edifact/Components/QTY.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/QVR.php b/Utils/EDI/Edifact/Components/QVR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/RCS.php b/Utils/EDI/Edifact/Components/RCS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/REF.php b/Utils/EDI/Edifact/Components/REF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/RJL.php b/Utils/EDI/Edifact/Components/RJL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/RNG.php b/Utils/EDI/Edifact/Components/RNG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/RTE.php b/Utils/EDI/Edifact/Components/RTE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/SEL.php b/Utils/EDI/Edifact/Components/SEL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/STG.php b/Utils/EDI/Edifact/Components/STG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/TAX.php b/Utils/EDI/Edifact/Components/TAX.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/TDT.php b/Utils/EDI/Edifact/Components/TDT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/TOD.php b/Utils/EDI/Edifact/Components/TOD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/TSR.php b/Utils/EDI/Edifact/Components/TSR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/UNH.php b/Utils/EDI/Edifact/Components/UNH.php deleted file mode 100644 index 4c69f96ee..000000000 --- a/Utils/EDI/Edifact/Components/UNH.php +++ /dev/null @@ -1,47 +0,0 @@ -type = $type; - $this->version = $version; - $this->subersion = $subersion; - $this->un = $un; - $this->bdewVersion = $bdewVersion; - } -} diff --git a/Utils/EDI/Edifact/Components/UNS.php b/Utils/EDI/Edifact/Components/UNS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/Components/UNT.php b/Utils/EDI/Edifact/Components/UNT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DEBADV.php b/Utils/EDI/Edifact/DEBADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DEBMUL.php b/Utils/EDI/Edifact/DEBMUL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DEBREC.php b/Utils/EDI/Edifact/DEBREC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DELFOR.php b/Utils/EDI/Edifact/DELFOR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DELJIT.php b/Utils/EDI/Edifact/DELJIT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DESADV.php b/Utils/EDI/Edifact/DESADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DESTIM.php b/Utils/EDI/Edifact/DESTIM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DGRECA.php b/Utils/EDI/Edifact/DGRECA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DIRDEB.php b/Utils/EDI/Edifact/DIRDEB.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DIRDEF.php b/Utils/EDI/Edifact/DIRDEF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DMRDEF.php b/Utils/EDI/Edifact/DMRDEF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DMSTAT.php b/Utils/EDI/Edifact/DMSTAT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCADV.php b/Utils/EDI/Edifact/DOCADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCAMA.php b/Utils/EDI/Edifact/DOCAMA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCAMI.php b/Utils/EDI/Edifact/DOCAMI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCAMR.php b/Utils/EDI/Edifact/DOCAMR.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCAPP.php b/Utils/EDI/Edifact/DOCAPP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCARE.php b/Utils/EDI/Edifact/DOCARE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/DOCINF.php b/Utils/EDI/Edifact/DOCINF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ENTREC.php b/Utils/EDI/Edifact/ENTREC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/FINCAN.php b/Utils/EDI/Edifact/FINCAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/FINPAY.php b/Utils/EDI/Edifact/FINPAY.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/FINSTA.php b/Utils/EDI/Edifact/FINSTA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/GENRAL.php b/Utils/EDI/Edifact/GENRAL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/GESMES.php b/Utils/EDI/Edifact/GESMES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/HANMOV.php b/Utils/EDI/Edifact/HANMOV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ICASRP.php b/Utils/EDI/Edifact/ICASRP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ICSOLI.php b/Utils/EDI/Edifact/ICSOLI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFCSUM.php b/Utils/EDI/Edifact/IFCSUM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTCCA.php b/Utils/EDI/Edifact/IFTCCA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTDGN.php b/Utils/EDI/Edifact/IFTDGN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTFCC.php b/Utils/EDI/Edifact/IFTFCC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTIAG.php b/Utils/EDI/Edifact/IFTIAG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTICL.php b/Utils/EDI/Edifact/IFTICL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMAN.php b/Utils/EDI/Edifact/IFTMAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMBC.php b/Utils/EDI/Edifact/IFTMBC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMBF.php b/Utils/EDI/Edifact/IFTMBF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMBP.php b/Utils/EDI/Edifact/IFTMBP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMCA.php b/Utils/EDI/Edifact/IFTMCA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMCS.php b/Utils/EDI/Edifact/IFTMCS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTMIN.php b/Utils/EDI/Edifact/IFTMIN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTRIN.php b/Utils/EDI/Edifact/IFTRIN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTSAI.php b/Utils/EDI/Edifact/IFTSAI.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTSTA.php b/Utils/EDI/Edifact/IFTSTA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IFTSTQ.php b/Utils/EDI/Edifact/IFTSTQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IMPDEF.php b/Utils/EDI/Edifact/IMPDEF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INFCON.php b/Utils/EDI/Edifact/INFCON.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INFENT.php b/Utils/EDI/Edifact/INFENT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INSDES.php b/Utils/EDI/Edifact/INSDES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INSPRE.php b/Utils/EDI/Edifact/INSPRE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INSREQ.php b/Utils/EDI/Edifact/INSREQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INSRPT.php b/Utils/EDI/Edifact/INSRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/INVOIC.php b/Utils/EDI/Edifact/INVOIC.php deleted file mode 100644 index 9361d2eb0..000000000 --- a/Utils/EDI/Edifact/INVOIC.php +++ /dev/null @@ -1,41 +0,0 @@ -unh = new UNH('INVOIC', 'D', '06A', 'UN', '2.6d'); - $this->bgm = new BGM(); - } -} diff --git a/Utils/EDI/Edifact/INVRPT.php b/Utils/EDI/Edifact/INVRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IPPOAD.php b/Utils/EDI/Edifact/IPPOAD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/IPPOMO.php b/Utils/EDI/Edifact/IPPOMO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ISENDS.php b/Utils/EDI/Edifact/ISENDS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ITRRPT.php b/Utils/EDI/Edifact/ITRRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JAPRES.php b/Utils/EDI/Edifact/JAPRES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JINFDE.php b/Utils/EDI/Edifact/JINFDE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JOBAPP.php b/Utils/EDI/Edifact/JOBAPP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JOBCON.php b/Utils/EDI/Edifact/JOBCON.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JOBMOD.php b/Utils/EDI/Edifact/JOBMOD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JOBOFF.php b/Utils/EDI/Edifact/JOBOFF.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/JUPREQ.php b/Utils/EDI/Edifact/JUPREQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/LEDGER.php b/Utils/EDI/Edifact/LEDGER.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/LREACT.php b/Utils/EDI/Edifact/LREACT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/LRECLM.php b/Utils/EDI/Edifact/LRECLM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEDPID.php b/Utils/EDI/Edifact/MEDPID.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEDPRE.php b/Utils/EDI/Edifact/MEDPRE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEDREQ.php b/Utils/EDI/Edifact/MEDREQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEDRPT.php b/Utils/EDI/Edifact/MEDRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEDRUC.php b/Utils/EDI/Edifact/MEDRUC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MEQPOS.php b/Utils/EDI/Edifact/MEQPOS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MOVINS.php b/Utils/EDI/Edifact/MOVINS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/MSCONS.php b/Utils/EDI/Edifact/MSCONS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ORDCHG.php b/Utils/EDI/Edifact/ORDCHG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ORDERS.php b/Utils/EDI/Edifact/ORDERS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/ORDRSP.php b/Utils/EDI/Edifact/ORDRSP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/OSTENQ.php b/Utils/EDI/Edifact/OSTENQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/OSTRPT.php b/Utils/EDI/Edifact/OSTRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PARTIN.php b/Utils/EDI/Edifact/PARTIN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PAXLST.php b/Utils/EDI/Edifact/PAXLST.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PAYDUC.php b/Utils/EDI/Edifact/PAYDUC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PAYEXT.php b/Utils/EDI/Edifact/PAYEXT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PAYMUL.php b/Utils/EDI/Edifact/PAYMUL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PAYORD.php b/Utils/EDI/Edifact/PAYORD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PRICAT.php b/Utils/EDI/Edifact/PRICAT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PRIHIS.php b/Utils/EDI/Edifact/PRIHIS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PROCST.php b/Utils/EDI/Edifact/PROCST.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PRODAT.php b/Utils/EDI/Edifact/PRODAT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PRODEX.php b/Utils/EDI/Edifact/PRODEX.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PROINQ.php b/Utils/EDI/Edifact/PROINQ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PROSRV.php b/Utils/EDI/Edifact/PROSRV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PROTAP.php b/Utils/EDI/Edifact/PROTAP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/PRPAID.php b/Utils/EDI/Edifact/PRPAID.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/QALITY.php b/Utils/EDI/Edifact/QALITY.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/QUOTES.php b/Utils/EDI/Edifact/QUOTES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RDRMES.php b/Utils/EDI/Edifact/RDRMES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REBORD.php b/Utils/EDI/Edifact/REBORD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RECADV.php b/Utils/EDI/Edifact/RECADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RECALC.php b/Utils/EDI/Edifact/RECALC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RECECO.php b/Utils/EDI/Edifact/RECECO.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RECLAM.php b/Utils/EDI/Edifact/RECLAM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RECORD.php b/Utils/EDI/Edifact/RECORD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REGENT.php b/Utils/EDI/Edifact/REGENT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RELIST.php b/Utils/EDI/Edifact/RELIST.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REMADV.php b/Utils/EDI/Edifact/REMADV.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REPREM.php b/Utils/EDI/Edifact/REPREM.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REQDOC.php b/Utils/EDI/Edifact/REQDOC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/REQOTE.php b/Utils/EDI/Edifact/REQOTE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RESETT.php b/Utils/EDI/Edifact/RESETT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RESMSG.php b/Utils/EDI/Edifact/RESMSG.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RETACC.php b/Utils/EDI/Edifact/RETACC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RETANN.php b/Utils/EDI/Edifact/RETANN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RETINS.php b/Utils/EDI/Edifact/RETINS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/RPCALL.php b/Utils/EDI/Edifact/RPCALL.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SAFHAZ.php b/Utils/EDI/Edifact/SAFHAZ.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SANCRT.php b/Utils/EDI/Edifact/SANCRT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SLSFCT.php b/Utils/EDI/Edifact/SLSFCT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SLSRPT.php b/Utils/EDI/Edifact/SLSRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SOCADE.php b/Utils/EDI/Edifact/SOCADE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SSIMOD.php b/Utils/EDI/Edifact/SSIMOD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SSRECH.php b/Utils/EDI/Edifact/SSRECH.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SSREGW.php b/Utils/EDI/Edifact/SSREGW.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/STATAC.php b/Utils/EDI/Edifact/STATAC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/STLRPT.php b/Utils/EDI/Edifact/STLRPT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SUPCOT.php b/Utils/EDI/Edifact/SUPCOT.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SUPMAN.php b/Utils/EDI/Edifact/SUPMAN.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/SUPRES.php b/Utils/EDI/Edifact/SUPRES.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/TANSTA.php b/Utils/EDI/Edifact/TANSTA.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/TAXCON.php b/Utils/EDI/Edifact/TAXCON.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/TPFREP.php b/Utils/EDI/Edifact/TPFREP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/UTILMD.php b/Utils/EDI/Edifact/UTILMD.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/UTILTS.php b/Utils/EDI/Edifact/UTILTS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/VATDEC.php b/Utils/EDI/Edifact/VATDEC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/VESDEP.php b/Utils/EDI/Edifact/VESDEP.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/WASDIS.php b/Utils/EDI/Edifact/WASDIS.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/WKGRDC.php b/Utils/EDI/Edifact/WKGRDC.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/EDI/Edifact/WKGRRE.php b/Utils/EDI/Edifact/WKGRRE.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/Utils/Encoding/Caesar.php b/Utils/Encoding/Caesar.php index bcb44d23b..52e995ac2 100644 --- a/Utils/Encoding/Caesar.php +++ b/Utils/Encoding/Caesar.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Caesar @@ -85,7 +83,7 @@ class Caesar $ascii = ord($raw[$i]) - ord($key[$j]); if ($ascii < self::LIMIT_LOWER) { - $ascii = self::LIMIT_UPPER + ($ascii - self::LIMIT_LOWER) ; + $ascii = self::LIMIT_UPPER + ($ascii - self::LIMIT_LOWER); } $result .= chr($ascii); @@ -93,4 +91,4 @@ class Caesar return $result; } -} \ No newline at end of file +} diff --git a/Utils/Encoding/EncodingInterface.php b/Utils/Encoding/EncodingInterface.php index 50eca9533..ea1c5b534 100644 --- a/Utils/Encoding/EncodingInterface.php +++ b/Utils/Encoding/EncodingInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding; /** * Encoding Interface * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface EncodingInterface @@ -47,4 +45,4 @@ interface EncodingInterface * @since 1.0.0 */ public static function decode($decoded); -} \ No newline at end of file +} diff --git a/Utils/Encoding/Gray.php b/Utils/Encoding/Gray.php index 449f010f5..a1055bc8e 100644 --- a/Utils/Encoding/Gray.php +++ b/Utils/Encoding/Gray.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class Gray @@ -47,4 +45,4 @@ final class Gray return $source; } -} \ No newline at end of file +} diff --git a/Utils/Encoding/Huffman/Dictionary.php b/Utils/Encoding/Huffman/Dictionary.php index 6af369bec..76b8b73c0 100644 --- a/Utils/Encoding/Huffman/Dictionary.php +++ b/Utils/Encoding/Huffman/Dictionary.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding\Huffman; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class Dictionary @@ -217,4 +215,4 @@ final class Dictionary return null; } -} \ No newline at end of file +} diff --git a/Utils/Encoding/Huffman/Huffman.php b/Utils/Encoding/Huffman/Huffman.php index 165879c0d..21a56d1c1 100644 --- a/Utils/Encoding/Huffman/Huffman.php +++ b/Utils/Encoding/Huffman/Huffman.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding\Huffman; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class Huffman @@ -149,4 +147,4 @@ final class Huffman return $source; } -} \ No newline at end of file +} diff --git a/Utils/Encoding/XorEncoding.php b/Utils/Encoding/XorEncoding.php index e34df4c3f..a9b80e173 100644 --- a/Utils/Encoding/XorEncoding.php +++ b/Utils/Encoding/XorEncoding.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Encoding; /** * XOR encoding class * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class XorEncoding @@ -49,10 +47,10 @@ final class XorEncoding $j = 0; } - $ascii = ord($source[$i]) ^ ord($key[$j]); + $ascii = ord($source[$i]) ^ ord($key[$j]); $result .= chr($ascii); } return $result; } -} \ No newline at end of file +} diff --git a/Utils/Excel/Excel.php b/Utils/Excel/Excel.php index 242a5aa3c..7b3d0fed8 100644 --- a/Utils/Excel/Excel.php +++ b/Utils/Excel/Excel.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Excel; @@ -21,8 +20,7 @@ require_once realpath(__DIR__ . '/../../../Resources/phpexcel/Classes/PHPExcel.p /** * Excel class. * - * @category Modules - * @package phpOMS\Utils\Excel + * @package Modules * @since 1.0.0 */ diff --git a/Utils/Git/Author.php b/Utils/Git/Author.php index 9d8c91b87..3ad752009 100644 --- a/Utils/Git/Author.php +++ b/Utils/Git/Author.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Author @@ -181,4 +179,4 @@ class Author { return $this->removalsCount; } -} \ No newline at end of file +} diff --git a/Utils/Git/Branch.php b/Utils/Git/Branch.php index b19c63367..706a12b30 100644 --- a/Utils/Git/Branch.php +++ b/Utils/Git/Branch.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Branch @@ -67,6 +65,6 @@ class Branch */ public function setName(string $name) /* : void */ { - $this->name = escapeshellarg($name); + $this->name = $name; } -} \ No newline at end of file +} diff --git a/Utils/Git/Commit.php b/Utils/Git/Commit.php index 2248e97c2..f9e4a84d8 100644 --- a/Utils/Git/Commit.php +++ b/Utils/Git/Commit.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Commit @@ -99,10 +97,11 @@ class Commit */ public function __construct(string $id = '') { - $this->id = $id; - $this->author = new Author(); - $this->branch = new Branch(); - $this->tag = new Tag(); + $this->id = $id; + $this->author = new Author(); + $this->branch = new Branch(); + $this->tag = new Tag(); + $this->repository = new Repository(realpath(__DIR__ . '/../../../../../')); } /** diff --git a/Utils/Git/Git.php b/Utils/Git/Git.php index 9b7cbcc6c..5bcc0bbe8 100644 --- a/Utils/Git/Git.php +++ b/Utils/Git/Git.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; @@ -20,11 +19,11 @@ use phpOMS\System\File\PathException; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class Git { diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index 6f2be2d1f..49164a72c 100644 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; @@ -21,11 +20,11 @@ use phpOMS\Utils\StringUtils; /** * Repository class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class Repository { @@ -71,7 +70,6 @@ class Repository public function __construct(string $path) { $this->setPath($path); - $this->branch = $this->getActiveBranch(); } /** @@ -115,15 +113,11 @@ class Repository */ public function getActiveBranch() : Branch { - if (!isset($this->branch)) { - $branches = $this->getBranches(); - $active = preg_grep('/^\*/', $branches); - reset($active); + $branches = $this->getBranches(); + $active = preg_grep('/^\*/', $branches); + reset($active); - $this->branch = new Branch(current($active)); - } - - return $this->branch; + return new Branch(current($active)); } /** @@ -163,9 +157,14 @@ class Repository private function run(string $cmd) : array { if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { - $cmd = 'cd ' . escapeshellarg(dirname(Git::getBin())) . ' && ' . basename(Git::getBin()) . ' -C ' . escapeshellarg($this->path) . ' ' . $cmd; + $cmd = 'cd ' . escapeshellarg(dirname(Git::getBin())) + . ' && ' . basename(Git::getBin()) + . ' -C ' . escapeshellarg($this->path) . ' ' + . $cmd; } else { - $cmd = escapeshellarg(Git::getBin()) . ' -C ' . escapeshellarg($this->path) . ' ' . $cmd; + $cmd = escapeshellarg(Git::getBin()) + . ' -C ' . escapeshellarg($this->path) . ' ' + . $cmd; } $pipes = []; @@ -220,23 +219,24 @@ class Repository * Create repository * * @param string $source Create repository from source (optional, can be remote) - * @param bool $bare Bare repository + * + * @return string * * @throws \Exception * * @since 1.0.0 */ - public function create(string $source = null, bool $bare = false) + public function create(string $source = null) { if (!is_dir($this->path) || file_exists($this->path . '/.git')) { throw new \Exception('Already repository'); } if (isset($source)) { - $this->clone($source); - } else { - $this->init($bare); + return stripos($source, '//') !== false ? $this->cloneRemote($source) : $this->cloneFrom($source); } + + return $this->run('init'); } /** @@ -264,11 +264,7 @@ class Repository */ public function add($files = '*') : string { - if (is_array($files)) { - $files = '"' . implode('" "', $files) . '"'; - } elseif (!is_string($files)) { - throw new \Exception('Wrong type'); - } + $files = $this->parseFileList($files); return implode("\n", $this->run('add ' . $files . ' -v')); } @@ -281,19 +277,35 @@ class Repository * * @return string * - * @throws \InvalidArgumentException - * * @since 1.0.0 */ public function rm($files = '*', bool $cached = false) : string + { + $files = $this->parseFileList($files); + + return implode("\n", $this->run('rm ' . ($cached ? '--cached ' : '') . $files)); + } + + /** + * Remove file(s) from repository + * + * @param string|array $files Files to remove + * + * @return string + * + * @throws \InvalidArgumentException + * + * @since 1.0.0 + */ + private function parseFileList($files) : string { if (is_array($files)) { - $files = '"' . implode('" "', $files) . '"'; + return '"' . implode('" "', $files) . '"'; } elseif (!is_string($files)) { throw new \InvalidArgumentException('Wrong type for $files.'); } - return implode("\n", $this->run('rm ' . ($cached ? '--cached ' : '') . $files)); + return $files; } /** @@ -619,7 +631,7 @@ class Repository * * @since 1.0.0 */ - public function getLOC(array $extensions = ['*']) : int + public function getLoc(array $extensions = ['*']) : int { $lines = $this->run('ls-files'); $loc = 0; @@ -734,13 +746,26 @@ class Repository */ public function getAdditionsRemovalsByContributor(Author $author, \DateTime $start = null, \DateTime $end = null) : array { + if (!isset($start)) { + $start = new \DateTime('1900-01-01'); + } + + if (!isset($end)) { + $end = new \DateTime('now'); + } + $addremove = ['added' => 0, 'removed' => 0]; - $lines = $this->run('log --author=' . escapeshellarg($author->getName()) . ' --since="' . $start->format('Y-m-d') . '" --before="' . $end->format('Y-m-d') . '" --pretty=tformat: --numstat'); + $lines = $this->run( + 'log --author=' . escapeshellarg($author->getName()) + . ' --since="' . $start->format('Y-m-d') + . '" --before="' . $end->format('Y-m-d') + . '" --pretty=tformat: --numstat' + ); foreach ($lines as $line) { $nums = explode(' ', $line); - $addremove['added'] += $nums[0]; + $addremove['added'] += $nums[0]; $addremove['removed'] += $nums[1]; } @@ -756,7 +781,7 @@ class Repository */ public function getRemote() : string { - return $this->run('config --get remote.origin.url'); + return implode("\n", $this->run('config --get remote.origin.url')); } /** @@ -786,7 +811,11 @@ class Repository $author = ' --author=' . escapeshellarg($author->getName()) . ''; } - $lines = $this->run('git log --before="' . $end->format('Y-m-d') . '" --after="' . $start->format('Y-m-d') . '"' . $author . ' --reverse --date=short'); + $lines = $this->run( + 'git log --before="' . $end->format('Y-m-d') + . '" --after="' . $start->format('Y-m-d') . '"' + . $author . ' --reverse --date=short'); + $count = count($lines); $commits = []; diff --git a/Utils/Git/Tag.php b/Utils/Git/Tag.php index c850f8c1d..6f401c623 100644 --- a/Utils/Git/Tag.php +++ b/Utils/Git/Tag.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Git; /** * Gray encoding class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Tag @@ -51,7 +49,7 @@ class Tag */ public function __construct(string $name = '') { - $this->name = escapeshellarg($name); + $this->name = $name; } /** @@ -75,7 +73,7 @@ class Tag */ public function setMessage(string $message) /* : void */ { - $this->message = escapeshellarg($message); + $this->message = $message; } /** @@ -89,5 +87,4 @@ class Tag { return $this->name; } - -} \ No newline at end of file +} diff --git a/Utils/IO/Csv/CsvDatabaseMapper.php b/Utils/IO/Csv/CsvDatabaseMapper.php index 52ad106ff..ec539abd1 100644 --- a/Utils/IO/Csv/CsvDatabaseMapper.php +++ b/Utils/IO/Csv/CsvDatabaseMapper.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Csv; @@ -26,7 +25,9 @@ class CsvDatabaseMapper implements IODatabaseMapper private $sources = []; private $delimiter = ';'; + private $enclosure = '"'; + private $lineBuffer = 500; private $autoIdentifyCsvSettings = false; diff --git a/Utils/IO/Csv/CsvInterface.php b/Utils/IO/Csv/CsvInterface.php index f18ce1399..59ba4664b 100644 --- a/Utils/IO/Csv/CsvInterface.php +++ b/Utils/IO/Csv/CsvInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Csv { @@ -20,12 +19,11 @@ namespace phpOMS\Utils\IO\Csv { * * PHP Version 7.1 * - * @category Framework - * @package Utils - * @copyright Dennis Eichhorn + * @package Framework + * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface CsvInterface diff --git a/Utils/IO/Csv/CsvSettings.php b/Utils/IO/Csv/CsvSettings.php index 2e06387be..6312b0344 100644 --- a/Utils/IO/Csv/CsvSettings.php +++ b/Utils/IO/Csv/CsvSettings.php @@ -4,22 +4,20 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Csv; /** * Options trait. * - * @category Framework - * @package phpOMS\Config + * @package Framework * @since 1.0.0 */ class CsvSettings diff --git a/Utils/IO/Excel/ExcelDatabaseMapper.php b/Utils/IO/Excel/ExcelDatabaseMapper.php index 26f7cdfe2..a7ebbea74 100644 --- a/Utils/IO/Excel/ExcelDatabaseMapper.php +++ b/Utils/IO/Excel/ExcelDatabaseMapper.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Excel; @@ -20,6 +19,7 @@ use phpOMS\Utils\IO\IODatabaseMapper; class ExcelDatabaseMapper implements IODatabaseMapper { private $sources = []; + private $lineBuffer = 500; public function addSource(string $source) @@ -41,4 +41,3 @@ class ExcelDatabaseMapper implements IODatabaseMapper { } } - diff --git a/Utils/IO/Excel/ExcelInterface.php b/Utils/IO/Excel/ExcelInterface.php index 9d871a5b6..06e8f0cc1 100644 --- a/Utils/IO/Excel/ExcelInterface.php +++ b/Utils/IO/Excel/ExcelInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Excel; /** * Excel interface. * - * @category Framework - * @package Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ExcelInterface diff --git a/Utils/IO/ExchangeInterface.php b/Utils/IO/ExchangeInterface.php index 21b16ad88..77a51a7c2 100644 --- a/Utils/IO/ExchangeInterface.php +++ b/Utils/IO/ExchangeInterface.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO; @@ -23,10 +22,9 @@ use phpOMS\Utils\IO\Pdf\PdfInterface; /** * Exchange interface. * - * @category Framework - * @package phpOMS\Utils\IO + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ExchangeInterface extends CsvInterface, JsonInterface, ExcelInterface, PdfInterface diff --git a/Utils/IO/IODatabaseMapper.php b/Utils/IO/IODatabaseMapper.php index eb3eeed37..cd46c3694 100644 --- a/Utils/IO/IODatabaseMapper.php +++ b/Utils/IO/IODatabaseMapper.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO; diff --git a/Utils/IO/Json/InvalidJsonException.php b/Utils/IO/Json/InvalidJsonException.php index 53aa67fef..0d4647679 100644 --- a/Utils/IO/Json/InvalidJsonException.php +++ b/Utils/IO/Json/InvalidJsonException.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Json; /** * Json decoding exception class. * - * @category Framework - * @package phpOMS\Utils\IO\Json + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class InvalidJsonException extends \UnexpectedValueException @@ -31,7 +29,7 @@ class InvalidJsonException extends \UnexpectedValueException * * @param string $message Exception message * @param int $code Exception code - * @param \Exception Previous exception + * @param \Exception $previous Previous exception * * @since 1.0.0 */ diff --git a/Utils/IO/Json/JsonInterface.php b/Utils/IO/Json/JsonInterface.php index d1bb6d1a5..f6903a9c3 100644 --- a/Utils/IO/Json/JsonInterface.php +++ b/Utils/IO/Json/JsonInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Json; /** * Cvs interface. * - * @category Framework - * @package Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface JsonInterface diff --git a/Utils/IO/Pdf/PdfInterface.php b/Utils/IO/Pdf/PdfInterface.php index 64d278a15..a91ca0f9b 100644 --- a/Utils/IO/Pdf/PdfInterface.php +++ b/Utils/IO/Pdf/PdfInterface.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Pdf; /** * Pdf interface. * - * @category Framework - * @package Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface PdfInterface diff --git a/Utils/IO/Zip/ArchiveInterface.php b/Utils/IO/Zip/ArchiveInterface.php index ecf949276..74181d394 100644 --- a/Utils/IO/Zip/ArchiveInterface.php +++ b/Utils/IO/Zip/ArchiveInterface.php @@ -4,22 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); + namespace phpOMS\Utils\IO\Zip; + /** * Archive interface * - * @category Framework - * @package phpOMS\Utils\IO + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ArchiveInterface @@ -36,7 +36,7 @@ interface ArchiveInterface * @since 1.0.0 */ public static function pack($sources, string $destination, bool $overwrite = true) : bool; - + /** * Unpack archive. * diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index 8dbc19300..57336af02 100644 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -4,24 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); + namespace phpOMS\Utils\IO\Zip; + /** * Zip class for handling zip files. * * Providing basic zip support * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Gz implements ArchiveInterface @@ -35,21 +35,21 @@ class Gz implements ArchiveInterface if (!$overwrite && file_exists($destination)) { return false; } - - if(($gz = gzopen($destination, 'w')) === false) { + + if (($gz = gzopen($destination, 'w')) === false) { return false; } - + $src = fopen($source, 'r'); - while(!feof($src)) { + while (!feof($src)) { gzwrite($gz, fread($src, 4096)); } - + fclose($src); - + return gzclose($gz); } - + /** * {@inheritdoc} */ @@ -59,18 +59,18 @@ class Gz implements ArchiveInterface if (file_exists($destination)) { return false; } - - if(($gz = gzopen($source, 'w')) === false) { + + if (($gz = gzopen($source, 'w')) === false) { return false; } - + $dest = fopen($destination, 'w'); while (!gzeof($gz)) { fwrite($dest, gzread($gz, 4096)); } - + fclose($dest); - + return gzclose($gz); } } diff --git a/Utils/IO/Zip/Tar.php b/Utils/IO/Zip/Tar.php index 1bbcf4890..05d00a484 100644 --- a/Utils/IO/Zip/Tar.php +++ b/Utils/IO/Zip/Tar.php @@ -4,24 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); + namespace phpOMS\Utils\IO\Zip; + /** * Zip class for handling zip files. * * Providing basic zip support * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Tar implements ArchiveInterface @@ -46,7 +46,10 @@ class Tar implements ArchiveInterface } if (is_dir($source)) { - $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST); + $files = new \RecursiveIteratorIterator( + new \RecursiveDirectoryIterator($source), + \RecursiveIteratorIterator::SELF_FIRST + ); foreach ($files as $file) { $file = str_replace('\\', '/', $file); @@ -77,6 +80,6 @@ class Tar implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - + } } diff --git a/Utils/IO/Zip/TarGz.php b/Utils/IO/Zip/TarGz.php index dc4f2ca88..df335d38b 100644 --- a/Utils/IO/Zip/TarGz.php +++ b/Utils/IO/Zip/TarGz.php @@ -4,24 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); + namespace phpOMS\Utils\IO\Zip; + /** * Zip class for handling zip files. * * Providing basic zip support * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class TarGz implements ArchiveInterface @@ -31,7 +31,7 @@ class TarGz implements ArchiveInterface */ public static function pack($source, string $destination, bool $overwrite = true) : bool { - if(!Tar::pack($source, $destination . '.tmp', $overwrite)) { + if (!Tar::pack($source, $destination . '.tmp', $overwrite)) { return false; } @@ -40,13 +40,13 @@ class TarGz implements ArchiveInterface return $pack; } - + /** * {@inheritdoc} */ public static function unpack(string $source, string $destination) : bool { - if(!Gz::unpack($source, $destination . '.tmp')) { + if (!Gz::unpack($source, $destination . '.tmp')) { return false; } diff --git a/Utils/IO/Zip/Zip.php b/Utils/IO/Zip/Zip.php index 95640c8c6..73e696b3a 100644 --- a/Utils/IO/Zip/Zip.php +++ b/Utils/IO/Zip/Zip.php @@ -4,29 +4,26 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\IO\Zip; use phpOMS\System\File\FileUtils; -use phpOMS\Utils\StringUtils; /** * Zip class for handling zip files. * * Providing basic zip support * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Zip implements ArchiveInterface @@ -69,7 +66,7 @@ class Zip implements ArchiveInterface $absolute = realpath($file); $absolute = str_replace('\\', '/', $absolute); - $dir = str_replace($source . '/', '', $relative . '/' . $absolute); + $dir = str_replace($source . '/', '', $relative . '/' . $absolute); if (is_dir($absolute)) { $zip->addEmptyDir($dir . '/'); @@ -84,13 +81,13 @@ class Zip implements ArchiveInterface return $zip->close(); } - + /** * {@inheritdoc} */ public static function unpack(string $source, string $destination) : bool { - if(!file_exists($source)) { + if (!file_exists($source)) { return false; } @@ -101,9 +98,9 @@ class Zip implements ArchiveInterface if (!$zip->open($source)) { return false; } - + $zip->extractTo($destination . '/'); - + return $zip->close(); } } diff --git a/Utils/ImageUtils.php b/Utils/ImageUtils.php index 0ef014db6..3a9011ba6 100644 --- a/Utils/ImageUtils.php +++ b/Utils/ImageUtils.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; @@ -20,10 +19,9 @@ namespace phpOMS\Utils; * * This class provides static helper functionalities for images. * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ImageUtils diff --git a/Utils/JobQueue/Job.php b/Utils/JobQueue/Job.php index 50a286a96..e3dcdae97 100644 --- a/Utils/JobQueue/Job.php +++ b/Utils/JobQueue/Job.php @@ -4,25 +4,23 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\JobQueue; /** * Array utils. * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Job @@ -50,4 +48,4 @@ class Job { $this->priority = $priority; } -} \ No newline at end of file +} diff --git a/Utils/JobQueue/JobQueue.php b/Utils/JobQueue/JobQueue.php index bbb5df5b7..81d13a753 100644 --- a/Utils/JobQueue/JobQueue.php +++ b/Utils/JobQueue/JobQueue.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\JobQueue; @@ -20,18 +19,21 @@ use phpOMS\Stdlib\Queue\PriorityQueue; /** * Array utils. * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class JobQueue { private $queue = null; + private $run = true; + private $suspended = false; + private $isTerminating = true; + private $isDeamonized; public function __construct() @@ -82,6 +84,8 @@ class JobQueue } sleep(1); + + return -1; } private function runAsDeamon() @@ -139,4 +143,4 @@ class JobQueue { // todo: save pid somewhere for kill } -} \ No newline at end of file +} diff --git a/Utils/JsonBuilder.php b/Utils/JsonBuilder.php index dec4a70b2..f36fe5bfa 100644 --- a/Utils/JsonBuilder.php +++ b/Utils/JsonBuilder.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; /** * Json builder class. * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class JsonBuilder implements \Serializable, \JsonSerializable @@ -87,10 +85,7 @@ class JsonBuilder implements \Serializable, \JsonSerializable } /** - * String representation of object - * @link http://php.net/manual/en/serializable.serialize.php - * @return string the string representation of the object or null - * @since 5.1.0 + * {@inheritdoc} */ public function serialize() { @@ -98,19 +93,16 @@ class JsonBuilder implements \Serializable, \JsonSerializable } /** - * Constructs the object - * @link http://php.net/manual/en/serializable.unserialize.php - * @param string $serialized- * The string representation of the object. - *
- * @return void - * @since 5.1.0 + * {@inheritdoc} */ public function unserialize($serialized) { $this->json = json_decode($serialized, true); } + /** + * {@inheritdoc} + */ public function jsonSerialize() { return $this->getJson(); diff --git a/Utils/PDF/Pdf.php b/Utils/PDF/Pdf.php index ecbf2965d..1b00d655c 100644 --- a/Utils/PDF/Pdf.php +++ b/Utils/PDF/Pdf.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\PDF; @@ -21,8 +20,7 @@ include __DIR__ . '/../../../Resources/tcpdf/tcpdf.php'; /** * Pdf class. * - * @category Modules - * @package phpOMS\Utils\Pdf + * @package Modules * @since 1.0.0 */ diff --git a/Utils/Parser/LaTex/Expressions/Product.php b/Utils/Parser/LaTex/Expressions/Product.php index d86e7600e..6f7dd5943 100644 --- a/Utils/Parser/LaTex/Expressions/Product.php +++ b/Utils/Parser/LaTex/Expressions/Product.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Expressions; diff --git a/Utils/Parser/LaTex/Expressions/Sum.php b/Utils/Parser/LaTex/Expressions/Sum.php index d920c2edb..6ac0a174a 100644 --- a/Utils/Parser/LaTex/Expressions/Sum.php +++ b/Utils/Parser/LaTex/Expressions/Sum.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Expressions; diff --git a/Utils/Parser/LaTex/Expressions/Trigonometry.php b/Utils/Parser/LaTex/Expressions/Trigonometry.php index f485cec6f..60cb52ad9 100644 --- a/Utils/Parser/LaTex/Expressions/Trigonometry.php +++ b/Utils/Parser/LaTex/Expressions/Trigonometry.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Expressions; diff --git a/Utils/Parser/LaTex/LaTexParser.php b/Utils/Parser/LaTex/LaTexParser.php index b1e480b27..779fdc0fa 100644 --- a/Utils/Parser/LaTex/LaTexParser.php +++ b/Utils/Parser/LaTex/LaTexParser.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex; diff --git a/Utils/Parser/LaTex/Types/Interval.php b/Utils/Parser/LaTex/Types/Interval.php index 9a1004351..f80f006eb 100644 --- a/Utils/Parser/LaTex/Types/Interval.php +++ b/Utils/Parser/LaTex/Types/Interval.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Types; diff --git a/Utils/Parser/LaTex/Types/MathFunction.php b/Utils/Parser/LaTex/Types/MathFunction.php index a78908389..a8050107d 100644 --- a/Utils/Parser/LaTex/Types/MathFunction.php +++ b/Utils/Parser/LaTex/Types/MathFunction.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Types; diff --git a/Utils/Parser/LaTex/Types/Variable.php b/Utils/Parser/LaTex/Types/Variable.php index 89f1daa42..26c2fbd23 100644 --- a/Utils/Parser/LaTex/Types/Variable.php +++ b/Utils/Parser/LaTex/Types/Variable.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\LaTex\Types; diff --git a/Utils/Parser/Markdown/License.txt b/Utils/Parser/Markdown/License.txt index b5a9d32b1..baca86f5b 100644 --- a/Utils/Parser/Markdown/License.txt +++ b/Utils/Parser/Markdown/License.txt @@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index 846c617b6..afb5eefab 100644 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -4,29 +4,29 @@ * * PHP Version 7.1 * - * @category TBD * @package TBD * @copyright Dennis Eichhorn * @license OMS License 1.0 + * @license Original license Emanuil Rusev, erusev.com (MIT) * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\Markdown; /** - * Array utils. + * Markdown parser class. * - * @category Framework - * @package phpOMS\Utils + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @license Original license Emanuil Rusev, erusev.com (MIT) + * @link http://website.orange-management.de * @since 1.0.0 */ class Markdown { - private static $blockTypes = [ + protected static $blockTypes = [ '#' => ['Header'], '*' => ['Rule', 'List'], '+' => ['List'], @@ -42,7 +42,6 @@ class Markdown '8' => ['List'], '9' => ['List'], ':' => ['Table'], - '<' => ['Comment', 'Markup'], '=' => ['SetextHeader'], '>' => ['Quote'], '[' => ['Reference'], @@ -52,72 +51,1020 @@ class Markdown '~' => ['FencedCode'], ]; - private static $inlineTypes = [ - '"' => ['SpecialCharacter'], - '!' => ['Image'], - '&' => ['SpecialCharacter'], - '*' => ['Emphasis'], - ':' => ['Url'], - '<' => ['UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'], - '>' => ['SpecialCharacter'], - '[' => ['Link'], - '_' => ['Emphasis'], - '`' => ['Code'], - '~' => ['Strikethrough'], + protected static $unmarkedBlockTypes = [ + 'Code', + ]; + + protected static $specialCharacters = [ + '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', + ]; + + protected static $strongRegex = [ + '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', + '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us', + ]; + + protected static $emRegex = [ + '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', + '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', + ]; + + protected static $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?'; + + protected static $voidElements = [ + 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', + ]; + + protected static $textLevelElements = [ + 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', + 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', + 'i', 'rp', 'del', 'code', 'strike', 'marquee', + 'q', 'rt', 'ins', 'font', 'strong', + 's', 'tt', 'kbd', 'mark', + 'u', 'xm', 'sub', 'nobr', + 'sup', 'ruby', + 'var', 'span', + 'wbr', 'time', + ]; + + protected static $inlineTypes = [ + '"' => ['SpecialCharacter'], + '!' => ['Image'], + '&' => ['SpecialCharacter'], + '*' => ['Emphasis'], + ':' => ['Url'], + '<' => ['UrlTag', 'EmailTag', 'SpecialCharacter'], + '>' => ['SpecialCharacter'], + '[' => ['Link'], + '_' => ['Emphasis'], + '`' => ['Code'], + '~' => ['Strikethrough'], '\\' => ['EscapeSequence'], ]; - private static $tags = [ - 'calendar' => [ - 'match' => 'regex here', - 'parsed' => 'output here', - ], + protected static $inlineMarkerList = '!"*_&[:<>`~\\'; + + private static $continuable = [ + 'Code', 'FencedCode', 'List', 'Quote', 'Table' ]; - public function __construct() + private static $completable = [ + 'Code', 'FencedCode' + ]; + + protected static $safeLinksWhitelist = [ + 'http://', 'https://', 'ftp://', 'ftps://', 'mailto:', + 'data:image/png;base64,', 'data:image/gif;base64,', 'data:image/jpeg;base64,', + 'irc:', 'ircs:', 'git:', 'ssh:', 'news:', 'steam:', + ]; + + private static $definitionData = []; + + public static function parse(string $text) : string { + self::$definitionData = []; + + $text = str_replace(["\r\n", "\r"], "\n", $text); + $text = trim($text, "\n"); + $lines = explode("\n", $text); + $markup = self::lines($lines); + + return trim($markup, "\n"); } - public function parse(string $raw) : string + protected static function lines(array $lines) : string { - /*$raw = $this->cleanup($raw); - $lines = explode("\n", $raw); + $currentBlock = null; - return trim($this->parseLines($lines), " \n");*/ + foreach ($lines as $line) { + if (chop($line) === '') { + if (isset($currentBlock)) { + $currentBlock['interrupted'] = true; + } - return $raw; - } + continue; + } - private function cleanup(string $raw) : string - { - $raw = str_replace(["\r\n", "\r", "\t"], ["\n", "\n", ' '], $raw); - $raw = trim($raw); - $raw = trim($raw, "\n"); + if (strpos($line, "\t") !== false) { + $parts = explode("\t", $line); + $line = $parts[0]; - return $raw; - } + unset($parts[0]); - private function parseLines(array $lines) : string - { - $block = array_keys(self::$blockTypes); - $inline = array_keys(self::$inlineTypes); + foreach ($parts as $part) { + $shortage = 4 - mb_strlen($line, 'utf-8') % 4; - foreach($lines as $line) { - foreach($line as $character) { - + $line .= str_repeat(' ', $shortage); + $line .= $part; + } + } + + $indent = 0; + while (isset($line[$indent]) && $line[$indent] === ' ') { + $indent ++; + } + + $text = $indent > 0 ? substr($line, $indent) : $line; + $lineArray = ['body' => $line, 'indent' => $indent, 'text' => $text]; + + if (isset($currentBlock['continuable'])) { + $block = self::{'block' . $currentBlock['type'] . 'Continue'}($lineArray, $currentBlock); + + if (isset($block)) { + $currentBlock = $block; + + continue; + } elseif (in_array($currentBlock['type'], self::$completable)) { + $currentBlock = self::{'block' . $currentBlock['type'] . 'Complete'}($currentBlock); + } + } + + $marker = $text[0]; + $blockTypes = self::$unmarkedBlockTypes; + + if (isset(self::$blockTypes[$marker])) { + foreach (self::$blockTypes[$marker] as $blockType) { + $blockTypes[] = $blockType; + } + } + + foreach ($blockTypes as $blockType) { + $block = self::{'block' . $blockType}($lineArray, $currentBlock); + + if (isset($block)) { + $block['type'] = $blockType; + + if (!isset($block['identified'])) { + $blocks[] = $currentBlock; + + $block['identified'] = true; + } + + if (in_array($blockType, self::$continuable)) { + $block['continuable'] = true; + } + + $currentBlock = $block; + + continue 2; + } + } + + if (isset($currentBlock) && !isset($currentBlock['type']) && !isset($currentBlock['interrupted'])) { + $currentBlock['element']['text'] .= "\n" . $text; + } else { + $blocks[] = $currentBlock; + $currentBlock = self::paragraph($lineArray); + $currentBlock['identified'] = true; } } - return ''; - } - - private function countIndention(string $line) : int - { - $indent = 0; - while (isset($line[$indent]) && $line[$indent] === ' ') { - $indent++; + if (isset($currentBlock['continuable']) && in_array($currentBlock['type'], self::$completable)) { + $currentBlock = self::{'block' . $currentBlock['type'] . 'Complete'}($currentBlock); } - return $indent; + $blocks[] = $currentBlock; + unset($blocks[0]); + $markup = ''; + + foreach ($blocks as $block) { + if (isset($block['hidden'])) { + continue; + } + + $markup .= "\n"; + $markup .= isset($block['markup']) ? $block['markup'] : self::element($block['element']); + } + + $markup .= "\n"; + + return $markup; } -} \ No newline at end of file + + protected static function blockCode(array $lineArray, array $block = null) /* : ?array */ + { + if (isset($block) && !isset($block['type']) && !isset($block['interrupted'])) { + return; + } + + if ($lineArray['indent'] < 4) { + return; + } + + return [ + 'element' => [ + 'name' => 'pre', + 'handler' => 'element', + 'text' => [ + 'name' => 'code', + 'text' => substr($lineArray['body'], 4), + ], + ], + ]; + } + + protected static function blockCodeContinue(array $lineArray, array $block) /* : ?array */ + { + if ($lineArray['indent'] < 4) { + return; + } + + if (isset($block['interrupted'])) { + $block['element']['text']['text'] .= "\n"; + + unset($block['interrupted']); + } + + $block['element']['text']['text'] .= "\n"; + $block['element']['text']['text'] .= substr($lineArray['body'], 4); + + return $block; + } + + protected static function blockCodeComplete(array $block) : array + { + return $block; + } + + protected static function blockFencedCode(array $lineArray) /* : ?array */ + { + if (!preg_match('/^[' . $lineArray['text'][0] . ']{3,}[ ]*([\w-]+)?[ ]*$/', $lineArray['text'], $matches)) { + return; + } + + $elementArray = [ + 'name' => 'code', + 'text' => '', + ]; + + if (isset($matches[1])) { + $elementArray['attributes'] = [ + 'class' => 'language-' . $matches[1], + ]; + } + + return [ + 'char' => $lineArray['text'][0], + 'element' => [ + 'name' => 'pre', + 'handler' => 'element', + 'text' => $elementArray, + ] + ]; + } + + protected static function blockFencedCodeContinue(array $lineArray, array $block) /* : ?array */ + { + if (isset($block['complete'])) { + return; + } + + if (isset($block['interrupted'])) { + $block['element']['text']['text'] .= "\n"; + + unset($block['interrupted']); + } + + if (preg_match('/^' . $block['char'] . '{3,}[ ]*$/', $lineArray['text'])) { + $block['element']['text']['text'] = substr($block['element']['text']['text'], 1); + $block['complete'] = true; + + return $block; + } + + $block['element']['text']['text'] .= "\n" . $lineArray['body']; + + return $block; + } + + protected static function blockFencedCodeComplete(array $block) : array + { + return $block; + } + + protected static function blockHeader(array $lineArray) /* : ?array */ + { + if (!isset($lineArray['text'][1])) { + return; + } + + $level = 1; + while (isset($lineArray['text'][$level]) && $lineArray['text'][$level] === '#') { + $level ++; + } + + if ($level > 6) { + return; + } + + return [ + 'element' => [ + 'name' => 'h' . min(6, $level), + 'text' => trim($lineArray['text'], '# '), + 'handler' => 'line', + ], + ]; + } + + protected static function blockList(array $lineArray) /* : ?array */ + { + list($name, $pattern) = $lineArray['text'][0] <= '-' ? ['ul', '[*+-]'] : ['ol', '[0-9]+[.]']; + + if (!preg_match('/^(' . $pattern . '[ ]+)(.*)/', $lineArray['text'], $matches)) { + return; + } + + $block = [ + 'indent' => $lineArray['indent'], + 'pattern' => $pattern, + 'element' => [ + 'name' => $name, + 'handler' => 'elements', + ], + ]; + + if ($name === 'ol') { + $listStart = stristr($matches[0], '.', true); + + if ($listStart !== '1') { + $block['element']['attributes'] = ['start' => $listStart]; + } + } + + $block['li'] = [ + 'name' => 'li', + 'handler' => 'li', + 'text' => [ + $matches[2], + ], + ]; + + $block['element']['text'][] = &$block['li']; + + return $block; + } + + protected static function blockListContinue(array $lineArray, array $block) /* : ?array */ + { + if ($block['indent'] === $lineArray['indent'] && preg_match('/^' . $block['pattern'] . '(?:[ ]+(.*)|$)/', $lineArray['text'], $matches)) { + if (isset($block['interrupted'])) { + $block['li']['text'][] = ''; + + unset($block['interrupted']); + } + + unset($block['li']); + + $block['li'] = [ + 'name' => 'li', + 'handler' => 'li', + 'text' => [ + isset($matches[1]) ? $matches[1] : '', + ], + ]; + + $block['element']['text'][] = &$block['li']; + + return $block; + } + + if ($lineArray['text'][0] === '[' && self::blockReference($lineArray)) { + return $block; + } + + if (!isset($block['interrupted'])) { + $block['li']['text'][] = preg_replace('/^[ ]{0,4}/', '', $lineArray['body']); + + return $block; + } + + if ($lineArray['indent'] > 0) { + $block['li']['text'][] = ''; + $block['li']['text'][] = preg_replace('/^[ ]{0,4}/', '', $lineArray['body']); + + unset($block['interrupted']); + + return $block; + } + } + + protected static function blockQuote(array $lineArray) /* : ?array */ + { + if (!preg_match('/^>[ ]?(.*)/', $lineArray['text'], $matches)) { + return; + } + + return [ + 'element' => [ + 'name' => 'blockquote', + 'handler' => 'lines', + 'text' => (array) $matches[1], + ], + ]; + } + + protected static function blockQuoteContinue(array $lineArray, array $block) /* : ?array */ + { + if ($lineArray['text'][0] === '>' && preg_match('/^>[ ]?(.*)/', $lineArray['text'], $matches)) { + if (isset($block['interrupted'])) { + $block['element']['text'][] = ''; + + unset($block['interrupted']); + } + + $block['element']['text'][] = $matches[1]; + + return $block; + } + + if (!isset($block['interrupted'])) { + $block['element']['text'][] = $lineArray['text']; + + return $block; + } + } + + protected static function blockRule(array $lineArray) /* : ?array */ + { + if (!preg_match('/^([' . $lineArray['text'][0] . '])([ ]*\1){2,}[ ]*$/', $lineArray['text'])) { + return; + } + + return [ + 'element' => [ + 'name' => 'hr' + ], + ]; + } + + protected static function blockSetextHeader(array $lineArray, array $block = null) /* : ?array */ + { + if (!isset($block) || isset($block['type']) || isset($block['interrupted'])) { + return; + } + + if (chop($lineArray['text'], $lineArray['text'][0]) !== '') { + return; + } + + $block['element']['name'] = $lineArray['text'][0] === '=' ? 'h1' : 'h2'; + + return $block; + } + + protected static function blockReference(array $lineArray) /* : ?array */ + { + if (!preg_match('/^\[(.+?)\]:[ ]*(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $lineArray['text'], $matches)) { + return; + } + + $data = [ + 'url' => $matches[2], + 'title' => $matches[3] ?? null, + ]; + + self::$definitionData['Reference'][strtolower($matches[1])] = $data; + + return ['hidden' => true]; + } + + protected static function blockTable($lineArray, array $block = null) /* : ?array */ + { + if (!isset($block) || isset($block['type']) || isset($block['interrupted'])) { + return; + } + + if (strpos($block['element']['text'], '|') !== false && chop($lineArray['text'], ' -:|') === '') { + $alignments = []; + $divider = $lineArray['text']; + $divider = trim($divider); + $divider = trim($divider, '|'); + $dividerCells = explode('|', $divider); + + foreach ($dividerCells as $dividerCell) { + $dividerCell = trim($dividerCell); + + if ($dividerCell === '') { + continue; + } + + $alignment = null; + + if ($dividerCell[0] === ':') { + $alignment = 'left'; + } + + if (substr($dividerCell, -1) === ':') { + $alignment = $alignment === 'left' ? 'center' : 'right'; + } + + $alignments[] = $alignment; + } + + $headerElements = []; + $header = $block['element']['text']; + $header = trim($header); + $header = trim($header, '|'); + $headerCells = explode('|', $header); + + foreach ($headerCells as $index => $headerCell) { + $headerElement = [ + 'name' => 'th', + 'text' => trim($headerCell), + 'handler' => 'line', + ]; + + if (isset($alignments[$index])) { + $headerElement['attributes'] = [ + 'style' => 'text-align: ' . $alignments[$index] . ';', + ]; + } + + $headerElements[] = $headerElement; + } + + $block = [ + 'alignments' => $alignments, + 'identified' => true, + 'element' => [ + 'name' => 'table', + 'handler' => 'elements', + ], + ]; + + $block['element']['text'][] = [ + 'name' => 'thead', + 'handler' => 'elements', + ]; + + $block['element']['text'][] = [ + 'name' => 'tbody', + 'handler' => 'elements', + 'text' => [], + ]; + + $block['element']['text'][0]['text'][] = [ + 'name' => 'tr', + 'handler' => 'elements', + 'text' => $headerElements, + ]; + + return $block; + } + } + + protected static function blockTableContinue(array $lineArray, array $block) /* : ?array */ + { + if (isset($block['interrupted'])) { + return; + } + + if ($lineArray['text'][0] === '|' || strpos($lineArray['text'], '|')) { + $elements = []; + $row = $lineArray['text']; + $row = trim($row); + $row = trim($row, '|'); + + preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches); + + foreach ($matches[0] as $index => $cell) { + $element = [ + 'name' => 'td', + 'handler' => 'line', + 'text' => trim($cell), + ]; + + if (isset($block['alignments'][$index])) { + $element['attributes'] = [ + 'style' => 'text-align: ' . $block['alignments'][$index] . ';', + ]; + } + + $elements[] = $element; + } + + $block['element']['text'][1]['text'][] = [ + 'name' => 'tr', + 'handler' => 'elements', + 'text' => $elements, + ]; + + return $block; + } + } + + protected static function paragraph(array $lineArray) : array + { + return [ + 'element' => [ + 'name' => 'p', + 'text' => $lineArray['text'], + 'handler' => 'line', + ], + ]; + } + + protected static function line(string $text) : string + { + $markup = ''; + + while ($excerpt = strpbrk($text, self::$inlineMarkerList)) { + $marker = $excerpt[0]; + $markerPosition = strpos($text, $marker); + $excerptArray = ['text' => $excerpt, 'context' => $text]; + + foreach (self::$inlineTypes[$marker] as $inlineType) { + $inline = self::{'inline' . $inlineType}($excerptArray); + + if (!isset($inline)) { + continue; + } + + if (isset($inline['position']) && $inline['position'] > $markerPosition) { + continue; + } + + if (!isset($inline['position'])) { + $inline['position'] = $markerPosition; + } + + $unmarkedText = substr($text, 0, $inline['position']); + $markup .= self::unmarkedText($unmarkedText); + $markup .= isset($inline['markup']) ? $inline['markup'] : self::element($inline['element']); + $text = substr($text, $inline['position'] + $inline['extent']); + + continue 2; + } + + $unmarkedText = substr($text, 0, $markerPosition + 1); + $markup .= self::unmarkedText($unmarkedText); + $text = substr($text, $markerPosition + 1); + } + + $markup .= self::unmarkedText($text); + + return $markup; + } + + protected static function inlineCode(array $excerpt) /* : ?array */ + { + $marker = $excerpt['text'][0]; + + if (!preg_match('/^(' . $marker . '+)[ ]*(.+?)[ ]*(? strlen($matches[0]), + 'element' => [ + 'name' => 'code', + 'text' => preg_replace("/[ ]*\n/", ' ', $matches[2]), + ], + ]; + } + + protected static function inlineEmailTag(array $excerpt) /* : ?array */ + { + if (strpos($excerpt['text'], '>') === false || !preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $excerpt['text'], $matches)) { + return; + } + + $url = $matches[1]; + + if (!isset($matches[2])) { + $url = 'mailto:' . $url; + } + + return [ + 'extent' => strlen($matches[0]), + 'element' => [ + 'name' => 'a', + 'text' => $matches[1], + 'attributes' => [ + 'href' => $url, + ], + ], + ]; + } + + protected static function inlineEmphasis(array $excerpt) /* : ?array */ + { + if (!isset($excerpt['text'][1])) { + return; + } + + $marker = $excerpt['text'][0]; + + if ($excerpt['text'][1] === $marker && preg_match(self::$strongRegex[$marker], $excerpt['text'], $matches)) { + $emphasis = 'strong'; + } elseif (preg_match(self::$emRegex[$marker], $excerpt['text'], $matches)) { + $emphasis = 'em'; + } else { + return; + } + + return [ + 'extent' => strlen($matches[0]), + 'element' => [ + 'name' => $emphasis, + 'handler' => 'line', + 'text' => $matches[1], + ], + ]; + } + + protected static function inlineEscapeSequence(array $excerpt) /* : ?array */ + { + if (!isset($excerpt['text'][1]) || !in_array($excerpt['text'][1], self::$specialCharacters)) { + return; + } + + return [ + 'markup' => $excerpt['text'][1], + 'extent' => 2, + ]; + } + + protected static function inlineImage(array $excerpt) /* : ?array */ + { + if (!isset($excerpt['text'][1]) || $excerpt['text'][1] !== '[') { + return; + } + + $excerpt['text'] = substr($excerpt['text'], 1); + $link = self::inlineLink($excerpt); + + if (!isset($link)) { + return; + } + + $inline = [ + 'extent' => $link['extent'] + 1, + 'element' => [ + 'name' => 'img', + 'attributes' => [ + 'src' => $link['element']['attributes']['href'], + 'alt' => $link['element']['text'], + ], + ], + ]; + + $inline['element']['attributes'] += $link['element']['attributes']; + + unset($inline['element']['attributes']['href']); + + return $inline; + } + + protected static function inlineLink(array $excerpt) /* : ?array */ + { + $element = [ + 'name' => 'a', + 'handler' => 'line', + 'text' => null, + 'attributes' => [ + 'href' => null, + 'title' => null, + ], + ]; + + $extent = 0; + $remainder = $excerpt['text']; + + if (!preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) { + return; + } + + $element['text'] = $matches[1]; + $extent += strlen($matches[0]); + $remainder = substr($remainder, $extent); + + if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) { + $element['attributes']['href'] = $matches[1]; + + if (isset($matches[2])) { + $element['attributes']['title'] = substr($matches[2], 1, - 1); + } + + $extent += strlen($matches[0]); + } else { + if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) { + $definition = strlen($matches[1]) ? $matches[1] : $element['text']; + $definition = strtolower($definition); + + $extent += strlen($matches[0]); + } else { + $definition = strtolower($element['text']); + } + + if (!isset(self::$definitionData['Reference'][$definition])) { + return; + } + + $def = self::$definitionData['Reference'][$definition]; + + $element['attributes']['href'] = $def['url']; + $element['attributes']['title'] = $def['title']; + } + + return [ + 'extent' => $extent, + 'element' => $element, + ]; + } + + protected static function inlineSpecialCharacter(array $excerpt) /* : ?array */ + { + if ($excerpt['text'][0] === '&' && !preg_match('/^?\w+;/', $excerpt['text'])) { + return [ + 'markup' => '&', + 'extent' => 1, + ]; + } + + $specialChar = ['>' => 'gt', '<' => 'lt', '"' => 'quot']; + + if (isset($specialChar[$excerpt['text'][0]])) { + return [ + 'markup' => '&' . $specialChar[$excerpt['text'][0]] . ';', + 'extent' => 1, + ]; + } + } + + protected static function inlineStrikethrough(array $excerpt) /* : ?array */ + { + if (!isset($excerpt['text'][1])) { + return; + } + + if ($excerpt['text'][1] !== '~' || !preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $excerpt['text'], $matches)) { + return; + } + + return [ + 'extent' => strlen($matches[0]), + 'element' => [ + 'name' => 'del', + 'text' => $matches[1], + 'handler' => 'line', + ], + ]; + } + + protected static function inlineUrl(array $excerpt) /* : ?array */ + { + if (!isset($excerpt['text'][2]) || $excerpt['text'][2] !== '/') { + return; + } + + if (!preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) { + return; + } + + return [ + 'extent' => strlen($matches[0][0]), + 'position' => $matches[0][1], + 'element' => [ + 'name' => 'a', + 'text' => $matches[0][0], + 'attributes' => [ + 'href' => $matches[0][0], + ], + ], + ]; + } + + protected static function inlineUrlTag(array $excerpt) /* : ?array */ + { + if (strpos($excerpt['text'], '>') === false || !preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $excerpt['text'], $matches)) { + return; + } + + return [ + 'extent' => strlen($matches[0]), + 'element' => [ + 'name' => 'a', + 'text' => $matches[1], + 'attributes' => [ + 'href' => $matches[1], + ], + ], + ]; + } + + protected static function unmarkedText(string $text) : string + { + $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "') { + $markup = $trimmedMarkup; + $markup = substr($markup, 3); + $position = strpos($markup, '
'); + $markup = substr_replace($markup, '', $position, 4); + } + + return $markup; + } + + protected static function sanitizeElement(array $element) : array + { + $safeUrlNameToAtt = [ + 'a' => 'href', + 'img' => 'src', + ]; + + if (isset($safeUrlNameToAtt[$element['name']])) { + $element = self::filterUnsafeUrlInAttribute($element, $safeUrlNameToAtt[$element['name']]); + } + + if (!empty($element['attributes'])) { + foreach ($element['attributes'] as $att => $val) { + if (!preg_match('/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/', $att)) { + unset($element['attributes'][$att]); + } elseif (self::striAtStart($att, 'on')) { + unset($element['attributes'][$att]); + } + } + } + + return $element; + } + + protected static function filterUnsafeUrlInAttribute(array $element, string $attribute) : array + { + foreach (self::$safeLinksWhitelist as $scheme) { + if (self::striAtStart($element['attributes'][$attribute], $scheme)) { + return $element; + } + } + + $element['attributes'][$attribute] = str_replace(':', '%3A', $element['attributes'][$attribute]); + + return $element; + } + + protected static function escape(string $text, bool $allowQuotes = false) : string + { + return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8'); + } + + protected static function striAtStart(string $string, string $needle) + { + $length = strlen($needle); + + if ($length > strlen($string)) { + return false; + } + + return strtolower(substr($string, 0, $length)) === strtolower($needle); + } +} diff --git a/Utils/Parser/Php/ArrayParser.php b/Utils/Parser/Php/ArrayParser.php index c16bb72d8..761430904 100644 --- a/Utils/Parser/Php/ArrayParser.php +++ b/Utils/Parser/Php/ArrayParser.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\Parser\Php; @@ -20,10 +19,9 @@ namespace phpOMS\Utils\Parser\Php; * * Parsing/serializing arrays to and from php file * - * @category Framework - * @package phpOMS\Utils\Parser + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class ArrayParser @@ -46,10 +44,38 @@ class ArrayParser $key = '"' . $key . '"'; } - $stringify .= ' ' . $key . ' => ' . MemberParser::parseVariable($val) . ',' . PHP_EOL; + $stringify .= ' ' . $key . ' => ' . self::parseVariable($val) . ',' . PHP_EOL; } return $stringify . ']'; } + + /** + * Serialize value. + * + * @param mixed $value Value to serialzie + * + * @return string + * + * @since 1.0.0 + */ + public static function parseVariable($value) : string + { + if (is_array($value)) { + return ArrayParser::serializeArray($value) . PHP_EOL; + } elseif (is_string($value)) { + return '"' . $value . '"'; + } elseif (is_scalar($value)) { + return (string) $value; + } elseif (is_null($value)) { + return 'null'; + } elseif (is_bool($value)) { + return $value ? 'true' : 'false'; + } elseif ($value instanceOf \Serializable) { + return self::parseVariable($value->serialize()); + } else { + throw new \UnexpectedValueException(); + } + } } diff --git a/Utils/Parser/Php/ClassParser.php b/Utils/Parser/Php/ClassParser.php deleted file mode 100644 index 55e1e8485..000000000 --- a/Utils/Parser/Php/ClassParser.php +++ /dev/null @@ -1,688 +0,0 @@ -isFinal = $final; - } - - /** - * Is final? - * - * @return bool - * - * @since 1.0.0 - */ - public function isFinal() : bool - { - return $this->isFinal; - } - - /** - * Set abstract. - * - * @param bool $abstract Is abstract - * - * @return void - * - * @since 1.0.0 - */ - public function setAbstract(bool $abstract) /* : void */ - { - $this->isAbstract = $abstract; - } - - /** - * Is abstract? - * - * @return bool - * - * @since 1.0.0 - */ - public function isAbstract() : bool - { - return $this->isAbstract; - } - - /** - * Get type. - * - * @return string - * - * @since 1.0.0 - */ - public function getType() : string - { - return $this->type; - } - - /** - * Set type. - * - * Available types are ClassType:: - * - * @param string $type Set type - * - * @return void - * - * @since 1.0.0 - */ - public function setType(string $type) /* : void */ - { - $this->type = $type; - } - - /** - * Get extends. - * - * @return string - * - * @since 1.0.0 - */ - public function getExtends() : string - { - return $this->extends; - } - - /** - * Set extends. - * - * @param string $extends Extended class - * - * @return void - * - * @since 1.0.0 - */ - public function setExtends(string $extends) /* : void */ - { - $this->extends = $extends; - } - - /** - * Remove extends. - * - * @return void - * - * @since 1.0.0 - */ - public function removeExtends() /* : void */ - { - $this->extends = ''; - } - - /** - * Get namespace. - * - * @return string - * - * @since 1.0.0 - */ - public function getNamespace() : string - { - return $this->namespace; - } - - /** - * Set namespace. - * - * @param string $namespace Namespace - * - * @return void - * - * @since 1.0.0 - */ - public function setNamespace(string $namespace) /* : void */ - { - $this->namespace = $namespace; - } - - /** - * Remove namespace. - * - * @return void - * - * @since 1.0.0 - */ - public function removeNamespace() /* : void */ - { - $this->namespace = ''; - } - - /** - * Add use. - * - * @param string $namespace Namespace to use - * @param string $as Namespace as - * - * @return void - * - * @since 1.0.0 - */ - public function addUse(string $namespace, string $as = null) /* : void */ - { - if (isset($as)) { - $this->use[$as] = $namespace; - } else { - $this->use[] = $namespace; - } - } - - /** - * Remove use. - * - * @param string $id Namespace numerical id or 'as' if used. - * - * @return bool - * - * @since 1.0.0 - */ - public function removeUse($id) : bool - { - if (isset($this->use[$id])) { - unset($this->use[$id]); - - return true; - } - - return false; - } - - /** - * Get name. - * - * @return string - * - * @since 1.0.0 - */ - public function getName() : string - { - return $this->name; - } - - /** - * Set name. - * - * @param string $name Class name - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) /* : void */ - { - $this->name = $name; - } - - /** - * Add implements. - * - * @param string $implements Implement - * - * @return void - * - * @since 1.0.0 - */ - public function addImplements(string $implements) /* : void */ - { - $this->implements[] = $implements; - - array_unique($this->implements); - } - - /** - * Add include. - * - * @param string $include Include - * - * @return void - * - * @since 1.0.0 - */ - public function addInclude(string $include) /* : void */ - { - $this->includes[] = $include; - - array_unique($this->includes); - } - - /** - * Add $require. - * - * @param string $require Require - * - * @return void - * - * @since 1.0.0 - */ - public function addRequire(string $require) /* : void */ - { - $this->requires[] = $require; - - array_unique($this->requires); - } - - /** - * Add trait. - * - * @param string $trait Trait to use - * @param string $as Trait as - * - * @return void - * - * @since 1.0.0 - */ - public function addTrait(string $trait, string $as = null) /* : void */ - { - if (isset($as)) { - $this->traits[$as] = $trait; - } else { - $this->traits[] = $trait; - } - } - - /** - * Remove trait. - * - * @param string $id Namespace numerical id or 'as' if used. - * - * @return bool - * - * @since 1.0.0 - */ - public function removeTrait($id) : bool - { - if (isset($this->traits[$id])) { - unset($this->traits[$id]); - - return true; - } - - return false; - } - - /** - * Add member. - * - * @param MemberParser $member Member - * - * @return bool - * - * @since 1.0.0 - */ - public function addMember(MemberParser $member) /* : void */ - { - $this->members[$member->getName()] = $member; - } - - /** - * Remove member by name. - * - * @param string $name Member name - * - * @return bool - * - * @since 1.0.0 - */ - public function removeMember(string $name) : bool - { - if (isset($this->members[$name])) { - unset($this->members[$name]); - - return true; - } - - return false; - } - - /** - * Get member by name. - * - * @param string $name Member name - * - * @return MemberParser - * - * @since 1.0.0 - */ - public function getMember(string $name) : MemberParser - { - return $this->members[$name] ?? new MemberParser(); - } - - /** - * Add function. - * - * @param FunctionParser $function Function - * - * @return bool - * - * @since 1.0.0 - */ - public function addFunction(FunctionParser $function) - { - $this->functions[$function->getName()] = $function; - } - - /** - * Remove function by name. - * - * @param string $name Function name - * - * @return bool - * - * @since 1.0.0 - */ - public function removeFunction(string $name) : bool - { - if (isset($this->functions[$name])) { - unset($this->functions[$name]); - - return true; - } - - return false; - } - - /** - * Get function by name. - * - * @param string $name Function name - * - * @return FunctionParser - * - * @since 1.0.0 - */ - public function getFunction(string $name) : FunctionParser - { - return $this->functions[$name] ?? new FunctionParser(); - } - - /** - * Serialize class. - * - * @return string - * - * @since 1.0.0 - */ - public function serialize() : string - { - $class = ''; - - $class .= $this->serializeRequire('require_once', $this->requires); - $class .= $this->serializeRequire('include_once', $this->includes); - $class .= $this->serializeNamespace(); - $class .= $this->serializeUse($this->use); - $class .= $this->serializeClass(); - $class .= '{' . PHP_EOL . PHP_EOL; - $class .= $this->serializeUse($this->traits); - - foreach ($this->members as $name => $member) { - $class .= $member->serialize() . PHP_EOL . PHP_EOL; - } - - foreach ($this->functions as $name => $function) { - $class .= $function->serialize() . PHP_EOL . PHP_EOL; - } - - $class .= '}'; - - return $class; - } - - /** - * Serialize require. - * - * @param string $keyword Keyword (e.g. include, require, include_once) - * @param array $source Require source - * - * @return string - * - * @since 1.0.0 - */ - private function serializeRequire(string $keyword, array $source) : string - { - $serialze = ''; - if (!empty($source)) { - foreach ($source as $require) { - $serialze .= $keyword . ' "' . $require . '";' . PHP_EOL; - } - - $serialze .= PHP_EOL; - } - - return $serialze; - } - - /** - * Serialize namespace. - * - * @return string - * - * @since 1.0.0 - */ - private function serializeNamespace() : string - { - $serialze = ''; - if (!empty($this->namespace)) { - $serialze = $this->namespace . ';' . PHP_EOL . PHP_EOL; - } - - return $serialze; - } - - /** - * Serialize use. - * - * @param array $source Use source - * - * @return string - * - * @since 1.0.0 - */ - private function serializeUse(array $source) : string - { - $serialze = ''; - if (!empty($source)) { - foreach ($source as $as => $use) { - $serialze .= 'use ' . $use . (is_string($as) ? ' as ' . $as : '') . ';' . PHP_EOL; - } - - $serialze .= PHP_EOL; - } - - return $serialze; - } - - /** - * Serialize class. - * - * @return string - * - * @since 1.0.0 - */ - private function serializeClass() : string - { - $serialze = ''; - if ($this->isFinal) { - $serialze .= 'final '; - } - - if ($this->isAbstract) { - $serialze .= 'abstract '; - } - - $serialze .= $this->type . ' ' . $this->name . ' '; - - if (!empty($this->extends)) { - $serialze .= 'extends ' . $this->extends . ' '; - } - - if (!empty($this->implements)) { - $serialze .= 'implements ' . implode(', ', $this->implements) . PHP_EOL; - } - - return $serialze; - } - -} \ No newline at end of file diff --git a/Utils/Parser/Php/ClassType.php b/Utils/Parser/Php/ClassType.php deleted file mode 100644 index 439e57a20..000000000 --- a/Utils/Parser/Php/ClassType.php +++ /dev/null @@ -1,36 +0,0 @@ -name; - } - - /** - * Set function name. - * - * @param string $name Function name - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) /* : void */ - { - $this->name = $name; - } - - /** - * Set function body. - * - * @param string $body Function body - * - * @return void - * - * @since 1.0.0 - */ - public function seBody(string $body) /* : void */ - { - $this->body = $body; - } - - /** - * Get function body. - * - * @return string - * - * @since 1.0.0 - */ - public function getBody() : string - { - return $this->body; - } - - /** - * Remove body. - * - * @return void - * - * @since 1.0.0 - */ - public function removeBody() /* : void */ - { - $this->body = ''; - } - - /** - * Get function visibility. - * - * @return string - * - * @since 1.0.0 - */ - public function getVisibility() : string - { - return $this->visibility; - } - - /** - * Set visibility. - * - * @param string $visibility Function visibility - * - * @return void - * - * @since 1.0.0 - */ - public function setVisibility(string $visibility) /* : void */ - { - $this->visibility = $visibility; - } - - /** - * Set static. - * - * @param bool $static Is static - * - * @return void - * - * @since 1.0.0 - */ - public function setStatic(bool $static) /* : void */ - { - $this->isStatic = $static; - } - - /** - * Is static? - * - * @return bool - * - * @since 1.0.0 - */ - public function isStatic() : bool - { - return $this->isStatic; - } - - /** - * Set final. - * - * @param bool $final Is final - * - * @return void - * - * @since 1.0.0 - */ - public function setFinal(bool $final) /* : void */ - { - $this->isFinal = $final; - } - - /** - * Is final? - * - * @return bool - * - * @since 1.0.0 - */ - public function isFinal() : bool - { - return $this->isFinal; - } - - /** - * Set abstract. - * - * @param bool $abstract Is abstract - * - * @return void - * - * @since 1.0.0 - */ - public function setAbstract(bool $abstract) /* : void */ - { - $this->isAbstract = $abstract; - - if ($this->isAbstract) { - $this->body = null; - } elseif (!$this->isAbstract && !isset($this->body)) { - $this->body = ''; - } - } - - /** - * Is abstract? - * - * @return bool - * - * @since 1.0.0 - */ - public function isAbstract() : bool - { - return $this->isAbstract; - } - - /** - * Remove return type. - * - * @return void - * - * @since 1.0.0 - */ - public function removeReturn() /* : void */ - { - $this->return = null; - } - - /** - * Get return type. - * - * @return string - * - * @since 1.0.0 - */ - public function getReturn() : string - { - return $this->return; - } - - /** - * Set return type. - * - * @param string $return Return type - * - * @return void - * - * @since 1.0.0 - */ - public function setReturn(string $return) /* : void */ - { - $this->return = $return; - } - - /** - * Add parameter to function. - * - * @param string $name Parameter name - * @param string $typehint Typehint - * @param string $default Default value - * - * @return void - * - * @since 1.0.0 - */ - public function addParameter(string $name, string $typehint = null, string $default = null) /* : void */ - { - $this->parameters[$name]['name'] = $name; - $this->parameters[$name]['typehint'] = $typehint; - - if (isset($default)) { - if ($default === 'null') { - $default = null; - } - - $this->parameters[$name]['default'] = $default; - } - } - - /** - * Serialize function. - * - * @return string - * - * @since 1.0.0 - */ - public function serialize() - { - $function = ''; - $function .= str_repeat(' ', ClassParser::INDENT); - - if ($this->isFinal) { - $function .= 'final '; - } - - if ($this->isAbstract) { - $function .= 'abstract '; - } - - $function .= $this->visibility . ' '; - - if ($this->isStatic) { - $function .= 'static '; - } - - $function .= 'function ' . $this->name . '('; - - $parameters = ''; - foreach ($this->parameters as $name => $para) { - $parameters = (isset($para['typehint']) ? $para['typehint'] . ' ' : '') . $para['name'] . (array_key_exists('default', $para) ? ' = ' . MemberParser::parseVariable($para['default']) : '') . ', '; - } - - $function .= rtrim($parameters, ', ') . ') '; - $function .= ($this->return ?? '') . PHP_EOL; - - if (isset($this->body)) { - $function .= str_repeat(' ', ClassParser::INDENT) . '{' . PHP_EOL . $this->addIndent($this->body) . PHP_EOL . str_repeat(' ', ClassParser::INDENT) . '}'; - } else { - $function .= ';'; - } - - return $function; - } - - /** - * Add indention for body. - * - * @param string $body Function body to indent - * - * @return string - * - * @since 1.0.0 - */ - private function addIndent(string $body) : string - { - $body = preg_split('/\r\n|\r|\n/', $body); - - foreach ($body as &$line) { - $line = str_repeat(' ', ClassParser::INDENT) . $line; - } - - return $body; - } -} \ No newline at end of file diff --git a/Utils/Parser/Php/MemberParser.php b/Utils/Parser/Php/MemberParser.php deleted file mode 100644 index f45cc79af..000000000 --- a/Utils/Parser/Php/MemberParser.php +++ /dev/null @@ -1,251 +0,0 @@ -name; - } - - /** - * Set member name. - * - * @param string $name Member name - * - * @return void - * - * @since 1.0.0 - */ - public function setName(string $name) /* : void */ - { - $this->name = $name; - } - - /** - * Get visibility. - * - * @return string - * - * @since 1.0.0 - */ - public function getVisibility() : string - { - return $this->visibility; - } - - /** - * Set visibility. - * - * @param string $visibility Member visibility - * - * @return void - * - * @since 1.0.0 - */ - public function setVisibility(string $visibility) /* : void */ - { - $this->visibility = $visibility; - } - - /** - * Set static. - * - * @param bool $static Is static - * - * @return void - * - * @since 1.0.0 - */ - public function setStatic(bool $static) /* : void */ - { - $this->isStatic = $static; - - if ($this->isStatic) { - $this->isConst = false; - } - } - - /** - * Is static? - * - * @return bool - * - * @since 1.0.0 - */ - public function isStatic() : bool - { - return $this->isStatic; - } - - /** - * Set const. - * - * @param bool $const Is const - * - * @return void - * - * @since 1.0.0 - */ - public function setConst(bool $const) /* : void */ - { - $this->isConst = $const; - - if ($this->isConst) { - $this->isStatic = false; - } - } - - /** - * Is const? - * - * @return bool - * - * @since 1.0.0 - */ - public function isConst() : bool - { - return $this->isConst; - } - - /** - * Set default value. - * - * @param string $default - * - * @return void - * - * @since 1.0.0 - */ - public function setDefault($default) /* : void */ - { - $this->default = $default; - } - - /** - * Serialize member. - * - * @return string - * - * @since 1.0.0 - */ - public function serialize() : string - { - $member = ''; - $member .= str_repeat(' ', ClassParser::INDENT); - - $member .= $this->visibility . ' '; - - if ($this->isStatic) { - $member .= 'static '; - } - - if ($this->isConst) { - $member .= 'const '; - } - - $member .= (!$this->isConst ? '$' : '') . $this->name . ' = ' . self::parseVariable($this->default) . ';'; - - return $member; - } - - /** - * Serialize value. - * - * @param mixed $value Value to serialzie - * - * @return string - * - * @since 1.0.0 - */ - public static function parseVariable($value) : string - { - if (is_array($value)) { - return ArrayParser::serializeArray($value) . PHP_EOL; - } elseif (is_string($value)) { - return '"' . $value . '"'; - } elseif (is_scalar($value)) { - return (string) $value; - } elseif (is_null($value)) { - return 'null'; - } elseif (is_bool($value)) { - return $value ? 'true' : 'false'; - } elseif ($value instanceOf \Serializable) { - return self::parseVariable($value->serialize()); - } else { - throw new \UnexpectedValueException(); - } - } -} \ No newline at end of file diff --git a/Utils/Parser/Php/Visibility.php b/Utils/Parser/Php/Visibility.php deleted file mode 100644 index bb8f9ab18..000000000 --- a/Utils/Parser/Php/Visibility.php +++ /dev/null @@ -1,37 +0,0 @@ -setTimestamp(mt_rand($start->getTimestamp(), $end->getTimestamp())); } } diff --git a/Utils/RnG/DistributionType.php b/Utils/RnG/DistributionType.php index 544296777..6ceaa11a6 100644 --- a/Utils/RnG/DistributionType.php +++ b/Utils/RnG/DistributionType.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; @@ -20,14 +19,13 @@ use phpOMS\Stdlib\Base\Enum; /** * Distribution type enum. * - * @category Framework - * @package Utils/RnG + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class DistributionType extends Enum { /* public */ const UNIFORM = 0; - /* public */ const NORMAL = 1; + /* public */ const NORMAL = 1; } diff --git a/Utils/RnG/Email.php b/Utils/RnG/Email.php index 0756d51e1..5aa4133c7 100644 --- a/Utils/RnG/Email.php +++ b/Utils/RnG/Email.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; diff --git a/Utils/RnG/File.php b/Utils/RnG/File.php index b892b587c..ef33cb874 100644 --- a/Utils/RnG/File.php +++ b/Utils/RnG/File.php @@ -4,25 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; - /** * File generator. * - * @category DataStorage - * @package Framework + * @package DataStorage * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class File @@ -35,16 +32,16 @@ class File * @since 1.0.0 */ private static $extensions = [ - ['exe', null], ['dat', null], ['txt', null], ['csv', 'txt'], ['doc', null], ['docx', 'doc'], - ['mp3', null], ['mp4', null], ['avi', null], ['mpeg', null], ['wmv', null], ['ppt', null], - ['xls', null], ['xlsx', 'xls'], ['xlsxm', 'xls'], ['php', null], ['html', null], ['tex', null], - ['js', null], ['c', null], ['cpp', null], ['h', null], ['res', null], ['ico', null], - ['jpg', null], ['png', null], ['gif', null], ['bmp', null], ['ttf', null], ['zip', null], - ['rar', null], ['7z', null], ['tar', 'gz'], ['gz', null], ['gz', null], ['sh', null], - ['bat', null], ['iso', null], ['css', null], ['json', null], ['ini', null], ['psd', null], - ['pptx', 'ppt'], ['xml', null], ['dll', null], ['wav', null], ['wma', null], ['vb', null], - ['tmp', null], ['tif', null], ['sql', null], ['swf', null], ['svg', null], ['rpm', null], - ['rss', null], ['pkg', null], ['pdf', null], ['mpg', null], ['mov', null], ['jar', null], + ['exe', null], ['dat', null], ['txt', null], ['csv', 'txt'], ['doc', null], ['docx', 'doc'], + ['mp3', null], ['mp4', null], ['avi', null], ['mpeg', null], ['wmv', null], ['ppt', null], + ['xls', null], ['xlsx', 'xls'], ['xlsxm', 'xls'], ['php', null], ['html', null], ['tex', null], + ['js', null], ['c', null], ['cpp', null], ['h', null], ['res', null], ['ico', null], + ['jpg', null], ['png', null], ['gif', null], ['bmp', null], ['ttf', null], ['zip', null], + ['rar', null], ['7z', null], ['tar', 'gz'], ['gz', null], ['gz', null], ['sh', null], + ['bat', null], ['iso', null], ['css', null], ['json', null], ['ini', null], ['psd', null], + ['pptx', 'ppt'], ['xml', null], ['dll', null], ['wav', null], ['wma', null], ['vb', null], + ['tmp', null], ['tif', null], ['sql', null], ['swf', null], ['svg', null], ['rpm', null], + ['rss', null], ['pkg', null], ['pdf', null], ['mpg', null], ['mov', null], ['jar', null], ['flv', null], ['fla', null], ['deb', null], ['py', null], ['pl', null], ]; diff --git a/Utils/RnG/Iban.php b/Utils/RnG/Iban.php index 85056b204..f3afbefdc 100644 --- a/Utils/RnG/Iban.php +++ b/Utils/RnG/Iban.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; diff --git a/Utils/RnG/LinearCongruentialGenerator.php b/Utils/RnG/LinearCongruentialGenerator.php index 074452972..e3fca8a9e 100644 --- a/Utils/RnG/LinearCongruentialGenerator.php +++ b/Utils/RnG/LinearCongruentialGenerator.php @@ -4,29 +4,40 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; /** * Linear congruential generator class * - * @category Framework - * @package phpOMS\Asset + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class LinearCongruentialGenerator { + /** + * BSD seed value. + * + * @var int + * @since 1.0.0 + */ private static $bsdSeed = 0; + + /** + * MSVCRT seed value. + * + * @var int + * @since 1.0.0 + */ private static $msvcrtSeed = 0; /** @@ -40,7 +51,7 @@ class LinearCongruentialGenerator */ public static function bsd(int $seed = 0) { - if($seed !== 0) { + if ($seed !== 0) { self::$bsdSeed = $seed; } @@ -58,7 +69,7 @@ class LinearCongruentialGenerator */ public static function msvcrt(int $seed = 0) { - if($seed !== 0) { + if ($seed !== 0) { self::$msvcrtSeed = $seed; } diff --git a/Utils/RnG/Name.php b/Utils/RnG/Name.php index ae64cc0cb..b4a25ac54 100644 --- a/Utils/RnG/Name.php +++ b/Utils/RnG/Name.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; /** * Name generator. * - * @category Framework - * @package Utils\RnG + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Name @@ -471,18 +469,18 @@ class Name 'female' => ['none'], 'male' => ['none'], 'family' => [ - 'Հովհաննիսյան', 'Հարությունյան', 'Սարգսյան', 'Խաչատրյան', 'Գրիգորյան', - 'আহমেদ', 'আলী', 'আক্তার', 'বন্দ্যোপাধ্যায়', 'নিক', 'ব্যাপারী', 'বড়ুয়া', 'বিশ্বাস', 'ভৌমিক', 'বসু', - '王', '李', '张', '刘', '陈', '杨', '黄', '赵', '吴', '周', '徐', '孙', '马', '朱', '胡', '郭', '何', '高', '林', '罗', - 'כהן', 'לוי', 'מזרחי', 'פרץ', 'ביטון', 'דהן', 'אברהם', 'פרידמן', 'מלכה', 'אזולאי', 'כץ', 'יוסף', 'דוד', 'עמר', 'אוחיון', - '김', '리', '박', '최', '정', '강', '조', '윤', '장', '림', '한', '신', '서', '권', '황', '안', '송', '홍', '고', '문', '손', '량', - 'Yılmaz', 'Kaya', 'Demir', 'Şahin', 'Çelik', 'Yıldız', 'Yıldırım', 'Öztürk', 'Aydın', 'Özdemir', 'Arslan', 'Doğan', 'Kılıç', 'Aslan', 'Çetin', 'Kara', 'Koç', 'Kurt', 'Özkan', 'Şimşek', + 'Հովհաննիսյան', 'Հարությունյան', 'Սարգսյան', 'Խաչատրյան', 'Գրիգորյան', 'আহমেদ', 'আলী', 'আক্তার', + 'বন্দ্যোপাধ্যায়', 'নিক', 'ব্যাপারী', 'বড়ুয়া', 'বিশ্বাস', 'ভৌমিক', 'বসু', '王', '李', '张', '刘', '陈', '杨', + '黄', '赵', '吴', '周', '徐', '孙', '马', '朱', '胡', '郭', '何', '高', '林', '罗', 'כהן', 'לוי', + 'מזרחי', 'פרץ', 'ביטון', 'דהן', 'אברהם', 'פרידמן', 'מלכה', 'אזולאי', 'כץ', 'יוסף', 'דוד', 'עמר', + 'אוחיון', '김', '리', '박', '최', '정', '강', '조', '윤', '장', '림', '한', '신', '서', '권', '황', + '안', '송', '홍', '고', '문', '손', '량', 'Yılmaz', 'Kaya', 'Demir', 'Şahin', 'Çelik', 'Yıldız', + 'Yıldırım', 'Öztürk', 'Aydın', 'Özdemir', 'Arslan', 'Doğan', 'Kılıç', 'Aslan', 'Çetin', 'Kara', + 'Koç', 'Kurt', 'Özkan', 'Şimşek', ], ] ]; - - /** * Get a random string. * diff --git a/Utils/RnG/Numeric.php b/Utils/RnG/Numeric.php index 0696086c9..00458dd5d 100644 --- a/Utils/RnG/Numeric.php +++ b/Utils/RnG/Numeric.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; diff --git a/Utils/RnG/Phone.php b/Utils/RnG/Phone.php index 128660d93..945154b05 100644 --- a/Utils/RnG/Phone.php +++ b/Utils/RnG/Phone.php @@ -4,25 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; - /** * Phone generator. * - * @category Framework - * @package Utils\RnG + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Phone @@ -58,7 +55,10 @@ class Phone $numberParts = substr_count($layout['struct'], '$'); for ($i = ($isInt ? 2 : 1); $i < $numberParts; $i++) { - $numberString = str_replace('$' . $i, StringUtils::generateString($layout['size'][$i - 1][0], $layout['size'][$i - 1][1], '0123456789'), $numberString); + $numberString = str_replace( + '$' . $i, StringUtils::generateString($layout['size'][$i - 1][0], $layout['size'][$i - 1][1], '0123456789'), + $numberString + ); } return $numberString; diff --git a/Utils/RnG/PostalZip.php b/Utils/RnG/PostalZip.php index bf3919bc3..a76b53af0 100644 --- a/Utils/RnG/PostalZip.php +++ b/Utils/RnG/PostalZip.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; diff --git a/Utils/RnG/StringUtils.php b/Utils/RnG/StringUtils.php index e70c147fd..225334a74 100644 --- a/Utils/RnG/StringUtils.php +++ b/Utils/RnG/StringUtils.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; /** * String generator. * - * @category Framework - * @package Utils\RnG + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class StringUtils @@ -38,7 +36,9 @@ class StringUtils * * @since 1.0.0 */ - public static function generateString(int $min = 10, int $max = 10, string $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string + public static function generateString(int $min = 10, int $max = 10, + string $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + ) : string { $length = mt_rand($min, $max); $charactersLength = strlen($charset); diff --git a/Utils/RnG/Text.php b/Utils/RnG/Text.php index dd9b8016d..072ff5939 100644 --- a/Utils/RnG/Text.php +++ b/Utils/RnG/Text.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\RnG; /** * Text generator. * - * @category Framework - * @package RnG + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Text @@ -33,22 +31,22 @@ class Text * @var string[] * @since 1.0.0 */ - private static $words_west = [ - 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero', - 'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut', 'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia', 'a', - 'pretium', 'quis', 'congue', 'praesent', 'sagittis', 'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros', 'dictum', - 'proin', 'accumsan', 'sapien', 'nec', 'massa', 'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus', 'quisque', - 'porttitor', 'ligula', 'dui', 'mollis', 'tempus', 'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam', 'tincidunt', 'id', - 'condimentum', 'enim', 'sodales', 'in', 'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque', 'fusce', 'augue', - 'leo', 'eget', 'semper', 'mattis', 'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada', 'rhoncus', 'porta', - 'sem', 'aliquet', 'et', 'nam', 'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat', 'donec', 'justo', - 'vehicula', 'ultricies', 'varius', 'ante', 'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae', 'etiam', - 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl', 'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', - 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae', - 'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu', 'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis', - 'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis', 'sollicitudin', 'integer', 'rutrum', 'duis', 'est', - 'etiam', 'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi', 'fermentum', 'consequat', 'suscipit', 'aliquam', - 'habitant', 'senectus', 'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus', 'elementum', 'tempor', 'risus', + private static $wordsWest = [ + 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero', + 'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut', 'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia', 'a', + 'pretium', 'quis', 'congue', 'praesent', 'sagittis', 'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros', 'dictum', + 'proin', 'accumsan', 'sapien', 'nec', 'massa', 'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus', 'quisque', + 'porttitor', 'ligula', 'dui', 'mollis', 'tempus', 'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam', 'tincidunt', 'id', + 'condimentum', 'enim', 'sodales', 'in', 'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque', 'fusce', 'augue', + 'leo', 'eget', 'semper', 'mattis', 'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada', 'rhoncus', 'porta', + 'sem', 'aliquet', 'et', 'nam', 'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat', 'donec', 'justo', + 'vehicula', 'ultricies', 'varius', 'ante', 'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae', 'etiam', + 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl', 'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', + 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae', + 'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu', 'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis', + 'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis', 'sollicitudin', 'integer', 'rutrum', 'duis', 'est', + 'etiam', 'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi', 'fermentum', 'consequat', 'suscipit', 'aliquam', + 'habitant', 'senectus', 'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus', 'elementum', 'tempor', 'risus', 'cras', ]; @@ -133,20 +131,20 @@ class Text } if ($words === null) { - $words = self::$words_west; + $words = self::$wordsWest; } - $punctuation = $this->generatePunctuation($length); - $punctuation_count = array_count_values( + $punctuation = $this->generatePunctuation($length); + $punctuationCount = array_count_values( array_map( function ($item) { return $item[1]; }, $punctuation ) - ) + ['.' => 0, '!' => 0, '?' => '?']; + ) + ['.' => 0, '!' => 0, '?' => 0]; - $this->sentences = $punctuation_count['.'] + $punctuation_count['!'] + $punctuation_count['?']; + $this->sentences = $punctuationCount['.'] + $punctuationCount['!'] + $punctuationCount['?']; if ($this->hasParagraphs) { $paragraph = $this->generateParagraph($this->sentences); @@ -235,16 +233,16 @@ class Text } /* Handle comma */ - $comma_here = (rand(0, 100) <= $probComma * 100 && $sentenceLength >= 2 * $minCommaSpacing ? true : false); - $posComma = []; + $commaHere = (rand(0, 100) <= $probComma * 100 && $sentenceLength >= 2 * $minCommaSpacing ? true : false); + $posComma = []; - if ($comma_here) { + if ($commaHere) { $posComma[] = rand($minCommaSpacing, $sentenceLength - $minCommaSpacing); $punctuation[] = [$i + $posComma[0], ',']; - $comma_here = (rand(0, 100) <= $probComma * 100 && $posComma[0] + $minCommaSpacing * 2 < $sentenceLength ? true : false); + $commaHere = (rand(0, 100) <= $probComma * 100 && $posComma[0] + $minCommaSpacing * 2 < $sentenceLength ? true : false); - if ($comma_here) { + if ($commaHere) { $posComma[] = rand($posComma[0] + $minCommaSpacing, $sentenceLength - $minCommaSpacing); $punctuation[] = [$i + $posComma[1], ',']; } @@ -253,16 +251,16 @@ class Text $i += $sentenceLength; /* Handle sentence ending */ - $is_dot = (rand(0, 100) <= $probDot * 100 ? true : false); + $isDot = (rand(0, 100) <= $probDot * 100 ? true : false); - if ($is_dot) { + if ($isDot) { $punctuation[] = [$i, '.']; continue; } - $is_ex = (rand(0, 100) <= $probExc * 100 ? true : false); + $isEx = (rand(0, 100) <= $probExc * 100 ? true : false); - if ($is_ex) { + if ($isEx) { $punctuation[] = [$i, '!']; continue; } @@ -296,7 +294,7 @@ class Text $paragraphLength = $length - $i; } - $i += $paragraphLength; + $i += $paragraphLength; $paragraph[] = $i; } diff --git a/Utils/StringCompare.php b/Utils/StringCompare.php index 4d471d751..dcee3e45f 100644 --- a/Utils/StringCompare.php +++ b/Utils/StringCompare.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; @@ -20,10 +19,9 @@ namespace phpOMS\Utils; * * This class helps to compare two strings * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class StringCompare @@ -38,7 +36,7 @@ class StringCompare /** * Constructor. - * + * * @param array $dictionary Dictionary * * @since 1.0.0 @@ -50,9 +48,9 @@ class StringCompare /** * Adds word to dictionary - * + * * @param string $word Word to add to dictionary - * + * * @return void * * @since 1.0.0 @@ -76,10 +74,10 @@ class StringCompare $bestScore = PHP_INT_MAX; $bestMatch = ''; - foreach($this->dictionary as $word) { + foreach ($this->dictionary as $word) { $score = self::fuzzyMatch($word, $match); - if($score < $bestScore) { + if ($score < $bestScore) { $bestScore = $score; $bestMatch = $word; } @@ -102,19 +100,19 @@ class StringCompare { $words1 = preg_split('/[ _-]/', $s1); $words2 = preg_split('/[ _-]/', $s2); - $total = 0; + $total = 0; - foreach($words1 as $word1) { + foreach ($words1 as $word1) { $best = strlen($s2); - foreach($words2 as $word2) { + foreach ($words2 as $word2) { $wordDist = levenshtein($word1, $word2); - if($wordDist < $best) { + if ($wordDist < $best) { $best = $wordDist; } - if($wordDist === 0) { + if ($wordDist === 0) { break; } } @@ -152,25 +150,30 @@ class StringCompare */ public static function valueLength(string $s1, string $s2) : int { - return abs(strlen($s1) - strlen($s2)); + return (int) abs(strlen($s1) - strlen($s2)); } /** * Calculate fuzzy match score. * - * @param string $s1 Word 1 - * @param string $s2 Word 2 + * @param string $s1 Word 1 + * @param string $s2 Word 2 * @param float $phraseWeight Weighting for phrase score - * @param float $wordWeight Weighting for word score - * @param float $minWeight Min weight - * @param float $maxWeight Max weight + * @param float $wordWeight Weighting for word score + * @param float $minWeight Min weight + * @param float $maxWeight Max weight * @param float $lengthWeight Weighting for word length * * @return float * * @since 1.0.0 */ - public static function fuzzyMatch(string $s1, string $s2, float $phraseWeight = 0.5, float $wordWeight = 1, float $minWeight = 10, float $maxWeight = 1, float $lengthWeight = -0.3) : float + public static function fuzzyMatch( + string $s1, string $s2, + float $phraseWeight = 0.5, float $wordWeight = 1, + float $minWeight = 10, float $maxWeight = 1, + float $lengthWeight = -0.3 + ) : float { $phraseValue = self::valuePhrase($s1, $s2); $wordValue = self::valueWords($s1, $s2); @@ -179,5 +182,5 @@ class StringCompare return min($phraseValue * $phraseWeight, $wordValue * $wordWeight) * $minWeight + max($phraseValue * $phraseWeight, $wordValue * $wordWeight) * $maxWeight + $lengthValue * $lengthWeight; - } -} \ No newline at end of file + } +} diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index 8b9df87fd..7ebff34fa 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils; @@ -20,11 +19,12 @@ namespace phpOMS\Utils; * * This class provides static helper functionalities for strings. * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * + * @SuppressWarnings(PHPMD.CamelCaseMethodName) */ class StringUtils { @@ -352,18 +352,18 @@ class StringUtils * * @param string $value String to analyze. * - * @return float + * @return float * * @since 1.0.0 */ public static function getEntropy(string $value) : float { - $entroy = 0.0; - $size = mb_strlen($value); + $entroy = 0.0; + $size = mb_strlen($value); $countChars = self::mb_count_chars($value); foreach ($countChars as $v) { - $p = $v / $size; + $p = $v / $size; $entroy -= $p * log($p) / log(2); } @@ -375,7 +375,7 @@ class StringUtils * * @param string $input String to count chars. * - * @return array + * @return array * * @since 1.0.0 */ @@ -384,10 +384,10 @@ class StringUtils $l = mb_strlen($input, 'UTF-8'); $unique = []; - for($i = 0; $i < $l; $i++) { + for ($i = 0; $i < $l; $i++) { $char = mb_substr($input, $i, 1, 'UTF-8'); - if(!array_key_exists($char, $unique)) { + if (!array_key_exists($char, $unique)) { $unique[$char] = 0; } diff --git a/Utils/TaskSchedule/Cron.php b/Utils/TaskSchedule/Cron.php index 2f8b9d765..f78d28e62 100644 --- a/Utils/TaskSchedule/Cron.php +++ b/Utils/TaskSchedule/Cron.php @@ -4,46 +4,126 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; /** * Cron class. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class Cron extends SchedulerAbstract { - public function save() - { - - } - /** * Run command * * @param string $cmd Command to run * - * @return array + * @return string + * + * @throws \Exception * * @since 1.0.0 */ - public function run(string $cmd) : array + private function run(string $cmd) : string { - // TODO: Implement run() method. - return []; + $cmd = 'cd ' . escapeshellarg(dirname(self::$bin)) . ' && ' . basename(self::$bin) . ' ' . $cmd; + + $pipes = []; + $desc = [ + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; + + $resource = proc_open($cmd, $desc, $pipes, __DIR__, null); + $stdout = stream_get_contents($pipes[1]); + $stderr = stream_get_contents($pipes[2]); + + foreach ($pipes as $pipe) { + fclose($pipe); + } + + $status = trim((string) proc_close($resource)); + + if ($status == -1) { + throw new \Exception($stderr); + } + + return trim($stdout); + } + + /** + * Normalize run result for easier parsing + * + * @param string $raw Raw command output + * + * @return string Normalized string for parsing + * + * @since 1.0.0 + */ + private function normalize(string $raw) : string + { + return str_replace("\r\n", "\n", $raw); + } + + /** + * {@inheritdoc} + */ + public function getAll() : array + { + $lines = explode("\n", $this->normalize($this->run('-l'))); + unset($lines[0]); + + $jobs = []; + foreach ($lines as $line) { + if ($line !== '' && strrpos($line, '#', -strlen($line)) === false) { + $jobs[] = CronJob::createWith(str_getcsv($line, ' ')); + } + } + + return $jobs; + } + + /** + * {@inheritdoc} + */ + public function getAllByName(string $name, bool $exact = true) : array + { + $lines = explode("\n", $this->normalize($this->run('-l'))); + unset($lines[0]); + + if ($exact) { + $jobs = []; + foreach ($lines as $line) { + $csv = str_getcsv($line, ' '); + + if ($line !== '' && strrpos($line, '#', -strlen($line)) === false && $csv[5] === $name) { + $jobs[] = CronJob::createWith($csv); + } + } + } else { + $jobs = []; + foreach ($lines as $line) { + $csv = str_getcsv($line, ' '); + + if ($line !== '' && strrpos($line, '#', -strlen($line)) === false && stripos($csv[5], $name) !== false) { + $jobs[] = CronJob::createWith($csv); + } + } + } + + return $jobs; } } diff --git a/Utils/TaskSchedule/CronJob.php b/Utils/TaskSchedule/CronJob.php index d2c58a931..950b73a2e 100644 --- a/Utils/TaskSchedule/CronJob.php +++ b/Utils/TaskSchedule/CronJob.php @@ -4,103 +4,35 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; /** * CronJob class. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class CronJob extends TaskAbstract implements \Serializable +class CronJob extends TaskAbstract { - /** - * Constructor. - * - * @param Interval $interval Interval - * @param string $cmd Command to execute - * - * @since 1.0.0 + * {@inheritdoc} */ - public function __construct(Interval $interval = null, $cmd = '') + public static function createWith(array $jobData) : TaskAbstract { - if (!isset($interval)) { - $this->interval = new Interval(); - } else { - $this->interval = $interval; - } + $job = new self($jobData[5], ''); - $this->command = $cmd; - } + $job->setRun($jobData[5]); - /** - * Serialize cronjob. - * - * @return string - * - * @since 1.0.0 - */ - public function serialize() - { - $minute = $this->printValue($this->interval->getMinute()); - $hour = $this->printValue($this->interval->getHour()); - $dayOfMonth = $this->printValue($this->interval->getDayOfMonth()); - $month = $this->printValue($this->interval->getMonth()); - $dayOfWeek = $this->printValue($this->interval->getDayOfWeek()); - - return $minute . ' ' . $hour . ' ' . $dayOfMonth . ' ' . $month . ' ' . $dayOfWeek . ' ' . $this->command; - } - - /** - * Print value. - * - * @param array $value Element to serialize - * - * @return string - * - * @since 1.0.0 - */ - private function printValue(array $value) : string - { - if (($count = count($value['dayOfWeek'])) > 0) { - $parsed = implode(',', $value['dayOfWeek']); - } elseif ($value['start'] !== 0 && $value['end']) { - $parsed = $value['start'] . '-' . $value['end']; - $count = 2; - } else { - $parsed = '*'; - $count = 1; - } - - if ($count === 0 && $value['step'] !== 0) { - $parsed .= '/' . $value['step']; - } - - return $parsed; - } - - /** - * Unserialize cronjob. - * - * @param string $serialized To unserialize - * - * @since 1.0.0 - */ - public function unserialize($serialized) - { - // TODO: Implement unserialize() method. + return $job; } } diff --git a/Utils/TaskSchedule/Interval.php b/Utils/TaskSchedule/Interval.php index a18d220a0..e2f27352e 100644 --- a/Utils/TaskSchedule/Interval.php +++ b/Utils/TaskSchedule/Interval.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; /** * Interval class for tasks. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Interval implements \Serializable @@ -137,7 +135,7 @@ class Interval implements \Serializable */ private function parseMinute(string $minute) : array { - + return [$minute]; } /** @@ -151,7 +149,7 @@ class Interval implements \Serializable */ private function parseHour(string $hour) : array { - + return [$hour]; } /** @@ -165,7 +163,7 @@ class Interval implements \Serializable */ private function parseDayOfMonth(string $dayOfMonth) : array { - + return [$dayOfMonth]; } /** @@ -179,7 +177,7 @@ class Interval implements \Serializable */ private function parseMonth(string $month) : array { - + return [$month]; } /** @@ -193,7 +191,7 @@ class Interval implements \Serializable */ private function parseDayOfWeek(string $dayOfWeek) : array { - + return [$dayOfWeek]; } /** @@ -207,7 +205,7 @@ class Interval implements \Serializable */ private function parseYear(string $year) : array { - + return [$year]; } /** diff --git a/Utils/TaskSchedule/InvalidTaskParameterException.php b/Utils/TaskSchedule/InvalidTaskParameterException.php deleted file mode 100644 index 8a55a9fd2..000000000 --- a/Utils/TaskSchedule/InvalidTaskParameterException.php +++ /dev/null @@ -1,35 +0,0 @@ -setRun($jobData[8]); + $job->setStatus($jobData[3]); - /** - * Constructs the object - * @link http://php.net/manual/en/serializable.unserialize.php - * @param string $serialized- * The string representation of the object. - *
- * @return void - * @since 5.1.0 - */ - public function unserialize($serialized) - { - // TODO: Implement unserialize() method. + if (DateTime::isValid($jobData[2])) { + $job->setNextRunTime(new \DateTime($jobData[2])); + } + + if (DateTime::isValid($jobData[5])) { + $job->setLastRuntime(new \DateTime($jobData[5])); + } + + $job->setComment($jobData[10]); + $job->addResult($jobData[6]); + + return $job; } } diff --git a/Utils/TaskSchedule/SchedulerAbstract.php b/Utils/TaskSchedule/SchedulerAbstract.php index 8a875680a..285a86907 100644 --- a/Utils/TaskSchedule/SchedulerAbstract.php +++ b/Utils/TaskSchedule/SchedulerAbstract.php @@ -4,36 +4,29 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; + use phpOMS\System\File\PathException; /** * Scheduler abstract. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ abstract class SchedulerAbstract { - /** - * Tasks. - * - * @var TaskAbstract[] - * @since 1.0.0 - */ - protected $tasks = []; /** * Bin path. @@ -79,6 +72,7 @@ abstract class SchedulerAbstract * @return bool * * @since 1.0.0 + * @codeCoverageIgnore */ public static function test() : bool { @@ -96,85 +90,16 @@ abstract class SchedulerAbstract } /** - * Add task + * Create task * - * @param TaskAbstract $task Task to add + * @param TaskAbstract * * @return void * * @since 1.0.0 */ - public function add(TaskAbstract $task) /* : void */ + public function create(TaskAbstract $task) /* : void */ { - $this->tasks[$task->getId()] = $task; + $this->run($task->getCommand()); } - - /** - * Remove task - * - * @param mixed $id Task id - * - * @return bool - * - * @since 1.0.0 - */ - public function remove(string $id) : bool - { - if (isset($this->tasks[$id])) { - unset($this->tasks[$id]); - - return true; - } - - return false; - } - - /** - * Get task - * - * @param mixed $id Task id - * - * @return TaskAbstract|null - * - * @since 1.0.0 - */ - public function get(string $id) - { - return $this->tasks[$id] ?? null; - } - - /** - * Get all tasks - * - * @return TaskAbstract[] - * - * @since 1.0.0 - */ - public function getAll() : array - { - return $this->tasks; - } - - /** - * Set task - * - * @param TaskAbstract $task Task to edit - * - * @return void - * - * @since 1.0.0 - */ - public function set(TaskAbstract $task) /* : void */ - { - $this->tasks[$task->getId()] = $task; - } - - /** - * Save tasks - * - * @return void - * - * @since 1.0.0 - */ - abstract public function save() /* : void */; } diff --git a/Utils/TaskSchedule/SchedulerFactory.php b/Utils/TaskSchedule/SchedulerFactory.php index ef8b6bd5d..81f37c758 100644 --- a/Utils/TaskSchedule/SchedulerFactory.php +++ b/Utils/TaskSchedule/SchedulerFactory.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; @@ -21,10 +20,9 @@ use phpOMS\System\SystemType; /** * Scheduler factory. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class SchedulerFactory @@ -49,4 +47,4 @@ final class SchedulerFactory throw new \Exception('Unsupported system.'); } } -} \ No newline at end of file +} diff --git a/Utils/TaskSchedule/TaskAbstract.php b/Utils/TaskSchedule/TaskAbstract.php index 9ef962f30..bc80dc258 100644 --- a/Utils/TaskSchedule/TaskAbstract.php +++ b/Utils/TaskSchedule/TaskAbstract.php @@ -4,24 +4,22 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; /** * Abstract task class. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class TaskAbstract @@ -50,25 +48,55 @@ abstract class TaskAbstract */ protected $run = ''; + /** + * Status of the task + * + * @var string + * @since 1.0.0 + */ protected $status = ''; + /** + * Next runtime + * + * @var \DateTime + * @since 1.0.0 + */ protected $nextRunTime = null; + /** + * Last runtime + * + * @var \DateTime + * @since 1.0.0 + */ protected $lastRunTime = null; - protected $start = null; - - protected $end = null; - + /** + * Comment + * + * @param string $name Name of the task + * @param string $cmd Command/script to run + * + * @var string + * @since 1.0.0 + */ protected $comment = ''; - protected $results = []; - - protected $author = ''; - - public function __construct(string $name, string $cmd = '') { - $this->id = $name; - $this->command = $cmd; + /** + * Constructor + * + * @param string $name Id/name of the task (on linux the same as the executable script) + * @param string $cmd Command to create the task + * + * @since 1.0.0 + */ + public function __construct(string $name, string $cmd = '') + { + $this->id = $name; + $this->command = $cmd; + $this->lastRunTime = new \DateTime('1900-01-01'); + $this->nextRunTime = new \DateTime('1900-01-01'); } /** @@ -84,7 +112,7 @@ abstract class TaskAbstract } /** - * Get command. + * Get command to create the task * * @return string * @@ -96,7 +124,7 @@ abstract class TaskAbstract } /** - * Set command. + * Set command to create the task * * @param string $command Command * @@ -110,7 +138,7 @@ abstract class TaskAbstract } /** - * Get run. + * Get command/script to run * * @return string * @@ -122,7 +150,7 @@ abstract class TaskAbstract } /** - * Set run. + * Set script to run * * @param string $run Command/script to run * @@ -194,7 +222,7 @@ abstract class TaskAbstract * * @since 1.0.0 */ - public function getLastRuntime() + public function getLastRuntime() { return $this->lastRunTime; } @@ -213,84 +241,6 @@ abstract class TaskAbstract $this->lastRunTime = $lastRunTime; } - /** - * Get start. - * - * @return \DateTime - * - * @since 1.0.0 - */ - public function getStart() - { - return $this->start; - } - - /** - * Set start. - * - * @param \DateTime $start Start - * - * @return void - * - * @since 1.0.0 - */ - public function setStart(\DateTime $start) /* : void */ - { - $this->start = $start; - } - - /** - * Get end. - * - * @return \DateTime - * - * @since 1.0.0 - */ - public function getEnd() - { - return $this->end; - } - - /** - * Set end. - * - * @param \DateTime $end End - * - * @return void - * - * @since 1.0.0 - */ - public function setEnd(\DateTime $end) /* : void */ - { - $this->end = $end; - } - - /** - * Get author. - * - * @return string - * - * @since 1.0.0 - */ - public function getAuthor() : string - { - return $this->author; - } - - /** - * Set author. - * - * @param string $author Author - * - * @return void - * - * @since 1.0.0 - */ - public function setAuthor(string $author) /* : void */ - { - $this->author = $author; - } - /** * Get comment. * @@ -318,14 +268,13 @@ abstract class TaskAbstract } /** - * Get comment. + * Create task based on job data * - * @return string + * @param array $jobData Raw job data * - * @since 1.0.0 + * @return TaskAbstract + * + * @since 1.0.0 */ - public function addResult(string $result) - { - $this->results[] = $result; - } + abstract public static function createWith(array $jobData) : TaskAbstract; } diff --git a/Utils/TaskSchedule/TaskFactory.php b/Utils/TaskSchedule/TaskFactory.php index ebfba5f41..2425b7388 100644 --- a/Utils/TaskSchedule/TaskFactory.php +++ b/Utils/TaskSchedule/TaskFactory.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; @@ -21,10 +20,9 @@ use phpOMS\System\SystemType; /** * Task factory. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ final class TaskFactory @@ -32,8 +30,8 @@ final class TaskFactory /** * Create task instance. * - * @param string $id Task id - * @param string $cmd Command to run + * @param string $id Task id + * @param string $cmd Command to run * * @return TaskAbstract * @@ -52,4 +50,4 @@ final class TaskFactory throw new \Exception('Unsupported system.'); } } -} \ No newline at end of file +} diff --git a/Utils/TaskSchedule/TaskScheduler.php b/Utils/TaskSchedule/TaskScheduler.php index 8dcc8c25e..df8a5484c 100644 --- a/Utils/TaskSchedule/TaskScheduler.php +++ b/Utils/TaskSchedule/TaskScheduler.php @@ -4,38 +4,27 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Utils\TaskSchedule; -use phpOMS\Validation\Base\DateTime; - /** * Task scheduler class. * - * @category Framework - * @package phpOMS\Utils\TaskSchedule + * @package Framework * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 + * @codeCoverageIgnore */ class TaskScheduler extends SchedulerAbstract { - /** - * {@inheritdoc} - */ - public function save() /* : void */ - { - - } - /** * Run command * @@ -83,51 +72,11 @@ class TaskScheduler extends SchedulerAbstract * * @since 1.0.0 */ - private function normalize(string $raw) : string + private function normalize(string $raw) : string { return str_replace("\r\n", "\n", $raw); } - /** - * Parse a list of jobs - * - * @param array $jobData Csv data containing the job information - * - * @return TaskAbstract Parsed job - * - * @since 1.0.0 - */ - private function parseJobList(array $jobData) : TaskAbstract - { - $job = TaskFactory::create($jobData[1], ''); - - $job->setRun($jobData[8]); - $job->setStatus($jobData[3]); - - if(DateTime::isValid($jobData[2])) { - $job->setNextRunTime(new \DateTime($jobData[2])); - } - - if(DateTime::isValid($jobData[5])) { - $job->setLastRuntime(new \DateTime($jobData[5])); - } - - $job->setAuthor($jobData[7]); - $job->setComment($jobData[10]); - - if(DateTime::isValid($jobData[20])) { - $job->setStart(new \DateTime($jobData[20])); - } - - if(DateTime::isValid($jobData[21])) { - $job->setEnd(new \DateTime($jobData[21])); - } - - $job->addResult($jobData[6]); - - return $job; - } - /** * {@inheritdoc} */ @@ -137,65 +86,40 @@ class TaskScheduler extends SchedulerAbstract unset($lines[0]); $jobs = []; - foreach($lines as $line) { - $jobs[] = $this->parseJobList(str_getcsv($line)); + foreach ($lines as $line) { + $jobs[] = Schedule::createWith(str_getcsv($line)); } - + return $jobs; } - /** - * {@inheritdoc} - */ - public function get(string $id) - { - // todo: implement - } - - /** - * {@inheritdoc} - */ - public function getByName(string $name) : Schedule - { - // todo: implement - } - /** * {@inheritdoc} */ public function getAllByName(string $name, bool $exact = true) : array { - if($exact) { + if ($exact) { $lines = explode("\n", $this->normalize($this->run('/query /v /fo CSV /tn ' . escapeshellarg($name)))); unset($lines[0]); $jobs = []; - foreach($lines as $line) { - $jobs[] = $this->parseJobList(str_getcsv($line)); + foreach ($lines as $line) { + $jobs[] = Schedule::createWith(str_getcsv($line)); } } else { $lines = explode("\n", $this->normalize($this->run('/query /v /fo CSV'))); - $jobs = []; - unset($lines[0]); - foreach($lines as $key => $line) { + $jobs = []; + foreach ($lines as $key => $line) { $line = str_getcsv($line); - if(strpos($line[1], $name) !== false) { - $jobs[] = $this->parseJobList($line); + if (stripos($line[1], $name) !== false) { + $jobs[] = Schedule::createWith($line); } } } return $jobs; } - - /** - * {@inheritdoc} - */ - public function create(Schedule $task) - { - // todo: implement - } } diff --git a/Utils/TestUtils.php b/Utils/TestUtils.php index 4095bbd37..268a9dedb 100644 --- a/Utils/TestUtils.php +++ b/Utils/TestUtils.php @@ -4,24 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Utils * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); + namespace phpOMS\Utils; + /** * Test utils. * * Only for testing purposes. MUST NOT be used for other purposes. * - * @category Framework * @package phpOMS\Utils * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class TestUtils @@ -29,7 +29,7 @@ class TestUtils /** * Set private object member * - * @param object $obj Object to modify + * @param object|string $obj Object to modify * @param string $name Member name to modify * @param mixed $value Value to set * @@ -39,57 +39,57 @@ class TestUtils */ public static function setMember(/* object */ $obj, string $name, $value) : bool { - $reflectionClass = new \ReflectionClass(get_class($obj)); - - if(!$reflectionClass->hasProperty($name)) { + $reflectionClass = new \ReflectionClass(is_string($obj) ? $obj : get_class($obj)); + + if (!$reflectionClass->hasProperty($name)) { return false; } - + $reflectionProperty = $reflectionClass->getProperty($name); - + if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } - + $reflectionProperty->setValue($obj, $value); - + if (!$accessible) { $reflectionProperty->setAccessible(false); } - + return true; } - + /** * Get private object member * - * @param object $obj Object to read + * @param object|string $obj Object to read * @param string $name Member name to read * * @return mixed Returns the member variable value * * @since 1.0.0 */ - public static function getMember(/* object */ $obj, string $name) + public static function getMember($obj, string $name) { - $reflectionClass = new \ReflectionClass(get_class($obj)); - - if(!$reflectionClass->hasProperty($name)) { + $reflectionClass = new \ReflectionClass(is_string($obj) ? $obj : get_class($obj)); + + if (!$reflectionClass->hasProperty($name)) { return null; } - + $reflectionProperty = $reflectionClass->getProperty($name); - + if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } - + $value = $reflectionProperty->getValue($obj); - + if (!$accessible) { $reflectionProperty->setAccessible(false); } - + return $value; } } diff --git a/Validation/Barcode/Barcode.php b/Validation/Barcode/Barcode.php index 42433e8f7..15042f1bb 100644 --- a/Validation/Barcode/Barcode.php +++ b/Validation/Barcode/Barcode.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/Barcode11.php b/Validation/Barcode/Barcode11.php index 880df57b4..93dc8f778 100644 --- a/Validation/Barcode/Barcode11.php +++ b/Validation/Barcode/Barcode11.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode11 extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/Barcode128.php b/Validation/Barcode/Barcode128.php index 291e2e412..3a1208905 100644 --- a/Validation/Barcode/Barcode128.php +++ b/Validation/Barcode/Barcode128.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode128 extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/Barcode25.php b/Validation/Barcode/Barcode25.php index f8d9b9ea0..ae90e7699 100644 --- a/Validation/Barcode/Barcode25.php +++ b/Validation/Barcode/Barcode25.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode25 extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/Barcode39.php b/Validation/Barcode/Barcode39.php index 55699b1ac..1c8b07e08 100644 --- a/Validation/Barcode/Barcode39.php +++ b/Validation/Barcode/Barcode39.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode39 extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/Barcode93.php b/Validation/Barcode/Barcode93.php index 9eda300d3..0e3b33a68 100644 --- a/Validation/Barcode/Barcode93.php +++ b/Validation/Barcode/Barcode93.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class Barcode93 extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/BarcodeCodebar.php b/Validation/Barcode/BarcodeCodebar.php index d58afad7d..5d2f08118 100644 --- a/Validation/Barcode/BarcodeCodebar.php +++ b/Validation/Barcode/BarcodeCodebar.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class BarcodeCodebar extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/BarcodeDatamatrix.php b/Validation/Barcode/BarcodeDatamatrix.php index e7858613c..5ce25b8ee 100644 --- a/Validation/Barcode/BarcodeDatamatrix.php +++ b/Validation/Barcode/BarcodeDatamatrix.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class BarcodeDatamatrix extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/BarcodeEAN.php b/Validation/Barcode/BarcodeEAN.php index bcd9a4904..82517ed8d 100644 --- a/Validation/Barcode/BarcodeEAN.php +++ b/Validation/Barcode/BarcodeEAN.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class BarcodeEAN extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/BarcodeMSI.php b/Validation/Barcode/BarcodeMSI.php index 3c9b35285..bcef353bb 100644 --- a/Validation/Barcode/BarcodeMSI.php +++ b/Validation/Barcode/BarcodeMSI.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class BarcodeMSI extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Barcode/QrCode.php b/Validation/Barcode/QrCode.php index bb67e095a..7ade74811 100644 --- a/Validation/Barcode/QrCode.php +++ b/Validation/Barcode/QrCode.php @@ -4,14 +4,13 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Barcode; @@ -21,6 +20,6 @@ class QrCode extends ValidatorAbstract { public static function isValid($value, array $constraints = null) { - + } -} \ No newline at end of file +} diff --git a/Validation/Base/DateTime.php b/Validation/Base/DateTime.php index 8f0e8cdb8..5f1b51b6d 100644 --- a/Validation/Base/DateTime.php +++ b/Validation/Base/DateTime.php @@ -4,26 +4,24 @@ * * 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 + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Base; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Validate date. * - * @category Validation - * @package Framework + * @package Validation * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class DateTime extends ValidatorAbstract diff --git a/Validation/Finance/BIC.php b/Validation/Finance/BIC.php index 5802fa04c..9fc758ce6 100644 --- a/Validation/Finance/BIC.php +++ b/Validation/Finance/BIC.php @@ -4,29 +4,27 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Finance; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Validate BIC * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class BIC extends ValidatorAbstract +abstract class BIC extends ValidatorAbstract { /** diff --git a/Validation/Finance/CreditCard.php b/Validation/Finance/CreditCard.php index 4ed2c178f..d61bdc11b 100644 --- a/Validation/Finance/CreditCard.php +++ b/Validation/Finance/CreditCard.php @@ -4,26 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Finance; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Credit card validation * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class CreditCard extends ValidatorAbstract @@ -46,12 +44,12 @@ abstract class CreditCard extends ValidatorAbstract $value = preg_replace('/\D/', '', $value); // Set the string length and parity - $number_length = strlen($value); - $parity = $number_length % 2; + $numberLength = strlen($value); + $parity = $numberLength % 2; // Loop through each digit and do the maths $total = 0; - for ($i = 0; $i < $number_length; $i++) { + for ($i = 0; $i < $numberLength; $i++) { $digit = $value[$i]; // Multiply alternate digits by two if ($i % 2 == $parity) { diff --git a/Validation/Finance/Iban.php b/Validation/Finance/Iban.php index a0479f372..6bad386d9 100644 --- a/Validation/Finance/Iban.php +++ b/Validation/Finance/Iban.php @@ -4,27 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Finance; use phpOMS\Validation\ValidatorAbstract; - /** - * Validator abstract. + * Iban validation. * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class Iban extends ValidatorAbstract diff --git a/Validation/Finance/IbanEnum.php b/Validation/Finance/IbanEnum.php index 3d2f2098e..dda7e3cf9 100644 --- a/Validation/Finance/IbanEnum.php +++ b/Validation/Finance/IbanEnum.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Finance; @@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum; /** * Iban layout definition. * - * @category Framework - * @package phpOMS\Localization + * @package phpOMS\Validation\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class IbanEnum extends Enum diff --git a/Validation/Finance/IbanErrorType.php b/Validation/Finance/IbanErrorType.php index 9d54d9f6a..fc00e1cda 100644 --- a/Validation/Finance/IbanErrorType.php +++ b/Validation/Finance/IbanErrorType.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Finance * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Finance; @@ -20,17 +19,16 @@ use phpOMS\Stdlib\Base\Enum; /** * Iban error type enum. * - * @category Framework - * @package phpOMS\Datatypes + * @package phpOMS\Validation\Finance * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class IbanErrorType extends Enum { - /* public */ const INVALID_COUNTRY = 1; - /* public */ const INVALID_LENGTH = 2; + /* public */ const INVALID_COUNTRY = 1; + /* public */ const INVALID_LENGTH = 2; /* public */ const INVALID_CHECKSUM = 4; - /* public */ const EXPECTED_ZERO = 8; + /* public */ const EXPECTED_ZERO = 8; /* public */ const EXPECTED_NUMERIC = 16; } diff --git a/Validation/ModelValidationTrait.php b/Validation/ModelValidationTrait.php index 3bdc9c26b..31ef9bdab 100644 --- a/Validation/ModelValidationTrait.php +++ b/Validation/ModelValidationTrait.php @@ -4,23 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation; - /** * Model validation trait. * - * @category Framework - * @package phpOMS\Config + * @package phpOMS\Validation + * @license OMS License 1.0 + * @link http://website.orange-management.de * @since 1.0.0 */ trait ModelValidationTrait @@ -47,7 +46,6 @@ trait ModelValidationTrait } /** @noinspection PhpUnusedPrivateMethodInspection */ - /** * Validate member variable. * diff --git a/Validation/Network/Email.php b/Validation/Network/Email.php index 30afa77c2..3d8814de0 100644 --- a/Validation/Network/Email.php +++ b/Validation/Network/Email.php @@ -4,29 +4,27 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Network * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Network; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Validate email. * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Network * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class Email extends ValidatorAbstract +abstract class Email extends ValidatorAbstract { /** diff --git a/Validation/Network/Hostname.php b/Validation/Network/Hostname.php index cc0ca5c1d..437ac6f32 100644 --- a/Validation/Network/Hostname.php +++ b/Validation/Network/Hostname.php @@ -4,26 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Network * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Network; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Validate hostname. * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Network * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class Hostname extends ValidatorAbstract diff --git a/Validation/Network/Ip.php b/Validation/Network/Ip.php index 3289b6872..e39d05cd9 100644 --- a/Validation/Network/Ip.php +++ b/Validation/Network/Ip.php @@ -4,29 +4,27 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation\Network * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation\Network; use phpOMS\Validation\ValidatorAbstract; /** - * Validator abstract. + * Validate IP. * - * @category Validation - * @package Framework + * @package phpOMS\Validation\Network * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ -class Ip extends ValidatorAbstract +abstract class Ip extends ValidatorAbstract { /** diff --git a/Validation/Validator.php b/Validation/Validator.php index ecb079c71..4b4987d33 100644 --- a/Validation/Validator.php +++ b/Validation/Validator.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation; @@ -20,8 +19,9 @@ use phpOMS\Utils\StringUtils; /** * Validator class. * - * @category Framework * @package phpOMS\Validation + * @license OMS License 1.0 + * @link http://website.orange-management.de * @since 1.0.0 */ final class Validator extends ValidatorAbstract @@ -39,10 +39,14 @@ final class Validator extends ValidatorAbstract */ public static function isValid($var, array $constraints = null) : bool { + if (!isset($constraints)) { + return true; + } + foreach ($constraints as $callback => $settings) { $callback = StringUtils::endsWith($callback, 'Not') ? substr($callback, 0, -3) : $callback; - $valid = self::$callback($var, ...$settings); - $valid = (StringUtils::endsWith($callback, 'Not') ? $valid : !$valid); + $valid = self::$callback($var, ...$settings); + $valid = (StringUtils::endsWith($callback, 'Not') ? $valid : !$valid); if (!$valid) { return false; diff --git a/Validation/ValidatorAbstract.php b/Validation/ValidatorAbstract.php index 2258eca5c..e6f080a4f 100644 --- a/Validation/ValidatorAbstract.php +++ b/Validation/ValidatorAbstract.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation; /** * Validator abstract. * - * @category Validation - * @package Framework + * @package phpOMS\Validation * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ValidatorAbstract implements ValidatorInterface @@ -60,15 +58,11 @@ abstract class ValidatorAbstract implements ValidatorInterface } /** - * Reset error information - * - * @return bool - * - * @since 1.0.0 + * {@inheritdoc} */ public static function resetError() /* : void */ { self::$error = 0; - self::$msg = ''; + self::$msg = ''; } } diff --git a/Validation/ValidatorInterface.php b/Validation/ValidatorInterface.php index 33589fdfb..b1e36403a 100644 --- a/Validation/ValidatorInterface.php +++ b/Validation/ValidatorInterface.php @@ -4,24 +4,22 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Validation * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Validation; /** * Validator interface. * - * @category Validation - * @package Framework + * @package phpOMS\Validation * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ interface ValidatorInterface @@ -30,7 +28,7 @@ interface ValidatorInterface /** * Check if value is valid. * - * @param mixed $value Value to validate + * @param mixed $value Value to validate * @param array $constraints Constraints for validation * * @return bool @@ -56,4 +54,13 @@ interface ValidatorInterface * @since 1.0.0 */ public static function getErrorCode() : int; + + /** + * Reset error information + * + * @return void + * + * @since 1.0.0 + */ + public static function resetError(); /* : void */ } diff --git a/Version/Version.php b/Version/Version.php index 2f5cc2b8d..aa41fe399 100644 --- a/Version/Version.php +++ b/Version/Version.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Version * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Version; @@ -20,10 +19,9 @@ namespace phpOMS\Version; * * Responsible for handling versions * - * @category Version - * @package Framework + * @package phpOMS\Version * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class Version diff --git a/Views/View.php b/Views/View.php index e869ad3de..a5830ae44 100644 --- a/Views/View.php +++ b/Views/View.php @@ -4,14 +4,13 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Views * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Views; @@ -23,12 +22,11 @@ use phpOMS\Module\Exception\InvalidModuleException; use phpOMS\Module\Exception\InvalidThemeException; /** - * List view. + * Basic view which can be used as basis for specific implementations. * - * @category Framework - * @package phpOMS/Views + * @package phpOMS\Views * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ class View extends ViewAbstract @@ -82,15 +80,17 @@ class View extends ViewAbstract * * @since 1.0.0 */ - public function __construct(ApplicationAbstract $app, RequestAbstract $request, ResponseAbstract $response) + public function __construct(ApplicationAbstract $app = null, RequestAbstract $request = null, ResponseAbstract $response = null) { $this->app = $app; $this->request = $request; $this->response = $response; - $this->l11n = $response->getHeader()->getL11n(); + $this->l11n = isset($response) ? $response->getHeader()->getL11n() : null; } /** + * Get data attached to view + * * @param string $id Data Id * * @return mixed @@ -103,6 +103,8 @@ class View extends ViewAbstract } /** + * Set data of view + * * @param string $id Data ID * @param mixed $data Data * @@ -136,6 +138,8 @@ class View extends ViewAbstract } /** + * Add data to view + * * @param string $id Data ID * @param mixed $data Data * @@ -145,7 +149,7 @@ class View extends ViewAbstract */ public function addData(string $id, $data) : bool { - if(isset($this->data[$id])) { + if (isset($this->data[$id])) { return false; } @@ -160,7 +164,7 @@ class View extends ViewAbstract * @param string $translation Text * @param string $module Module name * @param string $theme Theme name - * + * * @return string * * @throws InvalidModuleException Throws this exception if no data for the defined module could be found. @@ -203,7 +207,7 @@ class View extends ViewAbstract * @param string $translation Text * @param string $module Module name * @param string $theme Theme name - * + * * @return string * * @since 1.0.0 @@ -228,6 +232,8 @@ class View extends ViewAbstract } /** + * Get request of view + * * @return RequestAbstract * * @since 1.0.0 @@ -238,6 +244,8 @@ class View extends ViewAbstract } /** + * Get response of view + * * @return ResponseAbstract * * @since 1.0.0 @@ -246,5 +254,4 @@ class View extends ViewAbstract { return $this->response; } - } diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php index c7bb3cbeb..da7b1874c 100644 --- a/Views/ViewAbstract.php +++ b/Views/ViewAbstract.php @@ -4,26 +4,24 @@ * * PHP Version 7.1 * - * @category TBD - * @package TBD + * @package phpOMS\Views * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 - * @link http://orange-management.com + * @link http://website.orange-management.de */ -declare(strict_types=1); +declare(strict_types = 1); namespace phpOMS\Views; use phpOMS\System\File\PathException; /** - * List view. - * - * @category Framework - * @package phpOMS/Views + * View Abstract. + * + * @package phpOMS\Views * @license OMS License 1.0 - * @link http://orange-management.com + * @link http://website.orange-management.de * @since 1.0.0 */ abstract class ViewAbstract implements \Serializable @@ -48,7 +46,7 @@ abstract class ViewAbstract implements \Serializable /** * Constructor. * - * @since 1.0.0| header 1 | +header 2 | +header 2 | +
|---|---|---|
| cell 1.1 | +cell 1.2 | +cell 1.3 | +
| cell 2.1 | +cell 2.2 | +cell 2.3 | +
####### not a heading
+#
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/atx_heading.md b/tests/Utils/Parser/Markdown/data/atx_heading.md new file mode 100644 index 000000000..ad97b44ca --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/atx_heading.md @@ -0,0 +1,17 @@ +# h1 + +## h2 + +### h3 + +#### h4 + +##### h5 + +###### h6 + +####### not a heading + +# closed h1 # + +# \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/automatic_link.html b/tests/Utils/Parser/Markdown/data/automatic_link.html new file mode 100644 index 000000000..50a94ba0f --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/automatic_link.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/automatic_link.md b/tests/Utils/Parser/Markdown/data/automatic_link.md new file mode 100644 index 000000000..08d3bf46a --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/automatic_link.md @@ -0,0 +1 @@ +<?php
+
+$message = 'Hello World!';
+echo $message;
+> not a quote
+- not a list item
+[not a reference]: http://foo.com
\ No newline at end of file
diff --git a/tests/Utils/Parser/Markdown/data/code_block.md b/tests/Utils/Parser/Markdown/data/code_block.md
new file mode 100644
index 000000000..2cfc953cc
--- /dev/null
+++ b/tests/Utils/Parser/Markdown/data/code_block.md
@@ -0,0 +1,10 @@
+ not a quote
+ - not a list item
+ [not a reference]: http://foo.com
\ No newline at end of file
diff --git a/tests/Utils/Parser/Markdown/data/code_span.html b/tests/Utils/Parser/Markdown/data/code_span.html
new file mode 100644
index 000000000..5c4c231e3
--- /dev/null
+++ b/tests/Utils/Parser/Markdown/data/code_span.html
@@ -0,0 +1,6 @@
+a code span
this is also a codespan trailing text
and look at this one!
single backtick in a code span: `
backtick-delimited string in a code span: `foo`
sth `` sth
+\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/compound_blockquote.md b/tests/Utils/Parser/Markdown/data/compound_blockquote.md new file mode 100644 index 000000000..80c4aed16 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/compound_blockquote.md @@ -0,0 +1,10 @@ +> header +> ------ +> +> paragraph +> +> - li +> +> --- +> +> paragraph \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/compound_emphasis.html b/tests/Utils/Parser/Markdown/data/compound_emphasis.html new file mode 100644 index 000000000..178dd54ba --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/compound_emphasis.html @@ -0,0 +1,2 @@ +header
+paragraph
++
+- li
+
+paragraph
+
code code
codecodecode
paragraph
+paragraph
+paragraph
+++quote
+
em strong
+em strong strong
+strong em strong
+strong em strong strong
+em strong
+em strong strong
+strong em strong
+strong em strong strong
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/em_strong.md b/tests/Utils/Parser/Markdown/data/em_strong.md new file mode 100644 index 000000000..9abeb3fd4 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/em_strong.md @@ -0,0 +1,15 @@ +___em strong___ + +___em strong_ strong__ + +__strong _em strong___ + +__strong _em strong_ strong__ + +***em strong*** + +***em strong* strong** + +**strong *em strong*** + +**strong *em strong* strong** \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/email.html b/tests/Utils/Parser/Markdown/data/email.html new file mode 100644 index 000000000..c40759c96 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/email.html @@ -0,0 +1 @@ +my email is me@example.com
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/email.md b/tests/Utils/Parser/Markdown/data/email.md new file mode 100644 index 000000000..26b7b6cc5 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/email.md @@ -0,0 +1 @@ +my email isunderscore, asterisk, one two, three four, a, b
+strong and em and strong and em
+line +line +line
+this_is_not_an_emphasis
+an empty emphasis __ ** is not an emphasis
+*mixed *double and single asterisk** spans
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/emphasis.md b/tests/Utils/Parser/Markdown/data/emphasis.md new file mode 100644 index 000000000..85b9d2299 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/emphasis.md @@ -0,0 +1,13 @@ +_underscore_, *asterisk*, _one two_, *three four*, _a_, *b* + +**strong** and *em* and **strong** and *em* + +_line +line +line_ + +this_is_not_an_emphasis + +an empty emphasis __ ** is not an emphasis + +*mixed **double and* single asterisk** spans \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/escaping.html b/tests/Utils/Parser/Markdown/data/escaping.html new file mode 100644 index 000000000..ab1c41fdc --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/escaping.html @@ -0,0 +1,6 @@ +escaped *emphasis*.
+escaped \*emphasis\* in a code span
escaped \*emphasis\* in a code block
+\ ` * _ { } [ ] ( ) > # + - . !
+one_two one_two
+one*two one*two
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/escaping.md b/tests/Utils/Parser/Markdown/data/escaping.md new file mode 100644 index 000000000..9f174e98c --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/escaping.md @@ -0,0 +1,11 @@ +escaped \*emphasis\*. + +`escaped \*emphasis\* in a code span` + + escaped \*emphasis\* in a code block + +\\ \` \* \_ \{ \} \[ \] \( \) \> \# \+ \- \. \! + +_one\_two_ __one\_two__ + +*one\*two* **one\*two** \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/fenced_code_block.html b/tests/Utils/Parser/Markdown/data/fenced_code_block.html new file mode 100644 index 000000000..8bdabba96 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/fenced_code_block.html @@ -0,0 +1,6 @@ +<?php
+
+$message = 'fenced code block';
+echo $message;
+tilde
+echo 'language identifier';
\ No newline at end of file
diff --git a/tests/Utils/Parser/Markdown/data/fenced_code_block.md b/tests/Utils/Parser/Markdown/data/fenced_code_block.md
new file mode 100644
index 000000000..cbed8ebb5
--- /dev/null
+++ b/tests/Utils/Parser/Markdown/data/fenced_code_block.md
@@ -0,0 +1,14 @@
+```
+
+
![missing reference]
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/image_reference.md b/tests/Utils/Parser/Markdown/data/image_reference.md new file mode 100644 index 000000000..1e11d9479 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/image_reference.md @@ -0,0 +1,5 @@ +![Markdown Logo][image] + +[image]: /md.png + +![missing reference] \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/image_title.html b/tests/Utils/Parser/Markdown/data/image_title.html new file mode 100644 index 000000000..957c9505c --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/image_title.html @@ -0,0 +1,2 @@ +

an implicit reference link
+an implicit reference link with an empty link definition
+an implicit reference link followed by another
+an explicit reference link with a title
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/implicit_reference.md b/tests/Utils/Parser/Markdown/data/implicit_reference.md new file mode 100644 index 000000000..f850df964 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/implicit_reference.md @@ -0,0 +1,13 @@ +an [implicit] reference link + +[implicit]: http://example.com + +an [implicit][] reference link with an empty link definition + +an [implicit][] reference link followed by [another][] + +[another]: http://cnn.com + +an [explicit][example] reference link with a title + +[example]: http://example.com "Example" \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_link.html b/tests/Utils/Parser/Markdown/data/inline_link.html new file mode 100644 index 000000000..5ad564aa3 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_link.html @@ -0,0 +1,6 @@ + +link with parentheses in URL
+(link) in parentheses
+ + + \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_link.md b/tests/Utils/Parser/Markdown/data/inline_link.md new file mode 100644 index 000000000..6bac0b35e --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_link.md @@ -0,0 +1,11 @@ +[link](http://example.com) + +[link](/url-(parentheses)) with parentheses in URL + +([link](/index.php)) in parentheses + +[`link`](http://example.com) + +[](http://example.com) + +[ and text](http://example.com) \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_link_title.html b/tests/Utils/Parser/Markdown/data/inline_link_title.html new file mode 100644 index 000000000..ecdfd03da --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_link_title.html @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_link_title.md b/tests/Utils/Parser/Markdown/data/inline_link_title.md new file mode 100644 index 000000000..6e1c5af9b --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_link_title.md @@ -0,0 +1,11 @@ +[single quotes](http://example.com 'Title') + +[double quotes](http://example.com "Title") + +[single quotes blank](http://example.com '') + +[double quotes blank](http://example.com "") + +[space](http://example.com "2 Words") + +[parentheses](http://example.com/url-(parentheses) "Title") \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_title.html b/tests/Utils/Parser/Markdown/data/inline_title.html new file mode 100644 index 000000000..bbab93b6c --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_title.html @@ -0,0 +1 @@ +single quotes and double quotes
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/inline_title.md b/tests/Utils/Parser/Markdown/data/inline_title.md new file mode 100644 index 000000000..cb09344a1 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/inline_title.md @@ -0,0 +1 @@ +[single quotes](http://example.com 'Example') and [double quotes](http://example.com "Example") \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/lazy_blockquote.html b/tests/Utils/Parser/Markdown/data/lazy_blockquote.html new file mode 100644 index 000000000..0a2a2aaf9 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/lazy_blockquote.html @@ -0,0 +1,6 @@ ++\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/lazy_blockquote.md b/tests/Utils/Parser/Markdown/data/lazy_blockquote.md new file mode 100644 index 000000000..48f645f94 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/lazy_blockquote.md @@ -0,0 +1,5 @@ +> quote +the rest of it + +> another paragraph +the rest of it \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/lazy_list.html b/tests/Utils/Parser/Markdown/data/lazy_list.html new file mode 100644 index 000000000..1a5199249 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/lazy_list.html @@ -0,0 +1,4 @@ +quote +the rest of it
+another paragraph +the rest of it
+
line
+line
li
+line +line
+repeating numbers:
+large numbers:
+paragraph
+paragraph
+li
+double quotes and single quotes and parentheses
+[invalid title]: http://example.com example title
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/reference_title.md b/tests/Utils/Parser/Markdown/data/reference_title.md new file mode 100644 index 000000000..43cb21708 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/reference_title.md @@ -0,0 +1,6 @@ +[double quotes] and [single quotes] and [parentheses] + +[double quotes]: http://example.com "example title" +[single quotes]: http://example.com 'example title' +[parentheses]: http://example.com (example title) +[invalid title]: http://example.com example title \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/separated_nested_list.html b/tests/Utils/Parser/Markdown/data/separated_nested_list.html new file mode 100644 index 000000000..80a5cae26 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/separated_nested_list.html @@ -0,0 +1,9 @@ +li
+not a header
+++quote
+
indented:
+++quote
+
no space after >:
+\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/simple_blockquote.md b/tests/Utils/Parser/Markdown/data/simple_blockquote.md new file mode 100644 index 000000000..22b6b11a9 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/simple_blockquote.md @@ -0,0 +1,7 @@ +> quote + +indented: + > quote + +no space after `>`: +>quote \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/simple_table.html b/tests/Utils/Parser/Markdown/data/simple_table.html new file mode 100644 index 000000000..237d7efb3 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/simple_table.html @@ -0,0 +1,37 @@ +quote
+
| header 1 | +header 2 | +
|---|---|
| cell 1.1 | +cell 1.2 | +
| cell 2.1 | +cell 2.2 | +
| header 1 | +header 2 | +
|---|---|
| cell 1.1 | +cell 1.2 | +
| cell 2.1 | +cell 2.2 | +
li
+li
+li
+AT&T has an ampersand in their name
+this & that
+4 < 5 and 6 > 5
+http://example.com/autolink?a=1&b=2
+ + \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/special_characters.md b/tests/Utils/Parser/Markdown/data/special_characters.md new file mode 100644 index 000000000..111b03b63 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/special_characters.md @@ -0,0 +1,13 @@ +AT&T has an ampersand in their name + +this & that + +4 < 5 and 6 > 5 + +strikethrough
here's one followed by another one
~~ this ~~ is not one neither is ~this~
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/strikethrough.md b/tests/Utils/Parser/Markdown/data/strikethrough.md new file mode 100644 index 000000000..d169144d2 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/strikethrough.md @@ -0,0 +1,5 @@ +~~strikethrough~~ + +here's ~~one~~ followed by ~~another one~~ + +~~ this ~~ is not one neither is ~this~ \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/strong_em.html b/tests/Utils/Parser/Markdown/data/strong_em.html new file mode 100644 index 000000000..b709c9914 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/strong_em.html @@ -0,0 +1,6 @@ +em strong em
+strong em em
+em strong em em
+em strong em
+strong em em
+em strong em em
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/strong_em.md b/tests/Utils/Parser/Markdown/data/strong_em.md new file mode 100644 index 000000000..f2aa3c782 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/strong_em.md @@ -0,0 +1,11 @@ +*em **strong em*** + +***strong em** em* + +*em **strong em** em* + +_em __strong em___ + +___strong em__ em_ + +_em __strong em__ em_ \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/tab-indented_code_block.html b/tests/Utils/Parser/Markdown/data/tab-indented_code_block.html new file mode 100644 index 000000000..7c140de73 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/tab-indented_code_block.html @@ -0,0 +1,6 @@ +<?php
+
+$message = 'Hello World!';
+echo $message;
+
+echo "following a blank line";
\ No newline at end of file
diff --git a/tests/Utils/Parser/Markdown/data/tab-indented_code_block.md b/tests/Utils/Parser/Markdown/data/tab-indented_code_block.md
new file mode 100644
index 000000000..a405a1609
--- /dev/null
+++ b/tests/Utils/Parser/Markdown/data/tab-indented_code_block.md
@@ -0,0 +1,6 @@
+
+
+| 2.1\| 2.1one with a semantic name
+[one][404] with no definition
+multiline +one defined on 2 lines
+one with a mixed case label and an upper case definition
+one with the a label on the next line
+ \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/text_reference.md b/tests/Utils/Parser/Markdown/data/text_reference.md new file mode 100644 index 000000000..1a66a5cf6 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/text_reference.md @@ -0,0 +1,21 @@ +[reference link][1] + +[1]: http://example.com + +[one][website] with a semantic name + +[website]: http://example.com + +[one][404] with no definition + +[multiline +one][website] defined on 2 lines + +[one][Label] with a mixed case label and an upper case definition + +[LABEL]: http://example.com + +[one] +[1] with the a label on the next line + +[`link`][website] \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/unordered_list.html b/tests/Utils/Parser/Markdown/data/unordered_list.html new file mode 100644 index 000000000..cd95567b7 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/unordered_list.html @@ -0,0 +1,10 @@ +mixed markers:
+| header 1 | +header 2 | +
|---|---|
| cell 1.1 | +cell 1.2 | +
| cell 2.1 | +cell 2.2 | +
an autolink http://example.com
+inside of brackets [http://example.com], inside of braces {http://example.com}, inside of parentheses (http://example.com)
+trailing slash http://example.com/ and http://example.com/path/
\ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/url_autolinking.md b/tests/Utils/Parser/Markdown/data/url_autolinking.md new file mode 100644 index 000000000..840f35404 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/url_autolinking.md @@ -0,0 +1,5 @@ +an autolink http://example.com + +inside of brackets [http://example.com], inside of braces {http://example.com}, inside of parentheses (http://example.com) + +trailing slash http://example.com/ and http://example.com/path/ \ No newline at end of file diff --git a/tests/Utils/Parser/Markdown/data/whitespace.html b/tests/Utils/Parser/Markdown/data/whitespace.html new file mode 100644 index 000000000..f2dd7a002 --- /dev/null +++ b/tests/Utils/Parser/Markdown/data/whitespace.html @@ -0,0 +1 @@ +code
\ No newline at end of file
diff --git a/tests/Utils/Parser/Markdown/data/whitespace.md b/tests/Utils/Parser/Markdown/data/whitespace.md
new file mode 100644
index 000000000..4cf926a8a
--- /dev/null
+++ b/tests/Utils/Parser/Markdown/data/whitespace.md
@@ -0,0 +1,5 @@
+
+
+ code
+
+
\ No newline at end of file
diff --git a/tests/Utils/Parser/Php/ArrayParserTest.php b/tests/Utils/Parser/Php/ArrayParserTest.php
new file mode 100644
index 000000000..255637ae1
--- /dev/null
+++ b/tests/Utils/Parser/Php/ArrayParserTest.php
@@ -0,0 +1,36 @@
+ 'test',
+ 0 => 1,
+ 2 => true,
+ 'string2' => 1.3,
+ 3 => null,
+ 4 => [
+ 0 => 'a',
+ 1 => 'b',
+ ],
+ ];
+
+ self::assertEquals($array, eval('return '. ArrayParser::serializeArray($array) . ';'));
+ }
+}
diff --git a/tests/Utils/PermutationTest.php b/tests/Utils/PermutationTest.php
new file mode 100644
index 000000000..858aa3aa5
--- /dev/null
+++ b/tests/Utils/PermutationTest.php
@@ -0,0 +1,63 @@
+setTimestamp($min);
+ $dateMax->setTimestamp($max);
+
+ $rng = DateTime::generateDateTime($dateMin, $dateMax);
+
+ self::assertTrue($rng->getTimestamp() >= $min && $rng->getTimestamp() <= $max);
+ }
+ }
+}
diff --git a/tests/Utils/RnG/DistributionTypeTest.php b/tests/Utils/RnG/DistributionTypeTest.php
new file mode 100644
index 000000000..2e963a23f
--- /dev/null
+++ b/tests/Utils/RnG/DistributionTypeTest.php
@@ -0,0 +1,28 @@
+ 4) {
+ self::assertEquals(1406932606, LinearCongruentialGenerator::bsd());
+ self::assertEquals(654583775, LinearCongruentialGenerator::bsd());
+ self::assertEquals(1449466924, LinearCongruentialGenerator::bsd());
+ }
+ }
+
+ public function testMsRng()
+ {
+ self::assertEquals(38, LinearCongruentialGenerator::msvcrt());
+ self::assertEquals(7719, LinearCongruentialGenerator::msvcrt());
+
+ if (PHP_INT_SIZE > 4) {
+ self::assertEquals(21238, LinearCongruentialGenerator::msvcrt());
+ self::assertEquals(2437, LinearCongruentialGenerator::msvcrt());
+ }
+ }
+}
diff --git a/tests/Utils/RnG/NameTest.php b/tests/Utils/RnG/NameTest.php
new file mode 100644
index 000000000..9fc1d6ebb
--- /dev/null
+++ b/tests/Utils/RnG/NameTest.php
@@ -0,0 +1,24 @@
+<|;"');
+
+ if (strlen($random) > 12 || strlen($random) < 5) {
+ $outOfBounds = true;
+ }
+
+ if (in_array($random, $haystack)) {
+ $randomness++;
+ }
+
+ $haystack[] = $random;
+ }
+
+ self::assertFalse($outOfBounds);
+ self::assertLessThan(5, $randomness);
+ }
+}
diff --git a/tests/Utils/RnG/TextTest.php b/tests/Utils/RnG/TextTest.php
new file mode 100644
index 000000000..74eabe403
--- /dev/null
+++ b/tests/Utils/RnG/TextTest.php
@@ -0,0 +1,24 @@
+matchDictionary('Cartoon'));
+ self::assertEquals('Bathtub Sidewalk Table', $dict->matchDictionary('Sidewalk Table'));
+
+ // todo: this doesn't match since the length is too far apart
+ //self::assertEquals('Snowflake Bathtub Snowflake Toothbrush Sidewalk', $dict->matchDictionary('Toothbrush'));
+
+ $dict->add('Carton');
+ self::assertEquals('Carton', $dict->matchDictionary('carton'));
+ }
+}
diff --git a/tests/Utils/StringUtilsTest.php b/tests/Utils/StringUtilsTest.php
new file mode 100644
index 000000000..094696834
--- /dev/null
+++ b/tests/Utils/StringUtilsTest.php
@@ -0,0 +1,82 @@
+class = new class('') extends TaskAbstract {
+ public static function createWith(array $jobData) : TaskAbstract
+ {
+
+ }
+ };
+ }
+
+ public function testDefault()
+ {
+ self::assertEquals('', $this->class->getId());
+ self::assertEquals('', $this->class->getCommand());
+ self::assertEquals('', $this->class->getRun());
+ self::assertEquals('', $this->class->getStatus());
+ self::assertInstanceOf('\DateTime', $this->class->getNextRunTime());
+ self::assertInstanceOf('\DateTime', $this->class->getLastRuntime());
+ self::assertEquals('', $this->class->getComment());
+ }
+
+ public function testGetSet()
+ {
+ $this->class->setCommand('Command');
+ self::assertEquals('Command', $this->class->getCommand());
+
+ $this->class->setRun('Run');
+ self::assertEquals('Run', $this->class->getRun());
+
+ $this->class->setStatus('Status');
+ self::assertEquals('Status', $this->class->getStatus());
+
+ $this->class->setComment('Comment');
+ self::assertEquals('Comment', $this->class->getComment());
+
+ $date = new \DateTime('now');
+ $this->class->setLastRuntime($date);
+ self::assertEquals($date->format('Y-m-d'), $this->class->getLastRuntime()->format('Y-m-d'));
+
+ $this->class->setNextRuntime($date);
+ self::assertEquals($date->format('Y-m-d'), $this->class->getNextRuntime()->format('Y-m-d'));
+ }
+}
diff --git a/tests/Utils/TaskSchedule/TaskFactoryTest.php b/tests/Utils/TaskSchedule/TaskFactoryTest.php
new file mode 100644
index 000000000..af48c6e88
--- /dev/null
+++ b/tests/Utils/TaskSchedule/TaskFactoryTest.php
@@ -0,0 +1,26 @@
+dbPool = new DatabasePool();
+ /** @var array $CONFIG */
+ $this->dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']);
+
+ $this->app = new class extends ApplicationAbstract
+ {
+ };
+
+ $this->app->l11nManager = new L11nManager();
+ $this->app->dbPool = $this->dbPool;
+ }
+
+ public function testDefault()
+ {
+ $view = new View($this->app, new Request(new Http('')), new Response(new Localization()));
+
+ self::assertEmpty($view->getTemplate());
+ self::assertEmpty($view->getViews());
+ self::assertTrue(is_array($view->getViews()));
+ self::assertFalse($view->getView(0));
+ self::assertFalse($view->removeView(0));
+ self::assertNull($view->getData(0));
+ self::assertFalse($view->removeData(0));
+ self::assertEmpty($view->toArray());
+ }
+
+ public function testGetText()
+ {
+ $view = new View($this->app, $request = new Request(new Http('')), $response = new Response(new Localization()));
+ $view->setTemplate('/Modules/Admin/Theme/Backend/accounts-list');
+
+ $expected = [
+ 'en' => [
+ 'Admin' => [
+ 'Test' => 'Test'
+ ]
+ ]
+ ];
+
+ $this->app->l11nManager = new L11nManager();
+ $this->app->l11nManager->loadLanguage('en', 'Admin', $expected['en']);
+
+ self::assertEquals('Test', $view->getText('Test'));
+ self::assertEquals('<a href="test">Test</a>', $view->getHtml('Test'));
+ }
+
+ public function testGetSet()
+ {
+ $view = new View($this->app, $request = new Request(new Http('')), $response = new Response(new Localization()));
+
+ $view->setData('key', 'value');
+ self::assertEquals('value', $view->getData('key'));
+
+ self::assertTrue($view->addData('key2', 'valu2'));
+ self::assertFalse($view->addData('key2', 'valu3'));
+ self::assertEquals('valu2', $view->getData('key2'));
+
+ self::assertTrue($view->removeData('key2'));
+ self::assertFalse($view->removeData('key3'));
+
+ self::assertEquals($request, $view->getRequest());
+ self::assertEquals($response, $view->getResponse());
+
+ self::assertEquals('<a href="test">Test</a>', $view->printHtml('Test'));
+
+ $tView = new View($this->app, $request, $response);
+ self::assertTrue($view->addView('test', $tView));
+ self::assertEquals($tView, $view->getView('test'));
+ self::assertEquals(1, count($view->getViews()));
+ self::assertTrue($view->removeView('test'));
+ self::assertFalse($view->removeView('test'));
+ self::assertFalse($view->getView('test'));
+ }
+
+ public function testRender()
+ {
+ $view = new View($this->app, new Request(), new Response(new Localization()));
+
+ $view->setTemplate('/phpOMS/tests/Views/testTemplate');
+ self::assertEquals('Test', $view->render());
+
+ // todo: why is this failing?
+ //$view->setTemplate('phpOMS/tests/Views/testArray');
+ //self::assertEquals([1, 2, 3], $view->render());
+ }
+
+ /**
+ * @expectedException \phpOMS\System\File\PathException
+ */
+ public function testRenderException()
+ {
+ $view = new View($this->app, new Request(new Http('')), new Response(new Localization()));
+ $view->setTemplate('something.txt');
+
+ $view->render();
+ }
+
+ /**
+ * @expectedException \phpOMS\System\File\PathException
+ */
+ public function testSerializeException()
+ {
+ $view = new View($this->app, new Request(new Http('')), new Response(new Localization()));
+ $view->setTemplate('something.txt');
+
+ $view->serialize();
+ }
+}
diff --git a/tests/Views/testArray.tpl.php b/tests/Views/testArray.tpl.php
new file mode 100644
index 000000000..92dd15faa
--- /dev/null
+++ b/tests/Views/testArray.tpl.php
@@ -0,0 +1 @@
+Test
\ No newline at end of file