Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internals re-implementation #1339

Merged
merged 24 commits into from
May 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
linters:
phpcs:
standard: CakePHP
fixer: true

files:
ignore:
- 'vendor/*'

fixers:
enable: true
workflow: commit
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ addons:
postgresql: "9.2"

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
}],
"require": {
"php": ">=5.4",
"cakephp/collection": "^3.5",
"symfony/console": "^2.8|^3.0|^4.0",
"symfony/config": "^2.8|^3.0|^4.0",
"symfony/yaml": "^2.8|^3.0|^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|^5.7|^6.5",
"phpunit/phpunit": ">=5.7",
"sebastian/comparator": ">=1.2.3",
"cakephp/cakephp-codesniffer": "^3.0"
},
Expand Down
56 changes: 56 additions & 0 deletions src/Phinx/Db/Action/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Phinx
*
* (The MIT license)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
namespace Phinx\Db\Action;

use \Phinx\Db\Table\Table;

abstract class Action
{

/**
* @var \Phinx\Db\Table\Table
*/
protected $table;

/**
* Consturctor
*
* @param Table $table the Table to apply the action to
*/
public function __construct(Table $table)
{
$this->table = $table;
}

/**
* The table this action will be applied to
*
* @return \Phinx\Db\Table\Table
*/
public function getTable()
{
return $this->table;
}
}
80 changes: 80 additions & 0 deletions src/Phinx/Db/Action/AddColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Phinx
*
* (The MIT license)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
namespace Phinx\Db\Action;

use Phinx\Db\Table\Column;
use Phinx\Db\Table\Table;

class AddColumn extends Action
{

/**
* The column to add
*
* @var Column
*/
protected $column;

/**
* Constructo
*
* @param Table $table The table to add the column to
* @param Column $column The column to add
*/
public function __construct(Table $table, Column $column)
{
parent::__construct($table);
$this->column = $column;
}

/**
* Returns a new AddColumn object after assembling the given commands
*
* @param Table $table The table to add the column to
* @param mixed $columnName The column name
* @param mixed $type The column type
* @param mixed $options The column options
* @return AddColumn
*/
public static function build(Table $table, $columnName, $type = null, $options = [])
{
$column = new Column();
$column->setName($columnName);
$column->setType($type);
$column->setOptions($options); // map options to column methods

return new static($table, $column);
}

/**
* Returns the column to be added
*
* @return Column
*/
public function getColumn()
{
return $this->column;
}
}
97 changes: 97 additions & 0 deletions src/Phinx/Db/Action/AddForeignKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Phinx
*
* (The MIT license)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
namespace Phinx\Db\Action;

use InvalidArgumentException;
use Phinx\Db\Table\ForeignKey;
use Phinx\Db\Table\Table;

class AddForeignKey extends Action
{

/**
* The foreign key to add
*
* @var ForeignKey
*/
protected $foreignKey;

/**
* Constructor
*
* @param Table $table The table to add the foreign key to
* @param ForeignKey $fk The foreign key to add
*/
public function __construct(Table $table, ForeignKey $fk)
{
parent::__construct($table);
$this->foreignKey = $fk;
}

/**
* Creats a new AddForeignKey object after building the foreign key with
* the passed attibutes
*
* @param Table $table The table object to add the foreign key to
* @param string|string[] $columns The columns for the foreign key
* @param Table|string $referencedTable The table the foreign key references
* @param string $referencedColumns The columns in the referenced table
* @param array $options Extra options for the foreign key
* @param string|null $name The name of the foreing key
* @return AddForeignKey
*/
public static function build(Table $table, $columns, $referencedTable, $referencedColumns = ['id'], array $options = [], $name = null)
{
if (is_string($referencedColumns)) {
$referencedColumns = [$referencedColumns]; // str to array
}

if (is_string($referencedTable)) {
$referencedTable = new Table($referencedTable);
}

$fk = new ForeignKey();
$fk->setReferencedTable($referencedTable)
->setColumns($columns)
->setReferencedColumns($referencedColumns)
->setOptions($options);

if ($name !== null) {
$fk->setConstraint($name);
}

return new static($table, $fk);
}

/**
* Returns the foreign key to be added
*
* @return ForeignKey
*/
public function getForeignKey()
{
return $this->foreignKey;
}
}
89 changes: 89 additions & 0 deletions src/Phinx/Db/Action/AddIndex.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Phinx
*
* (The MIT license)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated * documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
namespace Phinx\Db\Action;

use InvalidArgumentException;
use Phinx\Db\Table\Index;
use Phinx\Db\Table\Table;

class AddIndex extends Action
{
/**
* The index to add to the table
*
* @var Index
*/
protected $index;

/**
* Constructor
*
* @param Table $table The table to add the index to
* @param Index $index The index to be added
*/
public function __construct(Table $table, Index $index)
{
parent::__construct($table);
$this->index = $index;
}

/**
* Creates a new AddIndex object after building the index object with the
* provided arguments
*
* @param Table $table The table to add the index to
* @param mixed $columns The columns to index
* @param array $options Additional options for the index creation
* @return AddIndex
*/
public static function build(Table $table, $columns, array $options = [])
{
// create a new index object if strings or an array of strings were supplied
$index = $columns;

if (!$columns instanceof Index) {
$index = new Index();

if (is_string($columns)) {
$columns = [$columns]; // str to array
}

$index->setColumns($columns);
$index->setOptions($options);
}

return new static($table, $index);
}

/**
* Returns the index to be added
*
* @return Index
*/
public function getIndex()
{
return $this->index;
}
}
Loading