Inheritance: extends Symfony\Component\Console\Application
Esempio n. 1
0
 /**
  * Get an instance of the Magerun app.
  *
  * @return \N98\Magento\Application
  */
 public function getMagerun()
 {
     if (!$this->magerun) {
         $this->magerun = new MagerunApplication($this->getApplication()->getAutoloader());
         $this->magerun->init();
     }
     return $this->magerun;
 }
Esempio n. 2
0
 /**
  * @return PHPUnit_Framework_MockObject_MockObject|Application
  */
 public function getApplication()
 {
     if ($this->application === null) {
         $root = $this->getTestMagentoRoot();
         $this->application = $this->getMock('N98\\Magento\\Application', array('getMagentoRootFolder'));
         $loader = (require __DIR__ . '/../../../../../vendor/autoload.php');
         $this->application->setAutoloader($loader);
         $this->application->expects($this->any())->method('getMagentoRootFolder')->will($this->returnValue($root));
         $this->application->init();
         $this->application->initMagento();
         if ($this->application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) {
             spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
         }
     }
     return $this->application;
 }
Esempio n. 3
0
 /**
  * @throws \RuntimeException
  * @return PHPUnit_Framework_MockObject_MockObject|\N98\Magento\Application
  */
 public function getApplication()
 {
     if ($this->application === null) {
         $root = getenv('N98_MAGERUN_TEST_MAGENTO_ROOT');
         if (empty($root)) {
             throw new \RuntimeException('Please specify environment variable N98_MAGERUN_TEST_MAGENTO_ROOT with path to your test
                 magento installation!');
         }
         $this->application = $this->getMock('N98\\Magento\\Application', array('getMagentoRootFolder'));
         $loader = (require __DIR__ . '/../../../../../vendor/autoload.php');
         $this->application->setAutoloader($loader);
         $this->application->expects($this->any())->method('getMagentoRootFolder')->will($this->returnValue($root));
         $this->application->init();
         $this->application->initMagento();
         if ($this->application->getMagentoMajorVersion() == Application::MAGENTO_MAJOR_VERSION_1) {
             spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
         }
     }
     return $this->application;
 }
 /**
  * Store the current database credentials to the default database
  * connection of the supplied application in the corresponding local.xml.
  *
  * @param Application $app
  * @return void
  * @throws \RuntimeException when the local.xml file does not exist or is
  *   not writable.
  */
 public function saveToApplication(Application $app)
 {
     $root = $app->getMagentoRootFolder();
     $localXmlPath = realpath("{$root}/app/etc/local.xml");
     if (!file_exists($localXmlPath) || !is_writable($localXmlPath)) {
         throw new \RuntimeException('File does not exist or could not be written to: ' . var_export($localXmlPath, true));
     }
     // Load the XML and travel down the xpath until we find our connection.
     $localXml = simplexml_load_file($localXmlPath);
     // Update the connection settings.
     $localXml->global->resources->default_setup->connection->host = $this->getHost();
     $localXml->global->resources->default_setup->connection->port = $this->getPort();
     $localXml->global->resources->default_setup->connection->username = $this->getUser();
     $localXml->global->resources->default_setup->connection->password = $this->getPassword();
     $localXml->global->resources->default_setup->connection->dbname = $this->getDatabase();
     // And persist the changes.
     $localXml->asXML($localXmlPath);
 }
Esempio n. 5
0
 /**
  * @param Application $application
  */
 public function registerCustomCommands(Application $application)
 {
     if (isset($this->config['commands']['customCommands']) && is_array($this->config['commands']['customCommands'])) {
         foreach ($this->config['commands']['customCommands'] as $commandClass) {
             if (is_array($commandClass)) {
                 // Support for key => value (name -> class)
                 $resolvedCommandClass = current($commandClass);
                 /** @var Command $command */
                 $command = new $resolvedCommandClass();
                 $command->setName(key($commandClass));
             } else {
                 /** @var Command $command */
                 $command = new $commandClass();
             }
             $application->add($command);
             $output = $this->output;
             if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
                 $output->writeln('<debug>Added command </debug><comment>' . get_class($command) . '</comment>');
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * @param Application $application
  */
 public function registerCustomCommands(Application $application)
 {
     foreach ($this->getArray(array('commands', 'customCommands')) as $commandClass) {
         $commandName = null;
         if (is_array($commandClass)) {
             // Support for key => value (name -> class)
             $commandName = key($commandClass);
             $commandClass = current($commandClass);
         }
         if (null === ($command = $this->newCommand($commandClass, $commandName))) {
             $this->output->writeln(sprintf('<error>Can not add nonexistent command class "%s" as command to the application</error>', $commandClass, $commandName));
             $this->debugWriteln('Please check the configuration files contain the correct class-name. If the ' . 'class-name is correct, check autoloader configurations.');
         } else {
             $this->debugWriteln(sprintf('<debug>Add command </debug> <info>%s</info> -> <comment>%s</comment>', $command->getName(), get_class($command)));
             $application->add($command);
         }
     }
 }
Esempio n. 7
0
 /**
  * @param Application $application
  */
 public function registerCustomCommands(Application $application)
 {
     foreach ($this->getArray(array('commands', 'customCommands')) as $commandClass) {
         $commandName = null;
         if (is_array($commandClass)) {
             // Support for key => value (name -> class)
             $commandName = key($commandClass);
             $commandClass = current($commandClass);
         }
         $command = $this->newCommand($commandClass, $commandName);
         $this->debugWriteln(sprintf('<debug>Add command </debug> <info>%s</info> -> <comment>%s</comment>', $command->getName(), get_class($command)));
         $application->add($command);
     }
 }