mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 14:38:39 +00:00
Get subdomain
This commit is contained in:
parent
d33f24aa6b
commit
bfa360ce24
1159
DataStorage/File/JsonBuilder.php
Normal file
1159
DataStorage/File/JsonBuilder.php
Normal file
File diff suppressed because it is too large
Load Diff
5
DataStorage/File/JsonGrammar.php
Normal file
5
DataStorage/File/JsonGrammar.php
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
// where create sub array
|
||||||
|
// order
|
||||||
|
// select data from where
|
||||||
|
// limit
|
||||||
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;
|
||||||
|
}
|
||||||
19
Uri/Http.php
19
Uri/Http.php
|
|
@ -231,6 +231,25 @@ final class Http implements UriInterface
|
||||||
return $this->host;
|
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 \array_slice($host, 0, $length);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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