本文整理汇总了PHP中Illuminate\Support\Str::is方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::is方法的具体用法?PHP Str::is怎么用?PHP Str::is使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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>");
}
示例2: isActive
/**
* {@inheritDoc}
*/
public function isActive()
{
// If URL start with # then it is only client side routing
if (Str::startsWith($this->getUrl(), '#')) {
return false;
}
return Str::is($this->getUrl(), $this->container->make(Request::class)->url());
}
示例3: scanPath
public function scanPath($path = '', $mask = null)
{
$files = scandir($this->getPath($path));
return collect($files)->filter(function ($file) use($mask) {
if (!in_array($file, ['.', '..'])) {
return $mask ? Str::is($mask, $file) : true;
}
return false;
});
}
示例4: findAvailableHandlers
/**
* Find all handlers that are available for the current SlashCommand
* and have a signature.
*
* @return Collection|SignatureHandler[]
*/
protected function findAvailableHandlers() : Collection
{
return collect(config('laravel-slack-slash-command.handlers'))->map(function (string $handlerClassName) {
return new $handlerClassName($this->request);
})->filter(function (HandlesSlashCommand $handler) {
return $handler instanceof SignatureHandler;
})->filter(function (SignatureHandler $handler) {
$signatureParts = new SignatureParts($handler->getSignature());
return Str::is($signatureParts->getSlashCommandName(), $this->request->command);
});
}
示例5: prepareParams
protected function prepareParams($params)
{
$data = array();
foreach ($params as $key => $value) {
if (is_object($value) && Str::is('Illuminate\\*\\Events\\*', get_class($value))) {
$value = $this->prepareParams(get_object_vars($value));
}
$data[$key] = htmlentities($this->exporter->exportValue($value), ENT_QUOTES, 'UTF-8', false);
}
return $data;
}
示例6: testStringIs
public function testStringIs()
{
$str = 'Laravel is really awesome';
$result = Str::is('Laravel', $str);
$this->assertEquals($result, false);
$str = 'Laravel is really awesome';
$result = Str::is('Laravel*', $str);
$this->assertEquals($result, true);
$str = 'Laravel is really awesome';
$result = Str::is('*is*', $str);
$this->assertEquals($result, true);
}
示例7: verifyUserCanAccessChannel
/**
* Authenticate the incoming request for a given channel.
*
* @param \Illuminate\Http\Request $request
* @param string $channel
* @return mixed
*/
protected function verifyUserCanAccessChannel($request, $channel)
{
foreach ($this->channels as $pattern => $callback) {
if (!Str::is(preg_replace('/\\{(.*?)\\}/', '*', $pattern), $channel)) {
continue;
}
$parameters = $this->extractAuthParameters($pattern, $channel, $callback);
if ($result = $callback($request->user(), ...$parameters)) {
return $this->validAuthenticationResponse($request, $result);
}
}
throw new HttpException(403);
}
示例8: check
/**
* Authenticate the incoming request for a given channel.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function check($request)
{
$channel = str_replace(['private-', 'presence-'], '', $request->channel_name);
foreach ($this->channels as $pattern => $callback) {
if (!Str::is($pattern, $channel)) {
continue;
}
$parameters = $this->extractAuthParameters($pattern, $channel);
if ($result = $callback($request->user(), ...$parameters)) {
return $this->validAuthenticationResponse($request, $result);
}
}
throw new HttpException(403);
}
示例9: getCustomMessageFromTranslator
/**
* Get the custom error message from translator.
*
* @param string $customKey
* @return string
*/
protected function getCustomMessageFromTranslator($customKey)
{
if (($message = $this->translator->trans($customKey)) !== $customKey) {
return $message;
}
$shortKey = preg_replace('/^lpanel::validation\\.custom\\./', '', $customKey);
$customMessages = Arr::dot((array) $this->translator->trans('lpanel::validation.custom'));
foreach ($customMessages as $key => $message) {
if (Str::contains($key, ['*']) && Str::is($key, $shortKey)) {
return $message;
}
}
return $customKey;
}
示例10: check
private function check($source, $ip)
{
if (count($source)) {
if (in_array($ip, $source)) {
return true;
}
}
foreach ($source as $pattern) {
if (Str::is($pattern, $ip)) {
return true;
}
}
return false;
}
示例11: displayPackages
private function displayPackages()
{
$vendors = $this->templateStorageEngine->getInstalledPackages();
$displayPackages = [];
foreach ($vendors as $vendor) {
foreach ($vendor['packages'] as $package) {
if ($this->argument('q') !== null) {
if (Str::is($this->argument('q'), $package['package']) === false) {
continue;
}
}
$displayPackages[] = [$package['package'], $vendor['vendor'], $package['version'], $package['instance']->getDescription()];
}
}
$this->table(['Package', 'Vendor', 'Version', 'Description'], $displayPackages);
}
示例12: findAlternativeHandlers
protected function findAlternativeHandlers(string $command) : Collection
{
$alternativeHandlers = collect(config('laravel-slack-slash-command.handlers'))->map(function (string $handlerClassName) {
return new $handlerClassName($this->request);
})->filter(function (HandlesSlashCommand $handler) {
return $handler instanceof SignatureHandler;
})->filter(function (SignatureHandler $handler) {
$signatureParts = new SignatureParts($handler->getSignature());
return Str::is($signatureParts->getSlashCommandName(), $this->request->command);
});
if (strpos($command, ':') !== false) {
$subHandlers = $this->findInNamespace($alternativeHandlers, $command);
if ($subHandlers->count()) {
return $subHandlers;
}
}
return $alternativeHandlers->filter(function (SignatureHandler $handler) use($command) {
return levenshtein($handler->getName(), $command) <= 2;
});
}
示例13: handle
public function handle($callback = null)
{
if (Arr::get($_POST, 'option') == $this->id) {
if (!is_null($callback)) {
call_user_func($callback, $this);
}
foreach ($this->items as $item) {
if ($item->type == "checkbox" && !isset($_POST[$item->id])) {
// preset value for checkboxes which are not checked
$_POST[$item->id] = "0";
}
if (Str::is('*[*]', $item->id)) {
continue;
}
if ($_POST[$item->id] != option($item->id, null, false)) {
Option::set($item->id, $_POST[$item->id]);
}
}
session()->flash($this->id . '.status', 'success');
}
return $this;
}
示例14: getOptions
/**
* Find the options for the current request, based on the paths/hosts settings.
*
* @param Request $request
*
* @return array
*/
protected function getOptions(Request $request)
{
$defaults = $this->app['config']->get('df.cors.defaults', []);
$paths = $this->getPath();
$uri = $request->getPathInfo() ?: '/';
$host = $request->getHost();
foreach ($paths as $pathPattern => $options) {
//Check for legacy patterns
if ($request->is($pathPattern) || Str::startsWith($pathPattern, '^') && preg_match('{' . $pathPattern . '}i', $uri)) {
$options = array_merge($defaults, $options);
// skip if the host is not matching
if (isset($options['hosts']) && count($options['hosts']) > 0) {
foreach ($options['hosts'] as $hostPattern) {
if (Str::is($hostPattern, $host)) {
return $options;
}
}
continue;
}
return $options;
}
}
return $defaults;
}
示例15: hasPermission
/**
* Check if the user has a permission.
*
* @param int|string $permission
* @return bool
*/
public function hasPermission($permission)
{
return $this->getPermissions()->contains(function ($key, $value) use($permission) {
return $permission == $value->id || Str::is($permission, $value->slug);
});
}