本文整理汇总了PHP中array_set函数的典型用法代码示例。如果您正苦于以下问题:PHP array_set函数的具体用法?PHP array_set怎么用?PHP array_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save($item, $value, $environment, $group, $namespace = null)
{
$path = DIR_APPLICATION . '/config/generated_overrides';
if (!$this->files->exists($path)) {
$this->files->makeDirectory($path, 0777);
} elseif (!$this->files->isDirectory($path)) {
$this->files->delete($path);
$this->files->makeDirectory($path, 0777);
}
if ($namespace) {
$path = "{$path}/{$namespace}";
if (!$this->files->exists($path)) {
$this->files->makeDirectory($path, 0777);
} elseif (!$this->files->isDirectory($path)) {
$this->files->delete($path);
$this->files->makeDirectory($path, 0777);
}
}
$file = "{$path}/{$group}.php";
$current = array();
if ($this->files->exists($file)) {
$current = $this->files->getRequire($file);
}
array_set($current, $item, $value);
$renderer = new Renderer($current);
return $this->files->put($file, $renderer->render()) !== false;
}
示例2: __set
/**
* Magic Method allows for user input to set a value inside the options array.
*
* @param $option
* @param $value
*
* @throws InvalidPrice
* @throws InvalidQuantity
* @throws InvalidTaxableValue
*/
public function __set($option, $value)
{
switch ($option) {
case CartItem::ITEM_QTY:
if (!is_numeric($value) || $value < 0) {
throw new InvalidQuantity('The quantity must be a valid number');
}
break;
case CartItem::ITEM_PRICE:
if (!is_numeric($value)) {
throw new InvalidPrice('The price must be a valid number');
}
break;
case CartItem::ITEM_TAX:
if (!empty($value) && (!is_numeric($value) || $value > 1)) {
throw new InvalidTaxableValue('The tax must be a float less than 1');
}
break;
case CartItem::ITEM_TAXABLE:
if (!is_bool($value) && $value != 0 && $value != 1) {
throw new InvalidTaxableValue('The taxable option must be a boolean');
}
break;
}
array_set($this->options, $option, $value);
if (is_callable([$this, 'generateHash'])) {
$this->generateHash();
}
}
示例3: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$input = $request->all();
array_set($input, 'match.id', $request->route('matchId'));
$request->replace($input);
return $next($request);
}
示例4: set
public static function set($identifier, $value)
{
$key = $identifier;
// Initiates everything
static::load();
array_set($key, static::$stack);
}
示例5: checkout
public function checkout($attributes)
{
return DB::transaction(function ($attributes) use($attributes) {
$shipping_address_same_as_billing_address = array_get($attributes, 'shipping_address_same_as_billing_address', false);
if ($shipping_address_same_as_billing_address) {
array_set($attributes, 'shipping_address_first_name', array_get($attributes, 'billing_address_first_name'));
array_set($attributes, 'shipping_address_last_name', array_get($attributes, 'billing_address_last_name'));
array_set($attributes, 'shipping_address_company', array_get($attributes, 'billing_address_company'));
array_set($attributes, 'shipping_address_address_1', array_get($attributes, 'billing_address_address_1'));
array_set($attributes, 'shipping_address_address_2', array_get($attributes, 'billing_address_address_2'));
array_set($attributes, 'shipping_address_city', array_get($attributes, 'billing_address_city'));
array_set($attributes, 'shipping_address_postal_code', array_get($attributes, 'billing_address_postal_code'));
array_set($attributes, 'shipping_address_country_id', array_get($attributes, 'billing_address_country_id'));
array_set($attributes, 'shipping_address_zone_id', array_get($attributes, 'billing_address_zone_id'));
}
$order = $this->create($attributes);
//add line items
$line_items = [];
foreach (array_get($attributes, 'line_items', []) as $line_item) {
$line_items[] = new LineItem($line_item);
}
$order->lineItems()->saveMany($line_items);
//add totals
$totals = [];
foreach (array_get($attributes, 'totals', []) as $total) {
$totals[] = new OrderTotal($total);
}
$order->totals()->saveMany($totals);
return $order;
});
}
示例6: fixRequestForArrayFields
protected function fixRequestForArrayFields(SS_HTTPRequest $request)
{
$postVars = $request->postVars();
$fileVars = array_intersect_key($postVars, $_FILES);
$fieldName = $this->owner->Name;
foreach ($fileVars as $name => $attributes) {
$nameParts = explode('][', trim(substr($fieldName, strlen($name) + 1), ']'));
$newAttributes = [];
$newValue = [];
$values = null;
foreach ($attributes as $attributeName => $attributeValues) {
$values = array_get($attributeValues, implode('.', $nameParts));
if (!$values || is_array($values) && empty($values)) {
break;
}
array_set($newAttributes, implode('.', $nameParts) . '.' . $attributeName, $values);
$newValue[$attributeName] = $values;
}
if (!$values) {
continue;
}
$postVars[$name] = $newAttributes;
$postVars[$fieldName] = $newValue;
}
return new SS_HTTPRequest($request->httpMethod(), $request->getURL(true), $request->getVars(), $postVars, $request->getBody());
}
示例7: set
/**
* Set a configuration item's value.
*
* <code>
* // Set the "session" configuration array
* Config::set('session', $array);
*
* // Set a configuration option that belongs by a bundle
* Config::set('admin::names.first', 'Taylor');
*
* // Set the "timezone" option in the "application" configuration file
* Config::set('application.timezone', 'UTC');
* </code>
*
* @param string $key
* @param mixed $value
* @return void
*/
public static function set($key, $value, $persistence = true)
{
list($bundle, $file, $item) = static::parse($key);
static::load($bundle, $file);
// If the item is null, it means the developer wishes to set the entire
// configuration array to a given value, so we will pass the entire
// array for the bundle into the array_set method.
if (is_null($item)) {
// @TODO handle saving of
// nested array configuration
array_set(static::$items[$bundle], $file, $value);
} else {
if ($persistence) {
$setting = Model\Setting::where_slug($item)->first();
if (!empty($setting)) {
array_set(static::$items[$bundle][$file], $item, $value);
$setting->value = $value;
$setting->save();
} else {
\Log::error('"' . __CLASS__ . '": Trying to persist a non existent setting "' . $item . '".');
return null;
}
} else {
array_set(static::$items[$bundle][$file], $item, $value);
}
}
}
示例8: create
/**
* Create's an application form.
*
* @param User $user
* @param array $attributes
* @return mixed
*/
public function create(User $user, $attributes = array())
{
array_set($attributes, 'user_id', $user->id);
$application = Application::create($attributes);
Event::fire(new ApplicationSubmittedEvent($application));
return $application;
}
示例9: fixTrackingCode
protected function fixTrackingCode()
{
$this->output(t('Updating tracking code.'));
$service = \Core::make('site');
$site = $service->getDefault();
$config = $site->getConfigRepository();
$proceed = true;
$tracking = $config->get('seo.tracking');
if (is_array($tracking) && isset($tracking['header']) && $tracking['header']) {
$proceed = false;
}
if (is_array($tracking) && isset($tracking['footer']) && $tracking['footer']) {
$proceed = false;
}
if ($proceed) {
// we saved it in the wrong place on the 8.0 upgrade.
$tracking = (array) \Config::get('concrete.seo.tracking', []);
$trackingCode = array_get($tracking, 'code');
if (!is_array($trackingCode)) {
array_set($tracking, 'code', ['header' => '', 'footer' => '']);
$trackingCode = (string) $trackingCode;
switch (array_get($tracking, 'code_position')) {
case 'top':
array_set($tracking, 'code.header', $trackingCode);
break;
case 'bottom':
default:
array_set($tracking, 'code.footer', $trackingCode);
break;
}
}
unset($tracking['code_position']);
$config->save('seo.tracking', $tracking);
}
}
示例10: getPreJson
/**
* @return Array
*/
public function getPreJson()
{
$result = [];
$group = '';
$g = 0;
foreach ($this->stack as $item) {
switch ($item['style']) {
case 'group':
$name = 'group_' . $item['name'];
$group = $group == '' ? $name : $group . '.' . $name;
array_set($result, $group . '._time', $item['time']);
break;
case 'groupend':
$group = substr($group, 0, strrpos($group, '.'));
break;
default:
$keyName = $group == '' ? '' : $group . '.';
$name = $item['name'] ? $item['name'] : 'nn_' . ++$g;
$keyName .= str_slug($item['style'] . '_' . $name, '_');
if (isset($item['value'])) {
array_set($result, $keyName, $item['value']);
}
break;
}
}
return $result;
}
示例11: appendFields
private function appendFields($form, $inputs, $values)
{
foreach ($inputs as $name => $arg) {
preg_match("/^([^[]+)\\[(.+)\\]\$/", $name, $m);
if (!empty($m)) {
$seq = (int) $m[2];
$value = array_get($values, "{$m['1']}.{$seq}");
$name = $m[1] . '[]';
} else {
$value = array_get($values, $name);
}
$arg['name'] = $name;
$type = array_get($arg, '_type');
unset($arg['_type']);
array_set($arg, 'value', $value);
$uio = 'form' . ucfirst($type);
$input = uio($uio, $arg);
$field = $this->wrapInput($name, $input);
$sectionName = array_get($arg, '_section');
unset($arg['_section']);
$style = array_get($this->arguments, 'type', 'panel');
$section = $this->getSection($form, $sectionName, $style);
$field->appendTo($section);
}
}
示例12: beforeOrAfterDotNotation
protected static function beforeOrAfterDotNotation(&$array, $key, $value, $keyNeighbor = null, $after = false)
{
if (is_null($keyNeighbor)) {
return $after ? static::set($array, $key, $value) : static::prepend($array, $value, $key);
}
$segments = explode('.', $keyNeighbor);
$keyNeighborLast = array_pop($segments);
if (count($segments) > 0) {
$leveledKey = implode('.', $segments);
$leveledArray = array_get($array, $leveledKey);
if (!is_array($leveledArray)) {
return $array;
}
} else {
$leveledKey = null;
$leveledArray =& $array;
}
$keyNeighborIndex = array_search($keyNeighborLast, array_keys($leveledArray));
if ($keyNeighborIndex !== false) {
if (isset($leveledArray[$key])) {
unset($leveledArray[$key]);
}
$leveledArray = array_slice($leveledArray, 0, $keyNeighborIndex + ($after ? 1 : 0)) + [$key => $value] + array_slice($leveledArray, $keyNeighborIndex);
} else {
array_set($leveledArray, $key, $value);
}
return array_set($array, $leveledKey, $leveledArray);
}
示例13: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->config = $this->getConfig();
$opts = $this->option();
if ($opts['forget']) {
if (isset(array_dot($this->config)[$opts['forget']])) {
$keys = explode('.', $opts['forget']);
array_forget($this->config, $opts['forget']);
if (empty($this->config[$keys[0]])) {
DB::table('config')->where('name', $keys[0])->delete();
} else {
DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]);
}
$this->info($opts['forget'] . ' removed.');
}
return $this->showList();
}
if ($opts['key'] && $opts['value']) {
$value = trim($opts['value']);
if (in_array($value, ['true', 'false', '0', '1'])) {
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
$old_config = $this->config;
array_set($this->config, $opts['key'], $value);
$keys = explode('.', $opts['key']);
if (isset($old_config[$keys[0]])) {
//update
DB::table('config')->where('name', $keys[0])->update(['value' => serialize($this->config[$keys[0]])]);
} else {
//insert
DB::table('config')->insert(['name' => $keys[0], 'value' => serialize($this->config[$keys[0]])]);
}
}
return $this->showList();
}
示例14: send
/**
* @param null $connection
* @return bool
* @throws \Exception
*/
public function send($connection = null)
{
$notifiers = Config::get('notifiers');
if (!is_null($connection) && array_has($notifiers, $connection)) {
$notifiers = array_only($notifiers, [$connection]);
}
$factory = new NotifyMeFactory();
$successes = 0;
foreach ($notifiers as $notifier) {
if ($this->sender) {
array_set($notifier, 'from', $this->sender);
}
$service = $factory->make($notifier);
switch (array_get($notifier, 'driver')) {
case 'hipchat':
$response = $service->notify(array_get($notifier, 'room'), $this->message);
break;
default:
throw new \Exception("Driver not yet supported.");
}
if ($response->isSent()) {
$successes++;
} else {
throw new \Exception($response->message());
}
}
return $successes == count($notifiers);
}
示例15: array_add
/**
* Add an element to an array using "dot" notation if it doesn't exist.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*/
function array_add($array, $key, $value)
{
if (is_null(array_get($array, $key))) {
array_set($array, $key, $value);
}
return $array;
}