示例#1
0
 /**
  * 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
0
 /**
  * {@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
0
 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;
     });
 }
 /**
  * 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
0
 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;
 }
 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
0
 /**
  * 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);
 }
 /**
  * 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
0
 /**
  * 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
0
 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
0
文件: Search.php 项目: newup/core
 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);
 }
 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;
     });
 }
 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
0
 /**
  * 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;
 }
 /**
  * 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);
     });
 }
示例#16
0
 /**
  * @param string $url
  */
 protected function findActiveByAliases($url)
 {
     $this->getPages()->each(function (PageInterface $page) use($url) {
         foreach ($page->getAliases() as $alias) {
             if (Str::is($alias, $url)) {
                 $page->setActive();
                 break;
             }
         }
         $page->findActiveByAliases($url);
     });
 }
示例#17
0
 function in_array_wildcard($what, $array)
 {
     foreach ($array as $pattern) {
         if (\Illuminate\Support\Str::is($pattern, $what)) {
             return true;
         }
     }
     return false;
 }
示例#18
0
 /**
  * Alias for the "currentRouteUses" method.
  *
  * @return bool
  */
 public function uses()
 {
     foreach (func_get_args() as $pattern) {
         if (Str::is($pattern, $this->currentRouteAction())) {
             return true;
         }
     }
     return false;
 }
示例#19
0
 /**
  * Determine if the current request URL and query string matches a pattern.
  *
  * @param  mixed  string
  * @return bool
  */
 public function fullUrlIs()
 {
     $url = $this->fullUrl();
     foreach (func_get_args() as $pattern) {
         if (Str::is($pattern, $url)) {
             return true;
         }
     }
     return false;
 }
示例#20
0
 public static function is($subdomen)
 {
     return ($s = static::subdomen()) ? Str::is($subdomen, $s) : null;
 }
示例#21
0
 /**
  * Get the custom error message from translator.
  *
  * @param  string  $customKey
  * @return string
  */
 protected function getCustomMessageFromTranslator($customKey)
 {
     $shortKey = str_replace('validation.custom.', '', $customKey);
     $customMessages = Arr::dot((array) $this->translator->trans('validation.custom'));
     foreach ($customMessages as $key => $message) {
         if ($key === $shortKey || Str::contains($key, ['*']) && Str::is($key, $shortKey)) {
             return $message;
         }
     }
     return $customKey;
 }
示例#22
0
 protected function getWildcardListeners($eventName)
 {
     $wildcards = array();
     foreach ($this->wildcards as $key => $listeners) {
         if (Str::is($key, $eventName)) {
             $wildcards = array_merge($wildcards, $listeners);
         }
     }
     return $wildcards;
 }
 protected function checkPattern($pattern)
 {
     $fullUrlPattern = $this->url->to($pattern);
     $fullUrl = $this->request->fullUrl();
     return Str::is($fullUrlPattern, $fullUrl);
 }
示例#24
0
 /**
  * Determine if the current request URI matches a pattern.
  *
  * @param  mixed  string
  * @return bool
  */
 public function is()
 {
     foreach (func_get_args() as $pattern) {
         if (Str::is($pattern, urldecode($this->path()))) {
             return true;
         }
     }
     return false;
 }
示例#25
0
文件: Route.php 项目: larakit/lk
 static function getRouteByUri($uri)
 {
     $uri = parse_url($uri, PHP_URL_PATH);
     $routes = [];
     foreach (\Route::getRoutes()->getRoutes() as $route) {
         $routes[$route->getUri()] = $route->getName();
     }
     krsort($routes);
     //        dd($routes);
     $uri = trim($uri, '/');
     if (!$uri) {
         return 'home';
     }
     $matched = false;
     $_m = [];
     $max = null;
     foreach ($routes as $route_uri => $name) {
         /** @var \Illuminate\Routing\Route $route */
         $route_uri = preg_replace('/\\/\\{(.*)\\?\\}/U', '*', $route_uri);
         $route_uri = preg_replace('/\\*\\*/U', '*', $route_uri);
         $route_uri = preg_replace('/\\{(.*)\\}/U', '*', $route_uri);
         //dump($route_uri . ' | ' . $matched . ' | ' . $max);
         if (\Illuminate\Support\Str::is($route_uri, $uri)) {
             $_m[] = [$name, $route_uri];
             $m = mb_substr_count($route_uri, '{');
             if (is_null($max) || !$m || $m < $max) {
                 $max = $m;
                 $matched = $name;
             }
         }
     }
     //dump($_m);
     return $matched;
 }
示例#26
0
 /**
  * Determines if a path should be removed.
  *
  * @param  $path
  * @return bool
  */
 private function shouldBeRemoved($path)
 {
     $path = $this->normalizePath($path);
     // Always remove "newup.keep" files.
     if (Str::is('*newup.keep', $path)) {
         return true;
     }
     foreach ($this->automaticallyRemovedPaths as $removedPath) {
         if (Str::is($this->normalizePath($removedPath), $path)) {
             return true;
         }
     }
     return false;
 }
示例#27
0
 /**
  * Get or check the current application environment.
  *
  * @param  mixed
  * @return string|bool
  */
 public function environment()
 {
     if (func_num_args() > 0) {
         $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
         foreach ($patterns as $pattern) {
             if (Str::is($pattern, $this['env'])) {
                 return true;
             }
         }
         return false;
     }
     return $this['env'];
 }
示例#28
0
 /**
  * Get or check the current application environment.
  *
  * @param  mixed
  * @return string
  */
 public function environment()
 {
     $env = env('APP_ENV', 'production');
     if (func_num_args() > 0) {
         $patterns = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
         foreach ($patterns as $pattern) {
             if (Str::is($pattern, $env)) {
                 return true;
             }
         }
         return false;
     }
     return $env;
 }
示例#29
0
文件: helpers.php 项目: saj696/pipe
 /**
  * Determine if a given string matches a given pattern.
  *
  * @param  string $pattern
  * @param  string $value
  * @return bool
  */
 function str_is($pattern, $value)
 {
     return Str::is($pattern, $value);
 }
示例#30
0
 /**
  * Determines if a file should simply be copied.
  *
  * @param $file
  * @return bool
  */
 private function shouldCopyFileInstead($file)
 {
     // Check if it should not be processed.
     if ($this->isExcludedFromVerbatim($file)) {
         return false;
     }
     foreach ($this->copyVerbatimPatterns as $pattern) {
         if (Str::is($pattern, $file)) {
             return true;
         }
     }
     return false;
 }