diff --git a/Account/Account.php b/Account/Account.php index 9714da3c3..44eb88318 100644 --- a/Account/Account.php +++ b/Account/Account.php @@ -17,7 +17,6 @@ namespace phpOMS\Account; use phpOMS\Contract\ArrayableInterface; use phpOMS\Localization\Localization; -use phpOMS\Localization\NullLocalization; use phpOMS\Validation\Base\Email; /** diff --git a/Account/Group.php b/Account/Group.php index dbaef5473..0e9230a15 100644 --- a/Account/Group.php +++ b/Account/Group.php @@ -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 - */ - 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 + */ + 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, + ]; + } } diff --git a/Config/SettingsAbstract.php b/Config/SettingsAbstract.php index e9cdff9c3..f14798ec2 100644 --- a/Config/SettingsAbstract.php +++ b/Config/SettingsAbstract.php @@ -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. diff --git a/Datatypes/Address.php b/Datatypes/Address.php index f00e57543..868651f12 100644 --- a/Datatypes/Address.php +++ b/Datatypes/Address.php @@ -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()]; } } diff --git a/Datatypes/Enum.php b/Datatypes/Enum.php index 7f44e1b9c..207d36bf9 100644 --- a/Datatypes/Enum.php +++ b/Datatypes/Enum.php @@ -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 - */ - 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 - */ - 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 + */ + 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 + */ + public static function isValidName(string $name) : bool + { + return defined($name); + } + } diff --git a/Datatypes/Iban.php b/Datatypes/Iban.php index 1c6bb5547..dbd5bf271 100644 --- a/Datatypes/Iban.php +++ b/Datatypes/Iban.php @@ -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 */ - 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 + */ + 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 */ - 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 - */ - 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 diff --git a/Datatypes/Location.php b/Datatypes/Location.php index 44128bcd5..aa40936aa 100644 --- a/Datatypes/Location.php +++ b/Datatypes/Location.php @@ -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 diff --git a/Localization/ISO4217CharEnum.php b/Localization/ISO4217CharEnum.php index d4fa5d2bf..77441da6c 100644 --- a/Localization/ISO4217CharEnum.php +++ b/Localization/ISO4217CharEnum.php @@ -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'; } diff --git a/Localization/Localization.php b/Localization/Localization.php index e9383f38f..4d1f9dc01 100644 --- a/Localization/Localization.php +++ b/Localization/Localization.php @@ -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. * diff --git a/Localization/Money.php b/Localization/Money.php index 794b2fab9..b433c95dc 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -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 */ - 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 - */ - public function setInt(int $value) - { - $this->value = $value; - } - - /** - * Get money value. - * - * @return int - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - 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 */ - 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 */ - 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 + */ + 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 + */ + public function setInt(int $value) + { + $this->value = $value; + } } diff --git a/Log/FileLogger.php b/Log/FileLogger.php index a8cda053a..ba38e2bf2 100644 --- a/Log/FileLogger.php +++ b/Log/FileLogger.php @@ -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; /** diff --git a/Message/Http/Request.php b/Message/Http/Request.php index cac7a7233..db15483c5 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -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 + */ + 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 */ - 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 - */ - 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 - */ - 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 + */ + public function getMethod() : string + { + if (!isset($this->method)) { + $this->method = $_SERVER['REQUEST_METHOD'] ?? RequestMethod::GET; + } + + return $this->method; + } } diff --git a/Module/ActivateAbstract.php b/Module/ActivateAbstract.php index 06a6f3810..88b72dc08 100644 --- a/Module/ActivateAbstract.php +++ b/Module/ActivateAbstract.php @@ -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 + */ + 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 - */ - private static function activateRoutes(string $destRoutePath, string $srcRoutePath) - { - // todo: remove route - } } diff --git a/Module/DeactivateAbstract.php b/Module/DeactivateAbstract.php index 8aba516e4..347e9b60b 100644 --- a/Module/DeactivateAbstract.php +++ b/Module/DeactivateAbstract.php @@ -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 + */ + 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 - */ - private static function deactivateRoutes(string $destRoutePath, string $srcRoutePath) - { - // todo: remove route - } } diff --git a/Module/ModuleAbstract.php b/Module/ModuleAbstract.php index 27b42437d..08edeb1a9 100644 --- a/Module/ModuleAbstract.php +++ b/Module/ModuleAbstract.php @@ -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. * diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index c897ee18e..2576eee7d 100644 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -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]; } diff --git a/Uri/Http.php b/Uri/Http.php index 0d4dda084..98e5d6d7d 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -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} */ diff --git a/Utils/JsonBuilder.php b/Utils/JsonBuilder.php index 234b5c641..96a4aa6b6 100644 --- a/Utils/JsonBuilder.php +++ b/Utils/JsonBuilder.php @@ -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 * diff --git a/Validation/BitcoinValidator.php b/Validation/BitcoinValidator.php index 86a227349..92101a5bd 100644 --- a/Validation/BitcoinValidator.php +++ b/Validation/BitcoinValidator.php @@ -51,7 +51,7 @@ class BitcoinValidator extends ValidatorAbstract } return true; - } catch(\Exception $e) { + } catch (\Exception $e) { self::$msg = $e->getMessage(); } finally { return false;