mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Unit test fixes
This commit is contained in:
parent
6ddd592297
commit
0b9c78144c
|
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
namespace phpOMS\Auth;
|
||||
|
||||
use phpOMS\Config\OptionsInterface;
|
||||
use phpOMS\Config\OptionsTrait;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\DatabaseType;
|
||||
use phpOMS\DataStorage\Session\SessionInterface;
|
||||
|
|
@ -34,10 +32,8 @@ use phpOMS\DataStorage\Session\SessionInterface;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Auth implements OptionsInterface
|
||||
class Auth
|
||||
{
|
||||
use OptionsTrait;
|
||||
|
||||
/**
|
||||
* Session instance.
|
||||
*
|
||||
|
|
@ -157,7 +153,7 @@ class Auth implements OptionsInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function logout(\int $uid)
|
||||
public function logout(\int $uid = null)
|
||||
{
|
||||
// TODO: logout other users? If admin wants to kick a user for updates etc.
|
||||
$this->session->remove('UID');
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ trait OptionsTrait
|
|||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return array_key_exists($key, $this->options);
|
||||
return isset($this->options[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,7 +55,7 @@ trait OptionsTrait
|
|||
public function setOption($key, $value, \bool $overwrite = true) : \bool
|
||||
{
|
||||
if ($overwrite || !array_key_exists($key, $this->options)) {
|
||||
$this->options[$key] = [$value, $overwrite];
|
||||
$this->options[$key] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ abstract class SettingsAbstract implements OptionsInterface
|
|||
switch ($this->connection->getType()) {
|
||||
case DatabaseType::MYSQL:
|
||||
$query = new Builder($this->connection);
|
||||
$sql = $query->select(static::$columns[0], 'settings_content')
|
||||
$sql = $query->select(...static::$columns)
|
||||
->from($this->connection->prefix . static::$table)
|
||||
->where(static::$columns[0], 'in', $columns)
|
||||
->toSql();
|
||||
|
|
@ -115,7 +115,6 @@ abstract class SettingsAbstract implements OptionsInterface
|
|||
* Set option by key.
|
||||
*
|
||||
* @param \string[] $options Column values for filtering
|
||||
* @param \bool $overwrite Overwrite existing settings
|
||||
* @param \bool $store Save this Setting immediately to database
|
||||
*
|
||||
* @return mixed Option value
|
||||
|
|
@ -123,9 +122,9 @@ abstract class SettingsAbstract implements OptionsInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function set(array $options, \bool $overwrite = true, \bool $store = false)
|
||||
public function set(array $options, \bool $store = false)
|
||||
{
|
||||
$this->setOptions($options, $overwrite);
|
||||
$this->setOptions($options);
|
||||
|
||||
if($store) {
|
||||
// save to db
|
||||
|
|
|
|||
|
|
@ -85,4 +85,17 @@ abstract class BuilderAbstract
|
|||
{
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query type.
|
||||
*
|
||||
* @return \int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getType() : \int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Database\Connection;
|
|||
|
||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Query\Grammar\Grammar as SchemaGrammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar;
|
||||
|
||||
/**
|
||||
* Database handler.
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
namespace phpOMS\DataStorage\Database\Connection;
|
||||
|
||||
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Query\Grammar\Grammar as SchemaGrammar;
|
||||
use phpOMS\DataStorage\Database\Schema\Grammar\Grammar as SchemaGrammar;
|
||||
|
||||
/**
|
||||
* Database connection interface.
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ abstract class GrammarAbstract
|
|||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $systemIdentifier = '"';
|
||||
protected $systemIdentifier = '"';
|
||||
|
||||
/**
|
||||
* And operator.
|
||||
|
|
@ -63,7 +63,7 @@ abstract class GrammarAbstract
|
|||
/**
|
||||
* Compile to query.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param BuilderAbstract $query Builder
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
|
|
@ -72,7 +72,7 @@ abstract class GrammarAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function compileQuery($query) : \string
|
||||
public function compileQuery(BuilderAbstract $query) : \string
|
||||
{
|
||||
return trim(
|
||||
implode(' ',
|
||||
|
|
@ -86,6 +86,8 @@ abstract class GrammarAbstract
|
|||
) . ';';
|
||||
}
|
||||
|
||||
abstract protected function compileComponents(BuilderAbstract $query) : array;
|
||||
|
||||
/**
|
||||
* Expressionize elements.
|
||||
*
|
||||
|
|
@ -118,6 +120,26 @@ abstract class GrammarAbstract
|
|||
return rtrim($expression, ', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile system.
|
||||
*
|
||||
* @param array|\string $system System
|
||||
* @param \string $prefix Prefix for table
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileSystem($system, \string $prefix = '') : \string
|
||||
{
|
||||
if (count($split = explode('.', $system)) == 2) {
|
||||
return $this->compileSystem($prefix . $split[0]) . '.' . $this->compileSystem($split[1]);
|
||||
} else {
|
||||
return $this->systemIdentifier . $prefix . $system . $this->systemIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDateFormat() : \string
|
||||
{
|
||||
return 'Y-m-d H:i:s';
|
||||
|
|
|
|||
|
|
@ -788,19 +788,6 @@ class Builder extends BuilderAbstract
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query type.
|
||||
*
|
||||
* @return \int
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function getType() : \int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merging query.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Query\Grammar;
|
||||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\GrammarAbstract;
|
||||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
use phpOMS\DataStorage\Database\Query\Column;
|
||||
|
|
@ -82,7 +83,7 @@ class Grammar extends GrammarAbstract
|
|||
/**
|
||||
* Compile components.
|
||||
*
|
||||
* @param Builder $query Builder
|
||||
* @param BuilderAbstract $query Builder
|
||||
*
|
||||
* @return \string[]
|
||||
*
|
||||
|
|
@ -91,7 +92,7 @@ class Grammar extends GrammarAbstract
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileComponents(Builder $query) : array
|
||||
protected function compileComponents(BuilderAbstract $query) : array
|
||||
{
|
||||
$sql = [];
|
||||
|
||||
|
|
@ -257,26 +258,6 @@ class Grammar extends GrammarAbstract
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile system.
|
||||
*
|
||||
* @param array|\string $system System
|
||||
* @param \string $prefix Prefix for table
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
protected function compileSystem($system, \string $prefix = '') : \string
|
||||
{
|
||||
if (count($split = explode('.', $system)) == 2) {
|
||||
return $this->compileSystem($prefix . $split[0]) . '.' . $this->compileSystem($split[1]);
|
||||
} else {
|
||||
return $this->systemIdentifier . $prefix . $system . $this->systemIdentifier;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile limit.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -25,5 +25,5 @@ class MysqlGrammar extends Grammar
|
|||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public $systemIdentifier = '`';
|
||||
protected $systemIdentifier = '`';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,12 +14,11 @@
|
|||
* @link http://orange-management.com
|
||||
*/
|
||||
|
||||
namespace phpOMS\DataStorage\Database\Schema\Query;
|
||||
namespace phpOMS\DataStorage\Database\Schema;
|
||||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
||||
use phpOMS\DataStorage\Database\Query;
|
||||
use phpOMS\DataStorage\Database\Schema\QueryType;
|
||||
|
||||
/**
|
||||
* Database query builder.
|
||||
|
|
@ -34,9 +33,9 @@ use phpOMS\DataStorage\Database\Schema\QueryType;
|
|||
*/
|
||||
class Builder extends BuilderAbstract
|
||||
{
|
||||
private $type = QueryType::SELECT;
|
||||
public $table = [];
|
||||
|
||||
private $table = [];
|
||||
public $drop = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -59,9 +58,11 @@ class Builder extends BuilderAbstract
|
|||
$this->table = array_unique($this->table);
|
||||
}
|
||||
|
||||
public function drop(\string $table)
|
||||
public function drop(...$table)
|
||||
{
|
||||
|
||||
$this->type = QueryType::DROP;
|
||||
$this->drop += $table;
|
||||
$this->drop = array_unique($this->drop);
|
||||
}
|
||||
|
||||
public function create(\string $table)
|
||||
|
|
@ -73,4 +74,17 @@ class Builder extends BuilderAbstract
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsing to string.
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function toSql() : \string
|
||||
{
|
||||
return $this->grammar->compileQuery($this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@
|
|||
|
||||
namespace phpOMS\DataStorage\Database\Schema\Grammar;
|
||||
|
||||
use phpOMS\DataStorage\Database\BuilderAbstract;
|
||||
use phpOMS\DataStorage\Database\GrammarAbstract;
|
||||
use phpOMS\DataStorage\Database\Schema\Builder;
|
||||
use phpOMS\DataStorage\Database\Schema\QueryType;
|
||||
|
||||
/**
|
||||
* Database query grammar.
|
||||
|
|
@ -41,4 +44,47 @@ class Grammar extends GrammarAbstract
|
|||
'selects',
|
||||
'from',
|
||||
];
|
||||
|
||||
/**
|
||||
* Select components.
|
||||
*
|
||||
* @var \string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $dropComponents = [
|
||||
'drop',
|
||||
];
|
||||
|
||||
public function compileComponents(BuilderAbstract $query) : array
|
||||
{
|
||||
$sql = [];
|
||||
|
||||
switch ($query->getType()) {
|
||||
case QueryType::DROP:
|
||||
$components = $this->dropComponents;
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown query type.');
|
||||
}
|
||||
|
||||
/* Loop all possible query components and if they exist compile them. */
|
||||
foreach ($components as $component) {
|
||||
if (isset($query->{$component}) && !empty($query->{$component})) {
|
||||
$sql[$component] = $this->{'compile' . ucfirst($component)}($query, $query->{$component});
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
protected function compileDrop(Builder $query, array $tables) : \string
|
||||
{
|
||||
$expression = $this->expressionizeTableColumn($tables, $query->getPrefix());
|
||||
|
||||
if ($expression === '') {
|
||||
$expression = '*';
|
||||
}
|
||||
|
||||
return 'DROP TABLE ' . $expression;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ use phpOMS\DataStorage\Database\Query\Builder;
|
|||
*/
|
||||
class MysqlGrammar extends Grammar
|
||||
{
|
||||
/**
|
||||
* System identifier.
|
||||
*
|
||||
* @var \string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $systemIdentifier = '`';
|
||||
|
||||
/**
|
||||
* Compile select.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ConsoleSession implements SessionInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct($sid)
|
||||
public function __construct($sid = false)
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class SocketSession implements SessionInterface
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public function __construct($sid)
|
||||
public function __construct($sid = false)
|
||||
{
|
||||
$this->sid = $sid;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,4 +38,5 @@ abstract class TagType extends Enum
|
|||
const SELECT = 5; /* <select> */
|
||||
const LABEL = 6; /* <label> */
|
||||
const ULIST = 7; /* <ul> */
|
||||
const OLIST = 8; /* <ul> */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,5 +44,6 @@ class UninstallAbstract
|
|||
*/
|
||||
public static function uninstall(Pool $dbPool, array $info)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
# Tests #
|
||||
|
||||
Unit tests
|
||||
|
||||
## License ##
|
||||
|
||||
* Orange Management
|
||||
* (c) 2013 - Dennis Eichhorn
|
||||
|
||||
## Contact ##
|
||||
|
||||
* Customer: spl1nes.com@googlemail.com
|
||||
* Developer: spl1nes.com@googlemail.com
|
||||
|
|
@ -63,11 +63,7 @@ class UriFactory
|
|||
*/
|
||||
public static function getQuery(\string $key)
|
||||
{
|
||||
if (isset(self::$uri[$key])) {
|
||||
return self::$uri[$key];
|
||||
}
|
||||
|
||||
return false;
|
||||
return self::$uri[$key] ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,16 +73,20 @@ class UriFactory
|
|||
* @param \string $value Replacement value
|
||||
* @param \bool $overwrite Overwrite if already exists
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function setQuery(\string $key, \string $value, \bool $overwrite = true)
|
||||
public static function setQuery(\string $key, \string $value, \bool $overwrite = true) : \bool
|
||||
{
|
||||
if ($overwrite || !isset(self::$uri[$key])) {
|
||||
self::$uri[$key] = $value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -116,26 +116,21 @@ class ArrayUtils
|
|||
*
|
||||
* @param mixed $needle Needle for search
|
||||
* @param array $haystack Haystack for search
|
||||
* @param mixed $id ID for search
|
||||
*
|
||||
* @return \bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function inArrayRecursive($needle, array $haystack, $id = null) : \bool
|
||||
public static function inArrayRecursive($needle, array $haystack) : \bool
|
||||
{
|
||||
$found = false;
|
||||
|
||||
if (isset($id) && isset($haystack[$id]) && $haystack[$id] === $needle) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($haystack as $item) {
|
||||
if ($item === $needle) {
|
||||
return true;
|
||||
} elseif (is_array($item)) {
|
||||
$found = self::inArrayRecursive($needle, $item, $id);
|
||||
$found = self::inArrayRecursive($needle, $item);
|
||||
|
||||
if ($found) {
|
||||
break;
|
||||
|
|
@ -203,16 +198,17 @@ class ArrayUtils
|
|||
* @param array $data Data to convert
|
||||
* @param \string $delimiter Delim to use
|
||||
* @param \string $enclosure Enclosure to use
|
||||
* @param \string $escape Escape to use
|
||||
*
|
||||
* @return \string
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function arrayToCSV(array $data, \string $delimiter = ';', \string $enclosure = '"') : \string
|
||||
public static function arrayToCSV(array $data, \string $delimiter = ';', \string $enclosure = '"', \string $escape = '\\') : \string
|
||||
{
|
||||
$outstream = fopen('php://output', 'r+');
|
||||
fputcsv($outstream, $data, $delimiter, $enclosure);
|
||||
$outstream = fopen('php://memory', 'r+');
|
||||
fputcsv($outstream, $data, $delimiter, $enclosure, $escape);
|
||||
rewind($outstream);
|
||||
$csv = fgets($outstream);
|
||||
fclose($outstream);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace phpOMS\Utils;
|
|||
* @link http://orange-management.com
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MultiMap
|
||||
class MultiMap implements \Countable
|
||||
{
|
||||
|
||||
/**
|
||||
|
|
@ -60,19 +60,55 @@ class MultiMap
|
|||
*
|
||||
* @param array $keys Keys for value
|
||||
* @param mixed $value Value to store
|
||||
* @param \bool $overwrite Add value if key exists
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
public function add(array $keys, $value)
|
||||
public function add(array $keys, $value, \bool $overwrite = true) : \bool
|
||||
{
|
||||
$this->values[] = $value;
|
||||
$id = count($this->values) - 1;
|
||||
$id = count($this->values);
|
||||
$inserted = false;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if ($overwrite || !isset($this->keys[$key])) {
|
||||
$id = $this->keys[$key] ?? $id;
|
||||
$this->keys[$key] = $id;
|
||||
|
||||
$inserted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($inserted) {
|
||||
$this->values[$id] = $value;
|
||||
}
|
||||
|
||||
// todo: is this really required???? - i don't think so!
|
||||
$this->garbageCollect();
|
||||
|
||||
return $inserted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Garbage collect unreferenced values/keys
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn
|
||||
*/
|
||||
private function garbageCollect()
|
||||
{
|
||||
foreach ($this->keys as $key => $keyValue) {
|
||||
if (!isset($this->values[$keyValue])) {
|
||||
unset($this->keys[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->values as $valueKey => $value) {
|
||||
if (!in_array($valueKey, $this->keys)) {
|
||||
unset($this->values[$valueKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +124,7 @@ class MultiMap
|
|||
*/
|
||||
public function get($key)
|
||||
{
|
||||
return $this->values[$this->keys[$key]] ?? null;
|
||||
return isset($this->keys[$key]) ? $this->values[$this->keys[$key]] ?? null : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -128,14 +164,10 @@ class MultiMap
|
|||
if (isset($this->keys[$key])) {
|
||||
$id = $this->keys[$key];
|
||||
|
||||
foreach ($this->keys as $key => $ref) {
|
||||
if ($ref === $id) {
|
||||
unset($this->keys[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
unset($this->values[$id]);
|
||||
|
||||
$this->garbageCollect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -160,6 +192,8 @@ class MultiMap
|
|||
if (isset($this->keys[$old]) && isset($this->keys[$new])) {
|
||||
$this->keys[$old] = $this->keys[$new];
|
||||
|
||||
$this->garbageCollect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -181,22 +215,9 @@ class MultiMap
|
|||
public function removeKey($key) : \bool
|
||||
{
|
||||
if (isset($this->keys[$key])) {
|
||||
$id = $this->keys[$key];
|
||||
|
||||
unset($this->keys[$key]);
|
||||
|
||||
$unreferencd = true;
|
||||
|
||||
foreach ($this->keys as $key => $value) {
|
||||
if ($value === $id) {
|
||||
$unreferencd = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($unreferencd) {
|
||||
unset($this->values[$id]);
|
||||
}
|
||||
$this->garbageCollect();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ class StringUtils
|
|||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function generateString($min = 10, $max = 10, $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
|
||||
public static function generateString(\int $min = 10, \int $max = 10, \string $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : \string
|
||||
{
|
||||
$length = rand($min, $max);
|
||||
$length = mt_rand($min, $max);
|
||||
$charactersLength = strlen($charset);
|
||||
$randomString = '';
|
||||
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $charset[rand(0, $charactersLength - 1)];
|
||||
$randomString .= $charset[mt_rand(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
|
|
|
|||
|
|
@ -46,6 +46,16 @@ class Email extends ValidatorAbstract
|
|||
*/
|
||||
public static function isValid(\string $value) : \bool
|
||||
{
|
||||
return filter_var($value, FILTER_VALIDATE_EMAIL) === false ? false : true;
|
||||
if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
|
||||
self::$msg = 'Invalid Email by filter_var standards';
|
||||
self::$error = 1;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$msg = '';
|
||||
self::$error = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,46 +43,6 @@ class Version
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Save version file.
|
||||
*
|
||||
* @param \string $type Lib or tool name
|
||||
* @param \string $version Version
|
||||
* @param \string $path Path to version file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function setVersion(\string $type, \string $version, \string $path)
|
||||
{
|
||||
$versions = self::getVersion($path);
|
||||
$versions[$type] = $version;
|
||||
file_put_contents($path, json_encode($versions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading version file.
|
||||
*
|
||||
* @param \string $jpath Path to version file
|
||||
*
|
||||
* @return \string[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||
*/
|
||||
public static function getVersion(\string $jpath) : array
|
||||
{
|
||||
$path = realpath($jpath);
|
||||
|
||||
if($path === false || Validator::startsWith($path, ROOT_PATH) === false || strpos($path, 'config.php') !== false) {
|
||||
throw new FilePathException($jpath);
|
||||
}
|
||||
|
||||
return json_decode(file_get_contents($path), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparing two versions.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user