Merge branch 'develop' of https://github.com/Orange-Management/phpOMS into develop

This commit is contained in:
Dennis Eichhorn 2019-03-14 18:51:08 +01:00
commit a52d01da80
13 changed files with 1552 additions and 12 deletions

View File

@ -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.
*

View File

@ -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
*

File diff suppressed because it is too large Load Diff

View 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
{
}

View 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;
}

View File

@ -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) {

View 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;
}

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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}
*/

View 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');
}
}

View 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
}
]
}

View 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
}
}
}
}