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 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -26,10 +25,9 @@ use phpOMS\Validation\Network\Email;
* The account class is the base model for accounts. This model contains the most common account * 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. * information. This model is not comparable to a profile which contains much more information.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Account implements ArrayableInterface, \JsonSerializable class Account implements ArrayableInterface, \JsonSerializable
@ -136,7 +134,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/** /**
* Account type. * Account type.
* *
* @var AccountType|int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $type = AccountType::USER; protected $type = AccountType::USER;
@ -144,7 +142,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/** /**
* Account status. * Account status.
* *
* @var AccountStatus|int * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $status = AccountStatus::INACTIVE; protected $status = AccountStatus::INACTIVE;
@ -168,10 +166,10 @@ class Account implements ArrayableInterface, \JsonSerializable
*/ */
public function __construct(int $id = 0) public function __construct(int $id = 0)
{ {
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');
$this->lastActive = new \DateTime('now'); $this->lastActive = new \DateTime('now');
$this->id = $id; $this->id = $id;
$this->l11n = new NullLocalization(); $this->l11n = new NullLocalization();
} }
/** /**
@ -324,14 +322,15 @@ class Account implements ArrayableInterface, \JsonSerializable
{ {
$app = isset($app) ? strtolower($app) : $app; $app = isset($app) ? strtolower($app) : $app;
foreach($this->permissions as $p) { foreach ($this->permissions as $p) {
if(($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit)) if (($p->getUnit() === $unit || $p->getUnit() === null || !isset($unit))
&& ($p->getApp() === $app || $p->getApp() === null || !isset($app)) && ($p->getApp() === $app || $p->getApp() === null || !isset($app))
&& ($p->getModule() === $module || $p->getModule() === null || !isset($module)) && ($p->getModule() === $module || $p->getModule() === null || !isset($module))
&& ($p->getType() === $type || $p->getType() === null || !isset($type)) && ($p->getType() === $type || $p->getType() === null || !isset($type))
&& ($p->getElement() === $element || $p->getElement() === null || !isset($element)) && ($p->getElement() === $element || $p->getElement() === null || !isset($element))
&& ($p->getComponent() === $component || $p->getComponent() === null || !isset($component)) && ($p->getComponent() === $component || $p->getComponent() === null || !isset($component))
&& ($p->getPermission() | $permission) === $p->getPermission()) { && ($p->getPermission() | $permission) === $p->getPermission()
) {
return true; return true;
} }
} }
@ -556,11 +555,17 @@ class Account implements ArrayableInterface, \JsonSerializable
* *
* @return void * @return void
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function generatePassword(string $password) /* : void */ public function generatePassword(string $password) /* : void */
{ {
$this->password = password_hash($password, PASSWORD_DEFAULT); $this->password = \password_hash($password, \PASSWORD_DEFAULT);
if ($this->password === false) {
throw new \Exception();
}
} }
/** /**
@ -625,7 +630,7 @@ class Account implements ArrayableInterface, \JsonSerializable
/** /**
* Json serialize. * Json serialize.
* *
* @return string * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -633,5 +638,4 @@ class Account implements ArrayableInterface, \JsonSerializable
{ {
return $this->toArray(); return $this->toArray();
} }
} }

View File

@ -4,19 +4,17 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
use phpOMS\Auth\Auth; use phpOMS\Auth\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface; use phpOMS\DataStorage\Session\SessionInterface;
/** /**
@ -24,10 +22,9 @@ use phpOMS\DataStorage\Session\SessionInterface;
* *
* The account manager is used to manage multiple accounts. * The account manager is used to manage multiple accounts.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class AccountManager implements \Countable class AccountManager implements \Countable
@ -49,14 +46,6 @@ class AccountManager implements \Countable
*/ */
private $session = null; private $session = null;
/**
* Authenticator.
*
* @var Auth
* @since 1.0.0
*/
private $auth = null;
/** /**
* Constructor. * Constructor.
* *
@ -66,8 +55,7 @@ class AccountManager implements \Countable
*/ */
public function __construct(SessionInterface $session) public function __construct(SessionInterface $session)
{ {
$this->session = $session; $this->session = $session;
$this->auth = new Auth($this->session);
} }
/** /**
@ -82,7 +70,7 @@ class AccountManager implements \Countable
public function get(int $id = 0) : Account public function get(int $id = 0) : Account
{ {
if ($id === 0) { if ($id === 0) {
$account = new Account($this->auth->authenticate()); $account = new Account(Auth::authenticate($this->session));
if (!isset($this->accounts[$account->getId()])) { if (!isset($this->accounts[$account->getId()])) {
$this->accounts[$account->getId()] = $account; $this->accounts[$account->getId()] = $account;
@ -94,18 +82,6 @@ class AccountManager implements \Countable
return $this->accounts[$id] ?? new NullAccount(); return $this->accounts[$id] ?? new NullAccount();
} }
/**
* Returns the authentication manager
*
* @return Auth
*
* @since 1.0.0
*/
public function getAuth() : Auth
{
return $this->auth;
}
/** /**
* Add account. * Add account.
* *
@ -157,5 +133,4 @@ class AccountManager implements \Countable
{ {
return count($this->accounts); return count($this->accounts);
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Account status enum. * Account status enum.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class AccountStatus extends Enum abstract class AccountStatus extends Enum

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Account type enum. * Account type enum.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class AccountType extends Enum abstract class AccountType extends Enum

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -20,10 +19,9 @@ use phpOMS\Contract\ArrayableInterface;
/** /**
* Account group class. * Account group class.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Group implements ArrayableInterface, \JsonSerializable class Group implements ArrayableInterface, \JsonSerializable
@ -123,6 +121,8 @@ class Group implements ArrayableInterface, \JsonSerializable
* *
* @param string $name Group name * @param string $name Group name
* *
* @return void
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function setName(string $name) /* : void */ public function setName(string $name) /* : void */
@ -147,6 +147,8 @@ class Group implements ArrayableInterface, \JsonSerializable
* *
* @param string $description Group description * @param string $description Group description
* *
* @return void
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function setDescription(string $description) /* : void */ public function setDescription(string $description) /* : void */
@ -171,11 +173,18 @@ class Group implements ArrayableInterface, \JsonSerializable
* *
* @param int $status Group status * @param int $status Group status
* *
* @return void
*
* @throws InvalidEnumValue
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function setStatus(int $status) /* : void */ public function setStatus(int $status) /* : void */
{ {
// todo: check valid if (!GroupStatus::isValidValue($status)) {
throw new InvalidEnumValue($status);
}
$this->status = $status; $this->status = $status;
} }
@ -208,7 +217,7 @@ class Group implements ArrayableInterface, \JsonSerializable
/** /**
* Json serialize. * Json serialize.
* *
* @return string * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Accept status enum. * Accept status enum.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class GroupStatus extends Enum abstract class GroupStatus extends Enum

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
/** /**
* Null account class. * Null account class.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class NullAccount extends Account class NullAccount extends Account

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -21,10 +20,9 @@ namespace phpOMS\Account;
* This permission abstract is the basis for all permissions. Contrary to it's name it is not an * 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. * abstract class and can be used directly if needed.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class PermissionAbstract class PermissionAbstract
@ -340,7 +338,7 @@ class PermissionAbstract
* *
* @param int $permission Permission * @param int $permission Permission
* *
* @return void * @return bool
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Account
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Account;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Permission type enum. * Permission type enum.
* *
* @category Framework
* @package phpOMS\Account * @package phpOMS\Account
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class PermissionType extends Enum 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 * PHP Version 7.1
* *
* @category TBD * @package phpOMS
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 1.0.0
* @link http://orange-management.com * @link http://website.orange-management.de
*/ */
declare(strict_types=1); declare(strict_types = 1);
namespace phpOMS; namespace phpOMS;
/** /**
* Application class. * Application class.
* *
* @category Framework * This class contains all necessary application members. Access to them
* @package Framework * is restricted to write once in order to prevent manipulation
* and afterwards read only.
*
* @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 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class ApplicationAbstract class ApplicationAbstract
@ -145,7 +161,7 @@ class ApplicationAbstract
*/ */
public function __set($name, $value) public function __set($name, $value)
{ {
if(!empty($this->$name)) { if (!empty($this->$name)) {
return; return;
} }

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Asset
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Asset;
/** /**
* Asset manager class. * Asset manager class.
* *
* @category Framework
* @package phpOMS\Asset * @package phpOMS\Asset
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class AssetManager implements \Countable class AssetManager implements \Countable
@ -115,5 +113,4 @@ class AssetManager implements \Countable
{ {
return count($this->assets); return count($this->assets);
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Asset
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Asset;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Asset types enum. * Asset types enum.
* *
* @category Framework
* @package phpOMS\Asset * @package phpOMS\Asset
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class AssetType extends Enum abstract class AssetType extends Enum

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Auth
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Auth;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Session\SessionInterface; use phpOMS\DataStorage\Session\SessionInterface;
/** /**
@ -23,44 +21,35 @@ use phpOMS\DataStorage\Session\SessionInterface;
* *
* Responsible for authenticating and initializing the connection * Responsible for authenticating and initializing the connection
* *
* @category Framework
* @package phpOMS\Auth * @package phpOMS\Auth
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Auth class Auth
{ {
/**
* Session instance.
*
* @var SessionInterface
* @since 1.0.0
*/
private $session = null;
/** /**
* Constructor. * Constructor.
* *
* @param SessionInterface $session Session
*
* @since 1.0.0 * @since 1.0.0
* @codeCoverageIgnore
*/ */
public function __construct(SessionInterface $session) private function __construct()
{ {
$this->session = $session;
} }
/** /**
* Authenticates user. * Authenticates user.
* *
* @param SessionInterface $session Session
*
* @return int * @return int
* *
* @since 1.0.0 * @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; return empty($uid) ? 0 : $uid;
} }
@ -68,15 +57,14 @@ class Auth
/** /**
* Logout the given user. * Logout the given user.
* *
* @param int $uid User ID * @param SessionInterface $session Session
* *
* @return void * @return void
* *
* @since 1.0.0 * @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. $session->remove('UID');
$this->session->remove('UID');
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Auth
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Auth;
@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum;
* *
* These are possible answers to authentications. * These are possible answers to authentications.
* *
* @category Framework
* @package phpOMS\Auth * @package phpOMS\Auth
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class LoginReturnType extends Enum abstract class LoginReturnType extends Enum

View File

@ -4,24 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 1.0.0
* @link http://orange-management.com * @link http://website.orange-management.de
*/ */
declare(strict_types=1); declare(strict_types = 1);
namespace phpOMS; namespace phpOMS;
/** /**
* Permission exception class. * Autoloader exception
* *
* @category Framework * This exception is thrown if a file couldn't be autoloaded
* @package phpOMS\System\File *
* @package phpOMS
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class AutoloadException extends \RuntimeException class AutoloadException extends \RuntimeException
@ -31,7 +31,7 @@ class AutoloadException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -4,26 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 1.0.0
* @link http://orange-management.com * @link http://website.orange-management.de
*/ */
declare(strict_types=1); declare(strict_types = 1);
namespace phpOMS; namespace phpOMS;
spl_autoload_register('\phpOMS\Autoloader::default_autoloader'); spl_autoload_register('\phpOMS\Autoloader::defaultAutoloader');
/** /**
* Autoloader class. * Autoloader class.
* *
* @category Framework * @package phpOMS
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Autoloader class Autoloader
@ -34,7 +32,7 @@ class Autoloader
* *
* @param string $class Class path * @param string $class Class path
* *
* @example Autoloader::default_autoloader('\phpOMS\Autoloader') // void * @example Autoloader::defaultAutoloader('\phpOMS\Autoloader') // void
* *
* @return void * @return void
* *
@ -42,12 +40,12 @@ class Autoloader
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function default_autoloader(string $class) /* : void */ public static function defaultAutoloader(string $class) /* : void */
{ {
$class = ltrim($class, '\\'); $class = ltrim($class, '\\');
$class = str_replace(['_', '\\'], '/', $class); $class = str_replace(['_', '\\'], '/', $class);
if(!file_exists($path = __DIR__ . '/../' . $class . '.php')) { if (!file_exists($path = __DIR__ . '/../' . $class . '.php')) {
return; return;
} }
@ -73,5 +71,4 @@ class Autoloader
return file_exists(__DIR__ . '/../' . $class . '.php'); return file_exists(__DIR__ . '/../' . $class . '.php');
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Finance
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance;
@ -29,7 +28,7 @@ class Depreciation
public static function getArithmeticProgressivDepreciationRate(float $start, int $duration) : float 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 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 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 public static function getGeometicDegressivDepreciationInT(float $start, float $residual, int $duration, int $t) : float

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Finance
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance;
@ -21,11 +20,13 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException;
/** /**
* Finance class. * Finance class.
* *
* @category Log * @package phpOMS\Business\Finance
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/ */
class FinanceFormulas class FinanceFormulas
{ {
@ -44,7 +45,7 @@ class FinanceFormulas
*/ */
public static function getAnnualPercentageYield(float $r, int $n) : float 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 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); return $fva / ((pow(1 + $r, $n) - 1) / $r);
} }
/** /**
* Annuity - Future Value w/ Continuous Compounding * Annuity - Future Value w/ Continuous Compounding
* *
@ -754,6 +754,20 @@ class FinanceFormulas
return log(2) / log(1 + $r); return log(2) / log(1 + $r);
} }
/**
* Get rate to dobule
*
* @param float $t Time in which to double investment
*
* @return float
*
* @since 1.0.0
*/
public static function getDoublingRate(float $t) : float
{
return exp(log(2) / $t) - 1;
}
/** /**
* Doubling Time - Continuous Compounding * Doubling Time - Continuous Compounding
* *
@ -896,7 +910,7 @@ class FinanceFormulas
*/ */
public static function getFutureValueFactor(float $r, int $n) : float 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; return $ownSales / $competitorSales;
} }
} }

View File

@ -4,15 +4,14 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class AR class AR
{ {

View File

@ -4,15 +4,14 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class ARCH class ARCH
{ {

View File

@ -4,15 +4,14 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class ARFIMA class ARFIMA
{ {

View File

@ -4,26 +4,26 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
use phpOMS\Math\Statistic\Average; use phpOMS\Math\Statistic\Average;
class ARIMA class ARIMA
{ {
private $data = []; private $data = [];
private $order = 0; private $order = 0;
public function __construct(array $data, int $order = 12) public function __construct(array $data, int $order = 12)
{ {
$this->data = $data; $this->data = $data;
$this->order = $order; $this->order = $order;
if ($order !== 12 && $order !== 4) { if ($order !== 12 && $order !== 4) {

View File

@ -4,15 +4,14 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class ARMA class ARMA
{ {

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package Framework
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; 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. * This can be used to simplify time series patterns for forecasts.
* *
* @category Framework * @package Framework
* @package phpOMS\Math\Finance\Forecasting
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @see https://www.otexts.org/fpp/6/1 * @see https://www.otexts.org/fpp/6/1
* @since 1.0.0 * @since 1.0.0
*/ */
@ -174,7 +172,7 @@ class ClassicalDecomposition
*/ */
public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int
{ {
return ($dataSize - $trendCycleComponents) / 2; return (int) (($dataSize - $trendCycleComponents) / 2);
} }
/** /**

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 * PHP Version 7.1
* *
* @category TBD * @package Framework
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.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; namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
@ -35,588 +35,78 @@ class ExponentialSmoothing
public function __construct(array $data) 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 * PHP Version 7.1
* *
* @category TBD * @package Framework
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
@ -20,16 +19,15 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Smoothing enum. * Smoothing enum.
* *
* @category Framework * @package Framework
* @package phpOMS\Html
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class SeasonalType extends Enum abstract class SeasonalType extends Enum
{ {
/* public */ const ALL = 0; /* public */ const ALL = 0;
/* public */ const NONE = 1; /* public */ const NONE = 1;
/* public */ const ADDITIVE = 2; /* public */ const ADDITIVE = 2;
/* public */ const MULTIPLICATIVE = 4; /* public */ const MULTIPLICATIVE = 4;
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package Framework
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting\ExponentialSmoothing;
@ -20,16 +19,15 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Smoothing enum. * Smoothing enum.
* *
* @category Framework * @package Framework
* @package phpOMS\Html
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class TrendType extends Enum abstract class TrendType extends Enum
{ {
/* public */ const ALL = 0; /* public */ const ALL = 0;
/* public */ const NONE = 1; /* public */ const NONE = 1;
/* public */ const ADDITIVE = 2; /* public */ const ADDITIVE = 2;
/* public */ const MULTIPLICATIVE = 4; /* public */ const MULTIPLICATIVE = 4;
} }

View File

@ -4,15 +4,14 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class GARCH class GARCH
{ {

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class MA class MA
{ {
} }

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class NAR class NAR
{ {
} }

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class NMA class NMA
{ {
} }

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
class SARIMA class SARIMA
{ {
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance\Forecasting;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Smoothing enum. * Smoothing enum.
* *
* @category Framework * @package Framework
* @package phpOMS\Html
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class SmoothingType extends Enum abstract class SmoothingType extends Enum

View File

@ -4,25 +4,26 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Finance
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance;
/** /**
* Finance class. * Finance class.
* *
* @category Log * @package phpOMS\Business\Finance
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/ */
class Loan class Loan
{ {
@ -122,5 +123,4 @@ class Loan
{ {
return $loan / $collateral; return $loan / $collateral;
} }
} }

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Finance
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance;
/** /**
* Finance class. * Finance class.
* *
* @category Log * @package phpOMS\Business\Finance
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Lorenzkurve class Lorenzkurve

View File

@ -4,25 +4,26 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Finance
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Finance;
/** /**
* Finance class. * Finance class.
* *
* @category Log * @package phpOMS\Business\Finance
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/ */
class StockBonds class StockBonds
{ {
@ -368,7 +369,6 @@ class StockBonds
*/ */
public static function getZeroCouponBondEffectiveYield(float $F, float $PV, int $n) : float 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,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Marketing
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Marketing;
@ -20,16 +19,18 @@ namespace phpOMS\Business\Marketing;
* *
* This class provided basic marketing metric calculations * This class provided basic marketing metric calculations
* *
* @category Framework * @package phpOMS\Business\Marketing
* @package phpOMS\Business
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Metrics { class Metrics
{
/** /**
* Calculate customer retention * Calculate customer retention
* *
* @latex r = \frac{ce - cn}{cs}
*
* @param int $ce Customer at the end of the period * @param int $ce Customer at the end of the period
* @param int $cn New customers during period * @param int $cn New customers during period
* @param int $cs Customers at the start of the period * @param int $cs Customers at the start of the period

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Marketing
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Marketing;
@ -21,13 +20,13 @@ namespace phpOMS\Business\Marketing;
* 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. * Instead of customers the NPS can also be transferred to non-customers.
* *
* @category Framework * @package phpOMS\Business\Marketing
* @package phpOMS\Business
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class NetPromoterScore { class NetPromoterScore
{
/** /**
* Score values * Score values
* *
@ -41,7 +40,8 @@ class NetPromoterScore {
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct() { public function __construct()
{
} }
@ -72,10 +72,10 @@ class NetPromoterScore {
$passives = 0; $passives = 0;
$detractors = 0; $detractors = 0;
foreach($this->scores as $score) { foreach ($this->scores as $score) {
if($score > 8) { if ($score > 8) {
$promoters++; $promoters++;
} elseif($score > 6) { } elseif ($score > 6) {
$passives++; $passives++;
} else { } else {
$detractors++; $detractors++;
@ -99,8 +99,8 @@ class NetPromoterScore {
public function countDetractors() : int public function countDetractors() : int
{ {
$count = 0; $count = 0;
foreach($this->scores as $score) { foreach ($this->scores as $score) {
if($score < 7) { if ($score < 7) {
$count++; $count++;
} }
} }
@ -120,8 +120,8 @@ class NetPromoterScore {
public function countPassives() : int public function countPassives() : int
{ {
$count = 0; $count = 0;
foreach($this->scores as $score) { foreach ($this->scores as $score) {
if($score > 6 && $score < 9) { if ($score > 6 && $score < 9) {
$count++; $count++;
} }
} }
@ -141,8 +141,8 @@ class NetPromoterScore {
public function countPromoters() : int public function countPromoters() : int
{ {
$count = 0; $count = 0;
foreach($this->scores as $score) { foreach ($this->scores as $score) {
if($score > 8) { if ($score > 8) {
$count++; $count++;
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Programming
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Programming;
@ -20,13 +19,13 @@ namespace phpOMS\Business\Programming;
* *
* This class provides basic programming metric calculations. * This class provides basic programming metric calculations.
* *
* @category Framework * @package phpOMS\Business\Programming
* @package phpOMS\Business
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Metrics { class Metrics
{
/** /**
* Calculate ABC metric score * Calculate ABC metric score
* *
@ -42,21 +41,22 @@ class Metrics {
*/ */
public static function abcScore(int $a, int $b, int $c) : int 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 * Calculate the C.R.A.P score
* *
* @latex r = \sqrt{a^{2} + b^{2} + c^{2}} * @latex r = com^{2} \times (1 - cov)^{3} + com
* *
* @param int $a Assignments * @param int $complexity Complexity
* @param int $b Branches * @param float $coverage Coverage
* @param int $c Conditionals
* *
* @return int * @return int
* *
* @since 1.0.0 * @since 1.0.0
*
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/ */
public static function CRAP(int $complexity, float $coverage) : int public static function CRAP(int $complexity, float $coverage) : int
{ {

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Business\Sales
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Business\Sales;
@ -21,13 +20,13 @@ namespace phpOMS\Business\Sales;
* 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. * the rank based on a marketshare in a Zipf distributed market.
* *
* @category Framework * @package phpOMS\Business\Sales
* @package phpOMS\Business
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class MarketShareEstimation { class MarketShareEstimation
{
/** /**
* Calculate rank (r) based on market share (m) * Calculate rank (r) based on market share (m)
* *
@ -44,8 +43,8 @@ class MarketShareEstimation {
public static function getRankFromMarketShare(int $participants, float $marketShare, float $modifier = 1.0) : int public static function getRankFromMarketShare(int $participants, float $marketShare, float $modifier = 1.0) : int
{ {
$sum = 0.0; $sum = 0.0;
for($i = 0; $i < $participants; $i++) { for ($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i+1, $modifier); $sum += 1 / pow($i + 1, $modifier);
} }
return (int) round(pow(1 / ($marketShare * $sum), 1 / $modifier)); return (int) round(pow(1 / ($marketShare * $sum), 1 / $modifier));
@ -67,8 +66,8 @@ class MarketShareEstimation {
public static function getMarketShareFromRank(int $participants, int $rank, float $modifier = 1.0) : float public static function getMarketShareFromRank(int $participants, int $rank, float $modifier = 1.0) : float
{ {
$sum = 0.0; $sum = 0.0;
for($i = 0; $i < $participants; $i++) { for ($i = 0; $i < $participants; $i++) {
$sum += 1 / pow($i+1, $modifier); $sum += 1 / pow($i + 1, $modifier);
} }
return (1 / pow($rank, $modifier)) / $sum; return (1 / pow($rank, $modifier)) / $sum;

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Config
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Config;
/** /**
* Options class. * Options class.
* *
* @category Framework
* @package phpOMS\Config * @package phpOMS\Config
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface OptionsInterface interface OptionsInterface
@ -73,5 +71,4 @@ interface OptionsInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public function getOption($key); public function getOption($key);
} }

View File

@ -4,22 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Config
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Config;
/** /**
* Options trait. * Options trait.
* *
* @category Framework
* @package phpOMS\Config * @package phpOMS\Config
* @license OMS License 1.0
* @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
trait OptionsTrait trait OptionsTrait
@ -54,7 +54,7 @@ trait OptionsTrait
*/ */
public function setOption($key, $value, bool $overwrite = true) : bool 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; $this->options[$key] = $value;
return true; return true;
@ -76,5 +76,4 @@ trait OptionsTrait
return false; return false;
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Config
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Config;
@ -24,10 +23,9 @@ use phpOMS\DataStorage\Database\Query\Builder;
* *
* Responsible for providing a database/cache bound settings manger * Responsible for providing a database/cache bound settings manger
* *
* @category Framework
* @package phpOMS\Config * @package phpOMS\Config
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class SettingsAbstract implements OptionsInterface abstract class SettingsAbstract implements OptionsInterface
@ -84,6 +82,7 @@ abstract class SettingsAbstract implements OptionsInterface
* @return mixed Option value * @return mixed Option value
* *
* @since 1.0.0 * @since 1.0.0
* @todo: don't db request if exists. check exists()
*/ */
public function get($columns) public function get($columns)
{ {
@ -110,10 +109,10 @@ abstract class SettingsAbstract implements OptionsInterface
break; break;
} }
return $options; return count($options) > 1 ? $options : reset($options);
} catch (\PDOException $e) { } catch (\PDOException $e) {
$exception = DatabaseExceptionFactory::createException($e); $exception = DatabaseExceptionFactory::createException($e);
$message = DatabaseExceptionFactory::createExceptionMessage($e); $message = DatabaseExceptionFactory::createExceptionMessage($e);
throw new $exception($message); throw new $exception($message);
} }
@ -134,7 +133,16 @@ abstract class SettingsAbstract implements OptionsInterface
$this->setOptions($options); $this->setOptions($options);
if ($store) { 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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Console;
/** /**
* CommandManager class. * CommandManager class.
* *
* @category Framework * @package Framework
* @package phpOMS\Socket
* @since 1.0.0 * @since 1.0.0
* *
* @todo : Hey, this looks like a copy of an event manager! * @todo : Hey, this looks like a copy of an event manager!
@ -128,5 +126,4 @@ class CommandManager implements \Countable
{ {
return $this->count; return $this->count;
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Contract
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Contract;
@ -20,10 +19,9 @@ namespace phpOMS\Contract;
* *
* This stands always in combination with a jsonable instance. * This stands always in combination with a jsonable instance.
* *
* @category Framework
* @package phpOMS\Contract * @package phpOMS\Contract
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface ArrayableInterface interface ArrayableInterface
@ -37,5 +35,4 @@ interface ArrayableInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public function toArray() : array; public function toArray() : array;
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD * @package phpOMS\Contract
* @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\Contract;
@ -21,10 +20,9 @@ namespace phpOMS\Contract;
* This is primarily used for classes that provide formatted output or output, * This is primarily used for classes that provide formatted output or output,
* that get's rendered in third party applications. * that get's rendered in third party applications.
* *
* @category Framework
* @package phpOMS\Contract * @package phpOMS\Contract
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface RenderableInterface interface RenderableInterface
@ -38,5 +36,4 @@ interface RenderableInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public function render() : string; public function render() : string;
} }

View File

@ -4,28 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
use phpOMS\DataStorage\Cache\CacheInterface;
use phpOMS\DataStorage\Cache\FileCache;
/** /**
* Database connection factory. * Database connection factory.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class CacheFactory class CacheFactory
@ -35,6 +29,7 @@ class CacheFactory
* Constructor. * Constructor.
* *
* @since 1.0.0 * @since 1.0.0
* @codeCoverageIgnore
*/ */
private function __construct() private function __construct()
{ {

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
/** /**
* Cache interface. * Cache interface.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface CacheInterface interface CacheInterface
@ -39,7 +38,7 @@ interface CacheInterface
* *
* @since 1.0.0 * @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. * Adding new data if it doesn't exist.
@ -109,7 +108,7 @@ interface CacheInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setStatus(int $status) /* : void */; public function setStatus(int $status); /* : void */
/** /**
* Updating existing value/key. * Updating existing value/key.
@ -141,5 +140,4 @@ interface CacheInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public function getThreshold() : int; public function getThreshold() : int;
} }

View File

@ -4,21 +4,18 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
use phpOMS\Config\OptionsInterface; use phpOMS\Config\OptionsInterface;
use phpOMS\Config\OptionsTrait; use phpOMS\Config\OptionsTrait;
use phpOMS\DataStorage\Cache\CacheFactory;
/** /**
* Cache class. * Cache class.
@ -26,10 +23,9 @@ use phpOMS\DataStorage\Cache\CacheFactory;
* Responsible for caching scalar data types and arrays. * Responsible for caching scalar data types and arrays.
* Caching HTML output and objects coming soon/is planned. * Caching HTML output and objects coming soon/is planned.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class CachePool implements OptionsInterface class CachePool implements OptionsInterface
@ -39,12 +35,11 @@ class CachePool implements OptionsInterface
/** /**
* MemCache instance. * MemCache instance.
* *
* @var \phpOMS\DataStorage\Cache\CacheInterface * @var \phpOMS\DataStorage\Cache\CacheInterface[]
* @since 1.0.0 * @since 1.0.0
*/ */
private $pool = null; private $pool = null;
/** /**
* Constructor. * Constructor.
* *
@ -64,7 +59,7 @@ class CachePool implements OptionsInterface
* *
* @since 1.0.0 * @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])) { if (isset($this->pool[$key])) {
return false; return false;
@ -106,11 +101,11 @@ class CachePool implements OptionsInterface
*/ */
public function get(string $key = '') /* : ?CacheInterface */ 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; return null;
} }
if(empty($key)) { if (empty($key)) {
return reset($this->pool); return reset($this->pool);
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
@ -22,15 +21,14 @@ use phpOMS\Stdlib\Base\Enum;
* *
* Possible caching status * Possible caching status
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class CacheStatus extends Enum abstract class CacheStatus extends Enum
{ {
/* public */ const ACTIVE = 0; /* public */ const ACTIVE = 0;
/* public */ const INACTIVE = 1; /* public */ const INACTIVE = 1;
/* public */ const ERROR = 2; /* public */ const ERROR = 2;
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
@ -22,19 +21,18 @@ use phpOMS\Stdlib\Base\Enum;
* *
* Possible caching types * Possible caching types
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class CacheType extends Enum abstract class CacheType extends Enum
{ {
/* public */ const _INT = 0; /* Data is integer */ /* public */ const _INT = 0; /* Data is integer */
/* public */ const _STRING = 1; /* Data is string */ /* public */ const _STRING = 1; /* Data is string */
/* public */ const _ARRAY = 2; /* Data is array */ /* public */ const _ARRAY = 2; /* Data is array */
/* public */ const _SERIALIZABLE = 3; /* Data is object */ /* public */ const _SERIALIZABLE = 3; /* Data is object */
/* public */ const _FLOAT = 4; /* Data is float */ /* public */ const _FLOAT = 4; /* Data is float */
/* public */ const _BOOL = 5; /* Data is bool */ /* public */ const _BOOL = 5; /* Data is bool */
/* public */ const _JSONSERIALIZABLE = 6; /* public */ const _JSONSERIALIZABLE = 6;
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
@ -24,10 +23,9 @@ use phpOMS\System\File\Local\File;
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class FileCache implements CacheInterface class FileCache implements CacheInterface
@ -108,7 +106,7 @@ class FileCache implements CacheInterface
*/ */
public function setStatus(int $status) /* : void */ public function setStatus(int $status) /* : void */
{ {
if(!CacheStatus::isValidValue($status)) { if (!CacheStatus::isValidValue($status)) {
throw new InvalidEnumValue($status); throw new InvalidEnumValue($status);
} }
@ -142,16 +140,14 @@ class FileCache implements CacheInterface
*/ */
public function set($key, $value, int $expire = -1) /* : void */ public function set($key, $value, int $expire = -1) /* : void */
{ {
if($this->status !== CacheStatus::ACTIVE) { if ($this->status !== CacheStatus::ACTIVE) {
return false; return;
} }
// todo: allow $key to contain / as char and create subdirectory if necessary. This is important for cleaner caching. // todo: allow $key to contain / as char and create subdirectory if necessary. This is important for cleaner caching.
$path = File::sanitize($key, self::SANITIZE); $path = File::sanitize($key, self::SANITIZE);
File::put($this->cachePath . '/' . trim($path, '/') . '.cache', $this->build($value, $expire)); 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 public function add($key, $value, int $expire = -1) : bool
{ {
if($this->status !== CacheStatus::ACTIVE) { if ($this->status !== CacheStatus::ACTIVE) {
return false; return false;
} }
$path = File::sanitize($key, self::SANITIZE); $path = $this->getPath($key);
$path = $this->cachePath . '/' . trim($path, '/') . '.cache';
if (!File::exists($path)) { if (!File::exists($path)) {
File::put($path, $this->build($value, $expire)); File::put($path, $this->build($value, $expire));
@ -262,9 +257,9 @@ class FileCache implements CacheInterface
private function getExpire(string $raw) : int private function getExpire(string $raw) : int
{ {
$expireStart = strpos($raw, self::DELIM); $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,14 +267,13 @@ class FileCache implements CacheInterface
*/ */
public function get($key, int $expire = -1) public function get($key, int $expire = -1)
{ {
if($this->status !== CacheStatus::ACTIVE) { if ($this->status !== CacheStatus::ACTIVE) {
return null; return null;
} }
$name = File::sanitize($key, self::SANITIZE); $path = $this->getPath($key);
$path = $this->cachePath . '/' . trim($name, '/') . '.cache';
if(!File::exists($path)) { if (!File::exists($path)) {
return null; return null;
} }
@ -291,11 +285,11 @@ class FileCache implements CacheInterface
} }
$raw = File::get($path); $raw = File::get($path);
$type = $raw[0]; $type = (int) $raw[0];
$expireStart = strpos($raw, self::DELIM); $expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart+1); $expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1)); $cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire < $now) { if ($cacheExpire >= 0 && $created + $cacheExpire < $now) {
$this->delete($key); $this->delete($key);
@ -303,6 +297,11 @@ class FileCache implements CacheInterface
return null; return null;
} }
return $this->parseValue($type, $raw, $expireEnd);
}
private function parseValue(int $type, string $raw, int $expireEnd)
{
$value = null; $value = null;
switch ($type) { switch ($type) {
@ -324,7 +323,7 @@ class FileCache implements CacheInterface
case CacheType::_SERIALIZABLE: case CacheType::_SERIALIZABLE:
case CacheType::_JSONSERIALIZABLE: case CacheType::_JSONSERIALIZABLE:
$namespaceStart = strpos($raw, self::DELIM, $expireEnd); $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); $namespace = substr($raw, $namespaceStart, $namespaceEnd);
$value = $namespace::unserialize(substr($raw, $namespaceEnd + 1)); $value = $namespace::unserialize(substr($raw, $namespaceEnd + 1));
@ -339,12 +338,11 @@ class FileCache implements CacheInterface
*/ */
public function delete($key, int $expire = -1) : bool public function delete($key, int $expire = -1) : bool
{ {
if($this->status !== CacheStatus::ACTIVE) { if ($this->status !== CacheStatus::ACTIVE) {
return false; return false;
} }
$name = File::sanitize($key, self::SANITIZE); $path = $this->getPath($key);
$path = $this->cachePath . '/' . trim($name, '/') . '.cache';
if ($expire < 0 && File::exists($path)) { if ($expire < 0 && File::exists($path)) {
File::delete($path); File::delete($path);
@ -353,12 +351,12 @@ class FileCache implements CacheInterface
} }
if ($expire >= 0) { if ($expire >= 0) {
$created = Directory::created($name)->getTimestamp(); $created = Directory::created(File::sanitize($key, self::SANITIZE))->getTimestamp();
$now = time(); $now = time();
$raw = file_get_contents($path); $raw = file_get_contents($path);
$expireStart = strpos($raw, self::DELIM); $expireStart = strpos($raw, self::DELIM);
$expireEnd = strpos($raw, self::DELIM, $expireStart+1); $expireEnd = strpos($raw, self::DELIM, $expireStart + 1);
$cacheExpire = substr($raw, $expireStart+1, $expireEnd - ($expireStart+1)); $cacheExpire = substr($raw, $expireStart + 1, $expireEnd - ($expireStart + 1));
if ($cacheExpire >= 0 && $created + $cacheExpire > $now) { if ($cacheExpire >= 0 && $created + $cacheExpire > $now) {
File::delete($path); File::delete($path);
@ -385,8 +383,7 @@ class FileCache implements CacheInterface
foreach ($dir as $file) { foreach ($dir as $file) {
if ($file instanceof File) { if ($file instanceof File) {
$created = $file->getCreatedAt()->getTimestamp(); $created = $file->getCreatedAt()->getTimestamp();
if ( if (($expire >= 0 && $created + $expire < $now)
($expire >= 0 && $created + $expire < $now)
|| ($expire < 0 && $created + $this->getExpire($file->getContent()) < $now) || ($expire < 0 && $created + $this->getExpire($file->getContent()) < $now)
) { ) {
File::delete($file->getPath()); File::delete($file->getPath());
@ -402,12 +399,11 @@ class FileCache implements CacheInterface
*/ */
public function replace($key, $value, int $expire = -1) : bool public function replace($key, $value, int $expire = -1) : bool
{ {
if($this->status !== CacheStatus::ACTIVE) { if ($this->status !== CacheStatus::ACTIVE) {
return false; return false;
} }
$name = File::sanitize($key, self::SANITIZE); $path = $this->getPath($key);
$path = $this->cachePath . '/' . trim($path, '/') . '.cache';
if (File::exists($path)) { if (File::exists($path)) {
File::put($path, $this->build($value, $expire)); File::put($path, $this->build($value, $expire));
@ -417,4 +413,10 @@ class FileCache implements CacheInterface
return false; 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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
/** /**
* Memcache class. * Memcache class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class MemCache implements CacheInterface class MemCache implements CacheInterface
@ -43,6 +41,8 @@ class MemCache implements CacheInterface
*/ */
private $threshold = 10; private $threshold = 10;
private $status;
/** /**
* Constructor. * Constructor.
* *
@ -50,7 +50,7 @@ class MemCache implements CacheInterface
*/ */
public function __construct() public function __construct()
{ {
$this->memc = new self(); $this->memc = null;
} }
/** /**
@ -174,5 +174,4 @@ class MemCache implements CacheInterface
$this->memc = null; $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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
/** /**
* Null cache class. * Null cache class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class NullCache implements CacheInterface class NullCache implements CacheInterface
@ -32,7 +30,6 @@ class NullCache implements CacheInterface
*/ */
public function set($key, $value, int $expire = -1) /* : void */ 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 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) 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 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 public function flush(int $expire = 0) : bool
{ {
// TODO: Implement flush() method.
return true; return true;
} }
@ -74,8 +69,6 @@ class NullCache implements CacheInterface
*/ */
public function flushAll() : bool public function flushAll() : bool
{ {
// TODO: Implement flush() method.
return true; return true;
} }
@ -84,7 +77,7 @@ class NullCache implements CacheInterface
*/ */
public function replace($key, $value, int $expire = -1) : bool 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 public function stats() : array
{ {
// TODO: Implement stats() method. return [];
} }
/** /**
@ -100,7 +93,7 @@ class NullCache implements CacheInterface
*/ */
public function getThreshold() : int public function getThreshold() : int
{ {
// TODO: Implement getThreshold() method. return 0;
} }
/** /**
@ -108,6 +101,5 @@ class NullCache implements CacheInterface
*/ */
public function setStatus(int $status) /* : void */ public function setStatus(int $status) /* : void */
{ {
// TODO: Implement setStatus() method.
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
@ -20,10 +19,9 @@ namespace phpOMS\DataStorage\Cache;
* *
* PHP Version 5.6 * PHP Version 5.6
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class RedisCache implements CacheInterface class RedisCache implements CacheInterface

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cache;
@ -20,10 +19,9 @@ namespace phpOMS\DataStorage\Cache;
* *
* PHP Version 5.6 * PHP Version 5.6
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Cache
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class WinCache implements CacheInterface class WinCache implements CacheInterface

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Cookie;
@ -20,10 +19,9 @@ use phpOMS\DataStorage\LockException;
/** /**
* CookieJar class * CookieJar class
* *
* @category Framework * @package Framework
* @package phpOMS\Utils
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class CookieJar class CookieJar
@ -47,6 +45,8 @@ class CookieJar
* Constructor. * Constructor.
* *
* @since 1.0.0 * @since 1.0.0
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
public function __construct() public function __construct()
{ {
@ -122,12 +122,12 @@ class CookieJar
*/ */
public function delete(string $id) : bool public function delete(string $id) : bool
{ {
if($this->remove($id)) { if ($this->remove($id)) {
if (self::$isLocked) { if (self::$isLocked) {
throw new LockException('CookieJar'); throw new LockException('CookieJar');
} }
if(!headers_sent()) { if (!headers_sent()) {
setcookie($id, '', time() - 3600); setcookie($id, '', time() - 3600);
return true; return true;

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage;
@ -22,10 +21,9 @@ use phpOMS\DataStorage\Database\Query\Builder;
* *
* DB, Cache, Session * DB, Cache, Session
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface DataMapperInterface interface DataMapperInterface
@ -47,11 +45,11 @@ interface DataMapperInterface
* *
* @param mixed $obj Object reference (gets filled with insert id) * @param mixed $obj Object reference (gets filled with insert id)
* *
* @return int Status * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function update($obj) : int; public static function update($obj);
/** /**
* Delete data. * Delete data.
@ -129,5 +127,4 @@ interface DataMapperInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public static function get($primaryKey); public static function get($primaryKey);
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
/** /**
* Database query builder. * Database query builder.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class BuilderAbstract abstract class BuilderAbstract
@ -60,6 +58,14 @@ abstract class BuilderAbstract
*/ */
protected $prefix = ''; protected $prefix = '';
/**
* Raw.
*
* @var string
* @since 1.0.0
*/
public $raw = '';
/** /**
* Set prefix. * Set prefix.
* *

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar;
* Handles the database connection. * Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away). * Implementing wrapper functions for multiple databases is planned (far away).
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class ConnectionAbstract implements ConnectionInterface abstract class ConnectionAbstract implements ConnectionInterface
@ -65,15 +63,15 @@ abstract class ConnectionAbstract implements ConnectionInterface
/** /**
* Database type. * Database type.
* *
* @var \phpOMS\DataStorage\Database\DatabaseType * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected $type = null; protected $type = 'undefined';
/** /**
* Database status. * Database status.
* *
* @var DatabaseStatus * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
protected $status = DatabaseStatus::CLOSED; protected $status = DatabaseStatus::CLOSED;
@ -202,5 +200,4 @@ abstract class ConnectionAbstract implements ConnectionInterface
$this->con = null; $this->con = null;
$this->status = DatabaseStatus::CLOSED; $this->status = DatabaseStatus::CLOSED;
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\DatabaseType;
/** /**
* Database connection factory. * Database connection factory.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class ConnectionFactory class ConnectionFactory
@ -57,10 +55,8 @@ class ConnectionFactory
switch ($dbdata['db']) { switch ($dbdata['db']) {
case DatabaseType::MYSQL: case DatabaseType::MYSQL:
return new MysqlConnection($dbdata); return new MysqlConnection($dbdata);
break;
case DatabaseType::SQLSRV: case DatabaseType::SQLSRV:
return new SqlServerConnection($dbdata); return new SqlServerConnection($dbdata);
break;
default: default:
throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.'); throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.');
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar;
/** /**
* Database connection interface. * Database connection interface.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
interface ConnectionInterface interface ConnectionInterface
@ -41,7 +39,7 @@ interface ConnectionInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function connect(array $dbdata) /* : void */; public function connect(array $dbdata); /* : void */
/** /**
* Get the database type. * Get the database type.
@ -68,7 +66,7 @@ interface ConnectionInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function close() /* : void */; public function close(); /* : void */
/** /**
* Return grammar for this connection. * Return grammar for this connection.
@ -87,5 +85,4 @@ interface ConnectionInterface
* @since 1.0.0 * @since 1.0.0
*/ */
public function getSchemaGrammar() : SchemaGrammar; public function getSchemaGrammar() : SchemaGrammar;
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -27,10 +26,9 @@ use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException;
* Handles the database connection. * Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away). * Implementing wrapper functions for multiple databases is planned (far away).
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class MysqlConnection extends ConnectionAbstract class MysqlConnection extends ConnectionAbstract
@ -60,32 +58,11 @@ class MysqlConnection extends ConnectionAbstract
{ {
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata; $this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
if(!isset($this->dbdata['db'])) { if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])) {
throw new InvalidConnectionConfigException('db'); throw new InvalidConnectionConfigException(json_encode($this->dbdata));
}
if(!isset($this->dbdata['host'])) {
throw new InvalidConnectionConfigException('host');
}
if(!isset($this->dbdata['port'])) {
throw new InvalidConnectionConfigException('port');
}
if(!isset($this->dbdata['database'])) {
throw new InvalidConnectionConfigException('database');
}
if(!isset($this->dbdata['login'])) {
throw new InvalidConnectionConfigException('login');
}
if(!isset($this->dbdata['password'])) {
throw new InvalidConnectionConfigException('password');
} }
$this->close(); $this->close();
$this->prefix = $dbdata['prefix'] ?? ''; $this->prefix = $dbdata['prefix'] ?? '';
try { try {
@ -101,5 +78,4 @@ class MysqlConnection extends ConnectionAbstract
$this->dbdata['password'] = '****'; $this->dbdata['password'] = '****';
} }
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Query\Grammar\SqliteGrammar;
* Handles the database connection. * Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away). * Implementing wrapper functions for multiple databases is planned (far away).
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class SqliteConnection extends ConnectionAbstract class SqliteConnection extends ConnectionAbstract
@ -71,5 +69,4 @@ class SqliteConnection extends ConnectionAbstract
$this->con = null; $this->con = null;
} }
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Connection;
@ -26,10 +25,9 @@ use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGramma
* Handles the database connection. * Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away). * Implementing wrapper functions for multiple databases is planned (far away).
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class SqlServerConnection extends ConnectionAbstract class SqlServerConnection extends ConnectionAbstract

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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -20,10 +19,9 @@ use phpOMS\DataStorage\Database\Schema\Exception\TableException;
/** /**
* Database exception factory. * Database exception factory.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class DatabaseExceptionFactory class DatabaseExceptionFactory

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
/** /**
* Database pool handler. * Database pool handler.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class DatabasePool class DatabasePool
@ -57,7 +55,7 @@ class DatabasePool
* *
* @since 1.0.0 * @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])) { if (isset($this->pool[$key])) {
return false; return false;
@ -79,11 +77,11 @@ class DatabasePool
*/ */
public function get(string $key = '') /* : ?ConnectionAbstract */ 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; return null;
} }
if(empty($key)) { if (empty($key)) {
return reset($this->pool); return reset($this->pool);
} }
@ -130,5 +128,4 @@ class DatabasePool
return true; return true;
} }
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum;
* *
* Possible database connection status * Possible database connection status
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class DatabaseStatus extends Enum abstract class DatabaseStatus extends Enum

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -22,17 +21,16 @@ use phpOMS\Stdlib\Base\Enum;
* *
* Database types that are supported by the application * Database types that are supported by the application
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class DatabaseType extends Enum abstract class DatabaseType extends Enum
{ {
/* public */ const MYSQL = 'mysql'; /* MySQL */ /* public */ const MYSQL = 'mysql'; /* MySQL */
/* public */ const SQLITE = 'sqlite'; /* SQLITE */ /* public */ const SQLITE = 'sqlite'; /* SQLITE */
/* public */ const PGSQL = 2; /* PostgreSQL */ /* public */ const PGSQL = 2; /* PostgreSQL */
/* public */ const ORACLE = 3; /* Oracle */ /* public */ const ORACLE = 3; /* Oracle */
/* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */ /* public */ const SQLSRV = 'mssql'; /* Microsoft SQL Server */
} }

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Exception;
/** /**
* Permission exception class. * Permission exception class.
* *
* @category Framework * @package Framework
* @package phpOMS\System\File
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class InvalidConnectionConfigException extends \InvalidArgumentException class InvalidConnectionConfigException extends \InvalidArgumentException
@ -31,12 +29,12 @@ class InvalidConnectionConfigException extends \InvalidArgumentException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct(string $message = '', int $code = 0, \Exception $previous = null) 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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Exception;
/** /**
* Permission exception class. * Permission exception class.
* *
* @category Framework * @package Framework
* @package phpOMS\System\File
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class InvalidMapperException extends \RuntimeException class InvalidMapperException extends \RuntimeException
@ -31,13 +29,13 @@ class InvalidMapperException extends \RuntimeException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function __construct(string $message = '', int $code = 0, \Exception $previous = null) public function __construct(string $message = '', int $code = 0, \Exception $previous = null)
{ {
if($message === '') { if ($message === '') {
parent::__construct('Empty mapper.', $code, $previous); parent::__construct('Empty mapper.', $code, $previous);
} else { } else {
parent::__construct('Mapper "' . $message . '" is invalid.', $code, $previous); parent::__construct('Mapper "' . $message . '" is invalid.', $code, $previous);

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
/** /**
* Grammar. * Grammar.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class GrammarAbstract abstract class GrammarAbstract
@ -170,7 +168,7 @@ abstract class GrammarAbstract
foreach ($elements as $key => $element) { foreach ($elements as $key => $element) {
if (is_string($element) && $element !== '*') { if (is_string($element) && $element !== '*') {
if(strpos($element, '.') === false) { if (strpos($element, '.') === false) {
$prefix = ''; $prefix = '';
} }
@ -237,25 +235,20 @@ abstract class GrammarAbstract
// todo: this is a bad way to handle select count(*) which doesn't need a prefix. Maybe remove prefixes in total? // todo: this is a bad way to handle select count(*) which doesn't need a prefix. Maybe remove prefixes in total?
$identifier = $this->systemIdentifier; $identifier = $this->systemIdentifier;
foreach($this->specialKeywords as $keyword) { foreach ($this->specialKeywords as $keyword) {
if($keyword === '' || strrpos($system, $keyword, -strlen($system)) !== false) { if (strrpos($system, $keyword, -strlen($system)) !== false) {
$prefix = ''; $prefix = '';
$identifier = ''; $identifier = '';
} }
} }
// todo: move remaining * test also here not just if .* but also if * (should be done in else?) // todo: move remaining * test also here not just if .* but also if * (should be done in else?)
if (count($split = explode('.', $system)) == 2) { if (count($split = explode('.', $system)) === 2) {
if ($split[1] === '*') { $system = $split[1] === '*' ? $split[1] : $this->compileSystem($split[1]);
$system = $split[1];
} else {
$system = $this->compileSystem($split[1]);
}
return $this->compileSystem($prefix . $split[0]) . '.' . $system; 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 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
@ -21,10 +20,9 @@ use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
/** /**
* Database query builder. * Database query builder.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Builder extends BuilderAbstract class Builder extends BuilderAbstract
@ -64,7 +62,7 @@ class Builder extends BuilderAbstract
/** /**
* Into. * Into.
* *
* @var array * @var string|\Closure
* @since 1.0.0 * @since 1.0.0
*/ */
public $into = null; public $into = null;
@ -152,7 +150,7 @@ class Builder extends BuilderAbstract
/** /**
* Offset. * Offset.
* *
* @var array * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
public $offset = null; public $offset = null;
@ -181,14 +179,6 @@ class Builder extends BuilderAbstract
*/ */
public $lock = false; public $lock = false;
/**
* Raw query.
*
* @var bool
* @since 1.0.0
*/
public $raw = '';
/** /**
* Comparison OPERATORS. * Comparison OPERATORS.
* *
@ -229,6 +219,7 @@ class Builder extends BuilderAbstract
* Constructor. * Constructor.
* *
* @param ConnectionAbstract $connection Database connection * @param ConnectionAbstract $connection Database connection
* @param bool $readOnly Query is read only
* *
* @since 1.0.0 * @since 1.0.0
*/ */
@ -352,21 +343,14 @@ class Builder extends BuilderAbstract
* *
* @return Builder * @return Builder
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function raw(string $raw) : Builder public function raw(string $raw) : Builder
{ {
if($this->isReadOnly) { if (!$this->isValidReadOnly($raw)) {
$test = strtolower($raw); throw new \Exception();
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();
}
} }
$this->type = QueryType::RAW; $this->type = QueryType::RAW;
@ -375,6 +359,37 @@ class Builder extends BuilderAbstract
return $this; 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. * Make raw column selection.
* *
@ -398,7 +413,7 @@ class Builder extends BuilderAbstract
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function distinct(...$columns) : Builder public function distinct() : Builder
{ {
$this->distinct = true; $this->distinct = true;
@ -408,7 +423,7 @@ class Builder extends BuilderAbstract
/** /**
* From. * From.
* *
* @param array $tables Tables * @param string|array $tables Tables
* *
* @return Builder * @return Builder
* *
@ -446,7 +461,7 @@ class Builder extends BuilderAbstract
/** /**
* Where. * Where.
* *
* @param string|array|\Closure $columns Columns * @param Where|string|\Closure|array $columns Columns
* @param string|array $operator Operator * @param string|array $operator Operator
* @param mixed $values Values * @param mixed $values Values
* @param string|array $boolean Boolean condition * @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 public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
{ {
// TODO: handle $value is null -> operator NULL
if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) { if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.'); throw new \InvalidArgumentException('Unknown operator.');
} }
if (is_array($columns)) { if (is_string($columns)) {
$i = 0; $columns = [$columns];
foreach ($columns as $key => $column) { $operator = [$operator];
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) { $values = [$values];
throw new \InvalidArgumentException('Unknown operator.'); $boolean = [$boolean];
} }
$this->wheres[self::getPublicColumnName($column)][] = [ $i = 0;
'column' => $column, foreach ($columns as $key => $column) {
'operator' => $operator[$i], if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
'value' => $values[$i],
'boolean' => $boolean[$i],
];
$i++;
}
} elseif (is_string($columns)) {
if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.'); throw new \InvalidArgumentException('Unknown operator.');
} }
$this->wheres[self::getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values, $this->wheres[self::getPublicColumnName($column)][] = [
'boolean' => $boolean,]; 'column' => $column,
} else { 'operator' => $operator[$i],
throw new \InvalidArgumentException(); 'value' => $values[$i],
'boolean' => $boolean[$i],
];
$i++;
} }
return $this; return $this;
@ -523,7 +533,7 @@ class Builder extends BuilderAbstract
*/ */
public function getTableOfSystem($expression, string $systemIdentifier) /* : ?string */ public function getTableOfSystem($expression, string $systemIdentifier) /* : ?string */
{ {
if(($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) { if (($pos = strpos($expression, $systemIdentifier . '.' . $systemIdentifier)) === false) {
return null; return null;
} }
@ -533,7 +543,9 @@ class Builder extends BuilderAbstract
/** /**
* Where and sub condition. * 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 * @return Builder
* *
@ -547,7 +559,9 @@ class Builder extends BuilderAbstract
/** /**
* Where or sub condition. * 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 * @return Builder
* *
@ -561,7 +575,7 @@ class Builder extends BuilderAbstract
/** /**
* Where in. * Where in.
* *
* @param string|array|\Closure $column Column * @param Where|string|\Closure|array $column Column
* @param mixed $values Values * @param mixed $values Values
* @param string $boolean Boolean condition * @param string $boolean Boolean condition
* *
@ -579,7 +593,7 @@ class Builder extends BuilderAbstract
/** /**
* Where null. * Where null.
* *
* @param string|array|\Closure $column Column * @param Where|string|\Closure|array $column Column
* @param string $boolean Boolean condition * @param string $boolean Boolean condition
* *
* @return Builder * @return Builder
@ -596,7 +610,7 @@ class Builder extends BuilderAbstract
/** /**
* Where not null. * Where not null.
* *
* @param string|array|\Closure $column Column * @param Where|string|\Closure|array $column Column
* @param string $boolean Boolean condition * @param string $boolean Boolean condition
* *
* @return Builder * @return Builder
@ -677,7 +691,7 @@ class Builder extends BuilderAbstract
public function orderBy($columns, $order = 'DESC') : Builder public function orderBy($columns, $order = 'DESC') : Builder
{ {
if (is_string($columns) || $columns instanceof \Closure) { if (is_string($columns) || $columns instanceof \Closure) {
if(!isset($this->orders[$order])) { if (!isset($this->orders[$order])) {
$this->orders[$order] = []; $this->orders[$order] = [];
} }
@ -696,7 +710,7 @@ class Builder extends BuilderAbstract
/** /**
* Offset. * Offset.
* *
* @param int|\Closure $offset Offset * @param int $offset Offset
* *
* @return Builder * @return Builder
* *
@ -712,7 +726,7 @@ class Builder extends BuilderAbstract
/** /**
* Limit. * Limit.
* *
* @param int|\Closure $limit Limit * @param int $limit Limit
* *
* @return Builder * @return Builder
* *
@ -726,7 +740,7 @@ class Builder extends BuilderAbstract
} }
/** /**
* Limit. * Union.
* *
* @param string|\phpOMS\DataStorage\Database\Query\Builder $query Query * @param string|\phpOMS\DataStorage\Database\Query\Builder $query Query
* *
@ -785,9 +799,13 @@ class Builder extends BuilderAbstract
/** /**
* Count results. * Count results.
* *
* @param string $table Table to count the result set
*
* @return Builder
*
* @since 1.0.0 * @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 // 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 . ')'); return $this->select('COUNT(' . $table . ')');
@ -836,11 +854,13 @@ class Builder extends BuilderAbstract
* *
* @return Builder * @return Builder
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function insert(...$columns) : Builder public function insert(...$columns) : Builder
{ {
if($this->isReadOnly) { if ($this->isReadOnly) {
throw new \Exception(); throw new \Exception();
} }
@ -941,15 +961,17 @@ class Builder extends BuilderAbstract
/** /**
* Update columns. * Update columns.
* *
* @param array $columns Column names to update * @param array $tables Column names to update
* *
* @return Builder * @return Builder
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
public function update(...$tables) : Builder public function update(...$tables) : Builder
{ {
if($this->isReadOnly) { if ($this->isReadOnly) {
throw new \Exception(); throw new \Exception();
} }
@ -968,7 +990,7 @@ class Builder extends BuilderAbstract
public function delete() : Builder public function delete() : Builder
{ {
if($this->isReadOnly) { if ($this->isReadOnly) {
throw new \Exception(); throw new \Exception();
} }
@ -1099,7 +1121,7 @@ class Builder extends BuilderAbstract
{ {
$sth = $this->connection->con->prepare($this->toSql()); $sth = $this->connection->con->prepare($this->toSql());
foreach($this->binds as $key => $bind) { foreach ($this->binds as $key => $bind) {
$type = self::getBindParamType($bind); $type = self::getBindParamType($bind);
$sth->bindParam($key, $bind, $type); $sth->bindParam($key, $bind, $type);
@ -1113,16 +1135,20 @@ class Builder extends BuilderAbstract
/** /**
* Get bind parameter type. * Get bind parameter type.
* *
* @param mixed $value Value to bind
*
* @return mixed * @return mixed
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getBindParamType($value) public static function getBindParamType($value)
{ {
if(is_int($value)) { if (is_int($value)) {
return PDO::PARAM_INT; return \PDO::PARAM_INT;
} elseif(is_string($value) || is_float($value)) { } elseif (is_string($value) || is_float($value)) {
return PDO::PARAM_STR; return \PDO::PARAM_STR;
} }
throw new \Exception(); throw new \Exception();
@ -1130,14 +1156,14 @@ class Builder extends BuilderAbstract
public static function getPublicColumnName($column) : string public static function getPublicColumnName($column) : string
{ {
if(is_string($column)) { if (is_string($column)) {
return $column; return $column;
} elseif($column instanceof Column) { } elseif ($column instanceof Column) {
return $column->getPublicName(); return $column->getPublicName();
} elseif($column instanceof \Closure) { } elseif ($column instanceof \Closure) {
return $column(); return $column();
} elseif($column instanceof \Serializable) { } elseif ($column instanceof \Serializable) {
return $column; return $column->serialize();
} }
throw new \Exception(); throw new \Exception();

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
/** /**
* Database query builder. * Database query builder.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Column class Column
@ -63,5 +61,4 @@ class Column
{ {
$this->column = $column; $this->column = $column;
} }
} }

View File

@ -4,18 +4,16 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
class Expression class Expression
{ {

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
@ -25,10 +24,9 @@ use phpOMS\DataStorage\Database\Query\Where;
/** /**
* Database query grammar. * Database query grammar.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Grammar extends GrammarAbstract class Grammar extends GrammarAbstract
@ -115,29 +113,12 @@ class Grammar extends GrammarAbstract
{ {
$sql = []; $sql = [];
switch ($query->getType()) { if ($query->getType() === QueryType::RAW) {
case QueryType::SELECT: return [$query->raw];
$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.');
} }
$components = $this->getComponents($query->getType());
/* Loop all possible query components and if they exist compile them. */ /* Loop all possible query components and if they exist compile them. */
foreach ($components as $component) { foreach ($components as $component) {
if (isset($query->{$component}) && !empty($query->{$component})) { if (isset($query->{$component}) && !empty($query->{$component})) {
@ -148,6 +129,35 @@ class Grammar extends GrammarAbstract
return $sql; 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. * Compile select.
* *
@ -173,7 +183,7 @@ class Grammar extends GrammarAbstract
* Compile select. * Compile select.
* *
* @param Builder $query Builder * @param Builder $query Builder
* @param array $columns Columns * @param array $table Table
* *
* @return string * @return string
* *
@ -244,7 +254,7 @@ class Grammar extends GrammarAbstract
foreach ($wheres as $key => $where) { foreach ($wheres as $key => $where) {
foreach ($where as $key2 => $element) { foreach ($where as $key2 => $element) {
$expression .= $this->compileWhereElement($element, $query, $first); $expression .= $this->compileWhereElement($element, $query, $first);
$first = false; $first = false;
} }
} }
@ -270,7 +280,7 @@ class Grammar extends GrammarAbstract
{ {
$expression = ''; $expression = '';
if(!$first) { if (!$first) {
$expression = ' ' . strtoupper($element['boolean']) . ' '; $expression = ' ' . strtoupper($element['boolean']) . ' ';
} }
@ -289,7 +299,7 @@ class Grammar extends GrammarAbstract
if (isset($element['value'])) { if (isset($element['value'])) {
$expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix()); $expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix());
} else { } else {
$operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT'; $operator = strtoupper($element['operator']) === '=' ? 'IS' : 'IS NOT';
$expression .= ' ' . $operator . ' ' . $this->compileValue($element['value'], $query->getPrefix()); $expression .= ' ' . $operator . ' ' . $this->compileValue($element['value'], $query->getPrefix());
} }
@ -317,7 +327,7 @@ class Grammar extends GrammarAbstract
protected function compileValue($value, $prefix = '') : string protected function compileValue($value, $prefix = '') : string
{ {
if (is_string($value)) { if (is_string($value)) {
if(strpos($value, ':') === 0) { if (strpos($value, ':') === 0) {
return $value; return $value;
} }
@ -420,11 +430,11 @@ class Grammar extends GrammarAbstract
$expression = ''; $expression = '';
foreach ($orders as $key => $order) { foreach ($orders as $key => $order) {
foreach($order as $column) { foreach ($order as $column) {
$expression .= $this->compileSystem($column, $query->getPrefix()) . ', '; $expression .= $this->compileSystem($column, $query->getPrefix()) . ', ';
} }
$expression = rtrim($expression, ', '); $expression = rtrim($expression, ', ');
$expression .= ' ' . $key . ', '; $expression .= ' ' . $key . ', ';
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Grammar class. * Grammar class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class MicrosoftGrammar extends Grammar class MicrosoftGrammar extends Grammar

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Grammar class. * Grammar class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class MysqlGrammar extends Grammar class MysqlGrammar extends Grammar

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Grammar class. * Grammar class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class OracleGrammar extends Grammar class OracleGrammar extends Grammar

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Grammar class. * Grammar class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class PostgresGrammar extends Grammar class PostgresGrammar extends Grammar

View File

@ -4,25 +4,24 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\Builder;
/** /**
* Grammar class. * Grammar class.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database\Query\Grammar
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class SqliteGrammar extends Grammar class SqliteGrammar extends Grammar

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
@ -20,23 +19,22 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Query type enum. * Query type enum.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class JoinType extends Enum abstract class JoinType extends Enum
{ {
/* public */ const JOIN = 'JOIN'; /* public */ const JOIN = 'JOIN';
/* public */ const LEFT_JOIN = 'LEFT JOIN'; /* public */ const LEFT_JOIN = 'LEFT JOIN';
/* public */ const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN'; /* public */ const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN';
/* public */ const LEFT_INNER_JOIN = 'LEFT INNER JOIN'; /* public */ const LEFT_INNER_JOIN = 'LEFT INNER JOIN';
/* public */ const RIGHT_JOIN = 'RIGHT JOIN'; /* public */ const RIGHT_JOIN = 'RIGHT JOIN';
/* public */ const RIGHT_OUTER_JOIN = 'RIGHT OUTER JOIN'; /* public */ const RIGHT_OUTER_JOIN = 'RIGHT OUTER JOIN';
/* public */ const RIGHT_INNER_JOIN = 'RIGHT INNER JOIN'; /* public */ const RIGHT_INNER_JOIN = 'RIGHT INNER JOIN';
/* public */ const OUTER_JOIN = 'OUTER JOIN'; /* public */ const OUTER_JOIN = 'OUTER JOIN';
/* public */ const INNER_JOIN = 'INNER JOIN'; /* public */ const INNER_JOIN = 'INNER JOIN';
/* public */ const CROSS_JOIN = 'CROSS JOIN'; /* public */ const CROSS_JOIN = 'CROSS JOIN';
/* public */ const FULL_OUTER_JOIN = 'FULL OUTER JOIN'; /* public */ const FULL_OUTER_JOIN = 'FULL OUTER JOIN';
} }

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
@ -20,10 +19,9 @@ use phpOMS\Stdlib\Base\Enum;
/** /**
* Query type enum. * Query type enum.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class QueryType extends Enum abstract class QueryType extends Enum
@ -33,5 +31,5 @@ abstract class QueryType extends Enum
/* public */ const UPDATE = 2; /* public */ const UPDATE = 2;
/* public */ const DELETE = 3; /* public */ const DELETE = 3;
/* public */ const RANDOM = 4; /* public */ const RANDOM = 4;
/* public */ const RAW = 5; /* public */ const RAW = 5;
} }

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Query;
/** /**
* Database query builder. * Database query builder.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Where class Where

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database;
@ -22,10 +21,9 @@ use phpOMS\Stdlib\Base\Enum;
* *
* Database types that are supported by the application * Database types that are supported by the application
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
abstract class RelationType extends Enum abstract class RelationType extends Enum

View File

@ -4,28 +4,25 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Schema;
use phpOMS\DataStorage\Database\BuilderAbstract; use phpOMS\DataStorage\Database\BuilderAbstract;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract; use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query;
/** /**
* Database query builder. * Database query builder.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Builder extends BuilderAbstract class Builder extends BuilderAbstract
@ -49,16 +46,16 @@ class Builder extends BuilderAbstract
public function select(...$table) /* : void */ public function select(...$table) /* : void */
{ {
$this->type = QueryType::SELECT; $this->type = QueryType::SELECT;
$this->table += $table; $this->table += $table;
$this->table = array_unique($this->table); $this->table = array_unique($this->table);
} }
public function drop(...$table) public function drop(...$table)
{ {
$this->type = QueryType::DROP; $this->type = QueryType::DROP;
$this->drop += $table; $this->drop += $table;
$this->drop = array_unique($this->drop); $this->drop = array_unique($this->drop);
} }
public function create(string $table) public function create(string $table)

View File

@ -4,24 +4,22 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Schema\Exception;
/** /**
* Path exception class. * Path exception class.
* *
* @category System * @package System
* @package Framework
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class TableException extends \PDOException class TableException extends \PDOException
@ -31,7 +29,7 @@ class TableException extends \PDOException
* *
* @param string $message Exception message * @param string $message Exception message
* @param int $code Exception code * @param int $code Exception code
* @param \Exception Previous exception * @param \Exception $previous Previous exception
* *
* @since 1.0.0 * @since 1.0.0
*/ */

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Schema\Grammar;
@ -22,10 +21,9 @@ use phpOMS\DataStorage\Database\Schema\QueryType;
/** /**
* Database query grammar. * Database query grammar.
* *
* @category Framework * @package Framework
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0 * @license OMS License 1.0
* @link http://orange-management.com * @link http://website.orange-management.de
* @since 1.0.0 * @since 1.0.0
*/ */
class Grammar extends GrammarAbstract class Grammar extends GrammarAbstract

View File

@ -4,14 +4,13 @@
* *
* PHP Version 7.1 * PHP Version 7.1
* *
* @category TBD
* @package TBD * @package TBD
* @copyright Dennis Eichhorn * @copyright Dennis Eichhorn
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @version 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; namespace phpOMS\DataStorage\Database\Schema\Grammar;

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