mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-21 05:48:41 +00:00
Merge pull request #99 from Orange-Management/develop
New stable pre-alpha
This commit is contained in:
commit
ae43d838c7
|
|
@ -108,29 +108,6 @@ class AccountManager implements \Countable
|
|||
return $this->accounts[$id] ?? new NullAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user.
|
||||
*
|
||||
* @param int $account Account id
|
||||
* @param string $login Username
|
||||
* @param string $password Password
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Exception Throws this exception if the account to login is not found in the AccountManager.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function login(int $account, string $login, string $password) : int
|
||||
{
|
||||
if (!isset($this->accounts[$account])) {
|
||||
throw new \Exception('Account not found in the account manager.');
|
||||
}
|
||||
|
||||
return $this->auth->login($login, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add account.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Account;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\Column;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
|
||||
class AccountMapper extends DataMapperAbstract
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $columns = [
|
||||
'account_id' => ['name' => 'account_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'account_status' => ['name' => 'account_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'account_type' => ['name' => 'account_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'account_login' => ['name' => 'account_login', 'type' => 'string', 'internal' => 'login'],
|
||||
'account_name1' => ['name' => 'account_name1', 'type' => 'string', 'internal' => 'name1'],
|
||||
'account_name2' => ['name' => 'account_name2', 'type' => 'string', 'internal' => 'name2'],
|
||||
'account_name3' => ['name' => 'account_name3', 'type' => 'string', 'internal' => 'name3'],
|
||||
'account_email' => ['name' => 'account_email', 'type' => 'string', 'internal' => 'email'],
|
||||
'account_lactive' => ['name' => 'account_lactive', 'type' => 'DateTime', 'internal' => 'lastActive'],
|
||||
'account_created_at' => ['name' => 'account_created', 'type' => 'DateTime', 'internal' => 'createdAt'],
|
||||
];
|
||||
|
||||
protected static $hasMany = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $table = 'account';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $createdAt = 'account_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $primaryField = 'account_id';
|
||||
|
||||
/**
|
||||
* Create object.
|
||||
*
|
||||
* @param mixed $obj Object
|
||||
* @param int $relations Behavior for relations creation
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function create($obj, int $relations = RelationType::ALL)
|
||||
{
|
||||
try {
|
||||
$objId = parent::create($obj, $relations);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $objId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find.
|
||||
*
|
||||
* @param array $columns Columns to select
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function find(...$columns) : Builder
|
||||
{
|
||||
return parent::find(...$columns)->from('account_permission')
|
||||
->where('account_permission.account_permission_for', '=', 'task')
|
||||
->where('account_permission.account_permission_id1', '=', 1)
|
||||
->where('task.task_id', '=', new Column('account_permission.account_permission_id2'))
|
||||
->where('account_permission.account_permission_r', '=', 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class AssetType extends Enum
|
||||
{
|
||||
/* public */ const CSS = 'css';
|
||||
/* public */ const JS = 'js';
|
||||
/* public */ const JSLATE = 'jslate';
|
||||
/* public */ const CSS = 0;
|
||||
/* public */ const JS = 1;
|
||||
/* public */ const JSLATE = 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,65 +86,6 @@ class Auth
|
|||
return $uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login user.
|
||||
*
|
||||
* @param string $login Username
|
||||
* @param string $password Password
|
||||
*
|
||||
* @return int Login code
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function login(string $login, string $password) : int
|
||||
{
|
||||
try {
|
||||
$result = null;
|
||||
|
||||
switch ($this->connection->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
|
||||
$sth = $this->connection->con->prepare(
|
||||
'SELECT
|
||||
`' . $this->connection->prefix . 'account`.*
|
||||
FROM
|
||||
`' . $this->connection->prefix . 'account`
|
||||
WHERE
|
||||
`account_login` = :login'
|
||||
);
|
||||
$sth->bindValue(':login', $login, \PDO::PARAM_STR);
|
||||
$sth->execute();
|
||||
|
||||
$result = $sth->fetchAll();
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: check if user is allowed to login on THIS page (backend|frontend|etc...)
|
||||
|
||||
if (!isset($result[0])) {
|
||||
return LoginReturnType::WRONG_USERNAME;
|
||||
}
|
||||
|
||||
$result = $result[0];
|
||||
|
||||
if ($result['account_tries'] <= 0) {
|
||||
return LoginReturnType::WRONG_INPUT_EXCEEDED;
|
||||
}
|
||||
|
||||
if (password_verify($password, $result['account_password'])) {
|
||||
$this->session->set('UID', $result['account_id']);
|
||||
$this->session->save();
|
||||
|
||||
return LoginReturnType::OK;
|
||||
}
|
||||
|
||||
return LoginReturnType::WRONG_PASSWORD;
|
||||
} catch (\Exception $e) {
|
||||
return LoginReturnType::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout the given user.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ use phpOMS\Datatypes\Enum;
|
|||
abstract class LoginReturnType extends Enum
|
||||
{
|
||||
/* public */ const OK = 0; /* Everything is ok and the user got authed */
|
||||
/* public */ const FAILURE = 1; /* Authentication resulted in a unexpected failure */
|
||||
/* public */ const WRONG_PASSWORD = 2; /* Authentication with wrong password */
|
||||
/* public */ const WRONG_USERNAME = 3; /* Authentication with unknown user */
|
||||
/* public */ const WRONG_PERMISSION = 4; /* User doesn't have permission to authenticate */
|
||||
/* public */ const NOT_ACTIVATED = 5; /* The user is not activated yet */
|
||||
/* public */ const WRONG_INPUT_EXCEEDED = 6; /* Too many wrong logins recently */
|
||||
/* public */ const TIMEOUTED = 7; /* User received a timeout and can not log in until a certain date */
|
||||
/* public */ const BANNED = 8; /* User is banned */
|
||||
/* public */ const INACTIVE = 9; /* User is inactive */
|
||||
/* public */ const FAILURE = -1; /* Authentication resulted in a unexpected failure */
|
||||
/* public */ const WRONG_PASSWORD = -2; /* Authentication with wrong password */
|
||||
/* public */ const WRONG_USERNAME = -3; /* Authentication with unknown user */
|
||||
/* public */ const WRONG_PERMISSION = -4; /* User doesn't have permission to authenticate */
|
||||
/* public */ const NOT_ACTIVATED = -5; /* The user is not activated yet */
|
||||
/* public */ const WRONG_INPUT_EXCEEDED = -6; /* Too many wrong logins recently */
|
||||
/* public */ const TIMEOUTED = -7; /* User received a timeout and can not log in until a certain date */
|
||||
/* public */ const BANNED = -8; /* User is banned */
|
||||
/* public */ const INACTIVE = -9; /* User is inactive */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ class Autoloader
|
|||
*
|
||||
* @param string $class Class path
|
||||
*
|
||||
* @example Autoloader::default_autoloader('\phpOMS\Autoloader') // void
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws AutoloadException Throws this exception if the class to autoload doesn't exist. This could also be related to a wrong namespace/file path correlation.
|
||||
|
|
@ -50,8 +52,12 @@ class Autoloader
|
|||
$class = ltrim($class, '\\');
|
||||
$class = str_replace(['_', '\\'], '/', $class);
|
||||
|
||||
if(!file_exists($path = __DIR__ . '/../' . $class . '.php')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once __DIR__ . '/../' . $class . '.php';
|
||||
include_once $path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,7 +65,9 @@ class Autoloader
|
|||
*
|
||||
* @param string $class Class path
|
||||
*
|
||||
* @return false|string
|
||||
* @example Autoloader::exists('\phpOMS\Autoloader') // true
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
|
|
|
|||
|
|
@ -88,6 +88,42 @@ class NetPromoterScore {
|
|||
|
||||
$total = $promoters + $passives + $detractors;
|
||||
|
||||
return ((int) ($promoters / $total)) - ((int) ($detractors / $total));
|
||||
return $total === 0 ? 0 : ((int) ($promoters * 100 / $total)) - ((int) ($detractors * 100 / $total));
|
||||
}
|
||||
|
||||
public function countDetractors() : int
|
||||
{
|
||||
$count = 0;
|
||||
foreach($this->scores as $score) {
|
||||
if($score < 7) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function countPassives() : int
|
||||
{
|
||||
$count = 0;
|
||||
foreach($this->scores as $score) {
|
||||
if($score > 6 && $score < 9) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function countPromoters() : int
|
||||
{
|
||||
$count = 0;
|
||||
foreach($this->scores as $score) {
|
||||
if($score > 8) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
|
|
@ -112,10 +112,10 @@ class CachePool implements OptionsInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function get(string $key)
|
||||
public function get(string $key) /* : ?CacheInterface */
|
||||
{
|
||||
if (!isset($this->pool[$key])) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->pool[$key];
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ abstract class CacheType extends Enum
|
|||
/* public */ const _STRING = 1; /* Data is string */
|
||||
/* public */ const _ARRAY = 2; /* Data is array */
|
||||
/* public */ const _SERIALIZABLE = 3; /* Data is object */
|
||||
/* public */ const _JSONSERIALIZABLE = 6;
|
||||
/* public */ const _FLOAT = 4; /* Data is float */
|
||||
/* public */ const _BOOL = 5; /* Data is float */
|
||||
/* public */ const _BOOL = 5; /* Data is bool */
|
||||
/* public */ const _JSONSERIALIZABLE = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,14 +80,14 @@ class FileCache implements CacheInterface
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config Cache config
|
||||
* @param string $path Cache path
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(string $path)
|
||||
{
|
||||
if (!File::exists($path)) {
|
||||
if (!Directory::exists(File::parent($path))) {
|
||||
Directory::create($path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ interface DataMapperInterface
|
|||
/**
|
||||
* Find data.
|
||||
*
|
||||
* @param array $columns Columns
|
||||
* @param string $search Search
|
||||
*
|
||||
* @return Builder
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function find(...$columns) : Builder;
|
||||
public static function find(string $search) : array;
|
||||
|
||||
/**
|
||||
* List data.
|
||||
|
|
|
|||
|
|
@ -69,6 +69,14 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
protected static $createdAt = '';
|
||||
|
||||
/**
|
||||
* Language
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $language_field = '';
|
||||
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
|
|
@ -288,25 +296,26 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Find data.
|
||||
*
|
||||
* @param array $columns Columns
|
||||
* @param string $search Search for
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function find(...$columns) : Builder
|
||||
public static function find(string $search) : array
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
if (count($columns) === 0) {
|
||||
$columns = [static::$table . '.*'];
|
||||
$query = static::getQuery();
|
||||
|
||||
foreach(static::$columns as $col) {
|
||||
if(isset($col['autocomplete']) && $col['autocomplete']) {
|
||||
$query->where(static::$table . '.' . $col['name'], 'LIKE', '%' . $search . '%', 'OR');
|
||||
}
|
||||
}
|
||||
|
||||
$query = new Builder(self::$db);
|
||||
$query->prefix(self::$db->getPrefix());
|
||||
|
||||
return $query->select(...$columns)->from(static::$table);
|
||||
|
||||
return static::getAllByQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -324,7 +333,13 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
if($obj === null ||
|
||||
(is_object($obj) && strpos($className = get_class($obj), '\Null') !== false)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$reflectionClass = new \ReflectionClass($className);
|
||||
$objId = self::createModel($obj, $reflectionClass);
|
||||
self::setObjectId($reflectionClass, $obj, $objId);
|
||||
|
||||
|
|
@ -370,6 +385,8 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$value = self::parseValue($column['type'], $id);
|
||||
|
||||
$query->insert($column['name'])->value($value, $column['type']);
|
||||
$temp = $query->toSql();
|
||||
$test = 1;
|
||||
break;
|
||||
} elseif (isset(static::$belongsTo[$propertyName]) && $column['internal'] === $propertyName) {
|
||||
$id = self::createBelongsTo($propertyName, $property->getValue($obj));
|
||||
|
|
@ -474,6 +491,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new \Exception('No mapper set for relation object.');
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -501,6 +519,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
|
||||
/** @var string $table */
|
||||
/** @var array $columns */
|
||||
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table) {
|
||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['dst']]['internal']);
|
||||
|
||||
|
|
@ -524,7 +543,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
|
||||
private static function createHasOne(\ReflectionClass $reflectionClass, $obj)
|
||||
{
|
||||
throw new \Excpetion();
|
||||
throw new \Exception();
|
||||
|
||||
foreach (static::$hasOne as $propertyName => $rel) {
|
||||
|
||||
|
|
@ -576,6 +595,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function createBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
$primaryKey = $mapper::getObjectId($obj);
|
||||
|
||||
|
|
@ -647,7 +667,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
return $value->serialize();
|
||||
} elseif ($value instanceof \JsonSerializable) {
|
||||
return json_encode($value->jsonSerialize());
|
||||
} elseif (is_object($value)) {
|
||||
} elseif (is_object($value) && method_exists($value, 'getId')) {
|
||||
return $value->getId();
|
||||
} elseif ($type === 'int') {
|
||||
return (int) $value;
|
||||
|
|
@ -695,6 +715,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new \Exception('No mapper set for relation object.');
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -721,6 +742,8 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
}
|
||||
|
||||
// create if not existing
|
||||
/** @var string $table */
|
||||
/** @var array $columns */
|
||||
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table) {
|
||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['dst']]['internal']);
|
||||
|
||||
|
|
@ -753,11 +776,14 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function updateRelationTable(string $propertyName, array $objsIds, $objId)
|
||||
{
|
||||
/** @var string $table */
|
||||
if (
|
||||
!empty($objsIds)
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$table
|
||||
|
|
@ -796,6 +822,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
private static function deleteRelationTable(string $propertyName, array $objsIds, $objId)
|
||||
{
|
||||
/** @var string $table */
|
||||
if (
|
||||
!empty($objsIds)
|
||||
&& static::$hasMany[$propertyName]['table'] !== static::$table
|
||||
|
|
@ -831,6 +858,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function updateOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
|
|
@ -857,6 +885,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function updateBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::update($obj);
|
||||
|
|
@ -998,6 +1027,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
throw new \Exception('No mapper set for relation object.');
|
||||
}
|
||||
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||
$objsIds = [];
|
||||
$relReflectionClass = null;
|
||||
|
|
@ -1051,6 +1081,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function deleteOwnsOne(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||
|
||||
// todo: delete owned one object is not recommended since it can be owned by by something else? or does owns one mean that nothing else can have a relation to this one?
|
||||
|
|
@ -1076,6 +1107,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
private static function deleteBelongsTo(string $propertyName, $obj)
|
||||
{
|
||||
if (is_object($obj)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$belongsTo[$propertyName]['mapper'];
|
||||
|
||||
return $mapper::delete($obj);
|
||||
|
|
@ -1243,7 +1275,8 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||
|
||||
foreach ($result as $member => $values) {
|
||||
if ($reflectionClass->hasProperty($member)) {
|
||||
if (!empty($values) && $reflectionClass->hasProperty($member)) {
|
||||
/** @var DataMapperAbstract $mapper */
|
||||
$mapper = static::$hasMany[$member]['mapper'];
|
||||
$reflectionProperty = $reflectionClass->getProperty($member);
|
||||
|
||||
|
|
@ -1468,15 +1501,16 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
* Get object.
|
||||
*
|
||||
* @param int $relations Load relations
|
||||
* @param string $lang Language
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getAll(int $relations = RelationType::ALL)
|
||||
public static function getAll(int $relations = RelationType::ALL, string $lang = '')
|
||||
{
|
||||
$obj = self::populateIterable(self::getAllRaw());
|
||||
$obj = self::populateIterable(self::getAllRaw($lang));
|
||||
self::fillRelations($obj, $relations);
|
||||
self::clear();
|
||||
|
||||
|
|
@ -1509,13 +1543,14 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
* @param int $limit Newest limit
|
||||
* @param Builder $query Pre-defined query
|
||||
* @param int $relations Load relations
|
||||
* @param string $lang Language
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL)
|
||||
public static function getNewest(int $limit = 1, Builder $query = null, int $relations = RelationType::ALL, string $lang = '')
|
||||
{
|
||||
self::extend(__CLASS__);
|
||||
|
||||
|
|
@ -1529,6 +1564,10 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$query->orderBy(static::$table . '.' . static::$columns[static::$primaryField]['name'], 'DESC');
|
||||
}
|
||||
|
||||
if (!empty(self::$language_field) && !empty($lang)) {
|
||||
$query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND');
|
||||
}
|
||||
|
||||
$sth = self::$db->con->prepare($query->toSql());
|
||||
$sth->execute();
|
||||
|
||||
|
|
@ -1555,7 +1594,6 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
*/
|
||||
public static function getAllByQuery(Builder $query, int $relations = RelationType::ALL) : array
|
||||
{
|
||||
$query = self::getQuery($query);
|
||||
$sth = self::$db->con->prepare($query->toSql());
|
||||
$sth->execute();
|
||||
|
||||
|
|
@ -1662,14 +1700,21 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
/**
|
||||
* Get all in raw output.
|
||||
*
|
||||
* @param string $lang Language
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getAllRaw() : array
|
||||
public static function getAllRaw(string $lang = '') : array
|
||||
{
|
||||
$query = self::getQuery();
|
||||
|
||||
if (!empty(self::$language_field) && !empty($lang)) {
|
||||
$query->where(static::$table . '.' . static::$language_field, '=', $lang, 'AND');
|
||||
}
|
||||
|
||||
$sth = self::$db->con->prepare($query->toSql());
|
||||
$sth->execute();
|
||||
|
||||
|
|
@ -1698,6 +1743,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$query->prefix(self::$db->getPrefix());
|
||||
|
||||
if ($relations === RelationType::ALL) {
|
||||
/** @var string $primaryField */
|
||||
$src = $value['src'] ?? $value['mapper']::$primaryField;
|
||||
|
||||
$query->select($value['table'] . '.' . $src)
|
||||
|
|
@ -1780,7 +1826,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
public static function getByRequest(RequestAbstract $request)
|
||||
{
|
||||
if (!is_null($request->getData('id'))) {
|
||||
$result = static::get($request->getData('id'))->__toString();
|
||||
$result = static::get($request->getData('id'));
|
||||
} elseif (!is_null($filter = $request->getData('filter'))) {
|
||||
$filter = strtolower($filter);
|
||||
|
||||
|
|
@ -1790,7 +1836,7 @@ class DataMapperAbstract implements DataMapperInterface
|
|||
$list = $request->getData('list');
|
||||
$result = static::get(json_decode($list, true));
|
||||
} else {
|
||||
$limit = $request->getData('limit') ?? 1;
|
||||
$limit = (int) ($request->getData('limit') ?? 1);
|
||||
$from = !is_null($request->getData('from')) ? new \DateTime($request->getData('from')) : null;
|
||||
$to = !is_null($request->getData('to')) ? new \DateTime($request->getData('to')) : null;
|
||||
|
||||
|
|
|
|||
|
|
@ -176,12 +176,12 @@ class Builder extends BuilderAbstract
|
|||
protected $unionOrders = [];
|
||||
|
||||
/**
|
||||
* Comparison operators.
|
||||
* Comparison OPERATORS.
|
||||
*
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
/* public */ const operators = [
|
||||
/* public */ const OPERATORS = [
|
||||
'=',
|
||||
'<',
|
||||
'>',
|
||||
|
|
@ -459,14 +459,14 @@ class Builder extends BuilderAbstract
|
|||
public function where($columns, $operator = null, $values = null, $boolean = 'and') : Builder
|
||||
{
|
||||
// TODO: handle $value is null -> operator NULL
|
||||
if (isset($operator) && !is_array($operator) && !in_array($operator, self::operators)) {
|
||||
if (isset($operator) && !is_array($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
if (is_array($columns)) {
|
||||
$i = 0;
|
||||
foreach ($columns as $key => $column) {
|
||||
if (isset($operator[$i]) && !in_array($operator[$i], self::operators)) {
|
||||
if (isset($operator[$i]) && !in_array(strtolower($operator[$i]), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
|
|
@ -480,7 +480,7 @@ class Builder extends BuilderAbstract
|
|||
$i++;
|
||||
}
|
||||
} elseif (is_string($columns)) {
|
||||
if (isset($operator) && !in_array($operator, self::operators)) {
|
||||
if (isset($operator) && !in_array(strtolower($operator), self::OPERATORS)) {
|
||||
throw new \InvalidArgumentException('Unknown operator.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -245,6 +245,8 @@ class Grammar extends GrammarAbstract
|
|||
$expression .= '(' . $this->compileWhere($element['column'], $query->getPrefix()) . ')';
|
||||
}
|
||||
|
||||
// todo: handle IN(...) as operator
|
||||
|
||||
if (isset($element['value'])) {
|
||||
$expression .= ' ' . strtoupper($element['operator']) . ' ' . $this->compileValue($element['value'], $query->getPrefix());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,6 @@ abstract class AddressType extends Enum
|
|||
/* public */ const SHIPPING = 3;
|
||||
/* public */ const BILLING = 4;
|
||||
/* public */ const WORK = 5;
|
||||
/* public */ const CONTRACT = 6;
|
||||
/* public */ const OTHER = 7;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,4 +140,17 @@ abstract class Enum
|
|||
return defined('static::' . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count enum variables
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function count() : int
|
||||
{
|
||||
return count(self::getConstants());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,11 +118,27 @@ class SmartDateTime extends \DateTime
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end of month object
|
||||
*
|
||||
* @return SmartDateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getEndOfMonth() : SmartDateTime
|
||||
{
|
||||
return new SmartDateTime($this->format('Y') . '-' . $this->format('m') . '-' . $this->getDaysOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start of month object
|
||||
*
|
||||
* @return SmartDateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getStartOfMonth() : SmartDateTime
|
||||
{
|
||||
return new SmartDateTime($this->format('Y') . '-' . $this->format('m') . '-01');
|
||||
|
|
@ -154,4 +170,68 @@ class SmartDateTime extends \DateTime
|
|||
return getdate(mktime(0, 0, 0, (int) $this->format('m'), 1, (int) $this->format('Y')))['wday'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is leap year in gregorian calendar
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function isLeapYear() : bool
|
||||
{
|
||||
return self::leapYear((int) $this->format('Y'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test year if leap year in gregorian calendar
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function leapYear(int $year) : bool
|
||||
{
|
||||
$isLeap = false;
|
||||
|
||||
if ($year % 4 == 0) {
|
||||
$isLeap = true;
|
||||
}
|
||||
|
||||
if ($year % 100 == 0) {
|
||||
$isLeap = false;
|
||||
}
|
||||
|
||||
if ($year % 400 == 0) {
|
||||
$isLeap = true;
|
||||
}
|
||||
|
||||
return $isLeap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get day of week
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getDayOfWeek(int $y, int $m, int $d) : int
|
||||
{
|
||||
$w = 1;
|
||||
$y = ($y - 1) % 400 + 1;
|
||||
$ly = ($y - 1) / 4;
|
||||
$ly = $ly - ($y - 1) / 100;
|
||||
$ly = $ly + ($y - 1) / 400;
|
||||
$ry = $y - 1 - $ly;
|
||||
$w = $w + $ry;
|
||||
$w = $w + 2 * $ly;
|
||||
$w = $w + date("z", mktime(0, 0, 0, $m, $d, $y)) + 1;;
|
||||
$w = ($w - 1) % 7 + 1;
|
||||
|
||||
return $w;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Event;
|
||||
|
||||
use phpOMS\Pattern\Mediator;
|
||||
|
||||
/**
|
||||
* EventManager class.
|
||||
*
|
||||
|
|
@ -32,7 +30,7 @@ use phpOMS\Pattern\Mediator;
|
|||
*
|
||||
* @todo : make cachable + database storable -> can reload user defined listeners (persistent events)
|
||||
*/
|
||||
class EventManager implements Mediator
|
||||
class EventManager
|
||||
{
|
||||
/**
|
||||
* Events.
|
||||
|
|
@ -63,13 +61,13 @@ class EventManager implements Mediator
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attach(string $group, \Closure $callback, bool $remove = false) : bool
|
||||
public function attach(string $group, \Closure $callback, bool $remove = false, bool $reset = false) : bool
|
||||
{
|
||||
if (isset($this->callbacks[$group])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->callbacks[$group] = ['remove' => $remove, 'func' => $callback];
|
||||
$this->callbacks[$group] = ['remove' => $remove, 'reset' => $reset, 'func' => $callback];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -77,27 +75,50 @@ class EventManager implements Mediator
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function trigger(string $group, string $id = '', bool $reset = false) /* : void */
|
||||
public function trigger(string $group, string $id = '', $data = null) /* : void */
|
||||
{
|
||||
if (isset($this->groups[$group])) {
|
||||
unset($this->groups[$group][$id]);
|
||||
if(!isset($this->callbacks[$group])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->hasOutstanding($group)) {
|
||||
$this->callbacks[$group]['func'];
|
||||
if (isset($this->groups[$group])) {
|
||||
$this->groups[$group][$id] = true;
|
||||
}
|
||||
|
||||
if (!$this->hasOutstanding($group)) {
|
||||
$this->callbacks[$group]['func']($data);
|
||||
|
||||
if ($this->callbacks[$group]['remove']) {
|
||||
$this->detach($group);
|
||||
} elseif($this->callbacks[$group]['reset']) {
|
||||
$this->reset($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function reset(string $group) /* : void */
|
||||
{
|
||||
foreach($this->groups[$group] as $id => $ok) {
|
||||
$this->groups[$group][$id] = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
private function hasOutstanding(string $group) : bool
|
||||
{
|
||||
return empty($this->groups[$group]);
|
||||
if(!isset($this->groups[$group])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($this->groups[$group] as $id => $ok) {
|
||||
if(!$ok) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com. IP ranges are transformed from string representation to integer representation.
|
||||
|
||||
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
|
||||
|
||||
This database incorporates GeoNames [http://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 3.0 License. To view a copy of this license, visit http://www.creativecommons.org/licenses/by/3.0/us/.
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -221,9 +221,7 @@ class Money implements \Serializable
|
|||
$this->value += $value;
|
||||
} elseif ($value instanceof Money) {
|
||||
$this->value += $value->getInt();
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -259,10 +257,7 @@ class Money implements \Serializable
|
|||
$this->value -= $value;
|
||||
} elseif ($value instanceof Money) {
|
||||
$this->value -= $value->getInt();
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,10 +108,6 @@ class FileLogger implements LoggerInterface
|
|||
$path = realpath($lpath);
|
||||
$this->verbose = $verbose;
|
||||
|
||||
if ($path !== false && StringUtils::startsWith($path, ROOT_PATH) === false) {
|
||||
throw new PathException($lpath);
|
||||
}
|
||||
|
||||
if (is_dir($lpath) || strpos($lpath, '.') === false) {
|
||||
$path = $path . '/' . date('Y-m-d') . '.log';
|
||||
} else {
|
||||
|
|
@ -266,7 +262,7 @@ class FileLogger implements LoggerInterface
|
|||
|
||||
$backtrace = json_encode($backtrace);
|
||||
|
||||
$replace['{backtrace}'] = str_replace(str_replace('\\', '\\\\', ROOT_PATH), '', $backtrace);
|
||||
$replace['{backtrace}'] = $backtrace;
|
||||
$replace['{datetime}'] = sprintf('%--19s', (new \DateTime('NOW'))->format('Y-m-d H:i:s'));
|
||||
$replace['{level}'] = sprintf('%--12s', $level);
|
||||
$replace['{path}'] = $_SERVER['REQUEST_URI'] ?? 'REQUEST_URI';
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Message;
|
||||
|
||||
use phpOMS\DataStorage\Cookie\CookieJar;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
/**
|
||||
* Response class.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -197,6 +197,8 @@ class Header extends HeaderAbstract
|
|||
}
|
||||
}
|
||||
|
||||
header("X-Powered-By: hidden");
|
||||
|
||||
$this->lock();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ namespace phpOMS\Message\Http;
|
|||
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\RequestSource;
|
||||
use phpOMS\Router\RouteVerb;
|
||||
use phpOMS\Uri\Http;
|
||||
use phpOMS\Uri\UriFactory;
|
||||
|
|
@ -38,14 +39,6 @@ use phpOMS\Uri\UriInterface;
|
|||
class Request extends RequestAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Path.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $path = null;
|
||||
|
||||
/**
|
||||
* Uploaded files.
|
||||
*
|
||||
|
|
@ -59,14 +52,14 @@ class Request extends RequestAbstract
|
|||
* @var BrowserType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $browser = null;
|
||||
private $browser = BrowserType::CHROME;
|
||||
/**
|
||||
* OS type.
|
||||
*
|
||||
* @var OSType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $os = null;
|
||||
private $os = OSType::LINUX;
|
||||
/**
|
||||
* Request information.
|
||||
*
|
||||
|
|
@ -88,6 +81,10 @@ class Request extends RequestAbstract
|
|||
{
|
||||
$this->l11n = $l11n;
|
||||
$this->uri = $uri;
|
||||
$this->source = RequestSource::WEB;
|
||||
$this->header = new Header();
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,12 +99,11 @@ class Request extends RequestAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function init($uri = null) /* : void */
|
||||
private function init() /* : void */
|
||||
{
|
||||
if (!isset($uri) && !isset($this->uri)) {
|
||||
if (!isset($this->uri)) {
|
||||
$this->initCurrentRequest();
|
||||
} else {
|
||||
$this->initPseudoRequest($uri ?? $this->uri->__toString());
|
||||
$this->lock();
|
||||
}
|
||||
|
||||
$this->data = array_change_key_case($this->data, CASE_LOWER);
|
||||
|
|
@ -117,8 +113,6 @@ class Request extends RequestAbstract
|
|||
$this->path = explode('/', $this->uri->getPath());
|
||||
|
||||
$this->setupUriBuilder();
|
||||
$this->createRequestHashs();
|
||||
$this->lock();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,29 +158,16 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
private function loadRequestLanguage() : string
|
||||
{
|
||||
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
|
||||
$lang = explode(';', $lang);
|
||||
if(!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
return 'EN';
|
||||
}
|
||||
|
||||
$lang = explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
$lang = explode('-', $lang[0]);
|
||||
|
||||
return $lang[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Init pseudo request
|
||||
*
|
||||
* @param mixed $uri Uri to handle as request
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function initPseudoRequest($uri) /* : void */
|
||||
{
|
||||
$this->setMethod($uri['type']);
|
||||
$this->uri->set($uri['uri']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up globals that musn't be used any longer
|
||||
*
|
||||
|
|
@ -232,39 +213,30 @@ class Request extends RequestAbstract
|
|||
/**
|
||||
* Create request hashs of current request
|
||||
*
|
||||
* The hashes are based on the request path and can be used as unique id.
|
||||
*
|
||||
* @param int $start Start hash from n-th path element
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo: maybe change to normal path string e.g. /some/path/here instead of hash! Remember to adjust navigation elements
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function createRequestHashs() /* : void */
|
||||
public function createRequestHashs(int $start = 0) /* : void */
|
||||
{
|
||||
$this->hash = [];
|
||||
foreach ($this->path as $key => $path) {
|
||||
$paths = [];
|
||||
for ($i = 1; $i < $key + 1; $i++) {
|
||||
for ($i = $start; $i < $key + 1; $i++) {
|
||||
$paths[] = $this->path[$i];
|
||||
}
|
||||
|
||||
$this->hash[] = $this->hashRequest($paths);
|
||||
$this->hash[] = sha1(implode('', $paths));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate request hash.
|
||||
*
|
||||
* @param array $request Request array
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private function hashRequest(array $request) : string
|
||||
{
|
||||
return sha1(implode('', $request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Mobile
|
||||
*
|
||||
|
|
@ -276,7 +248,7 @@ class Request extends RequestAbstract
|
|||
public function isMobile() : bool
|
||||
{
|
||||
// TODO: maybe replace this with smart media queries... checked gets handled in reverse!!!
|
||||
$useragent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$useragent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
||||
|
||||
if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', $useragent)) {
|
||||
return true;
|
||||
|
|
@ -301,12 +273,12 @@ class Request extends RequestAbstract
|
|||
/**
|
||||
* Determine request browser.
|
||||
*
|
||||
* @return BrowserType
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getBrowser() : BrowserType
|
||||
public function getBrowser() : string
|
||||
{
|
||||
if (!isset($this->browser)) {
|
||||
$arr = BrowserType::getConstants();
|
||||
|
|
@ -322,6 +294,16 @@ class Request extends RequestAbstract
|
|||
return $this->browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set browser type
|
||||
*
|
||||
* @param string $browser Browser type
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setBrowser(string $browser) /* : void */
|
||||
{
|
||||
$this->browser = $browser;
|
||||
|
|
@ -351,22 +333,19 @@ class Request extends RequestAbstract
|
|||
return $this->os;
|
||||
}
|
||||
|
||||
public function setOS(string $os) /* : void */
|
||||
{
|
||||
$this->os = $os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request hashes.
|
||||
* Set OS type
|
||||
*
|
||||
* @return array Request hashes
|
||||
* @param string $os OS type
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getHash() : array
|
||||
public function setOS(string $os) /* : void */
|
||||
{
|
||||
return $this->hash;
|
||||
$this->os = $os;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -374,7 +353,7 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
public function getOrigin() : string
|
||||
{
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
return $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -394,10 +373,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')
|
||||
|| (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https')
|
||||
|| (($_SERVER['HTTP_X_FORWARDED_SSL'] ?? '') === 'on')
|
||||
|| ($_SERVER['SERVER_PORT'] ?? '') == $port;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -421,7 +400,7 @@ class Request extends RequestAbstract
|
|||
*/
|
||||
public function getProtocolVersion() : string
|
||||
{
|
||||
return $_SERVER['SERVER_PROTOCOL'];
|
||||
return $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -472,6 +451,8 @@ class Request extends RequestAbstract
|
|||
return RouteVerb::PUT;
|
||||
case RequestMethod::POST:
|
||||
return RouteVerb::SET;
|
||||
case RequestMethod::DELETE:
|
||||
return RouteVerb::DELETE;
|
||||
default:
|
||||
throw new \Exception();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Rest
|
|||
/**
|
||||
* Make request.
|
||||
*
|
||||
* @param mixed $data Data to pass
|
||||
* @param Request $request Request
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
|
|
@ -49,7 +49,7 @@ class Rest
|
|||
case RequestMethod::POST:
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
|
||||
if ($data) {
|
||||
if ($request->getData() !== null) {
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData());
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -59,28 +59,6 @@ interface MessageInterface
|
|||
*/
|
||||
public function getBody() : string;
|
||||
|
||||
/**
|
||||
* Set status code.
|
||||
*
|
||||
* @param string $status Status code
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setStatusCode(string $status) /* : void */;
|
||||
|
||||
/**
|
||||
* Get status code.
|
||||
*
|
||||
* @return string Status code
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getStatusCode() : string;
|
||||
|
||||
/**
|
||||
* Get account id.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
Request
|
||||
|
|
@ -74,7 +74,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $data = null;
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* Request data.
|
||||
|
|
@ -114,15 +114,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
* @var \phpOMS\Message\RequestSource
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $source = null;
|
||||
|
||||
/**
|
||||
* Request status.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $status = null;
|
||||
private $source = null;
|
||||
|
||||
/**
|
||||
* Request hash.
|
||||
|
|
@ -140,6 +132,12 @@ abstract class RequestAbstract implements MessageInterface
|
|||
*/
|
||||
protected $lock = false;
|
||||
|
||||
/**
|
||||
* Request header.
|
||||
*
|
||||
* @var HeaderAbstract
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $header = null;
|
||||
|
||||
/**
|
||||
|
|
@ -206,7 +204,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
*/
|
||||
public function getRequestSource()
|
||||
{
|
||||
return self::$source;
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -218,7 +216,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
throw new InvalidEnumValue($source);
|
||||
}
|
||||
|
||||
self::$source = $source;
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -256,42 +254,18 @@ abstract class RequestAbstract implements MessageInterface
|
|||
return $this->path[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request type.
|
||||
*
|
||||
* E.g. M_JSON
|
||||
*
|
||||
* @param string $type Request type
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setType(string $type) /* : void */
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request type.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getType() : string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData($key = null)
|
||||
{
|
||||
if(!isset($key)) {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
$key = mb_strtolower($key);
|
||||
|
||||
return !isset($key) ? $this->data : $this->data[$key] ?? null;
|
||||
return $this->data[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -357,22 +331,6 @@ abstract class RequestAbstract implements MessageInterface
|
|||
$this->account = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setStatusCode(string $status) /* : void */
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getStatusCode() : string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request header.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ use phpOMS\Datatypes\Enum;
|
|||
abstract class ResponseType extends Enum
|
||||
{
|
||||
/* public */ const HTTP = 0; /* HTTP */
|
||||
/* public */ const JSON = 1; /* JSON */
|
||||
/* public */ const SOCKET = 2; /* Socket */
|
||||
/* public */ const CONSOLE = 3; /* Console */
|
||||
/* public */ const SOCKET = 1; /* Socket */
|
||||
/* public */ const CONSOLE = 2; /* Console */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class Head implements RenderableInterface
|
|||
/**
|
||||
* Set page title.
|
||||
*
|
||||
* @param string $type Asset type
|
||||
* @param int $type Asset type
|
||||
* @param string $uri Asset uri
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -156,7 +156,7 @@ class Head implements RenderableInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addAsset(string $type, string $uri) /* : void */
|
||||
public function addAsset(int $type, string $uri) /* : void */
|
||||
{
|
||||
$this->assets[$uri] = $type;
|
||||
}
|
||||
|
|
@ -308,7 +308,7 @@ class Head implements RenderableInterface
|
|||
{
|
||||
$asset = '';
|
||||
foreach ($this->assets as $uri => $type) {
|
||||
if ($type == AssetType::CSS) {
|
||||
if ($type === AssetType::CSS) {
|
||||
$asset .= '<link rel="stylesheet" type="text/css" href="' . $uri . '">';
|
||||
} elseif ($type === AssetType::JS) {
|
||||
$asset .= '<script src="' . $uri . '"></script>';
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class ActivateAbstract
|
|||
*/
|
||||
public static function activate(DatabasePool $dbPool, InfoManager $info) /* : void */
|
||||
{
|
||||
self::activateRoutes(ROOT_PATH . '/Web/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/http.php');
|
||||
self::activateRoutes(__DIR__ . '/../../Web/Routes.php', __DIR__ . '/../../Modules/' . $info->getDirectory() . '/Admin/Routes/http.php');
|
||||
self::activateInDatabase($dbPool, $info);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class DeactivateAbstract
|
|||
*/
|
||||
public static function deactivate(DatabasePool $dbPool, InfoManager $info) /* : void */
|
||||
{
|
||||
self::deactivateRoutes(ROOT_PATH . '/Web/Routes.php', ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes/http.php');
|
||||
self::deactivateRoutes(__DIR__ . '/../../Web/Routes.php', __DIR__ . '/../../Modules/' . $info->getDirectory() . '/Admin/Routes/http.php');
|
||||
self::deactivateInDatabase($dbPool, $info);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,20 @@ class InfoManager
|
|||
*/
|
||||
public function __construct($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
$this->path = realpath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info path
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function getPath() : string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -75,8 +88,8 @@ class InfoManager
|
|||
*/
|
||||
public function load() /* : void */
|
||||
{
|
||||
if (!file_exists($this->path)) {
|
||||
throw new PathException($this->path);
|
||||
if ($this->path === false || !file_exists($this->path)) {
|
||||
throw new PathException((string) $this->path);
|
||||
}
|
||||
|
||||
$this->info = json_decode(file_get_contents($this->path), true);
|
||||
|
|
@ -92,8 +105,8 @@ class InfoManager
|
|||
*/
|
||||
public function update() /* : void */
|
||||
{
|
||||
if (!file_exists($this->path)) {
|
||||
throw new PathException($this->path);
|
||||
if ($this->path === false || !file_exists($this->path)) {
|
||||
throw new PathException((string) $this->path);
|
||||
}
|
||||
|
||||
file_put_contents($this->path, json_encode($this->info, JSON_PRETTY_PRINT));
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class InstallerAbstract
|
|||
/**
|
||||
* Install module.
|
||||
*
|
||||
* @param string $routePath Route Path
|
||||
* @param string $modulePath Route Path
|
||||
* @param DatabasePool $dbPool Database instance
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
|
|
@ -101,10 +101,10 @@ class InstallerAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function install(string $routePath, DatabasePool $dbPool, InfoManager $info) /* : void */
|
||||
public static function install(string $modulePath, DatabasePool $dbPool, InfoManager $info) /* : void */
|
||||
{
|
||||
self::registerInDatabase($dbPool, $info);
|
||||
self::initRoutes($routePath, $info);
|
||||
self::initRoutes($modulePath, $info);
|
||||
self::activate($dbPool, $info);
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ class InstallerAbstract
|
|||
/**
|
||||
* Re-init module.
|
||||
*
|
||||
* @param string $routePath Route Path
|
||||
* @param string $modulePath Route Path
|
||||
* @param InfoManager $info Module info
|
||||
*
|
||||
* @return void
|
||||
|
|
@ -137,9 +137,9 @@ class InstallerAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function reInit(string $routePath, InfoManager $info) /* : void */
|
||||
public static function reInit(string $modulePath, InfoManager $info) /* : void */
|
||||
{
|
||||
self::initRoutes($routePath, $info);
|
||||
self::initRoutes($modulePath, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,15 +155,15 @@ class InstallerAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function initRoutes(string $routePath, InfoManager $info) /* : void */
|
||||
private static function initRoutes(string $modulePath, InfoManager $info) /* : void */
|
||||
{
|
||||
// todo: maybe use static::__DIR__ ?
|
||||
$directories = new Directory(ROOT_PATH . '/Modules/' . $info->getDirectory() . '/Admin/Routes');
|
||||
$directories = new Directory($modulePath . '/Admin/Routes');
|
||||
|
||||
foreach ($directories as $key => $subdir) {
|
||||
if ($subdir instanceof Directory) {
|
||||
foreach ($subdir as $key2 => $file) {
|
||||
self::installRoutes($routePath . '/' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
|
||||
self::installRoutes(__DIR__ . '/../../' . $subdir->getName() . '/' . basename($file->getName(), '.php') . '/Routes.php', $file->getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,14 +39,6 @@ use phpOMS\System\File\PathException;
|
|||
class ModuleManager
|
||||
{
|
||||
|
||||
/**
|
||||
* Module path.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
/* public */ const MODULE_PATH = __DIR__ . '/../../Modules';
|
||||
|
||||
/**
|
||||
* All modules that are running on this uri.
|
||||
*
|
||||
|
|
@ -79,13 +71,21 @@ class ModuleManager
|
|||
*/
|
||||
private $active = null;
|
||||
|
||||
/**
|
||||
* Module path.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $modulePath = __DIR__ . '/../../Modules';
|
||||
|
||||
/**
|
||||
* All modules in the module directory.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $all = null;
|
||||
private $all = null;
|
||||
|
||||
/**
|
||||
* To load based on request uri.
|
||||
|
|
@ -103,9 +103,10 @@ class ModuleManager
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct(ApplicationAbstract $app)
|
||||
public function __construct(ApplicationAbstract $app, string $modulePath = '')
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->modulePath = $modulePath;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -239,15 +240,15 @@ class ModuleManager
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public static function getAllModules() : array
|
||||
public function getAllModules() : array
|
||||
{
|
||||
if (!isset(self::$all)) {
|
||||
chdir(self::MODULE_PATH);
|
||||
if (!isset($this->all)) {
|
||||
chdir($this->modulePath);
|
||||
$files = glob('*', GLOB_ONLYDIR);
|
||||
$c = count($files);
|
||||
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
$path = self::MODULE_PATH . '/' . $files[$i] . '/info.json';
|
||||
$path = $this->modulePath . '/' . $files[$i] . '/info.json';
|
||||
|
||||
if (!file_exists($path)) {
|
||||
continue;
|
||||
|
|
@ -255,11 +256,11 @@ class ModuleManager
|
|||
}
|
||||
|
||||
$json = json_decode(file_get_contents($path), true);
|
||||
self::$all[$json['name']['internal']] = $json;
|
||||
$this->all[$json['name']['internal']] = $json;
|
||||
}
|
||||
}
|
||||
|
||||
return self::$all;
|
||||
return $this->all;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -368,7 +369,7 @@ class ModuleManager
|
|||
throw new \Exception('Module installer does not exist');
|
||||
}
|
||||
|
||||
$class::reInit(ROOT_PATH, $info);
|
||||
$class::reInit($this->modulePath, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -389,7 +390,7 @@ class ModuleManager
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists(self::MODULE_PATH . '/' . $module . '/Admin/Installer.php')) {
|
||||
if (!file_exists($this->modulePath . '/' . $module . '/Admin/Installer.php')) {
|
||||
// todo download;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -463,7 +464,7 @@ class ModuleManager
|
|||
throw new \Exception('Module installer does not exist');
|
||||
}
|
||||
|
||||
$class::install(ROOT_PATH, $this->app->dbPool, $info);
|
||||
$class::install($this->modulePath, $this->app->dbPool, $info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -526,7 +527,7 @@ class ModuleManager
|
|||
*/
|
||||
private function loadInfo(string $module) : InfoManager
|
||||
{
|
||||
$path = realpath($oldPath = self::MODULE_PATH . '/' . $module . '/' . 'info.json');
|
||||
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/' . 'info.json');
|
||||
|
||||
if ($path === false) {
|
||||
throw new PathException($oldPath);
|
||||
|
|
@ -576,10 +577,10 @@ class ModuleManager
|
|||
*/
|
||||
public function installProviding(string $from, string $for) /* : void */
|
||||
{
|
||||
if (file_exists(self::MODULE_PATH . '/' . $from . '/Admin/Install/' . $for . '.php')) {
|
||||
if (file_exists($this->modulePath . '/' . $from . '/Admin/Install/' . $for . '.php')) {
|
||||
$class = '\\Modules\\' . $from . '\\Admin\\Install\\' . $for;
|
||||
/** @var $class InstallerAbstract */
|
||||
$class::install(ROOT_PATH, $this->app->dbPool, null);
|
||||
$class::install($this->modulePath, $this->app->dbPool, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class Router
|
|||
*/
|
||||
public function importFromFile(string $path) : bool
|
||||
{
|
||||
if (stream_resolve_include_path($path) !== false) {
|
||||
if (file_exists($path)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$this->routes += include $path;
|
||||
|
||||
|
|
@ -100,12 +100,12 @@ class Router
|
|||
/**
|
||||
* Route request.
|
||||
*
|
||||
* @param RequestAbstract $request Request to route
|
||||
* @param string|RequestAbstract $request Request to route
|
||||
* @param int $verb Route verb
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
|
|
@ -118,7 +118,7 @@ class Router
|
|||
} elseif (is_string($request)) {
|
||||
$uri = $request;
|
||||
} else {
|
||||
throw new \Exception();
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$bound = [];
|
||||
|
|
@ -148,6 +148,6 @@ class Router
|
|||
*/
|
||||
private function match(string $route, int $routeVerb, string $uri, int $remoteVerb = RouteVerb::GET) : bool
|
||||
{
|
||||
return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb == RouteVerb::ANY || ($remoteVerb & $routeVerb) === $remoteVerb);
|
||||
return (bool) preg_match('~^' . $route . '$~', $uri) && ($routeVerb === RouteVerb::ANY || $remoteVerb === RouteVerb::ANY || ($remoteVerb & $routeVerb) === $remoteVerb);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ use phpOMS\Datatypes\Enum;
|
|||
*/
|
||||
abstract class PriorityMode extends Enum
|
||||
{
|
||||
/* public */ const FIFO = 0;
|
||||
/* public */ const LIFO = 0;
|
||||
/* public */ const EARLIEST_DEADLINE = 0;
|
||||
/* public */ const SHORTEST_JOB = 0;
|
||||
/* public */ const HIGHEST = 0;
|
||||
/* public */ const LOWEST = 0;
|
||||
/* public */ const FIFO = 1;
|
||||
/* public */ const LIFO = 2;
|
||||
/* public */ const EARLIEST_DEADLINE = 4;
|
||||
/* public */ const SHORTEST_JOB = 8;
|
||||
/* public */ const HIGHEST = 16;
|
||||
/* public */ const LOWEST = 32;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use phpOMS\System\File\ContainerInterface;
|
|||
use phpOMS\System\File\DirectoryInterface;
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\Utils\StringUtils;
|
||||
use phpOMS\System\File\Local\FileAbstract;
|
||||
use phpOMS\System\File\Local\Directory as DirectoryLocal;
|
||||
|
||||
/**
|
||||
|
|
@ -158,4 +159,149 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
{
|
||||
return DirectoryLocal::basename($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getNode(string $name) : FileAbstract
|
||||
{
|
||||
return $this->nodes[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNode() : bool
|
||||
{
|
||||
return self::create($this->path, $this->permission, true);
|
||||
|
||||
// todo: add node
|
||||
}
|
||||
|
||||
public function addNode($file) : bool
|
||||
{
|
||||
$this->count += $file->getCount();
|
||||
$this->size += $file->getSize();
|
||||
$this->nodes[$file->getName()] = $file;
|
||||
|
||||
return $file->createNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getParent() : ContainerInterface
|
||||
{
|
||||
// TODO: Implement getParent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function copyNode(string $to, bool $overwrite = false) : bool
|
||||
{
|
||||
// TODO: Implement copyNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function moveNode(string $to, bool $overwrite = false) : bool
|
||||
{
|
||||
// TODO: Implement moveNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteNode() : bool
|
||||
{
|
||||
// TODO: Implement deleteNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
reset($this->nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
return next($this->nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
$key = key($this->nodes);
|
||||
|
||||
return ($key !== null && $key !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
if (is_null($offset)) {
|
||||
$this->addNode($value);
|
||||
} else {
|
||||
$this->nodes[$offset] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->nodes[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
if (isset($this->nodes[$offset])) {
|
||||
unset($this->nodes[$offset]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@ use phpOMS\System\File\ContentPutMode;
|
|||
use phpOMS\System\File\FileInterface;
|
||||
use phpOMS\System\File\PathException;
|
||||
use phpOMS\System\File\Local\File as FileLocal;
|
||||
use phpOMS\System\File\Local\FileAbstract;
|
||||
use phpOMS\System\File\Local\Directory as DirectoryLocal;
|
||||
|
||||
/**
|
||||
|
|
@ -330,4 +331,170 @@ class File extends FileAbstract implements FileInterface
|
|||
{
|
||||
return FileLocal::extension($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent path of the resource.
|
||||
*
|
||||
* The parent resource path is always a directory.
|
||||
*
|
||||
* @return ContainerInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getParent() : ContainerInterface
|
||||
{
|
||||
// TODO: Implement getParent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Create resource at destination path.
|
||||
*
|
||||
* @return bool True on success and false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function createNode() : bool
|
||||
{
|
||||
// TODO: Implement createNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy resource to different location.
|
||||
*
|
||||
* @param string $to Path of the resource to copy to
|
||||
* @param bool $overwrite Overwrite/replace existing file
|
||||
*
|
||||
* @return bool True on success and false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function copyNode(string $to, bool $overwrite = false) : bool
|
||||
{
|
||||
// TODO: Implement copyNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Move resource to different location.
|
||||
*
|
||||
* @param string $to Path of the resource to move to
|
||||
* @param bool $overwrite Overwrite/replace existing file
|
||||
*
|
||||
* @return bool True on success and false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function moveNode(string $to, bool $overwrite = false) : bool
|
||||
{
|
||||
// TODO: Implement moveNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete resource at destination path.
|
||||
*
|
||||
* @return bool True on success and false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function deleteNode() : bool
|
||||
{
|
||||
// TODO: Implement deleteNode() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to file.
|
||||
*
|
||||
* @param string $content Content to save in file
|
||||
* @param int $mode Mode (overwrite, append)
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function putContent(string $content, int $mode = ContentPutMode::APPEND | ContentPutMode::CREATE) : bool
|
||||
{
|
||||
// TODO: Implement putContent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to file.
|
||||
*
|
||||
* Creates new file if it doesn't exist or overwrites existing file.
|
||||
*
|
||||
* @param string $content Content to save in file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function setContent(string $content) : bool
|
||||
{
|
||||
// TODO: Implement setContent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to file.
|
||||
*
|
||||
* Creates new file if it doesn't exist or overwrites existing file.
|
||||
*
|
||||
* @param string $content Content to save in file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function appendContent(string $content) : bool
|
||||
{
|
||||
// TODO: Implement appendContent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Save content to file.
|
||||
*
|
||||
* Creates new file if it doesn't exist or overwrites existing file.
|
||||
*
|
||||
* @param string $content Content to save in file
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function prependContent(string $content) : bool
|
||||
{
|
||||
// TODO: Implement prependContent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content from file.
|
||||
*
|
||||
* @return string Content of file
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getContent() : string
|
||||
{
|
||||
// TODO: Implement getContent() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file extension.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getExtension() : string
|
||||
{
|
||||
// TODO: Implement getExtension() method.
|
||||
}
|
||||
}
|
||||
|
|
@ -72,6 +72,17 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all files in directorz.
|
||||
*
|
||||
* @param string $path Path
|
||||
* @param string $filter Filter
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function list(string $path, string $filter = '*') : array
|
||||
{
|
||||
$list = [];
|
||||
|
|
|
|||
|
|
@ -40,15 +40,14 @@ final class OperatingSystem
|
|||
*/
|
||||
public static function getSystem() : int
|
||||
{
|
||||
switch (PHP_OS) {
|
||||
case stristr(PHP_OS, 'DAR'):
|
||||
return SystemType::OSX;
|
||||
case stristr(PHP_OS, 'WIN'):
|
||||
return SystemType::WIN;
|
||||
case stristr(PHP_OS, 'LINIX'):
|
||||
return SystemType::LINUX;
|
||||
default:
|
||||
return SystemType::UNKNOWN;
|
||||
}
|
||||
if(stristr(PHP_OS, 'DAR') !== false) {
|
||||
return SystemType::OSX;
|
||||
} elseif(stristr(PHP_OS, 'WIN') !== false) {
|
||||
return SystemType::WIN;
|
||||
} elseif(stristr(PHP_OS, 'LINUX') !== false) {
|
||||
return SystemType::LINUX;
|
||||
}
|
||||
|
||||
return SystemType::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
@ -112,11 +112,11 @@ class SystemUtils
|
|||
{
|
||||
$cpuusage = 0;
|
||||
|
||||
if (stristr(PHP_OS, 'WIN')) {
|
||||
if (stristr(PHP_OS, 'WIN') !== false) {
|
||||
exec('wmic cpu get LoadPercentage', $cpuusage);
|
||||
$cpuusage = $cpuusage[1];
|
||||
} elseif (stristr(PHP_OS, 'LINUX')) {
|
||||
$cpuusage = \sys_getloadavg()[0];
|
||||
} elseif (stristr(PHP_OS, 'LINUX') !== false) {
|
||||
$cpuusage = \sys_getloadavg()[0] * 100;
|
||||
}
|
||||
|
||||
return (int) $cpuusage;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ final class UnhandledHandler
|
|||
*/
|
||||
public static function exceptionHandler($e) /* : void */
|
||||
{
|
||||
$logger = FileLogger::getInstance(ROOT_PATH . '/Logs');
|
||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||
$logger->critical(FileLogger::MSG_FULL, [
|
||||
'message' => $e->getMessage(),
|
||||
'line' => $e->getLine(),
|
||||
|
|
@ -74,7 +74,7 @@ final class UnhandledHandler
|
|||
return false;
|
||||
}
|
||||
|
||||
$logger = FileLogger::getInstance(ROOT_PATH . '/Logs');
|
||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||
$logger->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'Unhandled error',
|
||||
'line' => $errline,
|
||||
|
|
@ -116,7 +116,7 @@ final class UnhandledHandler
|
|||
$e = error_get_last();
|
||||
|
||||
if (isset($e)) {
|
||||
$logger = FileLogger::getInstance(ROOT_PATH . '/Logs');
|
||||
$logger = FileLogger::getInstance(__DIR__ . '/../Logs');
|
||||
$logger->warning(FileLogger::MSG_FULL, [
|
||||
'message' => $e['message'],
|
||||
'line' => $e['line'],
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace phpOMS\Utils;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Color
|
||||
class ColorUtils
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
@ -83,4 +83,25 @@ class Color
|
|||
|
||||
return $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert int to rgb
|
||||
*
|
||||
* @param int $rgbInt Value to convert
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function intToRgb(int $rgbInt) : array
|
||||
{
|
||||
$rgb = ['r' => 0, 'g' => 0, 'b' => 0];
|
||||
|
||||
$rgb['b'] = $rgbInt & 255;
|
||||
$rgb['g'] = ($rgbInt >> 8) & 255;
|
||||
$rgb['r'] = ($rgbInt >> 16) & 255;
|
||||
|
||||
return $rgb;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,13 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Utils\Converter;
|
||||
|
||||
use phpOMS\Localization\ISO4217CharEnum;
|
||||
use phpOMS\Message\Http\Rest;
|
||||
use phpOMS\Message\Http\Request;
|
||||
use phpOMS\Message\Http\RequestMethod;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Uri\Http;
|
||||
|
||||
/**
|
||||
* Currency converter.
|
||||
*
|
||||
|
|
@ -98,16 +105,19 @@ class Currency
|
|||
public static function getEcbEuroRates() : array
|
||||
{
|
||||
if (!isset(self::$ecbCurrencies)) {
|
||||
$xml = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
|
||||
$xml = new \SimpleXMLElement($xml);
|
||||
$request = new Request(new Localization(), new Http('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
|
||||
$request->setMethod(RequestMethod::GET);
|
||||
|
||||
if (isset($xml->Cube)) {
|
||||
$node = $xml->Cube->Cube->Cube;
|
||||
} else {
|
||||
$xml = new \SimpleXMLElement(Rest::request($request));
|
||||
|
||||
if (!isset($xml->Cube)) {
|
||||
throw new \Exception('Invalid xml path');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$node = $xml->Cube->Cube->Cube;
|
||||
self::$ecbCurrencies = [];
|
||||
|
||||
foreach ($node as $key => $value) {
|
||||
self::$ecbCurrencies[strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate'];
|
||||
}
|
||||
|
|
@ -157,14 +167,14 @@ class Currency
|
|||
$from = strtoupper($from);
|
||||
$to = strtoupper($to);
|
||||
|
||||
if ((!isset($currencies[$from]) && $from !== 'EUR') || (!isset($currencies[$to]) && $to !== 'EUR')) {
|
||||
if ((!isset($currencies[$from]) && $from !== ISO4217CharEnum::_EUR) || (!isset($currencies[$to]) && $to !== ISO4217CharEnum::_EUR)) {
|
||||
throw new \InvalidArgumentException('Currency doesn\'t exists');
|
||||
}
|
||||
|
||||
if ($from !== 'EUR') {
|
||||
if ($from !== ISO4217CharEnum::_EUR) {
|
||||
$value /= $currencies[$from];
|
||||
}
|
||||
|
||||
return $to === 'EUR' ? $value : $value * $currencies[$to];
|
||||
return $to === ISO4217CharEnum::_EUR ? $value : $value * $currencies[$to];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,59 +30,12 @@ namespace phpOMS\Utils\Converter;
|
|||
*/
|
||||
class Ip
|
||||
{
|
||||
/* public */ const IP_TABLE_PATH = __DIR__ . '/../../Localization/Default/Ip/ipGeoLocation.csv';
|
||||
/* public */ const IP_TABLE_ITERATIONS = 100;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function ip2Country(string $ip) : string
|
||||
{
|
||||
$fh = fopen(self::IP_TABLE_PATH, 'r');
|
||||
|
||||
fseek($fh, 0, SEEK_END);
|
||||
$end = ftell($fh);
|
||||
fseek($fh, 0);
|
||||
$start = 0;
|
||||
$current = $start;
|
||||
|
||||
$ip = self::ip2Float($ip);
|
||||
$country = '';
|
||||
$counter = 0;
|
||||
|
||||
while ($counter < self::IP_TABLE_ITERATIONS) {
|
||||
$line = fgets($fh, 150);
|
||||
if ($current !== 0) {
|
||||
$line = fgets($fh, 150);
|
||||
}
|
||||
|
||||
$split = explode(',', $line);
|
||||
|
||||
if ($ip >= $split[0] && $ip <= $split[1]) {
|
||||
$country = $split[2];
|
||||
break;
|
||||
}
|
||||
|
||||
if ($ip > $split[1]) {
|
||||
$larger = true;
|
||||
$start = $current;
|
||||
fseek($fh, (int) (($end - $current) / 2), SEEK_CUR);
|
||||
} else {
|
||||
$larger = false;
|
||||
$end = $current;
|
||||
fseek($fh, (int) (($start - $current) / 2), SEEK_CUR);
|
||||
}
|
||||
|
||||
$counter++;
|
||||
$current = ftell($fh);
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
|
||||
return $country;
|
||||
}
|
||||
|
||||
public static function ip2Float(string $ip) : float
|
||||
{
|
||||
$split = explode('.', $ip);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ declare(strict_types=1);
|
|||
namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
||||
|
||||
/**
|
||||
* EDI 850 - Purchase order.
|
||||
* EDI
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\Converter
|
||||
|
|
@ -28,13 +28,18 @@ namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class EDI850
|
||||
abstract class EDIAbstract
|
||||
{
|
||||
private $header = null;
|
||||
|
||||
private $heading = null;
|
||||
|
||||
private $detail = [];
|
||||
private $detail = null;
|
||||
|
||||
private $summary = null;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->header = new Header();
|
||||
}
|
||||
}
|
||||
|
|
@ -32,5 +32,149 @@ class FunctionalGroupHedaer
|
|||
{
|
||||
private $functionalGroupHeader = 'GS';
|
||||
|
||||
private $functionIdentiferCode = FunctionalIdentifierCode::PO;
|
||||
private $functionalIdentifierCode = FunctionalIdentifierCode::PO;
|
||||
|
||||
private $applicationSenderCode = '';
|
||||
|
||||
private $appicationReceiverCode = '';
|
||||
|
||||
private $date = null;
|
||||
|
||||
private $groupControlNumber = 0;
|
||||
|
||||
private $responsibleAgencyCode = '';
|
||||
|
||||
private $version = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date = new \DateTime();
|
||||
}
|
||||
|
||||
public function getFunctionalGroupHeader() : string
|
||||
{
|
||||
return $this->functionalGroupHeader;
|
||||
}
|
||||
|
||||
public function getFunctionalIdentifierCode() : string
|
||||
{
|
||||
return $this->functionalIdentifierCode;
|
||||
}
|
||||
|
||||
public function setFunctionalIdentifierCode(string $code) /* : void */
|
||||
{
|
||||
if(!FunctionalIdentifierCode::isValidValue($code)) {
|
||||
throw \Exception();
|
||||
}
|
||||
|
||||
$this->functionalIdentifierCode = $code;
|
||||
}
|
||||
|
||||
public function getApplicationSenderCode() : string
|
||||
{
|
||||
return str_pad((string) $this->applicationSenderCode, 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function setApplicationSenderCode(string $code) /* : void */
|
||||
{
|
||||
if(strlen($code) < 2 || strlen($code) > 15) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->applicationSenderCode = $code;
|
||||
}
|
||||
|
||||
public function getApplicationReceiverCode() : string
|
||||
{
|
||||
return str_pad((string) $this->applicationReceiverCode, 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function setApplicationReceiverCode(string $code) /* : void */
|
||||
{
|
||||
if(strlen($code) < 2 || strlen($code) > 15) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->applicationReceiverCode = $code;
|
||||
}
|
||||
|
||||
public function setDate(\DateTime $date) /* : void */
|
||||
{
|
||||
$this->date = $date;
|
||||
}
|
||||
|
||||
public function getDate() : string
|
||||
{
|
||||
return $this->date->format('d:m:y');
|
||||
}
|
||||
|
||||
public function getTime() : string
|
||||
{
|
||||
return $this->date->format('d:m:y');
|
||||
}
|
||||
|
||||
public function getGroupControlNumber() : int
|
||||
{
|
||||
return $this->groupControlNumber;
|
||||
}
|
||||
|
||||
public function setGroupControlNumber(int $number) /* : void */
|
||||
{
|
||||
if($number < 0) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->groupControlNumber = $number;
|
||||
}
|
||||
|
||||
public function getResponsibleAgencyCode() : int
|
||||
{
|
||||
return $this->responsibleAgencyCode;
|
||||
}
|
||||
|
||||
public function setResponsibleAgencyCode(int $code) /* : void */
|
||||
{
|
||||
if($code < 0 || $code > 99) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->responsibleAgencyCode = $code;
|
||||
}
|
||||
|
||||
public function getVersion() : string
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
public function setVersion(string $version) /* : void */
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return $this->functionalGroupHeader . '*'
|
||||
. $this->getfunctionalIdentifierCode() . '*'
|
||||
. $this->getApplicationSenderCode() . '*'
|
||||
. $this->getApplicationReceiverCode() . '*'
|
||||
. $this->getDate() . '*'
|
||||
. $this->getTime() . '*'
|
||||
. $this->getGroupControlNumber() . '*'
|
||||
. $this->getResponsibleAgencyCode() . '*'
|
||||
. $this->getVersion() . '*' . self::COMPONENT_ELEMENT_SEPARATOR;
|
||||
}
|
||||
|
||||
public function unserialize($raw)
|
||||
{
|
||||
$split = explode($raw);
|
||||
|
||||
$this->setFunctionalGroupHeader(trim($split[0]));
|
||||
$this->setFunctionalIdentifierCode(trim($split[1]));
|
||||
$this->setApplicationSenderCode(trim($split[2]));
|
||||
$this->setApplicationReceiverCode(trim($split[3]));
|
||||
$this->setDate(new \DateTime(trim($split[4]) . '-' . trim($split[5])));
|
||||
$this->setGroupControlNumber(trim($split[6]));
|
||||
$this->setResponsibleAgencyCode((int) trim($split[7]));
|
||||
$this->setVersion(trim($split[8]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,5 +32,11 @@ class Header
|
|||
{
|
||||
private $interchangeControlHeader = null;
|
||||
|
||||
private $functionGroupHeader = null;
|
||||
private $functionalGroupHeader = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->interchangeControlHeader = new InterchangeControlHeader();
|
||||
$this->functionalGroupHeader = new FunctionalGroupHeader();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php
Normal file
42
Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
||||
|
||||
use phpOMS\Utils\EDI\AnsiX12\EDIAbstract;
|
||||
|
||||
/**
|
||||
* EDI 850 - Purchase order.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\Converter
|
||||
* @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 EDI850 extends EDIAbstract
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->heading = new EDIT850Heading();
|
||||
$this->detail = new EDIT850Detail();
|
||||
$this->summary = new EDI850Summary();
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,7 @@ namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class EDI850Heading
|
||||
class EDI850Detail
|
||||
{
|
||||
private $detailBaselineItemData = '';
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
||||
namespace phpOMS\Utils\EDI\AnsiX12\Purchase;
|
||||
|
||||
/**
|
||||
* EDI 850 - Purchase order.
|
||||
|
|
@ -30,9 +30,9 @@ namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
|||
*/
|
||||
class EDI850Heading
|
||||
{
|
||||
private $headingTransactionSetHeader = '';
|
||||
private $headingTransactionSetHeader = null;
|
||||
|
||||
private $headingBeginningSegmentPO = '';
|
||||
private $headingBeginningSegmentPO = null;
|
||||
|
||||
private $headingCurrency = '';
|
||||
|
||||
|
|
@ -47,4 +47,9 @@ class EDI850Heading
|
|||
private $headingMarksNumbers = 0;
|
||||
|
||||
private $headingLoopId = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->headingTransactionSetHeader = new TransactionSetHeader();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder;
|
||||
|
||||
/**
|
||||
* EDI 850 - Purchase order.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\Converter
|
||||
* @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 TransactionSetHeader
|
||||
{
|
||||
const IDENTIFIER = 'ST';
|
||||
|
||||
private $transactionSetIdentifierCode = 850;
|
||||
|
||||
private $transactionSetControlNumber = '';
|
||||
|
||||
public function getTransactionSetIdentiferCode() : int
|
||||
{
|
||||
return $this->transactionSetIdentifierCode;
|
||||
}
|
||||
|
||||
public function setTransactionIdentifierCode(int $code) /* : void */
|
||||
{
|
||||
$this->transactionSetIdentifierCode = $code;
|
||||
}
|
||||
|
||||
public function getTransactionSetControlNumber() : string
|
||||
{
|
||||
return str_pad((string) $this->transactionSetControlNumber, 9, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function setTransactionSetControlNumber(string $number) /* : void */
|
||||
{
|
||||
if(strlen($number) < 4 || strlen($number) > 9) {
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
$this->transactionSetControlNumber = $number;
|
||||
}
|
||||
|
||||
public function unserialize($raw)
|
||||
{
|
||||
$split = explode($raw);
|
||||
|
||||
$this->setTransactionSetIdentifierCode((int) trim($split[1]));
|
||||
$this->setTransactionSetControlNumber(trim($split[2]));
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return self::IDENTIFIER . '*'
|
||||
. $this->getTransactionSetIdentifierCode() . '*'
|
||||
. $this->getTransactionSetControlNumber();
|
||||
}
|
||||
}
|
||||
|
|
@ -63,7 +63,7 @@ class Caesar
|
|||
$ascii = ord($source[$i]) + ord($key[$j]);
|
||||
|
||||
if ($ascii > self::LIMIT_UPPER) {
|
||||
$ascii -= self::LIMIT_UPPER;
|
||||
$ascii = self::LIMIT_LOWER + ($ascii - self::LIMIT_UPPER);
|
||||
}
|
||||
|
||||
$result .= chr($ascii);
|
||||
|
|
@ -89,7 +89,7 @@ class Caesar
|
|||
$ascii = ord($raw[$i]) - ord($key[$j]);
|
||||
|
||||
if ($ascii < self::LIMIT_LOWER) {
|
||||
$ascii += self::LIMIT_LOWER;
|
||||
$ascii = self::LIMIT_UPPER + ($ascii - self::LIMIT_LOWER) ;
|
||||
}
|
||||
|
||||
$result .= chr($ascii);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,16 @@ namespace phpOMS\Utils;
|
|||
*/
|
||||
class ImageUtils
|
||||
{
|
||||
/**
|
||||
* Decode base64 image.
|
||||
*
|
||||
* @param string $img Encoded image
|
||||
*
|
||||
* @return string Decoded image
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function decodeBase64Image(string $img) : string
|
||||
{
|
||||
$img = str_replace('data:image/png;base64,', '', $img);
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Country
|
||||
{
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class Currency
|
||||
{
|
||||
}
|
||||
|
|
@ -17,6 +17,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\Utils\RnG;
|
||||
|
||||
class IBAN
|
||||
class Iban
|
||||
{
|
||||
}
|
||||
|
|
@ -73,6 +73,34 @@ class StringUtils
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a string contains any of the provided needles.
|
||||
*
|
||||
* The validation is done case sensitive.
|
||||
*
|
||||
* @param string $haystack Haystack
|
||||
* @param array $needles Needles to check if any of them are part of the haystack
|
||||
*
|
||||
* @example StringUtils::mb_contains('This string', ['This', 'test']); // true
|
||||
* @example StringUtils::mb_contains('This string', 'is st'); // true
|
||||
* @example StringUtils::mb_contains('This string', 'something'); // false
|
||||
*
|
||||
* @return bool The function returns true if any of the needles is part of the haystack, false otherwise.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public static function mb_contains(string $haystack, array $needles) : bool
|
||||
{
|
||||
foreach ($needles as $needle) {
|
||||
if (mb_strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a string ends with a certain string.
|
||||
*
|
||||
|
|
@ -334,4 +362,35 @@ class StringUtils
|
|||
|
||||
return $count;
|
||||
}
|
||||
|
||||
public static function getEntropy(string $value) : float
|
||||
{
|
||||
$entroy = 0.0;
|
||||
$size = mb_strlen($value);
|
||||
$countChars = self::mb_count_chars($value, 1);
|
||||
|
||||
foreach ($countChars as $v) {
|
||||
$p = $v / $size;
|
||||
$entroy -= $p * log($p) / log(2);
|
||||
}
|
||||
|
||||
return $entroy;
|
||||
}
|
||||
|
||||
public static function mb_count_chars(string $input) {
|
||||
$l = mb_strlen($input, 'UTF-8');
|
||||
$unique = [];
|
||||
|
||||
for($i = 0; $i < $l; $i++) {
|
||||
$char = mb_substr($input, $i, 1, 'UTF-8');
|
||||
|
||||
if(!array_key_exists($char, $unique)) {
|
||||
$unique[$char] = 0;
|
||||
}
|
||||
|
||||
$unique[$char]++;
|
||||
}
|
||||
|
||||
return $unique;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,6 @@ abstract class Hostname extends ValidatorAbstract
|
|||
*/
|
||||
public static function isValid($value) : bool
|
||||
{
|
||||
return filter_var(gethostbyname($value), FILTER_VALIDATE_IP);
|
||||
return filter_var(gethostbyname($value), FILTER_VALIDATE_IP) !== false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ abstract class IbanErrorType extends Enum
|
|||
{
|
||||
/* public */ const INVALID_COUNTRY = 1;
|
||||
/* public */ const INVALID_LENGTH = 2;
|
||||
/* public */ const INVALID_CHECKSUM = 3;
|
||||
/* public */ const EXPECTED_ZERO = 4;
|
||||
/* public */ const EXPECTED_NUMERIC = 5;
|
||||
/* public */ const INVALID_CHECKSUM = 4;
|
||||
/* public */ const EXPECTED_ZERO = 8;
|
||||
/* public */ const EXPECTED_NUMERIC = 16;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation;
|
||||
|
||||
/**
|
||||
* Bitcoin validator.
|
||||
*
|
||||
* @category Framework
|
||||
* @package phpOMS\Utils\TaskSchedule
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @license OMS License 1.0
|
||||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class BitcoinValidator extends ValidatorAbstract
|
||||
{
|
||||
/**
|
||||
* Validate bitcoin.
|
||||
*
|
||||
* @param string $addr Bitcoin address
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function isValid(string $addr) : bool
|
||||
{
|
||||
try {
|
||||
$decoded = self::decodeBase58($addr);
|
||||
|
||||
$d1 = hash("sha256", substr($decoded, 0, 21), true);
|
||||
$d2 = hash("sha256", $d1, true);
|
||||
|
||||
if (substr_compare($decoded, $d2, 21, 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::$msg = $e->getMessage();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode base 58 bitcoin address.
|
||||
*
|
||||
* @param string $addr Bitcoin address
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
private static function decodeBase58(string $addr) : string
|
||||
{
|
||||
$alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
||||
|
||||
$out = array_fill(0, 25, 0);
|
||||
$length = strlen($addr);
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (($p = strpos($alphabet, $addr[$i])) === false) {
|
||||
throw new \Exception('Invalid character found in address.');
|
||||
}
|
||||
|
||||
$c = $p;
|
||||
for ($j = 25; $j--;) {
|
||||
$c += (int) (58 * $out[$j]);
|
||||
$out[$j] = (int) ($c % 256);
|
||||
$c /= 256;
|
||||
$c = (int) $c;
|
||||
}
|
||||
|
||||
if ($c !== 0) {
|
||||
throw new \Exception('Bitcoin address too long.');
|
||||
}
|
||||
}
|
||||
|
||||
$result = '';
|
||||
foreach ($out as $val) {
|
||||
$result .= chr($val);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class Crc32 extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class Extension extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class FileSize extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class Hash extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class IsCompressed extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class IsExecutable extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class IsImage extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class IsPDF extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.1
|
||||
*
|
||||
* @category TBD
|
||||
* @package TBD
|
||||
* @author OMS Development Team <dev@oms.com>
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://orange-management.com
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Validation\File;
|
||||
|
||||
use phpOMS\Validation\ValidatorAbstract;
|
||||
|
||||
class MimeType extends ValidatorAbstract
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -145,14 +145,20 @@ class View extends ViewAbstract
|
|||
* @param string $id Data ID
|
||||
* @param mixed $data Data
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function addData(string $id, $data) /* : void */
|
||||
public function addData(string $id, $data) : bool
|
||||
{
|
||||
if(isset($this->data[$id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->data[$id] = $data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user