[2.0] Removed old CLI support.
This commit is contained in:
parent
5381e3d5a4
commit
45de5c6932
27 changed files with 0 additions and 4199 deletions
|
@ -1,234 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
use Doctrine\Common\Util\Inflector;
|
||||
|
||||
/**
|
||||
* Abstract CLI Namespace class
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
abstract class AbstractNamespace
|
||||
{
|
||||
/**
|
||||
* @var Configuration CLI Configuration instance
|
||||
*/
|
||||
private $_configuration = null;
|
||||
|
||||
/**
|
||||
* @var AbstractPrinter CLI Printer instance
|
||||
*/
|
||||
private $_printer = null;
|
||||
|
||||
/**
|
||||
* @var AbstractNamespace CLI Namespace instance
|
||||
*/
|
||||
private $_parentNamespace = null;
|
||||
|
||||
/**
|
||||
* @var array Available namespaces
|
||||
*/
|
||||
private $_namespaces = array();
|
||||
|
||||
/**
|
||||
* Add a single namespace to CLI.
|
||||
* Example of inclusion support to a single namespace:
|
||||
*
|
||||
* [php]
|
||||
* $cliOrmNamespace->addNamespace('my-custom-namespace');
|
||||
*
|
||||
* @param string $name CLI Namespace name
|
||||
*
|
||||
* @return CliController This object instance
|
||||
*/
|
||||
public function addNamespace($name)
|
||||
{
|
||||
$name = self::formatName($name);
|
||||
|
||||
if ($this->hasNamespace($name)) {
|
||||
throw CLIException::cannotOverrideNamespace($name);
|
||||
}
|
||||
|
||||
return $this->overrideNamespace($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides a namespace to CLI.
|
||||
* Example of inclusion support to a single namespace:
|
||||
*
|
||||
* [php]
|
||||
* $cli->overrideNamespace('orm');
|
||||
*
|
||||
* @param string $name CLI Namespace name
|
||||
*
|
||||
* @return AbstractNamespace Newly created CLI Namespace
|
||||
*/
|
||||
public function overrideNamespace($name)
|
||||
{
|
||||
$taskNamespace = new TaskNamespace($name);
|
||||
|
||||
$taskNamespace->setParentNamespace($this);
|
||||
$taskNamespace->setPrinter($this->_printer);
|
||||
$taskNamespace->setConfiguration($this->_configuration);
|
||||
|
||||
$this->_namespaces[$taskNamespace->getName()] = $taskNamespace;
|
||||
|
||||
return $taskNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve CLI Namespace.
|
||||
* Example of usage:
|
||||
*
|
||||
* [php]
|
||||
* $cliOrmNamespace = $cli->getNamespace('ORM');
|
||||
*
|
||||
* @param string $name CLI Namespace name
|
||||
*
|
||||
* @return TaskNamespace CLI Namespace
|
||||
*/
|
||||
public function getNamespace($name)
|
||||
{
|
||||
$name = self::formatName($name);
|
||||
|
||||
return isset($this->_namespaces[$name])
|
||||
? $this->_namespaces[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check existance of a CLI Namespace
|
||||
*
|
||||
* @param string CLI Namespace name
|
||||
*
|
||||
* @return boolean TRUE if namespace if defined, false otherwise
|
||||
*/
|
||||
public function hasNamespace($name)
|
||||
{
|
||||
return ($this->getNamespace($name) !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the parent CLI Namespace
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function setParentNamespace(AbstractNamespace $namespace)
|
||||
{
|
||||
$this->_parentNamespace = $namespace;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves currently parent CLI Namespace
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function getParentNamespace()
|
||||
{
|
||||
return $this->_parentNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all defined CLI Tasks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableTasks()
|
||||
{
|
||||
$tasks = array();
|
||||
|
||||
foreach ($this->_namespaces as $namespace) {
|
||||
$tasks = array_merge($tasks, $namespace->getAvailableTasks());
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the CLI Output Printer
|
||||
*
|
||||
* @param AbstractPrinter $printer CLI Output Printer
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function setPrinter(Printers\AbstractPrinter $printer = null)
|
||||
{
|
||||
$this->_printer = $printer ?: new Printers\AnsiColorPrinter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves currently used CLI Output Printer
|
||||
*
|
||||
* @return AbstractPrinter
|
||||
*/
|
||||
public function getPrinter()
|
||||
{
|
||||
return $this->_printer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the CLI Configuration
|
||||
*
|
||||
* #param Configuration $configuration CLI Configuration
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function setConfiguration(Configuration $config)
|
||||
{
|
||||
$this->_configuration = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves currently used CLI Configuration
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->_configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the CLI Namespace name into a camel-cased name
|
||||
*
|
||||
* @param string $name CLI Namespace name
|
||||
*
|
||||
* @return string Formatted CLI Namespace name
|
||||
*/
|
||||
public static function formatName($name)
|
||||
{
|
||||
return Inflector::classify($name);
|
||||
}
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* Generic CLI Controller of Tasks execution
|
||||
*
|
||||
* To include a new Task support, create a task:
|
||||
*
|
||||
* [php]
|
||||
* class MyProject\Tools\CLI\Tasks\MyTask extends Doctrine\ORM\Tools\CLI\Tasks\AbstractTask
|
||||
* {
|
||||
* public function run();
|
||||
* public function basicHelp();
|
||||
* public function extendedHelp();
|
||||
* public function validate();
|
||||
* }
|
||||
*
|
||||
* And then, load the namespace assoaicated an include the support to it in your command-line script:
|
||||
*
|
||||
* [php]
|
||||
* $cli = new Doctrine\Common\CLI\CLIController();
|
||||
* $cliNS = $cli->getNamespace('custom');
|
||||
* $cliNS->addTask('myTask', 'MyProject\Tools\CLI\Tasks\MyTask');
|
||||
*
|
||||
* To execute, just type any classify-able name:
|
||||
*
|
||||
* $ cli.php custom:my-task
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class CLIController extends AbstractNamespace
|
||||
{
|
||||
/**
|
||||
* The CLI processor of tasks
|
||||
*
|
||||
* @param Configuration $config
|
||||
* @param AbstractPrinter $printer CLI Output printer
|
||||
*/
|
||||
public function __construct(Configuration $config, Printers\AbstractPrinter $printer = null)
|
||||
{
|
||||
$this->setPrinter($printer);
|
||||
$this->setConfiguration($config);
|
||||
|
||||
// Include core namespaces of tasks
|
||||
$ns = 'Doctrine\Common\CLI\Tasks';
|
||||
$this->addNamespace('Core')
|
||||
->addTask('help', $ns . '\HelpTask')
|
||||
->addTask('version', $ns . '\VersionTask');
|
||||
|
||||
$ns = 'Doctrine\ORM\Tools\CLI\Tasks';
|
||||
$this->addNamespace('Orm')
|
||||
->addTask('clear-cache', $ns . '\ClearCacheTask')
|
||||
->addTask('convert-mapping', $ns . '\ConvertMappingTask')
|
||||
->addTask('ensure-production-settings', $ns . '\EnsureProductionSettingsTask')
|
||||
->addTask('generate-proxies', $ns . '\GenerateProxiesTask')
|
||||
->addTask('run-dql', $ns . '\RunDqlTask')
|
||||
->addTask('schema-tool', $ns . '\SchemaToolTask')
|
||||
->addTask('version', $ns . '\VersionTask')
|
||||
->addTask('convert-d1-schema', $ns . '\ConvertDoctrine1SchemaTask')
|
||||
->addTask('generate-entities', $ns . '\GenerateEntitiesTask')
|
||||
->addTask('generate-repositories', $ns . '\GenerateRepositoriesTask');
|
||||
|
||||
$ns = 'Doctrine\DBAL\Tools\CLI\Tasks';
|
||||
$this->addNamespace('Dbal')
|
||||
->addTask('run-sql', $ns . '\RunSqlTask')
|
||||
->addTask('version', $ns . '\VersionTask');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single task to CLI Core Namespace. This method acts as a delegate.
|
||||
* Example of inclusion support to a single task:
|
||||
*
|
||||
* [php]
|
||||
* $cli->addTask('my-custom-task', 'MyProject\CLI\Tasks\MyCustomTask');
|
||||
*
|
||||
* @param string $name CLI Task name
|
||||
* @param string $class CLI Task class (FQCN - Fully Qualified Class Name)
|
||||
*
|
||||
* @return CLIController This object instance
|
||||
*/
|
||||
public function addTask($name, $class)
|
||||
{
|
||||
$this->getNamespace('Core')->addTask($name, $class);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processor of CLI Tasks. Handles multiple task calls, instantiate
|
||||
* respective classes and run them.
|
||||
*
|
||||
* @param array $args CLI Arguments
|
||||
*/
|
||||
public function run($args = array())
|
||||
{
|
||||
// Remove script file argument
|
||||
$scriptFile = array_shift($args);
|
||||
|
||||
// If not arguments are defined, include "help"
|
||||
if (empty($args)) {
|
||||
array_unshift($args, 'Core:Help');
|
||||
}
|
||||
|
||||
// Process all sent arguments
|
||||
$args = $this->_processArguments($args);
|
||||
|
||||
try {
|
||||
$this->getPrinter()->writeln('Doctrine Command Line Interface' . PHP_EOL, 'HEADER');
|
||||
|
||||
// Handle possible multiple tasks on a single command
|
||||
foreach($args as $taskData) {
|
||||
$taskName = $taskData['name'];
|
||||
$taskArguments = $taskData['args'];
|
||||
|
||||
$this->runTask($taskName, $taskArguments);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
$message = $taskName . ' => ' . $e->getMessage();
|
||||
|
||||
if (isset($taskArguments['trace']) && $taskArguments['trace']) {
|
||||
$message .= PHP_EOL . PHP_EOL . $e->getTraceAsString();
|
||||
}
|
||||
|
||||
$this->getPrinter()->writeln($message, 'ERROR');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a given CLI Task
|
||||
*
|
||||
* @param atring $name CLI Task name
|
||||
* @param array $args CLI Arguments
|
||||
*/
|
||||
public function runTask($name, $args = array())
|
||||
{
|
||||
// Retrieve namespace name, task name and arguments
|
||||
$taskPath = explode(':', $name);
|
||||
|
||||
// Find the correct namespace where the task is defined
|
||||
$taskName = array_pop($taskPath);
|
||||
$taskNamespace = $this->_retrieveTaskNamespace($taskPath);
|
||||
|
||||
$taskNamespace->runTask($taskName, $args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes arguments and returns a structured hierachy.
|
||||
* Example:
|
||||
*
|
||||
* cli.php foo -abc --option=value bar --option -a=value --optArr=value1,value2
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
* array(
|
||||
* 0 => array(
|
||||
* 'name' => 'foo',
|
||||
* 'args' => array(
|
||||
* 'a' => true,
|
||||
* 'b' => true,
|
||||
* 'c' => true,
|
||||
* 'option' => 'value',
|
||||
* ),
|
||||
* ),
|
||||
* 1 => array(
|
||||
* 'name' => 'bar',
|
||||
* 'args' => array(
|
||||
* 'option' => true,
|
||||
* 'a' => 'value',
|
||||
* 'optArr' => array(
|
||||
* 'value1', 'value2'
|
||||
* ),
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* Based on implementation of Patrick Fisher <patrick@pwfisher.com> available at:
|
||||
* http://pwfisher.com/nucleus/index.php?itemid=45
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _processArguments($args = array())
|
||||
{
|
||||
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE;
|
||||
$regex = '/\s*[,]?\s*"([^"]*)"|\s*[,]?\s*([^,]*)/i';
|
||||
$preparedArgs = array();
|
||||
$out = & $preparedArgs;
|
||||
|
||||
foreach ($args as $arg){
|
||||
// --foo --bar=baz
|
||||
if (substr($arg, 0, 2) == '--'){
|
||||
$eqPos = strpos($arg, '=');
|
||||
|
||||
// --foo
|
||||
if ($eqPos === false){
|
||||
$key = substr($arg, 2);
|
||||
$out[$key] = isset($out[$key]) ? $out[$key] : true;
|
||||
// --bar=baz
|
||||
} else {
|
||||
$key = substr($arg, 2, $eqPos - 2);
|
||||
$value = substr($arg, $eqPos + 1);
|
||||
$value = (strpos($value, ' ') !== false) ? $value : array_values(array_filter(
|
||||
explode(',', $value), function ($v) { return trim($v) != ''; }
|
||||
));
|
||||
$out[$key] = ( ! is_array($value) || empty($value) || (is_array($value) && count($value) > 1))
|
||||
? $value : $value[0];
|
||||
}
|
||||
// -k=value -abc
|
||||
} else if (substr($arg, 0, 1) == '-'){
|
||||
// -k=value
|
||||
if (substr($arg, 2, 1) == '='){
|
||||
$key = substr($arg, 1, 1);
|
||||
$value = substr($arg, 3);
|
||||
$value = (strpos($value, ' ') !== false) ? $value : array_values(array_filter(
|
||||
explode(',', $value), function ($v) { return trim($v) != ''; }
|
||||
));
|
||||
$out[$key] = ( ! is_array($value) || (is_array($value) && count($value) > 1))
|
||||
? $value : $value[0];
|
||||
// -abc
|
||||
} else {
|
||||
$chars = str_split(substr($arg, 1));
|
||||
|
||||
foreach ($chars as $char){
|
||||
$key = $char;
|
||||
$out[$key] = isset($out[$key]) ? $out[$key] : true;
|
||||
}
|
||||
}
|
||||
// plain-arg
|
||||
} else {
|
||||
$key = count($preparedArgs);
|
||||
$preparedArgs[$key] = array(
|
||||
'name' => $arg,
|
||||
'args' => array()
|
||||
);
|
||||
$out = & $preparedArgs[$key]['args'];
|
||||
}
|
||||
}
|
||||
|
||||
return $preparedArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the correct namespace given a namespace path
|
||||
*
|
||||
* @param array $namespacePath CLI Namespace path
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
private function _retrieveTaskNamespace($namespacePath)
|
||||
{
|
||||
$taskNamespace = $this;
|
||||
$currentNamespacePath = '';
|
||||
|
||||
// Consider possible missing namespace (ie. "help") and forward to "core"
|
||||
if (count($namespacePath) == 0) {
|
||||
$namespacePath = array('Core');
|
||||
}
|
||||
|
||||
// Loop through each namespace
|
||||
foreach ($namespacePath as $namespaceName) {
|
||||
$taskNamespace = $taskNamespace->getNamespace($namespaceName);
|
||||
|
||||
// If the given namespace returned "null", throw exception
|
||||
if ($taskNamespace === null) {
|
||||
throw CLIException::namespaceDoesNotExist($namespaceName, $currentNamespacePath);
|
||||
}
|
||||
|
||||
$currentNamespacePath = (( ! empty($currentNamespacePath)) ? ':' : '')
|
||||
. $taskNamespace->getName();
|
||||
}
|
||||
|
||||
return $taskNamespace;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* CLI Exception class
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class CLIException extends \Exception
|
||||
{
|
||||
public static function namespaceDoesNotExist($namespaceName, $namespacePath = '')
|
||||
{
|
||||
return new self(
|
||||
"Namespace '{$namespaceName}' does not exist" .
|
||||
(( ! empty($namespacePath)) ? " in '{$namespacePath}'." : '.')
|
||||
);
|
||||
}
|
||||
|
||||
public static function taskDoesNotExist($taskName, $namespacePath)
|
||||
{
|
||||
return new self("Task '{$taskName}' does not exist in '{$namespacePath}'.");
|
||||
}
|
||||
|
||||
public static function cannotOverrideTask($taskName)
|
||||
{
|
||||
return new self("Task '{$taskName}' cannot be overriden.");
|
||||
}
|
||||
|
||||
public static function cannotOverrideNamespace($namespace) {
|
||||
return new self("Namespace '$namespace' cannot be overriden. Call overrideNamespace() directly.");
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* CLI Configuration class
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Configuration
|
||||
{
|
||||
/**
|
||||
* @var array Configuration attributes
|
||||
*/
|
||||
private $_attributes = array();
|
||||
|
||||
/**
|
||||
* Defines a new configuration attribute
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
* @param mixed $value Attribute value
|
||||
*
|
||||
* @return Configuration This object instance
|
||||
*/
|
||||
public function setAttribute($name, $value = null)
|
||||
{
|
||||
$this->_attributes[$name] = $value;
|
||||
|
||||
if ($value === null) {
|
||||
unset($this->_attributes[$name]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a configuration attribute
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
*
|
||||
* @return mixed Attribute value
|
||||
*/
|
||||
public function getAttribute($name)
|
||||
{
|
||||
return isset($this->_attributes[$name])
|
||||
? $this->_attributes[$name] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if configuration attribute is defined
|
||||
*
|
||||
* @param string $name Attribute name
|
||||
*
|
||||
* @return boolean TRUE if attribute exists, FALSE otherwise
|
||||
*/
|
||||
public function hasAttribute($name)
|
||||
{
|
||||
return isset($this->_attributes[$name]);
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* CLI Option definition
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Option
|
||||
{
|
||||
/** @var string Option name */
|
||||
private $_name;
|
||||
|
||||
/** @var string Option default value */
|
||||
private $_defaultValue;
|
||||
|
||||
/** @var string Option description */
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* Constructs a CLI Option
|
||||
*
|
||||
* @param string Option name
|
||||
* @param integer Option type
|
||||
* @param string Option description
|
||||
*/
|
||||
public function __construct($name, $defaultValue, $description)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_defaultValue = $defaultValue;
|
||||
$this->_description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Option name
|
||||
*
|
||||
* @return string Option name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Option default value
|
||||
*
|
||||
* @return mixed Option default value
|
||||
*/
|
||||
public function getDefaultValue()
|
||||
{
|
||||
return $this->_defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Option description
|
||||
*
|
||||
* @return string Option description
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Option instance into a string representation
|
||||
*
|
||||
* @return string CLI Option representation in string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$defaultValue = ( ! is_null($this->_defaultValue))
|
||||
? '=' . (is_array($this->_defaultValue) ? implode(',', $this->_defaultValue) : $this->_defaultValue)
|
||||
: '';
|
||||
|
||||
return '--' . $this->_name . $defaultValue;
|
||||
}
|
||||
}
|
|
@ -1,482 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
use Doctrine\Common\CLI\Printers\AbstractPrinter;
|
||||
|
||||
/**
|
||||
* CLI Option Group definition
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class OptionGroup
|
||||
{
|
||||
/* CLI Option Group CARDINALITY */
|
||||
/**
|
||||
* Defines the cardinality 0..N to CLI Option Group.
|
||||
* This means options in this group are optional and you can
|
||||
* define more than one CLI Option on a single command.
|
||||
*/
|
||||
const CARDINALITY_0_N = 0; // [...] [...] [...]
|
||||
|
||||
/**
|
||||
* Defines the cardinality 0..1 to CLI Option Group.
|
||||
* This means all options in this group are optional and you can
|
||||
* define only one CLI Option on a single command.
|
||||
*/
|
||||
const CARDINALITY_0_1 = 1; // [...|...|...]
|
||||
|
||||
/**
|
||||
* Defines the cardinality 1..1 to CLI Option Group.
|
||||
* This means all options in this group are required and you must
|
||||
* define only one CLI Option on a single command.
|
||||
*/
|
||||
const CARDINALITY_1_1 = 2; // (...|...|...)
|
||||
|
||||
/**
|
||||
* Defines the cardinality 1..N to CLI Option Group.
|
||||
* This means all options in this group are required and you must
|
||||
* define at least one CLI Option on a single command.
|
||||
*/
|
||||
const CARDINALITY_1_N = 3; // (... ... ...)
|
||||
|
||||
/**
|
||||
* Defines the cardinality N..N to CLI Option Group.
|
||||
* This means all options in this group are required and you must
|
||||
* define all CLI Options on a single command.
|
||||
*/
|
||||
const CARDINALITY_N_N = 4; // ... ... ...
|
||||
|
||||
/**
|
||||
* Defines the cardinality M..N to CLI Option Group.
|
||||
* This means all options in this group are either required or
|
||||
* optional and you can CLI Options on a single command.
|
||||
* This is the option to skip CLI Option validation.
|
||||
*/
|
||||
const CARDINALITY_M_N = 5; // ... ... ...
|
||||
|
||||
|
||||
/** @var integer Option Group cardinality */
|
||||
private $_cadinality;
|
||||
|
||||
/** @var array Option Group list of CLI Options */
|
||||
private $_options;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new CLI Option Group
|
||||
*
|
||||
* @param integer Option Group cardinality
|
||||
* @param array CLI Option Group options
|
||||
*/
|
||||
public function __construct($cardinality, $options = array())
|
||||
{
|
||||
$this->_cardinality = $cardinality;
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Option Group cardinality
|
||||
*
|
||||
* @return integer Option Group cardinality
|
||||
*/
|
||||
public function getCardinality()
|
||||
{
|
||||
return $this->_cardinality;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Option Group options
|
||||
*
|
||||
* @return array Option Group options
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the CLI Options inside this CLI Option Group
|
||||
*
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->_options = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes a new CLI Option to the Option Group
|
||||
*
|
||||
* @param Option|OptionGroup CLI Option or CLI Option Group
|
||||
* @return OptionGroup This object instance
|
||||
*/
|
||||
public function addOption($option)
|
||||
{
|
||||
if ($option instanceof Option || $option instanceof OptionGroup) {
|
||||
$this->_options[] = $option;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the CLI Option Group into a single line representation
|
||||
*
|
||||
* @param AbstractPrinter CLI Printer
|
||||
* @return string Single line string representation of CLI Option Group
|
||||
*/
|
||||
public function formatPlain(AbstractPrinter $printer)
|
||||
{
|
||||
$numOptions = count($this->_options);
|
||||
|
||||
if ($numOptions == 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$style = $this->_getGroupOptionStyle();
|
||||
$shouldDisplayExtras = (
|
||||
$numOptions > 1 ||
|
||||
$this->_cardinality == self::CARDINALITY_0_1 ||
|
||||
$this->_cardinality == self::CARDINALITY_0_N
|
||||
);
|
||||
|
||||
$str = ($shouldDisplayExtras) ? $printer->format($this->_startGroupDeclaration(), $style) : '';
|
||||
|
||||
// Loop through all CLI Options defined in OptionGroup
|
||||
for ($i = 0; $i < $numOptions; $i++) {
|
||||
$option = $this->_options[$i];
|
||||
|
||||
// Check for possible recursive OptionGroup
|
||||
if ($option instanceof OptionGroup) {
|
||||
// Simple increase nesting level by calling format recursively
|
||||
$str .= $option->formatPlain($printer);
|
||||
} else {
|
||||
// Expose the option formatted
|
||||
$str .= $printer->format((string) $option, $style);
|
||||
}
|
||||
|
||||
// Possibly append content if needed
|
||||
if ($i < $numOptions - 1) {
|
||||
$str .= $printer->format($this->_separatorGroupDeclaration(), $style);
|
||||
}
|
||||
}
|
||||
|
||||
$str .= ($shouldDisplayExtras) ? $printer->format($this->_endGroupDeclaration(), $style) : '';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
* Defines the start Option Group declaration string
|
||||
*
|
||||
* @return string Start Option Group declaration string
|
||||
*/
|
||||
private function _startGroupDeclaration()
|
||||
{
|
||||
$str = '';
|
||||
|
||||
// Inspect cardinality of OptionGroup
|
||||
switch ($this->_cardinality) {
|
||||
case self::CARDINALITY_0_1:
|
||||
case self::CARDINALITY_0_N:
|
||||
$str .= '[';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_1_1:
|
||||
case self::CARDINALITY_1_N:
|
||||
$str .= '(';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_N_N:
|
||||
case self::CARDINALITY_M_N:
|
||||
default:
|
||||
// Does nothing
|
||||
break;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
* Defines the separator Option Group declaration string
|
||||
*
|
||||
* @return string Separator Option Group declaration string
|
||||
*/
|
||||
private function _separatorGroupDeclaration()
|
||||
{
|
||||
$str = '';
|
||||
|
||||
// Inspect cardinality of OptionGroup
|
||||
switch ($this->_cardinality) {
|
||||
case self::CARDINALITY_0_1:
|
||||
case self::CARDINALITY_1_1:
|
||||
$str .= ' | ';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_1_N:
|
||||
case self::CARDINALITY_N_N:
|
||||
case self::CARDINALITY_M_N:
|
||||
$str .= ' ';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_0_N:
|
||||
$str .= '] [';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Does nothing
|
||||
break;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
* Defines the end Option Group declaration string
|
||||
*
|
||||
* @return string End Option Group declaration string
|
||||
*/
|
||||
private function _endGroupDeclaration()
|
||||
{
|
||||
$str = '';
|
||||
|
||||
// Inspect cardinality of OptionGroup
|
||||
switch ($this->_cardinality) {
|
||||
case self::CARDINALITY_0_1:
|
||||
case self::CARDINALITY_0_N:
|
||||
$str .= ']';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_1_1:
|
||||
case self::CARDINALITY_1_N:
|
||||
$str .= ')';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_N_N:
|
||||
case self::CARDINALITY_M_N:
|
||||
default:
|
||||
// Does nothing
|
||||
break;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
* Retrieve the Option Group style based on defined cardinality
|
||||
*
|
||||
* @return string CLI Style string representation
|
||||
*/
|
||||
private function _getGroupOptionStyle()
|
||||
{
|
||||
$style = 'NONE';
|
||||
|
||||
// Inspect cardinality of OptionGroup
|
||||
switch ($this->_cardinality) {
|
||||
case self::CARDINALITY_0_1:
|
||||
case self::CARDINALITY_0_N:
|
||||
$style = 'OPT_ARG';
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_1_1:
|
||||
case self::CARDINALITY_1_N:
|
||||
case self::CARDINALITY_N_N:
|
||||
case self::CARDINALITY_M_N:
|
||||
$style = 'REQ_ARG';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Does nothing
|
||||
break;
|
||||
}
|
||||
|
||||
return $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the CLI Option Group into a multi-line list with respective description
|
||||
*
|
||||
* @param AbstractPrinter CLI Printer
|
||||
* @return string Multi-line string representation of CLI Option Group
|
||||
*/
|
||||
public function formatWithDescription(AbstractPrinter $printer)
|
||||
{
|
||||
$numOptions = count($this->_options);
|
||||
|
||||
if ($numOptions == 0) {
|
||||
return 'No available options' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
$str = '';
|
||||
|
||||
// Get list of required and optional and max length options
|
||||
list(
|
||||
$requiredOptions, $optionalOptions, $maxOptionLength
|
||||
) = $this->_getOrganizedOptions(
|
||||
$this->_options, $this->_cardinality, 0
|
||||
);
|
||||
|
||||
// Array-unique options
|
||||
$requiredOptions = array_unique($requiredOptions);
|
||||
$optionalOptions = array_unique($optionalOptions);
|
||||
|
||||
// TODO Sort options alphabetically
|
||||
|
||||
// Displaying required options
|
||||
for ($i = 0, $l = count($requiredOptions); $i < $l; $i++) {
|
||||
$str .= $this->_displayOptionWithDescription(
|
||||
$printer, $requiredOptions[$i], 'REQ_ARG', $maxOptionLength
|
||||
);
|
||||
|
||||
// Include extra line breaks between options
|
||||
$str .= PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
// Displaying optional options
|
||||
for ($i = 0, $l = count($optionalOptions); $i < $l; $i++) {
|
||||
$str .= $this->_displayOptionWithDescription(
|
||||
$printer, $optionalOptions[$i], 'OPT_ARG', $maxOptionLength
|
||||
);
|
||||
|
||||
// Include extra line breaks between options
|
||||
$str .= PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organize the Options into arrays of required and optional options.
|
||||
* Also define the maximum length of CLI Options.
|
||||
*
|
||||
* @param array Array of CLI Option or CLI Option Group
|
||||
* @param integer Current CLI OptionGroup cardinality
|
||||
* @param integer Maximum length of CLI Options
|
||||
* @return array Array containing 3 indexes: required options, optional
|
||||
* options and maximum length of CLI Options
|
||||
*/
|
||||
private function _getOrganizedOptions($options, $cardinality, $maxColumn)
|
||||
{
|
||||
// Calculate maximum length and also organize the
|
||||
// options into required and optional ones
|
||||
$numOptions = count($options);
|
||||
$requiredOptions = array();
|
||||
$optionalOptions = array();
|
||||
|
||||
for ($i = 0; $i < $numOptions; $i++) {
|
||||
$option = $options[$i];
|
||||
|
||||
// Check for possible recursive OptionGroup
|
||||
if ($option instanceof OptionGroup) {
|
||||
// Initialize OptionGroup options
|
||||
$groupRequiredOptions = array();
|
||||
$groupOptionalOptions = array();
|
||||
|
||||
// Get nested information
|
||||
list(
|
||||
$groupRequiredOptions, $groupOptionalOptions, $maxGroupColumn
|
||||
) = $this->_getOrganizedOptions(
|
||||
$option->getOptions(), $option->getCardinality(), $maxColumn
|
||||
);
|
||||
|
||||
// Merge nested required and optional options
|
||||
$requiredOptions = array_merge($requiredOptions, $groupRequiredOptions);
|
||||
$optionalOptions = array_merge($optionalOptions, $groupOptionalOptions);
|
||||
|
||||
// If OptionGroup length is bigger than the current maximum, update
|
||||
if ($maxColumn < $maxGroupColumn) {
|
||||
$maxColumn = $maxGroupColumn;
|
||||
}
|
||||
} else {
|
||||
// Cardinality defines between optional or required options
|
||||
switch ($cardinality) {
|
||||
case self::CARDINALITY_0_1:
|
||||
case self::CARDINALITY_0_N:
|
||||
$optionalOptions[] = $option;
|
||||
break;
|
||||
|
||||
case self::CARDINALITY_1_1:
|
||||
case self::CARDINALITY_1_N:
|
||||
case self::CARDINALITY_N_N:
|
||||
case self::CARDINALITY_M_N:
|
||||
$requiredOptions[] = $option;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Does nothing
|
||||
break;
|
||||
}
|
||||
|
||||
// Build Option string
|
||||
$optionStr = (string) $option;
|
||||
|
||||
// + 2 = aditional spaces after option
|
||||
$length = strlen($optionStr) + 2;
|
||||
|
||||
if ($maxColumn < $length) {
|
||||
$maxColumn = $length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array($requiredOptions, $optionalOptions, $maxColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL:
|
||||
* Formats the CLI Option and also include the description
|
||||
*
|
||||
* @param AbstractPrinter CLI Printer
|
||||
* @param Option CLI Option to be formatted
|
||||
* @param string CLI Style string representation
|
||||
* @param integer Maximum CLI Option length
|
||||
* @return string Formats the current CLI Option line(s)
|
||||
*/
|
||||
private function _displayOptionWithDescription($printer, $option, $style, $maxOptionLength)
|
||||
{
|
||||
// Expose the option formatted
|
||||
$optionStr = (string) $option;
|
||||
|
||||
// Format Option string
|
||||
$str = $printer->format($optionStr, $style);
|
||||
|
||||
// Include missing spaces
|
||||
$str .= str_repeat(' ', $maxOptionLength - strlen($optionStr));
|
||||
|
||||
// Calculate and display description
|
||||
$str .= str_replace(
|
||||
PHP_EOL, PHP_EOL . str_repeat(' ', $maxOptionLength), $option->getDescription()
|
||||
);
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Printers;
|
||||
|
||||
use Doctrine\Common\CLI\Style;
|
||||
|
||||
/**
|
||||
* CLI Output Printer.
|
||||
* Abstract class responsable to provide basic methods to support output
|
||||
* styling and excerpt limited by output margin.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
abstract class AbstractPrinter
|
||||
{
|
||||
/**
|
||||
* @var resource Output Stream
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* @var integer Maximum column size
|
||||
*/
|
||||
protected $_maxColumnSize;
|
||||
|
||||
/**
|
||||
* @var array Array of Styles
|
||||
*/
|
||||
protected $_styles;
|
||||
|
||||
/**
|
||||
* Creates an instance of Printer
|
||||
*
|
||||
* @param resource $stream Output Stream
|
||||
*/
|
||||
public function __construct($stream = STDOUT)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
$this->_maxColumnSize = 80;
|
||||
|
||||
$this->_initStyles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes Printer Styles
|
||||
*
|
||||
*/
|
||||
protected function _initStyles()
|
||||
{
|
||||
// Defines base styles
|
||||
$this->addStyles(array(
|
||||
'ERROR' => new Style(),
|
||||
'INFO' => new Style(),
|
||||
'COMMENT' => new Style(),
|
||||
'HEADER' => new Style(),
|
||||
'NONE' => new Style(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a collection of styles to the Printer.
|
||||
* To include them, just call the method with the following structure:
|
||||
*
|
||||
* [php]
|
||||
* $printer->addStyles(array(
|
||||
* 'ERROR' => new Style('BLACK', 'DEFAULT', array('BOLD' => true)),
|
||||
* ...
|
||||
* ));
|
||||
*
|
||||
* @param array $tasks CLI Tasks to be included
|
||||
*/
|
||||
public function addStyles($styles)
|
||||
{
|
||||
foreach ($styles as $name => $style) {
|
||||
$this->addStyle($name, $style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single Style to Printer.
|
||||
* Example of inclusion to support a new Style:
|
||||
*
|
||||
* [php]
|
||||
* $printer->addStyle('ERROR', new Style('BLACK', 'DEFAULT', array('BOLD' => true)));
|
||||
*
|
||||
* @param string $name Style name
|
||||
* @param Style $style Style instance
|
||||
*/
|
||||
public function addStyle($name, Style $style)
|
||||
{
|
||||
$this->_styles[strtoupper($name)] = $style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a defined Style.
|
||||
*
|
||||
* @return Style
|
||||
*/
|
||||
public function getStyle($name)
|
||||
{
|
||||
if (is_string($name)) {
|
||||
$name = strtoupper($name);
|
||||
return isset($this->_styles[$name]) ? $this->_styles[$name] : null;
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum column size (defines the CLI margin).
|
||||
*
|
||||
* @param integer $maxColumnSize The maximum column size for a message
|
||||
*/
|
||||
public function setMaxColumnSize($maxColumnSize)
|
||||
{
|
||||
$this->_maxColumnSize = $maxColumnSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes to the output stream.
|
||||
*
|
||||
* @param string $message Message to be outputted
|
||||
*/
|
||||
public function output($message)
|
||||
{
|
||||
fwrite($this->_stream, $message);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats message applying the defined style and writes to the output stream.
|
||||
*
|
||||
* @param string $message Message to be outputted
|
||||
* @param mixed $style Optional style to be applied in message
|
||||
*/
|
||||
public function write($message, $style = 'NONE')
|
||||
{
|
||||
$this->output($this->format($message, $style));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a line to the output stream, formatting it by applying the defined style.
|
||||
*
|
||||
* @param string $message Message to be outputted
|
||||
* @param mixed $style Optional style to be applied in message
|
||||
*/
|
||||
public function writeln($message, $style = 'NONE')
|
||||
{
|
||||
$this->output($this->format($message, $style) . PHP_EOL);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the given message with the defined style.
|
||||
*
|
||||
* @param string $message Message to be formatted
|
||||
* @param mixed $style Style to be applied in message
|
||||
* @return string Formatted message
|
||||
*/
|
||||
abstract public function format($message, $style);
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Printers;
|
||||
|
||||
use Doctrine\Common\CLI\Style;
|
||||
|
||||
/**
|
||||
* CLI Output Printer for ANSI Color terminal
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class AnsiColorPrinter extends AbstractPrinter
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _initStyles()
|
||||
{
|
||||
$this->addStyles(array(
|
||||
'HEADER' => new Style('DEFAULT', 'DEFAULT', array('BOLD' => true)),
|
||||
'ERROR' => new Style('WHITE', 'RED', array('BOLD' => true)),
|
||||
'WARNING' => new Style('DEFAULT', 'YELLOW'),
|
||||
'KEYWORD' => new Style('BLUE', 'DEFAULT', array('BOLD' => true)),
|
||||
'REQ_ARG' => new Style('MAGENTA', 'DEFAULT', array('BOLD' => true)),
|
||||
'OPT_ARG' => new Style('CYAN', 'DEFAULT', array('BOLD' => true)),
|
||||
'INFO' => new Style('GREEN', 'DEFAULT', array('BOLD' => true)),
|
||||
'COMMENT' => new Style('DEFAULT', 'MAGENTA'),
|
||||
'NONE' => new Style(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function format($message, $style = 'NONE')
|
||||
{
|
||||
if ( ! $this->_supportsColor()) {
|
||||
return $message;
|
||||
}
|
||||
|
||||
$style = $this->getStyle($style);
|
||||
$str = $this->_getForegroundString($style)
|
||||
. $this->_getBackgroundString($style);
|
||||
$styleSet = ($str != '');
|
||||
|
||||
return $str . $message . ($styleSet ? chr(27) . '[0m' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ANSI string representation of requested color name
|
||||
*
|
||||
* @param Style $style Style
|
||||
* @return string
|
||||
*/
|
||||
protected function _getBackgroundString(Style $style)
|
||||
{
|
||||
$background = $style->getBackground();
|
||||
|
||||
if (empty($background)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$esc = chr(27);
|
||||
|
||||
switch (strtoupper($background)) {
|
||||
case 'BLACK':
|
||||
return $esc . '[40m';
|
||||
case 'RED':
|
||||
return $esc . '[41m';
|
||||
case 'GREEN':
|
||||
return $esc . '[42m';
|
||||
case 'YELLOW':
|
||||
return $esc . '[43m';
|
||||
case 'BLUE':
|
||||
return $esc . '[44m';
|
||||
case 'MAGENTA':
|
||||
return $esc . '[45m';
|
||||
case 'CYAN':
|
||||
return $esc . '[46m';
|
||||
case 'WHITE':
|
||||
return $esc . '[47m';
|
||||
case 'DEFAULT':
|
||||
default:
|
||||
return $esc . '[48m';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ANSI string representation of requested color name
|
||||
*
|
||||
* @param Style $style Style
|
||||
* @return string
|
||||
*/
|
||||
protected function _getForegroundString(Style $style)
|
||||
{
|
||||
$foreground = $style->getForeground();
|
||||
|
||||
if (empty($foreground)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$str = chr(27) . '[' . $this->_getOptionsString($style);
|
||||
|
||||
switch (strtoupper($foreground)) {
|
||||
case 'BLACK':
|
||||
return $str . '30m';
|
||||
case 'RED':
|
||||
return $str . '31m';
|
||||
case 'GREEN':
|
||||
return $str . '32m';
|
||||
case 'YELLOW':
|
||||
return $str . '33m';
|
||||
case 'BLUE':
|
||||
return $str . '34m';
|
||||
case 'MAGENTA':
|
||||
return $str . '35m';
|
||||
case 'CYAN':
|
||||
return $str . '36m';
|
||||
case 'WHITE':
|
||||
return $str . '37m';
|
||||
case 'DEFAULT_FGU':
|
||||
return $str . '38m';
|
||||
case 'DEFAULT':
|
||||
default:
|
||||
return $str . '39m';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ANSI string representation of requested options
|
||||
*
|
||||
* @param Style $style Style
|
||||
* @return string
|
||||
*/
|
||||
protected function _getOptionsString(Style $style)
|
||||
{
|
||||
$options = $style->getOptions();
|
||||
|
||||
if (empty($options)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$str = '';
|
||||
|
||||
foreach ($options as $name => $value) {
|
||||
if ($value) {
|
||||
$name = strtoupper($name);
|
||||
|
||||
switch ($name) {
|
||||
case 'BOLD':
|
||||
$str .= '1;';
|
||||
break;
|
||||
case 'HALF':
|
||||
$str .= '2;';
|
||||
break;
|
||||
case 'UNDERLINE':
|
||||
$str .= '4;';
|
||||
break;
|
||||
case 'BLINK':
|
||||
$str .= '5;';
|
||||
break;
|
||||
case 'REVERSE':
|
||||
$str .= '7;';
|
||||
break;
|
||||
case 'CONCEAL':
|
||||
$str .= '8;';
|
||||
break;
|
||||
default:
|
||||
// Ignore unknown option
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current Output Stream supports ANSI Colors
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private function _supportsColor()
|
||||
{
|
||||
return DIRECTORY_SEPARATOR != '\\' &&
|
||||
function_exists('posix_isatty') &&
|
||||
@posix_isatty($this->_stream);
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Printers;
|
||||
|
||||
use Doctrine\Common\CLI\Style;
|
||||
|
||||
/**
|
||||
* CLI Output Printer for Normal terminal
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class NormalPrinter extends AbstractPrinter
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function format($message, $style)
|
||||
{
|
||||
return $message;
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* CLI Output Style
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class Style
|
||||
{
|
||||
/**
|
||||
* @var string Background color
|
||||
*/
|
||||
private $_background;
|
||||
|
||||
/**
|
||||
* @var string Foreground color
|
||||
*/
|
||||
private $_foreground;
|
||||
|
||||
/**
|
||||
* @var array Formatting options
|
||||
*/
|
||||
private $_options = array();
|
||||
|
||||
/**
|
||||
* @param string $foreground Foreground color name
|
||||
* @param string $background Background color name
|
||||
* @param array $options Formatting options
|
||||
*/
|
||||
public function __construct($foreground = null, $background = null, $options = array())
|
||||
{
|
||||
$this->_foreground = strtoupper($foreground);
|
||||
$this->_background = strtoupper($background);
|
||||
$this->_options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the foreground color name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getForeground()
|
||||
{
|
||||
return $this->_foreground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the background color name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBackground()
|
||||
{
|
||||
return $this->_background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the formatting options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
use Doctrine\Common\CLI\Printers\AbstractPrinter,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\Common\CLI\Option;
|
||||
|
||||
/**
|
||||
* CLI Task documentation
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class TaskDocumentation
|
||||
{
|
||||
/** @var AbstractPrinter CLI Printer */
|
||||
private $_printer;
|
||||
|
||||
/** @var AbstractNamespace CLI Namespace */
|
||||
private $_namespace;
|
||||
|
||||
/** @var string CLI Task name */
|
||||
private $_name;
|
||||
|
||||
/** @var string CLI Task description */
|
||||
private $_description;
|
||||
|
||||
/** @var array CLI Task Option Group */
|
||||
private $_optionGroup;
|
||||
|
||||
/**
|
||||
* Constructs a new CLI Task Documentation
|
||||
*
|
||||
* @param AbstractNamespace CLI Namespace
|
||||
*/
|
||||
public function __construct(AbstractNamespace $namespace)
|
||||
{
|
||||
$this->_namespace = $namespace;
|
||||
$this->_printer = $namespace->getPrinter();
|
||||
$this->_optionGroup = new OptionGroup(OptionGroup::CARDINALITY_M_N);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Namespace
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the CLI Task name
|
||||
*
|
||||
* @param string Task name
|
||||
* @return TaskDocumentation This object instance
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Task name
|
||||
*
|
||||
* @return string Task name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the full CLI Task name
|
||||
*
|
||||
* @return string Task full name
|
||||
*/
|
||||
public function getFullName()
|
||||
{
|
||||
return $this->getNamespace()->getFullName() . ':' . $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the CLI Task description
|
||||
*
|
||||
* @param string Task description
|
||||
* @return TaskDocumentation This object instance
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->_description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Task description
|
||||
*
|
||||
* @var string Task description
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Task Option Group
|
||||
*
|
||||
* @return OptionGroup CLI Task Option Group
|
||||
*/
|
||||
public function getOptionGroup()
|
||||
{
|
||||
return $this->_optionGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes a new CLI Option Group to the CLI Task documentation
|
||||
*
|
||||
* @param OptionGroup CLI Option Group
|
||||
* @return TaskDocumentation This object instance
|
||||
*/
|
||||
public function addOption($option)
|
||||
{
|
||||
if ($option instanceof OptionGroup) {
|
||||
$this->_optionGroup->addOption($option);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the synopsis of associated CLI Task
|
||||
*
|
||||
* @return string CLI Task synopsis
|
||||
*/
|
||||
public function getSynopsis()
|
||||
{
|
||||
return $this->_printer->format($this->getFullName(), 'KEYWORD') . ' '
|
||||
. trim($this->_optionGroup->formatPlain($this->_printer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the complete documentation of associated CLI Task
|
||||
*
|
||||
* @return string CLI Task complete documentation
|
||||
*/
|
||||
public function getCompleteDocumentation()
|
||||
{
|
||||
$printer = $this->_printer;
|
||||
|
||||
return $printer->format('Task: ')
|
||||
. $printer->format($this->getFullName(), 'KEYWORD')
|
||||
. $printer->format(PHP_EOL)
|
||||
. $printer->format('Synopsis: ')
|
||||
. $this->getSynopsis()
|
||||
. $printer->format(PHP_EOL)
|
||||
. $printer->format('Description: ')
|
||||
. $printer->format($this->_description)
|
||||
. $printer->format(PHP_EOL)
|
||||
. $printer->format('Options: ')
|
||||
. $printer->format(PHP_EOL)
|
||||
. $this->_optionGroup->formatWithDescription($printer);
|
||||
}
|
||||
}
|
|
@ -1,251 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI;
|
||||
|
||||
/**
|
||||
* CLI Namespace class
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class TaskNamespace extends AbstractNamespace
|
||||
{
|
||||
/**
|
||||
* @var boolean CLI Tasks flag to check if they are already initialized
|
||||
*/
|
||||
private $_initialized = false;
|
||||
|
||||
/**
|
||||
* @var string CLI Namespace full name
|
||||
*/
|
||||
private $_fullName = null;
|
||||
|
||||
/**
|
||||
* @var string CLI Namespace name
|
||||
*/
|
||||
private $_name = null;
|
||||
|
||||
/**
|
||||
* @var array Available tasks
|
||||
*/
|
||||
private $_tasks = array();
|
||||
|
||||
/**
|
||||
* The CLI namespace
|
||||
*
|
||||
* @param string $name CLI Namespace name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->_name = self::formatName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an instantiated CLI Task by given its name.
|
||||
*
|
||||
* @param string $name CLI Task name
|
||||
*
|
||||
* @return AbstractTask
|
||||
*/
|
||||
public function getTask($name)
|
||||
{
|
||||
// Check if task exists in namespace
|
||||
if ($this->hasTask($name)) {
|
||||
$taskClass = $this->_tasks[self::formatName($name)];
|
||||
|
||||
return new $taskClass($this);
|
||||
}
|
||||
|
||||
throw CLIException::taskDoesNotExist($name, $this->getFullName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all CLI Task in this Namespace.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTasks()
|
||||
{
|
||||
return $this->_tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all defined CLI Tasks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableTasks()
|
||||
{
|
||||
$tasks = parent::getAvailableTasks();
|
||||
|
||||
foreach ($this->_tasks as $taskName => $taskClass) {
|
||||
$fullName = $this->getFullName() . ':' . $taskName;
|
||||
|
||||
$tasks[$fullName] = $taskClass;
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a single task to CLI Namespace.
|
||||
* Example of inclusion support to a single task:
|
||||
*
|
||||
* [php]
|
||||
* $cliOrmNamespace->addTask('my-custom-task', 'MyProject\Cli\Tasks\MyCustomTask');
|
||||
*
|
||||
* @param string $name CLI Task name
|
||||
* @param string $class CLI Task class (FQCN - Fully Qualified Class Name)
|
||||
*
|
||||
* @return TaskNamespace This object instance
|
||||
*/
|
||||
public function addTask($name, $class)
|
||||
{
|
||||
$name = self::formatName($name);
|
||||
|
||||
if ($this->hasTask($name)) {
|
||||
throw CLIException::cannotOverrideTask($name);
|
||||
}
|
||||
|
||||
return $this->overrideTask($name, $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides task on CLI Namespace.
|
||||
* Example of inclusion support to a single task:
|
||||
*
|
||||
* [php]
|
||||
* $cliOrmNamespace->overrideTask('schema-tool', 'MyProject\Cli\Tasks\MyCustomTask');
|
||||
*
|
||||
* @param string $name CLI Task name
|
||||
* @param string $class CLI Task class (FQCN - Fully Qualified Class Name)
|
||||
*
|
||||
* @return TaskNamespace This object instance
|
||||
*/
|
||||
public function overrideTask($name, $class)
|
||||
{
|
||||
$name = self::formatName($name);
|
||||
|
||||
$this->_tasks[$name] = $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check existance of a CLI Task
|
||||
*
|
||||
* @param string CLI Task name
|
||||
*
|
||||
* @return boolean TRUE if CLI Task if defined, false otherwise
|
||||
*/
|
||||
public function hasTask($name)
|
||||
{
|
||||
$name = self::formatName($name);
|
||||
|
||||
return isset($this->_tasks[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Namespace name
|
||||
*
|
||||
* @return string CLI Namespace name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the full CLI Namespace name
|
||||
*
|
||||
* @return string CLI Namespace full name
|
||||
*/
|
||||
public function getFullName()
|
||||
{
|
||||
if ($this->_fullName === null) {
|
||||
$str = $this->_name;
|
||||
|
||||
while (
|
||||
($parentNamespace = $this->getParentNamespace()) !== null &&
|
||||
! ($parentNamespace instanceof CliController)
|
||||
) {
|
||||
$str = $parentNamespace->getFullName() . ':' . $str;
|
||||
}
|
||||
|
||||
$this->_fullName = $str;
|
||||
}
|
||||
|
||||
return $this->_fullName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effectively instantiate and execute a given CLI Task
|
||||
*
|
||||
* @param string $name CLI Task name
|
||||
* @param array $arguments CLI Task arguments
|
||||
*/
|
||||
public function runTask($name, $arguments = array())
|
||||
{
|
||||
try {
|
||||
$task = $this->getTask($name);
|
||||
|
||||
// Merge global configuration if it exists
|
||||
if (($globalArgs = $this->getConfiguration()->getAttribute('globalArguments')) !== null) {
|
||||
$arguments = array_merge($globalArgs, $arguments);
|
||||
}
|
||||
|
||||
$task->setArguments($arguments);
|
||||
|
||||
if ((isset($arguments['help']) && $arguments['help']) || (isset($arguments['h']) && $arguments['h'])) {
|
||||
$task->extendedHelp(); // User explicitly asked for help option
|
||||
} else if (isset($arguments['basic-help']) && $arguments['basic-help']) {
|
||||
$task->basicHelp(); // User explicitly asked for basic help option
|
||||
} else if ($task->validate()) {
|
||||
$task->run();
|
||||
}
|
||||
} catch (CLIException $e) {
|
||||
$message = $this->getFullName() . ':' . $name . ' => ' . $e->getMessage();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
// If we want the trace of calls, append to error message
|
||||
if (isset($arguments['trace']) && $arguments['trace']) {
|
||||
$message .= PHP_EOL . PHP_EOL . $e->getTraceAsString();
|
||||
}
|
||||
|
||||
$printer->writeln($message, 'ERROR');
|
||||
|
||||
// Unable instantiate task or task is not valid
|
||||
if (isset($task) && $task !== null) {
|
||||
$printer->write(PHP_EOL);
|
||||
$task->basicHelp(); // Fallback of not-valid task arguments
|
||||
}
|
||||
|
||||
$printer->write(PHP_EOL);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,200 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\AbstractNamespace,
|
||||
Doctrine\Common\CLI\TaskDocumentation;
|
||||
|
||||
/**
|
||||
* Base class for CLI Tasks.
|
||||
* Provides basic methods and requires implementation of methods that
|
||||
* each task should implement in order to correctly work.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
abstract class AbstractTask
|
||||
{
|
||||
/**
|
||||
* @var AbstractNamespace CLI Namespace
|
||||
*/
|
||||
protected $_printer;
|
||||
|
||||
/**
|
||||
* @var TaskDocumentation CLI Task Documentation
|
||||
*/
|
||||
protected $_documentation;
|
||||
|
||||
/**
|
||||
* @var array CLI Task arguments
|
||||
*/
|
||||
protected $_arguments = array();
|
||||
|
||||
/**
|
||||
* Constructor of CLI Task
|
||||
*
|
||||
* @param AbstractNamespace CLI Namespace
|
||||
*/
|
||||
public function __construct(AbstractNamespace $namespace)
|
||||
{
|
||||
$this->_namespace = $namespace;
|
||||
$this->_documentation = new TaskDocumentation($namespace);
|
||||
|
||||
// Complete the CLI Task Documentation creation
|
||||
$this->buildDocumentation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Namespace
|
||||
*
|
||||
* @return AbstractNamespace
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Task Documentation
|
||||
*
|
||||
* @return TaskDocumentation
|
||||
*/
|
||||
public function getDocumentation()
|
||||
{
|
||||
return $this->_documentation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the CLI Task arguments
|
||||
*
|
||||
* @param array $arguments CLI Task arguments
|
||||
*
|
||||
* @return AbstractTask
|
||||
*/
|
||||
public function setArguments(array $arguments = array())
|
||||
{
|
||||
$this->_arguments = $arguments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the CLI Task arguments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->_arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves currently used CLI Output Printer
|
||||
*
|
||||
* @return AbstractPrinter
|
||||
*/
|
||||
public function getPrinter()
|
||||
{
|
||||
return $this->_namespace->getPrinter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves current used CLI Configuration
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function getConfiguration()
|
||||
{
|
||||
return $this->_namespace->getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose to CLI Output Printer the extended help of the given task.
|
||||
* This means it should detail all parameters, options and the meaning
|
||||
* of each one.
|
||||
* This method is executed when user types in CLI the following command:
|
||||
*
|
||||
* [bash]
|
||||
* ./doctrine task --help
|
||||
*
|
||||
*/
|
||||
public function extendedHelp()
|
||||
{
|
||||
$this->getPrinter()->output($this->_documentation->getCompleteDocumentation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose to CLI Output Printer the basic help of the given task.
|
||||
* This means it should only expose the basic task call. It is also
|
||||
* executed when user calls the global help; so this means it should
|
||||
* not pollute the Printer.
|
||||
* Basic help exposure is displayed when task does not pass the validate
|
||||
* (which means when user does not type the required options or when given
|
||||
* options are invalid, ie: invalid option), or when user requests to have
|
||||
* description of all available tasks.
|
||||
* This method is executed when user uses the following commands:
|
||||
*
|
||||
* [bash]
|
||||
* ./doctrine task --invalid-option
|
||||
* ./doctrine --help
|
||||
*
|
||||
*/
|
||||
public function basicHelp()
|
||||
{
|
||||
$this->getPrinter()
|
||||
->output($this->_documentation->getSynopsis())
|
||||
->output(PHP_EOL)
|
||||
->output(' ' . $this->_documentation->getDescription())
|
||||
->output(PHP_EOL . PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assures the given arguments matches with required/optional ones.
|
||||
* This method should be used to introspect arguments to check for
|
||||
* missing required arguments and also for invalid defined options.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
// TODO implement DAG here!
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely execution of task.
|
||||
* Each CLI task should implement this as normal flow execution of
|
||||
* what is supposed to do.
|
||||
*/
|
||||
abstract public function run();
|
||||
|
||||
/**
|
||||
* Generate the CLI Task Documentation
|
||||
*/
|
||||
abstract public function buildDocumentation();
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\CLIException;
|
||||
|
||||
/**
|
||||
* CLI Task to display available commands help
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class HelpTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('help')
|
||||
->setDescription('Exposes helpful information about all available tasks.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function extendedHelp()
|
||||
{
|
||||
$this->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposes the available tasks
|
||||
*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->getPrinter()->writeln('Available Tasks:', 'HEADER')->write(PHP_EOL);
|
||||
|
||||
// Find the CLI Controller
|
||||
$cliController = $this->getNamespace()->getParentNamespace();
|
||||
|
||||
// Switch between ALL available tasks and display the basic Help of each one
|
||||
$availableTasks = $cliController->getAvailableTasks();
|
||||
//unset($availableTasks['Core:Help']);
|
||||
|
||||
ksort($availableTasks);
|
||||
|
||||
foreach (array_keys($availableTasks) as $taskName) {
|
||||
$cliController->runTask($taskName, array('basic-help' => true));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\Common\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\Version;
|
||||
|
||||
/**
|
||||
* CLI Task to display the doctrine version
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class VersionTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
// There're no options on this task
|
||||
$this->getDocumentation()->getOptionGroup()->clear();
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('version')
|
||||
->setDescription('Displays the current installed Doctrine version.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the current version of Doctrine
|
||||
*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO');
|
||||
}
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\Common\Util\Debug,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup;
|
||||
|
||||
/**
|
||||
* Task for executing arbitrary SQL that can come from a file or directly from
|
||||
* the command line.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class RunSqlTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$dqlAndFile = new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option(
|
||||
'sql', '<SQL>', 'The SQL to execute.' . PHP_EOL .
|
||||
'If defined, --file can not be requested on same task.'
|
||||
),
|
||||
new Option(
|
||||
'file', '<PATH>', 'The path to the file with the SQL to execute.' . PHP_EOL .
|
||||
'If defined, --sql can not be requested on same task.'
|
||||
)
|
||||
));
|
||||
|
||||
$depth = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option('depth', '<DEPTH>', 'Dumping depth of Entities graph.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('run-sql')
|
||||
->setDescription('Executes arbitrary SQL from a file or directly from the command line.')
|
||||
->getOptionGroup()
|
||||
->addOption($dqlAndFile)
|
||||
->addOption($depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! (isset($arguments['sql']) ^ isset($arguments['file']))) {
|
||||
throw new CLIException('One of --sql or --file required, and only one.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the task.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
if (isset($arguments['file'])) {
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
$conn = $em->getConnection();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
$fileNames = (array) $arguments['file'];
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
if ( ! file_exists($fileName)) {
|
||||
throw new CLIException(sprintf('The SQL file [%s] does not exist.', $fileName));
|
||||
} else if ( ! is_readable($fileName)) {
|
||||
throw new CLIException(sprintf('The SQL file [%s] does not have read permissions.', $fileName));
|
||||
}
|
||||
|
||||
$printer->write('Processing file [' . $fileName . ']... ');
|
||||
$sql = file_get_contents($fileName);
|
||||
|
||||
if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) {
|
||||
// PDO Drivers
|
||||
try {
|
||||
$lines = 0;
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
do {
|
||||
// Required due to "MySQL has gone away!" issue
|
||||
$stmt->fetch();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$lines++;
|
||||
} while ($stmt->nextRowset());
|
||||
|
||||
$printer->writeln(sprintf('%d statements executed!', $lines));
|
||||
} catch (\PDOException $e) {
|
||||
$printer->writeln('error!')
|
||||
->writeln($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
// Non-PDO Drivers (ie. OCI8 driver)
|
||||
$stmt = $conn->prepare($sql);
|
||||
$rs = $stmt->execute();
|
||||
|
||||
if ($rs) {
|
||||
$printer->writeln('OK!');
|
||||
} else {
|
||||
$error = $stmt->errorInfo();
|
||||
|
||||
$printer->writeln('error!')
|
||||
->writeln($error['message']);
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
}
|
||||
} else if (isset($arguments['sql'])) {
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if (preg_match('/^select/i', $arguments['sql'])) {
|
||||
$stmt = $em->getConnection()->executeQuery($arguments['sql']);
|
||||
$resultSet = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC);
|
||||
} else {
|
||||
$resultSet = $em->getConnection()->executeUpdate($arguments['sql']);
|
||||
}
|
||||
|
||||
$maxDepth = isset($arguments['depth']) ? $arguments['depth'] : 7;
|
||||
|
||||
Debug::dump($resultSet, $maxDepth);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\DBAL\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\Version;
|
||||
|
||||
/**
|
||||
* CLI Task to display the doctrine version
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class VersionTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
// There're no options on this task
|
||||
$this->getDocumentation()->getOptionGroup()->clear();
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('version')
|
||||
->setDescription('Displays the current installed Doctrine version.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the current version of Doctrine
|
||||
*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO');
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CliException,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\Common\Cache\AbstractDriver;
|
||||
|
||||
/**
|
||||
* CLI Task to clear the cache of the various cache drivers
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class ClearCacheTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$cacheOptions = new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option('query', null, 'Clear the query cache.'),
|
||||
new Option('metadata', null, 'Clear the metadata cache.'),
|
||||
new OptionGroup(OptionGroup::CARDINALITY_M_N, array(
|
||||
new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option('result', null, 'Clear the result cache.')
|
||||
)),
|
||||
new OptionGroup(OptionGroup::CARDINALITY_0_N, array(
|
||||
new Option('id', '<ID>', 'The id of the cache entry to delete (accepts * wildcards).'),
|
||||
new Option('regex', '<REGEX>', 'Delete cache entries that match the given regular expression.'),
|
||||
new Option('prefix', '<PREFIX>', 'Delete cache entries that have the given prefix.'),
|
||||
new Option('suffix', '<SUFFIX>', 'Delete cache entries that have the given suffix.')
|
||||
))
|
||||
))
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('clear-cache')
|
||||
->setDescription('Clear cache from configured query, result and metadata drivers.')
|
||||
->getOptionGroup()
|
||||
->addOption($cacheOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
// Check if we have an active EntityManager
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
// When clearing the query cache no need to specify
|
||||
// id, regex, prefix or suffix.
|
||||
if (
|
||||
(isset($arguments['query']) || isset($arguments['metadata'])) && (isset($arguments['id']) ||
|
||||
isset($arguments['regex']) || isset($arguments['prefix']) || isset($arguments['suffix']))
|
||||
) {
|
||||
throw new CLIException(
|
||||
'When clearing the query or metadata cache do not ' .
|
||||
'specify any --id, --regex, --prefix or --suffix.'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
$query = isset($arguments['query']);
|
||||
$result = isset($arguments['result']);
|
||||
$metadata = isset($arguments['metadata']);
|
||||
$id = isset($arguments['id']) ? $arguments['id'] : null;
|
||||
$regex = isset($arguments['regex']) ? $arguments['regex'] : null;
|
||||
$prefix = isset($arguments['prefix']) ? $arguments['prefix'] : null;
|
||||
$suffix = isset($arguments['suffix']) ? $arguments['suffix'] : null;
|
||||
|
||||
$all = false;
|
||||
|
||||
if ( ! $query && ! $result && ! $metadata) {
|
||||
$all = true;
|
||||
}
|
||||
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
$configuration = $em->getConfiguration();
|
||||
|
||||
if ($query || $all) {
|
||||
$this->_doDelete(
|
||||
'query', $configuration->getQueryCacheImpl(), $id, $regex, $prefix, $suffix
|
||||
);
|
||||
}
|
||||
|
||||
if ($result || $all) {
|
||||
$this->_doDelete(
|
||||
'result', $configuration->getResultCacheImpl(), $id, $regex, $prefix, $suffix
|
||||
);
|
||||
}
|
||||
|
||||
if ($metadata || $all) {
|
||||
$this->_doDelete(
|
||||
'metadata', $configuration->getMetadataCacheImpl(), $id, $regex, $prefix, $suffix
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function _doDelete($type, $cacheDriver, $id, $regex, $prefix, $suffix)
|
||||
{
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
if ( ! $cacheDriver) {
|
||||
throw new CLIException('No driver has been configured for the ' . $type . ' cache.');
|
||||
}
|
||||
|
||||
if ($id) {
|
||||
$printer->writeln('Clearing ' . $type . ' cache entries that match the id "' . $id . '".', 'INFO');
|
||||
|
||||
$deleted = $cacheDriver->delete($id);
|
||||
|
||||
if (is_array($deleted)) {
|
||||
$this->_printDeleted($type, $deleted);
|
||||
} else if (is_bool($deleted) && $deleted) {
|
||||
$this->_printDeleted($type, array($id));
|
||||
}
|
||||
}
|
||||
|
||||
if ($regex) {
|
||||
$printer->writeln('Clearing ' . $type . ' cache entries that match the regular expression ".' . $regex . '"', 'INFO');
|
||||
|
||||
$this->_printDeleted($type, $cacheDriver->deleteByRegex('/' . $regex. '/'));
|
||||
}
|
||||
|
||||
if ($prefix) {
|
||||
$printer->writeln('Clearing ' . $type . ' cache entries that have the prefix "' . $prefix . '".', 'INFO');
|
||||
|
||||
$this->_printDeleted($type, $cacheDriver->deleteByPrefix($prefix));
|
||||
}
|
||||
|
||||
if ($suffix) {
|
||||
$printer->writeln('Clearing ' . $type . ' cache entries that have the suffix "' . $suffix . '".', 'INFO');
|
||||
|
||||
$this->_printDeleted($type, $cacheDriver->deleteBySuffix($suffix));
|
||||
}
|
||||
|
||||
if ( ! $id && ! $regex && ! $prefix && ! $suffix) {
|
||||
$printer->writeln('Clearing all ' . $type . ' cache entries.', 'INFO');
|
||||
|
||||
$this->_printDeleted($type, $cacheDriver->deleteAll());
|
||||
}
|
||||
}
|
||||
|
||||
private function _printDeleted($type, array $ids)
|
||||
{
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
if ( ! empty($ids)) {
|
||||
foreach ($ids as $id) {
|
||||
$printer->writeln(' - ' . $id);
|
||||
}
|
||||
} else {
|
||||
throw new CLIException('No ' . $type . ' cache entries found.');
|
||||
}
|
||||
|
||||
$printer->write(PHP_EOL);
|
||||
}
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\ORM\Tools\Export\ClassMetadataExporter,
|
||||
Doctrine\Common\CLI\CliException,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\ORM\Tools\ConvertDoctrine1Schema,
|
||||
Doctrine\ORM\Tools\EntityGenerator;
|
||||
|
||||
/**
|
||||
* CLI Task to convert a Doctrine 1 schema to a Doctrine 2 mapping file
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class ConvertDoctrine1SchemaTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$options = new OptionGroup(OptionGroup::CARDINALITY_N_N, array(
|
||||
new Option('from', '<FROM>', 'The path to the Doctrine 1 schema.'),
|
||||
new Option('to', '<TO>', 'The Doctrine 2 mapping format to convert to.'),
|
||||
new Option('dest', '<DEST>', 'The path to export the converted schema.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('convert-10-schema')
|
||||
->setDescription('Converts a Doctrine 1.X schema into a Doctrine 2.X schema.')
|
||||
->getOptionGroup()
|
||||
->addOption($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ( ! isset($arguments['from']) || ! isset($arguments['to']) || ! isset($arguments['dest'])) {
|
||||
throw new CLIException('You must specify a value for --from, --to and --dest');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
$printer->writeln(sprintf(
|
||||
'Converting Doctrine 1 schema at "%s" to the "%s" format',
|
||||
$printer->format($arguments['from'], 'KEYWORD'),
|
||||
$printer->format($arguments['to'], 'KEYWORD')
|
||||
)
|
||||
);
|
||||
|
||||
$cme = new ClassMetadataExporter();
|
||||
$exporter = $cme->getExporter($arguments['to'], $arguments['dest']);
|
||||
|
||||
if ($arguments['to'] === 'annotation') {
|
||||
$entityGenerator = new EntityGenerator();
|
||||
$exporter->setEntityGenerator($entityGenerator);
|
||||
}
|
||||
|
||||
$converter = new ConvertDoctrine1Schema($arguments['from']);
|
||||
$metadatas = $converter->getMetadatas();
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
$printer->writeln(
|
||||
sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD'))
|
||||
);
|
||||
}
|
||||
|
||||
$exporter->setMetadatas($metadatas);
|
||||
$exporter->export();
|
||||
|
||||
$printer->writeln(sprintf(
|
||||
'Writing Doctrine 2 mapping files to "%s"',
|
||||
$printer->format($arguments['dest'], 'KEYWORD')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CliException,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\ORM\Tools\EntityGenerator,
|
||||
Doctrine\ORM\Tools\Export\ClassMetadataExporter,
|
||||
Doctrine\ORM\Mapping\Driver\DriverChain,
|
||||
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
|
||||
Doctrine\ORM\Mapping\Driver\Driver;
|
||||
|
||||
/**
|
||||
* CLI Task to convert your mapping information between the various formats
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class ConvertMappingTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$convertOptions = new OptionGroup(OptionGroup::CARDINALITY_N_N, array(
|
||||
new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option('from', '<SOURCE>', 'The path to the mapping information to convert from (yml, xml, php, annotation).'),
|
||||
new Option('from-database', null, 'Use this option if you wish to reverse engineer your database to a set of Doctrine mapping files.')
|
||||
)),
|
||||
new Option('to', '<TYPE>', 'The format to convert to (yml, xml, php, annotation).'),
|
||||
new Option('dest', '<PATH>', 'The path to write the converted mapping information.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('convert-mapping')
|
||||
->setDescription('Convert mapping information between supported formats.')
|
||||
->getOptionGroup()
|
||||
->addOption($convertOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
if (isset($arguments['from-database']) && $arguments['from-database']) {
|
||||
$arguments['from'] = 'database';
|
||||
|
||||
$this->setArguments($arguments);
|
||||
}
|
||||
|
||||
if (!(isset($arguments['from']) && isset($arguments['to']) && isset($arguments['dest']))) {
|
||||
throw new CLIException(
|
||||
'You must include a value for all three options: --from, --to and --dest.'
|
||||
);
|
||||
}
|
||||
|
||||
if (strtolower($arguments['to']) != 'annotation' && isset($arguments['extend'])) {
|
||||
throw new CLIException(
|
||||
'You can only use the --extend argument when converting to annotations.'
|
||||
);
|
||||
}
|
||||
|
||||
if (strtolower($arguments['from']) == 'database') {
|
||||
// Check if we have an active EntityManager
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
$config = $em->getConfiguration();
|
||||
$config->setMetadataDriverImpl(
|
||||
new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
|
||||
$em->getConnection()->getSchemaManager()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$cme = new ClassMetadataExporter();
|
||||
$cme->setEntityManager($this->getConfiguration()->getAttribute('em'));
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
// Get exporter and configure it
|
||||
$exporter = $cme->getExporter($arguments['to'], $arguments['dest']);
|
||||
|
||||
if ($arguments['to'] === 'annotation') {
|
||||
$entityGenerator = new EntityGenerator();
|
||||
$exporter->setEntityGenerator($entityGenerator);
|
||||
|
||||
if (isset($arguments['extend']) && $arguments['extend']) {
|
||||
$entityGenerator->setClassToExtend($arguments['extend']);
|
||||
}
|
||||
|
||||
if (isset($arguments['num-spaces']) && $arguments['extend']) {
|
||||
$entityGenerator->setNumSpaces($arguments['num-spaces']);
|
||||
}
|
||||
}
|
||||
|
||||
$from = (array) $arguments['from'];
|
||||
|
||||
foreach ($from as $source) {
|
||||
$cme->addMappingSource($source);
|
||||
}
|
||||
|
||||
$metadatas = $cme->getMetadatas();
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
$printer->writeln(
|
||||
sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD'))
|
||||
);
|
||||
}
|
||||
|
||||
$printer->writeln('');
|
||||
$printer->writeln(
|
||||
sprintf(
|
||||
'Exporting "%s" mapping information to "%s"',
|
||||
$printer->format($arguments['to'], 'KEYWORD'),
|
||||
$printer->format($arguments['dest'], 'KEYWORD')
|
||||
)
|
||||
);
|
||||
|
||||
$exporter->setMetadatas($metadatas);
|
||||
$exporter->export();
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CLIException;
|
||||
|
||||
/**
|
||||
* CLI Task to ensure that Doctrine is properly configured for a production environment.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class EnsureProductionSettingsTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('ensure-production-settings')
|
||||
->setDescription('Verify that Doctrine is properly configured for a production environment.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
// Check if we have an active EntityManager
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
$em->getConfiguration()->ensureProductionSettings();
|
||||
|
||||
$this->getPrinter()->writeln('Environment is correctly configured for production.');
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\ORM\Tools\EntityGenerator,
|
||||
Doctrine\ORM\Tools\ClassMetadataReader;
|
||||
|
||||
/**
|
||||
* CLI Task to generate entity classes and method stubs from your mapping information.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class GenerateEntitiesTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$options = new OptionGroup(OptionGroup::CARDINALITY_N_N, array(
|
||||
new Option('from', '<FROM>', 'The path to mapping information.'),
|
||||
new Option('dest', '<DEST>', 'The path to generate your entity classes.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('generate-entities')
|
||||
->setDescription('Generate entity classes and method stubs from your mapping information.')
|
||||
->getOptionGroup()
|
||||
->addOption($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
|
||||
if ( ! isset($arguments['from']) || ! isset($arguments['dest'])) {
|
||||
throw new CLIException('You must specify a value for --from and --dest');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$printer = $this->getPrinter();
|
||||
$arguments = $this->getArguments();
|
||||
$from = $arguments['from'];
|
||||
$dest = realpath($arguments['dest']);
|
||||
|
||||
$entityGenerator = new EntityGenerator();
|
||||
$entityGenerator->setGenerateAnnotations(false);
|
||||
$entityGenerator->setGenerateStubMethods(true);
|
||||
$entityGenerator->setRegenerateEntityIfExists(false);
|
||||
$entityGenerator->setUpdateEntityIfExists(true);
|
||||
|
||||
if (isset($arguments['extend']) && $arguments['extend']) {
|
||||
$entityGenerator->setClassToExtend($arguments['extend']);
|
||||
}
|
||||
|
||||
if (isset($arguments['num-spaces']) && $arguments['extend']) {
|
||||
$entityGenerator->setNumSpaces($arguments['num-spaces']);
|
||||
}
|
||||
|
||||
$reader = new ClassMetadataReader();
|
||||
$reader->setEntityManager($this->getConfiguration()->getAttribute('em'));
|
||||
$reader->addMappingSource($from);
|
||||
$metadatas = $reader->getMetadatas();
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
$printer->writeln(
|
||||
sprintf('Processing entity "%s"', $printer->format($metadata->name, 'KEYWORD'))
|
||||
);
|
||||
}
|
||||
|
||||
$entityGenerator->generate($metadatas, $dest);
|
||||
|
||||
$printer->write(PHP_EOL);
|
||||
$printer->writeln(
|
||||
sprintf('Entity classes generated to "%s"',
|
||||
$printer->format($dest, 'KEYWORD')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup;
|
||||
|
||||
/**
|
||||
* Task to (re)generate the proxy classes used by doctrine.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision: 3938 $
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class GenerateProxiesTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$classDir = new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option('class-dir', '<PATH>', 'Specified directory where mapping classes are located.')
|
||||
));
|
||||
|
||||
$toDir = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option('to-dir', '<PATH>', 'Generates the classes in the specified directory.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('generate-proxies')
|
||||
->setDescription('Generates proxy classes for entity classes.')
|
||||
->getOptionGroup()
|
||||
->addOption($classDir)
|
||||
->addOption($toDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
|
||||
|
||||
if ($metadataDriver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) {
|
||||
if (isset($arguments['class-dir'])) {
|
||||
$metadataDriver->addPaths((array) $arguments['class-dir']);
|
||||
} else {
|
||||
throw new CLIException(
|
||||
'The supplied configuration uses the annotation metadata driver. ' .
|
||||
"The 'class-dir' argument is required for this driver."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
$cmf = $em->getMetadataFactory();
|
||||
$classes = $cmf->getAllMetadata();
|
||||
$factory = $em->getProxyFactory();
|
||||
|
||||
if (empty($classes)) {
|
||||
$printer->writeln('No classes to process.', 'INFO');
|
||||
} else {
|
||||
foreach ($classes as $class) {
|
||||
$printer->writeln(
|
||||
sprintf('Processing entity "%s"', $printer->format($class->name, 'KEYWORD'))
|
||||
);
|
||||
}
|
||||
|
||||
$factory->generateProxyClasses(
|
||||
$classes, isset($arguments['to-dir']) ? $arguments['to-dir'] : null
|
||||
);
|
||||
|
||||
$printer->writeln('');
|
||||
|
||||
$printer->writeln(
|
||||
sprintf('Proxy classes generated to "%s"',
|
||||
$printer->format(isset($arguments['to-dir']) ? $arguments['to-dir'] : $em->getConfiguration()->getProxyDir(), 'KEYWORD'))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\ORM\Tools\ClassMetadataReader;
|
||||
|
||||
/**
|
||||
* CLI Task to generate repository classes for some mapping information
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class GenerateRepositoriesTask extends ConvertMappingTask
|
||||
{
|
||||
private static $_template =
|
||||
'<?php
|
||||
|
||||
namespace <namespace>;
|
||||
|
||||
use \Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* <className>
|
||||
*
|
||||
* This class was generated by the Doctrine ORM. Add your own custom
|
||||
* repository methods below.
|
||||
*/
|
||||
class <className> extends EntityRepository
|
||||
{
|
||||
}';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$options = new OptionGroup(OptionGroup::CARDINALITY_N_N, array(
|
||||
new Option('from', '<FROM>', 'The path to mapping information.'),
|
||||
new Option('dest', '<DEST>', 'The path to generate your repository classes.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('generate-repositories')
|
||||
->setDescription('Generate repository classes for some mapping information.')
|
||||
->getOptionGroup()
|
||||
->addOption($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ( ! isset($arguments['from']) || ! isset($arguments['dest'])) {
|
||||
throw new CLIException('You must specify a value for --from and --dest');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$printer = $this->getPrinter();
|
||||
$arguments = $this->getArguments();
|
||||
$dest = realpath($arguments['dest']);
|
||||
|
||||
$reader = new ClassMetadataReader();
|
||||
$reader->setEntityManager($this->getConfiguration()->getAttribute('em'));
|
||||
$reader->addMappingSource($arguments['from']);
|
||||
$metadatas = $reader->getMetadatas();
|
||||
|
||||
foreach ($metadatas as $metadata) {
|
||||
if ($metadata->customRepositoryClassName) {
|
||||
$code = $this->_generateRepositoryClass($metadata->customRepositoryClassName);
|
||||
$path = $dest . '/' . str_replace('\\', '/', $metadata->customRepositoryClassName) . '.php';
|
||||
$dir = dirname($path);
|
||||
if ( ! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
$printer->writeln(
|
||||
sprintf('Processing entity "%s"',
|
||||
$printer->format($metadata->customRepositoryClassName, 'KEYWORD')
|
||||
)
|
||||
);
|
||||
file_put_contents($path, $code);
|
||||
}
|
||||
}
|
||||
$printer->writeln('');
|
||||
$printer->writeln(
|
||||
sprintf('Entity repository classes generated to "%s"',
|
||||
$printer->format($dest, 'KEYWORD')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function _generateRepositoryClass($fullyQualifiedClassName)
|
||||
{
|
||||
$namespace = substr($fullyQualifiedClassName, 0, strrpos($fullyQualifiedClassName, '\\'));
|
||||
|
||||
$pos = strrpos($fullyQualifiedClassName, '\\');
|
||||
$className = substr($fullyQualifiedClassName, $pos + 1, strlen($fullyQualifiedClassName));
|
||||
|
||||
$placeHolders = array(
|
||||
'<namespace>',
|
||||
'<className>'
|
||||
);
|
||||
$replacements = array(
|
||||
$namespace,
|
||||
$className
|
||||
);
|
||||
$code = str_replace($placeHolders, $replacements, self::$_template);
|
||||
return $code;
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\Common\Util\Debug,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\ORM\Query;
|
||||
|
||||
/**
|
||||
* Task for executing DQL in passed EntityManager.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class RunDqlTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$dql = new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option('dql', '<DQL>', 'The DQL to execute.')
|
||||
));
|
||||
|
||||
$hydrate = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option(
|
||||
'hydrate', '<HYDRATION_MODE>',
|
||||
'Hydration mode of result set.' . PHP_EOL .
|
||||
'Should be either: object, array, scalar or single-scalar.'
|
||||
)
|
||||
));
|
||||
|
||||
$firstResult = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option('first-result', '<INTEGER>', 'The first result in the result set.')
|
||||
));
|
||||
|
||||
$maxResults = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option('max-results', '<INTEGER>', 'The maximum number of results in the result set.')
|
||||
));
|
||||
|
||||
$depth = new OptionGroup(OptionGroup::CARDINALITY_0_1, array(
|
||||
new Option('depth', '<DEPTH>', 'Dumping depth of Entities graph.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('run-dql')
|
||||
->setDescription('Executes arbitrary DQL directly from the command line.')
|
||||
->getOptionGroup()
|
||||
->addOption($dql)
|
||||
->addOption($hydrate)
|
||||
->addOption($firstResult)
|
||||
->addOption($maxResults)
|
||||
->addOption($depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset($arguments['dql'])) {
|
||||
throw new CLIException('Argument --dql must be defined.');
|
||||
}
|
||||
|
||||
if (isset($arguments['hydrate'])) {
|
||||
$hydrationModeName = 'Doctrine\ORM\Query::HYDRATE_' . strtoupper(str_replace('-', '_', $arguments['hydrate']));
|
||||
|
||||
if ( ! defined($hydrationModeName)) {
|
||||
throw new CLIException("Argument --hydrate must be either 'object', 'array', 'scalar' or 'single-scalar'.");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arguments['first-result']) && ! ctype_digit($arguments['first-result'])) {
|
||||
throw new CLIException('Argument --first-result must be an integer value.');
|
||||
}
|
||||
|
||||
if (isset($arguments['max-results']) && ! ctype_digit($arguments['max-results'])) {
|
||||
throw new CLIException('Argument --max-results must be an integer value.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
$query = $em->createQuery($arguments['dql']);
|
||||
|
||||
$hydrationMode = isset($arguments['hydrate'])
|
||||
? constant('Doctrine\ORM\Query::HYDRATE_' . strtoupper(str_replace('-', '_', $arguments['hydrate'])))
|
||||
: Query::HYDRATE_OBJECT;
|
||||
|
||||
if (isset($arguments['first-result'])) {
|
||||
$query->setFirstResult($arguments['first-result']);
|
||||
}
|
||||
|
||||
if (isset($arguments['max-results'])) {
|
||||
$query->setMaxResults($arguments['max-results']);
|
||||
}
|
||||
|
||||
$resultSet = $query->getResult($hydrationMode);
|
||||
$maxDepth = isset($arguments['depth']) ? $arguments['depth'] : 7;
|
||||
|
||||
Debug::dump($resultSet, $maxDepth);
|
||||
}
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\CLI\CLIException,
|
||||
Doctrine\Common\CLI\Option,
|
||||
Doctrine\Common\CLI\OptionGroup,
|
||||
Doctrine\ORM\Tools\SchemaTool,
|
||||
Doctrine\Common\Annotations\AnnotationReader,
|
||||
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
|
||||
Doctrine\ORM\Mapping\Driver\XmlDriver,
|
||||
Doctrine\ORM\Mapping\Driver\YamlDriver;
|
||||
|
||||
/**
|
||||
* Task to create the database schema for a set of classes based on their mappings.
|
||||
*
|
||||
* This task has the following arguments:
|
||||
*
|
||||
* <tt>--class-dir=<path></tt>
|
||||
* Specifies the directory where to start looking for mapped classes.
|
||||
* This argument is required when the annotation metadata driver is used,
|
||||
* otherwise it has no effect.
|
||||
*
|
||||
* <tt>--dump-sql</tt>
|
||||
* Specifies that instead of directly executing the SQL statements,
|
||||
* they should be printed to the standard output.
|
||||
*
|
||||
* <tt>--create</tt>
|
||||
* Specifies that the schema of the classes should be created.
|
||||
*
|
||||
* <tt>--drop</tt>
|
||||
* Specifies that the schema of the classes should be dropped.
|
||||
*
|
||||
* <tt>--update</tt>
|
||||
* Specifies that the schema of the classes should be updated.
|
||||
*
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision: 3938 $
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class SchemaToolTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
$schemaOption = new OptionGroup(OptionGroup::CARDINALITY_1_1, array(
|
||||
new Option(
|
||||
'create', null,
|
||||
'Creates the schema in EntityManager (create tables on Database).' . PHP_EOL .
|
||||
'If defined, --drop, --update and --re-create can not be requested on same task.'
|
||||
),
|
||||
new Option(
|
||||
'drop', null,
|
||||
'Drops the schema of EntityManager (drop tables on Database).' . PHP_EOL .
|
||||
'Beware that the complete database is dropped by this command, '.PHP_EOL.
|
||||
'even tables that are not relevant to your metadata model.' . PHP_EOL .
|
||||
'If defined, --create, --update and --re-create can not be requested on same task.'
|
||||
),
|
||||
new Option(
|
||||
'update', null,
|
||||
'Updates the schema in EntityManager (update tables on Database).' . PHP_EOL .
|
||||
'This command does a save update, which does not delete any tables, sequences or affected foreign keys.' . PHP_EOL .
|
||||
'If defined, --create, --drop and --complete-update --re-create can not be requested on same task.'
|
||||
),
|
||||
new Option(
|
||||
'complete-update', null,
|
||||
'Updates the schema in EntityManager (update tables on Database).' . PHP_EOL .
|
||||
'Beware that all assets of the database which are not relevant to the current metadata are dropped by this command.'.PHP_EOL.
|
||||
'If defined, --create, --drop and --update --re-create can not be requested on same task.'
|
||||
),
|
||||
new Option(
|
||||
're-create', null,
|
||||
'Runs --drop then --create to re-create the database.' . PHP_EOL .
|
||||
'If defined, --create, --update and --drop can not be requested on same task.'
|
||||
)
|
||||
));
|
||||
|
||||
$optionalOptions = new OptionGroup(OptionGroup::CARDINALITY_0_N, array(
|
||||
new Option('dump-sql', null, 'Instead of try to apply generated SQLs into EntityManager, output them.'),
|
||||
new Option('class-dir', '<PATH>', 'Optional class directory to fetch for Entities.')
|
||||
));
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('schema-tool')
|
||||
->setDescription('Processes the schema and either apply it directly on EntityManager or generate the SQL output.')
|
||||
->getOptionGroup()
|
||||
->addOption($schemaOption)
|
||||
->addOption($optionalOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
if ($em === null) {
|
||||
throw new CLIException(
|
||||
"Attribute 'em' of CLI Configuration is not defined or it is not a valid EntityManager."
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($arguments['re-create'])) {
|
||||
$arguments['drop'] = true;
|
||||
$arguments['create'] = true;
|
||||
|
||||
unset($arguments['re-create']);
|
||||
|
||||
$this->setArguments($arguments);
|
||||
}
|
||||
|
||||
$isCreate = isset($arguments['create']) && $arguments['create'];
|
||||
$isDrop = isset($arguments['drop']) && $arguments['drop'];
|
||||
$isUpdate = isset($arguments['update']) && $arguments['update'];
|
||||
$isCompleteUpdate = isset($arguments['complete-update']) && $arguments['complete-update'];
|
||||
|
||||
if ($isUpdate && ($isCreate || $isDrop || $isCompleteUpdate)) {
|
||||
throw new CLIException(
|
||||
'You cannot use --update with --create, --drop or --complete-update.'
|
||||
);
|
||||
}
|
||||
|
||||
if ($isCompleteUpdate && ($isCreate || $isDrop || $isUpdate)) {
|
||||
throw new CLIException('You cannot use --complete-update with --create, --drop or --update.');
|
||||
}
|
||||
|
||||
if ( ! ($isCreate || $isDrop || $isUpdate || $isCompleteUpdate)) {
|
||||
throw new CLIException(
|
||||
'You must specify at a minimum one of the options: ' .
|
||||
'--create, --drop, --update, --re-create or --complete-update.'
|
||||
);
|
||||
}
|
||||
|
||||
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
|
||||
|
||||
if ($metadataDriver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) {
|
||||
if (isset($arguments['class-dir'])) {
|
||||
$metadataDriver->addPaths((array) $arguments['class-dir']);
|
||||
} else {
|
||||
throw new CLIException(
|
||||
'The supplied configuration uses the annotation metadata driver. ' .
|
||||
"The 'class-dir' argument is required for this driver."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$arguments = $this->getArguments();
|
||||
$printer = $this->getPrinter();
|
||||
|
||||
$isCreate = isset($arguments['create']) && $arguments['create'];
|
||||
$isDrop = isset($arguments['drop']) && $arguments['drop'];
|
||||
$isUpdate = isset($arguments['update']) && $arguments['update'];
|
||||
$isCompleteUpdate = isset($arguments['complete-update']) && $arguments['complete-update'];
|
||||
|
||||
$em = $this->getConfiguration()->getAttribute('em');
|
||||
|
||||
$cmf = $em->getMetadataFactory();
|
||||
$classes = $cmf->getAllMetadata();
|
||||
|
||||
if (empty($classes)) {
|
||||
$printer->writeln('No classes to process.', 'INFO');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$tool = new SchemaTool($em);
|
||||
|
||||
if ($isDrop) {
|
||||
if (isset($arguments['dump-sql'])) {
|
||||
foreach ($tool->getDropSchemaSql($classes) as $sql) {
|
||||
$printer->writeln($sql . ";");
|
||||
}
|
||||
} else {
|
||||
$printer->writeln('Dropping database schema...', 'INFO');
|
||||
$tool->dropSchema($classes);
|
||||
$printer->writeln('Database schema dropped successfully.', 'INFO');
|
||||
}
|
||||
}
|
||||
|
||||
if ($isCreate) {
|
||||
if (isset($arguments['dump-sql'])) {
|
||||
foreach ($tool->getCreateSchemaSql($classes) as $sql) {
|
||||
$printer->writeln($sql . ";");
|
||||
}
|
||||
} else {
|
||||
$printer->writeln('Creating database schema...', 'INFO');
|
||||
$tool->createSchema($classes);
|
||||
$printer->writeln('Database schema created successfully.', 'INFO');
|
||||
}
|
||||
}
|
||||
|
||||
if ($isUpdate || $isCompleteUpdate) {
|
||||
$saveMode = $isUpdate ? true : false;
|
||||
|
||||
if (isset($arguments['dump-sql'])) {
|
||||
foreach ($tool->getUpdateSchemaSql($classes, $saveMode) as $sql) {
|
||||
$printer->writeln($sql . ";");
|
||||
}
|
||||
} else {
|
||||
$printer->writeln('Updating database schema...', 'INFO');
|
||||
$tool->updateSchema($classes, $saveMode);
|
||||
$printer->writeln('Database schema updated successfully.', 'INFO');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This software consists of voluntary contributions made by many individuals
|
||||
* and is licensed under the LGPL. For more information, see
|
||||
* <http://www.doctrine-project.org>.
|
||||
*/
|
||||
|
||||
namespace Doctrine\ORM\Tools\CLI\Tasks;
|
||||
|
||||
use Doctrine\Common\CLI\Tasks\AbstractTask,
|
||||
Doctrine\Common\Version;
|
||||
|
||||
/**
|
||||
* CLI Task to display the doctrine version
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Roman Borschel <roman@code-factory.org>
|
||||
*/
|
||||
class VersionTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildDocumentation()
|
||||
{
|
||||
// There're no options on this task
|
||||
$this->getDocumentation()->getOptionGroup()->clear();
|
||||
|
||||
$doc = $this->getDocumentation();
|
||||
$doc->setName('version')
|
||||
->setDescription('Displays the current installed Doctrine version.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the current version of Doctrine
|
||||
*
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->getPrinter()->writeln('You are currently running Doctrine ' . Version::VERSION, 'INFO');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue