Formatting and new implementations

This commit is contained in:
Dennis Eichhorn 2016-05-06 23:39:33 +02:00
parent e5de7328ce
commit 277e360159
12 changed files with 455 additions and 27 deletions

View File

@ -13,38 +13,76 @@
* @version 1.0.0
* @link http://orange-management.com
*/
/*
NOT IN USE
Will be implemented later
*/
/* TODO: implement */
namespace phpOMS\DataStorage\Cookie;
/**
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* CookieJar class
*
* @category Framework
* @package phpOMS\Utils
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class CookieJar
{
/**
* Cookie values.
*
* @var array
* @since 1.0.0
*/
private $cookies = [];
/**
* Locked.
*
* @var bool
* @since 1.0.0
*/
private static $isLocked = false;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->cookies = $_COOKIE;
}
public function set($id, $value, int $expiry = 86400, $path = '/', $domain = null, bool $secure = false, bool $httponly = true, bool $overwrite = true) : bool
/**
* Set pending cookie
*
* @param string $id Cookie id
* @param mixed $value Cookie value
* @param int $expire Expire time
* @param string $path Path
* @param string $domain Domain
* @param bool $secure Is secure
* @param bool $httpOnly Allow only http access
* @param bool $overwrite Overwrite if already set
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function set(string $id, $value, int $expire = 86400, string $path = '/', string $domain = null, bool $secure = false, bool $httpOnly = true, bool $overwrite = true) : bool
{
if ($overwrite || !isset($this->cookies[$id])) {
$this->cookies[$id] = [
'value' => $value,
'expiry' => $expiry,
'expiry' => $expire,
'path' => $path,
'domain' => $domain,
'secure' => $secure,
'httponly' => $httponly,
'httponly' => $httpOnly,
];
return true;
@ -53,7 +91,17 @@ class CookieJar
return false;
}
public function remove($id) : bool
/**
* Remove pending cookie
*
* @param string $id Cookie id to remove
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function remove(string $id) : bool
{
if (isset($this->cookies[$id])) {
unset($this->cookies[$id]);
@ -64,12 +112,28 @@ class CookieJar
return false;
}
public function delete($id) : bool
/**
* Delete already set cookie
*
* @param string $id Cookie id to remove
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function delete(string $id)
{
$this->remove($id);
setcookie($id, '', time() - 3600);
}
/**
* Save cookie
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function save()
{
if (self::$isLocked) {
@ -81,11 +145,25 @@ class CookieJar
}
}
/**
* Lock
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function lock()
{
self::$isLocked = true;
}
/**
* Is locked?
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isLocked() : bool
{
return self::$isLocked;

View File

@ -15,14 +15,38 @@
*/
namespace phpOMS\Math\Algebra;
class PointPolygonIntersection
/**
* Scheduler factory.
*
* @category Framework
* @package phpOMS\Utils\TaskSchedule
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
final class PointPolygonIntersection
{
/**
* Epsilon.
*
* @var float
* @since 1.0.0
*/
const EPSILON = 1E-6;
private function __construct()
{
}
/**
* Point polygon relative position
*
* @param array $point Point location
* @param array $vertices Vertice locations
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function pointInPolygon(array $point, array $vertices) : int
{
$length = count($vertices);
@ -70,7 +94,18 @@ class PointPolygonIntersection
return 1;
}
private static function isOnVertex($point, $vertices)
/**
* Is point on vertex?
*
* @param array $point Point location
* @param array $vertices Vertice locations
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function isOnVertex($point, $vertices) : bool
{
foreach ($vertices as $vertex) {
if (abs($point['x'] - $vertex['x']) < self::EPSILON && abs($point['y'] - $vertex['y']) < self::EPSILON) {

View File

@ -39,7 +39,7 @@ class Regression
*
* @return array
*
* @throws
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>

View File

@ -0,0 +1,111 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Geometry;
/**
* Andrew's monotone chain convex hull algorithm class.
*
* @category Framework
* @package phpOMS\Utils\TaskSchedule
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*
* @todo: implement vertice class or use vertice class used by graphs? May be usefull in order to give vertices IDs!
*/
final class MonotoneChain
{
/**
* Counter clock wise turn?
*
* @param array $a Point b
* @param array $b Point c
* @param array $c Point d
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function cross(array $a, array $b, array $c) : float
{
return ($b['x'] - $a['x']) * ($c['y'] - $a['y']) - ($b['y'] - $a['y']) * ($c['x'] - $a['x']);
}
/**
* Sort by x coordinate then by z coordinate
*
* @param array $a Point b
* @param array $b Point c
*
* @return float
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private static function sort(array $a, array $b) : float
{
return $a['x'] === $b['x'] ? $a['y'] - $b['y'] : $a['x'] - $b['x'];
}
/**
* Create convex hull
*
* @param array $points Points (Point Cloud)
*
* @return array
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function createConvexHull(array $points) : array
{
if (($n = count($points)) > 1) {
$k = 0;
$h = [];
uasort($points, [self::class, 'sort']);
// Lower hull
for ($i = 0; $i < $n; ++$i) {
while ($k >= 2 && self::cross($h[$k - 2], $h[$k - 1], $points[$i]) <= 0) {
$k--;
}
$h[$k++] = $points[$i];
}
// Upper hull
for ($i = $n - 2, $t = $k + 1; $i >= 0; $i--) {
while ($k >= $t && self::cross($h[$k - 2], $h[$k - 1], $points[$i]) <= 0) {
$k--;
}
$h[$k++] = $points[$i];
}
if ($k > 1) {
$h = array_splice($h, $k - 1);
}
return $h;
}
return $points;
}
}

0
Math/Matrix/Cholesky.php Normal file
View File

View File

@ -18,10 +18,10 @@ namespace phpOMS\Math\Matrix;
use phpOMS\Datatypes\Enum;
/**
* Account type enum.
* Inverse type enum.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @package phpOMS\Math\Matrix
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -1,8 +1,44 @@
<?php
use phpOMS\Math\Number\Prime;
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Number;
/**
* Integer class
*
* @category Framework
* @package phpOMS\Utils
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Integer
{
/**
* Is integer.
*
* @param mixed $value Value to test
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isInteger($value) : bool
{
return is_int($value);

View File

@ -1,7 +1,44 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Math\Number;
/**
* Natura number class
*
* @category Framework
* @package phpOMS\Utils
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class Natural
{
/**
* Is natural number.
*
* @param mixed $value Value to test
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function isNatural($value) : bool
{
return is_int($value) && $value >= 0;

View File

@ -1,8 +1,48 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
use phpOMS\Math\Matrix\Matrix;
/**
* Gaussian elimination class
*
* @category Framework
* @package phpOMS\Math\Matrix
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class GaussianElimination
{
private function swapRows(&$a, &$b, $r1, $r2)
/**
* Swap rows.
*
* @param array $a Matrix A
* @param array $b Vector b
* @param int $r1 Row 1
* @param int $r2 Row 2
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
private function swapRows(&$a, &$b, int $r1, int $r2)
{
if ($r1 == $r2) {
return;
@ -17,8 +57,23 @@ class GaussianElimination
$b[$r2] = $tmp;
}
public function solve(array $A, array $b, int $limit) : array
/**
* Solve equation with gaussian elimination.
*
* @param Matrix $A Matrix A
* @param Matrix $b Vector b
*
* @return Matrix
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function solve(Matrix $A, Matrix $b) : Matrix
{
$limit = min($A->getM(), $A->getN());
$A = $A->getMatrix();
$b = $b->getMatrix();
for ($col = 0; $col < $limit; $col++) {
$j = $col;
$max = $A[$j][$j];
@ -47,7 +102,6 @@ class GaussianElimination
}
$x = [];
for ($col = $limit - 1; $col >= 0; $col--) {
$tmp = $b[$col];
@ -58,6 +112,9 @@ class GaussianElimination
$x[$col] = $tmp / $A[$col][$col];
}
return $x;
$Y = new Matrix(count($x), 1);
$Y->setMatrix($x);
return $Y;
}
}

View File

@ -8,8 +8,9 @@ class Dijkstra
{
$vertices = [];
$neighbours = [];
$graphArray = $graph->getEdges();
foreach ($graph_array as $edge) {
foreach ($graphArray as $edge) {
array_push($vertices, $edge[0], $edge[1]);
$neighbours[$edge[0]][] = ["end" => $edge[1], "cost" => $edge[2]];
$neighbours[$edge[1]][] = ["end" => $edge[0], "cost" => $edge[2]];

View File

@ -1,12 +1,47 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\TaskSchedule;
use phpOMS\System\OperatingSystem;
use phpOMS\System\SystemType;
/**
* Scheduler factory.
*
* @category Framework
* @package phpOMS\Utils\TaskSchedule
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
final class SchedulerFactory
{
/**
* Create scheduler instance.
*
* @return ScheduleInterface
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create() : ScheduleInterface
{
switch (OperatingSystem::getSystem()) {

View File

@ -1,12 +1,50 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\Utils\TaskSchedule;
use phpOMS\System\OperatingSystem;
use phpOMS\System\SystemType;
/**
* Task factory.
*
* @category Framework
* @package phpOMS\Utils\TaskSchedule
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
final class TaskFactory
{
/**
* Create task instance.
*
* @param Interval $interval Task interval
* @param string $cmd Command to run
*
* @return TaskInterface
*
* @throws \Exception
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create(Interval $interval = null, string $cmd = '') : TaskInterface
{
switch (OperatingSystem::getSystem()) {