/** * */ public function testMixin() { $expected = '{"section":{"a":"A","b":"BBB","c":["C1","C2"],"d":"DDD"},"items":[{"i":"I"},{"j":"J"},{"k":"K"}],"extra":{"x":"XXX"}}'; $data = ['section' => ['a' => "A", 'b' => "B", 'c' => ["C1"]], 'items' => [['i' => 'I'], ['j' => 'J']]]; $ext = ['section' => ['b' => "BBB", 'd' => "DDD", 'c' => ["C2"]], 'extra' => ['x' => "XXX"], 'items' => [['k' => 'K']]]; Param\Util::mixin($data, $ext); $this->assertEquals($data, json_decode($expected, true)); }
/** * @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 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; }