First Local Commit - After Clean up.
Signed-off-by: Rick Hays <rhays@haysgang.com>
This commit is contained in:
188
system/Commands/Database/CreateMigration.php
Normal file
188
system/Commands/Database/CreateMigration.php
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Autoload;
|
||||
use Config\Migrations;
|
||||
|
||||
/**
|
||||
* Creates a new migration file.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class CreateMigration extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:create';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Creates a new migration file.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:create [migration_name] [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [
|
||||
'migration_name' => 'The migration file name',
|
||||
];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-n' => 'Set migration namespace',
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
helper('inflector');
|
||||
$name = array_shift($params);
|
||||
|
||||
if (empty($name))
|
||||
{
|
||||
$name = CLI::prompt(lang('Migrations.nameMigration'));
|
||||
}
|
||||
|
||||
if (empty($name))
|
||||
{
|
||||
CLI::error(lang('Migrations.badCreateName'));
|
||||
return;
|
||||
}
|
||||
|
||||
$ns = $params['-n'] ?? CLI::getOption('n');
|
||||
$homepath = APPPATH;
|
||||
|
||||
if (! empty($ns))
|
||||
{
|
||||
// Get all namespaces from PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
|
||||
foreach ($namespaces as $namespace => $path)
|
||||
{
|
||||
if ($namespace === $ns)
|
||||
{
|
||||
$homepath = realpath($path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$ns = 'App';
|
||||
}
|
||||
|
||||
// Always use UTC/GMT so global teams can work together
|
||||
$config = config('Migrations');
|
||||
$fileName = gmdate($config->timestampFormat) . $name;
|
||||
|
||||
// full path
|
||||
$path = $homepath . '/Database/Migrations/' . $fileName . '.php';
|
||||
|
||||
// Class name should be pascal case now (camel case with upper first letter)
|
||||
$name = pascalize($name);
|
||||
|
||||
$template = <<<EOD
|
||||
<?php namespace $ns\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class {name} extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
EOD;
|
||||
$template = str_replace('{name}', $name, $template);
|
||||
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.writeError'));
|
||||
return;
|
||||
}
|
||||
|
||||
CLI::write('Created file: ' . CLI::color(str_replace($homepath, $ns, $path), 'green'));
|
||||
}
|
||||
|
||||
}
|
||||
167
system/Commands/Database/Migrate.php
Normal file
167
system/Commands/Database/Migrate.php
Normal file
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Services;
|
||||
|
||||
/**
|
||||
* Runs all new migrations.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class Migrate extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Locates and runs all new migrations against the database.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate [options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set for all namespaces, will ignore (-n) option',
|
||||
];
|
||||
|
||||
/**
|
||||
* Ensures that all migrations have been run.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
$runner->clearCliMessages();
|
||||
|
||||
CLI::write(lang('Migrations.latest'), 'yellow');
|
||||
|
||||
$namespace = $params['-n'] ?? CLI::getOption('n');
|
||||
$group = $params['-g'] ?? CLI::getOption('g');
|
||||
|
||||
try
|
||||
{
|
||||
// Check for 'all' namespaces
|
||||
if ($this->isAllNamespace($params))
|
||||
{
|
||||
$runner->setNamespace(null);
|
||||
}
|
||||
// Check for a specified namespace
|
||||
elseif ($namespace)
|
||||
{
|
||||
$runner->setNamespace($namespace);
|
||||
}
|
||||
|
||||
if (! $runner->latest($group))
|
||||
{
|
||||
CLI::write(lang('Migrations.generalFault'), 'red');
|
||||
}
|
||||
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message)
|
||||
{
|
||||
CLI::write($message);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To migrate all namespaces to the latest migration
|
||||
*
|
||||
* Demo:
|
||||
* 1. command line: php spark migrate:latest -all
|
||||
* 2. command file: $this->call('migrate:latest', ['-g' => 'test','-all']);
|
||||
*
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
private function isAllNamespace(array $params): bool
|
||||
{
|
||||
if (array_search('-all', $params) !== false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return ! is_null(CLI::getOption('all'));
|
||||
}
|
||||
|
||||
}
|
||||
112
system/Commands/Database/MigrateRefresh.php
Normal file
112
system/Commands/Database/MigrateRefresh.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
|
||||
/**
|
||||
* Does a rollback followed by a latest to refresh the current state
|
||||
* of the database.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class MigrateRefresh extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:refresh';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Does a rollback followed by a latest to refresh the current state of the database.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:refresh [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-all' => 'Set latest for all namespace, will ignore (-n) option',
|
||||
];
|
||||
|
||||
/**
|
||||
* Does a rollback followed by a latest to refresh the current state
|
||||
* of the database.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$this->call('migrate:rollback', ['-b' => 0]);
|
||||
$this->call('migrate');
|
||||
}
|
||||
|
||||
}
|
||||
142
system/Commands/Database/MigrateRollback.php
Normal file
142
system/Commands/Database/MigrateRollback.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Services;
|
||||
use Config\Autoload;
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class MigrateRollback extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:rollback';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs the "down" method for all migrations in the last batch.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:rollback [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-b' => 'Specify a batch to roll back to; e.g. "3" to return to batch #3 or "-2" to roll back twice',
|
||||
'-g' => 'Set database group',
|
||||
];
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
$group = $params['-g'] ?? CLI::getOption('g');
|
||||
|
||||
if (! is_null($group))
|
||||
{
|
||||
$runner->setGroup($group);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$batch = $params['-b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;
|
||||
CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');
|
||||
|
||||
if (! $runner->regress($batch))
|
||||
{
|
||||
CLI::write(lang('Migrations.generalFault'), 'red');
|
||||
}
|
||||
|
||||
$messages = $runner->getCliMessages();
|
||||
foreach ($messages as $message)
|
||||
{
|
||||
CLI::write($message);
|
||||
}
|
||||
|
||||
CLI::write('Done');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
181
system/Commands/Database/MigrateStatus.php
Normal file
181
system/Commands/Database/MigrateStatus.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Services;
|
||||
use Config\Autoload;
|
||||
|
||||
/**
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class MigrateStatus extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'migrate:status';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays a list of all migrations and whether they\'ve been run or not.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'migrate:status [Options]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-g' => 'Set database group',
|
||||
];
|
||||
|
||||
/**
|
||||
* Namespaces to ignore when looking for migrations.
|
||||
*
|
||||
* @var type
|
||||
*/
|
||||
protected $ignoredNamespaces = [
|
||||
'CodeIgniter',
|
||||
'Config',
|
||||
'Tests\Support',
|
||||
];
|
||||
|
||||
/**
|
||||
* Displays a list of all migrations and whether they've been run or not.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$runner = Services::migrations();
|
||||
|
||||
$group = $params['-g'] ?? CLI::getOption('g');
|
||||
|
||||
if (! is_null($group))
|
||||
{
|
||||
$runner->setGroup($group);
|
||||
}
|
||||
|
||||
// Get all namespaces from PSR4 paths.
|
||||
$config = new Autoload();
|
||||
$namespaces = $config->psr4;
|
||||
|
||||
// Loop for all $namespaces
|
||||
foreach ($namespaces as $namespace => $path)
|
||||
{
|
||||
if (in_array($namespace, $this->ignoredNamespaces))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$runner->setNamespace($namespace);
|
||||
$migrations = $runner->findMigrations();
|
||||
$history = $runner->getHistory();
|
||||
|
||||
CLI::write($namespace);
|
||||
|
||||
if (empty($migrations))
|
||||
{
|
||||
CLI::error(lang('Migrations.noneFound'));
|
||||
continue;
|
||||
}
|
||||
|
||||
ksort($migrations);
|
||||
|
||||
$max = 0;
|
||||
foreach ($migrations as $version => $migration)
|
||||
{
|
||||
$file = substr($migration->name, strpos($migration->name, $version . '_'));
|
||||
$migrations[$version]->name = $file;
|
||||
|
||||
$max = max($max, strlen($file));
|
||||
}
|
||||
|
||||
CLI::write(' ' . str_pad(lang('Migrations.filename'), $max + 4) . lang('Migrations.on'), 'yellow');
|
||||
|
||||
foreach ($migrations as $uid => $migration)
|
||||
{
|
||||
$date = '';
|
||||
foreach ($history as $row)
|
||||
{
|
||||
if ($runner->getObjectUid($row) !== $uid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$date = date('Y-m-d H:i:s', $row->time);
|
||||
}
|
||||
CLI::write(str_pad(' ' . $migration->name, $max + 6) . ($date ? $date : '---'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
133
system/Commands/Database/Seed.php
Normal file
133
system/Commands/Database/Seed.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Database;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use CodeIgniter\Database\Seeder;
|
||||
|
||||
/**
|
||||
* Runs the specified Seeder file to populate the database
|
||||
* with some data.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class Seed extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'Database';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'db:seed';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Runs the specified seeder to populate known data into the database.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'db:seed [seeder_name]';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [
|
||||
'seeder_name' => 'The seeder name to run',
|
||||
];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* Runs all of the migrations in reverse order, until they have
|
||||
* all been un-applied.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$seeder = new Seeder(new \Config\Database());
|
||||
|
||||
$seedName = array_shift($params);
|
||||
|
||||
if (empty($seedName))
|
||||
{
|
||||
$seedName = CLI::prompt(lang('Migrations.migSeeder'), 'DatabaseSeeder');
|
||||
}
|
||||
|
||||
if (empty($seedName))
|
||||
{
|
||||
CLI::error(lang('Migrations.migMissingSeeder'));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$seeder->call($seedName);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$this->showError($e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
121
system/Commands/Help.php
Normal file
121
system/Commands/Help.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
|
||||
/**
|
||||
* CI Help command for the spark script.
|
||||
*
|
||||
* Lists the basic usage information for the spark script,
|
||||
* and provides a way to list help for other commands.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class Help extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'help';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays basic usage information.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'help command_name';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [
|
||||
'command_name' => 'The command name [default: "help"]',
|
||||
];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the spark cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$command = array_shift($params);
|
||||
if (is_null($command))
|
||||
{
|
||||
$command = 'help';
|
||||
}
|
||||
|
||||
$commands = $this->commands->getCommands();
|
||||
$class = new $commands[$command]['class']($this->logger, $this->commands);
|
||||
|
||||
$class->showHelp();
|
||||
}
|
||||
|
||||
}
|
||||
197
system/Commands/ListCommands.php
Normal file
197
system/Commands/ListCommands.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
/**
|
||||
* CI Help command for the spark script.
|
||||
*
|
||||
* Lists the basic usage information for the spark script,
|
||||
* and provides a way to list help for other commands.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class ListCommands extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'list';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Lists the available commands.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'list';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* The length of the longest command name.
|
||||
* Used during display in columns.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $maxFirstLength = 0;
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the spark cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$commands = $this->commands->getCommands();
|
||||
|
||||
$this->describeCommands($commands);
|
||||
|
||||
CLI::newLine();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the commands on the CLI.
|
||||
*
|
||||
* @param array $commands
|
||||
*/
|
||||
protected function describeCommands(array $commands = [])
|
||||
{
|
||||
ksort($commands);
|
||||
|
||||
// Sort into buckets by group
|
||||
$sorted = [];
|
||||
$maxTitleLength = 0;
|
||||
|
||||
foreach ($commands as $title => $command)
|
||||
{
|
||||
if (! isset($sorted[$command['group']]))
|
||||
{
|
||||
$sorted[$command['group']] = [];
|
||||
}
|
||||
|
||||
$sorted[$command['group']][$title] = $command;
|
||||
|
||||
$maxTitleLength = max($maxTitleLength, strlen($title));
|
||||
}
|
||||
|
||||
ksort($sorted);
|
||||
|
||||
// Display it all...
|
||||
foreach ($sorted as $group => $items)
|
||||
{
|
||||
CLI::newLine();
|
||||
CLI::write($group);
|
||||
|
||||
foreach ($items as $title => $item)
|
||||
{
|
||||
$title = $this->padTitle($title, $maxTitleLength, 2, 2);
|
||||
|
||||
$out = CLI::color($title, 'yellow');
|
||||
|
||||
if (isset($item['description']))
|
||||
{
|
||||
$out .= CLI::wrap($item['description'], 125, strlen($title));
|
||||
}
|
||||
|
||||
CLI::write($out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Pads our string out so that all titles are the same length to nicely line up descriptions.
|
||||
*
|
||||
* @param string $item
|
||||
* @param integer $max
|
||||
* @param integer $extra // How many extra spaces to add at the end
|
||||
* @param integer $indent
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function padTitle(string $item, int $max, int $extra = 2, int $indent = 0): string
|
||||
{
|
||||
$max += $extra + $indent;
|
||||
|
||||
$item = str_repeat(' ', $indent) . $item;
|
||||
$item = str_pad($item, $max);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
}
|
||||
145
system/Commands/Server/Serve.php
Normal file
145
system/Commands/Server/Serve.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Server;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
/**
|
||||
* Launch the PHP development server
|
||||
*
|
||||
* Not testable, as it throws phpunit for a loop :-/
|
||||
*
|
||||
* @package CodeIgniter\Commands\Server
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class Serve extends BaseCommand
|
||||
{
|
||||
/**
|
||||
* Minimum PHP version
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $minPHPVersion = '7.2';
|
||||
|
||||
/**
|
||||
* Group
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'serve';
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Launches the CodeIgniter PHP-Development Server.';
|
||||
|
||||
/**
|
||||
* Usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'serve';
|
||||
|
||||
/**
|
||||
* Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-php' => 'The PHP Binary [default: "PHP_BINARY"]',
|
||||
'-host' => 'The HTTP Host [default: "localhost"]',
|
||||
'-port' => 'The HTTP Host Port [default: "8080"]',
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the server
|
||||
*
|
||||
* @param array $params Parameters
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
// Valid PHP Version?
|
||||
if (phpversion() < $this->minPHPVersion)
|
||||
{
|
||||
die('Your PHP version must be ' . $this->minPHPVersion .
|
||||
' or higher to run CodeIgniter. Current version: ' . phpversion());
|
||||
}
|
||||
|
||||
// Collect any user-supplied options and apply them.
|
||||
$php = CLI::getOption('php') ?? PHP_BINARY;
|
||||
$host = CLI::getOption('host') ?? 'localhost';
|
||||
$port = CLI::getOption('port') ?? '8080';
|
||||
|
||||
// Get the party started.
|
||||
CLI::write('CodeIgniter development server started on http://' . $host . ':' . $port, 'green');
|
||||
CLI::write('Press Control-C to stop.');
|
||||
|
||||
// Set the Front Controller path as Document Root.
|
||||
$docroot = escapeshellarg(FCPATH);
|
||||
|
||||
// Mimic Apache's mod_rewrite functionality with user settings.
|
||||
$rewrite = escapeshellarg(__DIR__ . '/rewrite.php');
|
||||
|
||||
// Call PHP's built-in webserver, making sure to set our
|
||||
// base path to the public folder, and to use the rewrite file
|
||||
// to ensure our environment is set and it simulates basic mod_rewrite.
|
||||
passthru($php . ' -S ' . $host . ':' . $port . ' -t ' . $docroot . ' ' . $rewrite);
|
||||
}
|
||||
|
||||
}
|
||||
35
system/Commands/Server/rewrite.php
Normal file
35
system/Commands/Server/rewrite.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter PHP-Development Server Rewrite Rules
|
||||
*
|
||||
* This script works with the CLI serve command to help run a seamless
|
||||
* development server based around PHP's built-in development
|
||||
* server. This file simply tries to mimic Apache's mod_rewrite
|
||||
* functionality so the site will operate as normal.
|
||||
*/
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// Avoid this file run when listing commands
|
||||
if (php_sapi_name() === 'cli')
|
||||
{
|
||||
return;
|
||||
}
|
||||
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
|
||||
|
||||
// Front Controller path - expected to be in the default folder
|
||||
$fcpath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR;
|
||||
|
||||
// Full path
|
||||
$path = $fcpath . ltrim($uri, '/');
|
||||
|
||||
// If $path is an existing file or folder within the public folder
|
||||
// then let the request handle it like normal.
|
||||
if ($uri !== '/' && (is_file($path) || is_dir($path)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, we'll load the index file and let
|
||||
// the framework handle the request from here.
|
||||
require_once $fcpath . 'index.php';
|
||||
// @codeCoverageIgnoreEnd
|
||||
136
system/Commands/Sessions/CreateMigration.php
Normal file
136
system/Commands/Sessions/CreateMigration.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Sessions;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\App;
|
||||
|
||||
/**
|
||||
* Creates a migration file for database sessions.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
|
||||
class CreateMigration extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'session:migration';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generates the migration file for database sessions.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'session:migration';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [
|
||||
'-n' => 'Set migration namespace',
|
||||
'-g' => 'Set database group',
|
||||
'-t' => 'Set table name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates a new migration file with the current timestamp.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params = [])
|
||||
{
|
||||
$config = new App();
|
||||
|
||||
$tableName = CLI::getOption('t') ?? 'ci_sessions';
|
||||
|
||||
$path = APPPATH . 'Database/Migrations/' . date('YmdHis_') . 'create_' . $tableName . '_table' . '.php';
|
||||
|
||||
$data = [
|
||||
'namespace' => CLI::getOption('n') ?? APP_NAMESPACE ?? 'App',
|
||||
'DBGroup' => CLI::getOption('g'),
|
||||
'tableName' => $tableName,
|
||||
'matchIP' => $config->sessionMatchIP ?? false,
|
||||
];
|
||||
|
||||
$template = view('\CodeIgniter\Commands\Sessions\Views\migration.tpl.php', $data, ['debug' => false]);
|
||||
$template = str_replace('@php', '<?php', $template);
|
||||
|
||||
// Write the file out.
|
||||
helper('filesystem');
|
||||
if (! write_file($path, $template))
|
||||
{
|
||||
CLI::error(lang('Migrations.migWriteError'));
|
||||
return;
|
||||
}
|
||||
|
||||
CLI::write('Created file: ' . CLI::color(str_replace(APPPATH, 'APPPATH/', $path), 'green'));
|
||||
}
|
||||
|
||||
}
|
||||
52
system/Commands/Sessions/Views/migration.tpl.php
Normal file
52
system/Commands/Sessions/Views/migration.tpl.php
Normal file
@@ -0,0 +1,52 @@
|
||||
@php namespace <?= $namespace ?>\Database\Migrations;
|
||||
|
||||
use CodeIgniter\Database\Migration;
|
||||
|
||||
class Migration_create_<?= $tableName ?>_table extends Migration
|
||||
{
|
||||
<?php if (isset($DBGroup)) : ?>
|
||||
protected $DBGroup = '<?= $DBGroup ?>';
|
||||
<?php endif ?>
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->forge->addField([
|
||||
'id' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 128,
|
||||
'null' => false
|
||||
],
|
||||
'ip_address' => [
|
||||
'type' => 'VARCHAR',
|
||||
'constraint' => 45,
|
||||
'null' => false
|
||||
],
|
||||
'timestamp' => [
|
||||
'type' => 'INT',
|
||||
'constraint' => 10,
|
||||
'unsigned' => true,
|
||||
'null' => false,
|
||||
'default' => 0
|
||||
],
|
||||
'data' => [
|
||||
'type' => 'TEXT',
|
||||
'null' => false,
|
||||
'default' => ''
|
||||
],
|
||||
]);
|
||||
<?php if ($matchIP === true) : ?>
|
||||
$this->forge->addKey(['id', 'ip_address'], true);
|
||||
<?php else: ?>
|
||||
$this->forge->addKey('id', true);
|
||||
<?php endif ?>
|
||||
$this->forge->addKey('timestamp');
|
||||
$this->forge->createTable('<?= $tableName ?>', true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
public function down()
|
||||
{
|
||||
$this->forge->dropTable('<?= $tableName ?>', true);
|
||||
}
|
||||
}
|
||||
131
system/Commands/Utilities/Namespaces.php
Normal file
131
system/Commands/Utilities/Namespaces.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Utilities;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Autoload;
|
||||
|
||||
/**
|
||||
* Lists namespaces set in Config\Autoload with their
|
||||
* full server path. Helps you to verify that you have
|
||||
* the namespaces setup correctly.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class Namespaces extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'namespaces';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Verifies your namespaces are setup correctly.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'namespaces';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the spark cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$config = new Autoload();
|
||||
|
||||
$tbody = [];
|
||||
foreach ($config->psr4 as $ns => $path)
|
||||
{
|
||||
$path = realpath($path) ?? $path;
|
||||
|
||||
$tbody[] = [
|
||||
$ns,
|
||||
realpath($path) ?? $path,
|
||||
is_dir($path) ? 'Yes' : 'MISSING',
|
||||
];
|
||||
}
|
||||
|
||||
$thead = [
|
||||
'Namespace',
|
||||
'Path',
|
||||
'Found?',
|
||||
];
|
||||
|
||||
CLI::table($tbody, $thead);
|
||||
}
|
||||
|
||||
}
|
||||
150
system/Commands/Utilities/Routes.php
Normal file
150
system/Commands/Utilities/Routes.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP
|
||||
*
|
||||
* This content is released under the MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2019 British Columbia Institute of Technology
|
||||
* Copyright (c) 2019 CodeIgniter Foundation
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author CodeIgniter Dev Team
|
||||
* @copyright 2019 CodeIgniter Foundation
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link https://codeigniter.com
|
||||
* @since Version 4.0.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Commands\Utilities;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use Config\Services;
|
||||
|
||||
/**
|
||||
* Lists all of the user-defined routes. This will include any Routes files
|
||||
* that can be discovered, but will NOT include any routes that are not defined
|
||||
* in a routes file, but are instead discovered through auto-routing.
|
||||
*
|
||||
* @package CodeIgniter\Commands
|
||||
*/
|
||||
class Routes extends BaseCommand
|
||||
{
|
||||
|
||||
/**
|
||||
* The group the command is lumped under
|
||||
* when listing commands.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $group = 'CodeIgniter';
|
||||
|
||||
/**
|
||||
* The Command's name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'routes';
|
||||
|
||||
/**
|
||||
* the Command's short description
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Displays all of user-defined routes. Does NOT display auto-detected routes.';
|
||||
|
||||
/**
|
||||
* the Command's usage
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $usage = 'routes';
|
||||
|
||||
/**
|
||||
* the Command's Arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $arguments = [];
|
||||
|
||||
/**
|
||||
* the Command's Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = [];
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Displays the help for the spark cli script itself.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function run(array $params)
|
||||
{
|
||||
$collection = Services::routes(true);
|
||||
$methods = [
|
||||
'get',
|
||||
'head',
|
||||
'post',
|
||||
'patch',
|
||||
'put',
|
||||
'delete',
|
||||
'options',
|
||||
'trace',
|
||||
'connect',
|
||||
'cli',
|
||||
];
|
||||
|
||||
$tbody = [];
|
||||
foreach ($methods as $method)
|
||||
{
|
||||
$routes = $collection->getRoutes($method);
|
||||
|
||||
foreach ($routes as $from => $to)
|
||||
{
|
||||
// filter for strings, as callbacks aren't displayable
|
||||
if (is_string($to))
|
||||
{
|
||||
$tbody[] = [
|
||||
$from,
|
||||
$method,
|
||||
$to,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$thead = [
|
||||
'Route',
|
||||
'Method',
|
||||
'Command',
|
||||
];
|
||||
|
||||
CLI::table($tbody, $thead);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user