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,12 +4,11 @@
* *
* 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);
@ -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;
@ -331,7 +329,8 @@ class Account implements ArrayableInterface, \JsonSerializable
&& ($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.
* *
@ -67,7 +56,6 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,27 @@ 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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,7 +40,7 @@ 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);
@ -73,5 +71,4 @@ class Autoloader
return file_exists(__DIR__ . '/../' . $class . '.php'); return file_exists(__DIR__ . '/../' . $class . '.php');
} }
} }

View File

@ -4,12 +4,11 @@
* *
* 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);

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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;

View File

@ -4,12 +4,11 @@
* *
* 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;

View File

@ -4,12 +4,11 @@
* *
* 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;

View File

@ -4,12 +4,11 @@
* *
* 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;
@ -19,6 +18,7 @@ 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)

View File

@ -4,12 +4,11 @@
* *
* 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;

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,12 @@
* *
* 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);
@ -38,585 +38,75 @@ class ExponentialSmoothing
$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]; public function getAMN()
if($seasonalType === SeasonalType::ALL) {
$seasonals = [SeasonalType::NONE, SeasonalType::ADDITIVE, SeasonalType::MULTIPLICATIVE];
}
$forecast = [];
$bestError = PHP_INT_MAX;
foreach($trends as $trend) {
foreach($seasonals as $seasonal) {
$tempForecast = $this->getForecast($future, $trend, $seasonal, $cycle, $damping);
if ($this->rmse < $bestError) {
$bestError = $this->rmse;
$forecast = $tempForecast;
}
}
}
return $forecast;
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::NONE) {
return $this->getNoneNone($future);
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getNoneAdditive($future, $cycle);
} elseif($trendType === TrendType::NONE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getNoneMultiplicative($future, $cycle);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::NONE) {
return $this->getAdditiveNone($future, $damping);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getAdditiveAdditive($future, $cycle, $damping);
} elseif($trendType === TrendType::ADDITIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getAdditiveMultiplicative($future, $cycle, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::NONE) {
return $this->getMultiplicativeNone($future, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::ADDITIVE) {
return $this->getMultiplicativeAdditive($future, $cycle, $damping);
} elseif($trendType === TrendType::MULTIPLICATIVE && $seasonalType === SeasonalType::MULTIPLICATIVE) {
return $this->getMultiplicativeMultiplicative($future, $cycle, $damping);
}
throw new \Exception();
}
private function dampingSum(float $damping, int $length) : float
{ {
if(abs($damping - 1) < 0.001) {
return $length;
} }
$sum = 0; public function getAMA()
for($i = 0; $i < $length; $i++) {
$sum += pow($damping, $i);
}
return $sum;
}
public function getNoneNone(int $future) : array
{ {
$level = [$this->data[0]];
$dataLength = count($this->data) + $future;
$forecast = [];
$alpha = 0.00;
while ($alpha < 1) {
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1];
$tempForecast[$i] = $level[$i];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
} }
$tempRMSE = Error::getRootMeanSquaredError($error); public function getAMM()
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getNoneAdditive(int $future, int $cycle) : array
{ {
$level = [$this->data[0]];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
} }
$alpha = 0.00; public function getMNN()
while ($alpha < 1) {
$gamma = 0.00;
while($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$gamma += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getNoneMultiplicative(int $future, int $cycle) : array
{ {
$level = [$this->data[0]];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
} }
$alpha = 0.00; public function getMNA()
while ($alpha < 1) {
$gamma = 0.00;
while($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * $level[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$gamma += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getAdditiveNone(int $future, float $damping) : array
{ {
$level = [$this->data[0]];
$trend = [$this->data[1] - $this->data[0]];
$dataLength = count($this->data) + $future;
$forecast = [];
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
} }
$tempRMSE = Error::getRootMeanSquaredError($error); public function getMNM()
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$beta += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getAdditiveAdditive(int $future, int $cycle, float $damping) : array
{ {
$level = [1 / $cycle * array_sum(array_slice($this->data, 0, $cycle))];
$trend = [1 / $cycle];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
} }
$trend[0] *= $sum; public function getMAN()
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] + $this->dampingSum($damping, $i) * $trend[$i] + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$gamma += 0.01;
}
$beta += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getAdditiveMultiplicative(int $future, int $cycle, float $damping) : array
{ {
$level = [1 / $cycle * array_sum(array_slice($this->data, 0, $cycle))];
$trend = [1 / $cycle];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
$gamma_ = $gamma * (1 - $alpha);
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
} }
$trend[0] *= $sum; public function getMAA()
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / $seasonal[$i]) + (1 - $alpha) * ($level[$i-1] + $damping * $trend[$i-1]);
$trend[$i] = $beta * ($level[$i] - $level[$i-1]) + (1 - $beta) * $damping * $trend[$i-1];
$seasonal[$i+$cycle] = $gamma_*($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) / ($level[$i-1] + $damping * $trend[$i-1]) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[] = ($level[$i] + $this->dampingSum($damping, $i) * $trend[$i-1]) * $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$gamma += 0.01;
}
$beta += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getMultiplicativeNone(int $future, float $damping) : array
{ {
$level = [$this->data[0]];
$trend = [$this->data[1] / $this->data[0]];
$dataLength = count($this->data) + $future;
$forecast = [];
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$level[$i] = $alpha * ($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i));
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
} }
$tempRMSE = Error::getRootMeanSquaredError($error); public function getMAM()
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$beta += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getMultiplicativeAdditive(int $future, int $cycle, float $damping) : array
{ {
$level = [$this->data[0]];
$trend = [1 / $cycle];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
} }
$trend[0] *= $sum; public function getMMN()
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i-1] - $level[0];
}
$alpha = 0.00;
while ($alpha < 1) {
$beta = 0.00;
while($beta < 1) {
$gamma = 0.00;
while($gamma < 1) {
$gamma_ = $gamma * (1 - $alpha);
$error = [];
$tempForecast = [];
for($i = 1; $i < $dataLength; $i++) {
$hm = (int) floor(($i-1) % $cycle) + 1;
$level[$i] = $alpha * (($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $seasonal[$i]) + (1 - $alpha) * $level[$i-1] * pow($trend[$i-1], $damping);
$trend[$i] = $beta * ($level[$i] / $level[$i-1]) + (1 - $beta) * pow($trend[$i-1], $damping);
$seasonal[$i+$cycle] = $gamma_*(($i < $dataLength - $future ? $this->data[$i-1] : $tempForecast[$i-1]) - $level[$i-1] * pow($trend[$i-1], $damping)) + (1 - $gamma_) * $seasonal[$i];
$tempForecast[$i] = $level[$i] * pow($trend[$i], $this->dampingSum($damping, $i)) + $seasonal[$i+$hm];
$error[] = $i < $dataLength - $future ? $this->data[$i] - $tempForecast[$i] : 0;
}
$tempRMSE = Error::getRootMeanSquaredError($error);
if ($tempRMSE < $this->rmse) {
$this->rmse = $tempRMSE;
$forecast = $tempForecast;
}
$gamma += 0.01;
}
$beta += 0.01;
}
$alpha += 0.01;
}
$this->errors = $error;
$this->mse = Error::getMeanSquaredError($error);
$this->mae = Error::getMeanAbsoulteError($error);
$this->sse = Error::getSumSquaredError($error);
return $forecast;
}
public function getMultiplicativeMultiplicative(int $future, int $cycle, float $damping) : array
{ {
$level = [$this->data[0]];
$trend = [1 / $cycle];
$dataLength = count($this->data) + $future;
$forecast = [];
$seasonal = [];
$sum = 0;
for($i = 1; $i < $cycle+1; $i++) {
$sum += ($this->data[$cycle] - $this->data[$i]) / $cycle;
} }
$trend[0] *= $sum; public function getMMA()
{
for($i = 1; $i < $cycle+1; $i++) {
$seasonal[$i] = $this->data[$i] / $level[0];
} }
$alpha = 0.00; public function getMMM()
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;
}
} }

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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 SeasonalType extends Enum abstract class SeasonalType extends Enum

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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 TrendType extends Enum abstract class TrendType extends Enum

View File

@ -4,12 +4,11 @@
* *
* 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;

View File

@ -4,12 +4,11 @@
* *
* 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;
@ -18,4 +17,3 @@ class MA
{ {
} }

View File

@ -4,12 +4,11 @@
* *
* 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;
@ -18,4 +17,3 @@ class NAR
{ {
} }

View File

@ -4,12 +4,11 @@
* *
* 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;
@ -18,4 +17,3 @@ class NMA
{ {
} }

View File

@ -4,12 +4,11 @@
* *
* 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;
@ -18,4 +17,3 @@ class SARIMA
{ {
} }

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -18,11 +17,13 @@ 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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -18,11 +17,13 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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()
{
} }

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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
* *
@ -48,15 +47,16 @@ class Metrics {
/** /**
* 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,12 +4,11 @@
* *
* 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);
@ -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)
* *

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -18,8 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,7 +109,7 @@ 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -18,8 +17,7 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -17,8 +16,6 @@ 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;

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -22,10 +21,9 @@ 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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -22,10 +21,9 @@ 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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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
@ -143,15 +141,13 @@ 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;
} }
/** /**
@ -163,8 +159,7 @@ class FileCache implements CacheInterface
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));
@ -276,8 +271,7 @@ class FileCache implements CacheInterface
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,7 +285,7 @@ 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);
@ -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) {
@ -343,8 +342,7 @@ class FileCache implements CacheInterface
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,7 +351,7 @@ 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);
@ -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());
@ -406,8 +403,7 @@ class FileCache implements CacheInterface
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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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()
{ {

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -26,10 +25,9 @@ use phpOMS\DataStorage\Database\Exception\InvalidMapperException;
* *
* 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
*/ */
class DataMapperAbstract implements DataMapperInterface class DataMapperAbstract implements DataMapperInterface
@ -72,7 +70,7 @@ class DataMapperAbstract implements DataMapperInterface
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static $language_field = ''; protected static $languageField = '';
/** /**
* Columns. * Columns.
@ -149,7 +147,7 @@ class DataMapperAbstract implements DataMapperInterface
/** /**
* Highest mapper to know when to clear initialized objects * Highest mapper to know when to clear initialized objects
* *
* @var DataMapperAbstract * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static $parentMapper = null; protected static $parentMapper = null;
@ -303,7 +301,7 @@ class DataMapperAbstract implements DataMapperInterface
// clear parent and objects // clear parent and objects
if (static::class === self::$parentMapper) { if (static::class === self::$parentMapper) {
self::$initObjects = []; //self::$initObjects = []; // todo: now all objects are cached for the whole request
self::$parentMapper = null; self::$parentMapper = null;
} }
} }
@ -346,13 +344,11 @@ class DataMapperAbstract implements DataMapperInterface
{ {
self::extend(__CLASS__); self::extend(__CLASS__);
if($obj === null || if (!isset($obj) || self::isNullObject($obj)) {
(is_object($obj) && strpos($className = get_class($obj), '\Null') !== false)
) {
return null; return null;
} }
$reflectionClass = new \ReflectionClass($className); $reflectionClass = new \ReflectionClass($obj);
$objId = self::createModel($obj, $reflectionClass); $objId = self::createModel($obj, $reflectionClass);
self::setObjectId($reflectionClass, $obj, $objId); self::setObjectId($reflectionClass, $obj, $objId);
@ -505,7 +501,7 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
private static function getObjectId($obj, \ReflectionClass $reflectionClass = null) private static function getObjectId($obj, \ReflectionClass $reflectionClass = null)
{ {
$reflectionClass = $reflectionClass ?? new \ReflectionClass(get_class($obj)); $reflectionClass = $reflectionClass ?? new \ReflectionClass($obj);
$reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']); $reflectionProperty = $reflectionClass->getProperty(static::$columns[static::$primaryField]['internal']);
if (!($isPublic = $reflectionProperty->isPublic())) { if (!($isPublic = $reflectionProperty->isPublic())) {
@ -594,7 +590,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -689,10 +685,6 @@ class DataMapperAbstract implements DataMapperInterface
private static function createHasOne(\ReflectionClass $reflectionClass, $obj) private static function createHasOne(\ReflectionClass $reflectionClass, $obj)
{ {
throw new \Exception(); throw new \Exception();
foreach (static::$hasOne as $propertyName => $rel) {
}
} }
/** /**
@ -825,8 +817,7 @@ class DataMapperAbstract implements DataMapperInterface
private static function createRelationTable(string $propertyName, array $objsIds, $objId) private static function createRelationTable(string $propertyName, array $objsIds, $objId)
{ {
/** @var string $table */ /** @var string $table */
if ( if (!empty($objsIds)
!empty($objsIds)
&& static::$hasMany[$propertyName]['table'] !== static::$table && static::$hasMany[$propertyName]['table'] !== static::$table
&& static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table && static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table
) { ) {
@ -929,7 +920,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -972,14 +963,11 @@ class DataMapperAbstract implements DataMapperInterface
* *
* Deletes old entries and creates new ones * Deletes old entries and creates new ones
* *
* @param string $propertyName Property name to initialize
* @param array $objsIds Object ids to insert * @param array $objsIds Object ids to insert
* @param mixed $objId Model to reference * @param mixed $objId Model to reference
* *
* @return mixed * @return mixed
* *
* @throws \Exception
*
* @since 1.0.0 * @since 1.0.0
*/ */
private static function updateRelationTable(array $objsIds, $objId) private static function updateRelationTable(array $objsIds, $objId)
@ -1014,8 +1002,7 @@ class DataMapperAbstract implements DataMapperInterface
private static function deleteRelationTable(string $propertyName, array $objsIds, $objId) private static function deleteRelationTable(string $propertyName, array $objsIds, $objId)
{ {
/** @var string $table */ /** @var string $table */
if ( if (!empty($objsIds)
!empty($objsIds)
&& static::$hasMany[$propertyName]['table'] !== static::$table && static::$hasMany[$propertyName]['table'] !== static::$table
&& static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table && static::$hasMany[$propertyName]['table'] !== static::$hasMany[$propertyName]['mapper']::$table
) { ) {
@ -1152,18 +1139,25 @@ class DataMapperAbstract implements DataMapperInterface
* @param mixed $obj Object reference (gets filled with insert id) * @param mixed $obj Object reference (gets filled with insert id)
* @param int $relations Create all relations as well * @param int $relations Create all relations as well
* *
* @return int * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function update($obj, int $relations = RelationType::ALL) : int public static function update($obj, int $relations = RelationType::ALL)
{ {
self::extend(__CLASS__); self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj)); if (!isset($obj) || self::isNullObject($obj)) {
return null;
}
$reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass); $objId = self::getObjectId($obj, $reflectionClass);
$update = true; $update = true;
// todo: maybe don't remove obj and just update cache... ? since it might have to be loaded again
self::removeInitialized(static::class, $objId);
if (empty($objId)) { if (empty($objId)) {
$update = false; $update = false;
self::create($obj, $relations); self::create($obj, $relations);
@ -1227,7 +1221,7 @@ class DataMapperAbstract implements DataMapperInterface
} }
if (!isset($relReflectionClass)) { if (!isset($relReflectionClass)) {
$relReflectionClass = new \ReflectionClass(get_class($value)); $relReflectionClass = new \ReflectionClass($value);
} }
$primaryKey = $mapper::getObjectId($value, $relReflectionClass); $primaryKey = $mapper::getObjectId($value, $relReflectionClass);
@ -1370,13 +1364,15 @@ class DataMapperAbstract implements DataMapperInterface
{ {
self::extend(__CLASS__); self::extend(__CLASS__);
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
$objId = self::getObjectId($obj, $reflectionClass); $objId = self::getObjectId($obj, $reflectionClass);
if (empty($objId)) { if (empty($objId)) {
return null; return null;
} }
self::removeInitialized(static::class, $objId);
if ($relations !== RelationType::NONE) { if ($relations !== RelationType::NONE) {
self::deleteHasMany($reflectionClass, $obj, $objId, $relations); self::deleteHasMany($reflectionClass, $obj, $objId, $relations);
} }
@ -1468,15 +1464,16 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param array[] $result Result set * @param array[] $result Result set
* @param mixed $obj Object to add the relations to * @param mixed $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateManyToMany(array $result, &$obj) /* : void */ public static function populateManyToMany(array $result, &$obj, int $depth = null) /* : void */
{ {
// todo: maybe pass reflectionClass as optional parameter for performance increase // todo: maybe pass reflectionClass as optional parameter for performance increase
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach ($result as $member => $values) { foreach ($result as $member => $values) {
if (!empty($values) && $reflectionClass->hasProperty($member)) { if (!empty($values) && $reflectionClass->hasProperty($member)) {
@ -1484,17 +1481,12 @@ class DataMapperAbstract implements DataMapperInterface
$mapper = static::$hasMany[$member]['mapper']; $mapper = static::$hasMany[$member]['mapper'];
$reflectionProperty = $reflectionClass->getProperty($member); $reflectionProperty = $reflectionClass->getProperty($member);
$values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? []));
if(empty($values)) {
continue;
}
if (!($accessible = $reflectionProperty->isPublic())) { if (!($accessible = $reflectionProperty->isPublic())) {
$reflectionProperty->setAccessible(true); $reflectionProperty->setAccessible(true);
} }
$objects = $mapper::get($values); $objects = $mapper::get($values, RelationType::ALL, null, $depth);
$reflectionProperty->setValue($obj, !is_array($objects) ? [$objects] : $objects); $reflectionProperty->setValue($obj, !is_array($objects) ? [$objects->getId() => $objects] : $objects);
if (!$accessible) { if (!$accessible) {
$reflectionProperty->setAccessible(false); $reflectionProperty->setAccessible(false);
@ -1508,24 +1500,20 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param array[] $result Result set * @param array[] $result Result set
* @param array $obj Object to add the relations to * @param array $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateManyToManyArray(array $result, array &$obj) /* : void */ public static function populateManyToManyArray(array $result, array &$obj, int $depth = null) /* : void */
{ {
foreach ($result as $member => $values) { foreach ($result as $member => $values) {
if (!empty($values)) { if (!empty($values)) {
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$hasMany[$member]['mapper']; $mapper = static::$hasMany[$member]['mapper'];
$values = array_diff($values, array_keys(self::$initObjects[$mapper] ?? []));
if(empty($values)) { $objects = $mapper::getArray($values, RelationType::ALL, $depth);
continue;
}
$objects = $mapper::getArray($values);
$obj[$member] = $objects; $obj[$member] = $objects;
} }
} }
@ -1535,6 +1523,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param mixed $obj Object to add the relations to * @param mixed $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1542,9 +1531,9 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateHasOne(&$obj) /* : void */ public static function populateHasOne(&$obj, int $depth = null) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$hasOne as $member => $one) { foreach (static::$hasOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // todo: is that if necessary? performance is suffering for sure!
@ -1557,13 +1546,15 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$hasOne[$member]['mapper']; $mapper = static::$hasOne[$member]['mapper'];
$id = $reflectionProperty->getValue($obj);
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { if (self::isNullObject($id)) {
$value = self::$initObjects[$mapper][$id]; continue;
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
} }
$id = is_object($id) ? self::getObjectId($id) : $id;
$value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
$reflectionProperty->setValue($obj, $value); $reflectionProperty->setValue($obj, $value);
if (!$accessible) { if (!$accessible) {
@ -1577,6 +1568,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param array $obj Object to add the relations to * @param array $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1584,19 +1576,12 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateHasOneArray(array &$obj) /* : void */ public static function populateHasOneArray(array &$obj, int $depth = null) /* : void */
{ {
foreach (static::$hasOne as $member => $one) { foreach (static::$hasOne as $member => $one) {
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$hasOne[$member]['mapper']; $mapper = static::$hasOne[$member]['mapper'];
$obj[$member] = self::getInitialized($mapper, $obj['member']) ?? $mapper::getArray($obj[$member], RelationType::ALL, $depth);
if(self::isInitialized($mapper, $obj['member'])) {
$value = self::$initObjects[$mapper][$obj['member']];
} else {
$value = $mapper::getArray($obj[$member]);
}
$obj[$member] = $value;
} }
} }
@ -1604,6 +1589,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param mixed $obj Object to add the relations to * @param mixed $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1611,9 +1597,9 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateOwnsOne(&$obj) /* : void */ public static function populateOwnsOne(&$obj, int $depth = null) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$ownsOne as $member => $one) { foreach (static::$ownsOne as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // todo: is that if necessary? performance is suffering for sure!
@ -1626,13 +1612,15 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$ownsOne[$member]['mapper']; $mapper = static::$ownsOne[$member]['mapper'];
$id = $reflectionProperty->getValue($obj);
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { if (self::isNullObject($id)) {
$value = self::$initObjects[$mapper][$id]; continue;
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
} }
$id = is_object($id) ? self::getObjectId($id) : $id;
$value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
$reflectionProperty->setValue($obj, $value); $reflectionProperty->setValue($obj, $value);
if (!$accessible) { if (!$accessible) {
@ -1646,6 +1634,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param array $obj Object to add the relations to * @param array $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1653,19 +1642,12 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateOwnsOneArray(array &$obj) /* : void */ public static function populateOwnsOneArray(array &$obj, int $depth = null) /* : void */
{ {
foreach (static::$ownsOne as $member => $one) { foreach (static::$ownsOne as $member => $one) {
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$ownsOne[$member]['mapper']; $mapper = static::$ownsOne[$member]['mapper'];
$obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::getArray($obj[$member], RelationType::ALL, $depth);
if(self::isInitialized($mapper, $obj[$member])) {
$value = self::$initObjects[$mapper][$obj[$member]];
} else {
$value = $mapper::getArray($obj[$member]);
}
$obj[$member] = $value;
} }
} }
@ -1673,6 +1655,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param mixed $obj Object to add the relations to * @param mixed $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1680,9 +1663,9 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateBelongsTo(&$obj) /* : void */ public static function populateBelongsTo(&$obj, int $depth = null) /* : void */
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach (static::$belongsTo as $member => $one) { foreach (static::$belongsTo as $member => $one) {
// todo: is that if necessary? performance is suffering for sure! // todo: is that if necessary? performance is suffering for sure!
@ -1695,13 +1678,15 @@ class DataMapperAbstract implements DataMapperInterface
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$belongsTo[$member]['mapper']; $mapper = static::$belongsTo[$member]['mapper'];
$id = $reflectionProperty->getValue($obj);
if(self::isInitialized($mapper, ($id = $reflectionProperty->getValue($obj)))) { if (self::isNullObject($id)) {
$value = self::$initObjects[$mapper][$id]; continue;
} else {
$value = $mapper::get($reflectionProperty->getValue($obj));
} }
$id = is_object($id) ? self::getObjectId($id) : $id;
$value = self::getInitialized($mapper, $id) ?? $mapper::get($id, RelationType::ALL, null, $depth);
$reflectionProperty->setValue($obj, $value); $reflectionProperty->setValue($obj, $value);
if (!$accessible) { if (!$accessible) {
@ -1715,6 +1700,7 @@ class DataMapperAbstract implements DataMapperInterface
* Populate data. * Populate data.
* *
* @param array $obj Object to add the relations to * @param array $obj Object to add the relations to
* @param int $depth Relation depth
* *
* @return void * @return void
* *
@ -1722,19 +1708,12 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function populateBelongsToArray(array &$obj) /* : void */ public static function populateBelongsToArray(array &$obj, int $depth = null) /* : void */
{ {
foreach (static::$belongsTo as $member => $one) { foreach (static::$belongsTo as $member => $one) {
/** @var string $mapper */ /** @var string $mapper */
$mapper = static::$belongsTo[$member]['mapper']; $mapper = static::$belongsTo[$member]['mapper'];
$obj[$member] = self::getInitialized($mapper, $obj[$member]) ?? $mapper::get($obj[$member], RelationType::ALL, null, $depth);
if(self::isInitialized($mapper, $obj[$member])) {
$value = self::$initObjects[$mapper][$obj[$member]];
} else {
$value = $mapper::get($obj[$member]);
}
$obj[$member] = $value;
} }
} }
@ -1752,10 +1731,13 @@ class DataMapperAbstract implements DataMapperInterface
*/ */
public static function populateAbstract(array $result, $obj) public static function populateAbstract(array $result, $obj)
{ {
$reflectionClass = new \ReflectionClass(get_class($obj)); $reflectionClass = new \ReflectionClass($obj);
foreach ($result as $column => $value) { foreach ($result as $column => $value) {
if (isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) { if (!isset(static::$columns[$column]['internal']) /* && $reflectionClass->hasProperty(static::$columns[$column]['internal']) */) {
continue;
}
$reflectionProperty = $reflectionClass->getProperty(static::$columns[$column]['internal']); $reflectionProperty = $reflectionClass->getProperty(static::$columns[$column]['internal']);
if (!($accessible = $reflectionProperty->isPublic())) { if (!($accessible = $reflectionProperty->isPublic())) {
@ -1783,7 +1765,6 @@ class DataMapperAbstract implements DataMapperInterface
$reflectionProperty->setAccessible(false); $reflectionProperty->setAccessible(false);
} }
} }
}
return $obj; return $obj;
} }
@ -1829,13 +1810,20 @@ class DataMapperAbstract implements DataMapperInterface
* @param mixed $primaryKey Key * @param mixed $primaryKey Key
* @param int $relations Load relations * @param int $relations Load relations
* @param mixed $fill Object to fill * @param mixed $fill Object to fill
* @param int $depth Relation depth
* *
* @return mixed * @return mixed
* *
* @todo: implement language
*
* @since 1.0.0 * @since 1.0.0
*/ */
public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null) public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null, int $depth = null)
{ {
if (isset($depth) && $depth < 1) {
return $primaryKey;
}
if (!isset(self::$parentMapper)) { if (!isset(self::$parentMapper)) {
self::setUpParentMapper(); self::setUpParentMapper();
} }
@ -1850,6 +1838,7 @@ class DataMapperAbstract implements DataMapperInterface
foreach ($primaryKey as $key => $value) { foreach ($primaryKey as $key => $value) {
if (self::isInitialized(static::class, $value)) { if (self::isInitialized(static::class, $value)) {
$obj[$value] = self::$initObjects[static::class][$value];
continue; continue;
} }
@ -1864,10 +1853,10 @@ class DataMapperAbstract implements DataMapperInterface
$obj[$value]->initialize(); $obj[$value]->initialize();
} }
self::addInitialized(static::class, $value); self::addInitialized(static::class, $value, $obj[$value]);
} }
self::fillRelations($obj, $relations); self::fillRelations($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
$countResulsts = count($obj); $countResulsts = count($obj);
@ -1881,6 +1870,13 @@ class DataMapperAbstract implements DataMapperInterface
return $obj; return $obj;
} }
/**
* Creates the current null object
*
* @return mixed
*
* @since 1.0.0
*/
private static function getNullModelObj() private static function getNullModelObj()
{ {
$class = static::class; $class = static::class;
@ -1898,13 +1894,18 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param mixed $primaryKey Key * @param mixed $primaryKey Key
* @param int $relations Load relations * @param int $relations Load relations
* @param int $depth Relation depth
* *
* @return mixed * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getArray($primaryKey, int $relations = RelationType::ALL) : array public static function getArray($primaryKey, int $relations = RelationType::ALL, int $depth = null) : array
{ {
if (isset($depth) && $depth < 1) {
return $primaryKey;
}
if (!isset(self::$parentMapper)) { if (!isset(self::$parentMapper)) {
self::setUpParentMapper(); self::setUpParentMapper();
} }
@ -1916,15 +1917,16 @@ class DataMapperAbstract implements DataMapperInterface
foreach ($primaryKey as $key => $value) { foreach ($primaryKey as $key => $value) {
if (self::isInitialized(static::class, $value)) { if (self::isInitialized(static::class, $value)) {
$obj[$value] = self::$initObjects[static::class][$value];
continue; continue;
} }
$obj[$value] = self::populateAbstractArray(self::getRaw($value)); $obj[$value] = self::populateAbstractArray(self::getRaw($value));
self::addInitialized(static::class, $value); self::addInitialized(static::class, $value, $obj[$value]);
} }
self::fillRelationsArray($obj, $relations); self::fillRelationsArray($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
return count($obj) === 1 ? reset($obj) : $obj; return count($obj) === 1 ? reset($obj) : $obj;
@ -1937,13 +1939,18 @@ class DataMapperAbstract implements DataMapperInterface
* @param string $ref The field that defines the for * @param string $ref The field that defines the for
* @param int $relations Load relations * @param int $relations Load relations
* @param mixed $fill Object to fill * @param mixed $fill Object to fill
* @param int $depth Relation depth
* *
* @return mixed * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getFor($refKey, string $ref, int $relations = RelationType::ALL, $fill = null) public static function getFor($refKey, string $ref, int $relations = RelationType::ALL, $fill = null, int $depth = null)
{ {
if (isset($depth) && $depth < 1) {
return $refKey;
}
if (!isset(self::$parentMapper)) { if (!isset(self::$parentMapper)) {
self::setUpParentMapper(); self::setUpParentMapper();
} }
@ -1962,7 +1969,7 @@ class DataMapperAbstract implements DataMapperInterface
$toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref)); $toLoad = self::getPrimaryKeysBy($value, self::getColumnByMember($ref));
} }
$obj[$value] = self::get($toLoad, $relations, $fill); $obj[$value] = self::get($toLoad, $relations, $fill, isset($depth) ? --$depth : null);
} }
$countResulsts = count($obj); $countResulsts = count($obj);
@ -2018,20 +2025,25 @@ class DataMapperAbstract implements DataMapperInterface
* Get object. * Get object.
* *
* @param int $relations Load relations * @param int $relations Load relations
* @param int $depth Relation depth
* @param string $lang Language * @param string $lang Language
* *
* @return array * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getAll(int $relations = RelationType::ALL, string $lang = '') : array public static function getAll(int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array
{ {
if (isset($depth) && $depth < 1) {
return null;
}
if (!isset(self::$parentMapper)) { if (!isset(self::$parentMapper)) {
self::setUpParentMapper(); self::setUpParentMapper();
} }
$obj = self::populateIterable(self::getAllRaw($lang)); $obj = self::populateIterable(self::getAllRaw($lang));
self::fillRelations($obj, $relations); self::fillRelations($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
return $obj; return $obj;
@ -2041,20 +2053,25 @@ class DataMapperAbstract implements DataMapperInterface
* Get object. * Get object.
* *
* @param int $relations Load relations * @param int $relations Load relations
* @param int $depth Relation depth
* @param string $lang Language * @param string $lang Language
* *
* @return array * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getAllArray(int $relations = RelationType::ALL, string $lang = '') : array public static function getAllArray(int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array
{ {
if (isset($depth) && $depth < 1) {
return null;
}
if (!isset(self::$parentMapper)) { if (!isset(self::$parentMapper)) {
self::setUpParentMapper(); self::setUpParentMapper();
} }
$obj = self::populateIterableArray(self::getAllRaw($lang)); $obj = self::populateIterableArray(self::getAllRaw($lang));
self::fillRelationsArray($obj, $relations); self::fillRelationsArray($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
return $obj; return $obj;
@ -2085,14 +2102,19 @@ class DataMapperAbstract implements DataMapperInterface
* @param int $limit Newest limit * @param int $limit Newest limit
* @param Builder $query Pre-defined query * @param Builder $query Pre-defined query
* @param int $relations Load relations * @param int $relations Load relations
* @param int $depth Relation depth
* @param string $lang Language * @param string $lang Language
* *
* @return mixed * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, string $lang = '') : array public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, int $depth = null, string $lang = '') : array
{ {
if (isset($depth) && $depth < 1) {
return null;
}
self::extend(__CLASS__); self::extend(__CLASS__);
$query = $query ?? new Builder(self::$db); $query = $query ?? new Builder(self::$db);
@ -2105,8 +2127,8 @@ class DataMapperAbstract implements DataMapperInterface
$query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC'); $query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC');
} }
if (!empty(self::$language_field) && !empty($lang)) { if (!empty(self::$languageField) && !empty($lang)) {
$query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); $query->where(static::$table . '.' . static::$languageField, '=', $lang, 'AND');
} }
$sth = self::$db->con->prepare($query->toSql()); $sth = self::$db->con->prepare($query->toSql());
@ -2115,7 +2137,7 @@ class DataMapperAbstract implements DataMapperInterface
$results = $sth->fetchAll(\PDO::FETCH_ASSOC); $results = $sth->fetchAll(\PDO::FETCH_ASSOC);
$obj = self::populateIterable(is_bool($results) ? [] : $results); $obj = self::populateIterable(is_bool($results) ? [] : $results);
self::fillRelations($obj, $relations); self::fillRelations($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
return $obj; return $obj;
@ -2127,13 +2149,18 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param Builder $query Query * @param Builder $query Query
* @param int $relations Relations * @param int $relations Relations
* @param int $depth Relation depth
* *
* @return array * @return array
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL) : array public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL, int $depth = null) : array
{ {
if (isset($depth) && $depth < 1) {
return null;
}
$sth = self::$db->con->prepare($query->toSql()); $sth = self::$db->con->prepare($query->toSql());
$sth->execute(); $sth->execute();
@ -2141,7 +2168,7 @@ class DataMapperAbstract implements DataMapperInterface
$results = is_bool($results) ? [] : $results; $results = is_bool($results) ? [] : $results;
$obj = self::populateIterable($results); $obj = self::populateIterable($results);
self::fillRelations($obj, $relations); self::fillRelations($obj, $relations, isset($depth) ? --$depth : null);
self::clear(); self::clear();
return $obj; return $obj;
@ -2152,13 +2179,18 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param int $amount Amount of random models * @param int $amount Amount of random models
* @param int $relations Relations type * @param int $relations Relations type
* @param int $depth Relation depth
* *
* @return mixed * @return mixed
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getRandom(int $amount = 1, int $relations = RelationType::ALL) public static function getRandom(int $amount = 1, int $relations = RelationType::ALL, int $depth = null)
{ {
if (isset($depth) && $depth < 1) {
return null;
}
$query = new Builder(self::$db); $query = new Builder(self::$db);
$query->prefix(self::$db->getPrefix()) $query->prefix(self::$db->getPrefix())
->random(static::$primaryField) ->random(static::$primaryField)
@ -2168,7 +2200,7 @@ class DataMapperAbstract implements DataMapperInterface
$sth = self::$db->con->prepare($query->toSql()); $sth = self::$db->con->prepare($query->toSql());
$sth->execute(); $sth->execute();
return self::get($sth->fetchAll(), $relations); return self::get($sth->fetchAll(), $relations, null, $depth);
} }
/** /**
@ -2176,36 +2208,47 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param mixed $obj Objects to fill * @param mixed $obj Objects to fill
* @param int $relations Relations type * @param int $relations Relations type
* @param int $depth Relation depth
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function fillRelations(array &$obj, int $relations = RelationType::ALL) /* : void */ public static function fillRelations(array &$obj, int $relations = RelationType::ALL, int $depth = null) /* : void */
{ {
if (isset($depth) && $depth < 1) {
return;
}
if ($relations === RelationType::NONE) {
return;
}
$hasMany = !empty(static::$hasMany); $hasMany = !empty(static::$hasMany);
$hasOne = !empty(static::$hasOne); $hasOne = !empty(static::$hasOne);
$ownsOne = !empty(static::$ownsOne); $ownsOne = !empty(static::$ownsOne);
$belongsTo = !empty(static::$belongsTo); $belongsTo = !empty(static::$belongsTo);
if ($relations !== RelationType::NONE && ($hasMany || $hasOne || $ownsOne || $belongsTo)) { if (!($hasMany || $hasOne || $ownsOne || $belongsTo)) {
return;
}
foreach ($obj as $key => $value) { foreach ($obj as $key => $value) {
/* loading relations from relations table and populating them and then adding them to the object */ /* loading relations from relations table and populating them and then adding them to the object */
if ($hasMany) { if ($hasMany) {
self::populateManyToMany(self::getHasManyRaw($key, $relations), $obj[$key]); self::populateManyToMany(self::getHasManyRaw($key, $relations), $obj[$key], $depth);
} }
if ($hasOne) { if ($hasOne) {
self::populateHasOne($obj[$key]); self::populateHasOne($obj[$key], $depth);
} }
if ($ownsOne) { if ($ownsOne) {
self::populateOwnsOne($obj[$key]); self::populateOwnsOne($obj[$key], $depth);
} }
if ($belongsTo) { if ($belongsTo) {
self::populateBelongsTo($obj[$key]); self::populateBelongsTo($obj[$key], $depth);
}
} }
} }
} }
@ -2215,36 +2258,47 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @param mixed $obj Objects to fill * @param mixed $obj Objects to fill
* @param int $relations Relations type * @param int $relations Relations type
* @param int $depth Relation depth
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function fillRelationsArray(array &$obj, int $relations = RelationType::ALL) /* : void */ public static function fillRelationsArray(array &$obj, int $relations = RelationType::ALL, int $depth = null) /* : void */
{ {
if (isset($depth) && $depth < 1) {
return null;
}
if ($relations !== RelationType::NONE) {
return;
}
$hasMany = !empty(static::$hasMany); $hasMany = !empty(static::$hasMany);
$hasOne = !empty(static::$hasOne); $hasOne = !empty(static::$hasOne);
$ownsOne = !empty(static::$ownsOne); $ownsOne = !empty(static::$ownsOne);
$belongsTo = !empty(static::$belongsTo); $belongsTo = !empty(static::$belongsTo);
if ($relations !== RelationType::NONE && ($hasMany || $hasOne || $ownsOne || $belongsTo)) { if (!($hasMany || $hasOne || $ownsOne || $belongsTo)) {
return;
}
foreach ($obj as $key => $value) { foreach ($obj as $key => $value) {
/* loading relations from relations table and populating them and then adding them to the object */ /* loading relations from relations table and populating them and then adding them to the object */
if ($hasMany) { if ($hasMany) {
self::populateManyToManyArray(self::getHasManyRaw($key, $relations), $obj[$key]); self::populateManyToManyArray(self::getHasManyRaw($key, $relations), $obj[$key], $depth);
} }
if ($hasOne) { if ($hasOne) {
self::populateHasOneArray($obj[$key]); self::populateHasOneArray($obj[$key], $depth);
} }
if ($ownsOne) { if ($ownsOne) {
self::populateOwnsOneArray($obj[$key]); self::populateOwnsOneArray($obj[$key], $depth);
} }
if ($belongsTo) { if ($belongsTo) {
self::populateBelongsToArray($obj[$key]); self::populateBelongsToArray($obj[$key], $depth);
}
} }
} }
} }
@ -2336,8 +2390,8 @@ class DataMapperAbstract implements DataMapperInterface
{ {
$query = self::getQuery(); $query = self::getQuery();
if (!empty(self::$language_field) && !empty($lang)) { if (!empty(self::$languageField) && !empty($lang)) {
$query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND'); $query->where(static::$table . '.' . static::$languageField, '=', $lang, 'AND');
} }
$sth = self::$db->con->prepare($query->toSql()); $sth = self::$db->con->prepare($query->toSql());
@ -2446,8 +2500,8 @@ class DataMapperAbstract implements DataMapperInterface
public static function getByRequest(RequestAbstract $request) public static function getByRequest(RequestAbstract $request)
{ {
if (!is_null($request->getData('id'))) { if (!is_null($request->getData('id'))) {
$result = static::get($request->getData('id')); $result = static::get((int) $request->getData('id'));
} elseif (!is_null($filter = $request->getData('filter'))) { } elseif (!is_null($filter = ((string) $request->getData('filter')))) {
$filter = strtolower($filter); $filter = strtolower($filter);
if ($filter === 'all') { if ($filter === 'all') {
@ -2457,8 +2511,8 @@ class DataMapperAbstract implements DataMapperInterface
$result = static::get(json_decode($list, true)); $result = static::get(json_decode($list, true));
} else { } else {
$limit = (int) ($request->getData('limit') ?? 1); $limit = (int) ($request->getData('limit') ?? 1);
$from = !is_null($request->getData('from')) ? new \DateTime($request->getData('from')) : null; $from = !is_null($request->getData('from')) ? new \DateTime((string) $request->getData('from')) : null;
$to = !is_null($request->getData('to')) ? new \DateTime($request->getData('to')) : null; $to = !is_null($request->getData('to')) ? new \DateTime((string) $request->getData('to')) : null;
$query = static::getQuery(); $query = static::getQuery();
$query->limit($limit); $query->limit($limit);
@ -2507,11 +2561,43 @@ class DataMapperAbstract implements DataMapperInterface
* *
* @since 1.0.0 * @since 1.0.0
*/ */
private static function isInitialized($mapper, $id) : bool private static function isInitialized(string $mapper, $id) : bool
{ {
return isset(self::$initObjects[$mapper]) && isset(self::$initObjects[$mapper][$id]); return isset(self::$initObjects[$mapper]) && isset(self::$initObjects[$mapper][$id]);
} }
/**
* Get initialized object
*
* @param string $mapper Mapper name
* @param mixed $id Object id
*
* @return mixed
*
* @since 1.0.0
*/
private static function getInitialized(string $mapper, $id)
{
return self::$initObjects[$mapper][$id] ?? null;
}
/**
* Remove initialized object
*
* @param string $mapper Mapper name
* @param mixed $id Object id
*
* @return mixed
*
* @since 1.0.0
*/
private static function removeInitialized(string $mapper, $id)
{
if (self::isInitialized($mapper, $id)) {
unset(self::$initObjects[$mapper][$id]);
}
}
/** /**
* Define the highest mapper of this request * Define the highest mapper of this request
* *
@ -2570,4 +2656,18 @@ class DataMapperAbstract implements DataMapperInterface
throw new \Exception('Invalid member name'); throw new \Exception('Invalid member name');
} }
/**
* Test if object is null object
*
* @param object $obj Object to check
*
* @return bool
*
* @since 1.0.0
*/
private static function isNullObject($obj) : bool
{
return is_object($obj) && strpos(get_class($obj), '\Null') !== false;
}
} }

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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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;
@ -130,5 +128,4 @@ class DatabasePool
return true; return true;
} }
} }

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -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 DatabaseType extends Enum abstract class DatabaseType extends Enum

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,7 +29,7 @@ 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
*/ */

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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,7 +29,7 @@ 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
*/ */

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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
@ -238,24 +236,19 @@ abstract class GrammarAbstract
$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,12 +4,11 @@
* *
* 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);
@ -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,11 +343,38 @@ 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)) {
throw new \Exception();
}
$this->type = QueryType::RAW;
$this->raw = rtrim($raw, ';');
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); $test = strtolower($raw);
if (strpos($test, 'insert') !== false if (strpos($test, 'insert') !== false
@ -364,15 +382,12 @@ class Builder extends BuilderAbstract
|| strpos($test, 'drop') !== false || strpos($test, 'drop') !== false
|| strpos($test, 'delete') !== false || strpos($test, 'delete') !== false
|| strpos($test, 'create') !== false || strpos($test, 'create') !== false
|| strpos($test, 'alter') !== false) { || strpos($test, 'alter') !== false
throw new \Exception(); ) {
} return false;
} }
$this->type = QueryType::RAW; return true;
$this->raw = rtrim($raw, ';');
return $this;
} }
/** /**
@ -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,12 +474,17 @@ 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)) {
$columns = [$columns];
$operator = [$operator];
$values = [$values];
$boolean = [$boolean];
}
$i = 0; $i = 0;
foreach ($columns as $key => $column) { foreach ($columns as $key => $column) {
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) { if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
@ -480,16 +500,6 @@ class Builder extends BuilderAbstract
$i++; $i++;
} }
} elseif (is_string($columns)) {
if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
throw new \InvalidArgumentException('Unknown operator.');
}
$this->wheres[self::getPublicColumnName($columns)][] = ['column' => $columns, 'operator' => $operator, 'value' => $values,
'boolean' => $boolean,];
} else {
throw new \InvalidArgumentException();
}
return $this; return $this;
} }
@ -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
@ -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,6 +854,8 @@ 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
@ -941,10 +961,12 @@ 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
@ -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();
@ -1137,7 +1163,7 @@ class Builder extends BuilderAbstract
} 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,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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:
$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]; 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
* *

View File

@ -4,12 +4,11 @@
* *
* 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);

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,12 +4,11 @@
* *
* 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);
@ -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 JoinType extends Enum abstract class JoinType extends Enum

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);
@ -17,15 +16,13 @@ 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

View File

@ -4,12 +4,11 @@
* *
* 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);
@ -18,10 +17,9 @@ 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,12 +4,11 @@
* *
* 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);
@ -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,12 +4,11 @@
* *
* 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);

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