mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 14:58:42 +00:00
PhpStorm autofix/format
This commit is contained in:
parent
0d7c17aa88
commit
a02f1cca5d
|
|
@ -994,7 +994,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
/**
|
/**
|
||||||
* Get random object
|
* Get random object
|
||||||
*
|
*
|
||||||
* @param int $amount Amount of random models
|
* @param int $amount Amount of random models
|
||||||
* @param int $relations Relations type
|
* @param int $relations Relations type
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
|
@ -1031,7 +1031,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
{
|
{
|
||||||
$hasMany = count(static::$hasMany) > 0;
|
$hasMany = count(static::$hasMany) > 0;
|
||||||
$hasOne = count(static::$hasOne) > 0;
|
$hasOne = count(static::$hasOne) > 0;
|
||||||
$ownsOne = count(static::$ownsOne) > 0;
|
$ownsOne = count(static::$ownsOne) > 0;
|
||||||
|
|
||||||
if ($relations !== RelationType::NONE && ($hasMany || $hasOne)) {
|
if ($relations !== RelationType::NONE && ($hasMany || $hasOne)) {
|
||||||
foreach ($obj as $key => $value) {
|
foreach ($obj as $key => $value) {
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class Grammar extends GrammarAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $randomComponents = [
|
protected $randomComponents = [
|
||||||
'random'
|
'random',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
namespace phpOMS\Dispatcher;
|
namespace phpOMS\Dispatcher;
|
||||||
|
|
||||||
use phpOMS\ApplicationAbstract;
|
use phpOMS\ApplicationAbstract;
|
||||||
use phpOMS\Message\RequestAbstract;
|
|
||||||
use phpOMS\Message\ResponseAbstract;
|
|
||||||
use phpOMS\Module\ModuleAbstract;
|
use phpOMS\Module\ModuleAbstract;
|
||||||
use phpOMS\System\File\PathException;
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class EventManager implements Mediator
|
||||||
*/
|
*/
|
||||||
public function attach(string $group, \Closure $callback, bool $remove = false) : bool
|
public function attach(string $group, \Closure $callback, bool $remove = false) : bool
|
||||||
{
|
{
|
||||||
if(isset($this->callbacks[$group])) {
|
if (isset($this->callbacks[$group])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,54 +74,54 @@ class EventManager implements Mediator
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function trigger(string $group, string $id = '')
|
||||||
|
{
|
||||||
|
if (isset($this->groups[$group])) {
|
||||||
|
unset($this->groups[$group][$id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->hasOutstanding($group)) {
|
||||||
|
$this->callbacks[$group]['func'];
|
||||||
|
|
||||||
|
if ($this->callbacks[$group]['remove']) {
|
||||||
|
$this->detach($group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
private function hasOutstanding(string $group) : bool
|
||||||
|
{
|
||||||
|
return empty($this->groups[$group]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function detach(string $group) : bool
|
public function detach(string $group) : bool
|
||||||
{
|
{
|
||||||
if(isset($this->callbacks[$group])) {
|
if (isset($this->callbacks[$group])) {
|
||||||
unset($this->callbacks[$group]);
|
unset($this->callbacks[$group]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($this->groups[$group])) {
|
if (isset($this->groups[$group])) {
|
||||||
unset($this->groups[$group]);
|
unset($this->groups[$group]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function trigger(string $group, string $id = '')
|
|
||||||
{
|
|
||||||
if(isset($this->groups[$group])) {
|
|
||||||
unset($this->groups[$group][$id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->hasOutstanding($group)) {
|
|
||||||
$this->callbacks[$group]['func'];
|
|
||||||
|
|
||||||
if($this->callbacks[$group]['remove']) {
|
|
||||||
$this->detach($group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
private function hasOutstanding(string $group) : bool
|
|
||||||
{
|
|
||||||
return empty($this->groups[$group]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function addGroup(string $group, string $id)
|
public function addGroup(string $group, string $id)
|
||||||
{
|
{
|
||||||
if(!isset($this->groups[$group])) {
|
if (!isset($this->groups[$group])) {
|
||||||
$this->groups[$group] = [];
|
$this->groups[$group] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,61 +1,61 @@
|
||||||
{
|
{
|
||||||
"language": "EN",
|
"language": "EN",
|
||||||
"country": "USA",
|
"country": "USA",
|
||||||
"currency": {
|
"currency": {
|
||||||
"code" : "USD",
|
"code": "USD",
|
||||||
"position": 0
|
"position": 0
|
||||||
},
|
},
|
||||||
"thousand": ",",
|
"thousand": ",",
|
||||||
"decimal": ".",
|
"decimal": ".",
|
||||||
"angle": "Degree",
|
"angle": "Degree",
|
||||||
"temperature": "celsius",
|
"temperature": "celsius",
|
||||||
"weight": {
|
"weight": {
|
||||||
"very_light" : "mg",
|
"very_light": "mg",
|
||||||
"light" : "g",
|
"light": "g",
|
||||||
"medium" : "kg",
|
"medium": "kg",
|
||||||
"heavy" : "t",
|
"heavy": "t",
|
||||||
"very_heavy" : "t",
|
"very_heavy": "t",
|
||||||
},
|
},
|
||||||
"speed": {
|
"speed": {
|
||||||
"very_slow" : "ms",
|
"very_slow": "ms",
|
||||||
"slow" : "ms",
|
"slow": "ms",
|
||||||
"medium" : "kph",
|
"medium": "kph",
|
||||||
"fast" : "kph",
|
"fast": "kph",
|
||||||
"very_fast" : "mach",
|
"very_fast": "mach",
|
||||||
"sea" : "knot"
|
"sea": "knot"
|
||||||
},
|
},
|
||||||
"length": {
|
"length": {
|
||||||
"very_short" : "mm",
|
"very_short": "mm",
|
||||||
"short" : "cm",
|
"short": "cm",
|
||||||
"medium" : "m",
|
"medium": "m",
|
||||||
"long" : "km",
|
"long": "km",
|
||||||
"very_long" : "km",
|
"very_long": "km",
|
||||||
"sea": "mile"
|
"sea": "mile"
|
||||||
},
|
},
|
||||||
"area": {
|
"area": {
|
||||||
"very_small" : "mm",
|
"very_small": "mm",
|
||||||
"small" : "cm",
|
"small": "cm",
|
||||||
"medium" : "m",
|
"medium": "m",
|
||||||
"large" : "km",
|
"large": "km",
|
||||||
"very_large" : "ha"
|
"very_large": "ha"
|
||||||
},
|
},
|
||||||
"volume": {
|
"volume": {
|
||||||
"very_small" : "ml",
|
"very_small": "ml",
|
||||||
"small" : "ml",
|
"small": "ml",
|
||||||
"medium" : "l",
|
"medium": "l",
|
||||||
"large" : "m",
|
"large": "m",
|
||||||
"very_large" : "km",
|
"very_large": "km",
|
||||||
"teaspoon": "metric teaspoon",
|
"teaspoon": "metric teaspoon",
|
||||||
"tablespoon": "metric tablespoon",
|
"tablespoon": "metric tablespoon",
|
||||||
"glass": "metric glass"
|
"glass": "metric glass"
|
||||||
},
|
},
|
||||||
"datetime": {
|
"datetime": {
|
||||||
"delim_date": ".",
|
"delim_date": ".",
|
||||||
"delim_time": ":",
|
"delim_time": ":",
|
||||||
"very_short": "d.m",
|
"very_short": "d.m",
|
||||||
"short": "m.y",
|
"short": "m.y",
|
||||||
"medium": "d.m.Y",
|
"medium": "d.m.Y",
|
||||||
"long": "d.m.Y h:i",
|
"long": "d.m.Y h:i",
|
||||||
"very_long": "d.m.Y h:i:s",
|
"very_long": "d.m.Y h:i:s",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -382,5 +382,5 @@ class Localization
|
||||||
public function setTemperatur(string $temperature)
|
public function setTemperatur(string $temperature)
|
||||||
{
|
{
|
||||||
$this->temperature = $temperature;
|
$this->temperature = $temperature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ class Money implements \Serializable
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string|int|float $value Value
|
* @param string|int|float $value Value
|
||||||
* @param string $thousands Thousands separator
|
* @param string $thousands Thousands separator
|
||||||
* @param string $decimal Decimal separator
|
* @param string $decimal Decimal separator
|
||||||
* @param string $symbol Currency symbol
|
* @param string $symbol Currency symbol
|
||||||
* @param int $position Symbol position
|
* @param int $position Symbol position
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
|
@ -82,42 +82,6 @@ class Money implements \Serializable
|
||||||
$this->position = $position;
|
$this->position = $position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set localization.
|
|
||||||
*
|
|
||||||
* @param string $thousands Thousands separator
|
|
||||||
* @param string $decimal Decimal separator
|
|
||||||
* @param string $symbol Currency symbol
|
|
||||||
* @param int $position Symbol position
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function setLocalization(string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0)
|
|
||||||
{
|
|
||||||
$this->thousands = $thousands;
|
|
||||||
$this->decimal = $decimal;
|
|
||||||
$this->symbol = $symbol;
|
|
||||||
$this->position = $position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set value by string.
|
|
||||||
*
|
|
||||||
* @param string $value Money value
|
|
||||||
*
|
|
||||||
* @return Money
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function setString(string $value) : Money
|
|
||||||
{
|
|
||||||
$this->value = self::toInt($value, $this->thousands, $this->decimal);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Money to int.
|
* Money to int.
|
||||||
*
|
*
|
||||||
|
|
@ -146,6 +110,57 @@ class Money implements \Serializable
|
||||||
return (int) (((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0'));
|
return (int) (((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set localization.
|
||||||
|
*
|
||||||
|
* @param string $thousands Thousands separator
|
||||||
|
* @param string $decimal Decimal separator
|
||||||
|
* @param string $symbol Currency symbol
|
||||||
|
* @param int $position Symbol position
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function setLocalization(string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0)
|
||||||
|
{
|
||||||
|
$this->thousands = $thousands;
|
||||||
|
$this->decimal = $decimal;
|
||||||
|
$this->symbol = $symbol;
|
||||||
|
$this->position = $position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set value by string.
|
||||||
|
*
|
||||||
|
* @param string $value Money value
|
||||||
|
*
|
||||||
|
* @return Money
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function setString(string $value) : Money
|
||||||
|
{
|
||||||
|
$this->value = self::toInt($value, $this->thousands, $this->decimal);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get money.
|
||||||
|
*
|
||||||
|
* @param int $decimals Precision
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function getCurrency(int $decimals = 2) : string
|
||||||
|
{
|
||||||
|
return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get money.
|
* Get money.
|
||||||
*
|
*
|
||||||
|
|
@ -166,21 +181,6 @@ class Money implements \Serializable
|
||||||
return ($decimals > 0) ? number_format($left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left;
|
return ($decimals > 0) ? number_format($left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get money.
|
|
||||||
*
|
|
||||||
* @param int $decimals Precision
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function getCurrency(int $decimals = 2) : string
|
|
||||||
{
|
|
||||||
return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add money.
|
* Add money.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
namespace phpOMS\Log;
|
namespace phpOMS\Log;
|
||||||
|
|
||||||
use phpOMS\Datatypes\Exception\InvalidEnumValue;
|
use phpOMS\Datatypes\Exception\InvalidEnumValue;
|
||||||
use phpOMS\System\File\Directory;
|
|
||||||
use phpOMS\System\File\File;
|
use phpOMS\System\File\File;
|
||||||
use phpOMS\System\File\PathException;
|
use phpOMS\System\File\PathException;
|
||||||
use phpOMS\Utils\StringUtils;
|
use phpOMS\Utils\StringUtils;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class AR {
|
class AR
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class ARCH {
|
class ARCH
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class ARFIMA {
|
class ARFIMA
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,133 +2,144 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class ARIMA {
|
class ARIMA
|
||||||
public function __construct(array $data, int $order = 12) {
|
{
|
||||||
if($order !== 12 && $order !== 4) {
|
public function __construct(array $data, int $order = 12)
|
||||||
throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition');
|
{
|
||||||
}
|
if ($order !== 12 && $order !== 4) {
|
||||||
}
|
throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getDecomposition() : array {
|
public function getDecomposition() : array
|
||||||
$iteration1 = $this->getIteration($this->data);
|
{
|
||||||
$iteration2 = $this->getIteration($iteration1);
|
$iteration1 = $this->getIteration($this->data);
|
||||||
$iteration3 = $this->getIteration($iteration2);
|
$iteration2 = $this->getIteration($iteration1);
|
||||||
|
$iteration3 = $this->getIteration($iteration2);
|
||||||
|
|
||||||
return $iteration3;
|
return $iteration3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getIteration(array $data) : array {
|
private function getIteration(array $data) : array
|
||||||
$multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE);
|
{
|
||||||
$tempDecomposition = $multiplicativeDecomposition->getDecomposition();
|
$multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE);
|
||||||
|
$tempDecomposition = $multiplicativeDecomposition->getDecomposition();
|
||||||
|
|
||||||
// 1
|
// 1
|
||||||
$trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order);
|
$trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order);
|
||||||
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
|
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
|
||||||
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true);
|
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true);
|
||||||
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
|
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
|
||||||
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
|
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
|
||||||
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
|
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
|
||||||
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true);
|
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true);
|
||||||
$prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent);
|
$prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent);
|
||||||
$trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries);
|
$trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries);
|
||||||
|
|
||||||
// 2
|
// 2
|
||||||
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
|
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
|
||||||
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true);
|
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true);
|
||||||
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
|
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
|
||||||
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
|
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
|
||||||
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
|
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
|
||||||
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true);
|
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true);
|
||||||
$seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent);
|
$seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent);
|
||||||
|
|
||||||
$remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent);
|
$remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent);
|
||||||
$modifiedRemainder = $this->removeOutliers($remainder, 0.5);
|
$modifiedRemainder = $this->removeOutliers($remainder, 0.5);
|
||||||
$modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder);
|
$modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder);
|
||||||
|
|
||||||
return $modifiedData;
|
return $modifiedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array {
|
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array
|
||||||
$remainder = [];
|
{
|
||||||
$count = count($prelimSeasonalComponent);
|
$remainder = [];
|
||||||
|
$count = count($prelimSeasonalComponent);
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
// +1 since 3x3 MA
|
// +1 since 3x3 MA
|
||||||
$remainder[] = $centeredRatios[$i+1] / $prelimSeasonalComponent[$i];
|
$remainder[] = $centeredRatios[$i + 1] / $prelimSeasonalComponent[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $remainder;
|
return $remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function removeOutliers(array $data, float $deviation = 0.5) : array {
|
private function removeOutliers(array $data, float $deviation = 0.5) : array
|
||||||
$avg = AVerage::arithmeticMean($data);
|
{
|
||||||
|
$avg = AVerage::arithmeticMean($data);
|
||||||
|
|
||||||
foreach($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
if($value / $avg - 1 > $deviation) {
|
if ($value / $avg - 1 > $deviation) {
|
||||||
$data[$key] = $avg;
|
$data[$key] = $avg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array {
|
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array
|
||||||
$centeredRatio = [];
|
{
|
||||||
$count = count($seasonal);
|
$centeredRatio = [];
|
||||||
|
$count = count($seasonal);
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
// +1 since 3x3 MA
|
// +1 since 3x3 MA
|
||||||
$centeredRatio[] = $remainder[$i+1] * $seasonal[$i];
|
$centeredRatio[] = $remainder[$i + 1] * $seasonal[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $centeredRatio;
|
return $centeredRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSeasonalAdjustedSeries(array $seasonal) : array {
|
private function getTrendCycleEstimation(array $seasonal) : array
|
||||||
$adjusted = [];
|
{
|
||||||
$count = count($seasonal);
|
$count = count($seasonal);
|
||||||
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
|
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
if ($count >= 12) {
|
||||||
$adjusted[] = $this->data[$start + $i] / $seasonal[$i];
|
$weight = Average::MAH23;
|
||||||
}
|
} elseif ($count >= 6) {
|
||||||
|
$weight = Average::MAH13;
|
||||||
|
} else {
|
||||||
|
$weight = Average::MAH9;
|
||||||
|
}
|
||||||
|
|
||||||
return $adjusted;
|
// todo: implement
|
||||||
}
|
|
||||||
|
|
||||||
private function getTrendCycleEstimation(array $seasonal) : array {
|
return $seasonal;
|
||||||
$count = count($seasonal);
|
}
|
||||||
|
|
||||||
if($count >= 12) {
|
private function getSeasonalAdjustedSeries(array $seasonal) : array
|
||||||
$weight = Average::MAH23;
|
{
|
||||||
} elseif($count >= 6) {
|
$adjusted = [];
|
||||||
$weight = Average::MAH13;
|
$count = count($seasonal);
|
||||||
} else {
|
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
|
||||||
$weight = Average::MAH9;
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: implement
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
$adjusted[] = $this->data[$start + $i] / $seasonal[$i];
|
||||||
|
}
|
||||||
|
|
||||||
return $seasonal;
|
return $adjusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRemainder(array $seasonal, array $trendCycle) {
|
private function getRemainder(array $seasonal, array $trendCycle)
|
||||||
$remainder = [];
|
{
|
||||||
foreach($seasonal as $key => $e) {
|
$remainder = [];
|
||||||
$remainder = $e / $trendCycle[$key];
|
foreach ($seasonal as $key => $e) {
|
||||||
}
|
$remainder = $e / $trendCycle[$key];
|
||||||
|
}
|
||||||
|
|
||||||
return $remainder;
|
return $remainder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array {
|
private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array
|
||||||
$data = [];
|
{
|
||||||
$count = count($trendCycleComponent);
|
$data = [];
|
||||||
|
$count = count($trendCycleComponent);
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i];
|
$data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class ARMA {
|
class ARMA
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,88 +4,96 @@ namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
use phpOMS\Math\Statistic\Average;
|
||||||
|
|
||||||
class ClassicalDecomposition {
|
class ClassicalDecomposition
|
||||||
const ADDITIVE = 0;
|
{
|
||||||
const MULTIPLICATIVE = 1;
|
const ADDITIVE = 0;
|
||||||
|
const MULTIPLICATIVE = 1;
|
||||||
|
|
||||||
private $mode = self::ADDITIVE;
|
private $mode = self::ADDITIVE;
|
||||||
private $data = [];
|
private $data = [];
|
||||||
private $order = 0;
|
private $order = 0;
|
||||||
private $dataSize = 0;
|
private $dataSize = 0;
|
||||||
|
|
||||||
public function __construct(array $data, int $order, int $mode = self::ADDITIVE) {
|
public function __construct(array $data, int $order, int $mode = self::ADDITIVE)
|
||||||
$this->mode = $mode;
|
{
|
||||||
$this->data = $data;
|
$this->mode = $mode;
|
||||||
$this->order = $order;
|
$this->data = $data;
|
||||||
|
$this->order = $order;
|
||||||
|
|
||||||
$this->dataSize = count($data);
|
$this->dataSize = count($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDecomposition() : array {
|
public function getDecomposition() : array
|
||||||
$trendCycleComponent = self::computeTrendCycle($this->data, $this->order);
|
{
|
||||||
$detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode);
|
$trendCycleComponent = self::computeTrendCycle($this->data, $this->order);
|
||||||
$seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order);
|
$detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode);
|
||||||
$remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent);
|
$seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order);
|
||||||
|
$remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'trendCycleComponent' => $trendCycleComponent,
|
'trendCycleComponent' => $trendCycleComponent,
|
||||||
'detrendedSeries' => $detrendedSeries,
|
'detrendedSeries' => $detrendedSeries,
|
||||||
'seasonalComponent' => $seasonalComponent,
|
'seasonalComponent' => $seasonalComponent,
|
||||||
'remainderComponent' => $remainderComponent,
|
'remainderComponent' => $remainderComponent,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function computeTrendCycle(array $data, int $order) : array {
|
public static function computeTrendCycle(array $data, int $order) : array
|
||||||
$mMA = Average::totalMovingAverage($data, $order, null, true);
|
{
|
||||||
|
$mMA = Average::totalMovingAverage($data, $order, null, true);
|
||||||
|
|
||||||
return $order % 2 === 0 ? Average::totalMovingAverage($mMA, 2, null, true) : $mMA;
|
return $order % 2 === 0 ? Average::totalMovingAverage($mMA, 2, null, true) : $mMA;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array {
|
public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array
|
||||||
$detrended = [];
|
{
|
||||||
$count = count($trendCycleComponent);
|
$detrended = [];
|
||||||
$start = self::getStartOfDecomposition(count($data), $count);
|
$count = count($trendCycleComponent);
|
||||||
|
$start = self::getStartOfDecomposition(count($data), $count);
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$detrended[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] : $data[$start + $i] / $trendCycleComponent[$i];
|
$detrended[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] : $data[$start + $i] / $trendCycleComponent[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $detrended;
|
return $detrended;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moving average can't start at index 0 since it needs to go m indices back for average -> can only start at m
|
* Moving average can't start at index 0 since it needs to go m indices back for average -> can only start at m
|
||||||
*/
|
*/
|
||||||
public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int {
|
public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int
|
||||||
return ($dataSize - $trendCycleComponents) / 2;
|
{
|
||||||
}
|
return ($dataSize - $trendCycleComponents) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
private function computeSeasonalComponent() : array {
|
private function computeSeasonalComponent() : array
|
||||||
$seasonalComponent = [];
|
{
|
||||||
|
$seasonalComponent = [];
|
||||||
|
|
||||||
for($i = 0; $i < $this->orderSize; $i++) {
|
for ($i = 0; $i < $this->orderSize; $i++) {
|
||||||
$temp = [];
|
$temp = [];
|
||||||
|
|
||||||
for($j = $i * $this->order; $j < $count; $j += $this->order) {
|
for ($j = $i * $this->order; $j < $count; $j += $this->order) {
|
||||||
$temp[] = $this->data[$j];
|
$temp[] = $this->data[$j];
|
||||||
}
|
}
|
||||||
|
|
||||||
$seasonalComponent[] = Average::arithmeticMean($temp);
|
$seasonalComponent[] = Average::arithmeticMean($temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $seasonalComponent;
|
return $seasonalComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array {
|
public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array
|
||||||
$remainderComponent = [];
|
{
|
||||||
$count = count($trendCycleComponent);
|
$remainderComponent = [];
|
||||||
$start = self::getStartOfDecomposition($this->dataSize, $count);
|
$count = count($trendCycleComponent);
|
||||||
$seasons = count($seasonalComponent);
|
$start = self::getStartOfDecomposition($this->dataSize, $count);
|
||||||
|
$seasons = count($seasonalComponent);
|
||||||
|
|
||||||
for($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
$remainderComponent[] = $this->mode === self::ADDITIVE ? $this->data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $this->data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]);
|
$remainderComponent[] = $this->mode === self::ADDITIVE ? $this->data[$start + $i] - $trendCycleComponent[$i] - $seasonalComponent[$i % $seasons] : $this->data[$start + $i] / ($trendCycleComponent[$i] * $seasonalComponent[$i % $seasons]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $remainderComponent;
|
return $remainderComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class ExponentialSmoothing {
|
class ExponentialSmoothing
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class GARCH {
|
class GARCH
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class MA {
|
class MA
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class NAR {
|
class NAR
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class NMA {
|
class NMA
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Finance\Forecasting;
|
namespace phpOMS\Math\Finance\Forecasting;
|
||||||
|
|
||||||
class SARIMA {
|
class SARIMA
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,5 @@ namespace phpOMS\Math\Number;
|
||||||
|
|
||||||
class Irrational
|
class Irrational
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -30,18 +30,92 @@ namespace phpOMS\Math\Statistic;
|
||||||
class Average
|
class Average
|
||||||
{
|
{
|
||||||
|
|
||||||
const MA3 = [1/3, 1/3];
|
const MA3 = [1 / 3, 1 / 3];
|
||||||
const MA5 = [0.2, 0.2, 0.2];
|
const MA5 = [0.2, 0.2, 0.2];
|
||||||
const MA2x12 = [5/6, 5/6, 5/6, 5/6, 5/6, 5/6, 0.42];
|
const MA2x12 = [5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 0.42];
|
||||||
const MA3x3 = [1/3, 2/9, 1/9];
|
const MA3x3 = [1 / 3, 2 / 9, 1 / 9];
|
||||||
const MA3x5 = [0.2, 0.2, 2/15, 4/6];
|
const MA3x5 = [0.2, 0.2, 2 / 15, 4 / 6];
|
||||||
const MAS15 = [0.231, 0.209, 0.144, 2/3, 0.009, -0.016, -0.019, -0.009];
|
const MAS15 = [0.231, 0.209, 0.144, 2 / 3, 0.009, -0.016, -0.019, -0.009];
|
||||||
const MAS21 = [0.171, 0.163, 0.134, 0.37, 0.51, 0.017, -0.006, -0.014, -0.014, -0.009, -0.003];
|
const MAS21 = [0.171, 0.163, 0.134, 0.37, 0.51, 0.017, -0.006, -0.014, -0.014, -0.009, -0.003];
|
||||||
const MAH5 = [0.558, 0.294, -0.73];
|
const MAH5 = [0.558, 0.294, -0.73];
|
||||||
const MAH9 = [0.330, 0.267, 0.119, -0.010, -0.041];
|
const MAH9 = [0.330, 0.267, 0.119, -0.010, -0.041];
|
||||||
const MAH13 = [0.240, 0.214, 0.147, 0.66, 0, -0.028, -0.019];
|
const MAH13 = [0.240, 0.214, 0.147, 0.66, 0, -0.028, -0.019];
|
||||||
const MAH23 = [0.148, 0.138, 0.122, 0.097, 0.068, 0.039, 0.013, -0.005, -0.015, -0.016, -0.011, -0.004];
|
const MAH23 = [0.148, 0.138, 0.122, 0.097, 0.068, 0.039, 0.013, -0.005, -0.015, -0.016, -0.011, -0.004];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Average change.
|
||||||
|
*
|
||||||
|
* @param array $x Dataset
|
||||||
|
* @param int $h Future steps
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function averageChange(array $x, int $h = 1) : float
|
||||||
|
{
|
||||||
|
$count = count($x);
|
||||||
|
|
||||||
|
return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* t = 3 and p = 3 means -1 0 +1, t = 4 and p = 2 means -1 0
|
||||||
|
* periods should be replaced with order than it's possible to test for even or odd m
|
||||||
|
* todo: maybe floor()?
|
||||||
|
*/
|
||||||
|
public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array
|
||||||
|
{
|
||||||
|
$periods = (int) ($order / 2);
|
||||||
|
$count = count($x) - ($symmetric ? $periods : 0);
|
||||||
|
$avg = [];
|
||||||
|
|
||||||
|
for ($i = $periods; $i < $count; $i++) {
|
||||||
|
$avg[] = self::movingAverage($x, $i, $order, $weight, $symmetric);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moving average or order m.
|
||||||
|
*
|
||||||
|
* @param array $x Dataset
|
||||||
|
* @param int $t Current period
|
||||||
|
* @param int $periods Periods to use for average
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*
|
||||||
|
* @todo : allow counter i also to go into the future... required for forecast how? should be doable!
|
||||||
|
*
|
||||||
|
* @throws
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function movingAverage(array $x, int $t, int $order, array $weight = null, bool $symmetric = false) : float
|
||||||
|
{
|
||||||
|
$periods = (int) ($order / 2);
|
||||||
|
$count = count($x);
|
||||||
|
|
||||||
|
if ($t < $periods || ($count < $periods) || ($symmetric && $t + $periods < $count)) {
|
||||||
|
throw new \Exception('Periods');
|
||||||
|
}
|
||||||
|
|
||||||
|
$end = $symmetric ? $periods - 1 : 0;
|
||||||
|
$end = $order % 2 === 0 ? $end - 1 : $end;
|
||||||
|
$start = $t - 1 - ($periods - 2);
|
||||||
|
|
||||||
|
if (isset($weight)) {
|
||||||
|
return self::weightedAverage(array_slice($x, $start, $end - $start), array_slice($weight, $start, $end - $start));
|
||||||
|
} else {
|
||||||
|
return self::arithmeticMean(array_slice($x, $start, $end - $start));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate weighted average.
|
* Calculate weighted average.
|
||||||
*
|
*
|
||||||
|
|
@ -73,10 +147,11 @@ class Average
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Average change.
|
* Calculate the arithmetic mean.
|
||||||
*
|
*
|
||||||
* @param array $x Dataset
|
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||||
* @param int $h Future steps
|
*
|
||||||
|
* @param array $values Values
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*
|
*
|
||||||
|
|
@ -85,63 +160,15 @@ class Average
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function averageChange(array $x, int $h = 1) : float
|
public static function arithmeticMean(array $values)
|
||||||
{
|
{
|
||||||
$count = count($x);
|
$count = count($values);
|
||||||
|
|
||||||
return $x[$count - 1] + $h * ($x[$count - 1] - $x[0]) / ($count - 1);
|
if ($count === 0) {
|
||||||
}
|
throw new \Exception('Division zero');
|
||||||
|
|
||||||
/**
|
|
||||||
* Moving average or order m.
|
|
||||||
*
|
|
||||||
* @param array $x Dataset
|
|
||||||
* @param int $t Current period
|
|
||||||
* @param int $periods Periods to use for average
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*
|
|
||||||
* @todo: allow counter i also to go into the future... required for forecast how? should be doable!
|
|
||||||
*
|
|
||||||
* @throws
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public static function movingAverage(array $x, int $t, int $order, array $weight = null, bool $symmetric = false) : float {
|
|
||||||
$periods = (int) ($order / 2);
|
|
||||||
$count = count($x);
|
|
||||||
|
|
||||||
if($t < $periods || ($count < $periods) || ($symmetric && $t + $periods < $count)) {
|
|
||||||
throw new \Exception('Periods');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$end = $symmetric ? $periods - 1 : 0;
|
return array_sum($values) / $count;
|
||||||
$end = $order % 2 === 0 ? $end - 1 : $end;
|
|
||||||
$start = $t - 1 -($periods - 2);
|
|
||||||
|
|
||||||
if(isset($weight)) {
|
|
||||||
return self::weightedAverage(array_slice($x, $start, $end-$start), array_slice($weight, $start, $end-$start));
|
|
||||||
} else {
|
|
||||||
return self::arithmeticMean(array_slice($x, $start, $end-$start));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* t = 3 and p = 3 means -1 0 +1, t = 4 and p = 2 means -1 0
|
|
||||||
* periods should be replaced with order than it's possible to test for even or odd m
|
|
||||||
* todo: maybe floor()?
|
|
||||||
*/
|
|
||||||
public static function totalMovingAverage(array $x, int $order, array $weight = null, bool $symmetric = false) : array {
|
|
||||||
$periods = (int) ($order / 2);
|
|
||||||
$count = count($x) - ($symmetric ? $periods : 0);
|
|
||||||
$avg = [];
|
|
||||||
|
|
||||||
for($i = $periods; $i < $count; $i++) {
|
|
||||||
$avg[] = self::movingAverage($x, $i, $order, $weight, $symmetric);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $avg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -193,31 +220,6 @@ class Average
|
||||||
return $median;
|
return $median;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate the arithmetic mean.
|
|
||||||
*
|
|
||||||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
|
||||||
*
|
|
||||||
* @param array $values Values
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*
|
|
||||||
* @throws
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public static function arithmeticMean(array $values)
|
|
||||||
{
|
|
||||||
$count = count($values);
|
|
||||||
|
|
||||||
if ($count === 0) {
|
|
||||||
throw new \Exception('Division zero');
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_sum($values) / $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the geometric mean.
|
* Calculate the geometric mean.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -181,17 +181,19 @@ class Error
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
public static function getSumSquaredError(array $errors) : float {
|
public static function getSumSquaredError(array $errors) : float
|
||||||
|
{
|
||||||
$error = 0.0;
|
$error = 0.0;
|
||||||
|
|
||||||
foreach($errors as $e) {
|
foreach ($errors as $e) {
|
||||||
$error += $e*$e;
|
$error += $e * $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRBarSquared(float $R, int $observations, int $predictors) : float {
|
public static function getRBarSquared(float $R, int $observations, int $predictors) : float
|
||||||
|
{
|
||||||
return 1 - (1 - $R * ($observations - 1) / ($observations - $predictors - 1));
|
return 1 - (1 - $R * ($observations - 1) / ($observations - $predictors - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +201,8 @@ class Error
|
||||||
* Get Aike's information criterion (AIC)
|
* Get Aike's information criterion (AIC)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function getAkaikeInformationCriterion(float $sse, int $observations, int $predictors) : float {
|
public static function getAkaikeInformationCriterion(float $sse, int $observations, int $predictors) : float
|
||||||
|
{
|
||||||
return $observations * log($sse / $observations) + 2 * ($predictors + 2);
|
return $observations * log($sse / $observations) + 2 * ($predictors + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,16 +211,18 @@ class Error
|
||||||
*
|
*
|
||||||
* Correction for small amount of observations
|
* Correction for small amount of observations
|
||||||
*/
|
*/
|
||||||
public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float {
|
public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float
|
||||||
return $aic + (2*($predictors +2)*($predictors + 3)) / ($observations - $predictors - 3);
|
{
|
||||||
|
return $aic + (2 * ($predictors + 2) * ($predictors + 3)) / ($observations - $predictors - 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Bayesian information criterion (BIC)
|
* Get Bayesian information criterion (BIC)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float {
|
public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float
|
||||||
return $observations * log($sse / $observations) + ($predictors +2)*log($observations);
|
{
|
||||||
|
return $observations * log($sse / $observations) + ($predictors + 2) * log($observations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||||
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regression class.
|
* Regression class.
|
||||||
*
|
*
|
||||||
|
|
@ -33,11 +29,13 @@ use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||||
*/
|
*/
|
||||||
class LevelLevelRegression extends RegressionAbstract
|
class LevelLevelRegression extends RegressionAbstract
|
||||||
{
|
{
|
||||||
public static function getSlope(float $b1, float $y, float $x) : float {
|
public static function getSlope(float $b1, float $y, float $x) : float
|
||||||
|
{
|
||||||
return $b1;
|
return $b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getElasticity(float $b1, float $y, float $x): float {
|
public static function getElasticity(float $b1, float $y, float $x): float
|
||||||
|
{
|
||||||
return $b1 * $y / $x;
|
return $b1 * $y / $x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||||
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regression class.
|
* Regression class.
|
||||||
*
|
*
|
||||||
|
|
@ -48,23 +44,25 @@ class LevelLogRegression extends RegressionAbstract
|
||||||
*/
|
*/
|
||||||
public static function getRegression(array $x, array $y) : array
|
public static function getRegression(array $x, array $y) : array
|
||||||
{
|
{
|
||||||
if(($c = count($x)) != count($y)) {
|
if (($c = count($x)) != count($y)) {
|
||||||
throw new \Exception('Dimension');
|
throw new \Exception('Dimension');
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < $c; $i++) {
|
for ($i = 0; $i < $c; $i++) {
|
||||||
$x[$i] = log($x[i]);
|
$x[$i] = log($x[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getRegression($x, $y);
|
return parent::getRegression($x, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSlope(float $b1, float $y, float $x) : float {
|
public static function getSlope(float $b1, float $y, float $x) : float
|
||||||
|
{
|
||||||
return $b1 / $x;
|
return $b1 / $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getElasticity(float $b1, float $y, float $x): float {
|
public static function getElasticity(float $b1, float $y, float $x): float
|
||||||
|
{
|
||||||
return $b1 / $x;
|
return $b1 / $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||||
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regression class.
|
* Regression class.
|
||||||
*
|
*
|
||||||
|
|
@ -48,23 +44,25 @@ class LogLevelRegression extends RegressionAbstract
|
||||||
*/
|
*/
|
||||||
public static function getRegression(array $x, array $y) : array
|
public static function getRegression(array $x, array $y) : array
|
||||||
{
|
{
|
||||||
if(($c = count($x)) != count($y)) {
|
if (($c = count($x)) != count($y)) {
|
||||||
throw new \Exception('Dimension');
|
throw new \Exception('Dimension');
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < $c; $i++) {
|
for ($i = 0; $i < $c; $i++) {
|
||||||
$y[$i] = log($y[i]);
|
$y[$i] = log($y[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getRegression($x, $y);
|
return parent::getRegression($x, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSlope(float $b1, float $y, float $x) : float {
|
public static function getSlope(float $b1, float $y, float $x) : float
|
||||||
|
{
|
||||||
return $b1 * $y;
|
return $b1 * $y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getElasticity(float $b1, float $y, float $x): float {
|
public static function getElasticity(float $b1, float $y, float $x): float
|
||||||
|
{
|
||||||
return $b1 * $x;
|
return $b1 * $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||||
|
|
||||||
use phpOMS\Math\Statistic\Average;
|
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regression class.
|
* Regression class.
|
||||||
*
|
*
|
||||||
|
|
@ -48,11 +44,11 @@ class LogLogRegression extends RegressionAbstract
|
||||||
*/
|
*/
|
||||||
public static function getRegression(array $x, array $y) : array
|
public static function getRegression(array $x, array $y) : array
|
||||||
{
|
{
|
||||||
if(($c = count($x)) != count($y)) {
|
if (($c = count($x)) != count($y)) {
|
||||||
throw new \Exception('Dimension');
|
throw new \Exception('Dimension');
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < $c; $i++) {
|
for ($i = 0; $i < $c; $i++) {
|
||||||
$x[$i] = log($x[i]);
|
$x[$i] = log($x[i]);
|
||||||
$y[$i] = log($y[i]);
|
$y[$i] = log($y[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -60,12 +56,14 @@ class LogLogRegression extends RegressionAbstract
|
||||||
return parent::getRegression($x, $y);
|
return parent::getRegression($x, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSlope(float $b1, float $y, float $x) : float {
|
public static function getSlope(float $b1, float $y, float $x) : float
|
||||||
|
{
|
||||||
return $b1 * $y / $x;
|
return $b1 * $y / $x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getElasticity(float $b1, float $y, float $x): float {
|
public static function getElasticity(float $b1, float $y, float $x): float
|
||||||
|
{
|
||||||
return $b1;
|
return $b1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,20 +2,26 @@
|
||||||
|
|
||||||
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
namespace phpOMS\Math\Statistic\Forecast\Regression;
|
||||||
|
|
||||||
class MultipleLinearRegression {
|
class MultipleLinearRegression
|
||||||
public static function getRegression(array $x, array $y) : array {
|
{
|
||||||
$X = new Matrix(count($x), count($x[0]));
|
public static function getRegression(array $x, array $y) : array
|
||||||
$X->setArray($x);
|
{
|
||||||
$XT = $X->transpose();
|
$X = new Matrix(count($x), count($x[0]));
|
||||||
|
$X->setArray($x);
|
||||||
|
$XT = $X->transpose();
|
||||||
|
|
||||||
$Y = new Matrix(count($y));
|
$Y = new Matrix(count($y));
|
||||||
$Y->setArray($y);
|
$Y->setArray($y);
|
||||||
|
|
||||||
|
|
||||||
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getVariance() : float {}
|
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getPredictionInterval() : array {}
|
public static function getVariance() : float
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPredictionInterval() : array
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,8 @@ use phpOMS\Math\Statistic\Average;
|
||||||
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
|
||||||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||||
|
|
||||||
abstract class RegressionAbstract {
|
abstract class RegressionAbstract
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Get linear regression based on scatter plot.
|
* Get linear regression based on scatter plot.
|
||||||
*
|
*
|
||||||
|
|
@ -22,7 +23,7 @@ abstract class RegressionAbstract {
|
||||||
*/
|
*/
|
||||||
public static function getRegression(array $x, array $y) : array
|
public static function getRegression(array $x, array $y) : array
|
||||||
{
|
{
|
||||||
if(count($x) != count($y)) {
|
if (count($x) != count($y)) {
|
||||||
throw new \Exception('Dimension');
|
throw new \Exception('Dimension');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ abstract class RegressionAbstract {
|
||||||
|
|
||||||
return ['b0' => self::getBeta0($x, $y, $b1), 'b1' => $b1];
|
return ['b0' => self::getBeta0($x, $y, $b1), 'b1' => $b1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard error of the regression.
|
* Standard error of the regression.
|
||||||
*
|
*
|
||||||
|
|
@ -129,7 +130,7 @@ abstract class RegressionAbstract {
|
||||||
return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x);
|
return Average::arithmeticMean($y) - $b1 * Average::arithmeticMean($x);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public static function getSlope(float $b1, float $y, float $x) : float;
|
abstract public static function getSlope(float $b1, float $y, float $x) : float;
|
||||||
|
|
||||||
abstract public static function getElasticity(float $b1, float $y, float $x): float;
|
abstract public static function getElasticity(float $b1, float $y, float $x): float;
|
||||||
}
|
}
|
||||||
|
|
@ -4,5 +4,5 @@ namespace phpOMS\Message\Mail;
|
||||||
|
|
||||||
class OAuth
|
class OAuth
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -154,9 +154,9 @@ class InstallerAbstract
|
||||||
{
|
{
|
||||||
$directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes');
|
$directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes');
|
||||||
|
|
||||||
foreach($directories as $key => $subdir) {
|
foreach ($directories as $key => $subdir) {
|
||||||
if($subdir instanceof Directory) {
|
if ($subdir instanceof Directory) {
|
||||||
foreach($subdir as $key2 => $file) {
|
foreach ($subdir as $key2 => $file) {
|
||||||
self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
|
self::installRoutes(ROOT_PATH . '/' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +178,7 @@ class InstallerAbstract
|
||||||
*/
|
*/
|
||||||
private static function installRoutes(string $destRoutePath, string $srcRoutePath)
|
private static function installRoutes(string $destRoutePath, string $srcRoutePath)
|
||||||
{
|
{
|
||||||
if(!file_exists($destRoutePath)) {
|
if (!file_exists($destRoutePath)) {
|
||||||
file_put_contents($destRoutePath, '<?php return [];');
|
file_put_contents($destRoutePath, '<?php return [];');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,11 +196,11 @@ class InstallerAbstract
|
||||||
throw new PermissionException($destRoutePath);
|
throw new PermissionException($destRoutePath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!file_exists($srcRoutePath)) {
|
if (!file_exists($srcRoutePath)) {
|
||||||
throw new PathException($srcRoutePath);
|
throw new PathException($srcRoutePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists($destRoutePath)) {
|
if (!file_exists($destRoutePath)) {
|
||||||
throw new PathException($destRoutePath);
|
throw new PathException($destRoutePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ namespace phpOMS\Module;
|
||||||
use phpOMS\ApplicationAbstract;
|
use phpOMS\ApplicationAbstract;
|
||||||
use phpOMS\Autoloader;
|
use phpOMS\Autoloader;
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
use phpOMS\DataStorage\Database\DatabaseType;
|
||||||
use phpOMS\Log\FileLogger;
|
|
||||||
use phpOMS\Message\Http\Request;
|
use phpOMS\Message\Http\Request;
|
||||||
use phpOMS\System\File\PathException;
|
use phpOMS\System\File\PathException;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ interface Mediator extends \Countable
|
||||||
*
|
*
|
||||||
* @param string $group Group
|
* @param string $group Group
|
||||||
* @param \Closure $callback Function to call if the event gets triggered
|
* @param \Closure $callback Function to call if the event gets triggered
|
||||||
* @param bool $remove Remove event after execution
|
* @param bool $remove Remove event after execution
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -62,8 +62,8 @@ interface Mediator extends \Countable
|
||||||
*
|
*
|
||||||
* Add new element to group
|
* Add new element to group
|
||||||
*
|
*
|
||||||
* @param string $group Group
|
* @param string $group Group
|
||||||
* @param string $id Event ID
|
* @param string $id Event ID
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -77,8 +77,8 @@ interface Mediator extends \Countable
|
||||||
*
|
*
|
||||||
* An object fires an event
|
* An object fires an event
|
||||||
*
|
*
|
||||||
* @param string $group Group
|
* @param string $group Group
|
||||||
* @param string $id Event ID
|
* @param string $id Event ID
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ class Router
|
||||||
*/
|
*/
|
||||||
public function importFromFile(string $path) : bool
|
public function importFromFile(string $path) : bool
|
||||||
{
|
{
|
||||||
if(file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
/** @noinspection PhpIncludeInspection */
|
/** @noinspection PhpIncludeInspection */
|
||||||
$this->routes += include $path;
|
$this->routes += include $path;
|
||||||
|
|
||||||
|
|
@ -76,7 +76,7 @@ class Router
|
||||||
*
|
*
|
||||||
* @param string $route Route regex
|
* @param string $route Route regex
|
||||||
* @param mixed $destination Destination e.g. Module:function & verb
|
* @param mixed $destination Destination e.g. Module:function & verb
|
||||||
* @param int $verb Request verb
|
* @param int $verb Request verb
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -85,7 +85,7 @@ class Router
|
||||||
*/
|
*/
|
||||||
public function add(string $route, $destination, int $verb = RouteVerb::GET)
|
public function add(string $route, $destination, int $verb = RouteVerb::GET)
|
||||||
{
|
{
|
||||||
if(!isset($this->routes[$route])) {
|
if (!isset($this->routes[$route])) {
|
||||||
$this->routes[$route] = [];
|
$this->routes[$route] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,7 +99,7 @@ class Router
|
||||||
* Route request.
|
* Route request.
|
||||||
*
|
*
|
||||||
* @param RequestAbstract $request Request to route
|
* @param RequestAbstract $request Request to route
|
||||||
* @param int $verb Route verb
|
* @param int $verb Route verb
|
||||||
*
|
*
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*
|
*
|
||||||
|
|
@ -110,10 +110,10 @@ class Router
|
||||||
*/
|
*/
|
||||||
public function route($request, int $verb = RouteVerb::GET) : array
|
public function route($request, int $verb = RouteVerb::GET) : array
|
||||||
{
|
{
|
||||||
if($request instanceof RequestAbstract) {
|
if ($request instanceof RequestAbstract) {
|
||||||
$uri = $request->getUri();
|
$uri = $request->getUri();
|
||||||
$verb = $request->getRouteVerb();
|
$verb = $request->getRouteVerb();
|
||||||
} elseif(is_string($request)) {
|
} elseif (is_string($request)) {
|
||||||
$uri = $request;
|
$uri = $request;
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
|
@ -135,9 +135,9 @@ class Router
|
||||||
* Match route and uri.
|
* Match route and uri.
|
||||||
*
|
*
|
||||||
* @param string $route Route
|
* @param string $route Route
|
||||||
* @param int $routeVerb GET,POST for this route
|
* @param int $routeVerb GET,POST for this route
|
||||||
* @param string $uri Uri
|
* @param string $uri Uri
|
||||||
* @param int $remoteVerb Verb this request is using
|
* @param int $remoteVerb Verb this request is using
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,15 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
|
||||||
return $this->sum() / $this->count();
|
return $this->sum() / $this->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sum()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count()
|
||||||
|
{
|
||||||
|
return count($this->collection);
|
||||||
|
}
|
||||||
|
|
||||||
public function chunk()
|
public function chunk()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -69,11 +78,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function count()
|
|
||||||
{
|
|
||||||
return count($this->collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function diff()
|
public function diff()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -85,23 +89,36 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
|
||||||
public function every(int $n)
|
public function every(int $n)
|
||||||
{
|
{
|
||||||
$new = [];
|
$new = [];
|
||||||
for($i = 0; $i < $this->count(); $i += $n) {
|
for ($i = 0; $i < $this->count(); $i += $n) {
|
||||||
$new[] = $this->get($i);
|
$new[] = $this->get($i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self($new);
|
return new self($new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get($key)
|
||||||
|
{
|
||||||
|
if (!isset($this->collection[$key])) {
|
||||||
|
if (is_int($key) && $key < $this->count()) {
|
||||||
|
return $this->collection[array_keys($this->collection)[$key]];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->collection[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function except($filter)
|
public function except($filter)
|
||||||
{
|
{
|
||||||
if(!is_array($filter)) {
|
if (!is_array($filter)) {
|
||||||
$filter = [$filter];
|
$filter = [$filter];
|
||||||
}
|
}
|
||||||
|
|
||||||
$new = [];
|
$new = [];
|
||||||
for($i = 0; $i < $this->count(); $i++) {
|
for ($i = 0; $i < $this->count(); $i++) {
|
||||||
|
|
||||||
if(!in_array($this->get($i), $filter)) {
|
if (!in_array($this->get($i), $filter)) {
|
||||||
$new[] = $this->get($i);
|
$new[] = $this->get($i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -154,19 +171,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key)
|
|
||||||
{
|
|
||||||
if(!isset($this->collection[$key])) {
|
|
||||||
if(is_int($key) && $key < $this->count()) {
|
|
||||||
return $this->collection[array_keys($this->collection)[$key]];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return $this->collection[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function groupBy()
|
public function groupBy()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -203,10 +207,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sum()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function merge()
|
public function merge()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
parent::index();
|
parent::index();
|
||||||
|
|
||||||
foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) {
|
foreach (glob($this->path . DIRECTORY_SEPARATOR . $this->filter) as $filename) {
|
||||||
if(!StringUtils::endsWith(trim($filename), '.') ) {
|
if (!StringUtils::endsWith(trim($filename), '.')) {
|
||||||
$file = is_dir($filename) ? new self($filename) : new File($filename);
|
$file = is_dir($filename) ? new self($filename) : new File($filename);
|
||||||
|
|
||||||
$this->add($file);
|
$this->add($file);
|
||||||
|
|
@ -215,6 +215,83 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parent directory path.
|
||||||
|
*
|
||||||
|
* @param string $path Path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public static function parent(string $path) : string
|
||||||
|
{
|
||||||
|
$path = explode('/', str_replace('\\', '/', $path));
|
||||||
|
array_pop($path);
|
||||||
|
|
||||||
|
return implode('/', $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function created(string $path) : \DateTime
|
||||||
|
{
|
||||||
|
// TODO: Implement created() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function changed(string $path) : \DateTime
|
||||||
|
{
|
||||||
|
// TODO: Implement changed() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function owner(string $path) : int
|
||||||
|
{
|
||||||
|
// TODO: Implement owner() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function permission(string $path) : int
|
||||||
|
{
|
||||||
|
// TODO: Implement permission() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Iterator */
|
||||||
|
|
||||||
|
public static function delete(string $path) : bool
|
||||||
|
{
|
||||||
|
// TODO: Implement delete() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
||||||
|
{
|
||||||
|
// TODO: Implement copy() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
||||||
|
{
|
||||||
|
// TODO: Implement move() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function put(string $path, string $content, bool $overwrite = true) : bool
|
||||||
|
{
|
||||||
|
// TODO: Implement put() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(string $path) : string
|
||||||
|
{
|
||||||
|
// TODO: Implement get() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ArrayAccess */
|
||||||
|
|
||||||
|
public static function size(string $path) : int
|
||||||
|
{
|
||||||
|
// TODO: Implement size() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exists(string $path) : bool
|
||||||
|
{
|
||||||
|
return file_exists($path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get node by name.
|
* Get node by name.
|
||||||
*
|
*
|
||||||
|
|
@ -261,24 +338,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get parent directory path.
|
|
||||||
*
|
|
||||||
* @param string $path Path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public static function parent(string $path) : string
|
|
||||||
{
|
|
||||||
$path = explode('/', str_replace('\\', '/', $path));
|
|
||||||
array_pop($path);
|
|
||||||
|
|
||||||
return implode('/', $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove by name.
|
* Remove by name.
|
||||||
*
|
*
|
||||||
|
|
@ -305,8 +364,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterator */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -349,7 +406,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
return ($key !== null && $key !== false);
|
return ($key !== null && $key !== false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ArrayAccess */
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -417,59 +473,4 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
||||||
{
|
{
|
||||||
// TODO: Implement getContent() method.
|
// TODO: Implement getContent() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function created(string $path) : \DateTime
|
|
||||||
{
|
|
||||||
// TODO: Implement created() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function changed(string $path) : \DateTime
|
|
||||||
{
|
|
||||||
// TODO: Implement changed() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function owner(string $path) : int
|
|
||||||
{
|
|
||||||
// TODO: Implement owner() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function permission(string $path) : int
|
|
||||||
{
|
|
||||||
// TODO: Implement permission() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function delete(string $path) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement delete() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement copy() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement move() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function put(string $path, string $content, bool $overwrite = true) : bool
|
|
||||||
{
|
|
||||||
// TODO: Implement put() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function get(string $path) : string
|
|
||||||
{
|
|
||||||
// TODO: Implement get() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function size(string $path) : int
|
|
||||||
{
|
|
||||||
// TODO: Implement size() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function exists(string $path) : bool
|
|
||||||
{
|
|
||||||
return file_exists($path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -49,16 +49,6 @@ class File extends FileAbstract
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDirName() : string
|
|
||||||
{
|
|
||||||
return basename(dirname($this->path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDirPath() : string
|
|
||||||
{
|
|
||||||
return dirname($this->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index file.
|
* Index file.
|
||||||
*
|
*
|
||||||
|
|
@ -74,6 +64,155 @@ class File extends FileAbstract
|
||||||
$this->size = filesize($this->path);
|
$this->size = filesize($this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function put(string $path, string $content, bool $overwrite = true) : bool
|
||||||
|
{
|
||||||
|
if ($overwrite || !file_exists($path)) {
|
||||||
|
if (!Directory::exists(dirname($path))) {
|
||||||
|
Directory::create(dirname($path), '0644', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($path, $content);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(string $path) : string
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file_get_contents($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function exists(string $path) : bool
|
||||||
|
{
|
||||||
|
return file_exists($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function parent(string $path) : string
|
||||||
|
{
|
||||||
|
return Directory::parent(dirname($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function created(string $path) : \DateTime
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$created = new \DateTime();
|
||||||
|
$created->setTimestamp(filemtime($path));
|
||||||
|
|
||||||
|
return $created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function changed(string $path) : \DateTime
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$changed = new \DateTime();
|
||||||
|
$changed->setTimestamp(filectime($path));
|
||||||
|
|
||||||
|
return $changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function size(string $path) : int
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filesize($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function owner(string $path) : int
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileowner($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function permission(string $path) : int
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
throw new PathException($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileperms($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function dirname(string $path) : string
|
||||||
|
{
|
||||||
|
return dirname($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
||||||
|
{
|
||||||
|
if (!file_exists($from)) {
|
||||||
|
throw new PathException($from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($overwrite || !file_exists($to)) {
|
||||||
|
if (!Directory::exists(dirname($to))) {
|
||||||
|
Directory::create(dirname($to), '0644', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
copy($from, $to);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
||||||
|
{
|
||||||
|
if (!file_exists($from)) {
|
||||||
|
throw new PathException($from);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($overwrite || !file_exists($to)) {
|
||||||
|
if (!Directory::exists(dirname($to))) {
|
||||||
|
Directory::create(dirname($to), '0644', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename($from, $to);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete(string $path) : bool
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink($path);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDirName() : string
|
||||||
|
{
|
||||||
|
return basename(dirname($this->path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDirPath() : string
|
||||||
|
{
|
||||||
|
return dirname($this->path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|
@ -82,6 +221,21 @@ class File extends FileAbstract
|
||||||
return self::create($this->path);
|
return self::create($this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function create(string $path) : bool
|
||||||
|
{
|
||||||
|
if (!file_exists($path)) {
|
||||||
|
if (!Directory::exists(dirname($path))) {
|
||||||
|
Directory::create(dirname($path), '0644', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
touch($path);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file content.
|
* Get file content.
|
||||||
*
|
*
|
||||||
|
|
@ -108,21 +262,6 @@ class File extends FileAbstract
|
||||||
file_put_contents($this->path, $content);
|
file_put_contents($this->path, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function put(string $path, string $content, bool $overwrite = true) : bool
|
|
||||||
{
|
|
||||||
if($overwrite || !file_exists($path)) {
|
|
||||||
if(!Directory::exists(dirname($path))) {
|
|
||||||
Directory::create(dirname($path), '0644', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
file_put_contents($path, $content);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFileName() : string
|
public function getFileName() : string
|
||||||
{
|
{
|
||||||
return explode('.', $this->name)[0];
|
return explode('.', $this->name)[0];
|
||||||
|
|
@ -135,145 +274,6 @@ class File extends FileAbstract
|
||||||
return $extension[1] ?? '';
|
return $extension[1] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get(string $path) : string
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return file_get_contents($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function exists(string $path) : bool
|
|
||||||
{
|
|
||||||
return file_exists($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function create(string $path) : bool
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
if(!Directory::exists(dirname($path))) {
|
|
||||||
Directory::create(dirname($path), '0644', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
touch($path);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function parent(string $path) : string
|
|
||||||
{
|
|
||||||
return Directory::parent(dirname($path));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function created(string $path) : \DateTime
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$created = new \DateTime();
|
|
||||||
$created->setTimestamp(filemtime($path));
|
|
||||||
|
|
||||||
return $created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function changed(string $path) : \DateTime
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$changed = new \DateTime();
|
|
||||||
$changed->setTimestamp(filectime($path));
|
|
||||||
|
|
||||||
return $changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function size(string $path) : int
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filesize($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function owner(string $path) : int
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileowner($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function permission(string $path) : int
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
throw new PathException($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileperms($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function dirname(string $path) : string
|
|
||||||
{
|
|
||||||
return dirname($path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
if(!file_exists($from)) {
|
|
||||||
throw new PathException($from);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($overwrite || !file_exists($to)) {
|
|
||||||
if(!Directory::exists(dirname($to))) {
|
|
||||||
Directory::create(dirname($to), '0644', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
copy($from, $to);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool
|
|
||||||
{
|
|
||||||
if(!file_exists($from)) {
|
|
||||||
throw new PathException($from);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($overwrite || !file_exists($to)) {
|
|
||||||
if(!Directory::exists(dirname($to))) {
|
|
||||||
Directory::create(dirname($to), '0644', true);
|
|
||||||
}
|
|
||||||
|
|
||||||
rename($from, $to);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function delete(string $path) : bool
|
|
||||||
{
|
|
||||||
if(!file_exists($path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unlink($path);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getParent() : FileInterface
|
public function getParent() : FileInterface
|
||||||
{
|
{
|
||||||
// TODO: Implement getParent() method.
|
// TODO: Implement getParent() method.
|
||||||
|
|
|
||||||
|
|
@ -30,61 +30,61 @@ namespace phpOMS\System\File;
|
||||||
*/
|
*/
|
||||||
interface FileInterface
|
interface FileInterface
|
||||||
{
|
{
|
||||||
public function getCount() : int;
|
public static function created(string $path) : \DateTime;
|
||||||
|
|
||||||
public function getSize() : int;
|
public static function changed(string $path) : \DateTime;
|
||||||
|
|
||||||
public function getName() : string;
|
public static function owner(string $path) : int;
|
||||||
|
|
||||||
public function getPath() : string;
|
public static function permission(string $path) : int;
|
||||||
|
|
||||||
public function getParent() : FileInterface;
|
public static function parent(string $path) : string;
|
||||||
|
|
||||||
public function createNode() : bool;
|
public static function create(string $path) : bool;
|
||||||
|
|
||||||
public function copyNode() : bool;
|
public static function delete(string $path) : bool;
|
||||||
|
|
||||||
public function moveNode() : bool;
|
public static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
||||||
|
|
||||||
public function deleteNode() : bool;
|
public static function move(string $from, string $to, bool $overwrite = false) : bool;
|
||||||
|
|
||||||
public function putContent() : bool;
|
public static function put(string $path, string $content, bool $overwrite = true) : bool;
|
||||||
|
|
||||||
public function getContent() : string;
|
public static function get(string $path) : string;
|
||||||
|
|
||||||
public function getCreatedAt() : \DateTime;
|
public static function size(string $path) : int;
|
||||||
|
|
||||||
public function getChangedAt() : \DateTime;
|
public static function exists(string $path) : bool;
|
||||||
|
|
||||||
public function getOwner() : int;
|
public function getCount() : int;
|
||||||
|
|
||||||
public function getPermission() : string;
|
public function getSize() : int;
|
||||||
|
|
||||||
public function index();
|
public function getName() : string;
|
||||||
|
|
||||||
public static function created(string $path) : \DateTime;
|
public function getPath() : string;
|
||||||
|
|
||||||
public static function changed(string $path) : \DateTime;
|
public function getParent() : FileInterface;
|
||||||
|
|
||||||
public static function owner(string $path) : int;
|
public function createNode() : bool;
|
||||||
|
|
||||||
public static function permission(string $path) : int;
|
public function copyNode() : bool;
|
||||||
|
|
||||||
public static function parent(string $path) : string;
|
public function moveNode() : bool;
|
||||||
|
|
||||||
public static function create(string $path) : bool;
|
public function deleteNode() : bool;
|
||||||
|
|
||||||
public static function delete(string $path) : bool;
|
public function putContent() : bool;
|
||||||
|
|
||||||
public static function copy(string $from, string $to, bool $overwrite = false) : bool;
|
public function getContent() : string;
|
||||||
|
|
||||||
public static function move(string $from, string $to, bool $overwrite = false) : bool;
|
public function getCreatedAt() : \DateTime;
|
||||||
|
|
||||||
public static function put(string $path, string $content, bool $overwrite = true) : bool;
|
public function getChangedAt() : \DateTime;
|
||||||
|
|
||||||
public static function get(string $path) : string;
|
public function getOwner() : int;
|
||||||
|
|
||||||
public static function size(string $path) : int;
|
public function getPermission() : string;
|
||||||
|
|
||||||
public static function exists(string $path) : bool;
|
public function index();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ class UriFactory
|
||||||
* . = DOM class
|
* . = DOM class
|
||||||
* / = Current path
|
* / = Current path
|
||||||
* ? = Current query
|
* ? = Current query
|
||||||
* @ =
|
* @ =
|
||||||
* $ = Other data
|
* $ = Other data
|
||||||
*
|
*
|
||||||
* @param string $uri Path data
|
* @param string $uri Path data
|
||||||
|
|
|
||||||
|
|
@ -239,10 +239,10 @@ class ArrayUtils
|
||||||
*/
|
*/
|
||||||
public static function getArg(string $id, array $args)
|
public static function getArg(string $id, array $args)
|
||||||
{
|
{
|
||||||
if(($key = array_search($id, $args)) === false || $key === count($args) - 1) {
|
if (($key = array_search($id, $args)) === false || $key === count($args) - 1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim($args[$key+1], '" ');
|
return trim($args[$key + 1], '" ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,8 @@ class LZW implements CompressionInterface
|
||||||
|
|
||||||
$w = chr($compressed[0]);
|
$w = chr($compressed[0]);
|
||||||
$result = $w;
|
$result = $w;
|
||||||
$count = count($compressed);
|
$count = count($compressed);
|
||||||
|
|
||||||
for ($i = 1; $i < $count; $i++) {
|
for ($i = 1; $i < $count; $i++) {
|
||||||
$k = $compressed[$i];
|
$k = $compressed[$i];
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ class LZW implements CompressionInterface
|
||||||
$entry = $dictionary[$k];
|
$entry = $dictionary[$k];
|
||||||
} else {
|
} else {
|
||||||
if ($k !== $dictSize) {
|
if ($k !== $dictSize) {
|
||||||
throw new \Exception('Wrong dictionary size!'. $k . '.' . $dictSize);
|
throw new \Exception('Wrong dictionary size!' . $k . '.' . $dictSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = $w . $w[0];
|
$entry = $w . $w[0];
|
||||||
|
|
|
||||||
|
|
@ -31,48 +31,44 @@ class Ip
|
||||||
const IP_TABLE_PATH = __DIR__ . '/../../Localization/Default/Ip/ipGeoLocation.csv';
|
const IP_TABLE_PATH = __DIR__ . '/../../Localization/Default/Ip/ipGeoLocation.csv';
|
||||||
const IP_TABLE_ITERATIONS = 100;
|
const IP_TABLE_ITERATIONS = 100;
|
||||||
|
|
||||||
private function __construct() {}
|
private function __construct()
|
||||||
|
|
||||||
public static function ip2Float(string $ip) : float
|
|
||||||
{
|
{
|
||||||
$split = explode('.', $ip);
|
|
||||||
return $split[0] * (256 ** 3) + $split[1] * (256 ** 2) + $split[2] * (256 ** 1) + $split[3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ip2Country(string $ip) : string
|
public static function ip2Country(string $ip) : string
|
||||||
{
|
{
|
||||||
$fh = fopen(self::IP_TABLE_PATH, 'r');
|
$fh = fopen(self::IP_TABLE_PATH, 'r');
|
||||||
|
|
||||||
fseek($fh, 0, SEEK_END);
|
fseek($fh, 0, SEEK_END);
|
||||||
$end = ftell($fh);
|
$end = ftell($fh);
|
||||||
fseek($fh, 0);
|
fseek($fh, 0);
|
||||||
$start = 0;
|
$start = 0;
|
||||||
$current = $start;
|
$current = $start;
|
||||||
|
|
||||||
$ip = self::ip2Float($ip);
|
$ip = self::ip2Float($ip);
|
||||||
$country = '';
|
$country = '';
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
|
|
||||||
while($counter < self::IP_TABLE_ITERATIONS) {
|
while ($counter < self::IP_TABLE_ITERATIONS) {
|
||||||
$line = fgets($fh, 150);
|
$line = fgets($fh, 150);
|
||||||
if($current !== 0) {
|
if ($current !== 0) {
|
||||||
$line = fgets($fh, 150);
|
$line = fgets($fh, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
$split = explode(',', $line);
|
$split = explode(',', $line);
|
||||||
|
|
||||||
if($ip >= $split[0] && $ip <= $split[1]) {
|
if ($ip >= $split[0] && $ip <= $split[1]) {
|
||||||
$country = $split[2];
|
$country = $split[2];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($ip > $split[1]) {
|
if ($ip > $split[1]) {
|
||||||
$larger = true;
|
$larger = true;
|
||||||
$start = $current;
|
$start = $current;
|
||||||
fseek($fh, ($end - $current) / 2, SEEK_CUR);
|
fseek($fh, ($end - $current) / 2, SEEK_CUR);
|
||||||
} else {
|
} else {
|
||||||
$larger = false;
|
$larger = false;
|
||||||
$end = $current;
|
$end = $current;
|
||||||
fseek($fh, ($start - $current) / 2, SEEK_CUR);
|
fseek($fh, ($start - $current) / 2, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,4 +80,11 @@ class Ip
|
||||||
|
|
||||||
return $country;
|
return $country;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function ip2Float(string $ip) : float
|
||||||
|
{
|
||||||
|
$split = explode('.', $ip);
|
||||||
|
|
||||||
|
return $split[0] * (256 ** 3) + $split[1] * (256 ** 2) + $split[2] * (256 ** 1) + $split[3];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -642,7 +642,7 @@ class Repository
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) {
|
if (!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,21 @@ class JobQueue
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function runAsDeamon()
|
||||||
|
{
|
||||||
|
ob_end_clean();
|
||||||
|
fclose(STDIN);
|
||||||
|
fclose(STDOUT);
|
||||||
|
fclose(STDERR);
|
||||||
|
|
||||||
|
function shutdown()
|
||||||
|
{
|
||||||
|
posix_kill(posix_getpid(), SIGHUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
register_shutdown_function('shutdown');
|
||||||
|
}
|
||||||
|
|
||||||
public function setRunning(bool $run = true)
|
public function setRunning(bool $run = true)
|
||||||
{
|
{
|
||||||
$this->run = $run;
|
$this->run = $run;
|
||||||
|
|
@ -97,16 +112,16 @@ class JobQueue
|
||||||
return $this->run;
|
return $this->run;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSuspended(bool $suspended = true)
|
|
||||||
{
|
|
||||||
$this->suspended = $suspended;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isSuspended() : bool
|
public function isSuspended() : bool
|
||||||
{
|
{
|
||||||
return $this->suspended;
|
return $this->suspended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSuspended(bool $suspended = true)
|
||||||
|
{
|
||||||
|
$this->suspended = $suspended;
|
||||||
|
}
|
||||||
|
|
||||||
public function isTerminating() : bool
|
public function isTerminating() : bool
|
||||||
{
|
{
|
||||||
return $this->isTerminating;
|
return $this->isTerminating;
|
||||||
|
|
@ -127,21 +142,6 @@ class JobQueue
|
||||||
$this->isDeamonized = $deamonized;
|
$this->isDeamonized = $deamonized;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function runAsDeamon()
|
|
||||||
{
|
|
||||||
ob_end_clean();
|
|
||||||
fclose(STDIN);
|
|
||||||
fclose(STDOUT);
|
|
||||||
fclose(STDERR);
|
|
||||||
|
|
||||||
function shutdown()
|
|
||||||
{
|
|
||||||
posix_kill(posix_getpid(), SIGHUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
register_shutdown_function('shutdown');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function savePid()
|
private function savePid()
|
||||||
{
|
{
|
||||||
// todo: save pid somewhere for kill
|
// todo: save pid somewhere for kill
|
||||||
|
|
|
||||||
|
|
@ -19,5 +19,5 @@ use phpOMS\Validation\ValidatorAbstract;
|
||||||
|
|
||||||
class Barcode39 extends ValidatorAbstract
|
class Barcode39 extends ValidatorAbstract
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +51,7 @@ abstract class Iban extends ValidatorAbstract
|
||||||
*/
|
*/
|
||||||
public static function isValid($value) : bool
|
public static function isValid($value) : bool
|
||||||
{
|
{
|
||||||
$value = str_replace(' ', '', strtolower($value));
|
$value = str_replace(' ', '', strtolower($value));
|
||||||
$enumName = 'C_' . strtoupper(substr($value, 0, 2));
|
$enumName = 'C_' . strtoupper(substr($value, 0, 2));
|
||||||
|
|
||||||
if (!IbanEnum::isValidName($enumName)) {
|
if (!IbanEnum::isValidName($enumName)) {
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ class BitcoinValidator extends ValidatorAbstract
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
self::$msg = $e->getMessage();
|
self::$msg = $e->getMessage();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
* @link http://orange-management.com
|
* @link http://orange-management.com
|
||||||
*/
|
*/
|
||||||
namespace phpOMS\Validation;
|
namespace phpOMS\Validation;
|
||||||
|
|
||||||
use phpOMS\Utils\StringUtils;
|
use phpOMS\Utils\StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,26 @@ abstract class ViewAbstract implements \Serializable
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort views by order.
|
||||||
|
*
|
||||||
|
* @param array $a Array 1
|
||||||
|
* @param array $b Array 2
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
private static function viewSort(array $a, array $b) : int
|
||||||
|
{
|
||||||
|
if ($a['order'] === $b['order']) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($a['order'] < $b['order']) ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the template.
|
* Get the template.
|
||||||
*
|
*
|
||||||
|
|
@ -85,26 +105,6 @@ abstract class ViewAbstract implements \Serializable
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort views by order.
|
|
||||||
*
|
|
||||||
* @param array $a Array 1
|
|
||||||
* @param array $b Array 2
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
private static function viewSort(array $a, array $b) : int
|
|
||||||
{
|
|
||||||
if ($a['order'] === $b['order']) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ($a['order'] < $b['order']) ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return View[]
|
* @return View[]
|
||||||
*
|
*
|
||||||
|
|
@ -195,6 +195,25 @@ abstract class ViewAbstract implements \Serializable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize view for rendering.
|
||||||
|
*
|
||||||
|
* @return string|array
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
|
*/
|
||||||
|
public function serialize()
|
||||||
|
{
|
||||||
|
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
|
||||||
|
|
||||||
|
if ($path === false) {
|
||||||
|
return $this->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->render();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Arrayify view and it's subviews.
|
* Arrayify view and it's subviews.
|
||||||
*
|
*
|
||||||
|
|
@ -207,7 +226,7 @@ abstract class ViewAbstract implements \Serializable
|
||||||
{
|
{
|
||||||
$viewArray = [];
|
$viewArray = [];
|
||||||
|
|
||||||
if($this->template !== '') {
|
if ($this->template !== '') {
|
||||||
$viewArray[] = $this->render();
|
$viewArray[] = $this->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,25 +265,6 @@ abstract class ViewAbstract implements \Serializable
|
||||||
return $ob;
|
return $ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize view for rendering.
|
|
||||||
*
|
|
||||||
* @return string|array
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
||||||
*/
|
|
||||||
public function serialize()
|
|
||||||
{
|
|
||||||
$path = realpath($oldPath = __DIR__ . '/../..' . $this->template . '.tpl.php');
|
|
||||||
|
|
||||||
if ($path === false) {
|
|
||||||
return $this->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unserialize view.
|
* Unserialize view.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user