/** * Get or set our $_SESSION var via . sperated array access * * @param key string A period seperated string of array keys and values * @param value string The value to be set * * @return array */ static function session($key, $value = null) { if (!is_null($value)) { Arr::set($_SESSION, ID . '.' . $key, $value); } return Arr::get($_SESSION, ID . '.' . $key); }
public static function setup_configs_template_body($configs) { foreach ($configs as $type => $types) { foreach ($types as $module => $modules) { foreach ($modules as $item_key => $items) { if (!isset($items['body'])) { continue; } if (!is_array($items['body'])) { continue; } if (!empty($items['body']['default']['file'])) { $ext = !empty($items['format']) ? $items['format'] : 'php'; $body = file_get_contents(sprintf('%sviews/%s.%s', APPPATH, $items['body']['default']['file'], $ext)); } elseif (!empty($items['body']['default']['value'])) { $body = $items['body']['default']['value']; } else { continue; } $key = implode('.', array($type, $module, $item_key, 'body')); Arr::set($configs, $key, $body); } } } return $configs; }
/** * Set a configuration item. * * @param string $key * @param mixed $value * @return void */ public static function set($key, $value) { list($module, $file, $key) = static::parse($key); if (!static::load($module, $file)) { throw new \Exception("Error setting configuration option. Configuration file [{$file}] is not defined."); } Arr::set(static::$items[$module][$file], $key, $value); }
public function update(array $menu) { // Set children $root = \Config::get('menu/' . $this->id, array()); \Arr::set($root, 'children', $menu); // Save to file return \Config::save('menu/' . $this->id, $root); }
/** * Set a configuration item * * Similar to the Config::get method, this function uses "dot" notation to * allow for setting of configuration items. Setting a configuration item does * not save the configuration permanently, only for the life of this request. * * ## Usage * * Config::set('file.key', $value); * * @param string The "dot" notation key to be set * @param mixed The value of the key to be set * @return void No value is returned */ public static function set($key, $value) { list($package, $file, $key) = static::parse($key); if (!static::load($package, $file)) { throw new \OutOfBoundsException('Error setting configuration option. Configuration file [%s] is not defined.', $file); } Arr::set(static::$items[$package][$file], $key, $value); }
/** * 设置值 * * @param $name 类型如get.name,post.id * @param $value * * @return bool */ public function set($name, $value) { $info = explode('.', $name); $action = strtoupper(array_shift($info)); if (isset(self::$items[$action])) { self::$items[$action] = Arr::set(self::$items[$action], implode('.', $info), $value); return true; } }
/** * Sets a config item * * @param mixed $key Config key or array to merge * @param mixed $value Config value * * @return this */ public function set_config($key, $value = null) { if (is_array($key)) { $this->config = \Arr::merge($this->config, $key); } else { \Arr::set($this->config, $key, $value); } return $this; }
/** * @param array $attributes * @return static */ public function newFromBuilder($attributes = [], $connection = null) { $attributes = (array) $attributes; $nestedData = []; foreach ($attributes as $key => $value) { $key = str_replace('---', '.', $key); Arr::set($nestedData, $key, $value); } $instance = $this->buildForeignEntity(null, $nestedData); return $instance; }
public function action_popup() { if (empty($_GET['url'])) { foreach ($this->config['fields'] as $key => $field) { if (\Arr::get($field, 'form.default') && !isset($_GET[$key])) { \Arr::set($_GET, $key, \Arr::get($field, 'form.default')); } } } return parent::action_popup(); }
/** * Sets a config value * * @param string * @param mixed * @return Fieldset this, to allow chaining */ public function set_config($config, $value = null) { $config = is_array($config) ? $config : array($config => $value); foreach ($config as $key => $value) { if (strpos($key, '.') === false) { $this->config[$key] = $value; } else { \Arr::set($this->config, $key, $value); } } return $this; }
public static function _init() { // static::$_properties = \Arr::merge(static::$_properties, array( // 'default_id' => array( // 'form' => array( // 'options' => function($model) { // $model->items; // $model = $model->to_array(); // return \Arr::pluck($model['items'], 'name', 'id'); // } // ) // ), // )); if (\Auth::has_access('enum.enum[all]')) { \Arr::set(static::$_properties, 'read_only.form', array('type' => 'checkbox', 'template' => 'switch', 'options' => array(gettext('No'), gettext('Yes')))); } }
/** * viewファイルからの全体オフセット量追加 * * このメソッドによる変更はインスタンスが破棄されるまで有効です * * @param real $x 水平方向のオフセット量 * @param real $y 垂直方向のオフセット量 */ public function set_global_offset($x = 0.0, $y = 0.0) { \Arr::set($this->config, 'global_offset.x', \Arr::get($this->config, 'global_offset.x') + $x); \Arr::set($this->config, 'global_offset.y', \Arr::get($this->config, 'global_offset.y') + $y); }
/** * Set new or update existing config variable * * <code> * Config::set('site.title', 'value'); * </code> * * @access public * @param string $key Key * @param mixed $value Value */ public static function set($key, $value) { Arr::set(static::$config, $key, $value); }
/** * Set an array item to a given value using "dot" notation. * * If no key is given to the method, the entire array will be replaced. * * @param array $array * @param string $key * @param mixed $value * @return array */ function array_set(&$array, $key, $value) { return Arr::set($array, $key, $value); }
/** * set session flash variables * * @param string name of the variable to set * @param mixed value * @access public * @return Fuel\Core\Session_Driver */ public function set_flash($name, $value) { if (strpos($name, '.') !== false) { $keys = explode('.', $name, 2); $name = array_shift($keys); } else { $keys = false; } if ($keys) { if (isset($this->flash[$this->config['flash_id'] . '::' . $name]['value'])) { $this->flash[$this->config['flash_id'] . '::' . $name]['state'] = 'new'; } else { $this->flash[$this->config['flash_id'] . '::' . $name] = array('state' => 'new', 'value' => array()); } \Arr::set($this->flash[$this->config['flash_id'] . '::' . $name]['value'], $keys[0], $value); } else { $this->flash[$this->config['flash_id'] . '::' . $name] = array('state' => 'new', 'value' => $value); } return $this; }
/** * Add a single parameter/value or an array of parameters * * @param string|array $param * @param mixed $value * @return Request_Driver */ public function add_param($param, $value = null) { if (!is_array($param)) { $param = array($param, $value); } foreach ($param as $key => $val) { \Arr::set($this->params, $key, $val); } return $this; }
/** * Set a field's value. * * @throws InvalidArgumentException - When the wrong target object type is passed to an association * @throws BadMethodCallException - When no property exists by that name. * @param string $field * @param mixed $value * @return void */ public function set($field, $value, $overwrite = true) { $metadata = $this->_metadata(); // First of all, if this is an association then we'll need to do some detective work... if ($metadata->hasAssociation($field)) { $target_class = $metadata->getAssociationTargetClass($field); if ($metadata->isSingleValuedAssociation($field)) { if ($value instanceof $target_class) { $association = $value; } else { if (is_numeric($value)) { $association = $target_class::find($value); } else { if (is_array($value)) { if (($aid = \Arr::get($value, 'id')) && is_numeric($aid)) { $association = $target_class::find($aid); } else { $association = isset($this->{$field}) && $this->{$field} instanceof $target_class ? $this->{$field} : new $target_class(); } } else { $this->{$field} = $association = null; return; } } } if (isset($association) && !$association instanceof Model) { throw new \InvalidArgumentException("The relation '{$field}' of '" . get_class($this) . "' is not an instance of CMF\\Doctrine\\Model - this convenience method won't work!"); } if (isset($association) && is_array($value)) { $association->populate($value); } $this->{$field} = $association; $this->completeOwningSide($field, $target_class, $association); if (isset($association)) { \D::manager()->persist($association); } } else { if ($metadata->isCollectionValuedAssociation($field)) { if (is_null($value) || empty($value)) { $value = array(); } else { if (is_numeric($value) || $value instanceof \CMF\Doctrine\Model) { $value = array($value); } else { if ($value instanceof Collection) { $value = $value->toArray(); } else { if (!is_array($value) && !$value instanceof Collection) { throw new \InvalidArgumentException("The value '{$value}' passed to '{$field}' of '" . get_class($this) . "' is not a collection or an array"); } } } } $value = array_values($value); $ids = array(); $collection = !isset($this->{$field}) ? new ArrayCollection() : $this->{$field}; $len = count($value); for ($i = 0; $i < $len; $i++) { $item = $value[$i]; $item_target_class = $target_class; if (is_numeric($item) || is_string($item)) { $item = $target_class::find($item); } else { if (is_array($item)) { $new_item = null; if (array_key_exists('id', $item) && !empty($item['id'])) { $new_item = $target_class::find($item['id']); } if (is_null($new_item)) { $type = str_replace('\\\\', '\\', isset($item['__type__']) ? $item['__type__'] : $target_class); if (isset($item['__type__']) && is_subclass_of($type, $target_class)) { $item_target_class = $type; } $new_item = new $item_target_class(); } $new_item->populate($item); $item = $new_item; } } if (is_null($item)) { continue; } if (!$collection->contains($item)) { $collection->add($item); $this->completeOwningSide($field, $item_target_class, $item); } \D::manager()->persist($item); $ids[] = $item->get('id'); if ($item->changed) { $this->changed = true; } } // If overwrite is true, remove collection items that aren't present in the given array if ($overwrite === true) { foreach ($collection as $collection_item) { $cid = $collection_item->get('id'); if (!is_null($cid) && !in_array($cid, $ids)) { $collection->removeElement($collection_item); $this->completeOwningSide($field, $target_class, $collection_item, true); $this->changed = true; } } } $this->{$field} = $collection; } } return; } if (property_exists($this, $field)) { // Otherwise, this is a normal property. Try and set it... if ($this->{$field} !== $value) { $this->{$field} = $value; $this->changed = true; } return; } else { if (($pos = strpos($field, '[')) !== false || ($pos = strpos($field, '.')) !== false) { // The property may be written in array syntax or dot notation. Try and decipher it... $field_name = substr($field, 0, $pos); $field_prop = substr(str_replace(array('[', ']'), array('.', ''), $field), $pos + 1); if (property_exists($this, $field_name)) { $field_val = $this->{$field_name}; if ($field_val instanceof Model) { $field_val->set($field_prop, $value); return; } if (!isset($this->{$field_name}) || !is_array($this->{$field_name})) { $this->{$field_name} = array(); } \Arr::set($this->{$field_name}, $field_prop, $value); return; } } } throw new \BadMethodCallException("no field with name '" . $field . "' exists on '" . $metadata->getName() . "'"); }
$arField = $_REQUEST; // Запишем массив для передачи в шаблонизатор Arr::set($arResult, 'arField', $arField); $isFieldExists = $main->db->getRow('SELECT id, code FROM ?n WHERE component_id = ?i AND id = ?i', PREFIX . '_components_fields_list', $arComponent['id'], $arField['id']); if ($isFieldExists['id']) { $main->db->query('DELETE FROM ?n WHERE component_id = ?i AND id = ?i', PREFIX . '_components_fields_list', $arComponent['id'], $isFieldExists['id']); } else { Arr::set($arResult, 'error', true); Arr::set($arResult, 'errors.code', 'Такого поля не существует в этом компоненте'); } } break; default: die('no action'); break; } // Добавляем все ключи массивов, возможных к выводу в шаблоне. $arKeys = []; foreach ($arResult as $key => $v) { $arKeys[] = $key; } Arr::set($arResult, 'arResultVars', $arKeys); unset($arKeys); // Результат обработки шаблона try { $main->tpl->display($currentTemplate . '.tpl', $arResult); } catch (Exception $e) { echo '<div style="color: red;">' . $e->getMessage() . '</div>'; } // Убираем сообщение из сессии. $main->clearMessage();
/** * Validates a credit card number. * * @param string $val Credit card number to validate. * @param string $type Credit card type (Visa, Discover, etc). * * @return bool */ public function _validation_creditcard($val, $type = null) { if ($this->_empty($val)) { return false; } // Remove all non-digit characters from the string. if (($val = preg_replace('/\\D+/', '', $val)) === '') { return false; } if ($type == null) { $type = $this->creditcard_type($val, 'key'); } elseif (is_array($type)) { foreach ($type as $t) { // Test each type for validity. if ($this->_validation_creditcard($val, $t)) { return true; } } return false; } Config::load('creditcards', true); $cards = Config::get('creditcards'); $type = strtolower($type); if (!isset($cards[$type])) { return false; } $length = strlen($val); // Validate card length by the card type. if (!in_array($length, preg_split('/\\D+/', $cards[$type]['length']))) { return false; } // Check card number prefix. if (!preg_match('/^' . $cards[$type]['prefix'] . '/', $val)) { return false; } // No Luhn check required. if ($cards[$type]['luhn'] == false) { return true; } // Add credit card type to the array of validated data. Arr::set($this->validated, 'account.provider', $this->creditcard_type($val, 'name')); return $this->luhn_check($val); }
/** * Run validation * * Performs validation with current fieldset and on given input, will try POST * when input wasn't given. * * @param array input that overwrites POST values * @param bool will skip validation of values it can't find or are null * @return bool whether validation succeeded */ public function run($input = null, $allow_partial = false, $temp_callables = array()) { if (is_null($input) and \Input::method() != 'POST') { return false; } // Backup current state of callables so they can be restored after adding temp callables $callable_backup = $this->callables; // Add temporary callables, reversed so first ends on top foreach (array_reverse($temp_callables) as $temp_callable) { $this->add_callable($temp_callable); } static::set_active($this); $this->validated = array(); $this->errors = array(); $this->input = $input ?: array(); $fields = $this->field(null, true); foreach ($fields as $field) { static::set_active_field($field); // convert form field array's to Fuel dotted notation $name = str_replace(array('[', ']'), array('.', ''), $field->name); $value = $this->input($name); if ($allow_partial === true and $value === null or is_array($allow_partial) and !in_array($field->name, $allow_partial)) { continue; } try { foreach ($field->rules as $rule) { $callback = $rule[0]; $params = $rule[1]; $this->_run_rule($callback, $value, $params, $field); } if (strpos($name, '.') !== false) { \Arr::set($this->validated, $name, $value); } else { $this->validated[$name] = $value; } } catch (Validation_Error $v) { $this->errors[$field->name] = $v; if ($field->fieldset()) { $field->fieldset()->Validation()->add_error($field->name, $v); } } } static::set_active(); static::set_active_field(); // Restore callables $this->callables = $callable_backup; return empty($this->errors); }
/** * Set a driver config setting. * * @param string $key the config key * @param mixed $value the new config value * @return object $this */ public function set_config($key, $value) { \Arr::set($this->config, $key, $value); return $this; }
<?php require_once 'bootstrap.php'; // simple email validation method function is_valid_email($mail) { return filter_var($mail, FILTER_VALIDATE_EMAIL) && !preg_match('/@\\[[^\\]]++\\]\\z/', $mail); } // convert Zenkaku to Hankaku $mail = mb_convert_kana(Arr::get($_POST, 'mail'), 'a', 'UTF-8'); Arr::set($_POST, 'mail', $mail); Session::write('posted', $_POST); $required = array('mail' => 'メールアドレスを入力してください'); $failed = array(); /** * validate missing input */ foreach ($required as $key => $errmsg) { $val = Arr::get($_POST, $key, ""); if ($val === "") { $failed[$key] = $errmsg; } } if (!isset($failed['mail']) and !is_valid_email($mail)) { $failed['mail'] = 'メールの形式に誤りがあるか、既に登録されています'; } /** メールの重複チェック. DB登録がある場合はコメントアウトして下さい. if (! isset($failed['mail'])) { $dbconn = Dbmanage::connect(); $dbtable = Dbmanage::$table; $stmt = $dbconn->prepare("SELECT id from {$dbtable} WHERE `mail` = :mail;");
/** * Generate the default data for the context object. * * @param bool $js Set this to generate the context for JS * * @return array The array to use for the "context" object */ private function _get_context($js = true) { $context_data = array('context' => array('locale' => $this->_get_locale(), 'timezone' => date('e'))); if ($js !== true) { $php_context = array('ip' => \Input::real_ip(), 'userAgent' => \Input::user_agent()); $context_data['context'] = \Arr::merge($context_data['context'], $php_context); // Don't use \Arr::set() since that will always add the keys. $context['campaign'] = $this->_add_element('name', \Input::get('utm_campaign'), array()); $context['campaign'] = $this->_add_element('source', \Input::get('utm_source'), $context['campaign']); $context['campaign'] = $this->_add_element('medium', \Input::get('utm_medium'), $context['campaign']); $context['campaign'] = $this->_add_element('term', \Input::get('utm_term'), $context['campaign']); $context['campaign'] = $this->_add_element('content', \Input::get('utm_content'), $context['campaign']); if (!empty($context['campaign'])) { $context_data['context'] = \Arr::merge($context_data['context'], $context); } // If we're using Google Analytics, we add it's ID. if (!empty($this->_ga_cookie_id)) { \Arr::set($context_data, 'integrations.Google Analytics.clientId', $this->_ga_cookie_id); } } return $context_data; }
/** * Set a value in the info array * * @return Theme */ public function set_info($var, $value = null, $type = 'active') { if ($type == 'active') { \Arr::set($this->active['info'], $var, $value); } elseif ($type == 'fallback') { \Arr::set($this->fallback['info'], $var, $value); } // return for chaining return $this; }
/** * 設定ファイルを読み込みます。 * * @param string $path 設定ファイルのパス * @param string|null $namespace 設定を読み込む空間名。 * 省略された時、ファイル名を名前空間として指定します。 * @param boolean|null $merge (optional) すでに名前空間に設定が読み込まれていた時、 * 既存の設定と上書き統合するか指定します。 * falseが指定され、名前空間競合が発生した時は、例外が投げられます。 * 初期値はtrueです。 */ public static function load($path, $namespace = null, $merge = true) { if (is_array($path)) { foreach ($path as $k => $v) { self::load($k, $v); } } if (file_exists($path) === false) { // 読み込み先ファイルが存在しなければエラー throw new OutOfBoundsException('設定ファイルが存在しません。(' . $path . ')'); } if (is_string($namespace) === false) { // 名前空間が指定されていなければ // ファイル名を取得する $namespace = pathinfo($path, PATHINFO_FILENAME); } // 設定ファイルを読み込み $conf = @(include $path); if ($conf !== false) { if (isset(self::$config[$namespace])) { if ($merge === true) { self::$config[$namespace] = array_merge_recursive(self::$config[$namespace], $conf); } else { throw new Exception('名前空間が競合しました: ' . $namespace); } } else { Arr::set(self::$config, $namespace, $conf); } } else { throw new Exception('設定ファイルが読み込めません。(' . $path . ')'); } }
/** * Set or replace a line in the language * * @param string key to the line * @param string value for the key * @param string group * @return void */ public static function set($line, $value, $group = null) { $key = ($group ? $group . '.' : '') . $line; \Arr::set(static::$lines, $key, $value); }
/** * Sets a (dot notated) config item * * @param * string a (dot notated) config key * @param * mixed the config value * @return void the \Arr::set result */ public static function set($item, $value) { strpos($item, '.') === false or static::$itemcache[$item] = $value; return \Arr::set(static::$items, $item, \Fuel::value($value)); }
}, 'forEach' => function ($fn, $context = null) { $self = Func::getContext(); $len = $self->length; for ($i = 0; $i < $len; $i++) { if ($self->hasOwnProperty($i)) { $fn->call($context, $self->get($i), (double) $i, $self); } } }, 'map' => function ($fn, $context = null) { $self = Func::getContext(); $results = new Arr(); $len = $results->length = $self->length; for ($i = 0; $i < $len; $i++) { if ($self->hasOwnProperty($i)) { $result = $fn->call($context, $self->get($i), (double) $i, $self); $results->set($i, $result); } } return $results; }, 'filter' => function ($fn, $context = null) { $self = Func::getContext(); $results = new Arr(); $len = $self->length; for ($i = 0; $i < $len; $i++) { if ($self->hasOwnProperty($i)) { $item = $self->get($i); $result = $fn->call($context, $item, (double) $i, $self); if (is($result)) { $results->push($item); } }
/** * Add an option value with label * * @param string|array one option value, or multiple value=>label pairs in an array * @param string * @return Fieldset_Field this, to allow chaining */ public function set_options($value, $label = null) { if (!is_array($value)) { \Arr::set($this->options, $value, $label); return $this; } $merge = function (&$array, $new, $merge) { foreach ($new as $k => $v) { if (isset($array[$k]) and is_array($array[$k]) and is_array($v)) { $merge($array[$k], $v); } else { $array[$k] = $v; } } }; empty($this->options) ? $this->options = $value : $merge($this->options, $value, $merge); return $this; }
/** * Update Current Page * * <code> * Pages::updateCurrentPage('title', 'My new Page Title'); * </code> * * @return array */ public static function updateCurrentPage($path, $value) { Arr::set(static::$current_page, $path, $value); }