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

@ -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

@ -74,22 +74,6 @@ class EventManager implements Mediator
return true;
}
/**
* {@inheritdoc}
*/
public function detach(string $group) : bool
{
if(isset($this->callbacks[$group])) {
unset($this->callbacks[$group]);
}
if(isset($this->groups[$group])) {
unset($this->groups[$group]);
}
return true;
}
/**
* {@inheritdoc}
*/
@ -116,6 +100,22 @@ class EventManager implements Mediator
return empty($this->groups[$group]);
}
/**
* {@inheritdoc}
*/
public function detach(string $group) : bool
{
if (isset($this->callbacks[$group])) {
unset($this->callbacks[$group]);
}
if (isset($this->groups[$group])) {
unset($this->groups[$group]);
}
return true;
}
/**
* {@inheritdoc}
*/

View File

@ -82,6 +82,34 @@ class Money implements \Serializable
$this->position = $position;
}
/**
* Money to int.
*
* @param string $value Money value
* @param string $thousands Thousands character
* @param string $decimal Decimal character
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function toInt(string $value, string $thousands = ',', string $decimal = '.') : int
{
$split = explode($decimal, $value);
$left = $split[0];
$left = str_replace($thousands, '', $left);
$right = '';
if (count($split) > 1) {
$right = $split[1];
}
$right = substr($right, 0, self::MAX_DECIMALS);
return (int) (((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0'));
}
/**
* Set localization.
*
@ -119,31 +147,18 @@ class Money implements \Serializable
}
/**
* Money to int.
* Get money.
*
* @param string $value Money value
* @param string $thousands Thousands character
* @param string $decimal Decimal character
* @param int $decimals Precision
*
* @return int
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function toInt(string $value, string $thousands = ',', string $decimal = '.') : int
public function getCurrency(int $decimals = 2) : string
{
$split = explode($decimal, $value);
$left = $split[0];
$left = str_replace($thousands, '', $left);
$right = '';
if (count($split) > 1) {
$right = $split[1];
}
$right = substr($right, 0, self::MAX_DECIMALS);
return (int) (((int) $left) * 10 ** self::MAX_DECIMALS + (int) str_pad($right, self::MAX_DECIMALS, '0'));
return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : '');
}
/**
@ -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,14 +2,17 @@
namespace phpOMS\Math\Finance\Forecasting;
class ARIMA {
public function __construct(array $data, int $order = 12) {
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 {
public function getDecomposition() : array
{
$iteration1 = $this->getIteration($this->data);
$iteration2 = $this->getIteration($iteration1);
$iteration3 = $this->getIteration($iteration2);
@ -17,7 +20,8 @@ class ARIMA {
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();
@ -48,7 +52,8 @@ class ARIMA {
return $modifiedData;
}
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array {
private function getPrelimRemainder(array $centeredRatios, array $prelimSeasonalComponent) : array
{
$remainder = [];
$count = count($prelimSeasonalComponent);
@ -60,7 +65,8 @@ class ARIMA {
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);
foreach ($data as $key => $value) {
@ -72,7 +78,8 @@ class ARIMA {
return $data;
}
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array {
private function getModifiedCenteredRatios(array $seasonal, array $remainder) : array
{
$centeredRatio = [];
$count = count($seasonal);
@ -84,19 +91,8 @@ class ARIMA {
return $centeredRatio;
}
private function getSeasonalAdjustedSeries(array $seasonal) : array {
$adjusted = [];
$count = count($seasonal);
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
for($i = 0; $i < $count; $i++) {
$adjusted[] = $this->data[$start + $i] / $seasonal[$i];
}
return $adjusted;
}
private function getTrendCycleEstimation(array $seasonal) : array {
private function getTrendCycleEstimation(array $seasonal) : array
{
$count = count($seasonal);
if ($count >= 12) {
@ -112,7 +108,21 @@ class ARIMA {
return $seasonal;
}
private function getRemainder(array $seasonal, array $trendCycle) {
private function getSeasonalAdjustedSeries(array $seasonal) : array
{
$adjusted = [];
$count = count($seasonal);
$start = ClassicalDecomposition::getStartOfDecomposition(count($this->data), $count);
for ($i = 0; $i < $count; $i++) {
$adjusted[] = $this->data[$start + $i] / $seasonal[$i];
}
return $adjusted;
}
private function getRemainder(array $seasonal, array $trendCycle)
{
$remainder = [];
foreach ($seasonal as $key => $e) {
$remainder = $e / $trendCycle[$key];
@ -121,7 +131,8 @@ class ARIMA {
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);

View File

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

View File

@ -4,7 +4,8 @@ namespace phpOMS\Math\Finance\Forecasting;
use phpOMS\Math\Statistic\Average;
class ClassicalDecomposition {
class ClassicalDecomposition
{
const ADDITIVE = 0;
const MULTIPLICATIVE = 1;
@ -13,7 +14,8 @@ class ClassicalDecomposition {
private $order = 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->order = $order;
@ -21,7 +23,8 @@ class ClassicalDecomposition {
$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);
$seasonalComponent = $this->computeSeasonalComponent($detrendedSeries, $this->order);
@ -35,13 +38,15 @@ class ClassicalDecomposition {
];
}
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);
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);
$start = self::getStartOfDecomposition(count($data), $count);
@ -56,11 +61,13 @@ class ClassicalDecomposition {
/**
* 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;
}
private function computeSeasonalComponent() : array {
private function computeSeasonalComponent() : array
{
$seasonalComponent = [];
for ($i = 0; $i < $this->orderSize; $i++) {
@ -76,7 +83,8 @@ class ClassicalDecomposition {
return $seasonalComponent;
}
public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array {
public static function computeRemainderComponent(array $trendCycleComponent, array $seasonalComponent) : array
{
$remainderComponent = [];
$count = count($trendCycleComponent);
$start = self::getStartOfDecomposition($this->dataSize, $count);

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

@ -42,6 +42,80 @@ class Average
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);
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;
$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,7 +181,8 @@ 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) {
@ -191,7 +192,8 @@ class 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));
}
@ -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,7 +211,8 @@ class Error
*
* 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);
}
@ -216,7 +220,8 @@ class Error
* 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);
}

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.
*
@ -59,11 +55,13 @@ class LevelLogRegression 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 / $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.
*
@ -59,11 +55,13 @@ class LogLevelRegression 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;
}
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.
*
@ -60,11 +56,13 @@ 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,8 +2,10 @@
namespace phpOMS\Math\Statistic\Forecast\Regression;
class MultipleLinearRegression {
public static function getRegression(array $x, array $y) : array {
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();
@ -15,7 +17,11 @@ class MultipleLinearRegression {
return $XT->mult($X)->inverse()->mult($XT)->mult($Y)->toArray();
}
public static function getVariance() : float {}
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.
*

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

@ -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()
{
}
@ -92,6 +96,19 @@ class Collection implements \Countable, \ArrayAccess, \Iterator, \JsonSerializab
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)) {
@ -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

@ -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,40 +64,6 @@ class File extends FileAbstract
$this->size = filesize($this->path);
}
/**
* {@inheritdoc}
*/
public function createNode() : bool
{
return self::create($this->path);
}
/**
* Get file content.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getContent() : string
{
return file_get_contents($this->path);
}
/**
* Set file content.
*
* @param string $content Content to set
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setContent(string $content)
{
file_put_contents($this->path, $content);
}
public static function put(string $path, string $content, bool $overwrite = true) : bool
{
if ($overwrite || !file_exists($path)) {
@ -123,18 +79,6 @@ class File extends FileAbstract
return false;
}
public function getFileName() : string
{
return explode('.', $this->name)[0];
}
public function getExtension() : string
{
$extension = explode('.', $this->name);
return $extension[1] ?? '';
}
public static function get(string $path) : string
{
if (!file_exists($path)) {
@ -149,21 +93,6 @@ class File extends FileAbstract
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));
@ -274,6 +203,77 @@ class File extends FileAbstract
return true;
}
public function getDirName() : string
{
return basename(dirname($this->path));
}
public function getDirPath() : string
{
return dirname($this->path);
}
/**
* {@inheritdoc}
*/
public function createNode() : bool
{
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.
*
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getContent() : string
{
return file_get_contents($this->path);
}
/**
* Set file content.
*
* @param string $content Content to set
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setContent(string $content)
{
file_put_contents($this->path, $content);
}
public function getFileName() : string
{
return explode('.', $this->name)[0];
}
public function getExtension() : string
{
$extension = explode('.', $this->name);
return $extension[1] ?? '';
}
public function getParent() : FileInterface
{
// TODO: Implement getParent() method.

View File

@ -30,6 +30,32 @@ namespace phpOMS\System\File;
*/
interface FileInterface
{
public static function created(string $path) : \DateTime;
public static function changed(string $path) : \DateTime;
public static function owner(string $path) : int;
public static function permission(string $path) : int;
public static function parent(string $path) : string;
public static function create(string $path) : bool;
public static function delete(string $path) : bool;
public static function copy(string $from, string $to, bool $overwrite = false) : bool;
public static function move(string $from, string $to, bool $overwrite = false) : bool;
public static function put(string $path, string $content, bool $overwrite = true) : bool;
public static function get(string $path) : string;
public static function size(string $path) : int;
public static function exists(string $path) : bool;
public function getCount() : int;
public function getSize() : int;
@ -61,30 +87,4 @@ interface FileInterface
public function getPermission() : string;
public function index();
public static function created(string $path) : \DateTime;
public static function changed(string $path) : \DateTime;
public static function owner(string $path) : int;
public static function permission(string $path) : int;
public static function parent(string $path) : string;
public static function create(string $path) : bool;
public static function delete(string $path) : bool;
public static function copy(string $from, string $to, bool $overwrite = false) : bool;
public static function move(string $from, string $to, bool $overwrite = false) : bool;
public static function put(string $path, string $content, bool $overwrite = true) : bool;
public static function get(string $path) : string;
public static function size(string $path) : int;
public static function exists(string $path) : bool;
}

View File

@ -31,12 +31,8 @@ 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
@ -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

@ -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

@ -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.
*
@ -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.
*