/** * Import XML data * * @param string $string * @return array */ protected function _fromXml($string, $recursive = false) { // If it forged with 'xml:ns' if (!$this->xmlIgnoreNamespaces) { static $escape_keys = array(); if (!$recursive) { $escape_keys = array('_xmlns' => 'xmlns'); } if (!$recursive and strpos($string, 'xmlns') !== false and preg_match_all('/(\\<.+?\\>)/s', $string, $matches)) { foreach ($matches[1] as $tag) { $escaped_tag = $tag; strpos($tag, 'xmlns=') !== false and $escaped_tag = str_replace('xmlns=', '_xmlns=', $tag); if (preg_match_all('/[\\s\\<\\/]([^\\/\\s\'"]*?:\\S*?)[=\\/\\>\\s]/s', $escaped_tag, $xmlns)) { foreach ($xmlns[1] as $ns) { $escaped = Arr::search($escape_keys, $ns); $escaped or $escape_keys[$escaped = str_replace(':', '_', $ns)] = $ns; $string = str_replace($tag, $escaped_tag = str_replace($ns, $escaped, $escaped_tag), $string); $tag = $escaped_tag; } } } } } $_arr = is_string($string) ? simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA) : $string; $arr = array(); // Convert all objects SimpleXMLElement to array recursively foreach ((array) $_arr as $key => $val) { if (!$this->xmlIgnoreNamespaces) { $key = Arr::get($escape_keys, $key, $key); } $arr[$key] = (is_array($val) or is_object($val)) ? $this->_fromXml($val, true) : $val; } return $arr; }
/** * Tests Arr::search() * * @test */ public function test_search_multi_array() { // Multi-dimensional array $arr_multi = array('one' => array('test' => 1), 'two' => array('test' => 2), 'three' => array('test' => array('a' => 'a', 'b' => 'b'))); $expected = 'one'; $this->assertEquals($expected, Arr::search($arr_multi, array('test' => 1), null, false)); $expected = null; $this->assertEquals($expected, Arr::search($arr_multi, 1, null, false)); // Multi-dimensional array (recursive) $expected = 'one.test'; $this->assertEquals($expected, Arr::search($arr_multi, 1)); $expected = 'three.test.b'; $this->assertEquals($expected, Arr::search($arr_multi, 'b', null, true)); }
/** * is valid timezone.<br> * check and return real timezone value. * * @param string $timezone check timezone * @return string return checked and get timezone value. if found that this is invalid then return null. */ public static function isValidTimezone($timezone) { \Config::load('timezone', 'timezone'); $timezone_list = \Config::get('timezone.timezone', array()); if (array_key_exists($timezone, $timezone_list)) { // found in timezone list key. convert to timezone list value. $timezone = static::getRealTimezoneValue($timezone); } elseif (\Arr::search($timezone_list, $timezone) === null) { // not found in the timezone list value. this is not the timezone key and not even timezone value.! $timezone = null; } unset($timezone_list); return $timezone; }