Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benakamoorthi@fastmail.fm>2014-03-31 00:29:30 +0400
committerdiosmosis <benakamoorthi@fastmail.fm>2014-03-31 00:30:07 +0400
commit1d3e3890c38793f7891fede1e570af4ee266ab49 (patch)
tree8b79b434ed451981e2d0f1ce235fdb95899a6579 /core/Console.php
parent8caf2dfadb648ece2c47c4a5ffe810f8687313a6 (diff)
Refactor console application entrypoint so is not read from directly.
Diffstat (limited to 'core/Console.php')
-rw-r--r--core/Console.php58
1 files changed, 31 insertions, 27 deletions
diff --git a/core/Console.php b/core/Console.php
index 3db5a83da7..28d6e4d6b6 100644
--- a/core/Console.php
+++ b/core/Console.php
@@ -11,23 +11,14 @@ namespace Piwik;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
-class Console
+class Console extends Application
{
- public function init()
- {
- $this->initPiwikHost();
- $this->initConfig();
- try {
- self::initPlugins();
- } catch(\Exception $e) {
- // Piwik not installed yet, no config file?
- }
- }
-
- public function run()
+ public function __construct()
{
- $console = new Application();
+ parent::__construct();
$option = new InputOption('piwik-domain',
null,
@@ -35,27 +26,40 @@ class Console
'Piwik URL (protocol and domain) eg. "http://piwik.example.org"'
);
- $console->getDefinition()->addOption($option);
+ $this->getDefinition()->addOption($option);
+ }
+
+ /**
+ * @deprecated
+ */
+ public function init()
+ {
+ // TODO: remove
+ }
+
+ public function doRun(InputInterface $input, OutputInterface $output)
+ {
+ $this->initPiwikHost($input);
+ $this->initConfig();
+ try {
+ self::initPlugins();
+ } catch(\Exception $e) {
+ // Piwik not installed yet, no config file?
+ }
$commands = $this->getAvailableCommands();
foreach ($commands as $command) {
-
if (!class_exists($command)) {
-
Log::warning(sprintf('Cannot add command %s, class does not exist', $command));
-
} elseif (!is_subclass_of($command, 'Piwik\Plugin\ConsoleCommand')) {
-
Log::warning(sprintf('Cannot add command %s, class does not extend Piwik\Plugin\ConsoleCommand', $command));
-
} else {
-
- $console->add(new $command);
+ $this->add(new $command);
}
}
- $console->run();
+ return parent::doRun($input, $output);
}
/**
@@ -65,7 +69,7 @@ class Console
*/
private function getAvailableCommands()
{
- $commands = $this->getDefaultCommands();
+ $commands = $this->getDefaultPiwikCommands();
/**
* Triggered to gather all available console commands. Plugins that want to expose new console commands
@@ -85,9 +89,9 @@ class Console
return $commands;
}
- protected function initPiwikHost()
+ protected function initPiwikHost(InputInterface $input)
{
- $piwikHostname = CronArchive::getParameterFromCli('piwik-domain', true);
+ $piwikHostname = $input->getParameterOption('--piwik-domain');
$piwikHostname = UrlHelper::getHostFromUrl($piwikHostname);
Url::setHost($piwikHostname);
}
@@ -110,7 +114,7 @@ class Console
$pluginsManager->loadPlugins($pluginsToLoad);
}
- private function getDefaultCommands()
+ private function getDefaultPiwikCommands()
{
$commands = array(
'Piwik\CliMulti\RequestCommand'