/** * Returns the configuration dependent on given items. * * @param array $item_names * An array of item names. * * @return array * An array of config items. */ protected function getConfigDependents(array $item_names = NULL) { $result = []; $config_collection = $this->featuresManager->getConfigCollection(); $packages = $this->featuresManager->getPackages(); $settings = $this->featuresManager->getSettings(); $allow_conflicts = $settings->get('conflicts'); if (empty($item_names)) { $item_names = array_keys($config_collection); } foreach ($item_names as $item_name) { if ($config_collection[$item_name]->getPackage()) { foreach ($config_collection[$item_name]->getDependents() as $dependent_item_name) { if (isset($config_collection[$dependent_item_name])) { $allow = TRUE; if (!$allow_conflicts && $config_collection[$dependent_item_name]->getPackage()) { if ($packages[$config_collection[$dependent_item_name]->getPackage()]) { $allow = $packages[$config_collection[$dependent_item_name]->getPackage()]->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT || $config_collection[$item_name]->getPackage() == $config_collection[$dependent_item_name]->getPackage(); } } if ($allow) { $result[] = $dependent_item_name; } } } } } return $result; }
/** * @covers ::reset */ public function testReset() { $packages = ['package' => ['machine_name' => 'package', 'config' => ['example.config', 'example.config3'], 'dependencies' => [], 'bundle' => 'giraffe'], 'package2' => ['machine_name' => 'package2', 'config' => ['example.config2'], 'dependencies' => [], 'bundle' => 'giraffe']]; $this->featuresManager->setPackages($packages); $config_item = new ConfigurationItem('example', [], ['package' => 'package']); $config_item2 = new ConfigurationItem('example2', [], ['package' => 'package2']); $this->featuresManager->setConfigCollection([$config_item, $config_item2]); $this->featuresManager->reset(); $this->assertEmpty($this->featuresManager->getPackages()); $config_collection = $this->featuresManager->getConfigCollection(); $this->assertEquals('', $config_collection[0]->getPackage()); $this->assertEquals('', $config_collection[1]->getPackage()); }
/** * Assigns a given subdirectory to configuration of specified types. * * @param string $subdirectory * The subdirectory that designated configuration should be exported to. */ protected function assignSubdirectoryByConfigTypes($subdirectory) { $current_bundle = $this->assigner->getBundle(); $settings = $current_bundle->getAssignmentSettings($this->getPluginId()); $types = $settings['types']['config']; $config_collection = $this->featuresManager->getConfigCollection(); foreach ($config_collection as &$item) { if (in_array($item->getType(), $types)) { $item->setSubdirectory($subdirectory); } } // Clean up the $item pass by reference. unset($item); $this->featuresManager->setConfigCollection($config_collection); }
/** * Returns the configuration dependent on given items. * * @param array $item_names * An array of item names. * @param string $package_name * Short machine name of feature to process. * * @return array * An array of config items. */ protected function getConfigDependents(array $item_names, $package_name) { $result = []; $config_collection = $this->featuresManager->getConfigCollection(); $packages = $this->featuresManager->getPackages(); $settings = $this->featuresManager->getSettings(); $allow_conflicts = $settings->get('conflicts'); if (empty($item_names)) { $item_names = array_keys($config_collection); } // Add any existing auto-detected items already in the package config $this->package = $packages[$package_name]; $package_config = isset($this->package) ? $this->package->getConfig() : array(); $package_config = !empty($package_config) ? array_unique(array_merge($package_config, $item_names)) : $item_names; foreach ($package_config as $config_name) { if (!$config_collection[$config_name]->getPackageExcluded()) { $result[] = $config_name; } } // Now add dependents of the items selected foreach ($item_names as $item_name) { if ($config_collection[$item_name]->getPackage()) { foreach ($config_collection[$item_name]->getDependents() as $dependent_item_name) { if (isset($config_collection[$dependent_item_name])) { $allow = TRUE; if (!$allow_conflicts && $config_collection[$dependent_item_name]->getPackage()) { if ($packages[$config_collection[$dependent_item_name]->getPackage()]) { $allow = $packages[$config_collection[$dependent_item_name]->getPackage()]->getStatus() == FeaturesManagerInterface::STATUS_NO_EXPORT || $config_collection[$item_name]->getPackage() == $config_collection[$dependent_item_name]->getPackage(); } } if ($allow) { $result[] = $dependent_item_name; } } } } } return $result; }
/** * @covers ::setConfigCollection * @covers ::getConfigCollection */ public function testConfigCollection() { $config = ['config' => 'collection']; $this->featuresManager->setConfigCollection($config); $this->assertArrayEquals($config, $this->featuresManager->getConfigCollection()); }