PhpStorm autofix/format

This commit is contained in:
Dennis Eichhorn 2016-08-20 12:04:30 +02:00
parent 0d7c17aa88
commit a02f1cca5d
49 changed files with 912 additions and 875 deletions

View File

@ -994,7 +994,7 @@ class DataMapperAbstract implements DataMapperInterface
/**
* Get random object
*
* @param int $amount Amount of random models
* @param int $amount Amount of random models
* @param int $relations Relations type
*
* @return mixed
@ -1031,7 +1031,7 @@ class DataMapperAbstract implements DataMapperInterface
{
$hasMany = count(static::$hasMany) > 0;
$hasOne = count(static::$hasOne) > 0;
$ownsOne = count(static::$ownsOne) > 0;
$ownsOne = count(static::$ownsOne) > 0;
if ($relations !== RelationType::NONE && ($hasMany || $hasOne)) {
foreach ($obj as $key => $value) {

View File

@ -87,7 +87,7 @@ class Grammar extends GrammarAbstract
* @since 1.0.0
*/
protected $randomComponents = [
'random'
'random',
];
/**

View File

@ -16,8 +16,6 @@
namespace phpOMS\Dispatcher;
use phpOMS\ApplicationAbstract;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Module\ModuleAbstract;
use phpOMS\System\File\PathException;

View File

@ -65,7 +65,7 @@ class EventManager implements Mediator
*/
public function attach(string $group, \Closure $callback, bool $remove = false) : bool
{
if(isset($this->callbacks[$group])) {
if (isset($this->callbacks[$group])) {
return false;
}
@ -74,54 +74,54 @@ class EventManager implements Mediator
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}
*/
public function detach(string $group) : bool
{
if(isset($this->callbacks[$group])) {
if (isset($this->callbacks[$group])) {
unset($this->callbacks[$group]);
}
if(isset($this->groups[$group])) {
if (isset($this->groups[$group])) {
unset($this->groups[$group]);
}
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}
*/
public function addGroup(string $group, string $id)
{
if(!isset($this->groups[$group])) {
if (!isset($this->groups[$group])) {
$this->groups[$group] = [];
}

View File

@ -1,61 +1,61 @@
{
"language": "EN",
"country": "USA",
"currency": {
"code" : "USD",
"position": 0
},
"thousand": ",",
"decimal": ".",
"angle": "Degree",
"temperature": "celsius",
"weight": {
"very_light" : "mg",
"light" : "g",
"medium" : "kg",
"heavy" : "t",
"very_heavy" : "t",
},
"speed": {
"very_slow" : "ms",
"slow" : "ms",
"medium" : "kph",
"fast" : "kph",
"very_fast" : "mach",
"sea" : "knot"
},
"length": {
"very_short" : "mm",
"short" : "cm",
"medium" : "m",
"long" : "km",
"very_long" : "km",
"sea": "mile"
},
"area": {
"very_small" : "mm",
"small" : "cm",
"medium" : "m",
"large" : "km",
"very_large" : "ha"
},
"volume": {
"very_small" : "ml",
"small" : "ml",
"medium" : "l",
"large" : "m",
"very_large" : "km",
"teaspoon": "metric teaspoon",
"tablespoon": "metric tablespoon",
"glass": "metric glass"
},
"datetime": {
"delim_date": ".",
"delim_time": ":",
"very_short": "d.m",
"short": "m.y",
"medium": "d.m.Y",
"long": "d.m.Y h:i",
"very_long": "d.m.Y h:i:s",
}
"language": "EN",
"country": "USA",
"currency": {
"code": "USD",
"position": 0
},
"thousand": ",",
"decimal": ".",
"angle": "Degree",
"temperature": "celsius",
"weight": {
"very_light": "mg",
"light": "g",
"medium": "kg",
"heavy": "t",
"very_heavy": "t",
},
"speed": {
"very_slow": "ms",
"slow": "ms",
"medium": "kph",
"fast": "kph",
"very_fast": "mach",
"sea": "knot"
},
"length": {
"very_short": "mm",
"short": "cm",
"medium": "m",
"long": "km",
"very_long": "km",
"sea": "mile"
},
"area": {
"very_small": "mm",
"small": "cm",
"medium": "m",
"large": "km",
"very_large": "ha"
},
"volume": {
"very_small": "ml",
"small": "ml",
"medium": "l",
"large": "m",
"very_large": "km",
"teaspoon": "metric teaspoon",
"tablespoon": "metric tablespoon",
"glass": "metric glass"
},
"datetime": {
"delim_date": ".",
"delim_time": ":",
"very_short": "d.m",
"short": "m.y",
"medium": "d.m.Y",
"long": "d.m.Y h:i",
"very_long": "d.m.Y h:i:s",
}
}

View File

@ -382,5 +382,5 @@ class Localization
public function setTemperatur(string $temperature)
{
$this->temperature = $temperature;
}
}
}

View File

@ -65,10 +65,10 @@ class Money implements \Serializable
* Constructor.
*
* @param string|int|float $value Value
* @param string $thousands Thousands separator
* @param string $decimal Decimal separator
* @param string $symbol Currency symbol
* @param int $position Symbol position
* @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>
@ -82,42 +82,6 @@ class Money implements \Serializable
$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.
*
@ -146,6 +110,57 @@ class Money implements \Serializable
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.
*
@ -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;
}
/**
* 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.
*

View File

@ -16,7 +16,6 @@
namespace phpOMS\Log;
use phpOMS\Datatypes\Exception\InvalidEnumValue;
use phpOMS\System\File\Directory;
use phpOMS\System\File\File;
use phpOMS\System\File\PathException;
use phpOMS\Utils\StringUtils;

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class AR {
class AR
{
}

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class ARCH {
class ARCH
{
}

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class ARFIMA {
class ARFIMA
{
}

View File

@ -2,133 +2,144 @@
namespace phpOMS\Math\Finance\Forecasting;
class ARIMA {
public function __construct(array $data, int $order = 12) {
if($order !== 12 && $order !== 4) {
throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition');
}
}
class ARIMA
{
public function __construct(array $data, int $order = 12)
{
if ($order !== 12 && $order !== 4) {
throw new \Exceptions('ARIMA only supports quarterly and monthly decomposition');
}
}
public function getDecomposition() : array {
$iteration1 = $this->getIteration($this->data);
$iteration2 = $this->getIteration($iteration1);
$iteration3 = $this->getIteration($iteration2);
public function getDecomposition() : array
{
$iteration1 = $this->getIteration($this->data);
$iteration2 = $this->getIteration($iteration1);
$iteration3 = $this->getIteration($iteration2);
return $iteration3;
}
return $iteration3;
}
private function getIteration(array $data) : array {
$multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE);
$tempDecomposition = $multiplicativeDecomposition->getDecomposition();
private function getIteration(array $data) : array
{
$multiplicativeDecomposition = new ClassicalDecomposition($data, $this->order, ClassicalDecomposition::MULTIPLICATIVE);
$tempDecomposition = $multiplicativeDecomposition->getDecomposition();
// 1
$trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order);
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true);
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true);
$prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent);
$trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries);
// 1
$trendCycleComponent = ClassicalDecomposition::computeTrendCycle($data, $this->order);
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 3, null, true), 3, null, true);
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 3, null, true), 3, null, true);
$prelimSeasonalAdjustedSeries = $this->getPrelimSeasonalAdjustedSeries($revisedSeasonalComponent);
$trendCycleComponent = $this->getTrendCycleEstimation($prelimSeasonalAdjustedSeries);
// 2
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true);
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true);
$seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent);
// 2
$centeredRatios = ClassicalDecomposition::computeDetrendedSeries($this->data, $trendCycleComponent, ClassicalDecomposition::MULTIPLICATIVE);
$prelimSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($centeredRatios, 5, null, true), 3, null, true);
$prelimRemainder = $this->getPrelimRemainder($centeredRatios, $prelimSeasonalComponent);
$modifiedRemainder = $this->removeOutliers($prelimRemainder, 0.5);
$modifiedCenteredRatios = $this->getModifiedCenteredRatios($prelimSeasonalComponent, $modifiedRemainder);
$revisedSeasonalComponent = Average::totalMovingAverage(Average::totalMovingAverage($modifiedCenteredRatios, 5, null, true), 3, null, true);
$seasonalAdjustedSeries = $this->getSeasonalAdjustedSeries($revisedSeasonalComponent);
$remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent);
$modifiedRemainder = $this->removeOutliers($remainder, 0.5);
$modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder);
$remainder = $this->getRemainder($seasonalAdjustedSeries, $trendCycleComponent);
$modifiedRemainder = $this->removeOutliers($remainder, 0.5);
$modifiedData = $this->getModifiedData($trendCycleComponent, $seasonalAdjustedSeries, $modifiedRemainder);
return $modifiedData;
}
return $modifiedData;
}
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array {
$remainder = [];
$count = count($prelimSeasonalComponent);
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array
{
$remainder = [];
$count = count($prelimSeasonalComponent);
for($i = 0; $i < $count; $i++) {
// +1 since 3x3 MA
$remainder[] = $centeredRatios[$i+1] / $prelimSeasonalComponent[$i];
}
for ($i = 0; $i < $count; $i++) {
// +1 since 3x3 MA
$remainder[] = $centeredRatios[$i + 1] / $prelimSeasonalComponent[$i];
}
return $remainder;
}
return $remainder;
}
private function removeOutliers(array $data, float $deviation = 0.5) : array {
$avg = AVerage::arithmeticMean($data);
private function removeOutliers(array $data, float $deviation = 0.5) : array
{
$avg = AVerage::arithmeticMean($data);
foreach($data as $key => $value) {
if($value / $avg - 1 > $deviation) {
$data[$key] = $avg;
}
}
foreach ($data as $key => $value) {
if ($value / $avg - 1 > $deviation) {
$data[$key] = $avg;
}
}
return $data;
}
return $data;
}
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array {
$centeredRatio = [];
$count = count($seasonal);
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array
{
$centeredRatio = [];
$count = count($seasonal);
for($i = 0; $i < $count; $i++) {
// +1 since 3x3 MA
$centeredRatio[] = $remainder[$i+1] * $seasonal[$i];
}
for ($i = 0; $i < $count; $i++) {
// +1 since 3x3 MA
$centeredRatio[] = $remainder[$i + 1] * $seasonal[$i];
}
return $centeredRatio;
}
return $centeredRatio;
}
private function getSeasonalAdjustedSeries(array $seasonal) : array {
$adjusted = [];
$count = count($seasonal);
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
private function getTrendCycleEstimation(array $seasonal) : array
{
$count = count($seasonal);
for($i = 0; $i < $count; $i++) {
$adjusted[] = $this->data[$start + $i] / $seasonal[$i];
}
if ($count >= 12) {
$weight = Average::MAH23;
} elseif ($count >= 6) {
$weight = Average::MAH13;
} else {
$weight = Average::MAH9;
}
return $adjusted;
}
// todo: implement
private function getTrendCycleEstimation(array $seasonal) : array {
$count = count($seasonal);
return $seasonal;
}
if($count >= 12) {
$weight = Average::MAH23;
} elseif($count >= 6) {
$weight = Average::MAH13;
} else {
$weight = Average::MAH9;
}
private function getSeasonalAdjustedSeries(array $seasonal) : array
{
$adjusted = [];
$count = count($seasonal);
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
// 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) {
$remainder = [];
foreach($seasonal as $key => $e) {
$remainder = $e / $trendCycle[$key];
}
private function getRemainder(array $seasonal, array $trendCycle)
{
$remainder = [];
foreach ($seasonal as $key => $e) {
$remainder = $e / $trendCycle[$key];
}
return $remainder;
}
return $remainder;
}
private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array {
$data = [];
$count = count($trendCycleComponent);
private function getModifiedData(array $trendCycleComponent, array $seasonalAdjustedSeries, array $remainder) : array
{
$data = [];
$count = count($trendCycleComponent);
for($i = 0; $i < $count; $i++) {
$data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i];
}
for ($i = 0; $i < $count; $i++) {
$data[] = $trendCycleComponent[$i] * $seasonalAdjustedSeries[$i] * $remainder[$i];
}
return $data;
}
return $data;
}
}

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class ARMA {
class ARMA
{
}

View File

@ -4,88 +4,96 @@ namespace phpOMS\Math\Finance\Forecasting;
use phpOMS\Math\Statistic\Average;
class ClassicalDecomposition {
const ADDITIVE = 0;
const MULTIPLICATIVE = 1;
class ClassicalDecomposition
{
const ADDITIVE = 0;
const MULTIPLICATIVE = 1;
private $mode = self::ADDITIVE;
private $data = [];
private $order = 0;
private $dataSize = 0;
private $mode = self::ADDITIVE;
private $data = [];
private $order = 0;
private $dataSize = 0;
public function __construct(array $data, int $order, int $mode = self::ADDITIVE) {
$this->mode = $mode;
$this->data = $data;
$this->order = $order;
public function __construct(array $data, int $order, int $mode = self::ADDITIVE)
{
$this->mode = $mode;
$this->data = $data;
$this->order = $order;
$this->dataSize = count($data);
}
$this->dataSize = count($data);
}
public function getDecomposition() : array {
$trendCycleComponent = self::computeTrendCycle($this->data, $this->order);
$detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode);
$seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order);
$remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent);
public function getDecomposition() : array
{
$trendCycleComponent = self::computeTrendCycle($this->data, $this->order);
$detrendedSeries = self::computeDetrendedSeries($this->data, $trendCycleComponent, $this->mode);
$seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order);
$remainderComponent = $this->computeRemainderComponent($trendCycleComponent, $seasonalComponent);
return [
'trendCycleComponent' => $trendCycleComponent,
'detrendedSeries' => $detrendedSeries,
'seasonalComponent' => $seasonalComponent,
'remainderComponent' => $remainderComponent,
];
}
return [
'trendCycleComponent' => $trendCycleComponent,
'detrendedSeries' => $detrendedSeries,
'seasonalComponent' => $seasonalComponent,
'remainderComponent' => $remainderComponent,
];
}
public static function computeTrendCycle(array $data, int $order) : array {
$mMA = Average::totalMovingAverage($data, $order, null, true);
public static function computeTrendCycle(array $data, int $order) : array
{
$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 {
$detrended = [];
$count = count($trendCycleComponent);
$start = self::getStartOfDecomposition(count($data), $count);
public static function computeDetrendedSeries(array $data, array $trendCycleComponent, int $mode) : array
{
$detrended = [];
$count = count($trendCycleComponent);
$start = self::getStartOfDecomposition(count($data), $count);
for($i = 0; $i < $count; $i++) {
$detrended[] = $mode === self::ADDITIVE ? $data[$start + $i] - $trendCycleComponent[$i] : $data[$start + $i] / $trendCycleComponent[$i];
}
for ($i = 0; $i < $count; $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
*/
public static function getStartOfDecomposition(int $dataSize, int $trendCycleComponents) : int {
return ($dataSize - $trendCycleComponents) / 2;
}
/**
* 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
{
return ($dataSize - $trendCycleComponents) / 2;
}
private function computeSeasonalComponent() : array {
$seasonalComponent = [];
private function computeSeasonalComponent() : array
{
$seasonalComponent = [];
for($i = 0; $i < $this->orderSize; $i++) {
$temp = [];
for ($i = 0; $i < $this->orderSize; $i++) {
$temp = [];
for($j = $i * $this->order; $j < $count; $j += $this->order) {
$temp[] = $this->data[$j];
}
for ($j = $i * $this->order; $j < $count; $j += $this->order) {
$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 {
$remainderComponent = [];
$count = count($trendCycleComponent);
$start = self::getStartOfDecomposition($this->dataSize, $count);
$seasons = count($seasonalComponent);
public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array
{
$remainderComponent = [];
$count = count($trendCycleComponent);
$start = self::getStartOfDecomposition($this->dataSize, $count);
$seasons = count($seasonalComponent);
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]);
}
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]);
}
return $remainderComponent;
}
return $remainderComponent;
}
}

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class ExponentialSmoothing {
class ExponentialSmoothing
{
}

View File

@ -2,6 +2,7 @@
namespace phpOMS\Math\Finance\Forecasting;
class GARCH {
class GARCH
{
}

View File

@ -2,7 +2,8 @@
namespace phpOMS\Math\Finance\Forecasting;
class MA {
class MA
{
}

View File

@ -2,7 +2,8 @@
namespace phpOMS\Math\Finance\Forecasting;
class NAR {
class NAR
{
}

View File

@ -2,7 +2,8 @@
namespace phpOMS\Math\Finance\Forecasting;
class NMA {
class NMA
{
}

View File

@ -2,7 +2,8 @@
namespace phpOMS\Math\Finance\Forecasting;
class SARIMA {
class SARIMA
{
}

View File

@ -18,5 +18,5 @@ namespace phpOMS\Math\Number;
class Irrational
{
}

View File

@ -30,18 +30,92 @@ namespace phpOMS\Math\Statistic;
class Average
{
const MA3 = [1/3, 1/3];
const MA3 = [1 / 3, 1 / 3];
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 MA3x3 = [1/3, 2/9, 1/9];
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 MA2x12 = [5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 5 / 6, 0.42];
const MA3x3 = [1 / 3, 2 / 9, 1 / 9];
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 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 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 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.
*
@ -73,10 +147,11 @@ class Average
}
/**
* Average change.
* Calculate the arithmetic mean.
*
* @param array $x Dataset
* @param int $h Future steps
* Example: ([1, 2, 2, 3, 4, 4, 2])
*
* @param array $values Values
*
* @return float
*
@ -85,63 +160,15 @@ class Average
* @since 1.0.0
* @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);
}
/**
* 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');
if ($count === 0) {
throw new \Exception('Division zero');
}
$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));
}
}
/**
* 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;
return array_sum($values) / $count;
}
/**
@ -193,31 +220,6 @@ class Average
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.
*

View File

@ -181,17 +181,19 @@ class Error
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function getSumSquaredError(array $errors) : float {
public static function getSumSquaredError(array $errors) : float
{
$error = 0.0;
foreach($errors as $e) {
$error += $e*$e;
foreach ($errors as $e) {
$error += $e * $e;
}
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));
}
@ -199,7 +201,8 @@ class Error
* 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);
}
@ -208,16 +211,18 @@ class Error
*
* Correction for small amount of observations
*/
public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float {
return $aic + (2*($predictors +2)*($predictors + 3)) / ($observations - $predictors - 3);
public static function getCorrectedAkaikeInformationCriterion(float $aic, int $observations, int $predictors) : float
{
return $aic + (2 * ($predictors + 2) * ($predictors + 3)) / ($observations - $predictors - 3);
}
/**
* Get Bayesian information criterion (BIC)
*
*/
public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float {
return $observations * log($sse / $observations) + ($predictors +2)*log($observations);
public static function getSchwarzBayesianInformationCriterion(float $sse, int $observations, int $predictors) : float
{
return $observations * log($sse / $observations) + ($predictors + 2) * log($observations);
}
/**

View File

@ -16,10 +16,6 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
use phpOMS\Math\Statistic\Average;
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
use phpOMS\Math\Statistic\MeasureOfDispersion;
/**
* Regression class.
*
@ -33,11 +29,13 @@ use phpOMS\Math\Statistic\MeasureOfDispersion;
*/
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;
}
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;
}
}

View File

@ -16,10 +16,6 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
use phpOMS\Math\Statistic\Average;
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
use phpOMS\Math\Statistic\MeasureOfDispersion;
/**
* Regression class.
*
@ -48,23 +44,25 @@ class LevelLogRegression extends RegressionAbstract
*/
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');
}
for($i = 0; $i < $c; $i++) {
for ($i = 0; $i < $c; $i++) {
$x[$i] = log($x[i]);
}
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;
}
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;
}
}

View File

@ -16,10 +16,6 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
use phpOMS\Math\Statistic\Average;
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
use phpOMS\Math\Statistic\MeasureOfDispersion;
/**
* Regression class.
*
@ -48,23 +44,25 @@ class LogLevelRegression extends RegressionAbstract
*/
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');
}
for($i = 0; $i < $c; $i++) {
for ($i = 0; $i < $c; $i++) {
$y[$i] = log($y[i]);
}
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;
}
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;
}
}

View File

@ -16,10 +16,6 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
use phpOMS\Math\Statistic\Average;
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
use phpOMS\Math\Statistic\MeasureOfDispersion;
/**
* Regression class.
*
@ -48,11 +44,11 @@ class LogLogRegression extends RegressionAbstract
*/
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');
}
for($i = 0; $i < $c; $i++) {
for ($i = 0; $i < $c; $i++) {
$x[$i] = log($x[i]);
$y[$i] = log($y[i]);
}
@ -60,12 +56,14 @@ class LogLogRegression extends RegressionAbstract
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;
}
public static function getElasticity(float $b1, float $y, float $x): float {
public static function getElasticity(float $b1, float $y, float $x): float
{
return $b1;
}
}

View File

@ -2,20 +2,26 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
class MultipleLinearRegression {
public static function getRegression(array $x, array $y) : array {
$X = new Matrix(count($x), count($x[0]));
$X->setArray($x);
$XT = $X->transpose();
class MultipleLinearRegression
{
public static function getRegression(array $x, array $y) : array
{
$X = new Matrix(count($x), count($x[0]));
$X->setArray($x);
$XT = $X->transpose();
$Y = new Matrix(count($y));
$Y->setArray($y);
$Y = new Matrix(count($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
{
}
}

View File

@ -6,7 +6,8 @@ use phpOMS\Math\Statistic\Average;
use phpOMS\Math\Statistic\Forecast\ForecastIntervalMultiplier;
use phpOMS\Math\Statistic\MeasureOfDispersion;
abstract class RegressionAbstract {
abstract class RegressionAbstract
{
/**
* Get linear regression based on scatter plot.
*
@ -22,7 +23,7 @@ abstract class RegressionAbstract {
*/
public static function getRegression(array $x, array $y) : array
{
if(count($x) != count($y)) {
if (count($x) != count($y)) {
throw new \Exception('Dimension');
}
@ -30,7 +31,7 @@ abstract class RegressionAbstract {
return ['b0' => self::getBeta0($x, $y, $b1), 'b1' => $b1];
}
/**
* Standard error of the regression.
*
@ -129,7 +130,7 @@ abstract class RegressionAbstract {
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;
}

View File

@ -4,5 +4,5 @@ namespace phpOMS\Message\Mail;
class OAuth
{
}

View File

@ -154,9 +154,9 @@ class InstallerAbstract
{
$directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes');
foreach($directories as $key => $subdir) {
if($subdir instanceof Directory) {
foreach($subdir as $key2 => $file) {
foreach ($directories as $key => $subdir) {
if ($subdir instanceof Directory) {
foreach ($subdir as $key2 => $file) {
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)
{
if(!file_exists($destRoutePath)) {
if (!file_exists($destRoutePath)) {
file_put_contents($destRoutePath, '<?php return [];');
}
@ -196,11 +196,11 @@ class InstallerAbstract
throw new PermissionException($destRoutePath);
}
} else {
if(!file_exists($srcRoutePath)) {
if (!file_exists($srcRoutePath)) {
throw new PathException($srcRoutePath);
}
if(!file_exists($destRoutePath)) {
if (!file_exists($destRoutePath)) {
throw new PathException($destRoutePath);
}
}

View File

@ -18,7 +18,6 @@ namespace phpOMS\Module;
use phpOMS\ApplicationAbstract;
use phpOMS\Autoloader;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\Log\FileLogger;
use phpOMS\Message\Http\Request;
use phpOMS\System\File\PathException;

View File

@ -36,7 +36,7 @@ interface Mediator extends \Countable
*
* @param string $group Group
* @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
*
@ -62,8 +62,8 @@ interface Mediator extends \Countable
*
* Add new element to group
*
* @param string $group Group
* @param string $id Event ID
* @param string $group Group
* @param string $id Event ID
*
* @return void
*
@ -77,8 +77,8 @@ interface Mediator extends \Countable
*
* An object fires an event
*
* @param string $group Group
* @param string $id Event ID
* @param string $group Group
* @param string $id Event ID
*
* @return void
*

View File

@ -61,7 +61,7 @@ class Router
*/
public function importFromFile(string $path) : bool
{
if(file_exists($path)) {
if (file_exists($path)) {
/** @noinspection PhpIncludeInspection */
$this->routes += include $path;
@ -76,7 +76,7 @@ class Router
*
* @param string $route Route regex
* @param mixed $destination Destination e.g. Module:function & verb
* @param int $verb Request verb
* @param int $verb Request verb
*
* @return void
*
@ -85,7 +85,7 @@ class Router
*/
public function add(string $route, $destination, int $verb = RouteVerb::GET)
{
if(!isset($this->routes[$route])) {
if (!isset($this->routes[$route])) {
$this->routes[$route] = [];
}
@ -99,7 +99,7 @@ class Router
* Route request.
*
* @param RequestAbstract $request Request to route
* @param int $verb Route verb
* @param int $verb Route verb
*
* @return string[]
*
@ -110,10 +110,10 @@ class Router
*/
public function route($request, int $verb = RouteVerb::GET) : array
{
if($request instanceof RequestAbstract) {
$uri = $request->getUri();
if ($request instanceof RequestAbstract) {
$uri = $request->getUri();
$verb = $request->getRouteVerb();
} elseif(is_string($request)) {
} elseif (is_string($request)) {
$uri = $request;
} else {
throw new \Exception();
@ -135,9 +135,9 @@ class Router
* Match route and uri.
*
* @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 int $remoteVerb Verb this request is using
* @param int $remoteVerb Verb this request is using
*
* @return bool
*

View File

@ -51,6 +51,15 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
return $this->sum() / $this->count();
}
public function sum()
{
}
public function count()
{
return count($this->collection);
}
public function chunk()
{
@ -69,11 +78,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
{
}
public function count()
{
return count($this->collection);
}
public function diff()
{
}
@ -85,23 +89,36 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
public function every(int $n)
{
$new = [];
for($i = 0; $i < $this->count(); $i += $n) {
for ($i = 0; $i < $this->count(); $i += $n) {
$new[] = $this->get($i);
}
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)
{
if(!is_array($filter)) {
if (!is_array($filter)) {
$filter = [$filter];
}
$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);
}
}
@ -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()
{
}
@ -203,10 +207,6 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
{
}
public function sum()
{
}
public function merge()
{
}

View File

@ -80,7 +80,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
parent::index();
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);
$this->add($file);
@ -215,6 +215,83 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
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.
*
@ -261,24 +338,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
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.
*
@ -305,8 +364,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
return false;
}
/* Iterator */
/**
* {@inheritdoc}
*/
@ -349,7 +406,6 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
return ($key !== null && $key !== false);
}
/* ArrayAccess */
/**
* {@inheritdoc}
*/
@ -417,59 +473,4 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
{
// 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);
}
}

View File

@ -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.
*
@ -74,6 +64,155 @@ class File extends FileAbstract
$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}
*/
@ -82,6 +221,21 @@ class File extends FileAbstract
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.
*
@ -108,21 +262,6 @@ class File extends FileAbstract
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
{
return explode('.', $this->name)[0];
@ -135,145 +274,6 @@ class File extends FileAbstract
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
{
// TODO: Implement getParent() method.

View File

@ -30,61 +30,61 @@ namespace phpOMS\System\File;
*/
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();
}

View File

@ -94,7 +94,7 @@ class UriFactory
* . = DOM class
* / = Current path
* ? = Current query
* @ =
* @ =
* $ = Other data
*
* @param string $uri Path data

View File

@ -239,10 +239,10 @@ class ArrayUtils
*/
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 trim($args[$key+1], '" ');
return trim($args[$key + 1], '" ');
}
}

View File

@ -81,8 +81,8 @@ class LZW implements CompressionInterface
$w = chr($compressed[0]);
$result = $w;
$count = count($compressed);
$count = count($compressed);
for ($i = 1; $i < $count; $i++) {
$k = $compressed[$i];
@ -90,7 +90,7 @@ class LZW implements CompressionInterface
$entry = $dictionary[$k];
} else {
if ($k !== $dictSize) {
throw new \Exception('Wrong dictionary size!'. $k . '.' . $dictSize);
throw new \Exception('Wrong dictionary size!' . $k . '.' . $dictSize);
}
$entry = $w . $w[0];

View File

@ -31,48 +31,44 @@ class Ip
const IP_TABLE_PATH = __DIR__ . '/../../Localization/Default/Ip/ipGeoLocation.csv';
const IP_TABLE_ITERATIONS = 100;
private function __construct() {}
public static function ip2Float(string $ip) : float
private function __construct()
{
$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');
fseek($fh, 0, SEEK_END);
$end = ftell($fh);
fseek($fh, 0);
$start = 0;
$start = 0;
$current = $start;
$ip = self::ip2Float($ip);
$ip = self::ip2Float($ip);
$country = '';
$counter = 0;
while($counter < self::IP_TABLE_ITERATIONS) {
while ($counter < self::IP_TABLE_ITERATIONS) {
$line = fgets($fh, 150);
if($current !== 0) {
if ($current !== 0) {
$line = fgets($fh, 150);
}
$split = explode(',', $line);
if($ip >= $split[0] && $ip <= $split[1]) {
if ($ip >= $split[0] && $ip <= $split[1]) {
$country = $split[2];
break;
}
if($ip > $split[1]) {
if ($ip > $split[1]) {
$larger = true;
$start = $current;
$start = $current;
fseek($fh, ($end - $current) / 2, SEEK_CUR);
} else {
$larger = false;
$end = $current;
$end = $current;
fseek($fh, ($start - $current) / 2, SEEK_CUR);
}
@ -84,4 +80,11 @@ class Ip
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];
}
}

View File

@ -642,7 +642,7 @@ class Repository
continue;
}
if(!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) {
if (!file_exists($path = $this->getDirectoryPath() . ($this->bare ? '/' : '/../') . $line)) {
return 0;
}

View File

@ -86,6 +86,21 @@ class JobQueue
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)
{
$this->run = $run;
@ -97,16 +112,16 @@ class JobQueue
return $this->run;
}
public function setSuspended(bool $suspended = true)
{
$this->suspended = $suspended;
}
public function isSuspended() : bool
{
return $this->suspended;
}
public function setSuspended(bool $suspended = true)
{
$this->suspended = $suspended;
}
public function isTerminating() : bool
{
return $this->isTerminating;
@ -127,21 +142,6 @@ class JobQueue
$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()
{
// todo: save pid somewhere for kill

View File

@ -19,5 +19,5 @@ use phpOMS\Validation\ValidatorAbstract;
class Barcode39 extends ValidatorAbstract
{
}

View File

@ -51,7 +51,7 @@ abstract class Iban extends ValidatorAbstract
*/
public static function isValid($value) : bool
{
$value = str_replace(' ', '', strtolower($value));
$value = str_replace(' ', '', strtolower($value));
$enumName = 'C_' . strtoupper(substr($value, 0, 2));
if (!IbanEnum::isValidName($enumName)) {

View File

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

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace phpOMS\Validation;
use phpOMS\Utils\StringUtils;
/**

View File

@ -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.
*
@ -85,26 +105,6 @@ abstract class ViewAbstract implements \Serializable
$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[]
*
@ -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.
*
@ -207,7 +226,7 @@ abstract class ViewAbstract implements \Serializable
{
$viewArray = [];
if($this->template !== '') {
if ($this->template !== '') {
$viewArray[] = $this->render();
}
@ -246,25 +265,6 @@ abstract class ViewAbstract implements \Serializable
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.
*