本文整理汇总了PHP中Arr::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::merge方法的具体用法?PHP Arr::merge怎么用?PHP Arr::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get(Model $from, array $conditions = array())
{
// Create the query on the model_through
$query = call_user_func(array($this->model_to, 'query'));
// set the model_from's keys as where conditions for the model_through
$join = array('table' => array($this->table_through, 't0_through'), 'join_type' => null, 'join_on' => array(), 'columns' => $this->select_through('t0_through'));
reset($this->key_from);
foreach ($this->key_through_from as $key) {
if ($from->{current($this->key_from)} === null) {
return array();
}
$query->where('t0_through.' . $key, $from->{current($this->key_from)});
next($this->key_from);
}
reset($this->key_to);
foreach ($this->key_through_to as $key) {
$join['join_on'][] = array('t0_through.' . $key, '=', 't0.' . current($this->key_to));
next($this->key_to);
}
$conditions = \Arr::merge($this->conditions, $conditions);
foreach (\Arr::get($conditions, 'where', array()) as $key => $condition) {
is_array($condition) or $condition = array($key, '=', $condition);
$query->where($condition);
}
foreach (\Arr::get($conditions, 'order_by', array()) as $field => $direction) {
if (is_numeric($field)) {
$query->order_by($direction);
} else {
$query->order_by($field, $direction);
}
}
$query->_join($join);
return $query->get();
}
示例2: action_execute
/**
* Handles the request to execute a task.
*
* Responsible for parsing the tasks to execute & also any config items that
* should be passed to the tasks
*/
public function action_execute()
{
if (empty($this->_task)) {
return $this->action_help();
}
$task = $this->_retrieve_task();
$defaults = $task->get_config_options();
if (!empty($defaults)) {
if (Arr::is_assoc($defaults)) {
$options = array_keys($defaults);
$options = call_user_func_array(array('CLI', 'options'), $options);
$config = Arr::merge($defaults, $options);
} else {
// Old behavior
$config = call_user_func_array(array('CLI', 'options'), $defaults);
}
} else {
$config = array();
}
// Validate $config
$validation = Validation::factory($config);
$validation = $task->build_validation($validation);
if (!$validation->check()) {
echo View::factory('minion/error/validation')->set('errors', $validation->errors($task->get_errors_file()));
} else {
// Finally, run the task
echo $task->execute($config);
}
}
示例3: get
public function get(Model $from, array $conditions = array())
{
$query = call_user_func(array($this->model_to, 'query'));
reset($this->key_to);
foreach ($this->key_from as $key) {
// no point running a query when a key value is null
if ($from->{$key} === null) {
return array();
}
$query->where(current($this->key_to), $from->{$key});
next($this->key_to);
}
$conditions = \Arr::merge($this->conditions, $conditions);
foreach (\Arr::get($conditions, 'where', array()) as $key => $condition) {
is_array($condition) or $condition = array($key, '=', $condition);
$query->where($condition);
}
foreach (\Arr::get($conditions, 'order_by', array()) as $field => $direction) {
if (is_numeric($field)) {
$query->order_by($direction);
} else {
$query->order_by($field, $direction);
}
}
return $query->get();
}
示例4: resolve
protected function resolve($item, $property)
{
$items = array();
$arrowPos = strpos($property, '->');
if ($arrowPos !== false) {
$propertyMatch = mb_substr($property, 0, $arrowPos);
} else {
$propertyMatch = $property;
}
$match = $item->{$propertyMatch};
if (empty($match)) {
return array();
}
if ($arrowPos !== false) {
if (is_array($match)) {
foreach ($match as $matched) {
$items = \Arr::merge($items, $this->resolve($matched, mb_substr($property, $arrowPos + 2)));
}
} else {
$items = \Arr::merge($items, $this->resolve($match, mb_substr($property, $arrowPos + 2)));
}
} else {
if (is_array($match)) {
$items = \Arr::merge($items, $match);
} else {
$items[] = $match;
}
}
return $items;
}
示例5: getQuery
/**
* Return the query builder for this model
*
* @return \Api\Rest_Query
*/
protected function getQuery($params = array())
{
if (!$this->query) {
$this->query = new Rest_Query($this->model, $this->plural, 'data', \Arr::merge($this->params, $params), $this->field);
}
return $this->query;
}
示例6: __construct
/**
* @param array $data
* @param null $id
*/
public function __construct($data = array(), $id = NULL)
{
$klass = get_called_class();
$meta = $klass::meta();
$this->_options = Arr::merge($this->_options, Arr::get($meta, "options"));
$this->__fields = Arr::get($meta, "fields");
$this->__2m_fields = Arr::get($meta, "2m_fields", array());
if ($this->__instance === NULL) {
$this->__instance = Arr::get($this->_options, "model");
}
$this->__relations = $this->__load_relations();
if ($data instanceof ORM) {
$data = $data->as_array();
}
$columns = Arr::get($this->_options, "model")->list_columns();
if ($id !== NULL) {
$this->__instance = Arr::get($this->_options, "model")->where(Arr::get($this->_options, "model")->primary_key(), "=", $id)->find();
$iterated = array();
foreach ($this->__instance->as_array() as $key => $value) {
$iterated[$key] = $value;
}
$data = Arr::merge($iterated, $data);
}
foreach ($columns as $column) {
$name = $column["column_name"];
$field = $this->__create_field($name, $column, $data);
$field->theme(Arr::get($this->_options, "theme"));
if (in_array($name, Arr::get($this->_options, "display_fields")) || empty($this->_options["display_fields"])) {
if (!in_array($name, Arr::get($this->_options, "except_fields"))) {
$this->add_field($field);
}
}
}
$this->__load_2m($data);
}
示例7: action_index
public function action_index()
{
$username = $this->request->param('username');
$this->view = new View_Message_Create();
$this->view->username = $username;
if ($this->request->method() == HTTP_Request::POST) {
try {
$post = $this->request->post();
$receiver = ORM::factory('User')->where('username', '=', $post['receiver'])->find();
if (!$receiver->loaded()) {
return Hint::error('Cannot find a user with the username: ' . $username);
} elseif ($this->user->id === $receiver->id) {
return Hint::error('You cannot send a message to yourself!');
}
$message_data = Arr::merge($this->request->post(), array('sender_id' => $this->user->id, 'receiver_id' => $receiver->id));
$message = ORM::factory('Message')->create_message($message_data, array('receiver_id', 'subject', 'content', 'sender_id'));
$message_data_sent = Arr::merge($this->request->post(), array('receiver_id' => $this->user->id, 'sender_id' => $receiver->id, 'sent' => 1, 'read' => 1));
ORM::factory('Message')->create_message($message_data_sent, array('receiver_id', 'subject', 'content', 'sender_id', 'sent', 'read'));
Hint::success('You have sent a message');
$this->redirect(Route::get('message.inbox')->uri());
} catch (ORM_Validation_Exception $e) {
Hint::error($e->errors('models'));
}
}
}
示例8: load
public function load($group)
{
if (!count($this->_sources)) {
throw new JsonApiApplication_Exception("No configuration sources attached");
}
if (empty($group)) {
throw new JsonApiApplication_Exception("Need to specify a config group");
}
if (!is_string($group)) {
throw new JsonApiApplication_Exception("Config group must be a string");
}
if (strpos($group, ".") !== FALSE) {
list($group, $path) = explode(".", $group, 2);
}
if (isset($this->_groups[$group])) {
if (isset($path)) {
return Arr::path($this->_groups[$group], $path, NULL, ".");
}
return $this->_groups[$group];
}
$config = array();
$sources = array_reverse($this->_sources);
foreach ($sources as $source) {
if ($source instanceof JsonApiApplication_Config_Reader) {
if ($source_config = $source->load($group)) {
$config = Arr::merge($config, $source_config);
}
}
}
$this->_groups[$group] = new JsonApiApplication_Config_Group($this, $group, $config);
if (isset($path)) {
return Arr::path($config, $path, NULL, ".");
}
return $this->_groups[$group];
}
示例9: create
/**
* Create a feed from the given parameters
*
* @param array $info Feed information
* @param array $items Items to add to the feed
* @param string $encoding Define which encoding to use [Optional]
*
* @return string
*
* @throws Feed_Exception
*
* @uses Arr::merge
* @uses URL::is_absolute
* @uses URL::site
*/
public function create(array $info, array $items, $encoding = NULL)
{
$generator = array('title' => Feed::NAME, 'link' => '', 'generator' => Feed::getGenerator());
$info = Arr::merge($generator, $info);
$feed = $this->prepareXML($encoding);
foreach ($info as $name => $value) {
if ($name === 'image') {
// Create an image element
$image = $feed->channel->addChild('image');
if (!isset($value['link'], $value['url'], $value['title'])) {
throw new Feed_Exception('Feed images require a link, url, and title');
}
if (URL::is_absolute($value['url'])) {
// Convert URIs to URLs
$value['url'] = URL::site($value['url'], TRUE);
}
// Create the image elements
$image->addChild('link', $value['link']);
$image->addChild('url', $value['url']);
$image->addChild('title', $value['title']);
} else {
if (($name === 'pubDate' or $name === 'lastBuildDate') and (is_int($value) or ctype_digit($value))) {
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
} elseif (($name === 'link' or $name === 'docs') and URL::is_absolute($value)) {
// Convert URIs to URLs
$value = URL::site($value, TRUE);
}
// Add the info to the channel
$feed->channel->addChild($name, $value);
}
}
foreach ($items as $item) {
// Add the item to the channel
$row = $feed->channel->addChild('item');
foreach ($item as $name => $value) {
if ($name === 'pubDate' and (is_int($value) or ctype_digit($value))) {
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
} elseif (($name === 'link' or $name === 'guid') and URL::is_absolute($value)) {
// Convert URIs to URLs
$value = URL::site($value, TRUE);
}
// Add the info to the row
$row->addChild($name, $value);
}
}
if (function_exists('dom_import_simplexml')) {
// Convert the feed object to a DOM object
$feed = dom_import_simplexml($feed)->ownerDocument;
// DOM generates more readable XML
$feed->formatOutput = TRUE;
// Export the document as XML
$feed = $feed->saveXML();
} else {
// Export the document as XML
$feed = $feed->asXML();
}
return $feed;
}
示例10: verify_access_token
/**
* Verify the access token.
*
* @param array an associative array of auth settings
* @return OAuthToken
* @link http://digg.com/api/docs/1.0/detail/oauth.verify
*/
public function verify_access_token()
{
// Configure the auth settings
$auth_config = array();
if ($this->is_valid_token(NULL, TRUE)) {
$token = $this->_token;
$auth_config = array('token_key' => $token->key, 'token_secret' => $token->secret);
}
$auth_config = Arr::merge($this->_auth_config, $auth_config);
// Configure the HTTP method, URL, and request parameters
$http_method = MMI_HTTP::METHOD_POST;
$url = $this->_api_url;
$parms = array('method' => 'oauth.verify');
// Verify the request token
$verified = 0;
$response = $this->_auth_request($auth_config, $http_method, $url, $parms);
if ($response instanceof MMI_Curl_Response) {
$http_status_code = $response->http_status_code();
if (intval($http_status_code) === 200) {
$data = $this->_decode_xml($response->body(), TRUE);
if (is_array($data)) {
$verified = intval(Arr::path($data, '@attributes.verified', 0));
}
}
}
unset($response);
return $verified === 1;
}
示例11: forge
/**
* Create an OpAuth instance
*
* @param array any call-time configuration to be used
* @param bool whether or not Opauth should run automatically
*/
public static function forge($config = array(), $autorun = true)
{
// deal with passing only the autorun value
if (func_num_args() == 1 and is_bool($config)) {
$autorun = $config;
$config = array();
}
// merge the default config with the runtime config
$config = \Arr::merge(\Config::get('opauth'), $config);
// define the transport system we use
$config['callback_transport'] = 'get';
// make sure we have a remotes table
if (!isset($config['table']) and ($config['table'] = static::$provider_table) === null) {
throw new \OpauthException('No providers table configured. At the moment, only SimpleAuth and OrmAuth can be auto-detected.');
}
// and a security salt
if (empty($config['security_salt'])) {
throw new \OpauthException('There is no "security_salt" defined in the opauth.php configuration file.');
}
// set some defaults, just in case
isset($config['security_iteration']) or $config['security_iteration'] = 300;
isset($config['security_timeout']) or $config['security_timeout'] = '2 minutes';
if (empty($config['path'])) {
$parsed_url = parse_url(\Uri::base() . \Request::main()->uri->get());
$path = explode('/', trim($parsed_url['path'], '/'));
// construct the path if needed
// $path = \Request::main()->uri->get_segments();
$params = count(\Request::active()->route->method_params);
while ($params-- > 0) {
array_pop($path);
}
$config['path'] = '/' . implode('/', $path) . '/';
}
// and construct the callback URL if needed
if (empty($config['callback_url'])) {
// pop the method name from the path
$path = explode('/', trim($config['path'], '/'));
array_pop($path);
// and add 'callback' as the controller callback action
$config['callback_url'] = '/' . implode('/', $path) . '/callback/';
}
// determine the name of the provider we want to call
if (!$autorun) {
// we're processing a callback
$config['provider'] = 'Callback';
} else {
if (empty($config['provider'])) {
$parsed_url = parse_url(\Uri::base() . \Request::main()->uri->get());
$provider = explode('/', substr($parsed_url['path'], strlen($config['path'])));
$config['provider'] = ucfirst($provider[0]);
}
// check if we have a strategy defined for this provider
$strategies = \Config::get('opauth.Strategy', array());
if (!array_key_exists(strtolower($config['provider']), array_change_key_case($strategies))) {
throw new \OpauthException('Opauth strategy "' . $config['provider'] . '" is not supported');
}
}
// return the created Auth_Opauth object
return new static($config, $autorun);
}
示例12: __construct
protected function __construct()
{
$this->_installer = new Installer();
$default = $this->_installer->default_params();
$this->_options = Arr::merge($this->_options, $default);
parent::__construct();
}
示例13: __construct
public function __construct($options)
{
if (!isset($options["choices"])) {
throw new Kohana_Exception("You should define a list of a choices into a factory for Choice field");
}
$this->_options = Arr::merge($this->_options, $options);
}
示例14: get_options
public function get_options()
{
$uid = $this->param('uid', NULL, TRUE);
$options = ORM::factory('email_type', (int) $uid)->data();
$options = Arr::merge($options, Config::get('email', 'default_template_data', array()));
$this->response($options);
}
示例15: get_request_token
/**
* Get a request token.
*
* @throws Kohana_Exception
* @param string the callback URL
* @param array an associative array of auth settings
* @return OAuthToken
*/
public function get_request_token($oauth_callback = NULL, $auth_config = array())
{
// Configure the auth settings
if (!is_array($auth_config)) {
$auth_config = array();
}
$auth_config = Arr::merge($this->_auth_config, $auth_config);
// Configure the HTTP method and the URL
$http_method = $this->_request_token_http_method;
$url = $this->_request_token_url;
$this->_ensure_parm('Request token URL', $url);
// Configure the auth scope parameter
$scope = Arr::get($auth_config, 'scope');
$this->_ensure_parm('Authorization scope', $scope);
$parms['scope'] = $scope;
// Configure the OAuth callback URL
if (!isset($oauth_callback)) {
$oauth_callback = $this->auth_callback_url();
}
if (!empty($oauth_callback)) {
$parms['oauth_callback'] = $oauth_callback;
}
// Make the request and extract the token
$response = $this->_auth_request($auth_config, $http_method, $url, $parms);
$token = NULL;
if ($this->_validate_curl_response($response, 'Invalid request token')) {
$token = $this->_extract_token($response);
}
return $token;
}