Merge pull request #155 from Orange-Management/develop

code style fixes
This commit is contained in:
Dennis Eichhorn 2018-02-03 14:56:19 +01:00 committed by GitHub
commit 4bb778faf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1317 changed files with 26307 additions and 14016 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.log

View File

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

View File

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

View File

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

View File

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

View File

@ -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
*/

View File

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

View File

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

View File

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

View File

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

View File

@ -1,32 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Algorithm;
use phpOMS\Stdlib\Base\Enum;
/**
* Task status enum.
*
* @category Tasks
* @package Modules
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class AlgorithmType extends Enum
{
/* public */ const BRUTEFORCE = 0;
}

View File

@ -1,89 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Algorithm\Knappsack;
use phpOMS\Algorithm\AlgorithmType;
/**
* Knappsack algorithm implementations
*
* @category Framework
* @package phpOMS\Auth
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Backpack
{
private $costMaximum = 0;
private $value = 0;
private $cost = 0;
private $items = [];
private $population = [];
public function __construct(float $costMaximum)
{
$this->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()
{
}
}

View File

@ -1,30 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\Algorithm\Knappsack;
/**
* Shape interface.
*
* @category Framework
* @package phpOMS\Math
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface ItemInterface
{
}

View File

@ -4,24 +4,40 @@
*
* 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;
/**
* Application class.
*
* This class contains all necessary application members. Access to them
* is restricted to write once in order to prevent manipulation
* and afterwards read only.
*
* @category Framework
* @package Framework
* @property mixed orgId
* @property string appName
* @property \phpOMS\DataStorage\Database\DatabasePool dbPool
* @property \phpOMS\Localization\L11nManager l11nManager
* @property \phpOMS\Router\Router router
* @property \phpOMS\DataStorage\Session\SessionInterface sessionManager
* @property \phpOMS\Module\ModuleManager moduleManager
* @property \phpOMS\Dispatcher\Dispatcher dispatcher
* @property \phpOMS\DataStorage\Cache\CachePool cachePool
* @property \Model\CoreSettings appSettings
* @property \phpOMS\Event\EventManager eventManager
* @property \phpOMS\Account\AccountManager accountManager
* @property \phpOMS\Log\FileLogger logger
*
* @package phpOMS
* @license OMS License 1.0
* @link http://orange-management.com
* @link http://website.orange-management.de
* @since 1.0.0
*/
class ApplicationAbstract
@ -143,9 +159,9 @@ class ApplicationAbstract
*
* @since 1.0.0
*/
public function __set($name, $value)
public function __set($name, $value)
{
if(!empty($this->$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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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
*/

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,33 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package Framework
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
use phpOMS\Stdlib\Base\Enum;
/**
* Smoothing enum.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
abstract class ErrorType extends Enum
{
/* public */ const ALL = 0;
/* public */ const NONE = 1;
/* public */ const ADDITIVE = 2;
/* public */ const MULTIPLICATIVE = 4;
}

View File

@ -4,14 +4,14 @@
*
* 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
* @see https://www.otexts.org/fpp/7/7
*/
declare(strict_types=1);
declare(strict_types = 1);
namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
@ -35,588 +35,78 @@ class ExponentialSmoothing
public function __construct(array $data)
{
$this->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;
}
}
public function getMMA()
{
}
public function getMMM()
{
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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()
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,176 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types = 1);
namespace phpOMS\DataStorage\Cache;
/**
* Memcache class.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class MemCached implements CacheInterface
{
/**
* Memcache instance.
*
* @var \Memcache
* @since 1.0.0
*/
private $memc = null;
/**
* Only cache if data is larger than threshold (0-100).
*
* @var int
* @since 1.0.0
*/
private $threshold = 10;
private $status;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->memc = null;
}
/**
* Adding server to server pool.
*
* @param mixed $data Server data array
*
* @return void
*
* @since 1.0.0
*/
public function addServer($data)
{
$this->memc->addServer($data['host'], $data['port'], $data['timeout']);
}
/**
* {@inheritdoc}
*/
public function set($key, $value, int $expire = -1) /* : void */
{
$this->memc->set($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function add($key, $value, int $expire = -1) : bool
{
return $this->memc->add($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function get($key, int $expire = -1)
{
return $this->memc->get($key);
}
/**
* {@inheritdoc}
*/
public function delete($key, int $expire = -1) : bool
{
$this->memc->delete($key);
}
/**
* {@inheritdoc}
*/
public function flush(int $expire = 0) : bool
{
$this->memc->flush();
return true;
}
/**
* {@inheritdoc}
*/
public function flushAll() : bool
{
$this->memc->flush();
return true;
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, int $expire = -1) : bool
{
$this->memc->replace($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
/** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
return $this->memc->getExtendedStats();
}
/**
* {@inheritdoc}
*/
public function getThreshold() : int
{
return $this->threshold;
}
/**
* {@inheritdoc}
*/
public function setStatus(int $status) /* : void */
{
$this->status = $status;
}
/**
* Destructor.
*
* @since 1.0.0
*/
public function __destruct()
{
$this->close();
}
/**
* Closing cache.
*
* @since 1.0.0
*/
public function close()
{
if ($this->memc !== null) {
$this->memc->close();
$this->memc = null;
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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.
*

View File

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

View File

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

View File

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

View File

@ -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'] = '****';
}
}
}

View File

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

View File

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

View File

@ -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'] = '****';
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,437 +0,0 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
declare(strict_types=1);
namespace phpOMS\DataStorage\Database;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
/**
* Datamapper for databases.
*
* DB, Cache, Session
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class DataMapperBaseAbstract
{
/**
* Database connection.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
protected static $db = null;
/**
* Overwriting extended values.
*
* @var bool
* @since 1.0.0
*/
protected static $overwrite = true;
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = '';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = '';
/**
* Language
*
* @var string
* @since 1.0.0
*/
protected static $language_field = '';
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
protected static $columns = [];
/**
* Relations.
*
* Relation is defined in a relation table
*
* @var string[]
* @since 1.0.0
*/
protected static $hasMany = [];
/**
* Relations.
*
* Relation is defined in the model
*
* @var string[]
* @since 1.0.0
*/
protected static $hasOne = [];
/**
* Relations.
*
* Relation is defined in current mapper
*
* @var string[]
* @since 1.0.0
*/
protected static $ownsOne = [];
/**
* Relations.
*
* Relation is defined in current mapper
*
* @var string[]
* @since 1.0.0
*/
protected static $belongsTo = [];
/**
* Table.
*
* @var string
* @since 1.0.0
*/
protected static $table = '';
/**
* Fields to load.
*
* @var array[]
* @since 1.0.0
*/
protected static $fields = [];
/**
* Initialized objects for cross reference to reduce initialization costs
*
* @var array[]
* @since 1.0.0
*/
protected static $initObjects = [];
/**
* Highest mapper to know when to clear initialized objects
*
* @var DataMapperAbstract
* @since 1.0.0
*/
protected static $parentMapper = null;
/**
* Extended value collection.
*
* @var array
* @since 1.0.0
*/
protected static $collection = [
'primaryField' => [],
'createdAt' => [],
'columns' => [],
'hasMany' => [],
'hasOne' => [],
'ownsOne' => [],
'table' => [],
];
/**
* Constructor.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function __construct()
{
}
/**
* Clone.
*
* @return void
*
* @since 1.0.0
* @codeCoverageIgnore
*/
private function __clone()
{
}
/**
* Set database connection.
*
* @param ConnectionAbstract $con Database connection
*
* @return void
*
* @since 1.0.0
*/
public static function setConnection(ConnectionAbstract $con) /* : void */
{
self::$db = $con;
}
/**
* Get primary field.
*
* @return string
*
* @since 1.0.0
*/
public static function getPrimaryField() : string
{
return static::$primaryField;
}
/**
* Get main table.
*
* @return string
*
* @since 1.0.0
*/
public static function getTable() : string
{
return static::$table;
}
/**
* Collect values from extension.
*
* @param mixed $class Current extended mapper
*
* @return void
*
* @since 1.0.0
*/
private static function extend($class) /* : void */
{
/* todo: have to implement this in the queries, so far not used */
self::$collection['primaryField'][] = $class::$primaryField;
self::$collection['createdAt'][] = $class::$createdAt;
self::$collection['columns'][] = $class::$columns;
self::$collection['hasMany'][] = $class::$hasMany;
self::$collection['hasOne'][] = $class::$hasOne;
self::$collection['ownsOne'][] = $class::$ownsOne;
self::$collection['table'][] = $class::$table;
if (($parent = get_parent_class($class)) !== false && !$class::$overwrite) {
self::extend($parent);
}
}
/**
* Resets all loaded mapper variables.
*
* This is used after one action is performed otherwise other models would use wrong settings.
*
* @return void
*
* @since 1.0.0
*/
public static function clear() /* : void */
{
self::$overwrite = true;
self::$primaryField = '';
self::$createdAt = '';
self::$columns = [];
self::$hasMany = [];
self::$hasOne = [];
self::$ownsOne = [];
self::$table = '';
self::$fields = [];
self::$collection = [
'primaryField' => [],
'createdAt' => [],
'columns' => [],
'hasOne' => [],
'ownsMany' => [],
'ownsOne' => [],
'table' => [],
];
// clear parent and objects
if(static::class === self::$parentMapper) {
self::$initObjects = [];
self::$parentMapper = null;
}
}
/**
* Get created at column
*
* @return string
*
* @since 1.0.0
*/
public static function getCreatedAt() : string
{
return static::$createdAt;
}
/**
* Get id of object
*
* @param Object $obj Model to create
* @param \ReflectionClass $reflectionClass Reflection class
*
* @return mixed
*
* @since 1.0.0
*/
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null)
{
$reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj));
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
if (!($isPublic = $reflectionProperty->isPublic())) {
$reflectionProperty->setAccessible(true);
}
$objectId = $reflectionProperty->getValue($obj);
if (!$isPublic) {
$reflectionProperty->setAccessible(false);
}
return $objectId;
}
/**
* Set id to model
*
* @param \ReflectionClass $reflectionClass Reflection class
* @param Object $obj Object to create
* @param mixed $objId Id to set
*
* @return void
*
* @since 1.0.0
*/
private static function setObjectId(\ReflectionClass $reflectionClass, $obj, $objId) /* : void */
{
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
if (!($isPublic = $reflectionProperty->isPublic())) {
$reflectionProperty->setAccessible(true);
}
settype($objId, static::$columns[static::$primaryField]['type']);
$reflectionProperty->setValue($obj, $objId);
if (!$isPublic) {
$reflectionProperty->setAccessible(false);
}
}
/**
* Parse value
*
* @param string $type Value type
* @param mixed $value Value to parse
*
* @return mixed
*
* @since 1.0.0
*/
private static function parseValue(string $type, $value)
{
if (is_null($value)) {
return null;
} elseif ($type === 'DateTime') {
return $value->format('Y-m-d H:i:s');
} elseif ($type === 'Json' || $type === 'jsonSerializable') {
return json_encode($value);
} elseif ($type === 'Serializable') {
return $value->serialize();
} elseif ($value instanceof \JsonSerializable) {
return json_encode($value->jsonSerialize());
} elseif (is_object($value) && method_exists($value, 'getId')) {
return $value->getId();
} elseif ($type === 'int') {
return (int) $value;
} elseif ($type === 'string') {
return (string) $value;
} elseif ($type === 'float') {
return (float) $value;
} elseif ($type === 'bool') {
return (bool) $value;
}
return $value;
}
/**
* Get mapper specific builder
*
* @param Builder $query Query to fill
*
* @return Builder
*
* @since 1.0.0
*/
public static function getQuery(Builder $query = null) : Builder
{
$query = $query ?? new Builder(self::$db);
$query->prefix(self::$db->getPrefix())
->select('*')
->from(static::$table);
return $query;
}
/**
* Define the highest mapper of this request
*
* @return void
*
* @since 1.0.0
*/
private static function setUpParentMapper() /* : void */
{
self::$parentMapper = static::class;
}
private static function getColumnByMember(string $name) : string
{
foreach(static::$columns as $cName => $column) {
if($column['internal'] === $name) {
return $cName;
}
}
throw \Exception();
}
}

View File

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

View File

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

View File

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

View File

@ -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 */
}

View File

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

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @package TBD
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://website.orange-management.de
*/
declare(strict_types = 1);
namespace phpOMS\DataStorage\Database\Exception;
/**
* Permission exception class.
*
* @package Framework
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0
*/
class InvalidDatabaseTypeException extends \InvalidArgumentException
{
/**
* Constructor.
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{
parent::__construct('Invalid database type "' . $message . '".', $code, $previous);
}
}

View File

@ -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 InvalidMapperException extends \RuntimeException
@ -31,13 +29,13 @@ class InvalidMapperException extends \RuntimeException
*
* @param string $message Exception message
* @param int $code Exception code
* @param \Exception Previous exception
* @param \Exception $previous Previous exception
*
* @since 1.0.0
*/
public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{
if($message === '') {
if ($message === '') {
parent::__construct('Empty mapper.', $code, $previous);
} else {
parent::__construct('Mapper "' . $message . '" is invalid.', $code, $previous);

View File

@ -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;
/**
* 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
*/
abstract class GrammarAbstract
@ -170,7 +168,7 @@ abstract class GrammarAbstract
foreach ($elements as $key => $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;
}
}

View File

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

View File

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

View File

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

View File

@ -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 . ', ';
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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
*/

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More