本文整理汇总了PHP中Arr::replace_key方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::replace_key方法的具体用法?PHP Arr::replace_key怎么用?PHP Arr::replace_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::replace_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse_browscap
/**
* download and parse the browscap file
*
* @return array array with parsed download info, or empty if the download is disabled of failed
*/
protected static function parse_browscap()
{
// get the browscap.ini file
switch (static::$config['browscap']['method']) {
case 'local':
if (!file_exists(static::$config['browscap']['file']) or filesize(static::$config['browscap']['file']) == 0) {
throw new \Exception('Agent class: could not open the local browscap.ini file.');
}
$data = @file_get_contents(static::$config['browscap']['file']);
break;
// socket connections are not implemented yet!
// socket connections are not implemented yet!
case 'sockets':
$data = false;
break;
case 'curl':
$curl = curl_init();
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERAGENT, 'Fuel PHP framework - Agent class (http://fuelphp.com)');
curl_setopt($curl, CURLOPT_URL, static::$config['browscap']['url']);
$data = curl_exec($curl);
curl_close($curl);
break;
case 'wrapper':
ini_set('user_agent', 'Fuel PHP framework - Agent class (http://fuelphp.com)');
$data = file_get_contents(static::$config['browscap']['url']);
default:
break;
}
if ($data === false) {
logger(\Fuel::L_ERROR, 'Failed to download browscap.ini file.', 'Agent::parse_browscap');
}
// parse the downloaded data
$browsers = @parse_ini_string($data, true, INI_SCANNER_RAW) or $browsers = array();
// remove the version and timestamp entry
array_shift($browsers);
$result = array();
// reverse sort on key string length
uksort($browsers, function ($a, $b) {
return strlen($a) < strlen($b) ? 1 : -1;
});
$index = array();
$count = 0;
// reduce the array keys
foreach ($browsers as $browser => $properties) {
$index[$browser] = $count++;
// fix any type issues
foreach ($properties as $var => $value) {
if (is_numeric($value)) {
$properties[$var] = $value + 0;
} elseif ($value == 'true') {
$properties[$var] = true;
} elseif ($value == 'false') {
$properties[$var] = false;
}
}
$result[$browser] = \Arr::replace_key($properties, static::$keys);
}
// reduce parent links to
foreach ($result as $browser => &$properties) {
if (array_key_exists('Parent', $properties)) {
if ($properties['Parent'] == 'DefaultProperties') {
unset($properties['Parent']);
} else {
if (array_key_exists($properties['Parent'], $index)) {
$properties['Parent'] = $index[$properties['Parent']];
} else {
unset($properties['Parent']);
}
}
}
}
// save the result to the cache
if (!empty($result)) {
$cache = \Cache::forge(static::$config['cache']['identifier'] . '.browscap');
$cache->set($result, static::$config['cache']['expiry']);
}
return $result;
}
示例2: insert_before
/**
* Insert before a specific key.
*
* @access public
* @return void
*/
public function insert_before($key, $title, $callback, $ukey = null)
{
$this->prepare_insert($callback, $ukey);
\Arr::insert_before_key($this->properties, $title, $key);
$this->properties = \Arr::replace_key($this->properties, array(0 => $ukey));
return $this;
}