本文整理汇总了PHP中Illuminate\Support\Arr::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::first方法的具体用法?PHP Arr::first怎么用?PHP Arr::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
/**
* search getter
*
* @param string $siteKey site key
* @param string $name the name
* @return ConfigEntity
*/
public function find($siteKey, $name)
{
$data = $this->getData($siteKey, $this->getHead($name));
return Arr::first($data, function ($idx, $item) use($name) {
return $item->name === $name;
});
}
示例2: handle
public function handle(Request $request, Closure $next)
{
$route = $request->route();
$parameters = $route->parameters();
$parameterKeys = array_keys($parameters);
// Look for parameters that match {*_morph_type} and {*_morph_id}
$morphTypeName = Arr::first($parameterKeys, function ($item) {
return ends_with($item, '_type');
});
$morphIdName = Arr::first($parameterKeys, function ($item) {
return ends_with($item, '_id');
});
if (!$morphTypeName or !$morphIdName) {
return $next($request);
}
$morphKey = preg_replace("/_type\$/", '', $morphTypeName);
if ($morphKey !== preg_replace("/_id\$/", '', $morphIdName)) {
return $next($request);
}
$morphTypeName = $morphKey . '_type';
$morphIdName = $morphKey . '_id';
$morphType = $parameters[$morphTypeName];
$morphId = $parameters[$morphIdName];
// Not going to worry about custom keys here.
$morphInstance = requireMorphInstance($morphType, $morphId);
$route->forgetParameter($morphTypeName);
$route->forgetParameter($morphIdName);
$route->setParameter($morphKey, $morphInstance);
return $next($request);
}
示例3: find
/**
* Find a model in the collection by key.
*
* @param mixed $key
* @param mixed $default
* @return \Illuminate\Database\Eloquent\Model
*/
public function find($key, $default = null)
{
if ($key instanceof Model) {
$key = $key->getKey();
}
return Arr::first($this->items, function ($model) use($key) {
return $model->getKey() == $key;
}, $default);
}
示例4: parseConditionalParameters
/**
* Parses the conditional parameter out of the action parameter. This is the parameter
* given to WordPress conditional functions later.
*
* @param array $action The action parameter where the conditional parameters are in
*
* @return array An array with the conditional parameters or null
*/
protected function parseConditionalParameters($action)
{
// Retrieve parameters. Accept only string or array.
// This help filter the $action parameters as it might also be a Closure.
$parameters = Arr::first($action, function ($value, $key) {
return is_string($value) || is_array($value);
});
if ($this->condition() && !is_null($parameters)) {
if (is_string($parameters) && strrpos($parameters, '@') !== false) {
/**
* In case of a controller value statement, return empty array.
*/
return [];
}
return is_array($parameters) ? $parameters : [$parameters];
}
return [];
}
示例5: getRelationForImagesWithResizesCaller
/**
* Get the relationship name of the image accessor for which images are enriched
*
* @return string
*/
protected function getRelationForImagesWithResizesCaller()
{
$self = __FUNCTION__;
$caller = Arr::first(debug_backtrace(false), function ($key, $trace) use($self) {
$caller = $trace['function'];
return !in_array($caller, ['getImagesWithResizes']) && $caller != $self;
});
if (is_null($caller)) {
return null;
}
// strip 'get' from front and 'attribute' from rear
return Str::camel(substr($caller['function'], 3, -9));
}
示例6: alreadyInParameters
/**
* Determine if an object of the given class is in a list of parameters.
*
* @param string $class
* @param array $parameters
* @return bool
*/
protected function alreadyInParameters($class, array $parameters)
{
return !is_null(Arr::first($parameters, function ($key, $value) use($class) {
return $value instanceof $class;
}));
}
示例7: findByName
/**
* Find a skill by its name
*
* @param $name
* @return \Burthorpe\Runescape\RS3\Skills\Contract|null
*/
public function findByName($name)
{
return Arr::first($this->items, function ($key, Contract $skill) use($name) {
return $skill->getName() === strtolower($name);
}, null);
}
示例8: getRouteMethod
private function getRouteMethod(Route $route)
{
$methods = $route->methods();
return Arr::first($methods);
}
示例9: getProvider
/**
* Get the registered service provider instance if it exists.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @return \Illuminate\Support\ServiceProvider|null
*/
public function getProvider($provider)
{
$name = is_string($provider) ? $provider : get_class($provider);
return Arr::first($this->serviceProviders, function ($value) use($name) {
return $value instanceof $name;
});
}
示例10: first
/**
* Get the first item from the collection.
*
* @param callable|null $callback
* @param mixed $default
* @return mixed
*/
public function first(callable $callback = null, $default = null)
{
if (is_null($callback)) {
return count($this->items) > 0 ? reset($this->items) : value($default);
}
return Arr::first($this->items, $callback, $default);
}
示例11: getExtension
/**
* Get the extension used by the view file.
*
* @param string $path
* @return string
*/
protected function getExtension($path)
{
$extensions = array_keys($this->extensions);
return Arr::first($extensions, function ($key, $value) use($path) {
return Str::endsWith($path, $value);
});
}
示例12: getEnvironmentArgument
/**
* Get the environment argument from the console.
*
* @param array $args
* @return string|null
*/
protected function getEnvironmentArgument(array $args)
{
return Arr::first($args, function ($k, $v) {
return starts_with($v, '--env');
});
}
示例13: buildMirrors
protected function buildMirrors($disks)
{
$main = $this->disk(Arr::first($disks))->getAdapter();
if (count($disks) > 2) {
$second = $this->buildMirrors(array_slice($disks, 1));
} else {
$second = $this->disk(Arr::last($disks))->getAdapter();
}
return new \League\Flysystem\Replicate\ReplicateAdapter(new \Litipk\Flysystem\Fallback\FallbackAdapter($main, $second, true), $second);
}
示例14: getGlobalScope
/**
* Get a global scope registered with the model.
*
* @param ScopeInterface $scope
* @return ScopeInterface|null
*/
public static function getGlobalScope($scope)
{
return Arr::first(static::$globalScopes[get_called_class()], function ($key, $value) use($scope) {
return $scope instanceof $value;
});
}
示例15: setContext
/**
* Set the active context(s).
*
* @param mixed $contexts
* @param bool $merge
*/
public function setContext($contexts, $merge = false)
{
$set = [];
if (is_object($contexts)) {
$contexts = [$contexts];
}
foreach ((array) $contexts as $context) {
if ($context instanceof AuthContext) {
$set[get_class($context)] = $context;
} elseif (is_string($context)) {
if (!class_exists($context)) {
$context = Arr::first($this->getRegisteredContexts(), function ($abstract, $concrete) use($context) {
return $abstract == $context || $concrete == $context;
});
}
$set[$context] = $this->loadContext($context);
}
}
$this->activeContexts = $merge ? array_merge($this->activeContexts, $set) : $set;
}