- First draft of current WIP

This commit is contained in:
mcndave committed 2019-08-21 16:13:00 -04:00
commit b73d046e0a
47 files changed
+2797

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
<?php
namespace Ulmus\Common;
abstract class Sql {
public static function function($name, ...$arguments)
{
return new class($name, ...$arguments) {
protected string $as = "";
protected string $name;
protected array $arguments;
public function __construct(string $name, ...$arguments) {
$this->name = $name;
$this->arguments = $arguments;
$this->parseArguments();
}
public function __toString() {
return implode(' ', array_filter([
"{$this->name}(" . implode(", ", $this->arguments) . ")",
$this->as ? "AS {$this->as}" : false,
]));
}
public function as($fieldName) {
$this->as = $fieldName;
return $this;
}
protected function parseArguments() {
foreach($this->arguments as &$item) {
$item = Sql::escape($item);
}
}
};
}
public static function escape($value)
{
switch(true) {
case is_object($value):
# @TODO Make sure the object is a Field
return (string) $value;
break;
case is_string($value):
$value = "\"$value\"";
break;
case is_null($value):
$value = "NULL";
break;
}
return $value;
}
public static function parameter($value) : string
{
}
}