当前位置: 首页>>代码示例>>PHP>>正文


PHP Arr::set_path方法代码示例

本文整理汇总了PHP中Arr::set_path方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::set_path方法的具体用法?PHP Arr::set_path怎么用?PHP Arr::set_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arr的用法示例。


在下文中一共展示了Arr::set_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extract

 /**
  * Retrieves multiple paths from an array. If the path does not exist in the
  * array, the default value will be added instead.
  *
  *     // Get the values "username", "password" from $_POST
  *     $auth = Arr::extract($_POST, array('username', 'password'));
  *
  *     // Get the value "level1.level2a" from $data
  *     $data = array('level1' => array('level2a' => 'value 1', 'level2b' => 'value 2'));
  *     Arr::extract($data, array('level1.level2a', 'password'));
  *
  * @param   array  $array    array to extract paths from
  * @param   array  $paths    list of path
  * @param   mixed  $default  default value
  * @return  array
  */
 public static function extract($array, array $paths, $default = NULL)
 {
     $found = array();
     foreach ($paths as $path) {
         Arr::set_path($found, $path, Arr::path($array, $path, $default));
     }
     return $found;
 }
开发者ID:procivam,项目名称:hochu-bilet-v3,代码行数:24,代码来源:Arr.php

示例2: as_array

 public function as_array()
 {
     $data = parent::as_array();
     $data['options'] = json_decode($data['options'], true);
     if (!Arr::path($data, "options.title.text", false)) {
         Arr::set_path($data, "options.title.text", __($data['name']));
     }
     return $data;
 }
开发者ID:ragchuck,项目名称:ra-Log,代码行数:9,代码来源:chart.php

示例3: changed

 public function changed($update, array $prefix = array())
 {
     $path = implode('.', $prefix);
     $data = array();
     if (!empty($this->_changed)) {
         if ($update) {
             $data['$inc'] = array($path => $this->_changed);
         } else {
             Arr::set_path($data, $path, $this->_value);
         }
     }
     return $data;
 }
开发者ID:memakeit,项目名称:MangoDB,代码行数:13,代码来源:counter.php

示例4: changed

 public function changed($update, array $prefix = array())
 {
     if (isset($this->_counter)) {
         // acting as counter
         return $this->_counter->changed($update, $prefix);
     }
     $changed = array();
     // Get a list of all relevant keys (current + unset keys)
     $keys = array();
     foreach ($this as $key => $value) {
         $keys[] = $key;
     }
     // don't use array_unique(array_merge(array_keys($this->_changed),$keys)) - array_unique has issues with 0 values (eg array_unique( array('a',0,0,'a','c'));
     $keys = array_merge($keys, array_diff(array_keys($this->_changed), $keys));
     // Walk through array
     foreach ($keys as $key) {
         $value = $this->offsetExists($key) ? $this->offsetGet($key) : NULL;
         if (isset($this->_changed[$key])) {
             // value has been changed
             if ($value instanceof Mango_Interface) {
                 $value = $value->as_array();
             }
             $path = array_merge($prefix, array($key));
             if ($this->_changed[$key] === TRUE) {
                 $data = array();
                 $path = implode('.', $path);
                 if ($update) {
                     $data = array('$set' => array($path => $value));
                 } else {
                     Arr::set_path($data, $path, $value);
                 }
                 $changed = Arr::merge($changed, $data);
                 // __set
                 /*$changed = $update
                 		? arr::merge($changed, array( '$set' => array( implode('.',$path) => $value)))
                 		: arr::merge($changed, arr::path_set($path,$value) );*/
             } else {
                 // __unset
                 if ($update) {
                     $changed = Arr::merge($changed, array('$unset' => array(implode('.', $path) => TRUE)));
                 }
             }
         } elseif ($value instanceof Mango_Interface) {
             $changed = Arr::merge($changed, $value->changed($update, array_merge($prefix, array($key))));
         }
     }
     return $changed;
 }
开发者ID:memakeit,项目名称:MangoDB,代码行数:48,代码来源:array.php

示例5: action_read

 /**
  * Returns all models as JSON
  */
 public function action_read()
 {
     try {
         $id = $this->request->param('id', Arr::get($this->_input, 'id'));
         //Kohana::$log->add(Log::DEBUG,$this->chart->as_array());
         if (empty($id)) {
             $data = $this->chart->read_all();
         } else {
             $data = $this->chart->as_array();
             if (!is_null($this->time)) {
                 $url = sprintf('chart/series/%s/%s', $id, date('Y/m/d', $this->time));
                 $request = Request::factory($url)->execute();
                 $series = json_decode($request->body(), true);
                 Arr::set_path($data, "options.series", Arr::pluck($series, 'options'));
                 Arr::set_path($data, "options.subtitle.text", utf8_encode(strftime("%#d. %B %Y", $this->time)));
             }
         }
         $this->response->body(json_encode($data));
     } catch (Kohana_Exception $e) {
         // Return HTTP 400: Bad Request
         $this->response->status(400);
     }
 }
开发者ID:ragchuck,项目名称:ra-Log,代码行数:26,代码来源:chart.php

示例6: action_read

 public function action_read()
 {
     try {
         $series = array();
         foreach ($this->chart->series->find_all() as $objPlot) {
             /* @var $plot Model_Plot */
             // The relevant series options for Highcharts are in
             // the 'options' as JSON
             $arrPlot = $objPlot->as_array();
             // Fetch the plot-data and add it to the options
             if (!is_null($this->time) and !Arr::path($arrPlot, "options.data", false)) {
                 Arr::set_path($arrPlot, "options.data", $objPlot->getData($this->time));
             }
             $series[] = $arrPlot;
         }
         //Kohana::$log->add(Log::DEBUG,  serialize($series));
         $this->response->headers('Content-Type', 'application/json');
         $this->response->body(json_encode($series));
     } catch (Kohana_Exception $e) {
         // Return HTTP 400: Bad Request
         $this->response->status(400);
     }
 }
开发者ID:ragchuck,项目名称:ra-Log,代码行数:23,代码来源:series.php

示例7: myset

 /**
  * To store changes made to configuration
  * Experimental
  *
  * @param string    $key    Path of variable eg: group.key or group.key.option1
  * @param mixed     $value  The new value
  * @return boolean
  */
 public static function myset($key, $value)
 {
     if (strpos($key, '.') !== FALSE) {
         return FALSE;
     }
     // Split the config group, item and path
     list($group, $item, $_path) = explode('.', $key, 3);
     $path = (isset($_path) and !empty($_path)) ? $item . '.' . $_path : $item;
     // load and override config array
     $config = self::load($group);
     Arr::set_path($config, $path, $value, '.');
     $status = TRUE;
     foreach (self::$_sources as $source) {
         // Copy each value in the config
         /** @var $source \Config_Source */
         $status = $source->write($group, $item, $config[$item]);
     }
     return $status;
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:27,代码来源:config.php

示例8: test_set_path

 /**
  * Tests Arr::path()
  *
  * @test
  * @dataProvider provider_set_path
  * @param string  $path       The path to follow
  * @param boolean $expected   The expected value
  * @param string  $delimiter  The path delimiter
  */
 public function test_set_path($expected, $array, $path, $value, $delimiter = NULL)
 {
     Arr::set_path($array, $path, $value, $delimiter);
     $this->assertSame($expected, $array);
 }
开发者ID:EhteshamMehmood,项目名称:BlogMVC,代码行数:14,代码来源:ArrTest.php

示例9: _resolve_namespaced_files

 /**
  * Convert namespaced $_FILES array into values Formo can understand
  *
  * @access protected
  * @param array $files
  * @return array
  */
 protected function _resolve_namespaced_files(array $files)
 {
     // The array we will eventually return
     $array = array();
     // Convert $files array to dot keys
     $dot_keys = array();
     foreach ($files as $parent_key => $values) {
         if (!empty($values['name'])) {
             $dot_keys = $this->_arr_dotsyntax($values['name']);
             break;
         }
     }
     // All the parts of each $_FILES contents
     $file_parts = array('name', 'type', 'tmp_name', 'error', 'size');
     foreach ($dot_keys as $dot_key) {
         $parts = explode('.', $dot_key);
         $file_name = array_pop($parts);
         foreach ($file_parts as $file_part) {
             // Create values pulled from the complex $_FILES array
             // for namespaced file inputs
             $set_path = $parent_key . '.' . $dot_key . '.' . $file_part;
             $find_path = $parent_key . '.' . $file_part . '.' . $dot_key;
             Arr::set_path($array, $set_path, Arr::path($files, $find_path));
         }
     }
     return $array;
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:34,代码来源:Innards.php

示例10: changed

 /**
  * Get all of the changed fields as an associative array.
  *
  * @param  boolean  indicate update (TRUE) or insert (FALSE) - (determines use of modifiers like $set/$inc)
  * @param  array    prefix data, used internally
  * @return  array  field => value
  */
 public function changed($update, array $prefix = array())
 {
     $changed = array();
     foreach ($this->_fields as $name => $field) {
         if (isset($field['local']) && $field['local'] === TRUE) {
             // local variables are not stored in DB
             continue;
         }
         $value = isset($this->_object[$name]) ? $this->_object[$name] : Arr::get($this->_clean, $name);
         // prepare prefix
         $path = array_merge($prefix, array($name));
         if (isset($this->_changed[$name])) {
             // value has been changed
             if ($value instanceof Mango_Interface) {
                 $value = $value->as_array();
             }
             if ($this->_changed[$name] === TRUE) {
                 $data = array();
                 $path = implode('.', $path);
                 if ($update) {
                     $data = array('$set' => array($path => $value));
                 } else {
                     Arr::set_path($data, $path, $value);
                 }
                 $changed = Arr::merge($changed, $data);
                 // __set
                 /*$changed = $update
                 		? arr::merge($changed,array('$set'=>array( implode('.',$path) => $value) ) )
                 		: arr::merge($changed, arr::path_set($path,$value) );*/
             } else {
                 // __unset
                 if ($update) {
                     $changed = Arr::merge($changed, array('$unset' => array(implode('.', $path) => TRUE)));
                 }
             }
         } elseif ($this->__isset($name)) {
             // check any (embedded) objects/arrays/sets
             if ($value instanceof Mango_Interface) {
                 $changed = Arr::merge($changed, $value->changed($update, $path));
             }
         }
     }
     return $changed;
 }
开发者ID:tscms,项目名称:mangodb,代码行数:51,代码来源:Mango.php

示例11: offsetSet

 /**
  * Throws an exception because Filter is read-only.
  * Implements ArrayAccess method.
  *
  * @throws  Kohana_Exception
  * @param   string   $offset    key to set
  * @param   mixed    $value     value to set
  * @return  void
  */
 public function offsetSet($offset, $value)
 {
     Arr::set_path($this->_data, $offset, $value);
 }
开发者ID:ZerGabriel,项目名称:cms-1,代码行数:13,代码来源:filter.php

示例12: set

 /**
  * Set a value for a field's attribute
  * You can use Arr::set_path's dot-syntax to set an attribute
  *
  * @access public
  * @param mixed $var
  * @param mixed $val (default: NULL)
  * @return void
  */
 public function set($var, $val = NULL)
 {
     if (is_array($var)) {
         foreach ($var as $key => $value) {
             $this->set($key, $value);
         }
         return $this;
     }
     if ($var === 'val') {
         // Special case for value
         $this->val($val);
         return $this;
     }
     if ($var === 'driver') {
         // Special case for driver
         $this->_set_driver($val);
         return $this;
     }
     if ($var == 'attr') {
         $this->attr($val);
         return $this;
     }
     if ($var == 'fields' and is_array($val)) {
         foreach ($val as $field) {
             $field['parent'] = $this;
             $new_field = Formo::factory($field);
             $this->add($new_field);
         }
         return $this;
     }
     if (strpos($var, '.') !== FALSE) {
         list($var, $parts) = explode('.', $var, 2);
     } else {
         $parts = NULL;
     }
     $array_name = $this->_get_var_name($var);
     if ($array_name === '_vars') {
         if ($parts) {
             return Arr::set_path($this->_vars, "{$var}.{$parts}", $val);
         } else {
             $this->_vars[$var] = $val;
         }
     } elseif ($parts) {
         Arr::set_path($this->{$array_name}, $parts, $val);
     } else {
         // Set the value
         $this->{$array_name} = $val;
     }
     return $this;
 }
开发者ID:bmidget,项目名称:kohana-formo,代码行数:59,代码来源:Formo.php

示例13: action_index

 public function action_index()
 {
     $ids = array_keys(Arr::get($_POST, 'job', array()));
     $ids = array_filter($ids, function ($st) {
         return preg_match('/^T1W[0-9]{12}$/i', $st);
     });
     if (!$ids) {
         throw new HTTP_Exception_404('Not found');
     }
     $users = DB::select('id', 'company_id')->from('users')->execute()->as_array('id', 'company_id');
     $companies = array();
     $result = Database_Mongo::collection('submissions')->find(array('job_key' => array('$in' => $ids), 'financial_time' => array('$gt' => 0)), array('user_id' => 1, 'job_key' => 1, 'paid' => 1, 'rate' => 1));
     foreach ($result as $submission) {
         if (Arr::get($users, $submission['user_id'])) {
             $path = array($users[$submission['user_id']], $submission['job_key']);
             Arr::set_path($companies, $path, Arr::path($companies, $path, 0) + $submission['paid'] * $submission['rate']);
         }
     }
     $paid = array();
     if ($companies) {
         $result = DB::select('job_key', 'company_id', DB::expr('SUM(`payment_jobs`.`amount`) as value'))->from('payment_jobs')->join('payments')->on('payment_id', '=', 'id')->where('job_key', 'IN', $ids)->group_by('job_key', 'company_id')->execute()->as_array();
         foreach ($result as $payment) {
             $paid[$payment['company_id']][$payment['job_key']] = $payment['value'];
         }
     }
     $jobs = array_fill_keys($ids, array('c' => array(), 'p' => array()));
     foreach ($companies as $company => $list) {
         foreach ($list as $key => $value) {
             $jobs[$key]['c'][$company] = $value;
         }
     }
     foreach ($paid as $company => $list) {
         foreach ($list as $key => $value) {
             $jobs[$key]['p'][$company] = $value;
         }
     }
     if (Arr::get($_POST, 'company') && Arr::get($_POST, 'payment')) {
         $company = Arr::get($companies, $_POST['company']);
         if (!$company) {
             die(json_encode(array('success' => false)));
         }
         $payments = array_map('floatval', array_intersect_key($_POST['payment'], $company));
         $payment = array('company_id' => intval($_POST['company']), 'admin_id' => User::current('id'), 'payment_time' => time(), 'amount' => array_sum($payments));
         Database::instance()->begin();
         $id = Arr::get(DB::insert('payments', array_keys($payment))->values(array_values($payment))->execute(), 0);
         $query = DB::insert('payment_jobs', array('payment_id', 'job_key', 'amount'));
         foreach ($company as $job => $value) {
             if (Arr::get($payments, $job)) {
                 $query->values(array($id, $job, $payments[$job]));
             }
         }
         $query->execute();
         $partial = array();
         $paid = array();
         $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => $ids)));
         foreach ($result as $job) {
             $data = Utils::calculate_financial($job);
             if (isset($data['$set']['partial'])) {
                 $partial[] = $job['_id'];
             } elseif (isset($data['$set']['paid'])) {
                 $paid[] = $job['_id'];
             }
         }
         if ($partial) {
             Database_Mongo::collection('jobs')->update(array('_id' => array('$in' => $partial)), array('$unset' => array('paid' => 1), '$set' => array('partial' => 1)), array('multiple' => 1));
         }
         if ($paid) {
             Database_Mongo::collection('jobs')->update(array('_id' => array('$in' => $paid)), array('$unset' => array('partial' => 1), '$set' => array('paid' => 1)), array('multiple' => 1));
         }
         Database::instance()->commit();
         Messages::save('Payment successfully added!', 'success');
         die(json_encode(array('success' => true)));
     }
     ksort($jobs);
     if ($companies) {
         $companies = DB::select('id', 'name')->from('companies')->where('id', 'IN', array_keys($companies))->order_by('name', 'ASC')->execute()->as_array('id', 'name');
     } else {
         $companies = array();
     }
     $view = View::factory('Jobs/Payment')->bind('jobs', $jobs)->bind('companies', $companies);
     $this->response->body($view);
 }
开发者ID:nikulinsanya,项目名称:exeltek,代码行数:82,代码来源:Payment.php

示例14: set_array_values

 private static function set_array_values(&$array, $path, $values)
 {
     $new = array();
     foreach ($values as $item) {
         parse_str($item, $item);
         $new = Arr::merge($new, $item);
     }
     Arr::set_path($array, $path, $new);
 }
开发者ID:openbuildings,项目名称:shipping,代码行数:9,代码来源:Items.php

示例15: changed

 public function changed($update, array $prefix = array())
 {
     // fetch changed elements in this set
     $elements = array();
     switch ($this->_mode) {
         case 'push':
         case 'set':
         case 'addToSet':
             foreach ($this->_changed as $index) {
                 $elements[] = $this->offsetGet($index);
             }
             break;
         case 'pull':
             // changed values were stored in _changed array
             $elements = $this->_changed;
             break;
     }
     // normalize changed elements
     foreach ($elements as &$element) {
         if ($element instanceof Mango_Interface) {
             $element = $element->as_array();
         }
     }
     if ($update === FALSE) {
         // no more changes possible after this
         $data = array();
         if (count($elements)) {
             Arr::set_path($data, implode('.', $prefix), $elements);
         }
         return $data;
         /*return count($elements)
         		? arr::path_set($prefix,$elements)
         		: array();*/
     }
     // First, get all changes made to the elements of this set directly
     $changes_local = array();
     switch ($this->_mode) {
         case 'pop':
             $changes_local = array('$pop' => array(implode('.', $prefix) => $this->_changed));
             break;
         case 'set':
             foreach ($this->_changed as $index => $set_index) {
                 $changes_local = Arr::merge($changes_local, array('$set' => array(implode('.', $prefix) . '.' . $set_index => $elements[$index])));
             }
             break;
         case 'unset':
             foreach ($this->_changed as $unset_index) {
                 $changes_local = Arr::merge($changes_local, array('$unset' => array(implode('.', $prefix) . '.' . $unset_index => TRUE)));
             }
             break;
         case 'addToSet':
             $elements = count($this->_changed) > 1 ? array('$each' => $elements) : $elements[0];
             $changes_local = array('$addToSet' => array(implode('.', $prefix) => $elements));
             break;
         case 'push':
         case 'pull':
             $mod = '$' . $this->_mode;
             if (count($this->_changed) > 1) {
                 $mod .= 'All';
             } else {
                 $elements = $elements[0];
             }
             $changes_local = array($mod => array(implode('.', $prefix) => $elements));
             break;
     }
     // Second, get all changes made within children elements themselves
     $changes_children = array();
     foreach ($this as $index => $value) {
         if (!is_array($this->_changed) || !in_array($this->_mode, array('push', 'set', 'addToSet')) || !in_array($index, $this->_changed)) {
             if ($value instanceof Mango_Interface) {
                 $changes_children = Arr::merge($changes_children, $value->changed($update, array_merge($prefix, array($index))));
             }
         }
     }
     // Some modifiers don't work well together in Mongo - check for mistakes
     if (isset($this->_mode) && $this->_mode !== 'set' && $this->_mode !== 'unset' && !empty($changes_children)) {
         throw new Mango_Exception('MongoDB does not support any other updates when already in :mode mode', array(':mode' => $this->_mode));
     }
     // Return all changes
     return Arr::merge($changes_local, $changes_children);
 }
开发者ID:memakeit,项目名称:MangoDB,代码行数:81,代码来源:set.php


注:本文中的Arr::set_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。