Optimize imports and order

This commit is contained in:
Dennis Eichhorn 2016-07-15 21:30:16 +02:00
parent f176329d6c
commit 0376d85ace
19 changed files with 439 additions and 460 deletions

View File

@ -17,7 +17,6 @@ namespace phpOMS\Account;
use phpOMS\Contract\ArrayableInterface;
use phpOMS\Localization\Localization;
use phpOMS\Localization\NullLocalization;
use phpOMS\Validation\Base\Email;
/**

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\Account;
use phpOMS\Contract\ArrayableInterface;
/**
@ -131,19 +132,6 @@ class Group implements ArrayableInterface, \JsonSerializable
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;
}
/**
* Set group name.
*
@ -157,6 +145,19 @@ class Group implements ArrayableInterface, \JsonSerializable
$this->name = $name;
}
/**
* Get group description.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDescription() : string
{
return $this->description;
}
/**
* Set group description.
*
@ -170,22 +171,6 @@ class Group implements ArrayableInterface, \JsonSerializable
$this->description = $description;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'createdBy' => $this->createdBy,
'createdAt' => $this->createdAt->format('Y-m-d H:i:s'),
'permissions' => $this->permissions,
'members' => $this->members,
];
}
/**
* Get string representation.
*
@ -211,4 +196,20 @@ class Group implements ArrayableInterface, \JsonSerializable
{
return json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'createdBy' => $this->createdBy,
'createdAt' => $this->createdAt->format('Y-m-d H:i:s'),
'permissions' => $this->permissions,
'members' => $this->members,
];
}
}

View File

@ -15,9 +15,9 @@
*/
namespace phpOMS\Config;
use phpOMS\DataStorage\Database\DatabaseExceptionFactory;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\DatabaseExceptionFactory;
/**
* Settings class.

View File

@ -151,16 +151,16 @@ class Address implements \JsonSerializable
/**
* {@inheritdoc}
*/
public function toArray() : array
public function jsonSerialize(int $option = 0) : string
{
return ['recipient' => $this->recipient, 'fao' => $this->fao, 'location' => $this->location->toArray()];
return json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
public function jsonSerialize(int $option = 0) : string
public function toArray() : array
{
return json_encode($this->toArray());
return ['recipient' => $this->recipient, 'fao' => $this->fao, 'location' => $this->location->toArray()];
}
}

View File

@ -31,38 +31,6 @@ namespace phpOMS\Datatypes;
abstract class Enum
{
/**
* 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
{
return defined($name);
}
/**
* Getting all constants of this enum.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getConstants() : array
{
$reflect = new \ReflectionClass(get_called_class());
return $reflect->getConstants();
}
/**
* Check enum value.
*
@ -82,6 +50,21 @@ abstract class Enum
return in_array($value, $values, true);
}
/**
* Getting all constants of this enum.
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getConstants() : array
{
$reflect = new \ReflectionClass(get_called_class());
return $reflect->getConstants();
}
/**
* Get random enum value.
*
@ -111,11 +94,28 @@ abstract class Enum
*/
public static function getByName(string $name)
{
if(!self::isValidName($name)) {
if (!self::isValidName($name)) {
throw new \Exception('Undefined constant');
}
return constant($name);
}
/**
* 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
{
return defined($name);
}
}

View File

@ -73,16 +73,18 @@ class Iban implements \Serializable
}
/**
* Get 2 digit country code
* Normalize iban
*
* @param string $iban Iban to normalize
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCountry() : string
public static function normalize(string $iban) : string
{
return substr($this->iban, 0, 2);
return strtoupper(str_replace(' ', '', $iban));
}
/**
@ -98,6 +100,19 @@ class Iban implements \Serializable
return strlen($this->iban);
}
/**
* Get iban checksum
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getChecksum() : string
{
return $this->getSequence('k');
}
/**
* Get sequence specified in the layout
*
@ -124,16 +139,16 @@ class Iban implements \Serializable
}
/**
* Get iban checksum
* Get 2 digit country code
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getChecksum() : string
public function getCountry() : string
{
return $this->getSequence('k');
return substr($this->iban, 0, 2);
}
/**
@ -255,6 +270,17 @@ class Iban implements \Serializable
return $this->getSequence('a');
}
/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return $this->prettyPrint();
}
/**
* Pretty print iban
*
@ -268,32 +294,6 @@ class Iban implements \Serializable
return wordwrap($this->iban, 4, ' ', true);
}
/**
* Normalize iban
*
* @param string $iban Iban to normalize
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function normalize(string $iban) : string
{
return strtoupper(str_replace(' ', '', $iban));
}
/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return $this->prettyPrint();
}
/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php

View File

@ -231,6 +231,25 @@ class Location implements \JsonSerializable, \Serializable
$this->geo = $geo;
}
/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return $this->jsonSerialize();
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : string
{
return json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
@ -246,25 +265,6 @@ class Location implements \JsonSerializable, \Serializable
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : string
{
return json_encode($this->toArray());
}
/**
* String representation of object
* @link http://php.net/manual/en/serializable.serialize.php
* @return string the string representation of the object or null
* @since 5.1.0
*/
public function serialize()
{
return $this->jsonSerialize();
}
/**
* Constructs the object
* @link http://php.net/manual/en/serializable.unserialize.php

View File

@ -30,231 +30,231 @@ use phpOMS\Datatypes\Enum;
*/
class ISO4217CharEnum extends Enum
{
const C_ALL = 'ALL';
const C_ALL = 'ALL';
const C_AFN = 'AFN';
const C_AFN = 'AFN';
const C_ARS = 'ARS';
const C_ARS = 'ARS';
const C_AWG = 'AWG';
const C_AWG = 'AWG';
const C_AUD = 'AUD';
const C_AUD = 'AUD';
const C_AZN = 'AZN';
const C_AZN = 'AZN';
const C_BSD = 'BSD';
const C_BSD = 'BSD';
const C_BBD = 'BBD';
const C_BBD = 'BBD';
const C_BYR = 'BYR';
const C_BYR = 'BYR';
const C_BZD = 'BZD';
const C_BZD = 'BZD';
const C_BMD = 'BMD';
const C_BMD = 'BMD';
const C_BOB = 'BOB';
const C_BOB = 'BOB';
const C_BAM = 'BAM';
const C_BAM = 'BAM';
const C_BWP = 'BWP';
const C_BWP = 'BWP';
const C_BGN = 'BGN';
const C_BGN = 'BGN';
const C_BRL = 'BRL';
const C_BRL = 'BRL';
const C_BND = 'BND';
const C_BND = 'BND';
const C_KHR = 'KHR';
const C_KHR = 'KHR';
const C_CAD = 'CAD';
const C_CAD = 'CAD';
const C_KYD = 'KYD';
const C_KYD = 'KYD';
const C_CLP = 'CLP';
const C_CLP = 'CLP';
const C_CNY = 'CNY';
const C_CNY = 'CNY';
const C_COP = 'COP';
const C_COP = 'COP';
const C_CRC = 'CRC';
const C_CRC = 'CRC';
const C_HRK = 'HRK';
const C_HRK = 'HRK';
const C_CUP = 'CUP';
const C_CUP = 'CUP';
const C_CZK = 'CZK';
const C_CZK = 'CZK';
const C_DKK = 'DKK';
const C_DKK = 'DKK';
const C_DOP = 'DOP';
const C_DOP = 'DOP';
const C_XCD = 'XCD';
const C_XCD = 'XCD';
const C_EGP = 'EGP';
const C_EGP = 'EGP';
const C_SVC = 'SVC';
const C_SVC = 'SVC';
const C_EEK = 'EEK';
const C_EEK = 'EEK';
const C_EUR = 'EUR';
const C_EUR = 'EUR';
const C_FKP = 'FKP';
const C_FKP = 'FKP';
const C_FJD = 'FJD';
const C_FJD = 'FJD';
const C_GHC = 'GHC';
const C_GHC = 'GHC';
const C_GIP = 'GIP';
const C_GIP = 'GIP';
const C_GTQ = 'GTQ';
const C_GTQ = 'GTQ';
const C_GGP = 'GGP';
const C_GGP = 'GGP';
const C_GYD = 'GYD';
const C_GYD = 'GYD';
const C_HNL = 'HNL';
const C_HNL = 'HNL';
const C_HKD = 'HKD';
const C_HKD = 'HKD';
const C_HUF = 'HUF';
const C_HUF = 'HUF';
const C_ISK = 'ISK';
const C_ISK = 'ISK';
const C_INR = 'INR';
const C_INR = 'INR';
const C_IDR = 'IDR';
const C_IDR = 'IDR';
const C_IRR = 'IRR';
const C_IRR = 'IRR';
const C_IMP = 'IMP';
const C_IMP = 'IMP';
const C_ILS = 'ILS';
const C_ILS = 'ILS';
const C_JMD = 'JMD';
const C_JMD = 'JMD';
const C_JPY = 'JPY';
const C_JPY = 'JPY';
const C_JEP = 'JEP';
const C_JEP = 'JEP';
const C_KZT = 'KZT';
const C_KZT = 'KZT';
const C_KES = 'KES';
const C_KES = 'KES';
const C_KGS = 'KGS';
const C_KGS = 'KGS';
const C_LAK = 'LAK';
const C_LAK = 'LAK';
const C_LVL = 'LVL';
const C_LVL = 'LVL';
const C_LBP = 'LBP';
const C_LBP = 'LBP';
const C_LRD = 'LRD';
const C_LRD = 'LRD';
const C_LTL = 'LTL';
const C_LTL = 'LTL';
const C_MKD = 'MKD';
const C_MKD = 'MKD';
const C_MYR = 'MYR';
const C_MYR = 'MYR';
const C_MUR = 'MUR';
const C_MUR = 'MUR';
const C_MXN = 'MXN';
const C_MXN = 'MXN';
const C_MNT = 'MNT';
const C_MNT = 'MNT';
const C_MZN = 'MZN';
const C_MZN = 'MZN';
const C_NAD = 'NAD';
const C_NAD = 'NAD';
const C_NPR = 'NPR';
const C_NPR = 'NPR';
const C_ANG = 'ANG';
const C_ANG = 'ANG';
const C_NZD = 'NZD';
const C_NZD = 'NZD';
const C_NIO = 'NIO';
const C_NIO = 'NIO';
const C_NGN = 'NGN';
const C_NGN = 'NGN';
const C_KPW = 'KPW';
const C_KPW = 'KPW';
const C_NOK = 'NOK';
const C_NOK = 'NOK';
const C_OMR = 'OMR';
const C_OMR = 'OMR';
const C_PKR = 'PKR';
const C_PKR = 'PKR';
const C_PAB = 'PAB';
const C_PAB = 'PAB';
const C_PYG = 'PYG';
const C_PYG = 'PYG';
const C_PEN = 'PEN';
const C_PEN = 'PEN';
const C_PHP = 'PHP';
const C_PHP = 'PHP';
const C_PLN = 'PLN';
const C_PLN = 'PLN';
const C_QAR = 'QAR';
const C_QAR = 'QAR';
const C_RON = 'RON';
const C_RON = 'RON';
const C_RUB = 'RUB';
const C_RUB = 'RUB';
const C_SHP = 'SHP';
const C_SHP = 'SHP';
const C_SAR = 'SAR';
const C_SAR = 'SAR';
const C_RSD = 'RSD';
const C_RSD = 'RSD';
const C_SCR = 'SCR';
const C_SCR = 'SCR';
const C_SGD = 'SGD';
const C_SGD = 'SGD';
const C_SBD = 'SBD';
const C_SBD = 'SBD';
const C_SOS = 'SOS';
const C_SOS = 'SOS';
const C_ZAR = 'ZAR';
const C_ZAR = 'ZAR';
const C_KRW = 'KRW';
const C_KRW = 'KRW';
const C_LKR = 'LKR';
const C_LKR = 'LKR';
const C_SEK = 'SEK';
const C_SEK = 'SEK';
const C_CHF = 'CHF';
const C_CHF = 'CHF';
const C_SRD = 'SRD';
const C_SRD = 'SRD';
const C_SYP = 'SYP';
const C_SYP = 'SYP';
const C_TWD = 'TWD';
const C_TWD = 'TWD';
const C_THB = 'THB';
const C_THB = 'THB';
const C_TTD = 'TTD';
const C_TTD = 'TTD';
const C_TRY = 'TRY';
const C_TRY = 'TRY';
const C_TRL = 'TRL';
const C_TRL = 'TRL';
const C_TVD = 'TVD';
const C_TVD = 'TVD';
const C_UAH = 'UAH';
const C_UAH = 'UAH';
const C_GBP = 'GBP';
const C_GBP = 'GBP';
const C_USD = 'USD';
const C_USD = 'USD';
const C_UYU = 'UYU';
const C_UYU = 'UYU';
const C_UZS = 'UZS';
const C_UZS = 'UZS';
const C_VEF = 'VEF';
const C_VEF = 'VEF';
const C_VND = 'VND';
const C_VND = 'VND';
const C_YER = 'YER';
const C_YER = 'YER';
const C_ZWD = 'ZWD';
const C_ZWD = 'ZWD';
}

View File

@ -31,6 +31,13 @@ use phpOMS\Datatypes\Exception\InvalidEnumValue;
class Localization
{
/**
* Localization manager.
*
* @var L11nManager
* @since 1.0.0
*/
public $l11nManager = null;
/**
* Country ID.
*
@ -38,7 +45,6 @@ class Localization
* @since 1.0.0
*/
private $country = ISO3166Enum::_US;
/**
* Timezone.
*
@ -46,7 +52,6 @@ class Localization
* @since 1.0.0
*/
private $timezone = 'America/New_York';
/**
* Language ISO code.
*
@ -54,7 +59,6 @@ class Localization
* @since 1.0.0
*/
private $language = ISO639x1Enum::_EN;
/**
* Currency.
*
@ -62,7 +66,6 @@ class Localization
* @since 1.0.0
*/
private $currency = ISO4217Enum::C_USD;
/**
* Number format.
*
@ -70,7 +73,6 @@ class Localization
* @since 1.0.0
*/
private $decimal = '.';
/**
* Number format.
*
@ -78,7 +80,6 @@ class Localization
* @since 1.0.0
*/
private $thousands = ',';
/**
* Time format.
*
@ -87,14 +88,6 @@ class Localization
*/
private $datetime = 'Y-m-d H:i:s';
/**
* Localization manager.
*
* @var L11nManager
* @since 1.0.0
*/
public $l11nManager = null;
/**
* Constructor.
*

View File

@ -15,7 +15,7 @@
*/
namespace phpOMS\Localization;
use \phpOMS\Math\Number\OperationInterface;
use phpOMS\Math\Number\OperationInterface;
/**
* Money class.
@ -38,7 +38,7 @@ class Money implements \Serializable, OperationInterface
* @since 1.0.0
*/
const MAX_DECIMALS = 5;
/**
* Currency symbol.
*
@ -62,7 +62,7 @@ class Money implements \Serializable, OperationInterface
* @since 1.0.0
*/
private $decimal = '.';
/**
* Value.
*
@ -70,50 +70,22 @@ class Money implements \Serializable, OperationInterface
* @since 1.0.0
*/
private $value = 0;
/**
* Constructor.
*
* @param string $currency Currency symbol
* @param string $currency Currency symbol
* @param string $thousands Thousands separator
* @param string $decimal Decimal separator
* @param string $decimal Decimal separator
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(string $currency = ISO4217CharEnum::C_USD, string $thousands = ',', string $decimal = '.')
public function __construct(string $currency = ISO4217CharEnum::C_USD, string $thousands = ',', string $decimal = '.')
{
$this->currency = $currency;
$this->currency = $currency;
$this->thousands = $thousands;
$this->decimal = $decimal;
}
/**
* Set money value.
*
* @param int $value Value
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setInt(int $value)
{
$this->value = $value;
}
/**
* Get money value.
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getInt() : int
{
return $this->value;
$this->decimal = $decimal;
}
/**
@ -126,16 +98,16 @@ class Money implements \Serializable, OperationInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setString(string $value)
public function setString(string $value)
{
$this->value = self::toInt($value, $this->decimal, $this->thousands);
}
/**
* Money to int.
*
* @param string $value Money value
* @param string $decimal Decimal character
* @param string $value Money value
* @param string $decimal Decimal character
* @param string $thousands Thousands character
*
* @return int
@ -151,15 +123,15 @@ class Money implements \Serializable, OperationInterface
$left = str_replace($thousands, '', $left);
$right = '';
if(count($split) > 1) {
if (count($split) > 1) {
$right = $split[1];
}
$right = substr($right, 0, -self::MAX_DECIMALS);
return (int) $left * 10 * self::MAX_DECIMALS + (int) $right;
}
/**
* Get money.
*
@ -170,20 +142,20 @@ class Money implements \Serializable, OperationInterface
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getAmount(int $decimals = 2) : string
public function getAmount(int $decimals = 2) : string
{
if($decimals > ($dec = constant('\phpOMS\Localization\ISO4217DecimalEnum::C_' . strtoupper($this->currency)))) {
$decimals = $dec ;
if ($decimals > ($dec = constant('\phpOMS\Localization\ISO4217DecimalEnum::C_' . strtoupper($this->currency)))) {
$decimals = $dec;
}
$value = (string) round($this->value, - self::MAX_DECIMALS + $decimals);
$value = (string) round($this->value, -self::MAX_DECIMALS + $decimals);
$left = substr($value, 0, -self::MAX_DECIMALS);
$left = substr($value, 0, -self::MAX_DECIMALS);
$right = substr($value, -self::MAX_DECIMALS);
return ($decimals > 0) ? number_format($left, 0, $this->thousands, $this->decimal) . $this->decimal . $right : (string) $left;
}
/**
* Add money.
*
@ -196,17 +168,30 @@ class Money implements \Serializable, OperationInterface
*/
public function add($value) : Money
{
if(is_string($value) || is_float($value)) {
if (is_string($value) || is_float($value)) {
$this->value += self::toInt((string) $value, $this->decimal, $this->thousands);
} elseif(is_int($value)) {
} elseif (is_int($value)) {
$this->value += $value;
} elseif($value instanceof Money) {
} elseif ($value instanceof Money) {
$this->value += $value->getInt();
}
return $this;
}
/**
* Get money value.
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getInt() : int
{
return $this->value;
}
/**
* Sub money.
*
@ -219,17 +204,17 @@ class Money implements \Serializable, OperationInterface
*/
public function sub($value) : Money
{
if(is_string($value) || is_float($value)) {
if (is_string($value) || is_float($value)) {
$this->value -= self::toInt((string) $value, $this->decimal, $this->thousands);
} elseif(is_int($value)) {
} elseif (is_int($value)) {
$this->value -= $value;
} elseif($value instanceof Money) {
} elseif ($value instanceof Money) {
$this->value -= $value->getInt();
}
return $this;
}
/**
* Mult.
*
@ -242,13 +227,13 @@ class Money implements \Serializable, OperationInterface
*/
public function mult($value) : Money
{
if(is_float($value) || is_int($value)) {
if (is_float($value) || is_int($value)) {
$this->value *= $value;
}
return $this;
}
/**
* Div.
*
@ -261,7 +246,7 @@ class Money implements \Serializable, OperationInterface
*/
public function div($value) : Money
{
if(is_float($value) || is_int($value)) {
if (is_float($value) || is_int($value)) {
$this->value = self::toInt((string) ($this->value / $value), $this->decimal, $this->thousands);
}
@ -295,7 +280,7 @@ class Money implements \Serializable, OperationInterface
*/
public function pow($value) : Money
{
if(is_float($value) || is_int($value)) {
if (is_float($value) || is_int($value)) {
$this->value = $this->value ** $value;
}
@ -329,4 +314,19 @@ class Money implements \Serializable, OperationInterface
{
$this->setInt($value);
}
/**
* Set money value.
*
* @param int $value Value
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setInt(int $value)
{
$this->value = $value;
}
}

View File

@ -16,9 +16,9 @@
namespace phpOMS\Log;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
use phpOMS\System\File\PathException;
use phpOMS\System\File\File;
use phpOMS\System\File\Directory;
use phpOMS\System\File\File;
use phpOMS\System\File\PathException;
use phpOMS\Validation\Validator;
/**

View File

@ -37,22 +37,6 @@ use phpOMS\Router\RouteVerb;
class Request extends RequestAbstract
{
/**
* Browser type.
*
* @var BrowserType
* @since 1.0.0
*/
private $browser = null;
/**
* OS type.
*
* @var OSType
* @since 1.0.0
*/
private $os = null;
/**
* Path.
*
@ -60,7 +44,6 @@ class Request extends RequestAbstract
* @since 1.0.0
*/
protected $path = null;
/**
* Request status.
*
@ -68,7 +51,6 @@ class Request extends RequestAbstract
* @since 1.0.0
*/
protected $status = RequestStatus::R_200;
/**
* Uploaded files.
*
@ -76,7 +58,20 @@ class Request extends RequestAbstract
* @since 1.0.0
*/
protected $files = [];
/**
* Browser type.
*
* @var BrowserType
* @since 1.0.0
*/
private $browser = null;
/**
* OS type.
*
* @var OSType
* @since 1.0.0
*/
private $os = null;
/**
* Request information.
*
@ -181,6 +176,22 @@ class Request extends RequestAbstract
$this->uri->set($uri['uri']);
}
/**
* Clean up globals that musn't be used any longer
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function cleanupGlobals()
{
unset($_FILES);
unset($_GET);
unset($_POST);
unset($_REQUEST);
}
/**
* Setup uri builder based on current request
*
@ -218,19 +229,18 @@ class Request extends RequestAbstract
}
/**
* Clean up globals that musn't be used any longer
* Generate request hash.
*
* @return void
* @param array $request Request array
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function cleanupGlobals()
private function hashRequest(array $request) : string
{
unset($_FILES);
unset($_GET);
unset($_POST);
unset($_REQUEST);
return sha1(implode('', $request));
}
/**
@ -253,21 +263,6 @@ class Request extends RequestAbstract
return false;
}
/**
* Generate request hash.
*
* @param array $request Request array
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function hashRequest(array $request) : string
{
return sha1(implode('', $request));
}
/**
* {@inheritdoc}
*/
@ -389,23 +384,6 @@ class Request extends RequestAbstract
return $lastElement;
}
/**
* Get request type.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getMethod() : string
{
if (!isset($this->method)) {
$this->method = $_SERVER['REQUEST_METHOD'] ?? RequestMethod::GET;
}
return $this->method;
}
/**
* {@inheritdoc}
*/
@ -466,4 +444,21 @@ class Request extends RequestAbstract
throw new \Exception();
}
}
/**
* Get request type.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getMethod() : string
{
if (!isset($this->method)) {
$this->method = $_SERVER['REQUEST_METHOD'] ?? RequestMethod::GET;
}
return $this->method;
}
}

View File

@ -49,6 +49,22 @@ class ActivateAbstract
self::activateInDatabase($dbPool, $info);
}
/**
* Install routes.
*
* @param string $destRoutePath Destination route path
* @param string $srcRoutePath Source route path
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function activateRoutes(string $destRoutePath, string $srcRoutePath)
{
// todo: remove route
}
/**
* Deactivate module in database.
*
@ -79,21 +95,4 @@ class ActivateAbstract
break;
}
}
/**
* Install routes.
*
* @param string $destRoutePath Destination route path
* @param string $srcRoutePath Source route path
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function activateRoutes(string $destRoutePath, string $srcRoutePath)
{
// todo: remove route
}
}

View File

@ -49,6 +49,22 @@ class DeactivateAbstract
self::deactivateInDatabase($dbPool, $info);
}
/**
* Install routes.
*
* @param string $destRoutePath Destination route path
* @param string $srcRoutePath Source route path
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function deactivateRoutes(string $destRoutePath, string $srcRoutePath)
{
// todo: remove route
}
/**
* Deactivate module in database.
*
@ -79,21 +95,4 @@ class DeactivateAbstract
break;
}
}
/**
* Install routes.
*
* @param string $destRoutePath Destination route path
* @param string $srcRoutePath Source route path
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function deactivateRoutes(string $destRoutePath, string $srcRoutePath)
{
// todo: remove route
}
}

View File

@ -29,22 +29,6 @@ namespace phpOMS\Module;
abstract class ModuleAbstract
{
/**
* Receiving modules from?
*
* @var string[]
* @since 1.0.0
*/
protected $receiving = [];
/**
* Receiving modules from?
*
* @var string[]
* @since 1.0.0
*/
protected static $providing = [];
/**
* Module name.
*
@ -52,7 +36,6 @@ abstract class ModuleAbstract
* @since 1.0.0
*/
const MODULE_NAME = '';
/**
* Module path.
*
@ -60,7 +43,6 @@ abstract class ModuleAbstract
* @since 1.0.0
*/
const MODULE_PATH = __DIR__ . '/../../Modules';
/**
* Module version.
*
@ -68,7 +50,13 @@ abstract class ModuleAbstract
* @since 1.0.0
*/
const MODULE_VERSION = '1.0.0';
/**
* Receiving modules from?
*
* @var string[]
* @since 1.0.0
*/
protected static $providing = [];
/**
* Localization files.
*
@ -76,7 +64,6 @@ abstract class ModuleAbstract
* @since 1.0.0
*/
protected static $localization = [];
/**
* Dependencies.
*
@ -84,7 +71,13 @@ abstract class ModuleAbstract
* @since 1.0.0
*/
protected static $dependencies = [];
/**
* Receiving modules from?
*
* @var string[]
* @since 1.0.0
*/
protected $receiving = [];
/**
* Application instance.
*

View File

@ -16,11 +16,11 @@
namespace phpOMS\Module;
use phpOMS\ApplicationAbstract;
use phpOMS\Autoloader;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\Log\FileLogger;
use phpOMS\Message\Http\Request;
use phpOMS\System\File\PathException;
use phpOMS\Autoloader;
/**
* Modules class.
@ -360,7 +360,7 @@ class ModuleManager
*/
public function reInit(string $module) : bool
{
if(file_exists($path = __DIR__ . '/../Web/Routes.php')) {
if (file_exists($path = __DIR__ . '/../Web/Routes.php')) {
unlink($path);
}
@ -600,7 +600,7 @@ class ModuleManager
*/
public function initModule($module)
{
if(!is_array($module)) {
if (!is_array($module)) {
$module = [$module];
}

View File

@ -135,10 +135,29 @@ class Http implements UriInterface
/**
* {@inheritdoc}
*/
public function setRootPath(string $root)
public function set(string $uri)
{
$this->rootPath = $root;
$this->set($this->uri);
$this->uri = $uri;
$url = parse_url($this->uri);
$this->scheme = $url['scheme'] ?? '';
$this->host = $url['host'] ?? null;
$this->port = $url['port'] ?? null;
$this->user = $url['user'] ?? null;
$this->pass = $url['pass'] ?? null;
$this->path = $url['path'] ?? null;
$this->path = rtrim($this->path, '.php');
$this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; // TODO: this could cause a bug if the rootpath is the same as a regular path which is usually the language
$this->query = $url['query'] ?? null;
if (isset($this->query)) {
parse_str($this->query, $this->query);
}
$this->fragment = $url['fragment'] ?? null;
$this->base = $this->scheme . '://' . $this->host . $this->rootPath;
}
/**
@ -176,6 +195,15 @@ class Http implements UriInterface
return $this->rootPath;
}
/**
* {@inheritdoc}
*/
public function setRootPath(string $root)
{
$this->rootPath = $root;
$this->set($this->uri);
}
/**
* {@inheritdoc}
*/
@ -245,34 +273,6 @@ class Http implements UriInterface
return $this->base;
}
/**
* {@inheritdoc}
*/
public function set(string $uri)
{
$this->uri = $uri;
$url = parse_url($this->uri);
$this->scheme = $url['scheme'] ?? '';
$this->host = $url['host'] ?? null;
$this->port = $url['port'] ?? null;
$this->user = $url['user'] ?? null;
$this->pass = $url['pass'] ?? null;
$this->path = $url['path'] ?? null;
$this->path = rtrim($this->path, '.php');
$this->path = strpos($this->path, $this->rootPath) === 0 ? substr($this->path, strlen($this->rootPath), strlen($this->path)) : $this->path; // TODO: this could cause a bug if the rootpath is the same as a regular path which is usually the language
$this->query = $url['query'] ?? null;
if (isset($this->query)) {
parse_str($this->query, $this->query);
}
$this->fragment = $url['fragment'] ?? null;
$this->base = $this->scheme . '://' . $this->host . $this->rootPath;
}
/**
* {@inheritdoc}
*/

View File

@ -80,7 +80,7 @@ class JsonBuilder implements \Serializable
/**
* Remove data.
*
* @param string $path Path to the element to delete
* @param string $path Path to the element to delete
*
* @return void
*

View File

@ -51,7 +51,7 @@ class BitcoinValidator extends ValidatorAbstract
}
return true;
} catch(\Exception $e) {
} catch (\Exception $e) {
self::$msg = $e->getMessage();
} finally {
return false;