Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Last active August 29, 2015 14:04
Show Gist options
  • Save shadowhand/e23e551a7c948373021a to your computer and use it in GitHub Desktop.
Save shadowhand/e23e551a7c948373021a to your computer and use it in GitHub Desktop.
Run phinx from the web
<?php
/* Phinx
*
* (The MIT license)
* Copyright (c) 2014 Rob Morgan
* Copyright (c) 2014 Woody Gilk <woody.gilk@gmail.com>
*
* 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.
*/
// copied from bin/phinx, need to decouple this a bit
if (!defined('PHINX_VERSION')) {
define('PHINX_VERSION', (0 === strpos('@PHINX_VERSION@', '@PHINX_VERSION')) ? '0.3.6' : '@PHINX_VERSION@');
}
$files = array(
__DIR__ . '/../../../autoload.php',
__DIR__ . '/../src/Phinx/autoload.php.dist'
);
$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require $file;
$found = true;
break;
}
}
if (!$found) {
die(
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
$app = new Phinx\Console\PhinxApplication(PHINX_VERSION);
// enable running phinx from the web by injecting ArrayInput and StreamOutput
// run locally with: php -S localhost:8080 web.php
$stream = fopen('php://output', 'w');
fwrite($stream, '<pre>');
$output = new Symfony\Component\Console\Output\StreamOutput($stream);
$input = new Symfony\Component\Console\Input\ArrayInput([
// first arg is the command
'migrate',
// other args are the options for the command
'-e' => 'development',
]);
$app->run($input, $output);
fwrite($stream, '</pre>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment