本文整理汇总了PHP中Illuminate\Support\Arr::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::exists方法的具体用法?PHP Arr::exists怎么用?PHP Arr::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::exists方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explode
/**
* Get an item from an array or object using "dot" notation.
*
* @param mixed $target
* @param string|array $key
* @param mixed $default
* @return mixed
*/
function data_get($target, $key, $default = null)
{
if (is_null($key)) {
return $target;
}
$key = is_array($key) ? $key : explode('.', $key);
while (($segment = array_shift($key)) !== null) {
if ($segment === '*') {
if ($target instanceof Collection) {
$target = $target->all();
} elseif (!is_array($target)) {
return value($default);
}
$result = Arr::pluck($target, $key);
return in_array('*', $key) ? Arr::collapse($result) : $result;
}
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
$target = $target[$segment];
} elseif (is_object($target) && isset($target->{$segment})) {
$target = $target->{$segment};
} else {
return value($default);
}
}
return $target;
}
示例2: locale
public function locale($lang, Request $request)
{
if (Arr::exists(config('locales'), $lang)) {
Session::set('locale', $lang);
}
if (isset($_SERVER['HTTP_REFERER'])) {
return redirect('/')->setTargetUrl($_SERVER['HTTP_REFERER'])->withCookie('locale', $lang);
} else {
return redirect('/')->withCookie('locale', $lang);
}
}
示例3: handle
public function handle($request, \Closure $next)
{
// Load from cookie
if (Cookie::has('locale')) {
session(['locale' => Cookie::get('locale')]);
}
if (Session::has('locale') && Arr::exists(config('locales'), session('locale'))) {
// Set app locale dynamically
App::setLocale(session('locale'));
}
return $next($request);
}
示例4: find
/**
* Find a handler for manage a request
*
* @param string $method
* @param string $path
* @return null|callable
*/
public function find($method, $path)
{
$method = Str::upper($method);
$handlers = $this->handlers[$method];
if (Arr::exists($handlers, $path)) {
return $handlers[$path];
}
foreach ($handlers as $regexPath => $handler) {
if (preg_match('@^' . $regexPath . '$@', $path)) {
return $handler;
}
}
}
示例5: __callStatic
public static function __callStatic($name, $attributes)
{
if (Str::startsWith('get', $name)) {
$method = Str::camel($name);
if (method_exists(new static(), $method)) {
$class = static::class;
if (Arr::exists($attributes, 0)) {
return $class::$method($attributes[0]);
}
return $class::$method();
}
}
return env(Str::upper(Str::snake(Str::substr($name, 3))));
}
示例6: rollback
/**
* Rollback the last migration operation.
*
* @param array|string $paths
* @param array $options
*
* @return array
*/
public function rollback($paths = [], array $options = [])
{
$this->notes = [];
$rolledBack = [];
$migrations = $this->getRanMigrations();
$files = $this->getMigrationFiles($paths);
$count = count($migrations);
if ($count === 0) {
$this->note('<info>Nothing to rollback.</info>');
} else {
$this->requireFiles($files);
$steps = Arr::get($options, 'step', 0);
if ($steps == 0) {
$steps = 1;
}
$lastBatch = $this->repository->getLastBatchNumber();
$stepDown = false;
foreach ($migrations as $migration) {
$migration = (object) $migration;
if ($lastBatch > $migration->batch && $stepDown) {
$steps--;
$stepDown = false;
$lastBatch = $migration->batch;
}
if ($steps <= 0) {
break;
}
if (Arr::exists($files, $migration->migration)) {
$rolledBack[] = $files[$migration->migration];
$stepDown = true;
$this->runDown($files[$migration->migration], $migration, Arr::get($options, 'pretend', false));
}
}
}
return $rolledBack;
}
示例7: explode
/**
* Set an item on an array or object using dot notation.
*
* @param mixed $target
* @param string|array $key
* @param mixed $value
* @param bool $overwrite
* @return mixed
*/
function data_set(&$target, $key, $value, $overwrite = true)
{
$segments = is_array($key) ? $key : explode('.', $key);
if (($segment = array_shift($segments)) === '*') {
if (!Arr::accessible($target)) {
$target = [];
}
if ($segments) {
foreach ($target as &$inner) {
data_set($inner, $segments, $value, $overwrite);
}
} elseif ($overwrite) {
foreach ($target as &$inner) {
$inner = $value;
}
}
} elseif (Arr::accessible($target)) {
if ($segments) {
if (!Arr::exists($target, $segment)) {
$target[$segment] = [];
}
data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite || !Arr::exists($target, $segment)) {
$target[$segment] = $value;
}
} elseif (is_object($target)) {
if ($segments) {
if (!isset($target->{$segment})) {
$target->{$segment} = [];
}
data_set($target->{$segment}, $segments, $value, $overwrite);
} elseif ($overwrite || !isset($target->{$segment})) {
$target->{$segment} = $value;
}
} else {
$target = [];
if ($segments) {
data_set($target[$segment], $segments, $value, $overwrite);
} elseif ($overwrite) {
$target[$segment] = $value;
}
}
return $target;
}
示例8: exists
/**
* {@inheritdoc}
*/
public function exists($key)
{
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $value) {
if (!Arr::exists($this->attributes, $value)) {
return false;
}
}
return true;
}