- Working on revamping Ulmus bases classes
This commit is contained in:
1 parent
c417b00ed4
commit
25ab845886
12 files changed
+303
-52
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
use Ulmus\Common\PdoObject;
|
||||
use Ulmus\Migration\FieldDefinition;
|
||||
|
||||
interface AdapterInterface {
|
||||
@@ -12,7 +11,7 @@ interface AdapterInterface {
|
||||
public const IDENTIFIER_SCHEMA = 4;
|
||||
public const IDENTIFIER_VALUE = 5;
|
||||
|
||||
public function connect() : object /* | PdoObject|mixed */;
|
||||
public function connect() : object;
|
||||
public function buildDataSourceName() : string;
|
||||
public function setup(array $configuration) : void;
|
||||
public function writableValue(/* mixed */ $value); /*: mixed*/
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
use Ulmus\Common\PdoObject;
|
||||
use Ulmus\Pdo;
|
||||
|
||||
use Ulmus\Exception\AdapterConfigurationException;
|
||||
|
||||
@@ -83,10 +83,10 @@ class MsSQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public function connect() : PdoObject
|
||||
public function connect() : Pdo
|
||||
{
|
||||
try {
|
||||
$pdo = new PdoObject($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo = new Pdo\Mssql($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
$pdo->setAttribute(\PDO::SQLSRV_ATTR_ENCODING, \PDO::SQLSRV_ENCODING_UTF8);
|
||||
|
||||
@@ -8,7 +8,7 @@ use Ulmus\Migration\FieldDefinition;
|
||||
use Ulmus\Migration\MigrateInterface;
|
||||
use Ulmus\Migration\SqlMigrationTrait;
|
||||
use Ulmus\QueryBuilder\Sql;
|
||||
use Ulmus\Common\PdoObject;
|
||||
use Ulmus\Pdo;
|
||||
|
||||
use Ulmus\Exception\AdapterConfigurationException;
|
||||
use Ulmus\Repository;
|
||||
@@ -71,10 +71,10 @@ class MySQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public function connect() : PdoObject
|
||||
public function connect() : \PDO
|
||||
{
|
||||
try {
|
||||
$pdo = new PdoObject($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo = new Pdo\Mysql($this->buildDataSourceName(), $this->username, $this->password);
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
|
||||
|
||||
+39
-40
@@ -3,7 +3,7 @@
|
||||
namespace Ulmus\Adapter;
|
||||
|
||||
use Collator;
|
||||
use Ulmus\Common\PdoObject;
|
||||
use Ulmus\Pdo;
|
||||
use Ulmus\ConnectionAdapter;
|
||||
use Ulmus\Entity;
|
||||
use Ulmus\Migration\FieldDefinition;
|
||||
@@ -24,16 +24,15 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
public null|array $pragmaClose = null,
|
||||
) { }
|
||||
|
||||
public function connect() : PdoObject
|
||||
public function connect() : \Pdo
|
||||
{
|
||||
try {
|
||||
#$pdo = new PdoObject($this->buildDataSourceName(), null, null);
|
||||
$pdo = new PdoObject\SqlitePdoObject($this->buildDataSourceName(), null, null);
|
||||
$pdo = new Pdo\Sqlite($this->buildDataSourceName(), null, null);
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||
|
||||
$pdo->onClose = function(PdoObject $obj) {
|
||||
$pdo->onClose = function(\PDO $obj) {
|
||||
static::registerPragma($obj, $this->pragmaClose);
|
||||
};
|
||||
|
||||
@@ -158,28 +157,28 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
return QueryBuilder\Sql\SqliteQueryBuilder::class;
|
||||
}
|
||||
|
||||
public function exportFunctions(PdoObject $pdo) : void
|
||||
public function exportFunctions(\PDO $pdo) : void
|
||||
{
|
||||
$pdo->sqliteCreateFunction('if', fn($comparison, $yes, $no) => $comparison ? $yes : $no, 3);
|
||||
$pdo->sqliteCreateFunction('length', fn($string) => strlen($string), 1);
|
||||
$pdo->sqliteCreateFunction('lcase', fn($string) => strtolower($string), 1);
|
||||
$pdo->sqliteCreateFunction('ucase', fn($string) => strtoupper($string), 1);
|
||||
$pdo->sqliteCreateFunction('md5', fn($string) => md5($string), 1);
|
||||
$pdo->sqliteCreateFunction('sha1', fn($string) => sha1($string), 1);
|
||||
$pdo->sqliteCreateFunction('sha256', fn($string) => hash('sha256', $string), 1);
|
||||
$pdo->sqliteCreateFunction('sha512', fn($string) => hash('sha512', $string), 1);
|
||||
$pdo->sqliteCreateFunction('whirlpool', fn($string) => hash('whirlpool', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3a', fn($string) => hash('murmur3a', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3c', fn($string) => hash('murmur3c', $string), 1);
|
||||
$pdo->sqliteCreateFunction('murmur3f', fn($string) => hash('murmur3f', $string), 1);
|
||||
$pdo->sqliteCreateFunction('left', fn($string, $length) => substr($string, 0, $length), 2);
|
||||
$pdo->sqliteCreateFunction('right', fn($string, $length) => substr($string, -$length), 2);
|
||||
$pdo->sqliteCreateFunction('strcmp', fn($s1, $s2) => strcmp($s1, $s2), 2);
|
||||
$pdo->sqliteCreateFunction('lpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_LEFT), 3);
|
||||
$pdo->sqliteCreateFunction('rpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_RIGHT), 3);
|
||||
$pdo->sqliteCreateFunction('concat', fn(...$args) => implode('', $args), -1);
|
||||
$pdo->sqliteCreateFunction('concat_ws', fn($separator, ...$args) => implode($separator, $args), -1);
|
||||
$pdo->sqliteCreateFunction('find_in_set', function($string, $string_list) {
|
||||
$pdo->createFunction('if', fn($comparison, $yes, $no) => $comparison ? $yes : $no, 3);
|
||||
$pdo->createFunction('length', fn($string) => strlen($string), 1);
|
||||
$pdo->createFunction('lcase', fn($string) => strtolower($string), 1);
|
||||
$pdo->createFunction('ucase', fn($string) => strtoupper($string), 1);
|
||||
$pdo->createFunction('md5', fn($string) => md5($string), 1);
|
||||
$pdo->createFunction('sha1', fn($string) => sha1($string), 1);
|
||||
$pdo->createFunction('sha256', fn($string) => hash('sha256', $string), 1);
|
||||
$pdo->createFunction('sha512', fn($string) => hash('sha512', $string), 1);
|
||||
$pdo->createFunction('whirlpool', fn($string) => hash('whirlpool', $string), 1);
|
||||
$pdo->createFunction('murmur3a', fn($string) => hash('murmur3a', $string), 1);
|
||||
$pdo->createFunction('murmur3c', fn($string) => hash('murmur3c', $string), 1);
|
||||
$pdo->createFunction('murmur3f', fn($string) => hash('murmur3f', $string), 1);
|
||||
$pdo->createFunction('left', fn($string, $length) => substr($string, 0, $length), 2);
|
||||
$pdo->createFunction('right', fn($string, $length) => substr($string, -$length), 2);
|
||||
$pdo->createFunction('strcmp', fn($s1, $s2) => strcmp($s1, $s2), 2);
|
||||
$pdo->createFunction('lpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_LEFT), 3);
|
||||
$pdo->createFunction('rpad', fn($string, $length, $pad) => str_pad($string, $length, $pad, STR_PAD_RIGHT), 3);
|
||||
$pdo->createFunction('concat', fn(...$args) => implode('', $args), -1);
|
||||
$pdo->createFunction('concat_ws', fn($separator, ...$args) => implode($separator, $args), -1);
|
||||
$pdo->createFunction('find_in_set', function($string, $string_list) {
|
||||
if ( $string === null || $string_list === null ) {
|
||||
return null;
|
||||
}
|
||||
@@ -190,13 +189,13 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
|
||||
return (int) in_array($string, explode(',', $string_list));
|
||||
}, 2);
|
||||
$pdo->sqliteCreateFunction('day', fn($date) => ( new \DateTime($date) )->format('j'), 1);
|
||||
$pdo->sqliteCreateFunction('month', fn($date) => ( new \DateTime($date) )->format('n'), 1);
|
||||
$pdo->sqliteCreateFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
|
||||
$pdo->sqliteCreateFunction('str_to_date', fn($value, $format) => ($f = \DateTime::createFromFormat($format, $value)) ? $f->format('Y-m-d H:i:s') : false);
|
||||
$pdo->createFunction('day', fn($date) => ( new \DateTime($date) )->format('j'), 1);
|
||||
$pdo->createFunction('month', fn($date) => ( new \DateTime($date) )->format('n'), 1);
|
||||
$pdo->createFunction('year', fn($date) => ( new \DateTime($date) )->format('Y'), 1);
|
||||
$pdo->createFunction('str_to_date', fn($value, $format) => ($f = \DateTime::createFromFormat($format, $value)) ? $f->format('Y-m-d H:i:s') : false);
|
||||
}
|
||||
|
||||
public function exportCollations(PdoObject $pdo) : void
|
||||
public function exportCollations(\PDO $pdo) : void
|
||||
{
|
||||
|
||||
if ( class_exists('Locale') ) {
|
||||
@@ -205,28 +204,28 @@ class SQLite implements AdapterInterface, MigrateInterface, SqlAdapterInterface
|
||||
$collator->setStrength(Collator::TERTIARY);
|
||||
$collator->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);
|
||||
|
||||
$pdo->sqliteCreateCollation('locale_cmp', fn($e1, $e2) => $collator->compare($e1, $e2));
|
||||
$pdo->sqliteCreateCollation('locale_cmp_desc', fn($e1, $e2) => $collator->compare($e2, $e1));
|
||||
$pdo->createCollation('locale_cmp', fn($e1, $e2) => $collator->compare($e1, $e2));
|
||||
$pdo->createCollation('locale_cmp_desc', fn($e1, $e2) => $collator->compare($e2, $e1));
|
||||
|
||||
$collatorCi = new Collator(\Locale::getDefault());
|
||||
$collatorCi->setStrength(Collator::SECONDARY);
|
||||
$collatorCi->setAttribute(Collator::NUMERIC_COLLATION, Collator::ON);
|
||||
|
||||
$pdo->sqliteCreateCollation('locale_cmp_ci', fn($e1, $e2) => $collatorCi->compare($e1, $e2));
|
||||
$pdo->sqliteCreateCollation('locale_cmp_ci_desc', fn($e1, $e2) => $collatorCi->compare($e2, $e1));
|
||||
$pdo->createCollation('locale_cmp_ci', fn($e1, $e2) => $collatorCi->compare($e1, $e2));
|
||||
$pdo->createCollation('locale_cmp_ci_desc', fn($e1, $e2) => $collatorCi->compare($e2, $e1));
|
||||
}
|
||||
else {
|
||||
$comp = fn(string $e1, string $e2) => \iconv('UTF-8', 'ASCII//TRANSLIT', $e1) <=> \iconv('UTF-8', 'ASCII//TRANSLIT', $e2);
|
||||
$pdo->sqliteCreateCollation('locale_cmp', fn($e1, $e2) => $comp);
|
||||
$pdo->sqliteCreateCollation('locale_cmp_desc', fn($e2, $e1) => $comp);
|
||||
$pdo->createCollation('locale_cmp', fn($e1, $e2) => $comp);
|
||||
$pdo->createCollation('locale_cmp_desc', fn($e2, $e1) => $comp);
|
||||
|
||||
$compCi = fn(string $e1, string $e2) => strtoupper(\iconv('UTF-8', 'ASCII//TRANSLIT', $e1)) <=> strtoupper(\iconv('UTF-8', 'ASCII//TRANSLIT', $e2));
|
||||
$pdo->sqliteCreateCollation('locale_cmp_ci', fn($e1, $e2) => $compCi);
|
||||
$pdo->sqliteCreateCollation('locale_cmp_ci_desc', fn($e2, $e1) => $compCi);
|
||||
$pdo->createCollation('locale_cmp_ci', fn($e1, $e2) => $compCi);
|
||||
$pdo->createCollation('locale_cmp_ci_desc', fn($e2, $e1) => $compCi);
|
||||
}
|
||||
}
|
||||
|
||||
public static function registerPragma(PdoObject $pdo, array $pragmaList) : void
|
||||
public static function registerPragma(\PDO $pdo, array $pragmaList) : void
|
||||
{
|
||||
$builder = new QueryBuilder\Sql\SqliteQueryBuilder();
|
||||
|
||||
|
||||
Reference in new issue
Block a user