mergeArrays() public static method

If an integer key exists in both arrays, the value from the second array will be appended the the first array. If both values are arrays, they are merged together, else the value of the second array overwrites the one of the first array.
See also: http://packages.zendframework.com/docs/latest/manual/en/index.html#zend-stdlib
public static mergeArrays ( array $a, array $b ) : array
$a array
$b array
return array
コード例 #1
0
 public function testExecute()
 {
     /**
      * Check autoloading
      */
     /* @var $application Application */
     $application = (require __DIR__ . '/../../../src/bootstrap.php');
     $application->setMagentoRootFolder($this->getTestMagentoRoot());
     $this->assertInstanceOf('\\N98\\Magento\\Application', $application);
     $loader = $application->getAutoloader();
     $this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader);
     /**
      * Check version
      */
     $this->assertEquals(Application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt')));
     /* @var $loader \Composer\Autoload\ClassLoader */
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98', $prefixes);
     $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml'));
     $configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('ssl' => 'sys:store:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel')));
     $application->setAutoExit(false);
     $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray));
     $application->run(new StringInput('list'), new NullOutput());
     // Check if autoloaders, commands and aliases are registered
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98MagerunTest', $prefixes);
     $testDummyCommand = $application->find('n98mageruntest:test:dummy');
     $this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand);
     $commandTester = new CommandTester($testDummyCommand);
     $commandTester->execute(array('command' => $testDummyCommand->getName()));
     $this->assertContains('dummy', $commandTester->getDisplay());
     $this->assertTrue($application->getDefinition()->hasOption('root-dir'));
     // check alias
     $this->assertInstanceOf('\\N98\\Magento\\Command\\System\\Store\\ListCommand', $application->find('ssl'));
 }
コード例 #2
0
 public function testExecute()
 {
     /**
      * Check autoloading
      */
     /* @var $application Application */
     $application = (require __DIR__ . '/../../../src/bootstrap.php');
     $magentoRootFolder = getenv('N98_MAGERUN_TEST_MAGENTO_ROOT');
     if (empty($magentoRootFolder)) {
         $this->markTestSkipped('Please specify environment variable N98_MAGERUN_TEST_MAGENTO_ROOT with path to your test ' . 'magento installation!');
     }
     $application->setMagentoRootFolder($magentoRootFolder);
     $this->assertInstanceOf('\\N98\\Magento\\Application', $application);
     $loader = $application->getAutoloader();
     $this->assertInstanceOf('\\Composer\\Autoload\\ClassLoader', $loader);
     /**
      * Check version
      */
     $this->assertEquals($application::APP_VERSION, trim(file_get_contents(__DIR__ . '/../../../version.txt')));
     /* @var $loader \Composer\Autoload\ClassLoader */
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98', $prefixes);
     $distConfigArray = Yaml::parse(file_get_contents(__DIR__ . '/../../../config.yaml'));
     $configArray = array('autoloaders' => array('N98MagerunTest' => __DIR__ . '/_ApplicationTestSrc'), 'commands' => array('customCommands' => array(0 => 'N98MagerunTest\\TestDummyCommand'), 'aliases' => array(array('cl' => 'cache:list'))), 'init' => array('options' => array('config_model' => 'N98MagerunTest\\AlternativeConfigModel')));
     $application->setAutoExit(false);
     $application->init(ArrayFunctions::mergeArrays($distConfigArray, $configArray));
     $application->run(new StringInput('list'), new NullOutput());
     // Check if autoloaders, commands and aliases are registered
     $prefixes = $loader->getPrefixes();
     $this->assertArrayHasKey('N98MagerunTest', $prefixes);
     $testDummyCommand = $application->find('n98mageruntest:test:dummy');
     $this->assertInstanceOf('\\N98MagerunTest\\TestDummyCommand', $testDummyCommand);
     $commandTester = new CommandTester($testDummyCommand);
     $commandTester->execute(array('command' => $testDummyCommand->getName()));
     $this->assertContains('dummy', $commandTester->getDisplay());
     $this->assertTrue($application->getDefinition()->hasOption('root-dir'));
     // Test alternative config model
     $application->initMagento();
     if (version_compare(\Mage::getVersion(), '1.7.0.2', '>=')) {
         // config_model option is only available in Magento CE >1.6
         $this->assertInstanceOf('\\N98MagerunTest\\AlternativeConfigModel', \Mage::getConfig());
     }
     // check alias
     $this->assertInstanceOf('\\N98\\Magento\\Command\\Cache\\ListCommand', $application->find('cl'));
 }
コード例 #3
0
 /**
  * MAGENTO_ROOT/app/etc/n98-magerun.yaml
  *
  * @param string $magentoRootFolder
  * @param string $magerunStopFileFolder
  * @param array $config
  *
  * @return array
  */
 public function loadProjectConfig($magentoRootFolder, $magerunStopFileFolder, array $config)
 {
     if (null !== $this->_projectConfig) {
         return ArrayFunctions::mergeArrays($config, $this->_projectConfig);
     }
     $this->_projectConfig = array();
     $locator = new ConfigLocator($this->_customConfigFilename, $magentoRootFolder);
     if ($projectConfigFile = $locator->getProjectConfigFile()) {
         $this->_projectConfig = $projectConfigFile->toArray();
     }
     if ($stopFileConfigFile = $locator->getStopFileConfigFile($magerunStopFileFolder)) {
         $this->_projectConfig = $stopFileConfigFile->mergeArray($this->_projectConfig);
     }
     return ArrayFunctions::mergeArrays($config, $this->_projectConfig);
 }
コード例 #4
0
ファイル: Application.php プロジェクト: jsiefer/n98-magerun2
 /**
  * @param array $initConfig
  * @param OutputInterface $output
  * @return ConfigurationLoader
  */
 public function getConfigurationLoader($initConfig = array(), OutputInterface $output)
 {
     if ($this->configurationLoader === null) {
         $this->configurationLoader = new ConfigurationLoader(ArrayFunctions::mergeArrays($this->config, $initConfig), $this->isPharMode(), $output);
     }
     return $this->configurationLoader;
 }
コード例 #5
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (String::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
コード例 #6
0
ファイル: ConfigFile.php プロジェクト: netz98/n98-magerun
 public function mergeArray(array $array)
 {
     $result = $this->toArray();
     return ArrayFunctions::mergeArrays($array, $result);
 }
コード例 #7
0
 /**
  * Loads a plugin config file and merges it to plugin config
  *
  * @param string       $magentoRootFolder
  * @param SplFileInfo $file
  */
 protected function registerPluginConfigFile($magentoRootFolder, $file)
 {
     if (BinaryString::startsWith($file->getPathname(), 'vfs://')) {
         $path = $file->getPathname();
     } else {
         $path = $file->getRealPath();
         if ($path === "") {
             throw new \UnexpectedValueException(sprintf("Realpath for '%s' did return an empty string.", $file));
         }
         if ($path === false) {
             $this->_output->writeln(sprintf("<error>Plugin config file broken link '%s'</error>", $file));
             return;
         }
     }
     if (OutputInterface::VERBOSITY_DEBUG <= $this->_output->getVerbosity()) {
         $this->_output->writeln('<debug>Load plugin config <comment>' . $path . '</comment></debug>');
     }
     $localPluginConfig = \file_get_contents($path);
     $localPluginConfig = Yaml::parse($this->applyVariables($localPluginConfig, $magentoRootFolder, $file));
     $this->_pluginConfig = ArrayFunctions::mergeArrays($this->_pluginConfig, $localPluginConfig);
 }
コード例 #8
0
ファイル: Config.php プロジェクト: CopeX/n98-magerun2
 /**
  * @param array $initConfig
  * @param bool $isPharMode
  * @param OutputInterface $output
  *
  * @return ConfigurationLoader
  */
 public function createLoader(array $initConfig, $isPharMode, OutputInterface $output)
 {
     $config = ArrayFunctions::mergeArrays($this->config, $initConfig);
     $loader = new ConfigurationLoader($config, $isPharMode, $output);
     return $loader;
 }