public function testArrayRemoveAssocRecursive() { $allUsers = ['users' => [1 => ['name' => 'Charles', 'role' => 'lead developper'], 2 => ['name' => 'Eric', 'role' => 'developper'], 3 => ['name' => 'Nicolas', 'role' => 'developper']]]; $nicolas = ['users' => [3 => ['name' => 'Nicolas', 'role' => 'developper']]]; $unknown = ['users' => [4 => ['name' => 'Unknown', 'role' => 'tester']]]; $expectedResult = ['users' => [1 => ['name' => 'Charles', 'role' => 'lead developper'], 2 => ['name' => 'Eric', 'role' => 'developper']]]; Collection::array_remove_assoc_recursive($allUsers, $nicolas); $this->assertSame($allUsers, $expectedResult); Collection::array_remove_assoc_recursive($expectedResult, $unknown); $this->assertSame($expectedResult, ['users' => [1 => ['name' => 'Charles', 'role' => 'lead developper'], 2 => ['name' => 'Eric', 'role' => 'developper']]]); }
/** * Adds userdefined functions. * * @param Configuration $config * @param array $options * @return Configuration */ private static function addCustomFunctions(Configuration $config, array $options = array()) { if (null !== ($strFcts = Collection::get($options, 'orm:entity_managers:default:dql:string_functions'))) { foreach ($strFcts as $name => $class) { if (class_exists($class)) { $config->addCustomStringFunction($name, $class); } } } if (null !== ($numFcts = Collection::get($options, 'orm:entity_managers:default:dql:numeric_functions'))) { foreach ($numFcts as $name => $class) { if (class_exists($class)) { $config->addCustomNumericFunction($name, $class); } } } if (null !== ($datetimeFcts = Collection::get($options, 'orm:entity_managers:default:dql:datetime_functions'))) { foreach ($datetimeFcts as $name => $class) { if (class_exists($class)) { $config->addCustomDatetimeFunction($name, $class); } } } return $config; }
/** * Returns an array of uid of the children of $nodeUid. * * @param string $nodeUid The node uid to look for children. * * @return string[] */ public function getNativelyNodeChildren($nodeUid) { $query = $this->createQueryBuilder('s')->select('s._uid', 's._leftnode')->where('s._parent = :node')->addOrderBy('s._leftnode', 'asc')->addOrderBy('s._modified', 'desc')->getQuery()->getSQL(); $result = $this->getEntityManager()->getConnection()->executeQuery((string) $query, [$nodeUid], [\Doctrine\DBAL\Types\Type::STRING])->fetchAll(); return Collection::array_column($result, 'uid0'); }
/** * Add or update 'override_site' section to provided $config with difference between current config settings * and config default settings. * * @param Config $config the config we want to add/update its 'override_site' section */ private function updateConfigOverridedSectionsForSite(Config $config) { if (false === $this->application->isStarted()) { throw new BBException('Application is not started, we are not able to persist multiple site config.'); } $default_sections = $this->configurator->getConfigDefaultSections($config); $current_sections = $config->getAllRawSections(); $sections_to_update = array_keys(Collection::array_diff_assoc_recursive($default_sections, $current_sections)); $sections_to_update = array_unique(array_merge($sections_to_update, array_keys(Collection::array_diff_assoc_recursive($current_sections, $default_sections)))); $override_site = $config->getRawSection('override_site') ?: array(); $site_uid = $this->application->getSite()->getUid(); if (false === array_key_exists($site_uid, $override_site)) { $override_site[$site_uid] = array(); } $override_sections_site =& $override_site[$site_uid]; foreach ($sections_to_update as $section) { if ('override_site' !== $section) { $override_sections_site[$section] = $config->getRawSection($section); } } $config->deleteAllSections(); foreach ($this->configurator->getConfigDefaultSections($config) as $section_name => $section_settings) { $config->setSection($section_name, $section_settings); } $config->setSection('override_site', $override_site, true); }
/** * Sets a parameter section. * * @param string $section * @param array $config * @param boolean $overwrite * * @return \BackBee\Config\Config The current config object */ public function setSection($section, array $config, $overwrite = false) { if (false === $overwrite && array_key_exists($section, $this->raw_parameters)) { $this->raw_parameters[$section] = Collection::array_merge_assoc_recursive($this->raw_parameters[$section], $config); } else { $this->raw_parameters[$section] = $config; } if (array_key_exists($section, $this->parameters)) { unset($this->parameters[$section]); } return $this; }
/** * Returns an array of uid of the children of $nodeUid * * @param string $nodeUid The node uid to look for children * @param string $classname * @param int $start * @param int $limit * * @return array */ private function getNodeChildren($nodeUid, $classname, $start = 0, $limit = 1000) { $query = sprintf('SELECT %s FROM %s WHERE %s = ? ORDER BY %s ASC, %s DESC LIMIT %d, %d', $this->requiredFields['uid'], $this->em->getClassMetadata($classname)->getTableName(), $this->requiredFields['parent_uid'], $this->requiredFields['leftnode'], $this->requiredFields['modified'], $start, $limit); $result = $this->em->getConnection()->executeQuery($query, array($nodeUid), array(Type::STRING))->fetchAll(); return Collection::array_column($result, $this->requiredFields['uid']); }