mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 01:38:41 +00:00
Formatting & bug fixes
This commit is contained in:
parent
292ac8d739
commit
ce182bab92
|
|
@ -422,7 +422,8 @@ class Account
|
|||
$this->lastActive = new \DateTime('NOW');
|
||||
}
|
||||
|
||||
public function setCreatedAt(\DateTime $created) {
|
||||
public function setCreatedAt(\DateTime $created)
|
||||
{
|
||||
$this->createdAt = $created;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,8 @@ class AccountManager implements \Countable
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function count() : int {
|
||||
public function count() : int
|
||||
{
|
||||
return count($this->accounts);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class AccountStatus extends Enum
|
||||
{
|
||||
const ACTIVE = 1;
|
||||
const ACTIVE = 1;
|
||||
const INACTIVE = 2;
|
||||
const TIMEOUT = 3;
|
||||
const BANNED = 4;
|
||||
const TIMEOUT = 3;
|
||||
const BANNED = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,6 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class AccountType extends Enum
|
||||
{
|
||||
const USER = 0;
|
||||
const USER = 0;
|
||||
const GROUP = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class AssetType extends Enum
|
||||
{
|
||||
const CSS = 'css';
|
||||
const JS = 'js';
|
||||
const CSS = 'css';
|
||||
const JS = 'js';
|
||||
const JSLATE = 'jslate';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,14 +32,14 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class LoginReturnType extends Enum
|
||||
{
|
||||
const OK = 0; /* Everything is ok and the user got authed */
|
||||
const FAILURE = 1; /* Authentication resulted in a unexpected failure */
|
||||
const WRONG_PASSWORD = 2; /* Authentication with wrong password */
|
||||
const WRONG_USERNAME = 3; /* Authentication with unknown user */
|
||||
const WRONG_PERMISSION = 4; /* User doesn't have permission to authenticate */
|
||||
const NOT_ACTIVATED = 5; /* The user is not activated yet */
|
||||
const OK = 0; /* Everything is ok and the user got authed */
|
||||
const FAILURE = 1; /* Authentication resulted in a unexpected failure */
|
||||
const WRONG_PASSWORD = 2; /* Authentication with wrong password */
|
||||
const WRONG_USERNAME = 3; /* Authentication with unknown user */
|
||||
const WRONG_PERMISSION = 4; /* User doesn't have permission to authenticate */
|
||||
const NOT_ACTIVATED = 5; /* The user is not activated yet */
|
||||
const WRONG_INPUT_EXCEEDED = 6; /* Too many wrong logins recently */
|
||||
const TIMEOUTED = 7; /* User received a timeout and can not log in until a certain date */
|
||||
const BANNED = 8; /* User is banned */
|
||||
const INACTIVE = 9; /* User is inactive */
|
||||
const TIMEOUTED = 7; /* User received a timeout and can not log in until a certain date */
|
||||
const BANNED = 8; /* User is banned */
|
||||
const INACTIVE = 9; /* User is inactive */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ interface OptionsInterface
|
|||
*
|
||||
* @param mixed $key Unique option key
|
||||
* @param mixed $value Option value
|
||||
* @param bool $overwrite Overwrite existing value
|
||||
* @param bool $overwrite Overwrite existing value
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
@ -59,7 +59,7 @@ interface OptionsInterface
|
|||
* Updating or adding settings.
|
||||
*
|
||||
* @param array $pair Key value pair
|
||||
* @param bool $overwrite Overwrite existing value
|
||||
* @param bool $overwrite Overwrite existing value
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ abstract class SettingsAbstract implements OptionsInterface
|
|||
/**
|
||||
* Set option by key.
|
||||
*
|
||||
* @param string[] $options Column values for filtering
|
||||
* @param bool $store Save this Setting immediately to database
|
||||
* @param string[] $options Column values for filtering
|
||||
* @param bool $store Save this Setting immediately to database
|
||||
*
|
||||
* @return mixed Option value
|
||||
*
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ class CommandManager implements \Countable
|
|||
* Attach new command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $callback Function callback
|
||||
* @param mixed $source Provider
|
||||
* @param mixed $callback Function callback
|
||||
* @param mixed $source Provider
|
||||
* @param bool $overwrite Overwrite existing
|
||||
*
|
||||
* @return bool
|
||||
|
|
@ -82,7 +82,7 @@ class CommandManager implements \Countable
|
|||
* Detach existing command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $source Provider
|
||||
* @param mixed $source Provider
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
@ -105,7 +105,7 @@ class CommandManager implements \Countable
|
|||
* Trigger command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $para Parameters to pass
|
||||
* @param mixed $para Parameters to pass
|
||||
*
|
||||
* @return mixed|bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ interface CacheInterface
|
|||
* @param mixed $key Unique cache key
|
||||
* @param mixed $value Cache value
|
||||
* @param CacheStatus $type Cache type
|
||||
* @param int $expire Valid duration (in s)
|
||||
* @param int $expire Valid duration (in s)
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -50,7 +50,7 @@ interface CacheInterface
|
|||
* @param mixed $key Unique cache key
|
||||
* @param mixed $value Cache value
|
||||
* @param CacheStatus $type Cache type
|
||||
* @param int $expire Valid duration (in s)
|
||||
* @param int $expire Valid duration (in s)
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class CacheStatus extends Enum
|
||||
{
|
||||
const INACTIVE = 0; /* Caching is disabled */
|
||||
const ERROR = 1; /* Caching failed */
|
||||
const MEMCACHE = 2; /* Caching OK */
|
||||
const FILECACHE = 3; /* Caching OK */
|
||||
const INACTIVE = 0; /* Caching is disabled */
|
||||
const ERROR = 1; /* Caching failed */
|
||||
const MEMCACHE = 2; /* Caching OK */
|
||||
const FILECACHE = 3; /* Caching OK */
|
||||
const REDISCACHE = 4; /* Caching OK */
|
||||
const WINCACHE = 5; /* Caching OK */
|
||||
const WINCACHE = 5; /* Caching OK */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ use phpOMS\Datatypes\Enum;
|
|||
abstract class CacheType extends Enum
|
||||
{
|
||||
const _NUMERIC = 0; /* Data is numeric */
|
||||
const _STRING = 1; /* Data is string */
|
||||
const _ARRAY = 2; /* Data is array */
|
||||
const _OBJECT = 3; /* Data is object */
|
||||
const _HEX = 4; /* Data is object */
|
||||
const _STRING = 1; /* Data is string */
|
||||
const _ARRAY = 2; /* Data is array */
|
||||
const _OBJECT = 3; /* Data is object */
|
||||
const _HEX = 4; /* Data is object */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ class MemCache implements CacheInterface
|
|||
*/
|
||||
public function stats() : array
|
||||
{
|
||||
/** @noinspection PhpMethodOrClassCallIsNotCaseSensitiveInspection */
|
||||
return $this->memc->getExtendedStats();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ class CookieJar
|
|||
if (self::$isLocked) {
|
||||
throw new \Exception('Already locked');
|
||||
}
|
||||
|
||||
|
||||
foreach ($this->cookies as $key => $cookie) {
|
||||
setcookie($key, $cookie['value'], $cookie['expiry'], $cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httponly']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function lock()
|
||||
public static function lock()
|
||||
{
|
||||
self::$isLocked = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database;
|
||||
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGrammar() : Grammar
|
||||
{
|
||||
if (!isset($this->grammar)) {
|
||||
|
|
|
|||
|
|
@ -262,7 +262,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
public function clear()
|
||||
{
|
||||
$this->fields = [];
|
||||
}
|
||||
|
||||
|
|
@ -305,7 +306,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
$query = new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->into(static::$table);
|
||||
->into(static::$table);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$properties = $reflectionClass->getProperties();
|
||||
|
|
@ -361,12 +362,12 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
$value = isset($value) ? json_encode($value) : '';
|
||||
} elseif ($column['type'] === 'Serializable') {
|
||||
$value = $value->serialize();
|
||||
} elseif(is_object($value)) {
|
||||
} elseif (is_object($value)) {
|
||||
$value = $value->getId();
|
||||
}
|
||||
|
||||
$query->insert($column['name'])
|
||||
->value($value, $column['type']);
|
||||
->value($value, $column['type']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -442,8 +443,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
/* is many->many */
|
||||
$relQuery = new Builder($this->db);
|
||||
$relQuery->prefix($this->db->getPrefix())
|
||||
->into(static::$hasMany[$pname]['table'])
|
||||
->insert(static::$hasMany[$pname]['src'], static::$hasMany[$pname]['dst']);
|
||||
->into(static::$hasMany[$pname]['table'])
|
||||
->insert(static::$hasMany[$pname]['src'], static::$hasMany[$pname]['dst']);
|
||||
|
||||
foreach ($objsIds as $key => $src) {
|
||||
$relQuery->values($src, $objId);
|
||||
|
|
@ -489,7 +490,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
$query = new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->into(static::$table);
|
||||
->into(static::$table);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
$properties = $reflectionClass->getProperties();
|
||||
|
|
@ -510,7 +511,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
$query->update($column['name'])
|
||||
->value($value);
|
||||
->value($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -551,7 +552,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
* Populate data.
|
||||
*
|
||||
* @param array $result Result set
|
||||
* @param mixed $obj Object to populate
|
||||
* @param mixed $obj Object to populate
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
@ -583,7 +584,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
* Is overwriting the hasOne id stored in the member variable by the object.
|
||||
* todo: hasMany needs to be implemented somehow?!?!
|
||||
*
|
||||
* @param $obj Object to add the relations to
|
||||
* @param $obj Object to add the relations to
|
||||
* @param int $relations Relations type
|
||||
*
|
||||
* @return mixed
|
||||
|
|
@ -740,7 +741,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
* Get object.
|
||||
*
|
||||
* @param mixed $primaryKey Key
|
||||
* @param int $relations Load relations
|
||||
* @param int $relations Load relations
|
||||
* @param mixed $fill Object to fill
|
||||
*
|
||||
* @return mixed
|
||||
|
|
@ -814,9 +815,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
*
|
||||
* This will fall back to the insert id if no datetime column is present.
|
||||
*
|
||||
* @param int $limit Newest limit
|
||||
* @param Builder $query Pre-defined query
|
||||
* @param int $relations Load relations
|
||||
* @param int $limit Newest limit
|
||||
* @param Builder $query Pre-defined query
|
||||
* @param int $relations Load relations
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
|
@ -827,9 +828,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
$query = $query ?? new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->limit($limit); /* todo: limit is not working, setting this to 2 doesn't have any effect!!! */
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->limit($limit); /* todo: limit is not working, setting this to 2 doesn't have any effect!!! */
|
||||
|
||||
if (!empty(static::$createdAt)) {
|
||||
$query->orderBy(static::$table . '.' . static::$columns[static::$createdAt]['name'], 'DESC');
|
||||
|
|
@ -841,7 +842,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
$sth->execute();
|
||||
|
||||
$results = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$obj = $this->populateIterable(is_bool($results) ? [] : $results);
|
||||
$obj = $this->populateIterable(is_bool($results) ? [] : $results);
|
||||
|
||||
$this->fillRelations($obj, $relations);
|
||||
$this->clear();
|
||||
|
|
@ -853,8 +854,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Get all by custom query.
|
||||
*
|
||||
* @param Builder $query Query
|
||||
* @param bool $relations Relations
|
||||
* @param Builder $query Query
|
||||
* @param bool $relations Relations
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -886,7 +887,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getRandom(int $relations = RelationType::ALL)
|
||||
public function getRandom(int $relations = RelationType::ALL)
|
||||
{
|
||||
// todo: implement
|
||||
}
|
||||
|
|
@ -894,15 +895,15 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Fill object with relations
|
||||
*
|
||||
* @param mixed $obj Objects to fill
|
||||
* @param int $relations Relations type
|
||||
* @param mixed $obj Objects to fill
|
||||
* @param int $relations Relations type
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function fillRelations(array &$obj, int $relations = RelationType::ALL)
|
||||
public function fillRelations(array &$obj, int $relations = RelationType::ALL)
|
||||
{
|
||||
$hasMany = count(static::$hasMany) > 0;
|
||||
$hasOne = count(static::$hasOne) > 0;
|
||||
|
|
@ -942,9 +943,9 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
$query = new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->where(static::$table . '.' . static::$primaryField, '=', $primaryKey);
|
||||
->select('*')
|
||||
->from(static::$table)
|
||||
->where(static::$table . '.' . static::$primaryField, '=', $primaryKey);
|
||||
|
||||
$sth = $this->db->con->prepare($query->toSql());
|
||||
$sth->execute();
|
||||
|
|
@ -968,8 +969,8 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
$query = new Builder($this->db);
|
||||
$query->prefix($this->db->getPrefix())
|
||||
->select('*')
|
||||
->from(static::$table);
|
||||
->select('*')
|
||||
->from(static::$table);
|
||||
|
||||
$sth = $this->db->con->prepare($query->toSql());
|
||||
$sth->execute();
|
||||
|
|
@ -983,7 +984,7 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
* Get raw by primary key
|
||||
*
|
||||
* @param mixed $primaryKey Primary key
|
||||
* @param int $relations Load relations
|
||||
* @param int $relations Load relations
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -1001,27 +1002,27 @@ abstract class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
if ($relations === RelationType::ALL) {
|
||||
$query->select($value['table'] . '.' . $value['src'])
|
||||
->from($value['table'])
|
||||
->where($value['table'] . '.' . $value['dst'], '=', $primaryKey);
|
||||
->from($value['table'])
|
||||
->where($value['table'] . '.' . $value['dst'], '=', $primaryKey);
|
||||
} elseif ($relations === RelationType::NEWEST) {
|
||||
|
||||
/*
|
||||
SELECT c.*, p1.*
|
||||
FROM customer c
|
||||
JOIN purchase p1 ON (c.id = p1.customer_id)
|
||||
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND
|
||||
(p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id))
|
||||
WHERE p2.id IS NULL;
|
||||
*/
|
||||
/*
|
||||
$query->select(static::$table . '.' . static::$primaryField, $value['table'] . '.' . $value['src'])
|
||||
->from(static::$table)
|
||||
->join($value['table'])
|
||||
->on(static::$table . '.' . static::$primaryField, '=', $value['table'] . '.' . $value['dst'])
|
||||
->leftOuterJoin($value['table'])
|
||||
->on(new And('1', new And(new Or('d1', 'd2'), 'id')))
|
||||
->where($value['table'] . '.' . $value['dst'], '=', 'NULL');
|
||||
*/
|
||||
/*
|
||||
SELECT c.*, p1.*
|
||||
FROM customer c
|
||||
JOIN purchase p1 ON (c.id = p1.customer_id)
|
||||
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND
|
||||
(p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id))
|
||||
WHERE p2.id IS NULL;
|
||||
*/
|
||||
/*
|
||||
$query->select(static::$table . '.' . static::$primaryField, $value['table'] . '.' . $value['src'])
|
||||
->from(static::$table)
|
||||
->join($value['table'])
|
||||
->on(static::$table . '.' . static::$primaryField, '=', $value['table'] . '.' . $value['dst'])
|
||||
->leftOuterJoin($value['table'])
|
||||
->on(new And('1', new And(new Or('d1', 'd2'), 'id')))
|
||||
->where($value['table'] . '.' . $value['dst'], '=', 'NULL');
|
||||
*/
|
||||
}
|
||||
|
||||
$sth = $this->db->con->prepare($query->toSql());
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class DatabaseExceptionFactory
|
|||
*/
|
||||
public static function create(\PDOException $e) : \PDOException
|
||||
{
|
||||
switch($e->getCode()) {
|
||||
switch ($e->getCode()) {
|
||||
case '42S02':
|
||||
return self::createTableViewException($e);
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class DatabaseStatus extends Enum
|
||||
{
|
||||
const OK = 0; /* Database connection successful */
|
||||
const OK = 0; /* Database connection successful */
|
||||
const MISSING_DATABASE = 1; /* Couldn't find database */
|
||||
const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
||||
const FAILURE = 3; /* Unknown failure */
|
||||
const READONLY = 4; /* Database connection is in readonly (but ok) */
|
||||
const CLOSED = 5; /* Database connection closed */
|
||||
const MISSING_TABLE = 2; /* One of the core tables couldn't be found */
|
||||
const FAILURE = 3; /* Unknown failure */
|
||||
const READONLY = 4; /* Database connection is in readonly (but ok) */
|
||||
const CLOSED = 5; /* Database connection closed */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,9 +32,9 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class DatabaseType extends Enum
|
||||
{
|
||||
const MYSQL = 0; /* MySQL */
|
||||
const MYSQL = 0; /* MySQL */
|
||||
const SQLITE = 1; /* SQLITE */
|
||||
const PGSQL = 2; /* PostgreSQL */
|
||||
const PGSQL = 2; /* PostgreSQL */
|
||||
const ORACLE = 3; /* Oracle */
|
||||
const SQLSRV = 4; /* Microsoft SQL Server */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ abstract class GrammarAbstract
|
|||
implode(' ',
|
||||
array_filter(
|
||||
$this->compileComponents($query),
|
||||
function($value) {
|
||||
function ($value) {
|
||||
return (string) $value !== '';
|
||||
}
|
||||
)
|
||||
|
|
@ -102,7 +102,7 @@ abstract class GrammarAbstract
|
|||
/**
|
||||
* Expressionize elements.
|
||||
*
|
||||
* @param array $elements Elements
|
||||
* @param array $elements Elements
|
||||
* @param string $prefix Prefix for table
|
||||
*
|
||||
* @return string
|
||||
|
|
|
|||
|
|
@ -382,7 +382,7 @@ class Builder extends BuilderAbstract
|
|||
*
|
||||
* @param string|array|\Closure $columns Columns
|
||||
* @param string|array $operator Operator
|
||||
* @param mixed $values Values
|
||||
* @param mixed $values Values
|
||||
* @param string|array $boolean Boolean condition
|
||||
*
|
||||
* @return Builder
|
||||
|
|
@ -429,7 +429,7 @@ class Builder extends BuilderAbstract
|
|||
* Where in.
|
||||
*
|
||||
* @param string|array|\Closure $column Column
|
||||
* @param mixed $values Values
|
||||
* @param mixed $values Values
|
||||
* @param string $boolean Boolean condition
|
||||
*
|
||||
* @return Builder
|
||||
|
|
@ -717,8 +717,8 @@ class Builder extends BuilderAbstract
|
|||
/**
|
||||
* Values to insert.
|
||||
*
|
||||
* @param mixed $value Values
|
||||
* @param string $type Data type to insert
|
||||
* @param mixed $value Values
|
||||
* @param string $type Data type to insert
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ class Grammar extends GrammarAbstract
|
|||
*
|
||||
* @param Builder $query Builder
|
||||
* @param array $wheres Where elmenets
|
||||
* @param bool $first Is first element (usefull for nesting)
|
||||
* @param bool $first Is first element (usefull for nesting)
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -222,7 +222,7 @@ class Grammar extends GrammarAbstract
|
|||
* Compile value.
|
||||
*
|
||||
* @param array|string|\Closure $value Value
|
||||
* @param string $prefix Prefix in case value is a table
|
||||
* @param string $prefix Prefix in case value is a table
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -262,7 +262,7 @@ class Grammar extends GrammarAbstract
|
|||
* Compile limit.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param int $limit Limit
|
||||
* @param int $limit Limit
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -278,7 +278,7 @@ class Grammar extends GrammarAbstract
|
|||
* Compile offset.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param int $offset Offset
|
||||
* @param int $offset Offset
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -361,7 +361,7 @@ class Grammar extends GrammarAbstract
|
|||
* Compile insert into table.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param string $table Table
|
||||
* @param string $table Table
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class JoinType extends Enum
|
||||
{
|
||||
const JOIN = 'JOIN';
|
||||
const LEFT_JOIN = 'LEFT JOIN';
|
||||
const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN';
|
||||
const LEFT_INNER_JOIN = 'LEFT INNER JOIN';
|
||||
const RIGHT_JOIN = 'RIGHT JOIN';
|
||||
const JOIN = 'JOIN';
|
||||
const LEFT_JOIN = 'LEFT JOIN';
|
||||
const LEFT_OUTER_JOIN = 'LEFT OUTER JOIN';
|
||||
const LEFT_INNER_JOIN = 'LEFT INNER JOIN';
|
||||
const RIGHT_JOIN = 'RIGHT JOIN';
|
||||
const RIGHT_OUTER_JOIN = 'RIGHT OUTER JOIN';
|
||||
const RIGHT_INNER_JOIN = 'RIGHT INNER JOIN';
|
||||
const OUTER_JOIN = 'OUTER JOIN';
|
||||
const INNER_JOIN = 'INNER JOIN';
|
||||
const CROSS_JOIN = 'CROSS JOIN';
|
||||
const FULL_OUTER_JOIN = 'FULL OUTER JOIN';
|
||||
const OUTER_JOIN = 'OUTER JOIN';
|
||||
const INNER_JOIN = 'INNER JOIN';
|
||||
const CROSS_JOIN = 'CROSS JOIN';
|
||||
const FULL_OUTER_JOIN = 'FULL OUTER JOIN';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,16 +47,16 @@ class TableException extends \PDOException
|
|||
{
|
||||
$pos1 = strpos($message, '\'');
|
||||
|
||||
if($pos1 === false) {
|
||||
if ($pos1 === false) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
$pos2 = strpos($message, '\'', $pos1+1);
|
||||
$pos2 = strpos($message, '\'', $pos1 + 1);
|
||||
|
||||
if($pos2 === false) {
|
||||
if ($pos2 === false) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
return substr($message, $pos1+1, $pos2-$pos1-1);
|
||||
return substr($message, $pos1 + 1, $pos2 - $pos1 - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,6 @@ abstract class QueryType extends Enum
|
|||
{
|
||||
const SELECT = 0;
|
||||
const CREATE = 1;
|
||||
const DROP = 2;
|
||||
const ALTER = 3;
|
||||
const DROP = 2;
|
||||
const ALTER = 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\DataStorage\Session;
|
||||
|
||||
use phpOMS\Uri\UriFactory;
|
||||
use phpOMS\Utils\RnG\StringUtils;
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ class HttpSession implements SessionInterface
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $liftetime Session life time
|
||||
* @param int $liftetime Session life time
|
||||
* @param string|int|bool $sid Session id
|
||||
*
|
||||
* @throws \Exception
|
||||
|
|
@ -73,7 +74,7 @@ class HttpSession implements SessionInterface
|
|||
session_set_cookie_params($liftetime, '/', null, false, true);
|
||||
session_start();
|
||||
$this->sessionData = $_SESSION;
|
||||
$_SESSION = null;
|
||||
$_SESSION = null;
|
||||
|
||||
$this->sid = session_id();
|
||||
$this->setCsrfProtection();
|
||||
|
|
@ -87,7 +88,7 @@ class HttpSession implements SessionInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function setCsrfProtection()
|
||||
private function setCsrfProtection()
|
||||
{
|
||||
$this->set('UID', 0, false);
|
||||
|
||||
|
|
@ -170,7 +171,7 @@ class HttpSession implements SessionInterface
|
|||
self::$isLocked = true;
|
||||
}
|
||||
|
||||
public static function isLocked()
|
||||
public static function isLocked()
|
||||
{
|
||||
return self::$isLocked;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ interface SessionInterface
|
|||
* Store session value by key.
|
||||
*
|
||||
* @param string|int $key Value key
|
||||
* @param mixed $value Value to store
|
||||
* @param bool $overwrite Overwrite existing values
|
||||
* @param mixed $value Value to store
|
||||
* @param bool $overwrite Overwrite existing values
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ namespace phpOMS\Datatypes;
|
|||
*/
|
||||
abstract class AddressType extends Enum
|
||||
{
|
||||
const HOME = 1;
|
||||
const HOME = 1;
|
||||
const BUSINESS = 2;
|
||||
const SHIPPING = 3;
|
||||
const BILLING = 4;
|
||||
const WORK = 5;
|
||||
const BILLING = 4;
|
||||
const WORK = 5;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ abstract class Enum
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getRandom()
|
||||
public static function getRandom()
|
||||
{
|
||||
$constants = self::getConstants();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ namespace phpOMS\Datatypes;
|
|||
*/
|
||||
abstract class PhoneType extends Enum
|
||||
{
|
||||
const HOME = 1;
|
||||
const HOME = 1;
|
||||
const BUSINESS = 2;
|
||||
const MOBILE = 3;
|
||||
const WORK = 4;
|
||||
const MOBILE = 3;
|
||||
const WORK = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class TagType extends Enum
|
||||
{
|
||||
const INPUT = 0; /* <input> */
|
||||
const BUTTON = 1; /* <button> */
|
||||
const LINK = 2; /* <a> */
|
||||
const INPUT = 0; /* <input> */
|
||||
const BUTTON = 1; /* <button> */
|
||||
const LINK = 2; /* <a> */
|
||||
const SYMMETRIC = 3; /* <span><div>... */
|
||||
const TEXTAREA = 4; /* <textarea> */
|
||||
const SELECT = 5; /* <select> */
|
||||
const LABEL = 6; /* <label> */
|
||||
const ULIST = 7; /* <ul> */
|
||||
const OLIST = 8; /* <ul> */
|
||||
const TEXTAREA = 4; /* <textarea> */
|
||||
const SELECT = 5; /* <select> */
|
||||
const LABEL = 6; /* <label> */
|
||||
const ULIST = 7; /* <ul> */
|
||||
const OLIST = 8; /* <ul> */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ use phpOMS\Validation\Validator;
|
|||
class FileLogger implements LoggerInterface
|
||||
{
|
||||
const MSG_BACKTRACE = '{datetime}; {level}; {ip}; {message}; {backtrace}';
|
||||
const MSG_FULL = '{datetime}; {level}; {ip}; {line}; {version}; {os}; {path}; {message}; {file}; {backtrace}';
|
||||
const MSG_SIMPLE = '{datetime}; {level}; {ip}; {message};';
|
||||
const MSG_FULL = '{datetime}; {level}; {ip}; {line}; {version}; {os}; {path}; {message}; {file}; {backtrace}';
|
||||
const MSG_SIMPLE = '{datetime}; {level}; {ip}; {message};';
|
||||
|
||||
/**
|
||||
* Timing array.
|
||||
|
|
@ -88,15 +88,15 @@ class FileLogger implements LoggerInterface
|
|||
*
|
||||
* Creates the logging object and overwrites all default values.
|
||||
*
|
||||
* @param string $lpath Path for logging
|
||||
* @param bool $verbose Verbose logging
|
||||
* @param string $lpath Path for logging
|
||||
* @param bool $verbose Verbose logging
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function __construct(string $lpath, bool $verbose = false)
|
||||
{
|
||||
$path = realpath($lpath);
|
||||
$path = realpath($lpath);
|
||||
self::$verbose = $verbose;
|
||||
|
||||
if ($path !== false && Validator::startsWith($path, ROOT_PATH) === false) {
|
||||
|
|
@ -262,12 +262,12 @@ class FileLogger implements LoggerInterface
|
|||
* @param array $a
|
||||
* @param array $b
|
||||
*
|
||||
* @return bool the comparison
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function orderSort($a, $b)
|
||||
private function orderSort($a, $b) : int
|
||||
{
|
||||
if ($a['time'] == $b['time']) {
|
||||
return 0;
|
||||
|
|
@ -297,7 +297,7 @@ class FileLogger implements LoggerInterface
|
|||
}
|
||||
|
||||
if (self::$verbose) {
|
||||
echo $message , "\n";
|
||||
echo $message, "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -628,7 +628,7 @@ class FileLogger implements LoggerInterface
|
|||
* Create console log.
|
||||
*
|
||||
* @param string $message Log message
|
||||
* @param bool $verbose Is verbose
|
||||
* @param bool $verbose Is verbose
|
||||
* @param array $context Context
|
||||
*
|
||||
* @return array
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ use phpOMS\Datatypes\Enum;
|
|||
abstract class LogLevel extends Enum
|
||||
{
|
||||
const EMERGENCY = 'emergency';
|
||||
const ALERT = 'alert';
|
||||
const CRITICAL = 'critical';
|
||||
const ERROR = 'error';
|
||||
const WARNING = 'warning';
|
||||
const NOTICE = 'notice';
|
||||
const INFO = 'info';
|
||||
const DEBUG = 'debug';
|
||||
const ALERT = 'alert';
|
||||
const CRITICAL = 'critical';
|
||||
const ERROR = 'error';
|
||||
const WARNING = 'warning';
|
||||
const NOTICE = 'notice';
|
||||
const INFO = 'info';
|
||||
const DEBUG = 'debug';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ interface LoggerInterface
|
|||
* System is unusable.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -46,7 +46,7 @@ interface LoggerInterface
|
|||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -58,7 +58,7 @@ interface LoggerInterface
|
|||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -69,7 +69,7 @@ interface LoggerInterface
|
|||
* be logged and monitored.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -82,7 +82,7 @@ interface LoggerInterface
|
|||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -92,7 +92,7 @@ interface LoggerInterface
|
|||
* Normal but significant events.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -104,7 +104,7 @@ interface LoggerInterface
|
|||
* Example: User logs in, SQL logs.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -114,7 +114,7 @@ interface LoggerInterface
|
|||
* Detailed debug information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
@ -125,7 +125,7 @@ interface LoggerInterface
|
|||
*
|
||||
* @param string $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @param array $context
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1005,7 +1005,7 @@ class FinanceFormulas
|
|||
/**
|
||||
* Net Present Value
|
||||
*
|
||||
* @param array $C Cash flow ($C[0] = initial investment)
|
||||
* @param array $C Cash flow ($C[0] = initial investment)
|
||||
* @param float $r Discount rate
|
||||
*
|
||||
* @return float
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Fibunacci
|
|||
{
|
||||
public static function isFibunacci(int $n)
|
||||
{
|
||||
return Functions::isSquare(5 * $n**2 + 4) || Functions::isSquare(5 * $n**2 - 4);
|
||||
return Functions::isSquare(5 * $n ** 2 + 4) || Functions::isSquare(5 * $n ** 2 - 4);
|
||||
}
|
||||
|
||||
public static function fibunacci(int $n, int $start = 1) : int
|
||||
|
|
@ -44,10 +44,10 @@ class Fibunacci
|
|||
|
||||
$old_1 = 0;
|
||||
$old_2 = $start;
|
||||
$fib = 0;
|
||||
$fib = 0;
|
||||
|
||||
for ($i = 4; $i < $n; $i++) {
|
||||
$fib = $old_1 + $old_2;
|
||||
$fib = $old_1 + $old_2;
|
||||
$old_1 = $old_2;
|
||||
$old_2 = $fib;
|
||||
}
|
||||
|
|
@ -57,6 +57,6 @@ class Fibunacci
|
|||
|
||||
public static function binet(int $n) : int
|
||||
{
|
||||
return (int) (((1 + sqrt(5))**$n - (1 - sqrt(5))**$n) / (2**$n * sqrt(5)));
|
||||
return (int) (((1 + sqrt(5)) ** $n - (1 - sqrt(5)) ** $n) / (2 ** $n * sqrt(5)));
|
||||
}
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ class Functions
|
|||
/**
|
||||
* Calculate inverse modular.
|
||||
*
|
||||
* @param int $a
|
||||
* @param int $a
|
||||
* @param int $n Modulo
|
||||
*
|
||||
* @return int
|
||||
|
|
@ -149,28 +149,29 @@ class Functions
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function invMod($a, $n) {
|
||||
public static function invMod($a, $n)
|
||||
{
|
||||
if ($n < 0) {
|
||||
$n = -$n;
|
||||
}
|
||||
|
||||
if ($a < 0) {
|
||||
if ($a < 0) {
|
||||
$a = $n - (-$a % $n);
|
||||
}
|
||||
|
||||
$t = 0;
|
||||
$nt = 1;
|
||||
$r = $n;
|
||||
$t = 0;
|
||||
$nt = 1;
|
||||
$r = $n;
|
||||
$nr = $a % $n;
|
||||
|
||||
while ($nr != 0) {
|
||||
$quot = (int) ($r / $nr);
|
||||
$tmp = $nt;
|
||||
$nt = $t - $quot * $nt;
|
||||
$t = $tmp;
|
||||
$tmp = $nr;
|
||||
$nr = $r - $quot * $nr;
|
||||
$r = $tmp;
|
||||
$tmp = $nt;
|
||||
$nt = $t - $quot * $nt;
|
||||
$t = $tmp;
|
||||
$tmp = $nr;
|
||||
$nr = $r - $quot * $nr;
|
||||
$r = $tmp;
|
||||
}
|
||||
|
||||
if ($r > 1) {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@
|
|||
|
||||
namespace phpOMS\Math\Matrix;
|
||||
|
||||
class IdentityMatrix extends Matrix {
|
||||
public function __constrcut(int $n)
|
||||
class IdentityMatrix extends Matrix
|
||||
{
|
||||
public function __constrcut(int $n)
|
||||
{
|
||||
$this->n = $n;
|
||||
$this->m = $n;
|
||||
|
||||
for($i = 0; $i < $n; $i++) {
|
||||
$this->matrix[$i] = array_fill(0, $n, 0);
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$this->matrix[$i] = array_fill(0, $n, 0);
|
||||
$this->matrix[$i][$i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace phpOMS\Math\Matrix;
|
||||
|
||||
class Matrix implements \ArrayAccess, \Iterator
|
||||
class Matrix implements \ArrayAccess, \Iterator
|
||||
{
|
||||
protected $matrix = [];
|
||||
|
||||
protected $n = 0;
|
||||
protected $m = 0;
|
||||
|
||||
public function __construct(int $m, int $n = 1)
|
||||
public function __construct(int $m, int $n = 1)
|
||||
{
|
||||
$this->n = $n;
|
||||
$this->m = $m;
|
||||
|
|
@ -17,7 +17,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
for ($i = 0; $i < $m; $i++) {
|
||||
$this->matrix[$i] = array_fill(0, $n, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setMatrix(array $matrix)
|
||||
{
|
||||
|
|
@ -71,8 +71,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
throw new \Exception('Dimension');
|
||||
}
|
||||
|
||||
$matrixArr = $matrix->getMatrix();
|
||||
$newMatrix = new Matrix($this->m, $nDim);
|
||||
$matrixArr = $matrix->getMatrix();
|
||||
$newMatrix = new Matrix($this->m, $nDim);
|
||||
$newMatrixArr = $newMatrix->getMatrix();
|
||||
|
||||
for ($i = 0; $i < $this->m; $i++) { // Row of $this
|
||||
|
|
@ -136,7 +136,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
throw new \Exception('Dimension');
|
||||
}
|
||||
|
||||
$matrixArr = $value->getMatrix();
|
||||
$matrixArr = $value->getMatrix();
|
||||
$newMatrixArr = $this->matrix;
|
||||
|
||||
foreach ($newMatrixArr as $i => $vector) {
|
||||
|
|
@ -167,17 +167,19 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
return $newMatrix;
|
||||
}
|
||||
|
||||
public function upperTriangular() : Matrix
|
||||
public function upperTriangular() : Matrix
|
||||
{
|
||||
$matrix = new Matrix($this->n, $this->n);
|
||||
|
||||
$matrixArr = $this->matrix;
|
||||
$matrix->setMatrix($this->upperTrianglize($matrixArr));
|
||||
$this->upperTrianglize($matrixArr);
|
||||
|
||||
$matrix->setMatrix($matrixArr);
|
||||
|
||||
return $matrix;
|
||||
}
|
||||
|
||||
public function lowerTriangular() : Matrix
|
||||
public function lowerTriangular() : Matrix
|
||||
{
|
||||
// todo: implement
|
||||
return new Matrix($this->m, $this->n);
|
||||
|
|
@ -191,9 +193,9 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
|
||||
switch ($algorithm) {
|
||||
case InversionType::GAUSS_JORDAN:
|
||||
return $this->inverseGaussJordan();
|
||||
return $this->inverseGaussJordan();
|
||||
default:
|
||||
throw new \Exception('');
|
||||
throw new \Exception('');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,9 +241,9 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
return $newMatrix;
|
||||
}
|
||||
|
||||
private function decompositionCholesky() : Matrix
|
||||
private function decompositionCholesky() : Matrix
|
||||
{
|
||||
$newMatrix = new Matrix($this->n, $this->n);
|
||||
$newMatrix = new Matrix($this->n, $this->n);
|
||||
$newMatrixArr = $newMatrix->getMatrix();
|
||||
|
||||
for ($i = 0; $i < $this->n; $i++) {
|
||||
|
|
@ -269,8 +271,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
for ($i = $mDim - 1; $i > 0; $i--) {
|
||||
if ($arr[$i - 1][0] < $arr[$i][0]) {
|
||||
for ($j = 0; $j < $nDim; $j++) {
|
||||
$temp = $arr[$i][$j];
|
||||
$arr[$i][$j] = $arr[$i - 1][$j];
|
||||
$temp = $arr[$i][$j];
|
||||
$arr[$i][$j] = $arr[$i - 1][$j];
|
||||
$arr[$i - 1][$j] = $temp;
|
||||
}
|
||||
}
|
||||
|
|
@ -294,36 +296,36 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
|
||||
private function upperTrianglize(array &$arr) : int
|
||||
{
|
||||
$n = count($arr);
|
||||
$n = count($arr);
|
||||
$sign = 1;
|
||||
|
||||
for ($i = 0; $i < $n; $i++) {
|
||||
$max = 0;
|
||||
|
||||
|
||||
for ($j = $i; $j < $n; $j++) {
|
||||
if (abs($arr[$j][$i]) > abs($arr[$max][$i])) {
|
||||
$max = $j;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($max) {
|
||||
$sign = -$sign;
|
||||
$temp = $arr[$i];
|
||||
$arr[$i] = $arr[$max];
|
||||
$sign = -$sign;
|
||||
$temp = $arr[$i];
|
||||
$arr[$i] = $arr[$max];
|
||||
$arr[$max] = $temp;
|
||||
}
|
||||
|
||||
|
||||
if (!$arr[$i][$i]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
for ($j = $i + 1; $j < $n; $j++) {
|
||||
$r = $arr[$j][$i] / $arr[$i][$i];
|
||||
|
||||
if (!$r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for ($c = $i; $c < $n; $c++) {
|
||||
$arr[$j][$c] -= $arr[$i][$c] * $r;
|
||||
}
|
||||
|
|
@ -331,7 +333,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
}
|
||||
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
|
||||
public function det()
|
||||
{
|
||||
|
|
@ -340,7 +342,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
}
|
||||
|
||||
$trianglize = $this->matrix;
|
||||
$prod = $this->upperTrianglize($trianglize);
|
||||
$prod = $this->upperTrianglize($trianglize);
|
||||
|
||||
for ($i = 0; $i < $this->n; $i++) {
|
||||
$prod *= $trianglize[$i][$i];
|
||||
|
|
@ -348,4 +350,122 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
|
||||
return $prod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current element
|
||||
* @link http://php.net/manual/en/iterator.current.php
|
||||
* @return mixed Can return any type.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
// TODO: Implement current() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Move forward to next element
|
||||
* @link http://php.net/manual/en/iterator.next.php
|
||||
* @return void Any returned value is ignored.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
// TODO: Implement next() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key of the current element
|
||||
* @link http://php.net/manual/en/iterator.key.php
|
||||
* @return mixed scalar on success, or null on failure.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
// TODO: Implement key() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current position is valid
|
||||
* @link http://php.net/manual/en/iterator.valid.php
|
||||
* @return boolean The return value will be casted to boolean and then evaluated.
|
||||
* Returns true on success or false on failure.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
// TODO: Implement valid() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the Iterator to the first element
|
||||
* @link http://php.net/manual/en/iterator.rewind.php
|
||||
* @return void Any returned value is ignored.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
// TODO: Implement rewind() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a offset exists
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetexists.php
|
||||
* @param mixed $offset <p>
|
||||
* An offset to check for.
|
||||
* </p>
|
||||
* @return boolean true on success or false on failure.
|
||||
* </p>
|
||||
* <p>
|
||||
* The return value will be casted to boolean if non-boolean was returned.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
// TODO: Implement offsetExists() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to retrieve
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetget.php
|
||||
* @param mixed $offset <p>
|
||||
* The offset to retrieve.
|
||||
* </p>
|
||||
* @return mixed Can return all value types.
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
// TODO: Implement offsetGet() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to set
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetset.php
|
||||
* @param mixed $offset <p>
|
||||
* The offset to assign the value to.
|
||||
* </p>
|
||||
* @param mixed $value <p>
|
||||
* The value to set.
|
||||
* </p>
|
||||
* @return void
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
// TODO: Implement offsetSet() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Offset to unset
|
||||
* @link http://php.net/manual/en/arrayaccess.offsetunset.php
|
||||
* @param mixed $offset <p>
|
||||
* The offset to unset.
|
||||
* </p>
|
||||
* @return void
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
// TODO: Implement offsetUnset() method.
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace phpOMS\Math\Matrix;
|
||||
|
||||
class Vector extends Matrix {
|
||||
public function __construct(int $m)
|
||||
class Vector extends Matrix
|
||||
{
|
||||
public function __construct(int $m)
|
||||
{
|
||||
parent::__construct($m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
use phpOMS\Math\Number\Prime;
|
||||
|
||||
class Integer implements Number
|
||||
class Integer
|
||||
{
|
||||
public static function isInteger($value) : bool
|
||||
{
|
||||
return is_int($value);
|
||||
}
|
||||
public static function isInteger($value) : bool
|
||||
{
|
||||
return is_int($value);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Greatest common diviser.
|
||||
*
|
||||
* @param int $n Number one
|
||||
|
|
@ -24,68 +24,69 @@ class Integer implements Number
|
|||
while (true) {
|
||||
if ($n === $m) {
|
||||
return $m;
|
||||
} if ($n > $m) {
|
||||
}
|
||||
if ($n > $m) {
|
||||
$n -= $m;
|
||||
} else {
|
||||
$m -= $n;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static function trialFactorization(int $value)
|
||||
{
|
||||
if ($value < 2) {
|
||||
return [];
|
||||
}
|
||||
public static function trialFactorization(int $value)
|
||||
{
|
||||
if ($value < 2) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$factors = [];
|
||||
$primes = Prime::sieveOfEratosthenes((int) $value**0.5);
|
||||
$factors = [];
|
||||
$primes = Prime::sieveOfEratosthenes((int) $value ** 0.5);
|
||||
|
||||
foreach($primes as $prime) {
|
||||
if($prime*$prime > $value) {
|
||||
break;
|
||||
}
|
||||
foreach ($primes as $prime) {
|
||||
if ($prime * $prime > $value) {
|
||||
break;
|
||||
}
|
||||
|
||||
while($value%$prime === 0) {
|
||||
$factors[] = $prime;
|
||||
$value /= $prime;
|
||||
}
|
||||
}
|
||||
while ($value % $prime === 0) {
|
||||
$factors[] = $prime;
|
||||
$value /= $prime;
|
||||
}
|
||||
}
|
||||
|
||||
if($value > 1) {
|
||||
$factors[] = $value;
|
||||
}
|
||||
if ($value > 1) {
|
||||
$factors[] = $value;
|
||||
}
|
||||
|
||||
return $factors;
|
||||
}
|
||||
return $factors;
|
||||
}
|
||||
|
||||
public static function pollardsRho($value, $x = 2, $factor = 1, $cycleSize = 2, $xFixed = 2)
|
||||
{
|
||||
while($factor === 1) {
|
||||
for($i = 1; $i < $cycleSize && $factor <= 1; $i++) {
|
||||
$x = ($x*$x+1)%$value;
|
||||
$factor = self::greatestCommonDivisor($x-$xFixed, $value);
|
||||
}
|
||||
public static function pollardsRho($value, $x = 2, $factor = 1, $cycleSize = 2, $xFixed = 2)
|
||||
{
|
||||
while ($factor === 1) {
|
||||
for ($i = 1; $i < $cycleSize && $factor <= 1; $i++) {
|
||||
$x = ($x * $x + 1) % $value;
|
||||
$factor = self::greatestCommonDivisor($x - $xFixed, $value);
|
||||
}
|
||||
|
||||
$cycleSize *= 2;
|
||||
$xFixed = $x;
|
||||
}
|
||||
$cycleSize *= 2;
|
||||
$xFixed = $x;
|
||||
}
|
||||
|
||||
return $factor;
|
||||
}
|
||||
return $factor;
|
||||
}
|
||||
|
||||
public static function fermatFactor(int $value)
|
||||
{
|
||||
$a = $value;
|
||||
$b2 = $a*$a - $value;
|
||||
public static function fermatFactor(int $value)
|
||||
{
|
||||
$a = $value;
|
||||
$b2 = $a * $a - $value;
|
||||
|
||||
while(abs((int) round(sqrt($b2), 0) - sqrt($b2)) > 0.0001) {
|
||||
$a += 1;
|
||||
$b2 = $a*$a - $value;
|
||||
}
|
||||
while (abs((int) round(sqrt($b2), 0) - sqrt($b2)) > 0.0001) {
|
||||
$a += 1;
|
||||
$b2 = $a * $a - $value;
|
||||
}
|
||||
|
||||
return $a - sqrt($b2);
|
||||
}
|
||||
return $a - sqrt($b2);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
class Natural implements Number
|
||||
class Natural
|
||||
{
|
||||
public static function isNatural($value) : bool
|
||||
{
|
||||
return is_int($value) && $value >= 0;
|
||||
}
|
||||
public static function isNatural($value) : bool
|
||||
{
|
||||
return is_int($value) && $value >= 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
class Number {
|
||||
public static function getType($number) {
|
||||
<?php
|
||||
|
||||
}
|
||||
class Number
|
||||
{
|
||||
public static function getType($number)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
interface NumberInterface {
|
||||
public function add($number);
|
||||
public function sub($number);
|
||||
public function mult($number);
|
||||
public function div($number);
|
||||
public function pow($p);
|
||||
public function abs($number);
|
||||
}
|
||||
|
|
@ -62,15 +62,15 @@ class Numbers
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public static function selfdescribing(int $n) : bool
|
||||
public static function selfdescribing(int $n) : bool
|
||||
{
|
||||
$split = str_split($n);
|
||||
foreach ($split as $place => $value) {
|
||||
if (substr_count($n, $place) != $value) {
|
||||
if (substr_count($n, $place) != $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
16
Math/Number/OpperationInterface.php
Normal file
16
Math/Number/OpperationInterface.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
interface NumberInterface
|
||||
{
|
||||
public function add($number);
|
||||
|
||||
public function sub($number);
|
||||
|
||||
public function mult($number);
|
||||
|
||||
public function div($number);
|
||||
|
||||
public function pow($p);
|
||||
|
||||
public function abs($number);
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ class Prime
|
|||
*/
|
||||
public static function mersenne(int $p) : int
|
||||
{
|
||||
return 2**$p - 1;
|
||||
return 2 ** $p - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,24 +81,24 @@ class Prime
|
|||
if ($n < 2 || $n % 2 == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$d = $n - 1;
|
||||
$s = 0;
|
||||
|
||||
|
||||
while ($d % 2 == 0) {
|
||||
$d /= 2;
|
||||
$s++;
|
||||
}
|
||||
|
||||
|
||||
for ($i = 0; $i < $k; $i++) {
|
||||
$a = mt_rand(2, $n - 1);
|
||||
|
||||
|
||||
$x = bcpowmod($a, $d, $n);
|
||||
|
||||
if ($x == 1 || $x == $n - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for ($j = 1; $j < $s; $j++) {
|
||||
$x = bcmod(bcmul($x, $x), $n);
|
||||
|
||||
|
|
@ -120,10 +120,10 @@ class Prime
|
|||
public static function sieveOfEratosthenes(int $n) : array
|
||||
{
|
||||
$number = 2;
|
||||
$range = range(2, $n);
|
||||
$range = range(2, $n);
|
||||
$primes = array_combine($range, $range);
|
||||
|
||||
while ($number*$number < $n) {
|
||||
|
||||
while ($number * $number < $n) {
|
||||
for ($i = $number; $i <= $n; $i += $number) {
|
||||
if ($i == $number) {
|
||||
continue;
|
||||
|
|
@ -141,11 +141,11 @@ class Prime
|
|||
public function isPrime(int $n) : bool
|
||||
{
|
||||
$i = 2;
|
||||
|
||||
|
||||
if ($n === 2) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$sqrtN = sqrt($n);
|
||||
while ($i <= $sqrtN) {
|
||||
if ($n % $i === 0) {
|
||||
|
|
@ -154,7 +154,7 @@ class Prime
|
|||
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,39 @@
|
|||
<?php
|
||||
|
||||
class GaussianElimination
|
||||
class GaussianElimination
|
||||
{
|
||||
private function swapRows(&$a, &$b, $r1, $r2)
|
||||
{
|
||||
if ($r1 == $r2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tmp = $a[$r1];
|
||||
|
||||
$tmp = $a[$r1];
|
||||
$a[$r1] = $a[$r2];
|
||||
$a[$r2] = $tmp;
|
||||
|
||||
$tmp = $b[$r1];
|
||||
|
||||
$tmp = $b[$r1];
|
||||
$b[$r1] = $b[$r2];
|
||||
$b[$r2] = $tmp;
|
||||
}
|
||||
|
||||
|
||||
public function solve(array $A, array $b, int $limit) : array
|
||||
{
|
||||
for ($col = 0; $col < $limit; $col++) {
|
||||
$j = $col;
|
||||
$j = $col;
|
||||
$max = $A[$j][$j];
|
||||
|
||||
|
||||
for ($i = $col + 1; $i < $limit; $i++) {
|
||||
$tmp = abs($A[$i][$col]);
|
||||
|
||||
if ($tmp > $max) {
|
||||
$j = $i;
|
||||
$j = $i;
|
||||
$max = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->swapRows($A, $b, $col, $j);
|
||||
|
||||
|
||||
for ($i = $col + 1; $i < $limit; $i++) {
|
||||
$tmp = $A[$i][$col] / $A[$col][$col];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace phpOMS\Math\Optimization\Graph;
|
||||
|
||||
class Dijkstra {
|
||||
public static function dijkstra(Graph $graph, $source, $target) {
|
||||
$vertices = [];
|
||||
class Dijkstra
|
||||
{
|
||||
public static function dijkstra(Graph $graph, $source, $target)
|
||||
{
|
||||
$vertices = [];
|
||||
$neighbours = [];
|
||||
|
||||
foreach ($graph_array as $edge) {
|
||||
|
|
@ -14,41 +16,41 @@ class Dijkstra {
|
|||
}
|
||||
|
||||
$vertices = array_unique($vertices);
|
||||
|
||||
$dist = [];
|
||||
|
||||
$dist = [];
|
||||
$previous = [];
|
||||
foreach ($vertices as $vertex) {
|
||||
$dist[$vertex] = INF;
|
||||
$previous[$vertex] = NULL;
|
||||
$dist[$vertex] = INF;
|
||||
$previous[$vertex] = null;
|
||||
}
|
||||
|
||||
|
||||
$dist[$source] = 0;
|
||||
$Q = $vertices;
|
||||
$Q = $vertices;
|
||||
|
||||
while (count($Q) > 0) {
|
||||
|
||||
|
||||
// TODO - Find faster way to get minimum
|
||||
$min = INF;
|
||||
|
||||
foreach ($Q as $vertex){
|
||||
foreach ($Q as $vertex) {
|
||||
if ($dist[$vertex] < $min) {
|
||||
$min = $dist[$vertex];
|
||||
$u = $vertex;
|
||||
$u = $vertex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$Q = array_diff($Q, [$u]);
|
||||
|
||||
if ($dist[$u] == INF || $u == $target) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isset($neighbours[$u])) {
|
||||
foreach ($neighbours[$u] as $arr) {
|
||||
$alt = $dist[$u] + $arr["cost"];
|
||||
|
||||
if ($alt < $dist[$arr["end"]]) {
|
||||
$dist[$arr["end"]] = $alt;
|
||||
$dist[$arr["end"]] = $alt;
|
||||
$previous[$arr["end"]] = $u;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +58,7 @@ class Dijkstra {
|
|||
}
|
||||
|
||||
$path = [];
|
||||
$u = $target;
|
||||
$u = $target;
|
||||
|
||||
while (isset($previous[$u])) {
|
||||
array_unshift($path, $u);
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace phpOMS\Math\Optimization\Graph;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface EdgeInterface
|
||||
interface EdgeInterface
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Get edge id.
|
||||
*
|
||||
* @return mixed
|
||||
|
|
@ -36,9 +36,9 @@ interface EdgeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getId();
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get edge weight.
|
||||
*
|
||||
* @return mixed
|
||||
|
|
@ -46,9 +46,9 @@ interface EdgeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getWeight();
|
||||
public function getWeight();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set weight.
|
||||
*
|
||||
* @param mixed $weight Weight of edge
|
||||
|
|
@ -56,9 +56,9 @@ interface EdgeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setWeight($weight);
|
||||
public function setWeight($weight);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get vertices.
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -66,9 +66,9 @@ interface EdgeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getVertices() : array;
|
||||
public function getVertices() : array;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Set vertices.
|
||||
*
|
||||
* @param VerticeInterface $a Vertice a
|
||||
|
|
@ -77,5 +77,5 @@ interface EdgeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setVertices(VerticeInterface $a, VerticeInterface $b);
|
||||
public function setVertices(VerticeInterface $a, VerticeInterface $b);
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Math\Optimization\Graph;
|
||||
|
||||
use phpOMS\Stdlib\Map\KeyType;
|
||||
use phpOMS\Stdlib\Map\MultiMap;
|
||||
use phpOMS\Stdlib\Map\OrderType;
|
||||
|
|
@ -53,7 +54,7 @@ class Graph
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
$this->edges = new MultiMap(KeyType::MULTIPLE, OrderType::LOOSE);
|
||||
}
|
||||
|
|
@ -89,7 +90,7 @@ class Graph
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addEdge(EdgeInterface $edge) : bool
|
||||
public function addEdge(EdgeInterface $edge) : bool
|
||||
{
|
||||
if (!isset($this->edges[$edge->getId()])) {
|
||||
$this->edges[$edge->getId()] = $edge;
|
||||
|
|
@ -149,8 +150,8 @@ class Graph
|
|||
*/
|
||||
public function removeEdgeById($id) : bool
|
||||
{
|
||||
if (isset($this->edge[$id])) {
|
||||
unset($this->edge[$id]);
|
||||
if (isset($this->edges[$id])) {
|
||||
unset($this->edges[$id]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ class Graph
|
|||
*/
|
||||
public function getEdgeById(int $id) : EdgeInterface
|
||||
{
|
||||
return $this->edges->get([$a, $b]) ?? new NullEdge();
|
||||
return $this->edges->get($id) ?? new NullEdge();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -214,7 +215,7 @@ class Graph
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function countVertices() : int
|
||||
public function countVertices() : int
|
||||
{
|
||||
return count($this->vertices);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<?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\Optimization\Graph;
|
||||
|
||||
|
||||
/**
|
||||
* Graph class
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Asset
|
||||
* @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 NullEdge
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?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\Optimization\Graph;
|
||||
|
||||
|
||||
/**
|
||||
* Graph class
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Asset
|
||||
* @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 NullVertice
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -26,9 +26,9 @@ namespace phpOMS\Math\Optimization\Graph;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
interface VerticeInterface
|
||||
interface VerticeInterface
|
||||
{
|
||||
/**
|
||||
/**
|
||||
* Get vertice id.
|
||||
*
|
||||
* @return mixed
|
||||
|
|
@ -36,9 +36,9 @@ interface VerticeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getId();
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get edges.
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -46,9 +46,9 @@ interface VerticeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getEdges() : array;
|
||||
public function getEdges() : array;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add edge.
|
||||
*
|
||||
* @param EdgeInterface $edge Edge to add to vertice
|
||||
|
|
@ -58,5 +58,5 @@ interface VerticeInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addEdge(EdgeInterface $edge) : bool;
|
||||
public function addEdge(EdgeInterface $edge) : bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,8 +131,8 @@ class Tour implements \Countable
|
|||
/**
|
||||
* Set city
|
||||
*
|
||||
* @param int $index Index to set/replace
|
||||
* @param City $city City
|
||||
* @param int $index Index to set/replace
|
||||
* @param City $city City
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
namespace phpOMS\Math\Shape\D2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Polygon class.
|
||||
*
|
||||
|
|
@ -133,7 +132,7 @@ class Polygon implements ShapeInterface
|
|||
/**
|
||||
* Set polygon coordinate.
|
||||
*
|
||||
* @param int $i Index
|
||||
* @param int $i Index
|
||||
* @param int|float $x X coordinate
|
||||
* @param int|float $y Y coordinate
|
||||
*
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ class Average
|
|||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param int $offset Offset for outlier
|
||||
* @param int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -148,7 +148,7 @@ class Average
|
|||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param int $offset Offset for outlier
|
||||
* @param int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -180,7 +180,7 @@ class Average
|
|||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $values Values
|
||||
* @param int $offset Offset for outlier
|
||||
* @param int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -217,7 +217,7 @@ class Average
|
|||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $angles Angles
|
||||
* @param int $offset Offset for outlier
|
||||
* @param int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
@ -290,8 +290,8 @@ class Average
|
|||
*/
|
||||
public static function angleToTime(float $angle) : string
|
||||
{
|
||||
$sec = 86400.0 * $angle / 360.0;
|
||||
$time = sprintf('%02d:%02d:%02d', floor($sec / 3600), floor(($sec % 3600) / 60), $sec % 60);
|
||||
$sec = 86400.0 * $angle / 360.0;
|
||||
$time = sprintf('%02d:%02d:%02d', floor($sec / 3600), floor(($sec % 3600) / 60), $sec % 60);
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
|
@ -302,7 +302,7 @@ class Average
|
|||
* Example: ([1, 2, 2, 3, 4, 4, 2])
|
||||
*
|
||||
* @param array $angles Angles
|
||||
* @param int $offset Offset for outlier
|
||||
* @param int $offset Offset for outlier
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class GeometricDistribution
|
|||
*/
|
||||
public static function getSkewness(float $lambda) : float
|
||||
{
|
||||
return (2 - $p) / sqrt(1 - $p);
|
||||
return (2 - $lambda) / sqrt(1 - $lambda);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -166,7 +166,7 @@ class GeometricDistribution
|
|||
*/
|
||||
public static function getExKurtosis(float $lambda) : float
|
||||
{
|
||||
return 6 + $p ** 2 / (1 - $p);
|
||||
return 6 + $lambda ** 2 / (1 - $lambda);
|
||||
}
|
||||
|
||||
public static function getRandom()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
namespace phpOMS\Math\Stochastic\Distribution;
|
||||
|
||||
use phpOMS\Math\Functions;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class UniformDistributionDiscrete
|
|||
* Get probability mass function.
|
||||
*
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
* @param float $b
|
||||
*
|
||||
* @return float
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Message;
|
||||
|
||||
use phpOMS\DataStorage\Cookie\CookieJar;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
|
|
@ -41,9 +42,9 @@ abstract class HeaderAbstract
|
|||
/**
|
||||
* Set header.
|
||||
*
|
||||
* @param string $key Header key
|
||||
* @param string $value Header value
|
||||
* @param bool $overwrite Overwrite if key already exists
|
||||
* @param string $key Header key
|
||||
* @param string $value Header value
|
||||
* @param bool $overwrite Overwrite if key already exists
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
|
|
|
|||
|
|
@ -32,15 +32,15 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class BrowserType extends Enum
|
||||
{
|
||||
const IE = 'msie'; /* Internet Explorer */
|
||||
const EDGE = 'edge'; /* Internet Explorer Edge 20+ */
|
||||
const FIREFOX = 'firefox'; /* Firefox */
|
||||
const SAFARI = 'safari'; /* Safari */
|
||||
const CHROME = 'chrome'; /* Chrome */
|
||||
const OPERA = 'opera'; /* Opera */
|
||||
const NETSCAPE = 'netscape'; /* Netscape */
|
||||
const MAXTHON = 'maxthon'; /* Maxthon */
|
||||
const IE = 'msie'; /* Internet Explorer */
|
||||
const EDGE = 'edge'; /* Internet Explorer Edge 20+ */
|
||||
const FIREFOX = 'firefox'; /* Firefox */
|
||||
const SAFARI = 'safari'; /* Safari */
|
||||
const CHROME = 'chrome'; /* Chrome */
|
||||
const OPERA = 'opera'; /* Opera */
|
||||
const NETSCAPE = 'netscape'; /* Netscape */
|
||||
const MAXTHON = 'maxthon'; /* Maxthon */
|
||||
const KONQUEROR = 'konqueror'; /* Konqueror */
|
||||
const HANDHELD = 'mobile'; /* Handheld Browser */
|
||||
const BLINK = 'blink'; /* Blink Browser */
|
||||
const HANDHELD = 'mobile'; /* Handheld Browser */
|
||||
const BLINK = 'blink'; /* Blink Browser */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class Header extends HeaderAbstract
|
|||
if (self::$isLocked) {
|
||||
throw new \Exception('Already locked');
|
||||
}
|
||||
|
||||
|
||||
if (isset($this->header[$key])) {
|
||||
unset($this->header[$key]);
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ class Header extends HeaderAbstract
|
|||
*/
|
||||
public function generate(string $code)
|
||||
{
|
||||
switch($code) {
|
||||
switch ($code) {
|
||||
case RequestStatus::R_403:
|
||||
$this->generate403();
|
||||
break;
|
||||
|
|
@ -204,7 +204,7 @@ class Header extends HeaderAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function generate406()
|
||||
private function generate406()
|
||||
{
|
||||
$this->set('HTTP', 'HTTP/1.0 406 Not acceptable');
|
||||
$this->set('Status', 'Status: 406 Not acceptable');
|
||||
|
|
@ -233,7 +233,7 @@ class Header extends HeaderAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function generate407()
|
||||
private function generate407()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,27 +32,27 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class OSType extends Enum
|
||||
{
|
||||
const WINDOWS_81 = 'windows nt 6.3'; /* Windows 8.1 */
|
||||
const WINDOWS_8 = 'windows nt 6.2'; /* Windows 8 */
|
||||
const WINDOWS_7 = 'windows nt 6.1'; /* Windows 7 */
|
||||
const WINDOWS_VISTA = 'windows nt 6.0'; /* Windows Vista */
|
||||
const WINDOWS_81 = 'windows nt 6.3'; /* Windows 8.1 */
|
||||
const WINDOWS_8 = 'windows nt 6.2'; /* Windows 8 */
|
||||
const WINDOWS_7 = 'windows nt 6.1'; /* Windows 7 */
|
||||
const WINDOWS_VISTA = 'windows nt 6.0'; /* Windows Vista */
|
||||
const WINDOWS_SERVER = 'windows nt 5.2'; /* Windows Server 2003/XP x64 */
|
||||
const WINDOWS_XP = 'windows nt 5.1'; /* Windows XP */
|
||||
const WINDOWS_XP_2 = 'windows xp'; /* Windows XP */
|
||||
const WINDOWS_2000 = 'windows nt 5.0'; /* Windows 2000 */
|
||||
const WINDOWS_ME = 'windows me'; /* Windows ME */
|
||||
const WINDOWS_98 = 'win98'; /* Windows 98 */
|
||||
const WINDOWS_95 = 'win95'; /* Windows 95 */
|
||||
const WINDOWS_311 = 'win16'; /* Windows 3.11 */
|
||||
const MAC_OS_X = 'macintosh'; /* Mac OS X */
|
||||
const MAC_OS_X_2 = 'mac os x'; /* Mac OS X */
|
||||
const MAC_OS_9 = 'mac_powerpc'; /* Mac OS 9 */
|
||||
const LINUX = 'linux'; /* Linux */
|
||||
const UBUNTU = 'ubuntu'; /* Ubuntu */
|
||||
const IPHONE = 'iphone'; /* IPhone */
|
||||
const IPOD = 'ipod'; /* IPod */
|
||||
const IPAD = 'ipad'; /* IPad */
|
||||
const ANDROID = 'android'; /* Android */
|
||||
const BLACKBERRY = 'blackberry'; /* Blackberry */
|
||||
const MOBILE = 'webos'; /* Mobile */
|
||||
const WINDOWS_XP = 'windows nt 5.1'; /* Windows XP */
|
||||
const WINDOWS_XP_2 = 'windows xp'; /* Windows XP */
|
||||
const WINDOWS_2000 = 'windows nt 5.0'; /* Windows 2000 */
|
||||
const WINDOWS_ME = 'windows me'; /* Windows ME */
|
||||
const WINDOWS_98 = 'win98'; /* Windows 98 */
|
||||
const WINDOWS_95 = 'win95'; /* Windows 95 */
|
||||
const WINDOWS_311 = 'win16'; /* Windows 3.11 */
|
||||
const MAC_OS_X = 'macintosh'; /* Mac OS X */
|
||||
const MAC_OS_X_2 = 'mac os x'; /* Mac OS X */
|
||||
const MAC_OS_9 = 'mac_powerpc'; /* Mac OS 9 */
|
||||
const LINUX = 'linux'; /* Linux */
|
||||
const UBUNTU = 'ubuntu'; /* Ubuntu */
|
||||
const IPHONE = 'iphone'; /* IPhone */
|
||||
const IPOD = 'ipod'; /* IPod */
|
||||
const IPAD = 'ipad'; /* IPad */
|
||||
const ANDROID = 'android'; /* Android */
|
||||
const BLACKBERRY = 'blackberry'; /* Blackberry */
|
||||
const MOBILE = 'webos'; /* Mobile */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class Request extends RequestAbstract
|
|||
|
||||
$this->path = explode('/', $this->uri->getPath());
|
||||
$this->l11n->setLanguage($this->path[0]);
|
||||
|
||||
|
||||
$this->setupUriBuilder();
|
||||
$this->createRequestHashs();
|
||||
}
|
||||
|
|
@ -141,9 +141,9 @@ class Request extends RequestAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function initCurrentRequest()
|
||||
private function initCurrentRequest()
|
||||
{
|
||||
$this->data = $_GET ?? [];
|
||||
$this->data = $_GET ?? [];
|
||||
$this->files = $_FILES ?? [];
|
||||
|
||||
if (isset($_SERVER['CONTENT_TYPE'])) {
|
||||
|
|
@ -222,7 +222,7 @@ class Request extends RequestAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function cleanupGlobals()
|
||||
private function cleanupGlobals()
|
||||
{
|
||||
unset($_FILES);
|
||||
unset($_GET);
|
||||
|
|
@ -364,10 +364,10 @@ class Request extends RequestAbstract
|
|||
}
|
||||
|
||||
return
|
||||
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
||||
|| (empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
|
||||
|| (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
|
||||
|| $_SERVER['SERVER_PORT'] == $port;
|
||||
(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
||||
|| (empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
|
||||
|| (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on')
|
||||
|| $_SERVER['SERVER_PORT'] == $port;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -409,7 +409,7 @@ class Request extends RequestAbstract
|
|||
public function getProtocolVersion() : string
|
||||
{
|
||||
return $_SERVER['SERVER_PROTOCOL'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -452,7 +452,7 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
public function getRouteVerb() : int
|
||||
{
|
||||
switch($this->getMethod()) {
|
||||
switch ($this->getMethod()) {
|
||||
case RequestMethod::GET:
|
||||
return RouteVerb::GET;
|
||||
case RequestMethod::PUT:
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class RequestMethod extends Enum
|
||||
{
|
||||
const GET = 'GET'; /* GET */
|
||||
const POST = 'POST'; /* POST */
|
||||
const PUT = 'PUT'; /* PUT */
|
||||
const GET = 'GET'; /* GET */
|
||||
const POST = 'POST'; /* POST */
|
||||
const PUT = 'PUT'; /* PUT */
|
||||
const DELETE = 'DELETE'; /* DELETE */
|
||||
const HEAD = 'HEAD'; /* HEAD */
|
||||
const TRACE = 'TRACE'; /* TRACE */
|
||||
const HEAD = 'HEAD'; /* HEAD */
|
||||
const TRACE = 'TRACE'; /* TRACE */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
*/
|
||||
public function render() : string
|
||||
{
|
||||
switch($this->header->get('Content-Type')) {
|
||||
switch ($this->header->get('Content-Type')) {
|
||||
case MimeType::M_JSON:
|
||||
return $this->getJson();
|
||||
default:
|
||||
|
|
@ -154,7 +154,6 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
$render .= json_encode($response);
|
||||
// TODO: remove this. This should never happen since then someone forgot to set the correct header. it should be json header!
|
||||
} else {
|
||||
var_dump($response);
|
||||
throw new \Exception('Wrong response type');
|
||||
}
|
||||
}
|
||||
|
|
@ -169,14 +168,14 @@ class Response extends ResponseAbstract implements RenderableInterface
|
|||
{
|
||||
$result = [];
|
||||
|
||||
foreach($this->response as $key => $response) {
|
||||
if($response instanceof View) {
|
||||
foreach ($this->response as $key => $response) {
|
||||
if ($response instanceof View) {
|
||||
$result += $response->toArray();
|
||||
} elseif(is_array($response)) {
|
||||
} elseif (is_array($response)) {
|
||||
$result += $response;
|
||||
} elseif(is_scalar($response)) {
|
||||
} elseif (is_scalar($response)) {
|
||||
$result[] = $response;
|
||||
} elseif($response instanceof \Serializable) {
|
||||
} elseif ($response instanceof \Serializable) {
|
||||
$result[] = $response->serialize();
|
||||
} else {
|
||||
throw new \Exception('Wrong response type');
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ class Rest
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function setRequest(Request $request) {
|
||||
public function setRequest(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,17 +34,19 @@ class Imap extends Mail
|
|||
|
||||
public function connect($host, $user, $password)
|
||||
{
|
||||
$this->host = $host;
|
||||
$this->host = $host;
|
||||
$this->inbox = imap_open($host, $user, $password);
|
||||
|
||||
return !($this->inbox === false);
|
||||
}
|
||||
|
||||
public function getBoxes() {
|
||||
public function getBoxes()
|
||||
{
|
||||
return imap_list($this->inbox, $this->host, '*');
|
||||
}
|
||||
|
||||
public function getQuota() {
|
||||
public function getQuota()
|
||||
{
|
||||
return imap_get_quotaroot($this->inbox, "INBOX");
|
||||
}
|
||||
|
||||
|
|
@ -133,10 +135,12 @@ class Imap extends Mail
|
|||
{
|
||||
if ($encoding == 3) {
|
||||
return imap_base64($content);
|
||||
} else if ($encoding == 1) {
|
||||
return imap_8bit($content);
|
||||
} else {
|
||||
return imap_qprint($content);
|
||||
if ($encoding == 1) {
|
||||
return imap_8bit($content);
|
||||
} else {
|
||||
return imap_qprint($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class MailType extends Enum
|
||||
{
|
||||
const MAIL = 0;
|
||||
const SMTP = 1;
|
||||
const IMAP = 2;
|
||||
const POP3 = 3;
|
||||
const MAIL = 0;
|
||||
const SMTP = 1;
|
||||
const IMAP = 2;
|
||||
const POP3 = 3;
|
||||
const SENDMAIL = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,8 @@ abstract class RequestAbstract implements MessageInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setMethod(string $method) {
|
||||
public function setMethod(string $method)
|
||||
{
|
||||
$this->method = $method;
|
||||
}
|
||||
|
||||
|
|
@ -261,6 +262,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
public function getData($key = null)
|
||||
{
|
||||
$key = mb_strtolower($key);
|
||||
|
||||
return !isset($key) ? $this->data : $this->data[$key] ?? null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class RequestSource extends Enum
|
||||
{
|
||||
const WEB = 0; /* This is a http request */
|
||||
const WEB = 0; /* This is a http request */
|
||||
const CONSOLE = 1; /* Request is a console command */
|
||||
const SOCKET = 2; /* Request through socket connection */
|
||||
const SOCKET = 2; /* Request through socket connection */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ abstract class ResponseAbstract implements MessageInterface
|
|||
*
|
||||
* @param mixed $key Response id
|
||||
* @param mixed $response Response to add
|
||||
* @param bool $overwrite Overwrite
|
||||
* @param bool $overwrite Overwrite
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class ResponseType extends Enum
|
||||
{
|
||||
const HTTP = 0; /* HTTP */
|
||||
const JSON = 1; /* JSON */
|
||||
const SOCKET = 2; /* Socket */
|
||||
const HTTP = 0; /* HTTP */
|
||||
const JSON = 1; /* JSON */
|
||||
const SOCKET = 2; /* Socket */
|
||||
const CONSOLE = 3; /* Console */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,9 +219,9 @@ class Meta implements RenderableInterface
|
|||
public function render() : string
|
||||
{
|
||||
return (count($this->keywords) > 0 ? '<meta name="keywords" content="' . implode(',', $this->keywords) . '">"' : '')
|
||||
. (isset($this->author) ? '<meta name="author" content="' . $this->author . '">' : '')
|
||||
. (isset($this->description) ? '<meta name="description" content="' . $this->description . '">' : '')
|
||||
. (isset($this->charset) ? '<meta charset="' . $this->charset . '">' : '')
|
||||
. '<meta name="generator" content="Orange Management">';
|
||||
. (isset($this->author) ? '<meta name="author" content="' . $this->author . '">' : '')
|
||||
. (isset($this->description) ? '<meta name="description" content="' . $this->description . '">' : '')
|
||||
. (isset($this->charset) ? '<meta charset="' . $this->charset . '">' : '')
|
||||
. '<meta name="generator" content="Orange Management">';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class ActivateAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class DeactivateAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ class InfoManager
|
|||
/**
|
||||
* Update info file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class InstallerAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -53,8 +53,8 @@ class InstallerAbstract
|
|||
/**
|
||||
* Install routes.
|
||||
*
|
||||
* @param string $destRoutePath Destination route path
|
||||
* @param string $srcRoutePath Source route path
|
||||
* @param string $destRoutePath Destination route path
|
||||
* @param string $srcRoutePath Source route path
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -63,9 +63,9 @@ class InstallerAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function installRoutes(string $destRoutePath, string $srcRoutePath)
|
||||
private static function installRoutes(string $destRoutePath, string $srcRoutePath)
|
||||
{
|
||||
if(file_exists($destRoutePath) && file_exists($srcRoutePath)) {
|
||||
if (file_exists($destRoutePath) && file_exists($srcRoutePath)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$appRoutes = include $destRoutePath;
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
|
|
@ -73,7 +73,7 @@ class InstallerAbstract
|
|||
|
||||
$appRoutes = array_merge_recursive($appRoutes, $moduleRoutes);
|
||||
|
||||
if(is_writable($destRoutePath)) {
|
||||
if (is_writable($destRoutePath)) {
|
||||
file_put_contents($destRoutePath, '<?php return ' . ArrayParser::serializeArray($appRoutes) . ';', LOCK_EX);
|
||||
} else {
|
||||
throw new PermissionException($destRoutePath);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class ModuleFactory
|
|||
/**
|
||||
* Gets and initializes modules.
|
||||
*
|
||||
* @param string $module Module ID
|
||||
* @param string $module Module ID
|
||||
* @param ApplicationAbstract $app Application
|
||||
*
|
||||
* @return ModuleAbstract
|
||||
|
|
@ -76,7 +76,7 @@ class ModuleFactory
|
|||
{
|
||||
if (!isset(self::$loaded[$module])) {
|
||||
try {
|
||||
$class = '\\Modules\\' . $module . '\\Controller';
|
||||
$class = '\\Modules\\' . $module . '\\Controller';
|
||||
$obj = new $class($app);
|
||||
self::$loaded[$module] = $obj;
|
||||
self::registerRequesting($obj);
|
||||
|
|
@ -118,11 +118,11 @@ class ModuleFactory
|
|||
*/
|
||||
private static function registerProvided(ModuleAbstract $obj)
|
||||
{
|
||||
$name = $obj->getName();
|
||||
if (isset(self::$providing[$name])) {
|
||||
foreach (self::$providing[$name] as $providing) {
|
||||
self::$loaded[$name]->addReceiving($providing);
|
||||
$name = $obj->getName();
|
||||
if (isset(self::$providing[$name])) {
|
||||
foreach (self::$providing[$name] as $providing) {
|
||||
self::$loaded[$name]->addReceiving($providing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,21 +146,21 @@ class ModuleManager
|
|||
if (!isset($this->uriLoad)) {
|
||||
switch ($this->app->dbPool->get('core')->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$uriHash = $request->getHash();
|
||||
$uriPdo = '';
|
||||
$uriHash = $request->getHash();
|
||||
$uriPdo = '';
|
||||
|
||||
$i = 1;
|
||||
$c = count($uriHash);
|
||||
for ($k = 0; $k < $c; $k++) {
|
||||
$uriPdo .= ':pid' . $i . ',';
|
||||
$i++;
|
||||
}
|
||||
$i = 1;
|
||||
$c = count($uriHash);
|
||||
for ($k = 0; $k < $c; $k++) {
|
||||
$uriPdo .= ':pid' . $i . ',';
|
||||
$i++;
|
||||
}
|
||||
|
||||
$uriPdo = rtrim($uriPdo, ',');
|
||||
$uriPdo = rtrim($uriPdo, ',');
|
||||
|
||||
/* TODO: make join in order to see if they are active */
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'SELECT
|
||||
/* TODO: make join in order to see if they are active */
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'SELECT
|
||||
`' . $this->app->dbPool->get('core')->prefix . 'module_load`.`module_load_type`, `' . $this->app->dbPool->get('core')->prefix . 'module_load`.*
|
||||
FROM
|
||||
`' . $this->app->dbPool->get('core')->prefix . 'module_load`
|
||||
|
|
@ -168,15 +168,15 @@ class ModuleManager
|
|||
`module_load_pid` IN(' . $uriPdo . ')'
|
||||
);
|
||||
|
||||
$i = 1;
|
||||
foreach ($uriHash as $hash) {
|
||||
$sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
|
||||
$i++;
|
||||
}
|
||||
$i = 1;
|
||||
foreach ($uriHash as $hash) {
|
||||
$sth->bindValue(':pid' . $i, $hash, \PDO::PARAM_STR);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$sth->execute();
|
||||
$sth->execute();
|
||||
|
||||
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
$this->uriLoad = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -314,10 +314,10 @@ class ModuleManager
|
|||
foreach ($installed as $key => $value) {
|
||||
$this->installProviding($key, $module);
|
||||
}
|
||||
} catch(PathException $e) {
|
||||
} catch (PathException $e) {
|
||||
// todo: handle module doesn't exist or files are missing
|
||||
//echo $e->getMessage();
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
//echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
|
@ -336,42 +336,42 @@ class ModuleManager
|
|||
{
|
||||
switch ($this->app->dbPool->get('core')->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$this->app->dbPool->get('core')->con->beginTransaction();
|
||||
$this->app->dbPool->get('core')->con->beginTransaction();
|
||||
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'INSERT INTO `' . $this->app->dbPool->get('core')->prefix . 'module` (`module_id`, `module_theme`, `module_path`, `module_active`, `module_version`) VALUES
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'INSERT INTO `' . $this->app->dbPool->get('core')->prefix . 'module` (`module_id`, `module_theme`, `module_path`, `module_active`, `module_version`) VALUES
|
||||
(:internal, :theme, :path, :active, :version);'
|
||||
);
|
||||
|
||||
$sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT);
|
||||
$sth->bindValue(':theme', 'Default', \PDO::PARAM_STR);
|
||||
$sth->bindValue(':path', $info->getDirectory(), \PDO::PARAM_STR);
|
||||
$sth->bindValue(':active', 1, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':version', $info->getVersion(), \PDO::PARAM_STR);
|
||||
$sth->bindValue(':internal', $info->getInternalName(), \PDO::PARAM_INT);
|
||||
$sth->bindValue(':theme', 'Default', \PDO::PARAM_STR);
|
||||
$sth->bindValue(':path', $info->getDirectory(), \PDO::PARAM_STR);
|
||||
$sth->bindValue(':active', 1, \PDO::PARAM_INT);
|
||||
$sth->bindValue(':version', $info->getVersion(), \PDO::PARAM_STR);
|
||||
|
||||
$sth->execute();
|
||||
$sth->execute();
|
||||
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'INSERT INTO `' . $this->app->dbPool->get('core')->prefix . 'module_load` (`module_load_pid`, `module_load_type`, `module_load_from`, `module_load_for`, `module_load_file`) VALUES
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare(
|
||||
'INSERT INTO `' . $this->app->dbPool->get('core')->prefix . 'module_load` (`module_load_pid`, `module_load_type`, `module_load_from`, `module_load_for`, `module_load_file`) VALUES
|
||||
(:pid, :type, :from, :for, :file);'
|
||||
);
|
||||
|
||||
$load = $info->getLoad();
|
||||
foreach ($load as $val) {
|
||||
foreach ($val['pid'] as $pid) {
|
||||
$sth->bindValue(':pid', $pid, \PDO::PARAM_STR);
|
||||
$sth->bindValue(':type', $val['type'], \PDO::PARAM_INT);
|
||||
$sth->bindValue(':from', $val['from'], \PDO::PARAM_STR);
|
||||
$sth->bindValue(':for', $val['for'], \PDO::PARAM_STR);
|
||||
$sth->bindValue(':file', $val['file'], \PDO::PARAM_STR);
|
||||
$load = $info->getLoad();
|
||||
foreach ($load as $val) {
|
||||
foreach ($val['pid'] as $pid) {
|
||||
$sth->bindValue(':pid', $pid, \PDO::PARAM_STR);
|
||||
$sth->bindValue(':type', $val['type'], \PDO::PARAM_INT);
|
||||
$sth->bindValue(':from', $val['from'], \PDO::PARAM_STR);
|
||||
$sth->bindValue(':for', $val['for'], \PDO::PARAM_STR);
|
||||
$sth->bindValue(':file', $val['file'], \PDO::PARAM_STR);
|
||||
|
||||
$sth->execute();
|
||||
$sth->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->app->dbPool->get('core')->con->commit();
|
||||
$this->app->dbPool->get('core')->con->commit();
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -408,7 +408,7 @@ class ModuleManager
|
|||
{
|
||||
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
|
||||
|
||||
if(!Autoloader::exists($class)) {
|
||||
if (!Autoloader::exists($class)) {
|
||||
throw new \Exception('Module installer does not exist');
|
||||
}
|
||||
|
||||
|
|
@ -453,10 +453,10 @@ class ModuleManager
|
|||
if ($this->installed === null) {
|
||||
switch ($this->app->dbPool->get('core')->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_id`,`module_theme`,`module_version`,`module_id` FROM `' . $this->app->dbPool->get('core')->prefix . 'module`');
|
||||
$sth->execute();
|
||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
break;
|
||||
$sth = $this->app->dbPool->get('core')->con->prepare('SELECT `module_id`,`module_theme`,`module_version`,`module_id` FROM `' . $this->app->dbPool->get('core')->prefix . 'module`');
|
||||
$sth->execute();
|
||||
$this->installed = $sth->fetchAll(\PDO::FETCH_GROUP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +526,7 @@ class ModuleManager
|
|||
'message' => 'Trying to initialize ' . $module . ' without controller.',
|
||||
'line' => $e->getLine(),
|
||||
'file' => $e->getFile(),
|
||||
]);
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -543,7 +543,7 @@ class ModuleManager
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function initModuleController(string $module)
|
||||
private function initModuleController(string $module)
|
||||
{
|
||||
$this->running[$module] = ModuleFactory::getInstance($module, $this->app);
|
||||
$this->app->dispatcher->set($this->running[$module], '\Modules\\' . $module . '\\Controller');
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class UninstallAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class UpdateAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param Pool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
namespace phpOMS\Pattern;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Observer.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
namespace phpOMS\Pattern;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Subject.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ use phpOMS\Socket\SocketAbstract;
|
|||
*/
|
||||
class ClientConnection
|
||||
{
|
||||
private $id = 0;
|
||||
private $socket = null;
|
||||
private $id = 0;
|
||||
private $socket = null;
|
||||
private $handshake = false;
|
||||
private $pid = null;
|
||||
private $pid = null;
|
||||
private $connected = true;
|
||||
|
||||
public function __construct($id, $socket)
|
||||
|
|
@ -48,35 +48,43 @@ class ClientConnection
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function getSocket() {
|
||||
public function getSocket()
|
||||
{
|
||||
return $this->socket;
|
||||
}
|
||||
|
||||
public function getHandshake() {
|
||||
public function getHandshake()
|
||||
{
|
||||
return $this->handshake;
|
||||
}
|
||||
|
||||
public function getPid() {
|
||||
public function getPid()
|
||||
{
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
public function isConnected() {
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->connected;
|
||||
}
|
||||
|
||||
public function setSocket($socket) {
|
||||
public function setSocket($socket)
|
||||
{
|
||||
$this->socket = $socket;
|
||||
}
|
||||
|
||||
public function setHandshake($handshake) {
|
||||
public function setHandshake($handshake)
|
||||
{
|
||||
$this->handshake = $handshake;
|
||||
}
|
||||
|
||||
public function setPid($pid) {
|
||||
public function setPid($pid)
|
||||
{
|
||||
$this->pid = $pid;
|
||||
}
|
||||
|
||||
public function setConnected(bool $connected) {
|
||||
public function setConnected(bool $connected)
|
||||
{
|
||||
$this->connected = $connected;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ class CommandManager implements \Countable
|
|||
* Attach new command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $callback Function callback
|
||||
* @param mixed $source Provider
|
||||
* @param mixed $callback Function callback
|
||||
* @param mixed $source Provider
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -75,7 +75,7 @@ class CommandManager implements \Countable
|
|||
* Detach existing command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $source Provider
|
||||
* @param mixed $source Provider
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -94,8 +94,8 @@ class CommandManager implements \Countable
|
|||
* Trigger command.
|
||||
*
|
||||
* @param string $cmd Command ID
|
||||
* @param mixed $conn Client ID
|
||||
* @param mixed $para Parameters to pass
|
||||
* @param mixed $conn Client ID
|
||||
* @param mixed $para Parameters to pass
|
||||
*
|
||||
* @return mixed|bool
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
namespace phpOMS\Socket\Packets;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Server class.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -30,15 +30,15 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class PacketType extends Enum
|
||||
{
|
||||
const CONNECT = 0; /* Client connection (server/sender) */
|
||||
const CONNECT = 0; /* Client connection (server/sender) */
|
||||
const DISCONNECT = 1; /* Client disconnection (server/sender) */
|
||||
const KICK = 2; /* Kick (server/client/sender) */
|
||||
const PING = 3; /* Ping (server/sender) */
|
||||
const HELP = 4; /* Help (server/sender) */
|
||||
const RESTART = 5; /* Restart server (server/all clients/client) */
|
||||
const MSG = 6; /* Message (server/sender/client/all clients?) */
|
||||
const LOGIN = 7; /* Login (server/sender) */
|
||||
const LOGOUT = 8; /* Logout (server/sender) */
|
||||
const ACCMODIFY = 9; /* Account modification (server/sender (admin)/user) */
|
||||
const MODULE = 999999999; /* Module packet ??? */
|
||||
const KICK = 2; /* Kick (server/client/sender) */
|
||||
const PING = 3; /* Ping (server/sender) */
|
||||
const HELP = 4; /* Help (server/sender) */
|
||||
const RESTART = 5; /* Restart server (server/all clients/client) */
|
||||
const MSG = 6; /* Message (server/sender/client/all clients?) */
|
||||
const LOGIN = 7; /* Login (server/sender) */
|
||||
const LOGOUT = 8; /* Logout (server/sender) */
|
||||
const ACCMODIFY = 9; /* Account modification (server/sender (admin)/user) */
|
||||
const MODULE = 999999999; /* Module packet ??? */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,10 @@ class ClientManager
|
|||
return $this->clients[$id] ?? new NullClientConnection(uniqid(), null);
|
||||
}
|
||||
|
||||
public function getBySocket($socket) {
|
||||
foreach($this->clients as $client) {
|
||||
if($client->getSocket() === $socket) {
|
||||
public function getBySocket($socket)
|
||||
{
|
||||
foreach ($this->clients as $client) {
|
||||
if ($client->getSocket() === $socket) {
|
||||
return $client;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,8 +44,9 @@ class ClientManager
|
|||
return new NullClientConnection(uniqid(), null);
|
||||
}
|
||||
|
||||
public function remove($id) {
|
||||
if(isset($this->clients[$id])) {
|
||||
public function remove($id)
|
||||
{
|
||||
if (isset($this->clients[$id])) {
|
||||
unset($this->clients[$id]);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ class Server extends SocketAbstract
|
|||
$origin = $match[1];
|
||||
}
|
||||
|
||||
$key = '';
|
||||
if (preg_match("/Sec-WebSocket-Key: (.*)\r\n/", $headers, $match)) {
|
||||
$key = $match[1];
|
||||
}
|
||||
|
|
@ -159,6 +160,7 @@ class Server extends SocketAbstract
|
|||
"\r\n\r\n";
|
||||
socket_write($client->getSocket(), $upgrade);
|
||||
$client->setHandshake(true);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
namespace phpOMS\Stdlib\Map;
|
||||
|
||||
use phpOMS\Utils\Permutation;
|
||||
|
||||
/**
|
||||
|
|
@ -65,7 +66,7 @@ class MultiMap implements \Countable
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $key Key type (all keys need to match or just one)
|
||||
* @param int $key Key type (all keys need to match or just one)
|
||||
* @param int $order Order of the keys is important (only required for multiple keys)
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -73,7 +74,7 @@ class MultiMap implements \Countable
|
|||
*/
|
||||
public function __construct(int $key = KeyType::SINGLE, int $order = OrderType::LOOSE)
|
||||
{
|
||||
$this->keyType = $key;
|
||||
$this->keyType = $key;
|
||||
$this->orderType = $order;
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ class MultiMap implements \Countable
|
|||
*
|
||||
* @param array $keys Keys for value
|
||||
* @param mixed $value Value to store
|
||||
* @param bool $overwrite Add value if key exists
|
||||
* @param bool $overwrite Add value if key exists
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
@ -169,7 +170,7 @@ class MultiMap implements \Countable
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function getSingle($key)
|
||||
private function getSingle($key)
|
||||
{
|
||||
return isset($this->keys[$key]) ? $this->values[$this->keys[$key]] ?? null : null;
|
||||
}
|
||||
|
|
@ -184,7 +185,7 @@ class MultiMap implements \Countable
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function getMultiple($key)
|
||||
private function getMultiple($key)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
if ($this->orderType === OrderType::LOOSE) {
|
||||
|
|
@ -409,7 +410,7 @@ class MultiMap implements \Countable
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function removeKeySingle($key) : bool
|
||||
private function removeKeySingle($key) : bool
|
||||
{
|
||||
if (isset($this->keys[$key])) {
|
||||
unset($this->keys[$key]);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class PriorityQueue implements \Countable, \Serializable
|
|||
/**
|
||||
* Insert element into queue.
|
||||
*
|
||||
* @param mixed $data Queue element
|
||||
* @param mixed $data Queue element
|
||||
* @param float $priority Priority of this element
|
||||
*
|
||||
* @return int
|
||||
|
|
@ -199,7 +199,14 @@ class PriorityQueue implements \Countable, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* Unserialize queue.
|
||||
*
|
||||
* @param string $data Data to unserialze
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function unserialize($data) : array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
*
|
||||
* This can become rather slow for large structures.
|
||||
*
|
||||
* @param string $dir Root dir to inspect
|
||||
* @param bool $recursive Get size recursive
|
||||
* @param string $dir Root dir to inspect
|
||||
* @param bool $recursive Get size recursive
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
|
|
@ -71,9 +71,11 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
if ($filename != ".." && $filename != ".") {
|
||||
if (is_dir($dir . "/" . $filename) && $recursive) {
|
||||
$countSize += self::getFolderSize($dir . "/" . $filename, $recursive);
|
||||
} else if (is_file($dir . "/" . $filename)) {
|
||||
$countSize += filesize($dir . "/" . $filename);
|
||||
$count++;
|
||||
} else {
|
||||
if (is_file($dir . "/" . $filename)) {
|
||||
$countSize += filesize($dir . "/" . $filename);
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -155,9 +157,9 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* Create directory.
|
||||
*
|
||||
* @param string $path Path
|
||||
* @param int $permission Directory permission
|
||||
* @param bool $recursive Create parent directories if applicable
|
||||
* @param string $path Path
|
||||
* @param int $permission Directory permission
|
||||
* @param bool $recursive Create parent directories if applicable
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
|
|
@ -204,19 +206,19 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $path Path
|
||||
* @param string $path Path
|
||||
* @param string $filter Filter
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(string $path, string $filter = '*')
|
||||
public function __construct(string $path, string $filter = '*')
|
||||
{
|
||||
$this->filter = $filter;
|
||||
parent::__construct($path);
|
||||
|
||||
if (file_exists($this->path)) {
|
||||
parent::index();
|
||||
$this->index();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +232,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function get(string $name) : FileAbstract
|
||||
public function get(string $name) : FileAbstract
|
||||
{
|
||||
return $this->nodes[$name] ?? new NullFile('');
|
||||
}
|
||||
|
|
@ -287,6 +289,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
$this->size -= $this->nodes[$name]->getSize();
|
||||
|
||||
unset($this->nodes[$name]);
|
||||
|
||||
// todo: unlink???
|
||||
|
||||
return true;
|
||||
|
|
@ -303,7 +306,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function index()
|
||||
public function index()
|
||||
{
|
||||
parent::index();
|
||||
|
||||
|
|
@ -340,7 +343,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function key()
|
||||
public function key()
|
||||
{
|
||||
return key($this->nodes);
|
||||
}
|
||||
|
|
@ -348,7 +351,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function next()
|
||||
public function next()
|
||||
{
|
||||
return next($this->nodes);
|
||||
}
|
||||
|
|
@ -367,7 +370,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->add($value);
|
||||
|
|
@ -379,7 +382,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->nodes[$offset]);
|
||||
}
|
||||
|
|
@ -387,7 +390,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
if (isset($this->nodes[$offset])) {
|
||||
unset($this->nodes[$offset]);
|
||||
|
|
@ -397,7 +400,7 @@ class Directory extends FileAbstract implements \Iterator, \ArrayAccess
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->nodes[$offset] ?? null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,11 +64,11 @@ class File extends FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(string $path)
|
||||
public function __construct(string $path)
|
||||
{
|
||||
parent::__construct($path);
|
||||
$this->count = 1;
|
||||
|
||||
|
||||
if (file_exists($this->path)) {
|
||||
$this->index();
|
||||
}
|
||||
|
|
@ -124,10 +124,10 @@ class File extends FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function index()
|
||||
public function index()
|
||||
{
|
||||
parent::index();
|
||||
|
||||
|
||||
$this->size = filesize($this->path);
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(string $path)
|
||||
public function __construct(string $path)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->name = basename($path);
|
||||
|
|
@ -145,7 +145,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getName() : string
|
||||
public function getName() : string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getPath() : string
|
||||
public function getPath() : string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function parent() : Directory
|
||||
public function parent() : Directory
|
||||
{
|
||||
return new Directory(Directory::getParent($this->path));
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getCreatedAt() : \DateTime
|
||||
public function getCreatedAt() : \DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
|
@ -207,7 +207,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getChangedAt() : \DateTime
|
||||
public function getChangedAt() : \DateTime
|
||||
{
|
||||
return $this->changedAt;
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getOwner() : int
|
||||
public function getOwner() : int
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getPermission() : string
|
||||
public function getPermission() : string
|
||||
{
|
||||
return $this->permission;
|
||||
}
|
||||
|
|
@ -246,11 +246,11 @@ abstract class FileAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function index()
|
||||
public function index()
|
||||
{
|
||||
$this->createdAt->setTimestamp(filemtime($this->path));
|
||||
$this->changedAt->setTimestamp(filectime($this->path));
|
||||
$this->owner = fileowner($this->path);
|
||||
$this->owner = fileowner($this->path);
|
||||
$this->permission = substr(sprintf('%o', fileperms($this->path)), -4);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,5 +30,5 @@ namespace phpOMS\System\File;
|
|||
*/
|
||||
class NullFile extends File
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user