/** * */ public function testLeaves() { $node = new Param\Node(['aa' => 11, 'bb' => 22, 'ss' => ['xx' => 77, 'yy' => 88], 'cc' => 33]); $leaves = Param\Util::leaves($node); $expected = array('aa' => 11, 'bb' => 22, 'ss.xx' => 77, 'ss.yy' => 88, 'cc' => 33); $this->assertEquals($leaves, $expected); }
/** * @param array $config * @param SplFileInfo $referer */ protected function processImport(&$config, SplFileInfo $referer, $deep = false) { $key = $this->getImportKey(); if (isset($config[$key])) { $import = (array) $config[$key]; foreach ($import as $name => $file) { $status = -1; $path = new SplFileInfo($this->resolveRef($file, $referer->getPath())); $data = $this->loadConfig($path, $deep, $status); if ($status == 0) { Util::mixin($config, [$name => $data]); } } unset($config[$key]); } if ($deep && is_array($config)) { foreach ($config as &$sub) { $this->processImport($sub, $referer, $deep); } } return $this; }
/** * @param Resources $context * @return boolean */ public static function autostart(Resources $context) { $config = $context->get('config'); // [php] $ini = $config->node('php'); foreach (Param\Util::leaves($ini) as $key => $value) { if (!is_scalar($value) && !is_null($value)) { $type = is_object($value) ? get_class($value) : gettype($value); throw new Exception\RuntimeException("INI parameter '{$key}' is of wrong type ({$type})"); } ini_set($key, $value); } // [locale] $info = array(); $locale = $config->node('locale'); foreach ($locale as $category => $spec) { $info[$category] = setlocale($category, $spec->getData()); } $context->setResource('locale', $info); return true; }
/** * @param array|Base $data * @return static */ public function inject($data, &$status = null) { // prepare: if (is_scalar($this->data) || is_null($this->data)) { $this->data = (array) $this->data; } if ($data instanceof Base) { $data = (array) $data->getData(); } // inject: if (is_array($this->data)) { Util::mixin($this->data, $data); $status = true; } else { $status = false; } return $this; }