• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Support\Arr类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: createClusters

 /**
  * Create multiple clusters (aggregate clients).
  *
  * @param  array  $clusters
  * @param  array  $options
  * @return void
  */
 protected function createClusters(array $clusters, array $options = [])
 {
     $options = array_merge($options, (array) Arr::pull($clusters, 'options'));
     foreach ($clusters as $name => $servers) {
         $this->clients += $this->createAggregateClient($name, $servers, array_merge($options, (array) Arr::pull($servers, 'options')));
     }
 }
开发者ID:jarnovanleeuwen,项目名称:framework,代码行数:14,代码来源:PredisDatabase.php


示例17: createConnection

 /**
  * Create a new PDO connection.
  *
  * @param  string $dsn
  * @param  array $config
  * @param  array $options
  * @return PDO
  * @throws Exception
  */
 public function createConnection($dsn, array $config, array $options)
 {
     $username = Arr::get($config, 'username');
     $password = Arr::get($config, 'password');
     $create_pdo = function ($dsn, $username, $password, $options) {
         try {
             $pdo = new PDO($dsn, $username, $password, $options);
         } catch (Exception $e) {
             $pdo = $this->tryAgainIfCausedByLostConnection($e, $dsn, $username, $password, $options);
         }
         $this->isClusterNodeReady($pdo);
         return $pdo;
     };
     if (is_array($dsn)) {
         foreach ($dsn as $idx => $dsn_string) {
             try {
                 return $create_pdo($dsn_string, $username, $password, $options);
             } catch (Exception $e) {
                 if (!$this->causedByLostConnection($e) || $idx >= count($dsn) - 1) {
                     throw $e;
                 }
             }
         }
     }
     return $create_pdo($dsn, $username, $password, $options);
 }
开发者ID:Rolice,项目名称:reconnector,代码行数:35,代码来源:MySqlConnector.php


示例18: migrate

 /**
  * Run migrations for the specified module.
  *
  * @param string $slug
  *
  * @return mixed
  */
 protected function migrate($slug = null)
 {
     $pretend = Arr::get($this->option(), 'pretend', false);
     if (!is_null($slug) && $this->module->exists($slug)) {
         $path = $this->getMigrationPath($slug);
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         $this->migrator->run($path, $pretend);
         // 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 {
         $modules = $this->module->all();
         if (count($modules) == 0) {
             return $this->error("Your application doesn't have any modules.");
         }
         $migrationsAll = [];
         foreach ($modules as $module) {
             $path = $this->getMigrationPath($module['slug']);
             $files = $this->migrator->getMigrationFiles($path);
             $ran = $this->migrator->getRepository()->getRan();
             $migrations = array_diff($files, $ran);
             $this->migrator->requireFiles($path, $migrations);
             $migrationsAll = array_merge($migrationsAll, $migrations);
         }
         if (floatval(App::version()) > 5.1) {
             $pretend = ['pretend' => $pretend];
         }
         sort($migrationsAll);
         $this->migrator->runMigrationList($migrationsAll, $pretend);
         // 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')) {
             foreach ($modules as $module) {
                 $this->call('module:seed', ['module' => $module['slug'], '--force' => true]);
             }
         }
     }
 }
开发者ID:samoilenkoevgeniy,项目名称:modules,代码行数:67,代码来源:ModuleMigrateCommand.php


示例19: boot

 /**
  * Register new BroadcastManager in boot
  *
  * @return void
  */
 public function boot()
 {
     $self = $this;
     $this->app->make(BroadcastManager::class)->extend('redisreliable', function ($app, $config) use($self) {
         return new RedisReliableBroadcaster($app->make('redis'), Arr::get($config, 'connection'), Arr::get($config, 'sub_min'), Arr::get($config, 'sub_list'));
     });
 }
开发者ID:trepatudo,项目名称:laravel-redisreliable,代码行数:12,代码来源:RedisReliableBroadcastServiceProvider.php


示例20: handle

 /**
  * Execute the console command.
  *
  * @return void
  */
 public function handle()
 {
     $roles = $this->file->getRequire(base_path(config('trust.permissions')));
     $this->call('trust:permissions');
     $all = Permission::all(['id', 'slug']);
     $create = 0;
     $update = 0;
     foreach ($roles as $slug => $attributes) {
         $role = $this->findRole($slug);
         if ($role) {
             if ($this->option('force')) {
                 ++$update;
                 $role->update($attributes + compact('slug'));
             }
         } else {
             ++$create;
             $role = Role::create($attributes + compact('slug'));
         }
         $permissions = array_reduce(Arr::get($attributes, 'permissions', []), function (Collection $result, string $name) use($all) {
             if (hash_equals('*', $name)) {
                 return $all->pluck('id');
             }
             if ($all->count() === $result->count()) {
                 return $result;
             }
             $filtered = $all->filter(function (Permission $permission) use($name) {
                 return Str::is($name, $permission->slug);
             })->pluck('id');
             return $result->merge($filtered);
         }, new Collection());
         $role->permissions()->sync($permissions->toArray());
     }
     $total = $create + $update;
     $this->line("Installed {$total} roles. <info>({$create} new roles, {$update} roles synced)</info>");
 }
开发者ID:znck,项目名称:trust,代码行数:40,代码来源:InstallRolesCommand.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Support\Collection类代码示例发布时间:2022-05-23
下一篇:
PHP Session\Store类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap