* Fixes environment default * Bump clue/ndjson-react from 1.1.0 to 1.2.0 Bumps [clue/ndjson-react](https://github.com/clue/reactphp-ndjson) from 1.1.0 to 1.2.0. - [Release notes](https://github.com/clue/reactphp-ndjson/releases) - [Changelog](https://github.com/clue/reactphp-ndjson/blob/master/CHANGELOG.md) - [Commits](https://github.com/clue/reactphp-ndjson/compare/v1.1.0...v1.2.0) --- updated-dependencies: - dependency-name: clue/ndjson-react dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Bump cache/array-adapter from 1.0.1 to 1.1.0 Bumps [cache/array-adapter](https://github.com/php-cache/array-adapter) from 1.0.1 to 1.1.0. - [Release notes](https://github.com/php-cache/array-adapter/releases) - [Changelog](https://github.com/php-cache/array-adapter/blob/master/Changelog.md) - [Commits](https://github.com/php-cache/array-adapter/compare/1.0.1...1.1.0) --- updated-dependencies: - dependency-name: cache/array-adapter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Bump monolog/monolog from 2.3.2 to 2.3.4 Bumps [monolog/monolog](https://github.com/Seldaek/monolog) from 2.3.2 to 2.3.4. - [Release notes](https://github.com/Seldaek/monolog/releases) - [Changelog](https://github.com/Seldaek/monolog/blob/main/CHANGELOG.md) - [Commits](https://github.com/Seldaek/monolog/compare/2.3.2...2.3.4) --- updated-dependencies: - dependency-name: monolog/monolog dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Bump cache/namespaced-cache from 1.0.0 to 1.1.0 Bumps [cache/namespaced-cache](https://github.com/php-cache/namespaced-cache) from 1.0.0 to 1.1.0. - [Release notes](https://github.com/php-cache/namespaced-cache/releases) - [Changelog](https://github.com/php-cache/namespaced-cache/blob/master/Changelog.md) - [Commits](https://github.com/php-cache/namespaced-cache/compare/1.0.0...1.1.0) --- updated-dependencies: - dependency-name: cache/namespaced-cache dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Bump gulp-sass from 4.1.1 to 5.0.0 Bumps [gulp-sass](https://github.com/dlmanning/gulp-sass) from 4.1.1 to 5.0.0. - [Release notes](https://github.com/dlmanning/gulp-sass/releases) - [Changelog](https://github.com/dlmanning/gulp-sass/blob/master/CHANGELOG.md) - [Commits](https://github.com/dlmanning/gulp-sass/compare/v4.1.1...v5.0.0) --- updated-dependencies: - dependency-name: gulp-sass dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Bump node-sass from 4.14.1 to 6.0.1 Bumps [node-sass](https://github.com/sass/node-sass) from 4.14.1 to 6.0.1. - [Release notes](https://github.com/sass/node-sass/releases) - [Changelog](https://github.com/sass/node-sass/blob/master/CHANGELOG.md) - [Commits](https://github.com/sass/node-sass/compare/v4.14.1...v6.0.1) --- updated-dependencies: - dependency-name: node-sass dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Bump gulp-brotli from 2.0.2 to 3.0.0 Bumps [gulp-brotli](https://github.com/seznam/gulp-brotli) from 2.0.2 to 3.0.0. - [Release notes](https://github.com/seznam/gulp-brotli/releases) - [Commits](https://github.com/seznam/gulp-brotli/compare/v2.0.2...v3.0.0) --- updated-dependencies: - dependency-name: gulp-brotli dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Bump imagemin-webp from 5.1.0 to 6.0.0 Bumps [imagemin-webp](https://github.com/imagemin/imagemin-webp) from 5.1.0 to 6.0.0. - [Release notes](https://github.com/imagemin/imagemin-webp/releases) - [Commits](https://github.com/imagemin/imagemin-webp/compare/v5.1.0...v6.0.0) --- updated-dependencies: - dependency-name: imagemin-webp dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: make pathfinder composer 2.x compliant extract mixed class into dedicated file and address filename typo in order to make the project PSR-4 compliant and work with Composer 2 * Bump league/html-to-markdown from 4.9.1 to 5.0.1 Bumps [league/html-to-markdown](https://github.com/thephpleague/html-to-markdown) from 4.9.1 to 5.0.1. - [Release notes](https://github.com/thephpleague/html-to-markdown/releases) - [Changelog](https://github.com/thephpleague/html-to-markdown/blob/master/CHANGELOG.md) - [Commits](https://github.com/thephpleague/html-to-markdown/compare/4.9.1...5.0.1) --- updated-dependencies: - dependency-name: league/html-to-markdown dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * composer.json: bumps monolog to 2.3.4 * composer.lock: Updates after dependabot merges * Adds package-lock.json * .gitignore: removes package-lock.json from ignore * Removes "slash" js dev dependency * pathfinder.ini: bumps version * Bumps version on public files Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Loïc LEUILLIOT <loic.leuilliot@gmail.com>
176 lines
4.1 KiB
PHP
176 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Exodus4D\Pathfinder\Db\Sql\Mysql;
|
|
|
|
use DB\SQL;
|
|
|
|
class Constraint
|
|
{
|
|
|
|
// available actions
|
|
const ACTIONS_DELETE = ['RESTRICT', 'CASCADE', 'SET NULL', 'NO ACTION'];
|
|
const ACTIONS_UPDATE = ['RESTRICT', 'CASCADE', 'SET NULL', 'NO ACTION'];
|
|
|
|
// default actions
|
|
const ACTION_DELETE = 'RESTRICT';
|
|
const ACTION_UPDATE = 'RESTRICT';
|
|
|
|
const TEXT_ActionNotSupported = 'Constraint action `%s` is not supported.';
|
|
|
|
protected $table;
|
|
protected $keys = [];
|
|
protected $referencedTable = '';
|
|
protected $referencedCols = [];
|
|
protected $onDelete = self::ACTION_DELETE;
|
|
protected $onUpdate = self::ACTION_UPDATE;
|
|
|
|
/**
|
|
* Constraint constructor.
|
|
* @param SQL\TableBuilder $table
|
|
* @param array $keys
|
|
* @param string $referencedTable
|
|
* @param array $referencedCols
|
|
*/
|
|
public function __construct(SQL\TableBuilder $table, $keys = [], $referencedTable = '', $referencedCols = ['id'])
|
|
{
|
|
$this->table = &$table;
|
|
$this->setKeys($keys);
|
|
$this->setReferencedTable($referencedTable);
|
|
$this->setReferencedCols($referencedCols);
|
|
}
|
|
|
|
/**
|
|
* @param mixed $keys
|
|
*/
|
|
public function setKeys($keys)
|
|
{
|
|
$this->keys = (array)$keys;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $referencedTable
|
|
*/
|
|
public function setReferencedTable($referencedTable)
|
|
{
|
|
$this->referencedTable = $referencedTable;
|
|
}
|
|
|
|
/**
|
|
* @param mixed $referencedCols
|
|
*/
|
|
public function setReferencedCols($referencedCols)
|
|
{
|
|
$this->referencedCols = (array)$referencedCols;
|
|
}
|
|
|
|
/**
|
|
* @param string $onDelete
|
|
*/
|
|
public function setOnDelete($onDelete)
|
|
{
|
|
if (in_array($onDelete, self::ACTIONS_DELETE)) {
|
|
$this->onDelete = $onDelete;
|
|
} else {
|
|
trigger_error(sprintf(self::TEXT_ActionNotSupported, $onDelete));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param string $onUpdate
|
|
*/
|
|
public function setOnUpdate($onUpdate)
|
|
{
|
|
if (in_array($onUpdate, self::ACTIONS_UPDATE)) {
|
|
$this->onUpdate = $onUpdate;
|
|
} else {
|
|
trigger_error(sprintf(self::TEXT_ActionNotSupported, $onUpdate));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getKeys()
|
|
{
|
|
return $this->keys;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getReferencedTable()
|
|
{
|
|
return $this->referencedTable;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getReferencedCols()
|
|
{
|
|
return $this->referencedCols;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getOnDelete()
|
|
{
|
|
return $this->onDelete;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getOnUpdate()
|
|
{
|
|
return $this->onUpdate;
|
|
}
|
|
|
|
/**
|
|
* get a constraint name for this table.
|
|
* This can either be used to generate unique constraint names for foreign keys in parent tables
|
|
* or generate a "part" of a name. e.g. for db-Query all constraints of this table (ignore columns)
|
|
* by "LIKE" selecting "information_schema"
|
|
* -> To get a certain constraint or generate a unique constraint, ALL params are required!
|
|
* @return string
|
|
*/
|
|
public function getConstraintName()
|
|
{
|
|
$constraintName = 'fk_' . $this->table->name;
|
|
|
|
if (!empty($this->getKeys())) {
|
|
$constraintName .= '___' . implode('__', $this->getKeys());
|
|
if (!empty($this->getReferencedTable())) {
|
|
$constraintName .= '___' . $this->getReferencedTable();
|
|
if (!empty($this->getReferencedCols())) {
|
|
$constraintName .= '___' . implode('__', $this->getReferencedCols());
|
|
}
|
|
}
|
|
}
|
|
|
|
return $constraintName;
|
|
}
|
|
|
|
/**
|
|
* checks if constraint is valid
|
|
* -> all required members must be set!
|
|
* @return bool
|
|
*/
|
|
public function isValid()
|
|
{
|
|
$valid = false;
|
|
|
|
if (
|
|
!empty($this->getKeys()) &&
|
|
!empty($this->getReferencedTable()) &&
|
|
!empty($this->getReferencedCols())
|
|
) {
|
|
$valid = true;
|
|
}
|
|
|
|
return $valid;
|
|
}
|
|
|
|
|
|
} |