Browse Source

Master merged into main

main
Vítězslav Dvořák 9 months ago
parent
commit
1270a00b25
  1. 11
      README.md
  2. 4
      composer.json
  3. 4
      debian/control
  4. 101
      src/Ease/SQL/Engine.php
  5. 8
      src/Ease/SQL/Orm.php
  6. 49
      src/Ease/SQL/SQL.php

11
README.md

@ -29,7 +29,7 @@ For Debian, Ubuntu & friends please use repo:
echo "deb http://repo.vitexsoftware.cz $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/vitexsoftware.list
sudo wget -O /etc/apt/trusted.gpg.d/vitexsoftware.gpg http://repo.vitexsoftware.cz/keyring.gpg
sudo apt update
sudo apt install php-ease-fluentpdo
sudo apt install php-vitexsoftware-ease-fluentpdo
```
In this case please add this to your app composer.json:
@ -69,6 +69,12 @@ At first you need initialise create sql user & database with login and password
from testing/phinx.yml and initialise testing database by **phinx migrate**
command:
```shell
make phpunit
```
Or initalize another database and update .env file
```
composer update
cd tests
@ -76,8 +82,7 @@ mysqladmin -u root -p create easetest
mysql -u root -p -e "GRANT ALL PRIVILEGES ON easetest.* TO easetest@localhost IDENTIFIED BY 'easetest'"
sudo -u postgres bash -c "psql -c \"CREATE USER easetest WITH PASSWORD 'easetest';\""
sudo -u postgres bash -c "psql -c \"create database easetest with owner easetest encoding='utf8' template template0;\""
../vendor/bin/phinx migrate -e development
../vendor/bin/phinx migrate -e testing
make prepare
```
Building

4
composer.json

@ -10,8 +10,8 @@
"license": "MIT",
"minimum-stability": "dev",
"require": {
"vitexsoftware/ease-core": "dev-main",
"fpdo/fluentpdo": "dev-master"
"vitexsoftware/ease-core": "^1.1",
"fpdo/fluentpdo": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^9",

4
debian/control

@ -7,8 +7,8 @@ Uploaders: Vitex <vitex@hippy.cz>
Priority: optional
Homepage: https://github.com/VitexSoftware/php-ease-fluentpdo
Package: php-vitexsotfware-ease-fluentpdo
Depends: ${misc:Depends},php-vitexsoftware-ease-core,php-pdo-mysql|php-pdo-pgsql|php-pdo-sqlite|php-pdo-sqlserver,php-pdo-sqlite
Package: php-vitexsoftware-ease-fluentpdo
Depends: ${misc:Depends},php-ease-core,php-pdo-mysql|php-pdo-pgsql|php-pdo-sqlite|php-pdo-sqlserver
Architecture: all
Conflicts: ease-framework
Replaces: php-ease-fluentpdo

101
src/Ease/SQL/Engine.php

@ -51,17 +51,105 @@ class Engine extends \Ease\Brick {
$this->setupProperty($options, 'lastModifiedColumn');
$this->setUp($options);
if (!is_null($identifier)) {
if (array_key_exists('autoload', $options) && ($options['autoload'] === false)) {
if (is_array($identifier)) {
if (array_key_exists('autoload', $options) && ($options['autoload'] === true)) {
$this->loadIdentifier($identifier);
} else {
$this->useIdentifier($identifier);
}
}
/**
* Use Given value as identifier
*
* @param mixed $identifier
*/
public function useIdentifier($identifier) {
switch ($this->howToProcess($identifier)) {
case 'values':
$this->takeData($identifier);
} else {
break;
case 'reuse':
$this->takeData($identifier->getData());
break;
case 'name':
$this->setDataValue($this->nameColumn, $identifier);
break;
case 'id':
$this->setMyKey($identifier);
break;
default:
break;
}
} else {
}
/**
* Load record usinf identifier
*
* @param mixed $identifier
*/
public function loadIdentifier($identifier) {
switch ($this->howToProcess($identifier)) {
case 'values':
$this->loadFromSQL($identifier);
break;
case 'reuse':
$this->takeData($identifier->getData());
break;
case 'name':
$this->loadFromSQL([$this->nameColumn, $identifier]);
break;
case 'id':
$this->loadFromSQL($identifier);
break;
default:
break;
}
}
/**
*
* @param \Ease\SQL\Engine $identifer
*
* @return string id|name|values|reuse|unknown
*/
public function howToProcess($identifer) {
switch (gettype($identifer)) {
case "integer":
case "double":
if ($this->getKeyColumn()) {
$recognizedAs = 'id';
}
break;
case "string":
if (!empty($this->nameColumn)) {
$recognizedAs = 'name';
}
break;
case "array":
$recognizedAs = 'values';
break;
case "object":
if ($identifer instanceof \Ease\SQL\Engine) {
$recognizedAs = 'reuse';
}
break;
default :
case "boolean":
case "NULL":
$recognizedAs = 'unknown';
break;
}
return $recognizedAs;
}
/**
*
* @param string|int|array $param
*
* @return boolean Record was found ?
*/
public function recordExist($identifier = null) {
return $this->listingQuery()->where(is_null($identifier) ? [$this->getKeyColumn =>$this->getMyKey()] : $identifier)->count() != 0;
}
/**
@ -112,8 +200,7 @@ class Engine extends \Ease\Brick {
*
* @return array
*/
public static function fixIterator($query)
{
public static function fixIterator($query) {
$data = $query->execute();
return $data ? $data : [];
}

8
src/Ease/SQL/Orm.php

@ -58,14 +58,14 @@ trait Orm {
public $dbType;
/**
* Nastavení vlastností přípojení.
* Default connection settings.
*
* @var array
*/
public $connectionSettings = [];
/**
* Objekt pro práci s SQL.
* PDO Driver object
*
* @var PDO
*/
@ -302,7 +302,7 @@ trait Orm {
* @return boolean
*/
public function dbreload() {
return $this->loadFromSQL($this->getMyKey());
return $this->loadFromSQL([$this->getMyTable() . '.' . $this->getKeyColumn() => $this->getMyKey()]);
}
/**
@ -374,7 +374,7 @@ trait Orm {
* Insert record to SQL database.
*
* @param array $data
*`
*
* @return int|null id of new row in database
*/
public function insertToSQL($data = null) {

49
src/Ease/SQL/SQL.php

@ -123,55 +123,6 @@ abstract class SQL extends \Ease\Molecule {
*/
protected $connectAllreadyUP = false;
/**
* Hack WHERE to make Sensio Labs checks happy.
*
* @var string
*/
public static $whr = ' WHERE ';
/**
* Hack SELECT to make Sensio Labs checks happy.
*
* @var string
*/
public static $sel = 'SELECT ';
/**
* Hack ORDER BY to make Sensio Labs checks happy.
*
* @var string
*/
public static $ord = ' ORDER BY ';
/**
* Hack LIMIT to make Sensio Labs checks happy.
*
* @var string
*/
public static $lmt = ' LIMIT ';
/**
* Hack FROM to make Sensio Labs checks happy.
*
* @var string
*/
public static $frm = ' FROM ';
/**
* Hack DELETE FROM to make Sensio Labs checks happy.
*
* @var string
*/
public static $dlt = 'DELETE FROM ';
/**
* Hack UPDATE to make Sensio Labs checks happy.
*
* @var string
*/
public static $upd = 'UPDATE ';
/**
* Obecný objekt databáze.
*/

Loading…
Cancel
Save