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

Allow console input to be used within adapters #958

Merged
merged 5 commits into from
Sep 19, 2016
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
3 changes: 3 additions & 0 deletions docs/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,9 @@ call this method for each index.
{
$table = $this->table('users');
$table->removeIndex(array('email'));

// alternatively, you can delete an index by its name, ie:
$table->removeIndexByName('idx_users_email');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Phinx/Migration/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ public function getEnvironment($name)
// create an environment instance and cache it
$environment = new Environment($name, $this->getConfig()->getEnvironment($name));
$this->environments[$name] = $environment;
$environment->setInput($this->getInput());
$environment->setOutput($this->getOutput());

return $environment;
Expand Down
32 changes: 32 additions & 0 deletions src/Phinx/Migration/Manager/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Phinx\Db\Adapter\AdapterInterface;
use Phinx\Migration\MigrationInterface;
use Phinx\Seed\SeedInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Environment
Expand All @@ -46,6 +47,11 @@ class Environment
*/
protected $options;

/**
* @var InputInterface
*/
protected $input;

/**
* @var OutputInterface
*/
Expand Down Expand Up @@ -196,6 +202,28 @@ public function getOptions()
return $this->options;
}

/**
* Sets the console input.
*
* @param InputInterface $input
* @return Environment
*/
public function setInput(InputInterface $input)
{
$this->input = $input;
return $this;
}

/**
* Gets the console input.
*
* @return InputInterface
*/
public function getInput()
{
return $this->input;
}

/**
* Sets the console output.
*
Expand Down Expand Up @@ -312,6 +340,10 @@ public function getAdapter()
->getWrapper($this->options['wrapper'], $adapter);
}

if ($this->getInput()) {
$adapter->setInput($this->getInput());
}

if ($this->getOutput()) {
$adapter->setOutput($this->getOutput());
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Phinx/Migration/Manager/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,11 @@ public function testExecutingAChangeMigrationDown()

$this->environment->executeMigration($migration, MigrationInterface::DOWN);
}

public function testGettingInputObject()
{
$this->environment->setInput($this->getMock('\Symfony\Component\Console\Input\InputInterface'));
$inputObject = $this->environment->getInput();
$this->assertInstanceOf('\Symfony\Component\Console\Input\InputInterface', $inputObject);
}
}