本文整理汇总了PHP中Illuminate\Support\Arr::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::get方法的具体用法?PHP Arr::get怎么用?PHP Arr::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: data
/**
* Get the message data.
*
* @param string $key|null
* @param string $default|null
* @return mixed
*/
public function data($key = null, $default = null)
{
if ($key) {
return Arr::get($this->data, $key, $default);
}
return $this->data;
}
示例2: 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>");
}
示例3: createSendgridDriver
/**
* Create an instance of the SendGrid Swift Transport driver.
*
* @return Transport\SendgridTransport
*/
protected function createSendgridDriver()
{
$config = $this->app['config']->get('services.sendgrid', []);
$client = new Client(Arr::get($config, 'guzzle', []));
$pretend = isset($config['pretend']) ? $config['pretend'] : false;
return new SendgridTransport($client, $config['api_key'], $pretend);
}
示例4: setOriginal
public function setOriginal($data)
{
$relations = Arr::get($data, $this->column);
foreach ($relations as $relation) {
$this->original[] = array_pop($relation['pivot']);
}
}
示例5: 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]);
}
}
}
}
示例6: 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);
}
示例7: 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'));
});
}
示例8: matter
public function matter(string $key = null, $default = null)
{
if ($key) {
return Arr::get($this->matter, $key, $default);
}
return $this->matter;
}
示例9: 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;
}
示例10: getModules
/**
* Modules of installed or not installed.
*
* @param bool $installed
*
* @return \Illuminate\Support\Collection
*/
public function getModules($installed = false)
{
if ($this->modules->isEmpty()) {
if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) {
(new Collection($directories))->each(function ($directory) use($installed) {
if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
$package = new Collection(json_decode($this->files->get($file), true));
if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) {
$module = new Module($name);
$module->setAuthor(Arr::get($package, 'authors'));
$module->setDescription(Arr::get($package, 'description'));
if ($installed) {
$module->setInstalled($installed);
}
if ($entries = data_get($package, 'autoload.psr-4')) {
foreach ($entries as $namespace => $entry) {
$module->setEntry($namespace . 'ModuleServiceProvider');
}
}
$this->modules->put($directory, $module);
}
}
});
}
}
return $this->modules;
}
示例11: boot
/**
* Bootstrap the application services.
*/
public function boot()
{
app('swift.transport')->extend('mailjet', function () {
$config = $this->app['config']->get('services.mailjet', []);
return new MailjetTransport(new HttpClient(Arr::get($config, 'guzzle', [])), $config['public'], $config['private']);
});
}
示例12: __construct
/**
* CurrencyManager constructor.
*
* @param array $configs
*/
public function __construct(array $configs)
{
$this->default = Arr::get($configs, 'default', 'USD');
$this->supported = Arr::get($configs, 'supported', ['USD']);
$this->nonIsoIncluded = Arr::get($configs, 'include-non-iso', false);
$this->currencies = new CurrencyCollection();
}
示例13: larakitRegisterMenuSubpages
static function larakitRegisterMenuSubpages($package, $alias)
{
//автоматическая регистрация дочерних страниц Subpages
$dir = base_path('vendor/' . $package . '/src/config/larakit/subpages/');
$dir = HelperFile::normalizeFilePath($dir);
if (file_exists($dir)) {
$dirs = rglob('*.php', 0, $dir);
foreach ($dirs as $d) {
$d = str_replace($dir, '', $d);
$d = str_replace('.php', '', $d);
$d = trim($d, '/');
$menus_subpages = (array) \Config::get($alias . '::larakit/subpages/' . $d);
if (count($menus_subpages)) {
foreach ($menus_subpages as $page => $items) {
$manager = \Larakit\Widget\WidgetSubpages::factory($page);
foreach ($items as $as => $props) {
$style = Arr::get($props, 'style', 'bg-aqua');
$is_curtain = Arr::get($props, 'is_curtain', false);
$manager->add($as, $style, $is_curtain);
}
}
}
}
}
}
示例14: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$config = Config::get('session');
$response->headers->setCookie(new Cookie($config['cookie'], $request->cookies->get($config['cookie']), $this->getCookieExpirationDate(), $config['path'], $config['domain'], Arr::get($config, 'secure', false)));
return $response;
}
示例15: get
/**
* Get an element from an array.
*
* @param array $array
* @param string $key Specify a nested element by separating keys with full stops.
* @param mixed $default If the element is not found, return this.
*
* @return mixed
*/
public static function get($array, $key, $default = null)
{
if (is_array($key)) {
return static::getArray($array, $key, $default);
}
return parent::get($array, $key, $default);
}