mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-18 12:48:41 +00:00
Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop
This commit is contained in:
commit
a52d01da80
|
|
@ -27,6 +27,7 @@ namespace phpOMS;
|
|||
* @property \phpOMS\Localization\L11nManager $l11nManager
|
||||
* @property \phpOMS\Router\Router $router
|
||||
* @property \phpOMS\DataStorage\Session\SessionInterface $sessionManager
|
||||
* @property \phpOMS\DataStorage\Cookie\CookieJar $cookieJar
|
||||
* @property \phpOMS\Module\ModuleManager $moduleManager
|
||||
* @property \phpOMS\Dispatcher\Dispatcher $dispatcher
|
||||
* @property \phpOMS\DataStorage\Cache\CachePool $cachePool
|
||||
|
|
@ -123,6 +124,14 @@ class ApplicationAbstract
|
|||
*/
|
||||
protected $sessionManager = null;
|
||||
|
||||
/**
|
||||
* Cookie instance.
|
||||
*
|
||||
* @var \phpOMS\DataStorage\Cookie\CookieJar
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $cookieJar = null;
|
||||
|
||||
/**
|
||||
* Server localization.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -111,6 +111,20 @@ final class CookieJar
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cookie value
|
||||
*
|
||||
* @param string $id Cookie id
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get(string $id)
|
||||
{
|
||||
return $this->cookies[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete already set cookie
|
||||
*
|
||||
|
|
|
|||
1160
DataStorage/File/JsonBuilder.php
Normal file
1160
DataStorage/File/JsonBuilder.php
Normal file
File diff suppressed because it is too large
Load Diff
35
DataStorage/File/JsonGrammar.php
Normal file
35
DataStorage/File/JsonGrammar.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
// where create sub array
|
||||
// order
|
||||
// select data from where
|
||||
// limit
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\File;
|
||||
|
||||
use phpOMS\DataStorage\File\QueryType;
|
||||
|
||||
/**
|
||||
* Json query JsonGrammar.
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class JsonGrammar
|
||||
{
|
||||
|
||||
}
|
||||
34
DataStorage/File/QueryType.php
Normal file
34
DataStorage/File/QueryType.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\DataStorage\File;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Query type enum.
|
||||
*
|
||||
* @package phpOMS\DataStorage\File
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class QueryType extends Enum
|
||||
{
|
||||
public const SELECT = 0;
|
||||
public const INSERT = 1;
|
||||
public const UPDATE = 2;
|
||||
public const DELETE = 3;
|
||||
public const RANDOM = 4;
|
||||
}
|
||||
|
|
@ -162,6 +162,10 @@ class Localization
|
|||
throw new InvalidEnumValue($langCode);
|
||||
}
|
||||
|
||||
if ($countryCode !== '*' && !\file_exists(__DIR__ . '/../Localization/Defaults/Definitions/' . $langCode . '_' . $countryCode . '.json')) {
|
||||
$countryCode = '*';
|
||||
}
|
||||
|
||||
$files = \glob(__DIR__ . '/../Localization/Defaults/Definitions/' . $langCode . '_' . $countryCode);
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
|
|
|||
|
|
@ -254,13 +254,11 @@ final class SingularValueDecomposition
|
|||
$pp = $p - 1;
|
||||
$iter = 0;
|
||||
|
||||
while (true) {
|
||||
while ($p > 0) {
|
||||
for ($k = $p - 2; $k >= -1; --$k) {
|
||||
if ($k === -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (\abs($e[$k]) <= $eps * (\abs($this->S[$k]) + \abs($this->S[$k + 1]))) {
|
||||
} elseif (\abs($e[$k]) <= $eps * (\abs($this->S[$k]) + \abs($this->S[$k + 1]))) {
|
||||
$e[$k] = 0.0;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,10 +108,10 @@ final class Request extends RequestAbstract
|
|||
*/
|
||||
private function initCurrentRequest() : void
|
||||
{
|
||||
$this->uri = new Http(Http::getCurrent());
|
||||
$this->uri = Http::fromCurrent();
|
||||
$this->data = $_GET ?? [];
|
||||
$this->files = $_FILES ?? [];
|
||||
$this->header->getL11n()->setLanguage($this->loadRequestLanguage());
|
||||
$this->header->getL11n()->setLanguage($this->getRequestLanguage());
|
||||
|
||||
$this->initNonGetData();
|
||||
}
|
||||
|
|
@ -155,23 +155,42 @@ final class Request extends RequestAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* Load request language
|
||||
* Get request language
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function loadRequestLanguage() : string
|
||||
public function getRequestLanguage() : string
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
return 'EN';
|
||||
return 'en';
|
||||
}
|
||||
|
||||
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
|
||||
$firstLocalComponents = \explode('-', $locals[0]);
|
||||
|
||||
return $firstLocalComponents[0];
|
||||
return \strtolower($firstLocalComponents[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request locale
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLocale() : string
|
||||
{
|
||||
if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
return 'en_US';
|
||||
}
|
||||
|
||||
$components = \explode(';', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
$locals = \stripos($components[0], ',') !== false ? $locals = \explode(',', $components[0]) : $components;
|
||||
|
||||
return \str_replace('-', '_', $locals[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -253,7 +272,7 @@ final class Request extends RequestAbstract
|
|||
$paths[] = $pathArray[$i];
|
||||
}
|
||||
|
||||
$this->hash[] = sha1(\implode('', $paths));
|
||||
$this->hash[] = \sha1(\implode('', $paths));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ abstract class RequestAbstract implements MessageInterface
|
|||
return [];
|
||||
}
|
||||
|
||||
$json = \json_decode($this->data[$key]);
|
||||
$json = \json_decode($this->data[$key], true);
|
||||
|
||||
return $json === false ? [] : $json;
|
||||
}
|
||||
|
|
|
|||
31
Uri/Http.php
31
Uri/Http.php
|
|
@ -193,6 +193,18 @@ final class Http implements UriInterface
|
|||
. '://' . ($_SERVER['HTTP_HOST'] ?? ''). ($_SERVER['REQUEST_URI'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create uri from current url
|
||||
*
|
||||
* @return Http Returns the current uri
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function fromCurrent() : self
|
||||
{
|
||||
return new self(self::getCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -234,6 +246,25 @@ final class Http implements UriInterface
|
|||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the subdomain of a host
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getSubdomain() : string
|
||||
{
|
||||
$host = explode('.', $this->host);
|
||||
$length = \count($host) - 2;
|
||||
|
||||
if ($length < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return \implode('.', \array_slice($host, 0, $length));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
153
tests/DataStorage/File/JsonBuilderTest.php
Normal file
153
tests/DataStorage/File/JsonBuilderTest.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package tests
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
|
||||
namespace phpOMS\tests\DataStorage\File;
|
||||
|
||||
use phpOMS\DataStorage\File\JsonBuilder;
|
||||
|
||||
class JsonBuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $table1 = [];
|
||||
private $table2 = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->table1 = \json_decode(\file_get_contents(__DIR__ . '/testDb1.json'), true);
|
||||
$this->table2 = \json_decode(\file_get_contents(__DIR__ . '/testDb2.json'), true);
|
||||
}
|
||||
|
||||
public function testJsonSelect() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals('acc1', $query->select('/0/account/*/name')->from($this->table1, $this->table2)->where('/0/account/*/id', '=', 1)->execute()['name']);
|
||||
self::assertEquals('acc6', $query->select('/1/account/*/name')->from($this->table1, $this->table2)->where('/1/account/*/id', '=', 2)->execute()['name']);
|
||||
|
||||
//$query = new JsonBuilder();
|
||||
//self::assertEquals($sql, $query->select('a.test')->distinct()->from('a')->where('a.test', '=', 1)->execute());
|
||||
|
||||
$query = new JsonBuilder();
|
||||
$datetime = new \DateTime('1999-31-12');
|
||||
self::assertEquals('dog2', $query->select('/0/animals/dog')->from($this->table2)->where('/0/animals/dog/created', '>', $datetime)->execute()['name']);
|
||||
|
||||
$table = $this->table2;
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['dog1', 'dog2', 'cat2'], $query->select('/0/animals/dog/*/name', function () {
|
||||
return '/0/animals/cat/*/name';
|
||||
})->from(function () use ($table) {
|
||||
return $table;
|
||||
})->where(['/0/animals/cat/*/owner', '/0/animals/dog/*/owner'], ['=', '='], [1, 4], ['and', 'or'])->execute());
|
||||
}
|
||||
|
||||
public function testJsonOrder() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['acc2', 'acc1', 'acc4'],
|
||||
$query->select('/0/account/*/name')
|
||||
->from($this->table1)
|
||||
->where('/0/account/*/id', '>', 0)
|
||||
->orderBy('/0/account/status', 'ASC')
|
||||
->execute()
|
||||
);
|
||||
}
|
||||
|
||||
public function testJsonOffsetLimit() : void
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
|
||||
$query = new JsonBuilder();
|
||||
self::assertEquals(['acc2', 'acc1'],
|
||||
$query->select('/0/account/*/name')
|
||||
->from($this->table1)
|
||||
->where('/0/account/*/id', '>', 0)
|
||||
->orderBy('/0/account/status', 'ASC')
|
||||
->limit(2)
|
||||
->execute()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testReadOnlyInsert() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->insert('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testReadOnlyUpdate() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testReadOnlyDelete() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidWhereOperator() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->where('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidJoinTable() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->join(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidJoinOperator() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->join('b')->on('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidOrOrderType() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->orderBy('a', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidOrColumnType() : void
|
||||
{
|
||||
$query = new JsonBuilder(true);
|
||||
$query->orderBy(null, 'DESC');
|
||||
}
|
||||
}
|
||||
36
tests/DataStorage/File/testDb1.json
Normal file
36
tests/DataStorage/File/testDb1.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"account": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "acc1",
|
||||
"status": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "acc2",
|
||||
"status": 1
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "acc4",
|
||||
"status": 2
|
||||
}
|
||||
],
|
||||
"news": [
|
||||
{
|
||||
"id": 1,
|
||||
"title": "news1",
|
||||
"by": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"title": "news2",
|
||||
"by": 4
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"title": "news4",
|
||||
"by": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
47
tests/DataStorage/File/testDb2.json
Normal file
47
tests/DataStorage/File/testDb2.json
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"account": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "acc5",
|
||||
"status": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "acc6",
|
||||
"status": 1
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "acc7",
|
||||
"status": 2
|
||||
}
|
||||
],
|
||||
"animals": {
|
||||
"dog": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "dog1",
|
||||
"owner": 4,
|
||||
"created": "1999-01-01"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "dog2",
|
||||
"owner": 1,
|
||||
"created": "2000-01-01"
|
||||
}
|
||||
],
|
||||
"cat": {
|
||||
"1": {
|
||||
"id": 1,
|
||||
"name": "cat1",
|
||||
"owner": 2
|
||||
},
|
||||
"2": {
|
||||
"id": 2,
|
||||
"name": "cat2",
|
||||
"owner": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user