当前位置: 首页>>代码示例>>PHP>>正文


PHP Arr::first方法代码示例

本文整理汇总了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;
     });
 }
开发者ID:xpressengine,项目名称:xpressengine,代码行数:14,代码来源:CacheDecorator.php

示例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);
 }
开发者ID:gez-studio,项目名称:gez-mall,代码行数:30,代码来源:SubstituteMorphBindings.php

示例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);
 }
开发者ID:bryanashley,项目名称:framework,代码行数:16,代码来源:Collection.php

示例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 [];
 }
开发者ID:themosis,项目名称:framework,代码行数:26,代码来源:Route.php

示例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));
 }
开发者ID:czim,项目名称:aalberts-pxlcms,代码行数:18,代码来源:CmsModel.php

示例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;
     }));
 }
开发者ID:RJacksonm1,项目名称:laravel-framework-for-54,代码行数:13,代码来源:RouteDependencyResolverTrait.php

示例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);
 }
开发者ID:burthorpe,项目名称:runescape-api,代码行数:12,代码来源:Repository.php

示例8: getRouteMethod

 private function getRouteMethod(Route $route)
 {
     $methods = $route->methods();
     return Arr::first($methods);
 }
开发者ID:gez-studio,项目名称:gez-mall,代码行数:5,代码来源:RequestTestCase.php

示例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;
     });
 }
开发者ID:GinoPane,项目名称:framework,代码行数:13,代码来源:Application.php

示例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);
 }
开发者ID:jeandrocouto,项目名称:warmupdelivery,代码行数:14,代码来源:Collection.php

示例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);
     });
 }
开发者ID:nix9,项目名称:laracasts,代码行数:13,代码来源:Factory.php

示例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');
     });
 }
开发者ID:liubo2055,项目名称:test-lazada,代码行数:12,代码来源:EnvironmentDetector.php

示例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);
 }
开发者ID:danhunsaker,项目名称:laravel-flysystem-others,代码行数:10,代码来源:FlysystemOtherManager.php

示例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;
     });
 }
开发者ID:phonedotcom,项目名称:sdk-php,代码行数:12,代码来源:Model.php

示例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;
 }
开发者ID:propaganistas,项目名称:laravel-auth-context,代码行数:26,代码来源:AuthContextManager.php


注:本文中的Illuminate\Support\Arr::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。