2009-08-24 00:27:02 +04:00
|
|
|
<?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>.
|
|
|
|
*/
|
|
|
|
|
2009-12-21 20:38:14 +03:00
|
|
|
namespace Doctrine\Common\Cli\Tasks;
|
2009-08-31 20:21:29 +04:00
|
|
|
|
2009-12-21 20:38:14 +03:00
|
|
|
use Doctrine\Common\Cli\AbstractNamespace,
|
|
|
|
Doctrine\Common\Cli\TaskDocumentation;
|
2009-08-24 00:27:02 +04:00
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-08-31 20:21:29 +04:00
|
|
|
* Base class for CLI Tasks.
|
2009-08-25 08:46:46 +04:00
|
|
|
* Provides basic methods and requires implementation of methods that
|
|
|
|
* each task should implement in order to correctly work.
|
2009-08-31 20:21:29 +04:00
|
|
|
*
|
2009-08-25 08:46:46 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision$
|
2009-12-21 20:38:14 +03:00
|
|
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
2009-08-25 08:46:46 +04:00
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
*/
|
2009-08-24 00:27:02 +04:00
|
|
|
abstract class AbstractTask
|
|
|
|
{
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* @var AbstractNamespace CLI Namespace
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-08-24 00:27:02 +04:00
|
|
|
protected $_printer;
|
2009-12-21 20:38:14 +03:00
|
|
|
|
2009-11-17 04:29:20 +03:00
|
|
|
/**
|
|
|
|
* @var TaskDocumentation CLI Task Documentation
|
|
|
|
*/
|
|
|
|
protected $_documentation;
|
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* @var array CLI Task arguments
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
protected $_arguments = array();
|
2009-08-31 20:21:29 +04:00
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-11-17 04:29:20 +03:00
|
|
|
* Constructor of CLI Task
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @param AbstractNamespace CLI Namespace
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function __construct(AbstractNamespace $namespace)
|
2009-08-24 00:27:02 +04:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
$this->_namespace = $namespace;
|
|
|
|
$this->_documentation = new TaskDocumentation($namespace);
|
2009-11-17 04:29:20 +03:00
|
|
|
|
|
|
|
// Complete the CLI Task Documentation creation
|
|
|
|
$this->buildDocumentation();
|
2009-08-24 00:27:02 +04:00
|
|
|
}
|
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Retrieves the CLI Namespace
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @return AbstractNamespace
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function getNamespace()
|
2009-08-24 00:27:02 +04:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
return $this->_namespace;
|
2009-08-24 00:27:02 +04:00
|
|
|
}
|
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Retrieves the CLI Task Documentation
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @return TaskDocumentation
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function getDocumentation()
|
2009-08-24 00:27:02 +04:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
return $this->_documentation;
|
2009-08-24 00:27:02 +04:00
|
|
|
}
|
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Defines the CLI Task arguments
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @param array $arguments CLI Task arguments
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @return AbstractTask
|
2009-08-25 08:46:46 +04:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function setArguments(array $arguments = array())
|
2009-08-25 08:46:46 +04:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
$this->_arguments = $arguments;
|
|
|
|
|
|
|
|
return $this;
|
2009-08-25 08:46:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Retrieves the CLI Task arguments
|
2009-08-25 08:46:46 +04:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function getArguments()
|
2009-10-30 03:15:53 +03:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
return $this->_arguments;
|
2009-10-30 03:15:53 +03:00
|
|
|
}
|
2009-12-21 20:38:14 +03:00
|
|
|
|
2009-10-30 03:15:53 +03:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Retrieves currently used CLI Output Printer
|
2009-10-30 03:15:53 +03:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @return AbstractPrinter
|
2009-10-30 03:15:53 +03:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function getPrinter()
|
2009-10-30 03:15:53 +03:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
return $this->_namespace->getPrinter();
|
2009-10-30 03:15:53 +03:00
|
|
|
}
|
2009-12-21 20:38:14 +03:00
|
|
|
|
2009-11-17 04:29:20 +03:00
|
|
|
/**
|
2009-12-21 20:38:14 +03:00
|
|
|
* Retrieves current used CLI Configuration
|
2009-11-17 04:29:20 +03:00
|
|
|
*
|
2009-12-21 20:38:14 +03:00
|
|
|
* @return Configuration
|
2009-11-17 04:29:20 +03:00
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function getConfiguration()
|
2009-11-17 04:29:20 +03:00
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
return $this->_namespace->getConfiguration();
|
2009-11-17 04:29:20 +03:00
|
|
|
}
|
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2009-11-17 04:29:20 +03:00
|
|
|
public function extendedHelp()
|
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
$this->getPrinter()->output($this->_documentation->getCompleteDocumentation());
|
2009-11-17 04:29:20 +03:00
|
|
|
}
|
2009-08-24 00:27:02 +04:00
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2009-11-17 04:29:20 +03:00
|
|
|
public function basicHelp()
|
|
|
|
{
|
2009-12-21 20:38:14 +03:00
|
|
|
$this->getPrinter()
|
2009-11-17 04:29:20 +03:00
|
|
|
->output($this->_documentation->getSynopsis())
|
|
|
|
->output(PHP_EOL)
|
|
|
|
->output(' ' . $this->_documentation->getDescription())
|
|
|
|
->output(PHP_EOL . PHP_EOL);
|
|
|
|
}
|
2009-08-24 00:27:02 +04:00
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2009-12-21 20:38:14 +03:00
|
|
|
public function validate()
|
|
|
|
{
|
|
|
|
// TODO implement DAG here!
|
|
|
|
return true;
|
|
|
|
}
|
2009-08-24 00:27:02 +04:00
|
|
|
|
2009-08-25 08:46:46 +04:00
|
|
|
/**
|
|
|
|
* Safely execution of task.
|
|
|
|
* Each CLI task should implement this as normal flow execution of
|
|
|
|
* what is supposed to do.
|
|
|
|
*/
|
2009-08-24 00:27:02 +04:00
|
|
|
abstract public function run();
|
2009-11-17 04:29:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the CLI Task Documentation
|
|
|
|
*/
|
|
|
|
abstract public function buildDocumentation();
|
2009-12-21 20:38:14 +03:00
|
|
|
}
|