Update namespaces
This commit is contained in:
107
src/Enforce/Database/Query/Builder.php
Normal file
107
src/Enforce/Database/Query/Builder.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query;
|
||||
|
||||
use Exception;
|
||||
use FilesystemIterator;
|
||||
use ProVM\Concept\Database\Query;
|
||||
|
||||
class Builder implements Query\Builder
|
||||
{
|
||||
public function __construct(array $query_classes)
|
||||
{
|
||||
$this->setQueries($query_classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getClasses(string $databaseType): array
|
||||
{
|
||||
$directories = new FilesystemIterator(__DIR__);
|
||||
foreach ($directories as $directory) {
|
||||
if (!$directory->isDir()) {
|
||||
continue;
|
||||
}
|
||||
if (strtolower($directory->getBasename()) !== strtolower($databaseType)) {
|
||||
continue;
|
||||
}
|
||||
$classes = [];
|
||||
$files = new FilesystemIterator($directory->getPathname());
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
continue;
|
||||
}
|
||||
$base = $file->getBasename('.php');
|
||||
$interface = "ProVM\\Concept\\Database\\Query\\{$base}";
|
||||
$class = __NAMESPACE__ . "\\{$directory->getBasename()}\\{$base}";
|
||||
$classes[$interface] = $class;
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
throw new Exception("Database type's classes not found");
|
||||
}
|
||||
protected array $query_classes;
|
||||
|
||||
protected function getQueries(): array
|
||||
{
|
||||
return $this->query_classes;
|
||||
}
|
||||
|
||||
protected function get(string $query_interface): string
|
||||
{
|
||||
return $this->query_classes[$query_interface];
|
||||
}
|
||||
|
||||
protected function addQuery(string $query_interface, string $query): Builder
|
||||
{
|
||||
$this->query_classes[$query_interface] = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setQueries(array $queries): Builder
|
||||
{
|
||||
foreach ($queries as $interface => $query) {
|
||||
$this->addQuery($interface, $query);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function build(string $query_interface, ?array $args = null): Query
|
||||
{
|
||||
$class = $this->get($query_interface);
|
||||
if ($args !== null) {
|
||||
return new $class(...$args);
|
||||
}
|
||||
return new $class;
|
||||
}
|
||||
|
||||
public function select(array|string $columns = '*'): Query\Select
|
||||
{
|
||||
return $this->build(Query\Select::class, compact('columns'));
|
||||
}
|
||||
public function insert(?string $table = null): Query\Insert
|
||||
{
|
||||
return $this->build(Query\Insert::class, compact('table'));
|
||||
}
|
||||
public function update(?string $table = null): Query\Update
|
||||
{
|
||||
return $this->build(Query\Update::class, compact('table'));
|
||||
}
|
||||
public function delete(?string $table = null): Query\Delete
|
||||
{
|
||||
return $this->build(Query\Delete::class, compact('table'));
|
||||
}
|
||||
|
||||
public function create(?string $table = null): Query\Create
|
||||
{
|
||||
return $this->build(Query\Create::class, compact('table'));
|
||||
}
|
||||
public function truncate(?string $table = null): Query\Truncate
|
||||
{
|
||||
return $this->build(Query\Truncate::class, compact('table'));
|
||||
}
|
||||
public function drop(?string $table = null): Query\Drop
|
||||
{
|
||||
return $this->build(Query\Drop::class, compact('table'));
|
||||
}
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Create.php
Normal file
8
src/Enforce/Database/Query/MySQL/Create.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Create extends Query\Create
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Delete.php
Normal file
8
src/Enforce/Database/Query/MySQL/Delete.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Delete extends Query\Delete
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Drop.php
Normal file
8
src/Enforce/Database/Query/MySQL/Drop.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Drop extends Query\Drop
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Insert.php
Normal file
8
src/Enforce/Database/Query/MySQL/Insert.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Insert extends Query\Insert
|
||||
{
|
||||
}
|
58
src/Enforce/Database/Query/MySQL/Select.php
Normal file
58
src/Enforce/Database/Query/MySQL/Select.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Select extends Query\Select
|
||||
{
|
||||
public function limit(int $limit, ?int $offset = null): Select
|
||||
{
|
||||
$this->setLimit($limit);
|
||||
if ($offset !== null) {
|
||||
$this->setOffset($offset);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected int $limit;
|
||||
protected int $offset;
|
||||
|
||||
public function getLimit(): int
|
||||
{
|
||||
return $this->limit;
|
||||
}
|
||||
public function getOffset(): int
|
||||
{
|
||||
return $this->offset;
|
||||
}
|
||||
|
||||
public function setLimit(int $limit): Select
|
||||
{
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
public function setOffset(int $offset): Select
|
||||
{
|
||||
$this->offset = $offset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getLimitString(): string
|
||||
{
|
||||
return (isset($this->limit)) ? " LIMIT {$this->getLimit()}{$this->getOffsetString()}" : '';
|
||||
}
|
||||
protected function getOffsetString(): string
|
||||
{
|
||||
return (isset($this->offset)) ? " OFFSET {$this->getOffset()}" : '';
|
||||
}
|
||||
|
||||
public function build(): string
|
||||
{
|
||||
return parent::build();
|
||||
/*$query = [
|
||||
parent::build(),
|
||||
$this->getLimitString()
|
||||
];
|
||||
return implode('', $query);*/
|
||||
}
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Truncate.php
Normal file
8
src/Enforce/Database/Query/MySQL/Truncate.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Truncate extends Query\Truncate
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/MySQL/Update.php
Normal file
8
src/Enforce/Database/Query/MySQL/Update.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\MySQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Update extends Query\Update
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Create.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Create.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Create extends Query\Create
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Delete.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Delete.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Delete extends Query\Delete
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Drop.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Drop.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Drop extends Query\Drop
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Insert.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Insert.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Insert extends Query\Insert
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Select.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Select.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Select extends Query\Select
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Truncate.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Truncate.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Truncate extends Query\Truncate
|
||||
{
|
||||
}
|
8
src/Enforce/Database/Query/PostgreSQL/Update.php
Normal file
8
src/Enforce/Database/Query/PostgreSQL/Update.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace ProVM\Enforce\Database\Query\PostgreSQL;
|
||||
|
||||
use ProVM\Ideal\Database\Query;
|
||||
|
||||
class Update extends Query\Update
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user