本文整理汇总了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;
}
示例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.");
}
}
示例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;
}
示例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);
}
示例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);
}
}
示例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));
}
示例7: handleDotCase
protected function handleDotCase(&$array, $key, $value)
{
if (strpos($key, '.') !== false) {
unset($array[$key]);
Arr::set($array, $key, $value);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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));
}
示例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;
}
示例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);
}