Initial xentral_oss_20.3.c9ffacf

This commit is contained in:
Alex
2021-05-21 08:49:41 +02:00
parent 5406e4a551
commit 34e5ac43d9
18884 changed files with 2109867 additions and 0 deletions
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\SchemaCreator\Collection;
use ArrayIterator;
use IteratorAggregate;
use Xentral\Components\SchemaCreator\Exception\SchemaCreatorInvalidArgumentException;
use Xentral\Components\SchemaCreator\Interfaces\ColumnInterface;
final class ColumnCollection implements IteratorAggregate
{
/** @var array|ColumnInterface[] */
private $values = [];
/** @var null|ColumnInterface */
private $autoIncrementColumn;
/**
* @param array $values
*/
public function __construct(array $values = [])
{
foreach ($values as $value) {
$this->add($value);
}
}
/**
* @param ColumnInterface $field
*
* @return void
*/
public function add(ColumnInterface $field): void
{
if ($this->hasColumn($field->getField()) === true) {
throw new SchemaCreatorInvalidArgumentException(
sprintf('Column name `%s` already added', $field->getField())
);
}
$options = $field->getOptions();
if (array_key_exists('extra', $options) && $options['extra'] !== null) {
if ($options['extra'] === 'AUTO_INCREMENT' || $options['extra'] === 'ai') {
$this->autoIncrementColumn = $field;
}
}
$this->values[] = $field;
}
/**
* @param string $column
*
* @return bool
*/
public function hasColumn(string $column): bool
{
/** @var ColumnInterface $configuredColumns */
foreach ($this->values as $configuredColumns) {
if ($column === $configuredColumns->getField()) {
return true;
}
}
return false;
}
/**
* @return array|string[]
*/
public function getFields(): array
{
$fields = [];
foreach ($this->values as $column) {
$fields[] = $column->getField();
}
return $fields;
}
/**
* @return ArrayIterator|ColumnInterface[]
*/
public function getIterator()
{
return new ArrayIterator($this->values);
}
/***
* @return bool
*/
public function hasAutoIncrement(): bool
{
return null !== $this->autoIncrementColumn;
}
/**
* @return ColumnInterface|null
*/
public function getAutoIncrementColumn(): ?ColumnInterface
{
return $this->autoIncrementColumn;
}
}
@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\SchemaCreator\Collection;
use ArrayIterator;
use IteratorAggregate;
use Xentral\Components\SchemaCreator\Exception\SchemaCreatorInvalidArgumentException;
use Xentral\Components\SchemaCreator\Interfaces\PrimaryKeyInterface;
use Xentral\Components\SchemaCreator\Interfaces\IndexInterface;
final class IndexCollection implements IteratorAggregate
{
/** @var array|IndexInterface[] */
private $values = [];
/**
* @param array $values
*/
public function __construct(array $values = [])
{
foreach ($values as $value) {
$this->add($value);
}
}
/**
* @return bool
*/
public function hasPrimaryKey(): bool
{
foreach ($this->values as $configuredKeys) {
if ($configuredKeys instanceof PrimaryKeyInterface) {
return true;
}
}
return false;
}
/**
* @param string $key
*
* @return bool
*/
public function hasIndex(string $key): bool
{
/** @var IndexInterface $configuredKeys */
foreach ($this->values as $configuredKeys) {
if ($key === $configuredKeys->getName()) {
return true;
}
}
return false;
}
/**
* @param IndexInterface $key
*
* @return void
*/
public function add(IndexInterface $key): void
{
if ($this->hasIndex($key->getName()) === true) {
throw new SchemaCreatorInvalidArgumentException(
sprintf('Key name `%s` already added', $key->getName())
);
}
$this->values[] = $key;
}
/**
* @return array
*/
public function getIndexNames(): array
{
$indexes = [];
foreach ($this->values as $index) {
$indexes[] = $index instanceof PrimaryKeyInterface ? 'PRIMARY' : $index->getName();
}
return $indexes;
}
/**
* @return ArrayIterator|IndexInterface[]
*/
public function getIterator()
{
return new ArrayIterator($this->values);
}
}
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\SchemaCreator\Collection;
use ArrayIterator;
use IteratorAggregate;
use Xentral\Components\SchemaCreator\Schema\TableSchema;
final class SchemaCollection implements IteratorAggregate
{
/** @var array|TableSchema[] */
private $values = [];
/**
* @param TableSchema $schema
*/
public function add(TableSchema $schema): void
{
$this->values[] = $schema;
}
/**
* @return ArrayIterator|TableSchema[]
*/
public function getIterator()
{
return new ArrayIterator($this->values);
}
}
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Xentral\Components\SchemaCreator\Collection;
use ArrayIterator;
use IteratorAggregate;
use Xentral\Components\SchemaCreator\Option\TableOption;
final class TableOptionCollection implements IteratorAggregate
{
/** @var array|TableOption[] */
private $values = [];
/**
* @param TableOption $option
*/
public function add(TableOption $option): void
{
$this->values[] = $option;
}
/**
* @param string $option
*
* @return void
*/
public function remove(string $option): void
{
foreach ($this->values as $key => $tableOption) {
if ($tableOption->getOption() === $option) {
unset($this->values[$key]);
}
}
$this->values = array_values($this->values);
}
/**
* @param string $option
*
* @return TableOption|null
*/
public function getTableOption(string $option): ?TableOption
{
foreach ($this->values as $tableOption) {
if ($tableOption->getOption() === $option) {
return $tableOption;
}
}
return null;
}
/**
* @param string $option
*
* @return bool
*/
public function hasOption(string $option): bool
{
foreach ($this->values as $tableOption) {
if ($tableOption->getOption() === $option) {
return true;
}
}
return false;
}
/**
* @return ArrayIterator|TableOption[]
*/
public function getIterator()
{
return new ArrayIterator($this->values);
}
}