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


PHP Support\Arr类代码示例

本文整理汇总了PHP中Illuminate\Support\Arr的典型用法代码示例。如果您正苦于以下问题:PHP Arr类的具体用法?PHP Arr怎么用?PHP Arr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Arr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getRules

 /**
  * @return array
  */
 public static function getRules($scene = 'saving')
 {
     $rules = [];
     array_walk(static::$_rules, function ($v, $k) use(&$rules, $scene) {
         $rules[$k] = [];
         array_walk($v, function ($vv, $kk) use(&$rules, $scene, $k) {
             if (isset($v['on'])) {
                 $scenes = explode(',', $vv['on']);
                 $rule = Arr::get($vv, 'rule', false);
                 if ($rule && in_array($scene, $scenes)) {
                     $rules[$k][] = $rule;
                 }
             } else {
                 if ($scene == 'saving') {
                     $rule = Arr::get($vv, 'rule', false);
                     if ($rule) {
                         $rules[$k][] = $rule;
                     }
                 }
             }
         });
         if (empty($rules[$k])) {
             unset($rules[$k]);
         } else {
             $rules[$k] = implode('|', $rules[$k]);
         }
     });
     return $rules;
 }
开发者ID:tsotsi,项目名称:model-validate,代码行数:32,代码来源:ValidateModel.php

示例2: migrate

 /**
  * Run migrations for the specified module.
  *
  * @param  string $slug
  * @return mixed
  */
 protected function migrate($slug)
 {
     if ($this->module->exists($slug)) {
         $pretend = Arr::get($this->option(), 'pretend', false);
         $options = ['pretend' => $pretend];
         $path = $this->getMigrationPath($slug);
         $this->migrator->run($path, $options);
         // Once the migrator has run we will grab the note output and send it out to
         // the console screen, since the migrator itself functions without having
         // any instances of the OutputInterface contract passed into the class.
         foreach ($this->migrator->getNotes() as $note) {
             if (!$this->option('quiet')) {
                 $this->line($note);
             }
         }
         // Finally, if the "seed" option has been given, we will re-run the database
         // seed task to re-populate the database, which is convenient when adding
         // a migration and a seed at the same time, as it is only this command.
         if ($this->option('seed')) {
             $this->call('module:seed', ['module' => $slug, '--force' => true]);
         }
     } else {
         return $this->error("Module does not exist.");
     }
 }
开发者ID:rikardote,项目名称:portal,代码行数:31,代码来源:ModuleMigrateCommand.php

示例3: create

 /**
  * Create a new menu.
  *
  * @return $this
  */
 public function create()
 {
     $menu = $this->handler->add($this->name, $this->getAttribute('position'))->title($this->getAttribute('title'))->link($this->getAttribute('link'))->handles(Arr::get($this->menu, 'link'));
     $this->attachIcon($menu);
     $this->handleNestedMenu();
     return $this;
 }
开发者ID:quetzyg,项目名称:foundation,代码行数:12,代码来源:MenuHandler.php

示例4: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $referer = $request->server->get('referer');
     // Referer is not provided, we continue
     if (is_null($referer) or env('APP_ENV', 'production') !== 'production') {
         return $next($request);
     }
     // Handle the dictionnary.
     // @todo Refactor that
     $dir = realpath(dirname(__FILE__) . '/../../../../../') . '/';
     $path = $dir . 'spammers.json';
     $file = file_get_contents($path);
     // Dictionnary is not readable, abort.
     if (empty($file)) {
         abort(500, 'Unable to read spammers.json');
     }
     $dictionary = json_decode($file);
     // Parse the referer
     $url = new Parser(new PublicSuffixList([]));
     $host = $url->parseHost($referer)->host;
     // Compare dictionary against the referer...
     $search = Arr::where($dictionary, function ($key, $value) use($host) {
         return mb_stripos($host, $value) !== false;
     });
     // ...and check for results
     if (count($search) > 0) {
         abort(500, 'Spammers protection');
     }
     // No spam, we can continue :)
     return $next($request);
 }
开发者ID:akibatech,项目名称:analytics-spammers,代码行数:38,代码来源:CheckForSpammers.php

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

示例6: getConnector

 public function getConnector()
 {
     $options = Arr::get($this->config, 'options', []);
     $user = $this->request->user();
     $accessControl = Arr::get($this->config, 'accessControl');
     $roots = Arr::get($options, 'roots', []);
     foreach ($roots as $key => $disk) {
         $disk['driver'] = empty($disk['driver']) === true ? 'LocalFileSystem' : $disk['driver'];
         $disk['autoload'] = true;
         if (empty($disk['path']) === false && $disk['path'] instanceof Closure === true) {
             $disk['path'] = call_user_func($disk['path']);
         }
         switch ($disk['driver']) {
             case 'LocalFileSystem':
                 if (strpos($disk['path'], '{user_id}') !== -1 && is_null($user) === true) {
                     continue;
                 }
                 $userId = $user->id;
                 $disk['path'] = str_replace('{user_id}', $userId, $disk['path']);
                 $disk['URL'] = $this->urlGenerator->to(str_replace('{user_id}', $userId, $disk['URL']));
                 if ($this->filesystem->exists($disk['path']) === false) {
                     $this->filesystem->makeDirectory($disk['path'], 0755, true);
                 }
                 $disk = array_merge(['mimeDetect' => 'internal', 'utf8fix' => true, 'tmbCrop' => false, 'tmbBgColor' => 'transparent', 'accessControl' => $accessControl], $disk);
                 break;
         }
         $roots[$key] = $disk;
     }
     $options = array_merge($options, ['roots' => $roots, 'session' => $this->session]);
     return new Connector(new BaseElfinder($options));
 }
开发者ID:recca0120,项目名称:elfinder,代码行数:31,代码来源:Elfinder.php

示例7: handleDotCase

 protected function handleDotCase(&$array, $key, $value)
 {
     if (strpos($key, '.') !== false) {
         unset($array[$key]);
         Arr::set($array, $key, $value);
     }
 }
开发者ID:spira,项目名称:api-core,代码行数:7,代码来源:ValidationExceptionTransformer.php

示例8: 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;
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:34,代码来源:helpers.php

示例9: 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

示例10: replaceNamedParameters

 /**
  * Replace all of the named parameters in the path.
  *
  * @param  string $path
  * @param  array  $parameters
  *
  * @return string
  */
 protected function replaceNamedParameters($path, &$parameters)
 {
     $this->ensureTenancyInParameters($path, $parameters);
     return preg_replace_callback('/\\{(.*?)\\??\\}/', function ($m) use(&$parameters) {
         return isset($parameters[$m[1]]) ? Arr::pull($parameters, $m[1]) : $m[0];
     }, $path);
 }
开发者ID:illuminate3,项目名称:laravel-doctrine-tenancy,代码行数:15,代码来源:UrlGenerator.php

示例11: denormalize

 static function denormalize($phone)
 {
     $p = self::normalize($phone);
     $length = mb_strlen($p);
     if (6 == $length) {
         $p = '83522' . $p;
         $length = mb_strlen($p);
     }
     $config = \Config::get('larakit::phones.' . $length, []);
     if (!count($config)) {
         return $p;
     }
     $codes = array_keys($config);
     rsort($codes);
     foreach ($codes as $code) {
         if ($code == mb_substr($p, 0, mb_strlen($code))) {
             $mask = Arr::get($config, $code . '.mask');
             $phone_array = str_split(mb_substr($p, mb_strlen($code)));
             $mask_array = str_split($mask);
             foreach ($mask_array as $key => $symbol) {
                 if ('#' == $symbol) {
                     $mask_array[$key] = array_shift($phone_array);
                 }
             }
             return implode('', $mask_array);
         }
     }
     return null;
 }
开发者ID:larakit,项目名称:lk,代码行数:29,代码来源:HelperPhone.php

示例12: updateDoc

 /**
  * Update documentation.
  *
  * @param  string $doc
  * @param  string $version
  * @return void
  */
 protected function updateDoc($doc, $version = null)
 {
     $path = config('docs.path');
     if (!($data = Arr::get($this->docs->getDocs(), $doc))) {
         return;
     }
     if (!$this->files->exists("{$path}/{$doc}")) {
         $this->git->clone($data['repository'], "{$path}/{$doc}");
     }
     $this->git->setRepository("{$path}/{$doc}");
     $this->git->checkout('master');
     $this->git->pull('origin');
     if ($version) {
         $versions = [$version];
     } else {
         $versions = $this->getVersions();
     }
     foreach ($versions as $version) {
         $this->git->checkout($version);
         $this->git->pull('origin', $version);
         $this->git->checkout($version);
         $storagePath = storage_path("docs/{$doc}/{$version}");
         $this->files->copyDirectory("{$path}/{$doc}", $storagePath);
         $this->docs->clearCache($doc, $version);
     }
 }
开发者ID:hazzardweb,项目名称:docs.hazzardweb.com,代码行数:33,代码来源:UpdateDocs.php

示例13: onDeletedResource

 public static final function onDeletedResource($response)
 {
     $data = (array) json_decode($response->getBody(), true);
     Arr::forget($data, ['code', 'message']);
     $data = json_encode($data);
     return $response->withBody(Psr7\stream_for($data));
 }
开发者ID:loduis,项目名称:alegra-php,代码行数:7,代码来源:Resource.php

示例14: getHistory

 /**
  * Get the class's history.
  *
  * @param string|null $type
  *
  * @return array
  */
 public function getHistory($type = null)
 {
     $handle = $this->getHistoryHandle();
     $history = $this->history[$handle];
     $history = Arr::get($history, $type);
     return $history;
 }
开发者ID:marcelgwerder,项目名称:rocketeer,代码行数:14,代码来源:HasHistory.php

示例15: getRecipePath

 /**
  * Get recipe files location
  *
  * @return string
  */
 public function getRecipePath()
 {
     $directory = $this->getDirectoryPath();
     $content = $this->filesystem->get($directory . '/' . self::CONFIGFILE);
     $contentArr = json_decode($content, true);
     return Arr::get($contentArr, 'recipe_path', null);
 }
开发者ID:elepunk,项目名称:oven,代码行数:12,代码来源:Configurator.php


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