This commit is contained in:
Dennis Eichhorn 2015-11-29 22:03:06 +01:00
parent 0602cef226
commit 7de136815a
302 changed files with 278923 additions and 0 deletions

390
Account/Account.php Normal file
View File

@ -0,0 +1,390 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
use phpOMS\Localization\Localization;
use phpOMS\Localization\NullLocalization;
/**
* Account manager class.
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Account
{
/**
* Id.
*
* @var \int
* @since 1.0.0
*/
protected $id = 0;
/**
* Names.
*
* @var \string
* @since 1.0.0
*/
protected $name1 = '';
/**
* Names.
*
* @var \string
* @since 1.0.0
*/
protected $name2 = '';
/**
* Names.
*
* @var \string
* @since 1.0.0
*/
protected $name3 = '';
/**
* Email.
*
* @var \string
* @since 1.0.0
*/
protected $email = '';
/**
* Ip.
*
* Used in order to make sure ips don't change
*
* @var \string
* @since 1.0.0
*/
protected $origin = '';
/**
* Login.
*
* @var \string
* @since 1.0.0
*/
protected $login = '';
/**
* Last activity.
*
* @var \DateTime
* @since 1.0.0
*/
protected $lastActive = null;
/**
* Permissions.
*
* @var array
* @since 1.0.0
*/
protected $permissions = [];
/**
* Groups.
*
* @var \int[]
* @since 1.0.0
*/
protected $groups = [];
/**
* Account type.
*
* @var AccountType
* @since 1.0.0
*/
protected $type = AccountType::USER;
/**
* Account status.
*
* @var AccountStatus
* @since 1.0.0
*/
protected $status = AccountStatus::INACTIVE;
/**
* Localization.
*
* @var Localization
* @since 1.0.0
*/
protected $l11n = null;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* Get account id.
*
* @return \int Account id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : \int
{
return $this->id;
}
/**
* Get localization.
*
* @return Localization
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getL11n() : Localization
{
return $this->l11n ?? new NullLocalization();
}
/**
* Set localization.
*
* @param Localization $l11n Localization
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setL11n(Localization $l11n)
{
$this->l11n = $l11n;
}
/**
* Get name1.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName1() : \string
{
return $this->name1;
}
/**
* Get name2.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName2() : \string
{
return $this->name2;
}
/**
* Get name3.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName3() : \string
{
return $this->name3;
}
/**
* Get email.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEmail() : \string
{
return $this->email;
}
/**
* Get status.
*
* AccountStatus
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getStatus() : \int
{
return $this->status;
}
/**
* Get type.
*
* AccountType
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : \int
{
return $this->type;
}
/**
* Get last activity.
*
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLastActive() : \DateTime
{
return $this->lastActive ?? new \DateTime('NOW');
}
/**
* Set name1.
*
* @param \string $name Name
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName1(\string $name)
{
$this->name1 = $name;
}
/**
* Set name2.
*
* @param \string $name Name
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName2(\string $name)
{
$this->name2 = $name;
}
/**
* Set name3.
*
* @param \string $name Name
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName3(\string $name)
{
$this->name3 = $name;
}
/**
* Set email.
*
* @param \string $email Email
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setEmail(\string $email)
{
$this->email = $email;
}
/**
* Get status.
*
* @param \int $status Status
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setStatus(\int $status)
{
$this->status = $status;
}
/**
* Get type.
*
* @param \int $type Type
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setType(\int $type)
{
$this->type = $type;
}
/**
* Get last activity.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function updateLastActive()
{
$this->lastActive = new \DateTime('NOW');
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
/**
* Account manager class.
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class AccountManager
{
/**
* Accounts.
*
* @var Account[]
* @since 1.0.0
*/
private $accounts = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* Get account.
*
* @param \int $id Account id
*
* @return Account
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get(\int $id) : Account
{
return $this->accounts[$id] ?? new NullAccount();
}
/**
* Set account.
*
* @param Account $account Account
*
* @return \int Account id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set(Account $account)
{
if (!isset($this->accounts[$account->getId()])) {
$this->accounts[$account->getId()] = $account;
return $account->getId();
}
return null;
}
}

37
Account/AccountStatus.php Normal file
View File

@ -0,0 +1,37 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
use phpOMS\Datatypes\Enum;
/**
* Account type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class AccountStatus extends Enum
{
const ACTIVE = 1;
const INACTIVE = 2;
const TIMEOUT = 3;
const BANNED = 4;
}

35
Account/AccountType.php Normal file
View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
use phpOMS\Datatypes\Enum;
/**
* Account type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class AccountType extends Enum
{
const USER = 0;
const GROUP = 1;
}

141
Account/Group.php Normal file
View File

@ -0,0 +1,141 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
class Group
{
/**
* Account id.
*
* @var \int
* @since 1.0.0
*/
protected $id = 0;
/**
* Account name.
*
* @var \string
* @since 1.0.0
*/
protected $name = '';
/**
* Account name.
*
* @var \string
* @since 1.0.0
*/
protected $description = '';
/**
* Account name.
*
* @var \int
* @since 1.0.0
*/
protected $members = [];
/**
* Parents .
*
* @var \int[]
* @since 1.0.0
*/
protected $parents = [];
/**
* Permissions.
*
* @var \int[]
* @since 1.0.0
*/
protected $permissions = [];
/**
* Multition cache.
*
* @var \Model\Account[]
* @since 1.0.0
*/
private static $instances = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* Multition constructor.
*
* @param \int $id Account id
*
* @return \phpOMS\Account\Group
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getInstance($id)
{
return self::$instances[$id] = self::$instances[$id] ?? new self();
}
/**
* Get account id.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId()
{
return $this->id;
}
/**
* Get account name.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : \string
{
return $this->name;
}
/**
* Get group description.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDescription() : \string
{
return $this->description;
}
}

31
Account/NullAccount.php Normal file
View File

@ -0,0 +1,31 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Account;
/**
* Null account class.
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class NullAccount extends Account
{
}

127
ApplicationAbstract.php Normal file
View File

@ -0,0 +1,127 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS;
/**
* Application class.
*
* @category Framework
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ApplicationAbstract
{
/**
* Database object.
*
* @var \phpOMS\DataStorage\Database\Pool
* @since 1.0.0
*/
public $dbPool = null;
/**
* Application settings object.
*
* @var \Model\CoreSettings
* @since 1.0.0
*/
public $appSettings = null;
/**
* Account manager instance.
*
* @var \phpOMS\Account\AccountManager
* @since 1.0.0
*/
public $accountManager = null;
/**
* Cache instance.
*
* @var \phpOMS\DataStorage\Cache\CacheManager
* @since 1.0.0
*/
public $cacheManager = null;
/**
* ModuleManager instance.
*
* @var \phpOMS\Module\ModuleManager
* @since 1.0.0
*/
public $moduleManager = null;
/**
* Router instance.
*
* @var \phpOMS\Router\Router
* @since 1.0.0
*/
public $router = null;
/**
* Dispatcher instance.
*
* @var \phpOMS\Dispatcher\Dispatcher
* @since 1.0.0
*/
public $dispatcher = null;
/**
* Session instance.
*
* @var \phpOMS\DataStorage\Session\SessionInterface
* @since 1.0.0
*/
public $sessionManager = null;
/**
* Server localization.
*
* @var \phpOMS\Localization\Localization
* @since 1.0.0
*/
public $l11nServer = null;
/**
* Server localization.
*
* @var \phpOMS\Log\FileLogger
* @since 1.0.0
*/
public $logger = null;
/**
* L11n manager.
*
* @var \phpOMS\Localization\L11nManager
* @since 1.0.0
*/
public $l11nManager = null;
/**
* Event manager.
*
* @var \phpOMS\Event\EventManager
* @since 1.0.0
*/
public $eventManager = null;
}

119
Asset/AssetManager.php Normal file
View File

@ -0,0 +1,119 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Asset;
use phpOMS\DataStorage\Database\Pool;
/**
* Asset manager class.
*
* Responsible for authenticating and initializing the connection
*
* @category Framework
* @package phpOMS\Asset
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class AssetManager
{
/**
* Assets.
*
* @var array
* @since 1.0.0
*/
private $assets = [];
/**
* Constructor.
*
* @param Pool $dbPool Database pool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(Pool $dbPool)
{
}
/**
* Add asset.
*
* @param \string $id Asset id
* @param \string $asset Asset
* @param \bool $overwrite Overwrite
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set(\string $id, \string $asset, \bool $overwrite = true) : \bool
{
if ($overwrite || !isset($this->assets[$id])) {
$this->assets[$id] = $asset;
return true;
}
return false;
}
/**
* Remove asset.
*
* @param \string $id Asset id
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function remove(\string $id) : \bool
{
if (isset($this->assets[$id])) {
unset($this->assets[$id]);
return true;
}
return false;
}
/**
* Get asset.
*
* @param \string $id Asset id
*
* @return mixed Asset
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get(\string $id)
{
if (isset($this->assets[$id])) {
return $this->assets[$id];
}
return null;
}
}

37
Asset/AssetType.php Normal file
View File

@ -0,0 +1,37 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Asset;
use phpOMS\Datatypes\Enum;
/**
* Login return types enum.
*
* These are possible answers to authentications.
*
* @category Framework
* @package phpOMS\Auth
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class AssetType extends Enum
{
const CSS = 'css';
const JS = 'js';
}

165
Auth/Auth.php Normal file
View File

@ -0,0 +1,165 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Auth;
use phpOMS\Config\OptionsInterface;
use phpOMS\Config\OptionsTrait;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Session\SessionInterface;
/**
* Auth class.
*
* Responsible for authenticating and initializing the connection
*
* @category Framework
* @package phpOMS\Auth
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Auth implements OptionsInterface
{
use OptionsTrait;
/**
* Session instance.
*
* @var SessionInterface
* @since 1.0.0
*/
private $session = null;
/**
* Database connection instance.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
private $connection = null;
/**
* Constructor.
*
* @param ConnectionAbstract $connection Database connection
* @param SessionInterface $session Session
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(ConnectionAbstract $connection, SessionInterface $session)
{
$this->connection = $connection;
$this->session = $session;
}
/**
* Authenticates user.
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function authenticate() : \bool
{
$uid = $this->session->get('UID');
if ($uid === null) {
$uid = false;
}
return $uid;
}
/**
* Login user.
*
* @param \string $login Username
* @param \string $password Password
*
* @return \int Login code
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function login(\string $login, \string $password) : \int
{
try {
$result = null;
switch ($this->connection->getType()) {
case DatabaseType::MYSQL:
$sth = $this->connection->con->prepare(
'SELECT
`' . $this->connection->prefix . 'account`.*
FROM
`' . $this->connection->prefix . 'account`
WHERE
`account_login` = :login'
);
$sth->bindValue(':login', $login, \PDO::PARAM_STR);
$sth->execute();
$result = $sth->fetchAll();
break;
}
// TODO: check if user is allowed to login on THIS page (backend|frontend|etc...)
if (!isset($result[0])) {
return LoginReturnType::WRONG_USERNAME;
}
$result = $result[0];
if ($result['account_tries'] <= 0) {
return LoginReturnType::WRONG_INPUT_EXCEEDED;
}
if (password_verify($password, $result['account_password'])) {
$this->session->set('UID', $result['account_id']);
$this->session->save();
return LoginReturnType::OK;
}
return LoginReturnType::WRONG_PASSWORD;
} catch (\Exception $e) {
return LoginReturnType::FAILURE;
}
}
/**
* Logout the given user.
*
* @param \int $uid User ID
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function logout(\int $uid)
{
// TODO: logout other users? If admin wants to kick a user for updates etc.
$this->session->remove('UID');
}
}

45
Auth/LoginReturnType.php Normal file
View File

@ -0,0 +1,45 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Auth;
use phpOMS\Datatypes\Enum;
/**
* Login return types enum.
*
* These are possible answers to authentications.
*
* @category Framework
* @package phpOMS\Auth
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class LoginReturnType extends Enum
{
const OK = 0; /* Everything is ok and the user got authed */
const FAILURE = 1; /* Authentication resulted in a unexpected failure */
const WRONG_PASSWORD = 2; /* Authentication with wrong password */
const WRONG_USERNAME = 3; /* Authentication with unknown user */
const WRONG_PERMISSION = 4; /* User doesn't have permission to authenticate */
const NOT_ACTIVATED = 5; /* The user is not activated yet */
const WRONG_INPUT_EXCEEDED = 6; /* Too many wrong logins recently */
const TIMEOUTED = 7; /* User received a timeout and can not log in until a certain date */
const BANNED = 8; /* User is banned */
const INACTIVE = 9; /* User is inactive */
}

75
Autoloader.php Normal file
View File

@ -0,0 +1,75 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS;
spl_autoload_register('\phpOMS\Autoloader::default_autoloader');
/**
* Autoloader class.
*
* @category Framework
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Autoloader
{
/**
* Loading classes by namespace + class name.
*
* @param \string $class Class path
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function default_autoloader(\string $class)
{
if (($class = self::exists($class)) !== false) {
/** @noinspection PhpIncludeInspection */
include __DIR__ . '/../' . $class . '.php';
}
}
/**
* Check if class exists.
*
* @param \string $class Class path
*
* @return false|string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function exists(\string $class)
{
$class = ltrim($class, '\\');
$class = str_replace(['_', '\\'], DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . '/../' . $class . '.php')) {
return $class;
}
return false;
}
}

View File

@ -0,0 +1,83 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Config;
/**
* Options class.
*
* @category Framework
* @package phpOMS\Config
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface OptionsInterface
{
/**
* Is this key set.
*
* @param mixed $key Key to check for existence
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function exists($key);
/**
* Updating or adding settings.
*
* @param mixed $key Unique option key
* @param mixed $value Option value
* @param \bool $overwrite Overwrite existing value
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setOption($key, $value, \bool $overwrite = true) : \bool;
/**
* Updating or adding settings.
*
* @param array $pair Key value pair
* @param \bool $overwrite Overwrite existing value
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setOptions(array $pair, \bool $overwrite = true) : \bool;
/**
* Get option by key.
*
* @param mixed $key Unique option key
*
* @return mixed Option value
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getOption($key);
}

80
Config/OptionsTrait.php Normal file
View File

@ -0,0 +1,80 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Config;
/**
* Options trait.
*
* @category Framework
* @package phpOMS\Config
* @since 1.0.0
*/
trait OptionsTrait
{
/**
* Options.
*
* @var array
* @since 1.0.0
*/
private $options = [];
/**
* {@inheritdoc}
*/
public function exists($key)
{
return array_key_exists($key, $this->options);
}
/**
* {@inheritdoc}
*/
public function getOption($key)
{
return $this->options[$key] ?? null;
}
/**
* {@inheritdoc}
*/
public function setOption($key, $value, \bool $overwrite = true) : \bool
{
if ($overwrite || !array_key_exists($key, $this->options)) {
$this->options[$key] = [$value, $overwrite];
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function setOptions(array $pair, \bool $overwrite = true) : \bool
{
if ($overwrite) {
$this->options += $pair;
return true;
}
return false;
}
}

134
Config/SettingsAbstract.php Normal file
View File

@ -0,0 +1,134 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Config;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Builder;
/**
* Settings class.
*
* Responsible for providing a database/cache bound settings manger
*
* @category Framework
* @package phpOMS\Config
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class SettingsAbstract implements OptionsInterface
{
use OptionsTrait;
/**
* Cache manager (pool).
*
* @var \phpOMS\DataStorage\Cache\CacheManager
* @since 1.0.0
*/
protected $cache = null;
/**
* Database connection instance.
*
* @var \phpOMS\DataStorage\Database\Connection\ConnectionAbstract
* @since 1.0.0
*/
protected $connection = null;
/**
* Settings table.
*
* @var \string
* @since 1.0.0
*/
protected static $table = null;
/**
* Columns to identify the value.
*
* @var \string[]
* @since 1.0.0
*/
protected static $columns = [
'id',
];
/**
* Field where the actual value is stored.
*
* @var \string
* @since 1.0.0
*/
protected $valueField = 'option';
/**
* Get option by key.
*
* @param \string[] $columns Column values for filtering
*
* @return mixed Option value
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get(array $columns)
{
$options = false;
switch ($this->connection->getType()) {
case DatabaseType::MYSQL:
$query = new Builder($this->connection);
$sql = $query->select(static::$columns[0], 'settings_content')
->from($this->connection->prefix . static::$table)
->where(static::$columns[0], 'in', $columns)
->toSql();
$sth = $this->connection->con->prepare($sql);
$sth->execute();
$options = $sth->fetchAll(\PDO::FETCH_KEY_PAIR);
$this->setOptions($options);
break;
}
return $options;
}
/**
* Set option by key.
*
* @param \string[] $options Column values for filtering
* @param \bool $overwrite Overwrite existing settings
* @param \bool $store Save this Setting immediately to database
*
* @return mixed Option value
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set(array $options, \bool $overwrite = true, \bool $store = false)
{
$this->setOptions($options, $overwrite);
if($store) {
// save to db
}
}
}

137
Console/CommandManager.php Normal file
View File

@ -0,0 +1,137 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Console;
/**
* CommandManager class.
*
* @category Framework
* @package phpOMS\Socket
* @since 1.0.0
*
* @todo : Hey, this looks like a copy of an event manager!
*/
class CommandManager implements \Countable
{
/**
* Commands.
*
* @var mixed[]
* @since 1.0.0
*/
private $commands = [];
/**
* Commands.
*
* @var \int
* @since 1.0.0
*/
private $count = 0;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* Attach new command.
*
* @param \string $cmd Command ID
* @param mixed $callback Function callback
* @param mixed $source Provider
* @param \bool $overwrite Overwrite existing
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function attach(\string $cmd, $callback, $source, \bool $overwrite = true) : \bool
{
if ($overwrite || !isset($this->commands[$cmd])) {
$this->commands[$cmd] = [$callback, $source];
$this->count++;
return true;
}
return false;
}
/**
* Detach existing command.
*
* @param \string $cmd Command ID
* @param mixed $source Provider
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function detach(\string $cmd, $source) : \bool
{
if (array_key_exists($cmd, $this->commands)) {
unset($this->commands[$cmd]);
$this->count--;
return true;
}
return false;
}
/**
* Trigger command.
*
* @param \string $cmd Command ID
* @param mixed $para Parameters to pass
*
* @return mixed|bool
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function trigger(\string $cmd, $para)
{
if (array_key_exists($cmd, $this->commands)) {
return $this->commands[$cmd][0]($para);
}
return false;
}
/**
* Count commands.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn
*/
public function count() : \int
{
return $this->count;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Contract;
/**
* Defines an object arrayable.
*
* This stands always in combination with a jsonable instance.
*
* @category Framework
* @package phpOMS\Contract
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface ArrayableInterface
{
/**
* Get the instance as an array.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function toArray() : array;
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Contract;
/**
* This is contract expects a class to be serializable via json.
*
* This is used in order to distinguish between serialize and json_encode
*
* @category Framework
* @package phpOMS\Contract
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface JsonableInterface extends ArrayableInterface
{
/**
* Convert the object to its JSON representation.
*
* @param \int $options
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function toJson(\int $options = 0) : \string;
}

31
Contract/Object.php Normal file
View File

@ -0,0 +1,31 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Contract;
/**
* Degenerate interface for type hinting object.
*
* @category Framework
* @package phpOMS\Contract
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface Object
{
}

View File

@ -0,0 +1,45 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Contract;
/**
* Make a class renderable.
*
* This is primarily used for classes that provide formatted output or output,
* that get's rendered in third party applications.
*
* @category Framework
* @package phpOMS\Contract
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface RenderableInterface
{
/**
* Get the evaluated contents of the object.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function render() : \string;
}

View File

@ -0,0 +1,135 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
/**
* Cache interface.
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface CacheInterface
{
/**
* Updating or adding cache data.
*
* @param mixed $key Unique cache key
* @param mixed $value Cache value
* @param CacheStatus $type Cache type
* @param \int $expire Valid duration (in s)
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000);
/**
* Adding new data if it doesn't exist.
*
* @param mixed $key Unique cache key
* @param mixed $value Cache value
* @param CacheStatus $type Cache type
* @param \int $expire Valid duration (in s)
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000) : \bool;
/**
* Get cache by key.
*
* @param mixed $key Unique cache key
* @param CacheStatus $type Cache status/type
*
* @return mixed Cache value
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($key, CacheStatus $type = null);
/**
* Remove value by key.
*
* @param mixed $key Unique cache key
* @param CacheStatus $type Cache status/type
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function delete($key, CacheStatus $type = null) : \bool;
/**
* Removing all elements from cache (invalidate cache).
*
* @param CacheStatus $type Cache status/type
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function flush(CacheStatus $type = null);
/**
* Updating existing value/key.
*
* @param mixed $key Unique cache key
* @param mixed $value Cache value
* @param CacheType $type Cache type
* @param \int $expire Timestamp
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1) : \bool;
/**
* Requesting cache stats.
*
* @return mixed[] Stats array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function stats() : array;
/**
* Get the threshold required to cache data using this cache.
*
* @return \int Storage threshold
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getThreshold() : \int;
}

View File

@ -0,0 +1,248 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
use phpOMS\Config\OptionsInterface;
use phpOMS\Config\OptionsTrait;
use phpOMS\DataStorage\Database\Pool;
/**
* Cache class.
*
* Responsible for caching scalar data types and arrays.
* Caching HTML output and objects coming soon/is planned.
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class CacheManager implements OptionsInterface
{
use OptionsTrait;
/**
* MemCache instance.
*
* @var \phpOMS\DataStorage\Cache\MemCache
* @since 1.0.0
*/
private $memc = null;
/**
* RedisCache instance.
*
* @var \phpOMS\DataStorage\Cache\RedisCache
* @since 1.0.0
*/
private $redisc = null;
/**
* RedisCache instance.
*
* @var \phpOMS\DataStorage\Cache\WinCache
* @since 1.0.0
*/
private $winc = null;
/**
* FileCache instance.
*
* @var \phpOMS\DataStorage\Cache\FileCache
* @since 1.0.0
*/
private $filec = null;
/**
* FileCache instance.
*
* @var Pool
* @since 1.0.0
*/
private $dbPool = null;
/**
* Constructor.
*
* @param Pool $dbPool Database pool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(Pool $dbPool)
{
$this->dbPool = $dbPool;
}
/**
* Init cache.
*
* @param mixed $options Options used to initialize the different caching types
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function init($options = null)
{
if ($options === null) {
/* This is costing me 1ms, maybe init settings first cause i'm making another settings call later on -> same call 2 times */
$sth = $this->dbPool->get('core')->con->prepare('SELECT `content` FROM `' . $this->dbPool->get('core')->prefix . 'settings` WHERE `id` = 1000000015');
$sth->execute();
$cache_data = $sth->fetchAll();
$this->setOption('cache:type', (int) $cache_data[0][0]);
} else {
$this->options = $options;
}
}
/**
* {@inheritdoc}
*/
public function update()
{
}
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
$this->getInstance($type)->set($key, $value, $type = null, $expire);
}
/**
* Requesting caching instance.
*
* @param CacheStatus $type Cache to request
*
* @return \phpOMS\DataStorage\Cache\MemCache|\phpOMS\DataStorage\Cache\FileCache|null
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getInstance(CacheStatus $type = null)
{
if (($type === null || $type === CacheStatus::MEMCACHE) && $this->memc !== null) {
return $this->memc;
}
if (($type === null || $type === CacheStatus::REDISCACHE) && $this->redisc !== null) {
return $this->redisc;
}
if (($type === null || $type === CacheStatus::WINCACHE) && $this->winc !== null) {
return $this->winc;
}
if (($type === null || $type === CacheStatus::FILECACHE) && $this->filec !== null) {
return $this->filec;
}
return new NullCache();
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
$this->getInstance($type)->add($key, $value, $type = null, $expire);
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
return $this->getInstance($type)->get($key);
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
$this->getInstance($type)->delete($key);
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
if ($type === null) {
$this->filec->flush();
$this->memc->flush();
} elseif ($type === CacheStatus::MEMCACHE) {
$this->memc->flush();
} elseif ($type === CacheStatus::FILECACHE) {
$this->filec->flush();
}
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null)
{
$this->getInstance($type)->replace($key, $value);
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
$stats = [];
if ($this->memc !== null) {
$stats['memc'] = $this->memc->stats();
}
if ($this->filec !== null) {
$stats['filec'] = $this->filec->stats();
}
return $stats;
}
/**
* {@inheritdoc}
*/
public function getThreshold() : array
{
$threshold = [];
if ($this->memc !== null) {
$threshold['memc'] = $this->memc->getThreshold();
}
if ($this->filec !== null) {
$threshold['filec'] = $this->filec->getThreshold();
}
return $threshold;
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
use phpOMS\Datatypes\Enum;
/**
* Cache status enum.
*
* Possible caching status
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class CacheStatus extends Enum
{
const INACTIVE = 0; /* Caching is disabled */
const ERROR = 1; /* Caching failed */
const MEMCACHE = 2; /* Caching OK */
const FILECACHE = 3; /* Caching OK */
const REDISCACHE = 4; /* Caching OK */
const WINCACHE = 5; /* Caching OK */
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
use phpOMS\Datatypes\Enum;
/**
* Cache type enum.
*
* Possible caching types
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class CacheType extends Enum
{
const _NUMERIC = 0; /* Data is numeric */
const _STRING = 1; /* Data is string */
const _ARRAY = 2; /* Data is array */
const _OBJECT = 3; /* Data is object */
const _HEX = 4; /* Data is object */
}

View File

@ -0,0 +1,116 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
use phpOMS\System\FileSystem;
/**
* MemCache class.
*
* PHP Version 5.6
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class FileCache implements CacheInterface
{
/**
* Cache path.
*
* @var \string
* @since 1.0.0
*/
const CACHE_PATH = __DIR__ . '/../../../Cache';
/**
* Only cache if data is larger than threshold (0-100).
*
* @var \int
* @since 1.0.0
*/
private $threshold = 50;
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
array_map('unlink', glob(self::CACHE_PATH . '/*'));
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1)
{
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
$stats = [];
$stats['count'] = FileSystem::getFileCount(self::CACHE_PATH);
// size, avg. last change compared to now
return $stats;
}
/**
* {@inheritdoc}
*/
public function getThreshold() : \int
{
return $this->threshold;
}
}

View File

@ -0,0 +1,163 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
/**
* Memcache class.
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class MemCache 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;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->memc = new self();
}
/**
* Adding server to server pool.
*
* @param mixed $data Server data array
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function addServer($data)
{
$this->memc->addServer($data['host'], $data['port'], $data['timeout']);
}
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
$this->memc->set($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
return $this->memc->add($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
return $this->memc->get($key);
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
$this->memc->delete($key);
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
$this->memc->flush();
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1)
{
$this->memc->replace($key, $value, false, $expire);
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
return $this->memc->getExtendedStats();
}
/**
* {@inheritdoc}
*/
public function getThreshold() : \int
{
return $this->threshold;
}
/**
* Destructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __destruct()
{
$this->close();
}
/**
* Closing cache.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function close()
{
if ($this->memc !== null) {
$this->memc->close();
$this->memc = null;
}
}
}

View File

@ -0,0 +1,96 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
/**
* Null cache class.
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class NullCache implements CacheInterface
{
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement set() method.
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement add() method.
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
// TODO: Implement get() method.
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
// TODO: Implement delete() method.
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
// TODO: Implement flush() method.
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1)
{
// TODO: Implement replace() method.
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
// TODO: Implement stats() method.
}
/**
* {@inheritdoc}
*/
public function getThreshold() : \int
{
// TODO: Implement getThreshold() method.
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
/**
* RedisCache class.
*
* PHP Version 5.6
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class RedisCache implements CacheInterface
{
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement set() method.
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement add() method.
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
// TODO: Implement get() method.
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
// TODO: Implement delete() method.
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
// TODO: Implement flush() method.
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1)
{
// TODO: Implement replace() method.
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
// TODO: Implement stats() method.
}
/**
* {@inheritdoc}
*/
public function getThreshold() : \int
{
// TODO: Implement getThreshold() method.
}
}

View File

@ -0,0 +1,98 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Cache;
/**
* WinCache class.
*
* PHP Version 5.6
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class WinCache implements CacheInterface
{
/**
* {@inheritdoc}
*/
public function set($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement set() method.
}
/**
* {@inheritdoc}
*/
public function add($key, $value, CacheStatus $type = null, \int $expire = 2592000)
{
// TODO: Implement add() method.
}
/**
* {@inheritdoc}
*/
public function get($key, CacheStatus $type = null)
{
// TODO: Implement get() method.
}
/**
* {@inheritdoc}
*/
public function delete($key, CacheStatus $type = null)
{
// TODO: Implement delete() method.
}
/**
* {@inheritdoc}
*/
public function flush(CacheStatus $type = null)
{
// TODO: Implement flush() method.
}
/**
* {@inheritdoc}
*/
public function replace($key, $value, CacheType $type = null, \int $expire = -1)
{
// TODO: Implement replace() method.
}
/**
* {@inheritdoc}
*/
public function stats() : array
{
// TODO: Implement stats() method.
}
/**
* {@inheritdoc}
*/
public function getThreshold() : \int
{
// TODO: Implement getThreshold() method.
}
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
/*
NOT IN USE
Will be implemented later
*/
/* TODO: implement */
namespace phpOMS\Cookie;
/**
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
class CookieJar
{
}

View File

@ -0,0 +1,138 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage;
use phpOMS\DataStorage\Database\Query\Builder;
/**
* Datamapper interface.
*
* DB, Cache, Session
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface DataMapperInterface
{
/**
* Update data.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function update();
/**
* Save data.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function save();
/**
* Delete data.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function delete();
/**
* Find data.
*
* @param array $columns Columns
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function find(...$columns) : Builder;
/**
* List data.
*
* @param Builder $query Query
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function listResults(Builder $query);
/**
* Populate data.
*
* @param array $result Result set
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populate(array $result);
/**
* Populate data.
*
* @param array $result Result set
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populateIterable(array $result) : array;
/**
* Load.
*
* @param array $objects Objects to load
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function with(...$objects);
/**
* Get object.
*
* @param mixed $primaryKey Key
*
* @return self
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($primaryKey);
}

View File

@ -0,0 +1,153 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
/**
* Database handler.
*
* Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away).
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class ConnectionAbstract implements ConnectionInterface
{
/**
* Connection object.
*
* This can be used externally to define queries and execute them.
*
* @var \PDO
* @since 1.0.0
*/
public $con = null;
/**
* Database prefix.
*
* The database prefix name for unique table names
*
* @var \string
* @since 1.0.0
*/
public $prefix = '';
/**
* Database data.
*
* @var \string[]
* @since 1.0.0
*/
protected $dbdata = null;
/**
* Database type.
*
* @var \phpOMS\DataStorage\Database\DatabaseType
* @since 1.0.0
*/
protected $type = null;
/**
* Database status.
*
* @var DatabaseStatus
* @since 1.0.0
*/
protected $status = DatabaseStatus::CLOSED;
/**
* Database grammar.
*
* @var Grammar
* @since 1.0.0
*/
protected $grammar = null;
/**
* {@inheritdoc}
*/
public function getType() : \int
{
return $this->type;
}
/**
* {@inheritdoc}
*/
public function getStatus() : \int
{
return $this->status;
}
/**
* Get table prefix.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPrefix() : \string
{
return $this->prefix;
}
/**
* {@inheritdoc}
*/
public function getGrammar() : Grammar
{
if (!isset($this->grammar)) {
$this->grammar = new Grammar();
}
return $this->grammar;
}
/**
* Object destructor.
*
* Sets the database connection to null
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __destruct()
{
$this->close();
}
/**
* {@inheritdoc}
*/
public function close()
{
$this->con = null;
$this->status = DatabaseStatus::CLOSED;
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
/**
* Database connection factory.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ConnectionFactory
{
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function __construct()
{
}
/**
* Create database connection.
*
* Overwrites current connection if existing
*
* @param \string[] $dbdata the basic database information for establishing a connection
*
* @return ConnectionInterface
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create(array $dbdata) : ConnectionInterface
{
switch ($dbdata['db']) {
case 'mysql':
return new MysqlConnection($dbdata);
break;
default:
throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.');
}
}
}

View File

@ -0,0 +1,88 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
/**
* Database connection interface.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface ConnectionInterface
{
/**
* Connect to database.
*
* Overwrites current connection if existing
*
* @param \string[] $dbdata the basic database information for establishing a connection
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function connect(array $dbdata);
/**
* Get the database type.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : \int;
/**
* Get the database status.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getStatus() : \int;
/**
* Close database connection.
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function close();
/**
* Return grammar for this connection.
*
* @return Grammar
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getGrammar() : Grammar;
}

View File

@ -0,0 +1,78 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
/**
* Database handler.
*
* Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away).
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class MysqlConnection extends ConnectionAbstract
{
/**
* Object constructor.
*
* Creates the database object and overwrites all default values.
*
* @param \string[] $dbdata the basic database information for establishing a connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(array $dbdata)
{
$this->type = DatabaseType::MYSQL;
$this->grammar = new MysqlGrammar();
$this->connect($dbdata);
}
/**
* {@inheritdoc}
*/
public function connect(array $dbdata = null)
{
$this->close();
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
$this->prefix = $dbdata['prefix'];
try {
$this->con = new \PDO($this->dbdata['db'] . ':host=' . $this->dbdata['host'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->status = DatabaseStatus::OK;
} catch (\PDOException $e) {
$this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
}
}
}

View File

@ -0,0 +1,78 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Grammar\SqliteGrammar;
/**
* Database handler.
*
* Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away).
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class SqliteConnection extends ConnectionAbstract
{
/**
* Object constructor.
*
* Creates the database object and overwrites all default values.
*
* @param \string[] $dbdata the basic database information for establishing a connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(array $dbdata)
{
$this->type = DatabaseType::MYSQL;
$this->grammar = new SqliteGrammar();
$this->connect($dbdata);
}
/**
* {@inheritdoc}
*/
public function connect(array $dbdata = null)
{
$this->close();
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
$this->prefix = $dbdata['prefix'];
try {
$this->con = new \PDO($this->dbdata['db'] . ':' . $this->dbdata['path']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->status = DatabaseStatus::OK;
} catch (\PDOException $e) {
$this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
}
}
}

View File

@ -0,0 +1,600 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\DataMapperInterface;
/**
* Datamapper for databases.
*
* DB, Cache, Session
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class DataMapperAbstract implements DataMapperInterface
{
/**
* Database connection.
*
* @var \phpOMS\DataStorage\Database\Connection\ConnectionAbstract
* @since 1.0.0
*/
protected $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 = '';
/**
* Columns.
*
* @var array<string, array>
* @since 1.0.0
*/
protected static $columns = [];
/**
* Relations.
*
* @var \string[]
* @since 1.0.0
*/
protected static $hasMany = [];
/**
* Relations.
*
* @var \string[]
* @since 1.0.0
*/
protected static $ownsMany = [];
/**
* Relations.
*
* @var \string[]
* @since 1.0.0
*/
protected static $hasOne = [];
/**
* Extending relations.
*
* @var \string[]
* @since 1.0.0
*/
protected static $extends = [];
/**
* Relations.
*
* @var \string[]
* @since 1.0.0
*/
protected static $ownsOne = [];
/**
* Table.
*
* @var \string
* @since 1.0.0
*/
protected static $table = '';
/**
* Extended value collection.
*
* @var array
* @since 1.0.0
*/
protected $collection = [
'primaryField' => [],
'createdAt' => [],
'columns' => [],
'hasMany' => [],
'hasOne' => [],
'ownsMany' => [],
'ownsOne' => [],
'table' => [],
];
/**
* Constructor.
*
* @param ConnectionAbstract $con Database connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(ConnectionAbstract $con)
{
$this->db = $con;
$this->extend($this);
}
/**
* Collect values from extension.
*
* @param mixed $class Current extended mapper
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function extend($class)
{
$this->collection['primaryField'][] = $class::$primaryField;
$this->collection['createdAt'][] = $class::$createdAt;
$this->collection['columns'][] = $class::$columns;
$this->collection['hasMany'][] = $class::$hasMany;
$this->collection['hasOne'][] = $class::$hasOne;
$this->collection['ownsMany'][] = $class::$ownsMany;
$this->collection['ownsOne'][] = $class::$ownsOne;
$this->collection['table'][] = $class::$table;
if (($parent = get_parent_class($class)) !== false && !$class::$overwrite) {
$this->extend($parent);
}
}
/**
* Update data.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function update()
{
}
/**
* Save data.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function save()
{
}
/**
* Delete data.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function delete()
{
}
/**
* Find data.
*
* @param array $columns Columns
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function find(...$columns) : Builder
{
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix());
return $query->select(...$columns)->from(static::$table);
}
/**
* Create object in db.
*
* @param mixed $obj Object reference (gets filled with insert id)
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function create(&$obj)
{
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix())
->into(static::$table);
$reflectionClass = new \ReflectionClass(get_class($obj));
$properties = $reflectionClass->getProperties();
foreach ($properties as $property) {
foreach (static::$columns as $key => $column) {
if ($column['internal'] === $property) {
$value = $property->getValue($obj);
if ($column['type'] === 'DateTime') {
$value = isset($value) ? $value->format('Y-m-d H:i:s') : null;
}
$query->insert($column['name'])
->values($value);
break;
}
}
}
$this->db->con->prepare($query->toSql())->execute();
$objId = $this->db->con->lastInsertId();
$reflectionProperty = $reflectionClass->getProperty('id');
if (!($accessible = $reflectionProperty->isPublic())) {
$reflectionProperty->setAccessible(true);
}
settype($objId, static::$columns[static::$primaryField]['type']);
$reflectionProperty->setValue($obj, $objId);
if (!$accessible) {
$reflectionProperty->setAccessible(false);
}
return $objId;
}
/**
* Find data.
*
* @param Builder $query Query
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function listResults(Builder $query)
{
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
return $this->populateIterable($sth->fetchAll(\PDO::FETCH_ASSOC));
}
/**
* Populate data.
*
* @param array $result Result set
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populate(array $result)
{
$class = get_class($this);
$class = str_replace('Mapper', '', $class);
$obj = new $class();
return $this->populateAbstract($result, $obj);
}
/**
* Populate data.
*
* @param array $result Query result set
* @param mixed $obj Object to populate
*
* @return mixed
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populateAbstract(array $result, $obj)
{
$reflectionClass = new \ReflectionClass(get_class($obj));
foreach ($result as $column => $value) {
if ($reflectionClass->hasProperty(static::$columns[$column]['internal'])) {
$reflectionProperty = $reflectionClass->getProperty(static::$columns[$column]['internal']);
if (!($accessible = $reflectionProperty->isPublic())) {
$reflectionProperty->setAccessible(true);
}
if (in_array(static::$columns[$column]['type'], ['string', 'int', 'float'])) {
settype($value, static::$columns[$column]['type']);
$reflectionProperty->setValue($obj, $value);
} elseif (static::$columns[$column]['type'] === 'DateTime') {
$reflectionProperty->setValue($obj, new \DateTime($value));
} else {
throw new \UnexpectedValueException('Value "' . static::$columns[$column]['type'] . '" is not supported.');
}
if (!$accessible) {
$reflectionProperty->setAccessible(false);
}
}
}
return $obj;
}
/**
* Get newest.
*
* This will fall back to the insert id if no datetime column is present.
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getNewest()
{
if (!isset(static::$createdAt) || !isset(static::$columns[static::$createdAt])) {
throw new \BadMethodCallException('Method "' . __METHOD__ . '" is not supported.');
}
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix())
->select('*')
->from(static::$table)
->limit(1);
if(isset(static::$createdAt)) {
$query->orderBy(static::$table . '.' . static::$columns[static::$createdAt]['name'], 'DESC');
} else {
$query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC');
}
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
$results = $sth->fetch(\PDO::FETCH_ASSOC);
return $this->populate(is_bool($results) ? [] : $results);
}
/**
* Populate data.
*
* @param array $result Result set
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function populateIterable(array $result) : array
{
$row = [];
foreach ($result as $element) {
if (isset($element[static::$primaryField])) {
$row[$element[static::$primaryField]] = $this->populate($element);
} else {
$row[] = $this->populate($element);
}
}
return $row;
}
/**
* Load.
*
* @param array $objects Objects to load
*
* @return null
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function with(...$objects)
{
}
/**
* Get object.
*
* @param mixed $primaryKey Key
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($primaryKey)
{
$obj = $this->populate($this->getRaw($primaryKey));
if (isset($obj)) {
return $obj;
} else {
$class = get_class($this);
$class = str_replace('Mapper', '', $class);
$class = explode('\\', $class);
$pos = count($class) - 1;
$class[$pos] = 'Null' . $class[$pos];
$class = implode('\\', $class);
return $class;
}
}
/**
* Get object.
*
* @param mixed $primaryKey Key
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getRaw($primaryKey) : array
{
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix())
->select('*')
->from(static::$table)
->where(static::$table . '.' . static::$primaryField, '=', $primaryKey);
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
$results = $sth->fetch(\PDO::FETCH_ASSOC);
return is_bool($results) ? [] : $results;
}
/**
* Get all by custom query.
*
* @param Builder $query Query
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAllByQuery(Builder $query) : array
{
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
$results = is_bool($results) ? [] : $results;
return $this->populateIterable($results);
}
public function getRelations($primaryKey) : array
{
$result = [];
foreach (static::$hasMany as $member => $value) {
if (!isset($value['mapper'])) {
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix())
->select($value['table'] . '.' . $value['src'])
->from($value['table'])
->where($value['table'] . '.' . $value['dst'], '=', $primaryKey);
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
$result[$member] = $sth->fetchAll(\PDO::FETCH_ASSOC);
}
}
return $result;
}
/**
* Get object.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAll()
{
return $this->populateIterable($this->getAllRaw());
}
/**
* Get all in raw output.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAllRaw() : array
{
$query = new Builder($this->db);
$query->prefix($this->db->getPrefix())
->select('*')
->from(static::$table);
$sth = $this->db->con->prepare($query->toSql());
$sth->execute();
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
return is_bool($results) ? [] : $results;
}
/**
* Get primary field.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPrimaryField() : \string
{
return static::$primaryField;
}
/**
* Get main table.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTable() : \string
{
return static::$table;
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database;
use phpOMS\Datatypes\Enum;
/**
* Database status enum.
*
* Possible database connection status
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class DatabaseStatus extends Enum
{
const OK = 0; /* Database connection successful */
const MISSING_DATABASE = 1; /* Couldn't find database */
const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
const FAILURE = 3; /* Unknown failure */
const READONLY = 4; /* Database connection is in readonly (but ok) */
const CLOSED = 5; /* Database connection closed */
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database;
use phpOMS\Datatypes\Enum;
/**
* Database type enum.
*
* Database types that are supported by the application
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class DatabaseType extends Enum
{
const MYSQL = 0; /* MySQL */
const SQLITE = 1; /* SQLITE */
const PGSQL = 2; /* PostgreSQL */
const ORACLE = 3; /* Oracle */
const SQLSRV = 4; /* Microsoft SQL Server */
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database;
abstract class Grammar
{
protected $tablePrefix = '';
public function getDateFormat() : \string
{
return 'Y-m-d H:i:s';
}
public function getTablePrefix() : \string
{
return $this->tablePrefix;
}
public function setTablePrefix(\string $prefix)
{
$this->tablePrefix = $prefix;
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
/**
* Database pool handler.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Pool
{
/**
* Databases.
*
* @var ConnectionAbstract[]
* @since 1.0.0
*/
private $pool = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* Add database.
*
* @param mixed $key Database key
* @param ConnectionAbstract $db Database
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function add($key = 'core', ConnectionAbstract $db) : \bool
{
if (isset($this->pool[$key])) {
return false;
}
$this->pool[$key] = $db;
return true;
}
/**
* Get database.
*
* @param mixed $key Database key
*
* @return ConnectionAbstract
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($key = 'core')
{
if (!isset($this->pool[$key])) {
return false;
}
return $this->pool[$key];
}
/**
* Remove database.
*
* @param mixed $key Database key
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function remove($key) : \bool
{
if (!isset($this->pool[$key])) {
return false;
}
unset($this->pool[$key]);
return true;
}
/**
* Create database.
*
* @param mixed $key Database key
* @param array $config Database config data
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function create($key, array $config)
{
if (isset($this->pool[$key])) {
return;
}
$this->pool[$key] = ConnectionFactory::create($config);
}
}

View File

@ -0,0 +1,883 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query;
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
/**
* Database query builder.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Builder
{
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
public $selects = [];
/**
* Into.
*
* @var array
* @since 1.0.0
*/
public $into = null;
/**
* Into columns.
*
* @var array
* @since 1.0.0
*/
public $inserts = [];
/**
* Into columns.
*
* @var array
* @since 1.0.0
*/
public $values = [];
/**
* Distinct.
*
* @var \bool
* @since 1.0.0
*/
public $distinct = false;
/**
* From.
*
* @var array
* @since 1.0.0
*/
public $from = [];
/**
* Joins.
*
* @var array
* @since 1.0.0
*/
public $joins = [];
/**
* Where.
*
* @var array
* @since 1.0.0
*/
public $wheres = [];
/**
* Group.
*
* @var array
* @since 1.0.0
*/
public $groups = [];
/**
* Order.
*
* @var array
* @since 1.0.0
*/
public $orders = [];
/**
* Limit.
*
* @var array
* @since 1.0.0
*/
public $limit = null;
/**
* Offset.
*
* @var array
* @since 1.0.0
*/
public $offset = null;
/**
* Binds.
*
* @var array
* @since 1.0.0
*/
private $binds = [];
/**
* Union.
*
* @var array
* @since 1.0.0
*/
public $unions = [];
/**
* Lock.
*
* @var \bool
* @since 1.0.0
*/
public $lock = false;
/**
* Database connectino.
*
* @var ConnectionAbstract
* @since 1.0.0
*/
protected $connection = null;
/**
* Grammar.
*
* @var \phpOMS\DataStorage\Database\Query\Grammar\GrammarInterface
* @since 1.0.0
*/
protected $grammar = null;
/**
* Query type.
*
* @var QueryType
* @since 1.0.0
*/
protected $type = null;
protected $unionLimit = null;
protected $unionOffset = null;
protected $unionOrders = [];
/**
* Prefix.
*
* @var \string
* @since 1.0.0
*/
protected $prefix = '';
/**
* Comparison operators.
*
* @var \string[]
* @since 1.0.0
*/
const operators = [
'=',
'<',
'>',
'<=',
'>=',
'<>',
'!=',
'like',
'like binary',
'not like',
'between',
'ilike',
'&',
'|',
'^',
'<<',
'>>',
'rlike',
'regexp',
'not regexp',
'~',
'~*',
'!~',
'!~*',
'similar to',
'not similar to',
'in',
];
/**
* Constructor.
*
* @param ConnectionAbstract $connection Database connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(ConnectionAbstract $connection)
{
$this->connection = $connection;
$this->grammar = $connection->getGrammar();
}
/**
* Set prefix.
*
* @param \string $prefix Prefix
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function prefix(\string $prefix)
{
$this->prefix = $prefix;
return $this;
}
/**
* Get prefix.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPrefix() : \string
{
return $this->prefix;
}
/**
* Select.
*
* @param array $columns Columns
*
* @return Builder
*
* @todo Closure is not working this way, needs to be evaluated befor assigning
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function select(...$columns) : Builder
{
// todo handle wrong parameters
$this->type = QueryType::SELECT;
foreach ($columns as $key => $column) {
if (is_string($column) || $column instanceof \Closure) {
$this->selects[] = $column;
} else {
throw new \InvalidArgumentException();
}
}
return $this;
}
/**
* Bind parameter.
*
* @param \string|array|\Closure $binds Binds
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function bind($binds) : Builder
{
if (is_array($binds)) {
$this->binds += $binds;
} elseif (is_string($binds) || $binds instanceof \Closure) {
$this->binds[] = $binds;
} else {
throw new \InvalidArgumentException();
}
return $this;
}
/**
* Creating new.
*
* @return self
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function newQuery() : Builder
{
return new static($this->connection, $this->grammar);
}
/**
* Parsing to string.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function toSql() : \string
{
return $this->grammar->compileQuery($this);
}
/**
* Executing.
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function execute()
{
// todo: handle different query types (select, insert etc)
}
/**
* Make raw column selection.
*
* @param \string|\Closure $expression Raw expression
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function selectRaw($expression) : Builder
{
$this->selects[null][] = $expression;
return $this;
}
/**
* Is distinct.
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function distinct() : Builder
{
$this->distinct = true;
return $this;
}
/**
* From.
*
* @param array $tables Tables
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function from(...$tables) : Builder
{
foreach ($tables as $key => $table) {
if (is_string($table) || $table instanceof \Closure) {
$this->from[] = $table;
} else {
throw new \InvalidArgumentException();
}
}
return $this;
}
/**
* Make raw from.
*
* @param \string|array|\Closure $expression Expression
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function fromRaw($expression) : Builder
{
$this->from[null][] = $expression;
return $this;
}
/**
* Or Where.
*
* @param \string|array|\Closure $columns Columns
* @param \string $operator Operator
* @param \string|array|\Closure $values Values
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function orWhere($columns, \string $operator = null, $values = null) : Builder
{
return $this->where($columns, $operator, $values, 'or');
}
/**
* Where.
*
* @param \string|array|\Closure $columns Columns
* @param \string|array $operator Operator
* @param mixed $values Values
* @param \string|array $boolean Boolean condition
*
* @return Builder
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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($operator, self::operators)) {
throw new \InvalidArgumentException('Unknown operator.');
}
if (is_array($columns)) {
$i = 0;
foreach ($columns as $key => $column) {
if (isset($operator[$i]) && !in_array($operator[$i], self::operators)) {
throw new \InvalidArgumentException('Unknown operator.');
}
$this->wheres[$key][] = ['column' => $column, 'operator' => $operator[$i],
'value' => $values[$i],
'boolean' => $boolean[$i],];
$i++;
}
} elseif (is_string($columns)) {
if (isset($operator) && !in_array($operator, self::operators)) {
throw new \InvalidArgumentException('Unknown operator.');
}
$this->wheres[null][] = ['column' => $columns, 'operator' => $operator, 'value' => $values,
'boolean' => $boolean,];
} else {
throw new \InvalidArgumentException();
}
return $this;
}
/**
* Where in.
*
* @param \string|array|\Closure $column Column
* @param mixed $values Values
* @param \string $boolean Boolean condition
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function whereIn($column, $values = null, \string $boolean = 'and') : Builder
{
$this->where($column, 'in', $values, $boolean);
return $this;
}
/**
* Where null.
*
* @param \string|array|\Closure $column Column
* @param \string $boolean Boolean condition
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function whereNull($column, \string $boolean = 'and') : Builder
{
$this->where($column, '=', null, $boolean);
return $this;
}
/**
* Where not null.
*
* @param \string|array|\Closure $column Column
* @param \string $boolean Boolean condition
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function whereNotNull($column, \string $boolean = 'and') : Builder
{
$this->where($column, '!=', null, $boolean);
return $this;
}
/**
* Group by.
*
* @param \string|array|\Closure $columns Grouping result
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function groupBy(...$columns) : Builder
{
foreach ($columns as $key => $column) {
if (is_string($column) || $column instanceof \Closure) {
$this->groups[] = $column;
} else {
throw new \InvalidArgumentException();
}
}
return $this;
}
/**
* Order by newest.
*
* @param \string|\Closure $column Column
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function newest($column) : Builder
{
$this->orderBy($column, 'DESC');
return $this;
}
/**
* Order by oldest.
*
* @param \string|\Closure $column Column
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function oldest($column) : Builder
{
$this->orderBy($column, 'ASC');
return $this;
}
/**
* Order by oldest.
*
* @param \string|array|\Closure $columns Columns
* @param \string|string[] $order Orders
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function orderBy($columns, $order = 'DESC') : Builder
{
if (is_string($columns) || $columns instanceof \Closure) {
$this->orders[] = ['column' => $columns, 'order' => $order];
} elseif (is_array($columns)) {
foreach ($columns as $key => $column) {
$this->orders[] = ['column' => $column, 'order' => $order[$key]];
}
} else {
throw new \InvalidArgumentException();
}
return $this;
}
/**
* Offset.
*
* @param \int|\Closure $offset Offset
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function offset($offset) : Builder
{
$this->offset = $offset;
return $this;
}
/**
* Limit.
*
* @param \int|\Closure $limit Limit
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function limit($limit) : Builder
{
$this->limit = $limit;
return $this;
}
/**
* Limit.
*
* @param \string|\phpOMS\DataStorage\Database\Query\Builder $query Query
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function union($query) : Builder
{
if (!is_array($query)) {
$this->unions[] = $query;
} else {
$this->unions += $query;
}
return $this;
}
public function lock()
{
}
public function lockUpdate()
{
}
public function __toString()
{
return $this->grammar->compileQuery($this);
}
public function find()
{
}
public function count()
{
}
public function exists()
{
}
public function min()
{
}
public function max()
{
}
public function sum()
{
}
public function avg()
{
}
public function get()
{
return $this;
}
/**
* Insert into columns.
*
* @param array $columns Columns
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function insert(...$columns) : Builder
{
$this->type = QueryType::INSERT;
foreach ($columns as $key => $column) {
$this->inserts[] = $column;
}
return $this;
}
/**
* Table to insert into.
*
* @param \string|\Closure $table Table
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function into($table) : Builder
{
$this->into = $table;
return $this;
}
/**
* Values to insert.
*
* @param array $values Values
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function values(...$values) : Builder
{
$this->values[] = $values;
return $this;
}
public function update() : Builder
{
$this->type = QueryType::UPDATE;
return $this;
}
public function increment()
{
}
public function decrement()
{
}
public function delete()
{
$this->type = QueryType::DELETE;
return $this;
}
public function create($table)
{
return $this;
}
public function drop()
{
return $this;
}
public function raw()
{
return $this;
}
public function join($table1, $table2, $column1, $opperator, $column2)
{
return $this;
}
public function joinWhere()
{
}
public function leftJoin()
{
}
public function leftJoinWhere()
{
}
public function rightJoin()
{
}
public function rightJoinWhere()
{
}
public function rollback()
{
return $this;
}
public function commit() : Builder
{
return $this;
}
/**
* Get query type.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : \int
{
return $this->type;
}
public function merge($query) : Builder {
return clone($this);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query;
/**
* Database query builder.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Column
{
private $column = '';
/**
* Constructor.
*
* @param \string $column Column
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(\string $column)
{
$this->column = $column;
}
public function getColumn() : \string
{
return $this->column;
}
public function setColumn(\string $column)
{
$this->column = $column;
}
}

View File

@ -0,0 +1,533 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
use phpOMS\DataStorage\Database\Query\QueryType;
/**
* Database query grammar.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Grammar extends \phpOMS\DataStorage\Database\Grammar
{
/**
* Comment style.
*
* @var \string
* @since 1.0.0
*/
protected $comment = '--';
/**
* String quotes style.
*
* @var \string
* @since 1.0.0
*/
protected $valueQuotes = '\'';
/**
* System identifier.
*
* @var \string
* @since 1.0.0
*/
public $systemIdentifier = '"';
/**
* And operator.
*
* @var \string
* @since 1.0.0
*/
protected $and = 'AND';
/**
* Or operator.
*
* @var \string
* @since 1.0.0
*/
protected $or = 'OR';
/**
* Select components.
*
* @var \string[]
* @since 1.0.0
*/
protected $selectComponents = [
'aggregate',
'selects',
'from',
'joins',
'wheres',
'havings',
'groups',
'orders',
'limit',
'offset',
'unions',
'lock',
];
/**
* Insert components.
*
* @var \string[]
* @since 1.0.0
*/
protected $insertComponents = [
'into',
'inserts',
'values',
];
/**
* Update components.
*
* @var \string[]
* @since 1.0.0
*/
protected $updateComponents = [
'updates',
'sets',
'wheres',
];
/**
* Compile to query.
*
* @param Builder $query Builder
*
* @return \string
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function compileQuery($query) : \string
{
return trim(
implode(' ',
array_filter(
$this->compileComponents($query),
function ($value) {
return (string) $value !== '';
}
)
)
) . ';';
}
/**
* Compile components.
*
* @param Builder $query Builder
*
* @return \string[]
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileComponents(Builder $query) : array
{
$sql = [];
switch ($query->getType()) {
case QueryType::SELECT:
$components = $this->selectComponents;
break;
case QueryType::INSERT:
$components = $this->insertComponents;
break;
case QueryType::UPDATE:
$components = null;
break;
case QueryType::DELETE:
$components = null;
break;
default:
throw new \InvalidArgumentException('Unknown query type.');
}
/* Loop all possible query components and if they exist compile them. */
foreach ($components as $component) {
if (isset($query->{$component}) && !empty($query->{$component})) {
$sql[$component] = $this->{'compile' . ucfirst($component)}($query, $query->{$component});
}
}
return $sql;
}
/**
* Compile select.
*
* @param Builder $query Builder
* @param array $columns Columns
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileSelects(Builder $query, array $columns) : \string
{
$expression = $this->expressionizeTableColumn($columns, $query->getPrefix());
if ($expression == '') {
return '';
}
return ($query->distinct ? 'SELECT DISTINCT ' : 'SELECT ') . $expression;
}
/**
* Expressionize elements.
*
* @param array $elements Elements
* @param \string $prefix Prefix for table
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function expressionizeTableColumn(array $elements, \string $prefix = '') : \string
{
$expression = '';
foreach ($elements as $key => $element) {
if (is_string($element) && $element !== '*') {
$expression .= $this->compileSystem($element, $prefix) . ', ';
} elseif (is_string($element) && $element === '*') {
$expression .= '*, ';
} elseif ($element instanceof \Closure) {
$expression .= $element() . ', ';
} elseif ($element instanceof Builder) {
$expression .= $element->toSql() . ', ';
} else {
throw new \InvalidArgumentException();
}
}
return rtrim($expression, ', ');
}
/**
* Compile from.
*
* @param Builder $query Builder
* @param array $table Tables
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileFrom(Builder $query, array $table) : \string
{
$expression = $this->expressionizeTableColumn($table, $query->getPrefix());
if ($expression == '') {
return '';
}
return 'FROM ' . $expression;
}
/**
* Compile where.
*
* @param Builder $query Builder
* @param array $wheres Where elmenets
* @param \bool $first Is first element (usefull for nesting)
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileWheres(Builder $query, array $wheres, \bool $first = true) : \string
{
$expression = '';
foreach ($wheres as $key => $where) {
foreach ($where as $key2 => $element) {
if (!$first) {
$expression .= ' ' . strtoupper($element['boolean']) . ' ';
}
if (is_string($element['column'])) {
$expression .= $this->compileSystem($element['column'], $query->getPrefix()) . ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix());
} elseif ($element['column'] instanceof \Closure) {
} elseif ($element['column'] instanceof Builder) {
}
if (is_string($element['value'])) {
} elseif ($element['value'] instanceof \Closure) {
} elseif ($element['value'] instanceof Builder) {
} elseif ($element['value'] instanceof \DateTime) {
} elseif (is_int($element['value'])) {
} elseif (is_bool($element['value'])) {
} elseif (is_null($element['value'])) {
} elseif (is_float($element['value'])) {
} elseif (is_array($element['value'])) {
// is bind
}
$first = false;
}
}
if ($expression == '') {
return '';
}
return 'WHERE ' . $expression;
}
/**
* Compile value.
*
* @param array|string|\Closure $value Value
* @param \string $prefix Prefix in case value is a table
*
* @return \string
*
* @throws \InvalidArgumentException
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileValue($value, $prefix = '') : \string
{
if (is_string($value)) {
return $this->valueQuotes . $value . $this->valueQuotes;
} elseif (is_int($value)) {
return $value;
} elseif (is_array($value)) {
$values = '';
foreach ($value as $val) {
$values .= $this->compileValue($val) . ', ';
}
return '(' . rtrim($values, ', ') . ')';
} elseif ($value instanceof \DateTime) {
return $this->valueQuotes . $value->format('Y-m-d h:m:s') . $this->valueQuotes;
} elseif (is_null($value)) {
return 'NULL';
} elseif (is_bool($value)) {
return (string) ((int) $value);
} elseif ($value instanceof Column) {
return $this->compileSystem($value->getColumn(), $prefix);
} else {
throw new \InvalidArgumentException();
}
}
/**
* Compile system.
*
* @param array|\string $system System
* @param \string $prefix Prefix for table
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileSystem($system, \string $prefix = '') : \string
{
if (count($split = explode('.', $system)) == 2) {
return $this->compileSystem($prefix . $split[0]) . '.' . $this->compileSystem($split[1]);
} else {
return $this->systemIdentifier . $prefix . $system . $this->systemIdentifier;
}
}
/**
* Compile limit.
*
* @param Builder $query Builder
* @param \int $limit Limit
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileLimit(Builder $query, $limit) : \string
{
return 'LIMIT ' . $limit;
}
/**
* Compile offset.
*
* @param Builder $query Builder
* @param \int $offset Offset
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileOffset(Builder $query, $offset) : \string
{
return 'OFFSET ' . $offset;
}
private function compileJoins()
{
return '';
}
private function compileGroups(Builder $query, array $groups)
{
$expression = '';
foreach ($groups as $group) {
$expression .= $this->compileSystem($group, $query->getPrefix()) . ', ';
}
$expression = rtrim($expression, ', ');
return 'GROUP BY ' . $expression;
}
/**
* Compile offset.
*
* @param Builder $query Builder
* @param array $orders Order
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function compileOrders(Builder $query, array $orders) : \string
{
$expression = '';
foreach ($orders as $order) {
$expression .= $this->compileSystem($order['column'], $query->getPrefix()) . ' ' . $order['order'] . ', ';
}
if ($expression == '') {
return '';
}
$expression = rtrim($expression, ', ');
return 'ORDER BY ' . $expression;
}
private function compileUnions()
{
return '';
}
private function compileLock()
{
return '';
}
/**
* Compile insert into table.
*
* @param Builder $query Builder
* @param \string $table Table
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileInto(Builder $query, $table) : \string
{
return 'INSERT INTO ' . $this->compileSystem($table, $query->getPrefix());
}
/**
* Compile insert into columns.
*
* @param Builder $query Builder
* @param array $columns Columns
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileInserts(Builder $query, array $columns) : \string
{
$cols = '';
foreach ($columns as $column) {
$cols .= $this->compileSystem($column) . ', ';
}
if ($cols == '') {
return '';
}
return '(' . rtrim($cols, ', ') . ')';
}
/**
* Compile insert values.
*
* @param Builder $query Builder
* @param array $values Values
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
protected function compileValues(Builder $query, array $values) : \string
{
$vals = '';
foreach ($values as $value) {
$vals .= $this->compileValue($value) . ', ';
}
if ($vals == '') {
return '';
}
return 'VALUES ' . rtrim($vals, ', ');
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query\Grammar;
use phpOMS\DataStorage\Database\Grammar;
class GrammarInterface extends Grammar
{
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query\Grammar;
class MysqlGrammar extends Grammar
{
/**
* System identifier.
*
* @var \string
* @since 1.0.0
*/
public $systemIdentifier = '`';
}

View File

@ -0,0 +1,29 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query\Grammar;
class SqliteGrammar extends Grammar
{
/**
* System identifier.
*
* @var \string
* @since 1.0.0
*/
public $systemIdentifier = '`';
}

View File

@ -0,0 +1,37 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Query;
use phpOMS\Datatypes\Enum;
/**
* Query type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class QueryType extends Enum
{
const SELECT = 0;
const INSERT = 1;
const UPDATE = 2;
const DELETE = 3;
}

View File

View File

@ -0,0 +1,61 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Schema;
interface GrammarInterface
{
public function typeTinyInt($places);
public function typeSmallInt($places);
public function typeMediumInt($places);
public function typeInt($places);
public function typeBigInt($places);
public function typeFloat($m, $e, $b = 10);
public function typeDouble($m, $e, $b = 10);
public function typeDecimal($a, $b);
public function typeBoolean();
public function typeJson();
public function typeDate();
public function typeTime();
public function typeDateTime();
public function typeTimestamp();
public function typeBinary();
public function typeChar();
public function typeString();
public function typeMediumText();
public function typeText();
public function typeLongText();
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Schema;
use phpOMS\Datatypes\Enum;
/**
* Database type enum.
*
* Database types that are supported by the application
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class QueryType extends Enum
{
const CREATE = 0;
const DROP = 1;
const ALTER = 2;
}

View File

@ -0,0 +1,99 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Session;
/**
* Console session class.
*
* @category Framework
* @package phpOMS\DataStorage\Session
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ConsoleSession implements SessionInterface
{
/**
* Session ID.
*
* @var \string|\int
* @since 1.0.0
*/
private $sid = null;
/**
* Constructor.
*
* @param \string|\int $sid Session id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct($sid)
{
$this->sid = $sid;
}
/**
* {@inheritdoc}
*/
public function get($key)
{
}
/**
* {@inheritdoc}
*/
public function set($key, $value, \bool $overwrite = true) : \bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function remove($key) : \bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function getSID()
{
return $this->sid;
}
/**
* {@inheritdoc}
*/
public function setSID($sid)
{
$this->sid = $sid;
}
/**
* {@inheritdoc}
*/
public function save()
{
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Session;
/**
* Http session class.
*
* @category Framework
* @package phpOMS\DataStorage\Session
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class HttpSession implements SessionInterface
{
private $sessionData = [];
/**
* Session ID.
*
* @var \string|int
* @since 1.0.0
*/
private $sid = null;
/**
* Constructor.
*
* @param \int $liftetime Session life time
* @param \string|int|\bool $sid Session id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(\int $liftetime = 3600, $sid = false)
{
if ($sid !== false) {
session_id($sid);
}
session_set_cookie_params($liftetime);
session_start();
$this->sessionData = $_SESSION;
$this->sid = session_id();
session_write_close();
}
/**
* {@inheritdoc}
*/
public function get($key)
{
return $this->sessionData[$key] ?? null;
}
/**
* {@inheritdoc}
*/
public function set($key, $value, \bool $overwrite = true) : \bool
{
if($overwrite || !isset($this->sessionData[$key])) {
$this->sessionData[$key] = $value;
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function save()
{
session_id($this->sid);
session_start();
$_SESSION = $this->sessionData;
session_write_close();
}
/**
* {@inheritdoc}
*/
public function remove($key) : \bool
{
if (isset($this->sessionData[$key])) {
unset($this->sessionData[$key]);
return true;
}
return false;
}
/**
* {@inheritdoc}
*/
public function getSID()
{
return $this->sid;
}
/**
* {@inheritdoc}
*/
public function setSID($sid)
{
$this->sid = $sid;
}
}

View File

@ -0,0 +1 @@
# Session #

View File

@ -0,0 +1,102 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Session;
/**
* Session interface.
*
* Sessions can be used by http requests, console interaction and socket connections
*
* @category Framework
* @package phpOMS\DataStorage\Cache
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface SessionInterface
{
/**
* Get session variable by key.
*
* @param \string|\int $key Value key
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get($key);
/**
* Store session value by key.
*
* @param \string|\int $key Value key
* @param mixed $value Value to store
* @param \bool $overwrite Overwrite existing values
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set($key, $value, \bool $overwrite = true) : \bool;
/**
* Remove value from session by key.
*
* @param \string|\int $key Value key
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function remove($key) : \bool;
/**
* Save session.
*
* @todo : implement save type (session, cache, database)
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function save();
/**
* @return \int|\string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getSID();
/**
* @param \int|\string $sid
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setSID($sid);
}

View File

@ -0,0 +1,99 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Session;
/**
* Socket session class.
*
* @category Framework
* @package phpOMS\DataStorage\Session
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class SocketSession implements SessionInterface
{
/**
* Session ID.
*
* @var \string|\int
* @since 1.0.0
*/
private $sid = null;
/**
* Constructor.
*
* @param \string|\int $sid Session id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct($sid)
{
$this->sid = $sid;
}
/**
* {@inheritdoc}
*/
public function get($key)
{
}
/**
* {@inheritdoc}
*/
public function set($key, $value, \bool $overwrite = true) : \bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function remove($key) : \bool
{
return false;
}
/**
* {@inheritdoc}
*/
public function getSID()
{
return $this->sid;
}
/**
* {@inheritdoc}
*/
public function setSID($sid)
{
$this->sid = $sid;
}
/**
* {@inheritdoc}
*/
public function save()
{
}
}

168
Datatypes/Address.php Normal file
View File

@ -0,0 +1,168 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
use phpOMS\Contract\JsonableInterface;
/**
* Address class.
*
* @category Framework
* @package phpOMS\Datatypes
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Address implements JsonableInterface
{
/**
* Name of the receiver.
*
* @var \string
* @since 1.0.0
*/
private $recipient = null;
/**
* Sub of the address.
*
* @var \string
* @since 1.0.0
*/
private $fao = null;
/**
* Location.
*
* @var Location
* @since 1.0.0
*/
private $location = null;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->location = new Location();
}
/**
* Get recipient.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getRecipient() : \string
{
return $this->recipient;
}
/**
* Set recipient.
*
* @param \string $recipient Recipient
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setRecipient(\string $recipient)
{
$this->recipient = $recipient;
}
/**
* Get FAO.
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFAO() : \string
{
return $this->fao;
}
/**
* Set FAO.
*
* @param \string $fao FAO
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setFAO(\string $fao)
{
$this->fao = $fao;
}
/**
* Get location.
*
* @return Location
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLocation() : Location
{
return $this->location;
}
/**
* Set location.
*
* @param Location $location Location
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setLocation(Location $location)
{
$this->location = $location;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return ['recipient' => $this->recipient, 'fao' => $this->fao, 'location' => $this->location->toArray()];
}
/**
* {@inheritdoc}
*/
public function toJson(\int $option = 0) : \string
{
return json_encode($this->toArray());
}
}

36
Datatypes/AddressType.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
/**
* Address type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class AddressType extends Enum
{
const HOME = 1;
const BUSINESS = 2;
const SHIPPING = 3;
const BILLING = 4;
const WORK = 5;
}

98
Datatypes/Enum.php Normal file
View File

@ -0,0 +1,98 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
/**
* Enum class.
*
* Replacing the SplEnum class and providing basic enum.
*
* @category Framework
* @package phpOMS\Datatypes
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class Enum
{
/**
* Caching constant values.
*
* @var array
* @since 1.0.0
*/
private static $constCache = null;
/**
* Checking enum name.
*
* Checking if a certain const name exists (case sensitive)
*
* @param \string $name Name of the value (case sensitive)
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isValidName(\string $name) : \bool
{
$constants = self::getConstants();
return array_key_exists($name, $constants);
}
/**
* Getting all constants of this enum.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getConstants() : array
{
if (!isset(self::$constCache)) {
$reflect = new \ReflectionClass(get_called_class());
self::$constCache = $reflect->getConstants();
}
return self::$constCache;
}
/**
* Check enum value.
*
* Checking if a given value is part of this enum
*
* @param mixed $value Value to check
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isValidValue($value) : \bool
{
$values = array_values(self::getConstants());
return in_array($value, $values, $strict = true);
}
}

109
Datatypes/EnumArray.php Normal file
View File

@ -0,0 +1,109 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
/**
* Enum class.
*
* Replacing the SplEnum class and providing basic enum.
*
* @category Framework
* @package phpOMS\Datatypes
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class EnumArray
{
/**
* Checking enum name.
*
* Checking if a certain const name exists (case sensitive)
*
* @param \string $name Name of the value (case sensitive)
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isValidName(\string $name) : \bool
{
$constants = self::getConstants();
return array_key_exists($name, $constants);
}
/**
* Getting all constants of this enum.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getConstants() : array
{
/** @var array $constants */
return (new static())::$constants;
}
/**
* Check enum value.
*
* Checking if a given value is part of this enum
*
* @param mixed $value Value to check
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isValidValue($value) : \bool
{
$constants = self::getConstants();
return in_array($value, $constants, $strict = true);
}
/**
* Get enum value by name.
*
* @param mixed $key Key to look for
*
* @return mixed
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function get($key)
{
$constants = self::getConstants()[$key];
if (!isset($constants[$key])) {
throw new \OutOfBoundsException('Key "' . $key . '" is not valid.');
}
return $constants[$key];
}
}

130
Datatypes/ExactFloat.php Normal file
View File

@ -0,0 +1,130 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes\ExactFloat;
class ExactFloat
{
private static $length = 0;
public static function setLength($length)
{
self::$length = (int) $length;
}
public static function sum($a, $b, $length = null)
{
$length = $length ?? self::$length;
$split_a = explode('.', $a) + ['0', '0'];
$split_b = explode('.', $b) + ['0', '0'];
$sign_a = '+';
$sign_b = '+';
$sign_sum = '';
$decimals = [0, 0];
$decimals[0] = (int) $split_a[0] + (int) $split_b[0];
/* Get sign and length */
$len_a = strlen($split_a[1]);
if ($a[0] === '-') {
$sign_a = '-';
}
$len_b = strlen($split_b[1]);
if ($b[0] === '-') {
$sign_b = '-';
}
/* Pad to same length */
$len_max = max($len_a, $len_b);
$val_a = (int) ($sign_a . str_pad($split_a[1], $len_max, '0'));
$val_b = (int) ($sign_b . str_pad($split_b[1], $len_max, '0'));
$temp_sum = $val_a + $val_b;
if ($sign_a === '+' && $sign_b === '+') {
if (strlen((string) $temp_sum) > $len_max) {
$decimals[0]++;
$decimals[1] = (int) substr((string) $temp_sum, 1);
}
} elseif ($sign_a === '+' && $sign_b === '-') {
// todo: keep 0.5 in mind maybe decimals0--?!?!?! most likely not
if ((int) $split_a[0] > (int) $split_b[0]) {
if ($val_a < $val_b) {
$temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum;
}
} else {
if ($val_a > $val_b) {
$temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum;
}
}
$decimals[1] = (int) ltrim((string) $temp_sum, '-');
} elseif ($sign_a === '-' && $sign_b === '+') {
if ((int) $split_a[0] < (int) $split_b[0]) {
if ($val_a > $val_b) {
$temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum;
}
} else {
if ($val_a < $val_b) {
$temp_sum = 10 * strlen((string) $temp_sum) - $temp_sum;
}
}
$decimals[1] = (int) ltrim((string) $temp_sum, '-');
} elseif ($sign_a === '-' && $sign_b === '-') {
if (strlen((string) $temp_sum) > $len_max + 1) {
$decimals[0]--;
$decimals[1] = (int) substr((string) $temp_sum, 2);
}
if ($decimals[0] === 0) {
$sign_sum = '-';
}
}
/* Too short */
$str_sum = str_pad((string) $decimals[1], $length, '0');
/* Too long */
/* TODO: handle rounding, carefull with e.g. 1.99995 -> 2.00 */
if ($sign_sum === '-') {
$str_sum = substr($str_sum, 0, $length + 1);
} else {
$str_sum = substr($str_sum, 0, $length);
}
return $sign_sum . $decimals[0] . ($length > 0 ? '.' . $str_sum : '');
}
public static function mult($a, $b, $length = null)
{
}
public static function div($a, $b, $length = null)
{
}
public static function __toString()
{
return '';
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes\Exception;
/**
* Filesystem class.
*
* Performing operations on the file system
*
* @category System
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class InvalidEnumName extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
{
parent::__construct('The enum name "' . $message . '" is not valid.', $code, $previous);
}
}

View File

@ -0,0 +1,39 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes\Exception;
/**
* Filesystem class.
*
* Performing operations on the file system
*
* @category System
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class InvalidEnumValue extends \UnexpectedValueException
{
public function __construct($message, $code = 0, \Exception $previous = null)
{
parent::__construct('The enum value "' . $message . '" is not valid.', $code, $previous);
}
}

259
Datatypes/Location.php Normal file
View File

@ -0,0 +1,259 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
use phpOMS\Contract\JsonableInterface;
/**
* Location class.
*
* @category Framework
* @package phpOMS\Datatypes
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Location implements JsonableInterface
{
/**
* Zip or postal.
*
* @var \string
* @since 1.0.0
*/
private $postal = null;
/**
* Name of city.
*
* @var \string
* @since 1.0.0
*/
private $city = null;
/**
* Name of the country.
*
* @var \string
* @since 1.0.0
*/
private $country = null;
/**
* Street & district.
*
* @var \string
* @since 1.0.0
*/
private $address = null;
/**
* State.
*
* @var \string
* @since 1.0.0
*/
private $state = null;
/**
* Geo coordinates.
*
* @var \float[]
* @since 1.0.0
*/
private $geo = null;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPostal() : \string
{
return $this->postal;
}
/**
* @param \string $postal
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setPostal(\string $postal)
{
$this->postal = $postal;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCity() : \string
{
return $this->city;
}
/**
* @param \string $city
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCity(\string $city)
{
$this->city = $city;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCountry() : \string
{
return $this->country;
}
/**
* @param \string $country
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCountry(\string $country)
{
$this->country = $country;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAddress() : \string
{
return $this->address;
}
/**
* @param \string $address
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setAddress(\string $address)
{
$this->address = $address;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getState() : \string
{
return $this->state;
}
/**
* @param \string $state
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setState(\string $state)
{
$this->state = $state;
}
/**
* @return \float[]
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getGeo() : array
{
return $this->geo;
}
/**
* @param \float[] $geo
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setGeo(array $geo)
{
$this->geo = $geo;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'postal' => $this->postal,
'city' => $this->city,
'country' => $this->country,
'address' => $this->address,
'state' => $this->state,
'geo' => $this->geo,
];
}
/**
* {@inheritdoc}
*/
public function toJson(\int $option = 0) : \string
{
return json_encode($this->toArray());
}
}

35
Datatypes/PhoneType.php Normal file
View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
/**
* Address type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class PhoneType extends Enum
{
const HOME = 1;
const BUSINESS = 2;
const MOBILE = 3;
const WORK = 4;
}

102
Datatypes/SmartDateTime.php Normal file
View File

@ -0,0 +1,102 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Datatypes;
/**
* SmartDateTime.
*
* Providing smarter datetimes
*
* @category Modules
* @package phpOMS\Datatypes
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class SmartDateTime extends \DateTime
{
const FORMAT = 'Y-m-d hh:mm:ss';
const TIMEZONE = 'UTC';
/**
* {@inheritdoc}
*/
public function __construct($time = 'now', $timezone = null)
{
parent::__construct($time, $timezone);
}
/**
* Modify datetime in a smart way.
*
* @param \int $y Year
* @param \int $m Month
* @param \int $d Day
* @param \int $calendar Calendar
*
* @return SmartDateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function createModify(\int $y, \int $m = 0, \int $d = 0, \int $calendar = CAL_GREGORIAN) : SmartDateTime
{
$dt = clone $this;
$dt->smartModify($y, $m, $d, $calendar);
return $dt;
}
/**
* Modify datetime in a smart way.
*
* @param \int $y Year
* @param \int $m Month
* @param \int $d Day
* @param \int $calendar Calendar
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function smartModify(\int $y, \int $m = 0, \int $d = 0, \int $calendar = CAL_GREGORIAN)
{
$y_new = (int) $this->format('Y') + $y;
$m_new = ((int) $this->format('m') + $m) % 12;
$m_new = $m_new === 0 ? 12 : $m_new;
$d_month_old = cal_days_in_month($calendar, (int) $this->format('m'), (int) $this->format('Y'));
$d_month_new = cal_days_in_month($calendar, $m_new, $y_new);
$d_old = (int) $this->format('d');
if ($d_old > $d_month_new) {
$d_new = $d_month_new;
} elseif ($d_old < $d_month_new && $d_old === $d_month_old) {
$d_new = $d_month_new;
} else {
$d_new = $d_old;
}
$this->setDate($y_new, $m_new, $d_new);
if ($d !== 0) {
$this->modify($d . ' day');
}
}
}

160
Dispatcher/Dispatcher.php Normal file
View File

@ -0,0 +1,160 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Dispatcher;
use phpOMS\ApplicationAbstract;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Module\ModuleAbstract;
use phpOMS\Views\ViewLayout;
/**
* Dispatcher class.
*
* @category Framework
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Dispatcher
{
/**
* Application.
*
* @var ApplicationAbstract
* @since 1.0.0
*/
private $app = null;
/**
* Controller.
*
* Set in the module manager on module initialization.
*
* @var array
* @since 1.0.0
*/
private $controllers = [];
/**
* Constructor.
*
* @param ApplicationAbstract $app Appliaction
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(ApplicationAbstract $app)
{
$this->app = $app;
}
/**
* Dispatch controller.
*
* @param \string|array|\Closure $controller Controller string
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Data
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function dispatch($controller, RequestAbstract $request, ResponseAbstract $response, $data = null) : array
{
$views = [];
$type = ViewLayout::UNDEFINED;
if (isset($controller['type'])) {
$type = $controller['type'];
$controller = $controller['dest'];
}
if (is_string($controller)) {
$dispatch = explode(':', $controller);
$this->get($dispatch[0]);
if (count($dispatch) == 3) {
/* Handling static functions */
$views[$type][$controller] = $dispatch[0]::$dispatch[2]();
} else {
$views[$type][$controller] = $this->controllers[$dispatch[0]]->{$dispatch[1]}($request, $response, $data);
}
} elseif (is_array($controller)) {
foreach ($controller as $controllerSingle) {
foreach ($controllerSingle as $c) {
$views += $this->dispatch($c, $request, $response, $data);
}
}
} elseif ($controller instanceof \Closure) {
$views[$type][] = $controller($this->app, $request, $response, $data);
} else {
throw new \UnexpectedValueException('Unexpected controller type.');
}
return $views;
}
/**
* Get controller.
*
* @param \string $controller Controller string
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function get(\string $controller) : \bool
{
if (!isset($this->controllers[$controller])) {
$this->controllers[$controller] = new $controller($this->app);
return true;
}
return false;
}
/**
* Set controller by alias.
*
* @param ModuleAbstract $controller Controller
* @param \string $name Controller string
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set(ModuleAbstract $controller, \string $name) : \bool
{
if (!isset($this->controllers[$name])) {
$this->controllers[$name] = $controller;
return true;
}
return false;
}
}

134
Event/EventManager.php Normal file
View File

@ -0,0 +1,134 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Event;
use phpOMS\Pattern\Mediator;
use phpOMS\Utils\ArrayUtils;
/**
* EventManager class.
*
* @category Framework
* @package phpOMS\Event
* @since 1.0.0
*
* @todo : make cachable + database storable -> can reload user defined listeners (persistent events)
*/
class EventManager implements Mediator
{
/**
* Events.
*
* @var array
* @since 1.0.0
*/
private $events = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* {@inheritdoc}
*/
public function attach(\string $event, \Closure $callback = null, \string $listener = null) : \string
{
$this->events[$event][$listener] = $callback;
return $event . '/' . $listener;
}
/**
* {@inheritdoc}
*/
public function trigger(\string $event, \Closure $callback = null, \string $source = null) : \int
{
$count = 0;
foreach ($this->events[$event] as $event) {
$event($source);
$count++;
}
if (isset($callback)) {
/** @var $callback Callable */
$callback();
}
return $count;
}
/**
* Trigger event.
*
* An object fires an event until it's callback returns false
*
* @param \string $event Event ID
* @param \Closure $callback Callback function of the event. This will get triggered after firering all listener callbacks.
* @param \string $source What class is invoking this event
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function triggerUntil(\string $event, \Closure $callback = null, \string $source = null) : \int
{
$run = true;
$count = 0;
do {
foreach ($this->events[$event] as $event) {
$run = $event($source);
$count++;
}
} while ($run);
if ($callback !== null) {
$callback();
}
return $count;
}
/**
* {@inheritdoc}
*/
public function detach(\int $event)
{
$this->events = ArrayUtils::unsetArray($event, $this->events, '/');
}
/**
* Count event listenings.
*
* @return \int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function count() : \int
{
return count($this->events);
}
}

41
Html/TagType.php Normal file
View File

@ -0,0 +1,41 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Html;
use phpOMS\Datatypes\Enum;
/**
* Tag type enum.
*
* @category Framework
* @package phpOMS\Html
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
abstract class TagType extends Enum
{
const INPUT = 0; /* <input> */
const BUTTON = 1; /* <button> */
const LINK = 2; /* <a> */
const SYMMETRIC = 3; /* <span><div>... */
const TEXTAREA = 4; /* <textarea> */
const SELECT = 5; /* <select> */
const LABEL = 6; /* <label> */
const ULIST = 7; /* <ul> */
}

0
Install/Backup.php Normal file
View File

55
Install/DummyFactory.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Install;
/**
* Dummy data factory.
*
* Used in order to install dummy data of modules
*
* @category Install
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class DummyFactory
{
/**
* Generate dummy data.
*
* @param \phpOMS\DataStorage\Database\Pool $db Database instance
* @param \string $module Module name (= directory name)
* @param \int $amount Amount of dummy data
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function generate($db, $module, $amount = 9997)
{
if (file_exists(__DIR__ . '/../../Modules/' . $module . '/Admin/Dummy.class.php')) {
/** @var \phpOMS\Install\DummyInterface $class */
$class = '\\Modules\\' . $module . '\\Admin\\Dummy';
$class::generate($db, $amount);
}
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Install;
/**
* Dummy data interface.
*
* Used in order to install dummy data of modules
*
* @category Install
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
interface DummyInterface
{
/**
* Generate dummy data.
*
* @param \phpOMS\DataStorage\Database\Pool $db Database instance
* @param \int $amount Amount of dummy data
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function generate($db, $amount);
}

0
Install/Library.php Normal file
View File

1
Install/README.md Normal file
View File

@ -0,0 +1 @@
# Install #

0
Install/Uninstall.php Normal file
View File

44
Install/Update.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Install;
/**
* Update class.
*
* @category Install
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Update
{
/* TODO: remove relative elements (security) and only allow paths in this application */
public static function replace($old, $new)
{
unlink($old);
rename('somewhere_in_temp_folder/' . $new, $old);
}
public static function remove($old)
{
unlink($old);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,522 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\Enum;
/**
* Country codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO3166Enum extends Enum
{
const _AF = 'Afghanistan';
const _AX = 'Aland Islands';
const _AL = 'Albania';
const _DZ = 'Algeria';
const _AS = 'American Samoa';
const _AD = 'Andorra';
const _AO = 'Angola';
const _AI = 'Anguilla';
const _AQ = 'Antarctica';
const _AG = 'Antigua And Barbuda';
const _AR = 'Argentina';
const _AM = 'Armenia';
const _AW = 'Aruba';
const _AU = 'Australia';
const _AT = 'Austria';
const _AZ = 'Azerbaijan';
const _BS = 'Bahamas';
const _BH = 'Bahrain';
const _BD = 'Bangladesh';
const _BB = 'Barbados';
const _BY = 'Belarus';
const _BE = 'Belgium';
const _BZ = 'Belize';
const _BJ = 'Benin';
const _BM = 'Bermuda';
const _BT = 'Bhutan';
const _BO = 'Bolivia';
const _BA = 'Bosnia And Herzegovina';
const _BW = 'Botswana';
const _BV = 'Bouvet Island';
const _BR = 'Brazil';
const _IO = 'British Indian Ocean Territory';
const _BN = 'Brunei Darussalam';
const _BG = 'Bulgaria';
const _BF = 'Burkina Faso';
const _BI = 'Burundi';
const _KH = 'Cambodia';
const _CM = 'Cameroon';
const _CA = 'Canada';
const _CV = 'Cape Verde';
const _KY = 'Cayman Islands';
const _CF = 'Central African Republic';
const _TD = 'Chad';
const _CL = 'Chile';
const _CN = 'China';
const _CX = 'Christmas Island';
const _CC = 'Cocos (Keeling) Islands';
const _CO = 'Colombia';
const _KM = 'Comoros';
const _CG = 'Congo';
const _CD = 'Congo, Democratic Republic';
const _CK = 'Cook Islands';
const _CR = 'Costa Rica';
const _CI = 'Cote D\'Ivoire';
const _HR = 'Croatia';
const _CU = 'Cuba';
const _CY = 'Cyprus';
const _CZ = 'Czech Republic';
const _DK = 'Denmark';
const _DJ = 'Djibouti';
const _DM = 'Dominica';
const _DO = 'Dominican Republic';
const _EC = 'Ecuador';
const _EG = 'Egypt';
const _SV = 'El Salvador';
const _GQ = 'Equatorial Guinea';
const _ER = 'Eritrea';
const _EE = 'Estonia';
const _ET = 'Ethiopia';
const _FK = 'Falkland Islands (Malvinas)';
const _FO = 'Faroe Islands';
const _FJ = 'Fiji';
const _FI = 'Finland';
const _FR = 'France';
const _GF = 'French Guiana';
const _PF = 'French Polynesia';
const _TF = 'French Southern Territories';
const _GA = 'Gabon';
const _GM = 'Gambia';
const _GE = 'Georgia';
const _DE = 'Germany';
const _GH = 'Ghana';
const _GI = 'Gibraltar';
const _GR = 'Greece';
const _GL = 'Greenland';
const _GD = 'Grenada';
const _GP = 'Guadeloupe';
const _GU = 'Guam';
const _GT = 'Guatemala';
const _GG = 'Guernsey';
const _GN = 'Guinea';
const _GW = 'Guinea-Bissau';
const _GY = 'Guyana';
const _HT = 'Haiti';
const _HM = 'Heard Island & Mcdonald Islands';
const _VA = 'Holy See (Vatican City State)';
const _HN = 'Honduras';
const _HK = 'Hong Kong';
const _HU = 'Hungary';
const _IS = 'Iceland';
const _IN = 'India';
const _ID = 'Indonesia';
const _IR = 'Iran, Islamic Republic Of';
const _IQ = 'Iraq';
const _IE = 'Ireland';
const _IM = 'Isle Of Man';
const _IL = 'Israel';
const _IT = 'Italy';
const _JM = 'Jamaica';
const _JP = 'Japan';
const _JE = 'Jersey';
const _JO = 'Jordan';
const _KZ = 'Kazakhstan';
const _KE = 'Kenya';
const _KI = 'Kiribati';
const _KR = 'Korea';
const _KW = 'Kuwait';
const _KG = 'Kyrgyzstan';
const _LA = 'Lao People\'s Democratic Republic';
const _LV = 'Latvia';
const _LB = 'Lebanon';
const _LS = 'Lesotho';
const _LR = 'Liberia';
const _LY = 'Libyan Arab Jamahiriya';
const _LI = 'Liechtenstein';
const _LT = 'Lithuania';
const _LU = 'Luxembourg';
const _MO = 'Macao';
const _MK = 'Macedonia';
const _MG = 'Madagascar';
const _MW = 'Malawi';
const _MY = 'Malaysia';
const _MV = 'Maldives';
const _ML = 'Mali';
const _MT = 'Malta';
const _MH = 'Marshall Islands';
const _MQ = 'Martinique';
const _MR = 'Mauritania';
const _MU = 'Mauritius';
const _YT = 'Mayotte';
const _MX = 'Mexico';
const _FM = 'Micronesia, Federated States Of';
const _MD = 'Moldova';
const _MC = 'Monaco';
const _MN = 'Mongolia';
const _ME = 'Montenegro';
const _MS = 'Montserrat';
const _MA = 'Morocco';
const _MZ = 'Mozambique';
const _MM = 'Myanmar';
const _NA = 'Namibia';
const _NR = 'Nauru';
const _NP = 'Nepal';
const _NL = 'Netherlands';
const _AN = 'Netherlands Antilles';
const _NC = 'New Caledonia';
const _NZ = 'New Zealand';
const _NI = 'Nicaragua';
const _NE = 'Niger';
const _NG = 'Nigeria';
const _NU = 'Niue';
const _NF = 'Norfolk Island';
const _MP = 'Northern Mariana Islands';
const _NO = 'Norway';
const _OM = 'Oman';
const _PK = 'Pakistan';
const _PW = 'Palau';
const _PS = 'Palestinian Territory, Occupied';
const _PA = 'Panama';
const _PG = 'Papua New Guinea';
const _PY = 'Paraguay';
const _PE = 'Peru';
const _PH = 'Philippines';
const _PN = 'Pitcairn';
const _PL = 'Poland';
const _PT = 'Portugal';
const _PR = 'Puerto Rico';
const _QA = 'Qatar';
const _RE = 'Reunion';
const _RO = 'Romania';
const _RU = 'Russian Federation';
const _RW = 'Rwanda';
const _BL = 'Saint Barthelemy';
const _SH = 'Saint Helena';
const _KN = 'Saint Kitts And Nevis';
const _LC = 'Saint Lucia';
const _MF = 'Saint Martin';
const _PM = 'Saint Pierre And Miquelon';
const _VC = 'Saint Vincent And Grenadines';
const _WS = 'Samoa';
const _SM = 'San Marino';
const _ST = 'Sao Tome And Principe';
const _SA = 'Saudi Arabia';
const _SN = 'Senegal';
const _RS = 'Serbia';
const _SC = 'Seychelles';
const _SL = 'Sierra Leone';
const _SG = 'Singapore';
const _SK = 'Slovakia';
const _SI = 'Slovenia';
const _SB = 'Solomon Islands';
const _SO = 'Somalia';
const _ZA = 'South Africa';
const _GS = 'South Georgia And Sandwich Isl.';
const _ES = 'Spain';
const _LK = 'Sri Lanka';
const _SD = 'Sudan';
const _SR = 'Suriname';
const _SJ = 'Svalbard And Jan Mayen';
const _SZ = 'Swaziland';
const _SE = 'Sweden';
const _CH = 'Switzerland';
const _SY = 'Syrian Arab Republic';
const _TW = 'Taiwan';
const _TJ = 'Tajikistan';
const _TZ = 'Tanzania';
const _TH = 'Thailand';
const _TL = 'Timor-Leste';
const _TG = 'Togo';
const _TK = 'Tokelau';
const _TO = 'Tonga';
const _TT = 'Trinidad And Tobago';
const _TN = 'Tunisia';
const _TR = 'Turkey';
const _TM = 'Turkmenistan';
const _TC = 'Turks And Caicos Islands';
const _TV = 'Tuvalu';
const _UG = 'Uganda';
const _UA = 'Ukraine';
const _AE = 'United Arab Emirates';
const _GB = 'United Kingdom';
const _US = 'United States';
const _UM = 'United States Outlying Islands';
const _UY = 'Uruguay';
const _UZ = 'Uzbekistan';
const _VU = 'Vanuatu';
const _VE = 'Venezuela';
const _VN = 'Viet Nam';
const _VG = 'Virgin Islands, British';
const _VI = 'Virgin Islands, U.S.';
const _WF = 'Wallis And Futuna';
const _EH = 'Western Sahara';
const _YE = 'Yemen';
const _ZM = 'Zambia';
const _ZW = 'Zimbabwe';
}

View File

@ -0,0 +1,280 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\EnumArray;
/**
* Country codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO3166EnumArray extends EnumArray
{
protected static $constants = [
'af' => 'Afghanistan',
'ax' => 'Aland Islands',
'al' => 'Albania',
'dz' => 'Algeria',
'as' => 'American Samoa',
'ad' => 'Andorra',
'ao' => 'Angola',
'ai' => 'Anguilla',
'aq' => 'Antarctica',
'ag' => 'Antigua And Barbuda',
'ar' => 'Argentina',
'am' => 'Armenia',
'aw' => 'Aruba',
'au' => 'Australia',
'at' => 'Austria',
'az' => 'Azerbaijan',
'bs' => 'Bahamas',
'bh' => 'Bahrain',
'bd' => 'Bangladesh',
'bb' => 'Barbados',
'by' => 'Belarus',
'be' => 'Belgium',
'bz' => 'Belize',
'bj' => 'Benin',
'bm' => 'Bermuda',
'bt' => 'Bhutan',
'bo' => 'Bolivia',
'ba' => 'Bosnia And Herzegovina',
'bw' => 'Botswana',
'bv' => 'Bouvet Island',
'br' => 'Brazil',
'io' => 'British Indian Ocean Territory',
'bn' => 'Brunei Darussalam',
'bg' => 'Bulgaria',
'bf' => 'Burkina Faso',
'bi' => 'Burundi',
'kh' => 'Cambodia',
'cm' => 'Cameroon',
'ca' => 'Canada',
'cv' => 'Cape Verde',
'ky' => 'Cayman Islands',
'cf' => 'Central African Republic',
'td' => 'Chad',
'cl' => 'Chile',
'cn' => 'China',
'cx' => 'Christmas Island',
'cc' => 'Cocos (Keeling) Islands',
'co' => 'Colombia',
'km' => 'Comoros',
'cg' => 'Congo',
'cd' => 'Congo, Democratic Republic',
'ck' => 'Cook Islands',
'cr' => 'Costa Rica',
'ci' => 'Cote D\'Ivoire',
'hr' => 'Croatia',
'cu' => 'Cuba',
'cy' => 'Cyprus',
'cz' => 'Czech Republic',
'dk' => 'Denmark',
'dj' => 'Djibouti',
'dm' => 'Dominica',
'do' => 'Dominican Republic',
'ec' => 'Ecuador',
'eg' => 'Egypt',
'sv' => 'El Salvador',
'gq' => 'Equatorial Guinea',
'er' => 'Eritrea',
'ee' => 'Estonia',
'et' => 'Ethiopia',
'fk' => 'Falkland Islands (Malvinas)',
'fo' => 'Faroe Islands',
'fj' => 'Fiji',
'fi' => 'Finland',
'fr' => 'France',
'gf' => 'French Guiana',
'pf' => 'French Polynesia',
'tf' => 'French Southern Territories',
'ga' => 'Gabon',
'gm' => 'Gambia',
'ge' => 'Georgia',
'de' => 'Germany',
'gh' => 'Ghana',
'gi' => 'Gibraltar',
'gr' => 'Greece',
'gl' => 'Greenland',
'gd' => 'Grenada',
'gp' => 'Guadeloupe',
'gu' => 'Guam',
'gt' => 'Guatemala',
'gg' => 'Guernsey',
'gn' => 'Guinea',
'gw' => 'Guinea-Bissau',
'gy' => 'Guyana',
'ht' => 'Haiti',
'hm' => 'Heard Island & Mcdonald Islands',
'va' => 'Holy See (Vatican City State)',
'hn' => 'Honduras',
'hk' => 'Hong Kong',
'hu' => 'Hungary',
'is' => 'Iceland',
'in' => 'India',
'id' => 'Indonesia',
'ir' => 'Iran, Islamic Republic Of',
'iq' => 'Iraq',
'ie' => 'Ireland',
'im' => 'Isle Of Man',
'il' => 'Israel',
'it' => 'Italy',
'jm' => 'Jamaica',
'jp' => 'Japan',
'je' => 'Jersey',
'jo' => 'Jordan',
'kz' => 'Kazakhstan',
'ke' => 'Kenya',
'ki' => 'Kiribati',
'kr' => 'Korea',
'kw' => 'Kuwait',
'kg' => 'Kyrgyzstan',
'la' => 'Lao People\'s Democratic Republic',
'lv' => 'Latvia',
'lb' => 'Lebanon',
'ls' => 'Lesotho',
'lr' => 'Liberia',
'ly' => 'Libyan Arab Jamahiriya',
'li' => 'Liechtenstein',
'lt' => 'Lithuania',
'lu' => 'Luxembourg',
'mo' => 'Macao',
'mk' => 'Macedonia',
'mg' => 'Madagascar',
'mw' => 'Malawi',
'my' => 'Malaysia',
'mv' => 'Maldives',
'ml' => 'Mali',
'mt' => 'Malta',
'mh' => 'Marshall Islands',
'mq' => 'Martinique',
'mr' => 'Mauritania',
'mu' => 'Mauritius',
'yt' => 'Mayotte',
'mx' => 'Mexico',
'fm' => 'Micronesia, Federated States Of',
'md' => 'Moldova',
'mc' => 'Monaco',
'mn' => 'Mongolia',
'me' => 'Montenegro',
'ms' => 'Montserrat',
'ma' => 'Morocco',
'mz' => 'Mozambique',
'mm' => 'Myanmar',
'na' => 'Namibia',
'nr' => 'Nauru',
'np' => 'Nepal',
'nl' => 'Netherlands',
'an' => 'Netherlands Antilles',
'nc' => 'New Caledonia',
'nz' => 'New Zealand',
'ni' => 'Nicaragua',
'ne' => 'Niger',
'ng' => 'Nigeria',
'nu' => 'Niue',
'nf' => 'Norfolk Island',
'mp' => 'Northern Mariana Islands',
'no' => 'Norway',
'om' => 'Oman',
'pk' => 'Pakistan',
'pw' => 'Palau',
'ps' => 'Palestinian Territory, Occupied',
'pa' => 'Panama',
'pg' => 'Papua New Guinea',
'py' => 'Paraguay',
'pe' => 'Peru',
'ph' => 'Philippines',
'pn' => 'Pitcairn',
'pl' => 'Poland',
'pt' => 'Portugal',
'pr' => 'Puerto Rico',
'qa' => 'Qatar',
're' => 'Reunion',
'ro' => 'Romania',
'ru' => 'Russian Federation',
'rw' => 'Rwanda',
'bl' => 'Saint Barthelemy',
'sh' => 'Saint Helena',
'kn' => 'Saint Kitts And Nevis',
'lc' => 'Saint Lucia',
'mf' => 'Saint Martin',
'pm' => 'Saint Pierre And Miquelon',
'vc' => 'Saint Vincent And Grenadines',
'ws' => 'Samoa',
'sm' => 'San Marino',
'st' => 'Sao Tome And Principe',
'sa' => 'Saudi Arabia',
'sn' => 'Senegal',
'rs' => 'Serbia',
'sc' => 'Seychelles',
'sl' => 'Sierra Leone',
'sg' => 'Singapore',
'sk' => 'Slovakia',
'si' => 'Slovenia',
'sb' => 'Solomon Islands',
'so' => 'Somalia',
'za' => 'South Africa',
'gs' => 'South Georgia And Sandwich Isl.',
'es' => 'Spain',
'lk' => 'Sri Lanka',
'sd' => 'Sudan',
'sr' => 'Suriname',
'sj' => 'Svalbard And Jan Mayen',
'sz' => 'Swaziland',
'se' => 'Sweden',
'ch' => 'Switzerland',
'sy' => 'Syrian Arab Republic',
'tw' => 'Taiwan',
'tj' => 'Tajikistan',
'tz' => 'Tanzania',
'th' => 'Thailand',
'tl' => 'Timor-Leste',
'tg' => 'Togo',
'tk' => 'Tokelau',
'to' => 'Tonga',
'tt' => 'Trinidad And Tobago',
'tn' => 'Tunisia',
'tr' => 'Turkey',
'tm' => 'Turkmenistan',
'tc' => 'Turks And Caicos Islands',
'tv' => 'Tuvalu',
'ug' => 'Uganda',
'ua' => 'Ukraine',
'ae' => 'United Arab Emirates',
'gb' => 'United Kingdom',
'us' => 'United States',
'um' => 'United States Outlying Islands',
'uy' => 'Uruguay',
'uz' => 'Uzbekistan',
'vu' => 'Vanuatu',
've' => 'Venezuela',
'vn' => 'Viet Nam',
'vg' => 'Virgin Islands, British',
'vi' => 'Virgin Islands, U.S.',
'wf' => 'Wallis And Futuna',
'eh' => 'Western Sahara',
'ye' => 'Yemen',
'zm' => 'Zambia',
'zw' => 'Zimbabwe',
];
}

View File

@ -0,0 +1,260 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\Enum;
/**
* Country codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO4217Enum extends Enum
{
const C_ALL = 'Albania, Leke';
const C_AFN = 'Afghanistan, Afghanis';
const C_ARS = 'Argentina, Pesos';
const C_AWG = 'Aruba, Guilders';
const C_AUD = 'Australia, Dollars';
const C_AZN = 'Azerbaijan, New Manats';
const C_BSD = 'Bahamas, Dollars';
const C_BBD = 'Barbados, Dollars';
const C_BYR = 'Belarus, Rubles';
const C_BZD = 'Belize, Dollars';
const C_BMD = 'Bermuda, Dollars';
const C_BOB = 'Bolivia, Bolivianos';
const C_BAM = 'Bosnia and Herzegovina, Convertible Marka';
const C_BWP = 'Botswana, Pulas';
const C_BGN = 'Bulgaria, Leva';
const C_BRL = 'Brazil, Reais';
const C_BND = 'Brunei Darussalam, Dollars';
const C_KHR = 'Cambodia, Riels';
const C_CAD = 'Canada, Dollars';
const C_KYD = 'Cayman Islands, Dollars';
const C_CLP = 'Chile, Pesos';
const C_CNY = 'China, Yuan Renminbi';
const C_COP = 'Colombia, Pesos';
const C_CRC = 'Costa Rica, Colón';
const C_HRK = 'Croatia, Kuna';
const C_CUP = 'Cuba, Pesos';
const C_CZK = 'Czech Republic, Koruny';
const C_DKK = 'Denmark, Kroner';
const C_DOP = 'Dominican Republic, Pesos';
const C_XCD = 'East Caribbean, Dollars';
const C_EGP = 'Egypt, Pounds';
const C_SVC = 'El Salvador, Colones';
const C_EEK = 'Estonia, Krooni';
const C_EUR = 'Euro';
const C_FKP = 'Falkland Islands, Pounds';
const C_FJD = 'Fiji, Dollars';
const C_GHC = 'Ghana, Cedis';
const C_GIP = 'Gibraltar, Pounds';
const C_GTQ = 'Guatemala, Quetzales';
const C_GGP = 'Guernsey, Pounds';
const C_GYD = 'Guyana, Dollars';
const C_HNL = 'Honduras, Lempiras';
const C_HKD = 'Hong Kong, Dollars';
const C_HUF = 'Hungary, Forint';
const C_ISK = 'Iceland, Kronur';
const C_INR = 'India, Rupees';
const C_IDR = 'Indonesia, Rupiahs';
const C_IRR = 'Iran, Rials';
const C_IMP = 'Isle of Man, Pounds';
const C_ILS = 'Israel, New Shekels';
const C_JMD = 'Jamaica, Dollars';
const C_JPY = 'Japan, Yen';
const C_JEP = 'Jersey, Pounds';
const C_KZT = 'Kazakhstan, Tenge';
const C_KES = 'Kenyan Shilling';
const C_KGS = 'Kyrgyzstan, Soms';
const C_LAK = 'Laos, Kips';
const C_LVL = 'Latvia, Lati';
const C_LBP = 'Lebanon, Pounds';
const C_LRD = 'Liberia, Dollars';
const C_LTL = 'Lithuania, Litai';
const C_MKD = 'Macedonia, Denars';
const C_MYR = 'Malaysia, Ringgits';
const C_MUR = 'Mauritius, Rupees';
const C_MXN = 'Mexico, Pesos';
const C_MNT = 'Mongolia, Tugriks';
const C_MZN = 'Mozambique, Meticais';
const C_NAD = 'Namibia, Dollars';
const C_NPR = 'Nepal, Rupees';
const C_ANG = 'Netherlands Antilles, Guilders';
const C_NZD = 'New Zealand, Dollars';
const C_NIO = 'Nicaragua, Cordobas';
const C_NGN = 'Nigeria, Nairas';
const C_KPW = 'North Korea, Won';
const C_NOK = 'Norway, Krone';
const C_OMR = 'Oman, Rials';
const C_PKR = 'Pakistan, Rupees';
const C_PAB = 'Panama, Balboa';
const C_PYG = 'Paraguay, Guarani';
const C_PEN = 'Peru, Nuevos Soles';
const C_PHP = 'Philippines, Pesos';
const C_PLN = 'Poland, Zlotych';
const C_QAR = 'Qatar, Rials';
const C_RON = 'Romania, New Lei';
const C_RUB = 'Russia, Rubles';
const C_SHP = 'Saint Helena, Pounds';
const C_SAR = 'Saudi Arabia, Riyals';
const C_RSD = 'Serbia, Dinars';
const C_SCR = 'Seychelles, Rupees';
const C_SGD = 'Singapore, Dollars';
const C_SBD = 'Solomon Islands, Dollars';
const C_SOS = 'Somalia, Shillings';
const C_ZAR = 'South Africa, Rand';
const C_KRW = 'South Korea, Won';
const C_LKR = 'Sri Lanka, Rupees';
const C_SEK = 'Sweden, Kronor';
const C_CHF = 'Switzerland, Francs';
const C_SRD = 'Suriname, Dollars';
const C_SYP = 'Syria, Pounds';
const C_TWD = 'Taiwan, New Dollars';
const C_THB = 'Thailand, Baht';
const C_TTD = 'Trinidad and Tobago, Dollars';
const C_TRY = 'Turkey, Lira';
const C_TRL = 'Turkey, Liras';
const C_TVD = 'Tuvalu, Dollars';
const C_UAH = 'Ukraine, Hryvnia';
const C_GBP = 'United Kingdom, Pounds';
const C_USD = 'United States of America, Dollars';
const C_UYU = 'Uruguay, Pesos';
const C_UZS = 'Uzbekistan, Sums';
const C_VEF = 'Venezuela, Bolivares Fuertes';
const C_VND = 'Vietnam, Dong';
const C_YER = 'Yemen, Rials';
const C_ZWD = 'Zimbabwe, Zimbabwe Dollars';
}

View File

@ -0,0 +1,149 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\EnumArray;
/**
* Currency codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO4217EnumArray extends EnumArray
{
protected static $constants = [
'ALL' => ['Albania, Leke', '4c, 65, 6b'],
'AFN' => ['Afghanistan, Afghanis', '60b'],
'ARS' => ['Argentina, Pesos', '24'],
'AWG' => ['Aruba, Guilders', '192'],
'AUD' => ['Australia, Dollars', '24'],
'AZN' => ['Azerbaijan, New Manats', '43c, 430, 43d'],
'BSD' => ['Bahamas, Dollars', '24'],
'BBD' => ['Barbados, Dollars', '24'],
'BYR' => ['Belarus, Rubles', '70, 2e'],
'BZD' => ['Belize, Dollars', '42, 5a, 24'],
'BMD' => ['Bermuda, Dollars', '24'],
'BOB' => ['Bolivia, Bolivianos', '24, 62'],
'BAM' => ['Bosnia and Herzegovina, Convertible Marka', '4b, 4d'],
'BWP' => ['Botswana, Pulas', '50'],
'BGN' => ['Bulgaria, Leva', '43b, 432'],
'BRL' => ['Brazil, Reais', '52, 24'],
'BND' => ['Brunei Darussalam, Dollars', '24'],
'KHR' => ['Cambodia, Riels', '17db'],
'CAD' => ['Canada, Dollars', '24'],
'KYD' => ['Cayman Islands, Dollars', '24'],
'CLP' => ['Chile, Pesos', '24'],
'CNY' => ['China, Yuan Renminbi', 'a5'],
'COP' => ['Colombia, Pesos', '24'],
'CRC' => ['Costa Rica, Colón', '20a1'],
'HRK' => ['Croatia, Kuna', '6b, 6e'],
'CUP' => ['Cuba, Pesos', '20b1'],
'CZK' => ['Czech Republic, Koruny', '4b, 10d'],
'DKK' => ['Denmark, Kroner', '6b, 72'],
'DOP' => ['Dominican Republic, Pesos', '52, 44, 24'],
'XCD' => ['East Caribbean, Dollars', '24'],
'EGP' => ['Egypt, Pounds', 'a3'],
'SVC' => ['El Salvador, Colones', '24'],
'EEK' => ['Estonia, Krooni', '6b, 72'],
'EUR' => ['Euro', '20ac'],
'FKP' => ['Falkland Islands, Pounds', 'a3'],
'FJD' => ['Fiji, Dollars', '24'],
'GHC' => ['Ghana, Cedis', 'a2'],
'GIP' => ['Gibraltar, Pounds', 'a3'],
'GTQ' => ['Guatemala, Quetzales', '51'],
'GGP' => ['Guernsey, Pounds', 'a3'],
'GYD' => ['Guyana, Dollars', '24'],
'HNL' => ['Honduras, Lempiras', '4c'],
'HKD' => ['Hong Kong, Dollars', '24'],
'HUF' => ['Hungary, Forint', '46, 74'],
'ISK' => ['Iceland, Kronur', '6b, 72'],
'INR' => ['India, Rupees', '20a8'],
'IDR' => ['Indonesia, Rupiahs', '52, 70'],
'IRR' => ['Iran, Rials', 'fdfc'],
'IMP' => ['Isle of Man, Pounds', 'a3'],
'ILS' => ['Israel, New Shekels', '20aa'],
'JMD' => ['Jamaica, Dollars', '4a, 24'],
'JPY' => ['Japan, Yen', 'a5'],
'JEP' => ['Jersey, Pounds', 'a3'],
'KZT' => ['Kazakhstan, Tenge', '43b, 432'],
'KES' => ['Kenyan Shilling', '4b, 73, 68, 73'],
'KGS' => ['Kyrgyzstan, Soms', '43b, 432'],
'LAK' => ['Laos, Kips', '20ad'],
'LVL' => ['Latvia, Lati', '4c, 73'],
'LBP' => ['Lebanon, Pounds', 'a3'],
'LRD' => ['Liberia, Dollars', '24'],
'LTL' => ['Lithuania, Litai', '4c, 74'],
'MKD' => ['Macedonia, Denars', '434, 435, 43d'],
'MYR' => ['Malaysia, Ringgits', '52, 4d'],
'MUR' => ['Mauritius, Rupees', '20a8'],
'MXN' => ['Mexico, Pesos', '24'],
'MNT' => ['Mongolia, Tugriks', '20ae'],
'MZN' => ['Mozambique, Meticais', '4d, 54'],
'NAD' => ['Namibia, Dollars', '24'],
'NPR' => ['Nepal, Rupees', '20a8'],
'ANG' => ['Netherlands Antilles, Guilders', '192'],
'NZD' => ['New Zealand, Dollars', '24'],
'NIO' => ['Nicaragua, Cordobas', '43, 24'],
'NGN' => ['Nigeria, Nairas', '20a6'],
'KPW' => ['North Korea, Won', '20a9'],
'NOK' => ['Norway, Krone', '6b, 72'],
'OMR' => ['Oman, Rials', 'fdfc'],
'PKR' => ['Pakistan, Rupees', '20a8'],
'PAB' => ['Panama, Balboa', '42, 2f, 2e'],
'PYG' => ['Paraguay, Guarani', '47, 73'],
'PEN' => ['Peru, Nuevos Soles', '53, 2f, 2e'],
'PHP' => ['Philippines, Pesos', '50, 68, 70'],
'PLN' => ['Poland, Zlotych', '7a, 142'],
'QAR' => ['Qatar, Rials', 'fdfc'],
'RON' => ['Romania, New Lei', '6c, 65, 69'],
'RUB' => ['Russia, Rubles', '440, 443, 431'],
'SHP' => ['Saint Helena, Pounds', 'a3'],
'SAR' => ['Saudi Arabia, Riyals', 'fdfc'],
'RSD' => ['Serbia, Dinars', '414, 438, 43d, 2e'],
'SCR' => ['Seychelles, Rupees', '20a8'],
'SGD' => ['Singapore, Dollars', '24'],
'SBD' => ['Solomon Islands, Dollars', '24'],
'SOS' => ['Somalia, Shillings', '53'],
'ZAR' => ['South Africa, Rand', '52'],
'KRW' => ['South Korea, Won', '20a9'],
'LKR' => ['Sri Lanka, Rupees', '20a8'],
'SEK' => ['Sweden, Kronor', '6b, 72'],
'CHF' => ['Switzerland, Francs', '43, 48, 46'],
'SRD' => ['Suriname, Dollars', '24'],
'SYP' => ['Syria, Pounds', 'a3'],
'TWD' => ['Taiwan, New Dollars', '4e, 54, 24'],
'THB' => ['Thailand, Baht', 'e3f'],
'TTD' => ['Trinidad and Tobago, Dollars', '54, 54, 24'],
'TRY' => ['Turkey, Lira', '54, 4c'],
'TRL' => ['Turkey, Liras', '20a4'],
'TVD' => ['Tuvalu, Dollars', '24'],
'UAH' => ['Ukraine, Hryvnia', '20b4'],
'GBP' => ['United Kingdom, Pounds', 'a3'],
'USD' => ['United States of America, Dollars', '24'],
'UYU' => ['Uruguay, Pesos', '24, 55'],
'UZS' => ['Uzbekistan, Sums', '43b, 432'],
'VEF' => ['Venezuela, Bolivares Fuertes', '42, 73'],
'VND' => ['Vietnam, Dong', '20ab'],
'YER' => ['Yemen, Rials', 'fdfc'],
'ZWD' => ['Zimbabwe, Zimbabwe Dollars', '5a, 24'],
];
}

400
Localization/ISO639Enum.php Normal file
View File

@ -0,0 +1,400 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\Enum;
/**
* Language codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO639Enum extends Enum
{
const _AA = 'Afar';
const _AB = 'Abkhaz';
const _AE = 'Avestan';
const _AF = 'Afrikaans';
const _AK = 'Akan';
const _AM = 'Amharic';
const _AN = 'Aragonese';
const _AR = 'Arabic';
const _AS = 'Assamese';
const _AV = 'Avaric';
const _AY = 'Aymara';
const _AZ = 'Azerbaijani';
const _BA = 'Bashkir';
const _BE = 'Belarusian';
const _BG = 'Bulgarian';
const _BH = 'Bihari';
const _BI = 'Bislama';
const _BM = 'Bambara';
const _BN = 'Bengali';
const _BO = 'Tibetan Standard, Tibetan, Central';
const _BR = 'Breton';
const _BS = 'Bosnian';
const _CA = 'Catalan; Valencian';
const _CE = 'Chechen';
const _CH = 'Chamorro';
const _CO = 'Corsican';
const _CR = 'Cree';
const _CS = 'Czech';
const _CU = 'Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic';
const _CV = 'Chuvash';
const _CY = 'Welsh';
const _DA = 'Danish';
const _DE = 'German';
const _DV = 'Divehi; Dhivehi; Maldivian;';
const _DZ = 'Dzongkha';
const _EE = 'Ewe';
const _EL = 'Greek, Modern';
const _EN = 'English';
const _EO = 'Esperanto';
const _ES = 'Spanish; Castilian';
const _ET = 'Estonian';
const _EU = 'Basque';
const _FA = 'Persian';
const _FF = 'Fula; Fulah; Pulaar; Pular';
const _FI = 'Finnish';
const _FJ = 'Fijian';
const _FO = 'Faroese';
const _FR = 'French';
const _FY = 'Western Frisian';
const _GA = 'Irish';
const _GD = 'Scottish Gaelic; Gaelic';
const _GL = 'Galician';
const _GN = 'Guaraní';
const _GU = 'Gujarati';
const _GV = 'Manx';
const _HA = 'Hausa';
const _HE = 'Hebrew (modern)';
const _HI = 'Hindi';
const _HO = 'Hiri Motu';
const _HR = 'Croatian';
const _HT = 'Haitian; Haitian Creole';
const _HU = 'Hungarian';
const _HY = 'Armenian';
const _HZ = 'Herero';
const _IA = 'Interlingua';
const _ID = 'Indonesian';
const _IE = 'Interlingue';
const _IG = 'Igbo';
const _II = 'Nuosu';
const _IK = 'Inupiaq';
const _IO = 'Ido';
const _IS = 'Icelandic';
const _IT = 'Italian';
const _IU = 'Inuktitut';
const _JA = 'Japanese (ja)';
const _JV = 'Javanese (jv)';
const _KA = 'Georgian';
const _KG = 'Kongo';
const _KI = 'Kikuyu, Gikuyu';
const _KJ = 'Kwanyama, Kuanyama';
const _KK = 'Kazakh';
const _KL = 'Kalaallisut, Greenlandic';
const _KM = 'Khmer';
const _KN = 'Kannada';
const _KO = 'Korean';
const _KR = 'Kanuri';
const _KS = 'Kashmiri';
const _KU = 'Kurdish';
const _KV = 'Komi';
const _KW = 'Cornish';
const _KY = 'Kirghiz, Kyrgyz';
const _LA = 'Latin';
const _LB = 'Luxembourgish, Letzeburgesch';
const _LG = 'Luganda';
const _LI = 'Limburgish, Limburgan, Limburger';
const _LN = 'Lingala';
const _LO = 'Lao';
const _LT = 'Lithuanian';
const _LU = 'Luba-Katanga';
const _LV = 'Latvian';
const _MG = 'Malagasy';
const _MH = 'Marshallese';
const _MI = 'Maori';
const _MK = 'Macedonian';
const _ML = 'Malayalam';
const _MN = 'Mongolian';
const _MR = 'Marathi (Mara?hi)';
const _MS = 'Malay';
const _MT = 'Maltese';
const _MY = 'Burmese';
const _NA = 'Nauru';
const _NB = 'Norwegian Bokmål';
const _ND = 'North Ndebele';
const _NE = 'Nepali';
const _NG = 'Ndonga';
const _NL = 'Dutch';
const _NN = 'Norwegian Nynorsk';
const _NO = 'Norwegian';
const _NR = 'South Ndebele';
const _NV = 'Navajo, Navaho';
const _NY = 'Chichewa; Chewa; Nyanja';
const _OC = 'Occitan';
const _OJ = 'Ojibwe, Ojibwa';
const _OM = 'Oromo';
const _OR = 'Oriya';
const _OS = 'Ossetian, Ossetic';
const _PA = 'Panjabi, Punjabi';
const _PI = 'Pali';
const _PL = 'Polish';
const _PS = 'Pashto, Pushto';
const _PT = 'Portuguese';
const _QU = 'Quechua';
const _RM = 'Romansh';
const _RN = 'Kirundi';
const _RO = 'Romanian, Moldavian, Moldovan';
const _RU = 'Russian';
const _RW = 'Kinyarwanda';
const _SA = 'Sanskrit (Sa?sk?ta)';
const _SC = 'Sardinian';
const _SD = 'Sindhi';
const _SE = 'Northern Sami';
const _SG = 'Sango';
const _SI = 'Sinhala, Sinhalese';
const _SK = 'Slovak';
const _SL = 'Slovene';
const _SM = 'Samoan';
const _SN = 'Shona';
const _SO = 'Somali';
const _SQ = 'Albanian';
const _SR = 'Serbian';
const _SS = 'Swati';
const _ST = 'Southern Sotho';
const _SU = 'Sundanese';
const _SV = 'Swedish';
const _SW = 'Swahili';
const _TA = 'Tamil';
const _TE = 'Telugu';
const _TG = 'Tajik';
const _TH = 'Thai';
const _TI = 'Tigrinya';
const _TK = 'Turkmen';
const _TL = 'Tagalog';
const _TN = 'Tswana';
const _TO = 'Tonga (Tonga Islands)';
const _TR = 'Turkish';
const _TS = 'Tsonga';
const _TT = 'Tatar';
const _TW = 'Twi';
const _TY = 'Tahitian';
const _UG = 'Uighur, Uyghur';
const _UK = 'Ukrainian';
const _UR = 'Urdu';
const _UZ = 'Uzbek';
const _VE = 'Venda';
const _VI = 'Vietnamese';
const _VO = 'Volapük';
const _WA = 'Walloon';
const _WO = 'Wolof';
const _XH = 'Xhosa';
const _YI = 'Yiddish';
const _YO = 'Yoruba';
const _ZA = 'Zhuang, Chuang';
const _ZH = 'Chinese';
const _ZU = 'Zulu';
}

View File

@ -0,0 +1,219 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\EnumArray;
/**
* Language codes ISO list.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO639EnumArray extends EnumArray
{
protected static $constants = [
'aa' => 'Afar',
'ab' => 'Abkhaz',
'ae' => 'Avestan',
'af' => 'Afrikaans',
'ak' => 'Akan',
'am' => 'Amharic',
'an' => 'Aragonese',
'ar' => 'Arabic',
'as' => 'Assamese',
'av' => 'Avaric',
'ay' => 'Aymara',
'az' => 'Azerbaijani',
'ba' => 'Bashkir',
'be' => 'Belarusian',
'bg' => 'Bulgarian',
'bh' => 'Bihari',
'bi' => 'Bislama',
'bm' => 'Bambara',
'bn' => 'Bengali',
'bo' => 'Tibetan Standard, Tibetan, Central',
'br' => 'Breton',
'bs' => 'Bosnian',
'ca' => 'Catalan; Valencian',
'ce' => 'Chechen',
'ch' => 'Chamorro',
'co' => 'Corsican',
'cr' => 'Cree',
'cs' => 'Czech',
'cu' => 'Old Church Slavonic, Church Slavic, Church Slavonic, Old Bulgarian, Old Slavonic',
'cv' => 'Chuvash',
'cy' => 'Welsh',
'da' => 'Danish',
'de' => 'German',
'dv' => 'Divehi; Dhivehi; Maldivian;',
'dz' => 'Dzongkha',
'ee' => 'Ewe',
'el' => 'Greek, Modern',
'en' => 'English',
'eo' => 'Esperanto',
'es' => 'Spanish; Castilian',
'et' => 'Estonian',
'eu' => 'Basque',
'fa' => 'Persian',
'ff' => 'Fula; Fulah; Pulaar; Pular',
'fi' => 'Finnish',
'fj' => 'Fijian',
'fo' => 'Faroese',
'fr' => 'French',
'fy' => 'Western Frisian',
'ga' => 'Irish',
'gd' => 'Scottish Gaelic; Gaelic',
'gl' => 'Galician',
'gn' => 'Guaraní',
'gu' => 'Gujarati',
'gv' => 'Manx',
'ha' => 'Hausa',
'he' => 'Hebrew (modern)',
'hi' => 'Hindi',
'ho' => 'Hiri Motu',
'hr' => 'Croatian',
'ht' => 'Haitian; Haitian Creole',
'hu' => 'Hungarian',
'hy' => 'Armenian',
'hz' => 'Herero',
'ia' => 'Interlingua',
'id' => 'Indonesian',
'ie' => 'Interlingue',
'ig' => 'Igbo',
'ii' => 'Nuosu',
'ik' => 'Inupiaq',
'io' => 'Ido',
'is' => 'Icelandic',
'it' => 'Italian',
'iu' => 'Inuktitut',
'ja' => 'Japanese (ja)',
'jv' => 'Javanese (jv)',
'ka' => 'Georgian',
'kg' => 'Kongo',
'ki' => 'Kikuyu, Gikuyu',
'kj' => 'Kwanyama, Kuanyama',
'kk' => 'Kazakh',
'kl' => 'Kalaallisut, Greenlandic',
'km' => 'Khmer',
'kn' => 'Kannada',
'ko' => 'Korean',
'kr' => 'Kanuri',
'ks' => 'Kashmiri',
'ku' => 'Kurdish',
'kv' => 'Komi',
'kw' => 'Cornish',
'ky' => 'Kirghiz, Kyrgyz',
'la' => 'Latin',
'lb' => 'Luxembourgish, Letzeburgesch',
'lg' => 'Luganda',
'li' => 'Limburgish, Limburgan, Limburger',
'ln' => 'Lingala',
'lo' => 'Lao',
'lt' => 'Lithuanian',
'lu' => 'Luba-Katanga',
'lv' => 'Latvian',
'mg' => 'Malagasy',
'mh' => 'Marshallese',
'mi' => 'Maori',
'mk' => 'Macedonian',
'ml' => 'Malayalam',
'mn' => 'Mongolian',
'mr' => 'Marathi (Mara?hi)',
'ms' => 'Malay',
'mt' => 'Maltese',
'my' => 'Burmese',
'na' => 'Nauru',
'nb' => 'Norwegian Bokmål',
'nd' => 'North Ndebele',
'ne' => 'Nepali',
'ng' => 'Ndonga',
'nl' => 'Dutch',
'nn' => 'Norwegian Nynorsk',
'no' => 'Norwegian',
'nr' => 'South Ndebele',
'nv' => 'Navajo, Navaho',
'ny' => 'Chichewa; Chewa; Nyanja',
'oc' => 'Occitan',
'oj' => 'Ojibwe, Ojibwa',
'om' => 'Oromo',
'or' => 'Oriya',
'os' => 'Ossetian, Ossetic',
'pa' => 'Panjabi, Punjabi',
'pi' => 'Pali',
'pl' => 'Polish',
'ps' => 'Pashto, Pushto',
'pt' => 'Portuguese',
'qu' => 'Quechua',
'rm' => 'Romansh',
'rn' => 'Kirundi',
'ro' => 'Romanian, Moldavian, Moldovan',
'ru' => 'Russian',
'rw' => 'Kinyarwanda',
'sa' => 'Sanskrit (Sa?sk?ta)',
'sc' => 'Sardinian',
'sd' => 'Sindhi',
'se' => 'Northern Sami',
'sg' => 'Sango',
'si' => 'Sinhala, Sinhalese',
'sk' => 'Slovak',
'sl' => 'Slovene',
'sm' => 'Samoan',
'sn' => 'Shona',
'so' => 'Somali',
'sq' => 'Albanian',
'sr' => 'Serbian',
'ss' => 'Swati',
'st' => 'Southern Sotho',
'su' => 'Sundanese',
'sv' => 'Swedish',
'sw' => 'Swahili',
'ta' => 'Tamil',
'te' => 'Telugu',
'tg' => 'Tajik',
'th' => 'Thai',
'ti' => 'Tigrinya',
'tk' => 'Turkmen',
'tl' => 'Tagalog',
'tn' => 'Tswana',
'to' => 'Tonga (Tonga Islands)',
'tr' => 'Turkish',
'ts' => 'Tsonga',
'tt' => 'Tatar',
'tw' => 'Twi',
'ty' => 'Tahitian',
'ug' => 'Uighur, Uyghur',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
've' => 'Venda',
'vi' => 'Vietnamese',
'vo' => 'Volapük',
'wa' => 'Walloon',
'wo' => 'Wolof',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'yo' => 'Yoruba',
'za' => 'Zhuang, Chuang',
'zh' => 'Chinese',
'zu' => 'Zulu',
];
}

View File

@ -0,0 +1,42 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\EnumArray;
/**
* Datetime ISO format.
*
* Careful only (1) is considered as the ISO8601 standard. This file is only supposed to
* contain all plausible datetime strings.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ISO8601EnumArray extends EnumArray
{
protected static $constants = [
1 => 'YYYY-MM-DD hh:mm:ss', // ietf: rfc3339
2 => 'YYYY.MM.DD hh:mm:ss',
3 => 'DD-MM-YYYY hh:mm:ss',
4 => 'DD.MM.YYYY hh:mm:ss',
];
}

View File

@ -0,0 +1,107 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
/**
* Localization class.
*
* @category Framework
* @package phpOMS\Localization
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class L11nManager
{
/**
* Language.
*
* @var \string[][]
* @since 1.0.0
*/
private $language = [];
/**
* Verify if language is loaded.
*
* @param \string $language Language iso code
*
* @return \bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function isLanguageLoaded(\string $language) : \bool
{
return isset($this->language[$language]);
}
/**
* Load language.
*
* One module can only be loaded once. Once the module got loaded it's not
* possible to load more language files later on.
*
* @param \string $language Language iso code
* @param \string $from Module name
* @param \string[][] $files Language files content
*
* @return void
*
* @throws
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function loadLanguage(\string $language, \string $from, array $files)
{
if(!isset($files[$from])) {
throw new \Exception('Unexpected language key: ' . $from);
}
if (!isset($this->language[$language][$from])) {
$this->language[$language][$from] = $files[$from];
} else {
/** @noinspection PhpWrongStringConcatenationInspection */
$this->language[$language][$from] = $files[$from] + $this->language[$language][$from];
}
}
/**
* Get application language.
*
* @param \string $language Language iso code
* @param \string $module Module name
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLanguage(\string $language, \string $module = null) : array
{
if (!isset($module) && isset($this->language[$language])) {
return $this->language[$language];
} elseif (isset($this->language[$language])) {
return $this->language[$language][$module];
} else {
return [];
}
}
}

View File

@ -0,0 +1,287 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
use phpOMS\Datatypes\Exception\InvalidEnumName;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
/**
* Localization class.
*
* @category Framework
* @package phpOMS\Localization
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Localization
{
/**
* Country ID.
*
* @var \string
* @since 1.0.0
*/
public $country = null;
/**
* Timezone.
*
* @var \string
* @since 1.0.0
*/
public $timezone = null;
/**
* Language ISO code.
*
* @var \string
* @since 1.0.0
*/
public $language = 'en';
/**
* Currency.
*
* @var \string
* @since 1.0.0
*/
public $currency = null;
/**
* Number format.
*
* @var \string
* @since 1.0.0
*/
public $numberformat = null;
/**
* Time format.
*
* @var \string
* @since 1.0.0
*/
public $datetime = null;
/**
* Language array.
*
* @var \string[]
* @since 1.0.0
*/
public $lang = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
// TODO: implement!!!
setlocale(LC_TIME, '');
setlocale(LC_NUMERIC, '');
setlocale(LC_MONETARY, '');
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCountry() : \string
{
return $this->country;
}
/**
* @param \string $country
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCountry(\string $country)
{
if(!ISO3166Enum::isValidValue($country)) {
throw new InvalidEnumValue($country);
}
$this->country = $country;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTimezone() : \string
{
return $this->timezone;
}
/**
* @param \string $timezone
*
* @todo: maybe make parameter int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setTimezone(\string $timezone)
{
if(!TimeZoneEnumArray::isValidValue($timezone)) {
throw new InvalidEnumValue($timezone);
}
$this->timezone = $timezone;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLanguage() : \string
{
return $this->language;
}
/**
* @param \string $language
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setLanguage(\string $language)
{
if(!ISO639EnumArray::isValidName($language)) {
throw new InvalidEnumName($language);
}
$this->language = $language;
}
/**
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLang() : array
{
return $this->lang;
}
/**
* @param array $lang
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setLang(array $lang)
{
$this->lang = $lang;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCurrency() : \string
{
return $this->currency;
}
/**
* @param \string $currency
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCurrency(\string $currency)
{
if(!ISO4217EnumArray::isValidName($currency)) {
throw new InvalidEnumName($currency);
}
$this->currency = $currency;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDatetime() : \string
{
return $this->datetime;
}
/**
* @param \string $datetime
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDatetime(\string $datetime)
{
$this->datetime = $datetime;
}
/**
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getNumberformat() : \string
{
return $this->numberformat;
}
/**
* @param \string $numberformat
*
* @return \string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setNumberformat(\string $numberformat) : \string
{
$this->numberformat = $numberformat;
}
}

View File

@ -0,0 +1,34 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Localization;
/**
* Localization class.
*
* @category Framework
* @package phpOMS\Localization
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class NullLocalization extends Localization
{
}

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