本文整理汇总了PHP中Illuminate\Support\Arr::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::set方法的具体用法?PHP Arr::set怎么用?PHP Arr::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleDotCase
protected function handleDotCase(&$array, $key, $value)
{
if (strpos($key, '.') !== false) {
unset($array[$key]);
Arr::set($array, $key, $value);
}
}
示例2: set
/**
* Set a given configuration value.
*
* @param array|string $key
* @param mixed $value
* @return void
*/
public function set($key, $value = null)
{
$keys = is_array($key) ? $key : [$key => $value];
foreach ($keys as $key => $value) {
Arr::set($this->items, $key, $value);
}
}
示例3: testPasswordResetUsingConfirmationCode
public function testPasswordResetUsingConfirmationCode()
{
if (!$this->serviceExists('mymail')) {
$emailService = \DreamFactory\Core\Models\Service::create(["name" => "mymail", "label" => "Test mail service", "description" => "Test mail service", "is_active" => true, "type" => "local_email", "mutable" => true, "deletable" => true, "config" => ["driver" => "sendmail", "command" => "/usr/sbin/sendmail -bs"]]);
$userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4);
$userConfig->password_email_service_id = $emailService->id;
$userConfig->save();
}
if (!\DreamFactory\Core\Models\EmailTemplate::whereName('mytemplate')->exists()) {
$template = \DreamFactory\Core\Models\EmailTemplate::create(['name' => 'mytemplate', 'description' => 'test', 'to' => $this->user2['email'], 'subject' => 'rest password test', 'body_text' => 'link {link}']);
$userConfig = \DreamFactory\Core\User\Models\UserConfig::find(4);
$userConfig->password_email_template_id = $template->id;
$userConfig->save();
}
Arr::set($this->user2, 'email', 'arif@dreamfactory.com');
$user = $this->createUser(2);
Config::set('mail.pretend', true);
$rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['reset' => 'true'], ['email' => $user['email']]);
$content = $rs->getContent();
$this->assertTrue($content['success']);
/** @var User $userModel */
$userModel = User::find($user['id']);
$code = $userModel->confirm_code;
$rs = $this->makeRequest(Verbs::POST, static::RESOURCE, ['login' => 'true'], ['email' => $user['email'], 'code' => $code, 'new_password' => '778877']);
$content = $rs->getContent();
$this->assertTrue($content['success']);
$this->assertTrue(Session::isAuthenticated());
$userModel = User::find($user['id']);
$this->assertEquals('y', $userModel->confirm_code);
$this->service = ServiceHandler::getService($this->serviceId);
$rs = $this->makeRequest(Verbs::POST, 'session', [], ['email' => $user['email'], 'password' => '778877']);
$content = $rs->getContent();
$this->assertTrue(!empty($content['session_id']));
}
示例4: setRequestInput
/**
* Replace a single item in a given Request’s input using dot-notation
* @param Request $request to modify
* @param string $key in dot-notation
* @param mixed $value to set
*/
protected function setRequestInput(Request $request, $key, $value)
{
if (strpos($key, '.')) {
// The data to set is deeper than 1 level down
// meaning the final value of the input's first level key is expected to be an array
list($first_level_key, $key_rest) = explode('.', $key, 2);
// Pull out the input's existing first level value to modify it as an array
$first_level_value = $request->input($first_level_key);
//Request::input() pulls from all input data using dot-notation (ArrayAccess on Request would also pull out files which is undesirable here).
if (!is_array($first_level_value)) {
$first_level_value = [];
}
Arr::set($first_level_value, $key_rest, $value);
} else {
// The data to set is in the first level
$first_level_key = $key;
$first_level_value = $value;
}
$request->merge([$first_level_key => $first_level_value]);
// The only current alternatives for modifying Request input data are merge() and replace(), the latter replacing the whole input data.
/*
* It could look tempting to skip all of the above code and just
* Arr::set() on the Request object utilizing it's ArrayAccess...
* But it doesn't work for the second- or higher dot-levels because of the
* non-reference return value of ArrayAccess::offsetGet()
*/
}
示例5: set
/**
* Update setting
*
* @param $key
* @param $value
* @return mixed
*/
public function set($key, $value)
{
$this->prepare();
if (!$this->has($key) || $this->get($key) != $value) {
$this->isDirty = true;
}
Arr::set($this->data, $key, $value);
}
示例6: htmlspecialchars
function traitAjax_response()
{
$data = ['vendor' => static::getVendor(), 'package' => static::getEntity()];
$ret = array_merge($data, $this->traitAjaxParams);
$message = Arr::get($ret, 'message');
$message = htmlspecialchars($message);
Arr::set($ret, 'message', $message);
return $ret;
}
示例7: set
/**
* Set a given configuration value.
*
* @param array|string $key
* @param mixed $value
* @return void
*/
public function set($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $innerKey => $innerValue) {
Arr::set($this->items, $innerKey, $innerValue);
}
} else {
Arr::set($this->items, $key, $value);
}
}
示例8: only
/**
* Get a subset of the items from the input data.
*
* @param array|mixed $keys
* @return array
*/
public function only($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = [];
$input = self::all();
foreach ($keys as $key) {
Arr::set($results, $key, Arr::get($input, $key));
}
return $results;
}
示例9: testPATCHPassword
public function testPATCHPassword()
{
$user = $this->createUser(1);
Arr::set($user, 'password', '1234');
$payload = json_encode($user, JSON_UNESCAPED_SLASHES);
$rs = $this->makeRequest(Verbs::PATCH, static::RESOURCE . '/' . $user['id'], [], $payload);
$content = $rs->getContent();
$this->assertFalse(Session::authenticate(['email' => $user['email'], 'password' => '1234']));
$this->assertTrue($this->adminCheck([$content]));
}
示例10: set
/**
* Set a value on the server.
*
* @param string|array $key
* @param mixed|null $value
*/
public function set($key, $value = null)
{
// Set the value on the contents
$contents = (array) $this->getContents();
if (is_array($key)) {
$contents = $key;
} else {
Arr::set($contents, $key, $value);
}
$this->saveContents($contents);
}
示例11: getClean
function getClean()
{
$ret = $this->data;
foreach ($this->filters as $field => $filters) {
foreach ($filters as $filter) {
$filtered = call_user_func($filter, Arr::get($ret, $field));
Arr::set($ret, $field, $filtered);
}
}
return $ret;
}
示例12: map
public function map($data)
{
foreach ($data as &$item) {
$value = Arr::get($item, $this->name);
if ($this->hasValueWrapper()) {
$value = call_user_func($this->valueWrapper, $value);
Arr::set($item, $this->name, $value);
}
}
return $data;
}
示例13: createIndex
/**
* Create a new search index.
*
* @param string|null $index
* @param array|null $settings
* @param array|null $mappings
* @return array
*/
public function createIndex($index = null, array $settings = null, array $mappings = null)
{
$indexName = $index ?: $this->getDefaultIndex();
$params = ['index' => $indexName];
if (!empty($settings)) {
Arr::set($params, 'body.settings', $settings);
}
if (!empty($mappings)) {
Arr::set($params, 'body.mappings', $mappings);
}
return $this->client->indices()->create($params);
}
示例14: register
static function register($code, $name, $aliases = [])
{
self::$roles[$code] = $name;
ksort(self::$roles);
$aliases = (array) $aliases;
foreach ($aliases as $alias) {
self::$aliases[$alias] = $code;
}
$code = str_replace('.', '.items.', $code);
Arr::set(self::$tree, $code . '.name', $name);
Arr::set(self::$tree, $code . '.code', $code);
}
示例15: reqOnlyIfExists
function reqOnlyIfExists($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = [];
$input = request()->all();
foreach ($keys as $key) {
if (request()->exists($key)) {
Arr::set($results, $key, Arr::get($input, $key));
}
}
return $results;
}