/** * Return the valid authentication response. * * @param \Illuminate\Http\Request $request * @param mixed $result * @return mixed */ public function validAuthenticationResponse($request, $result) { if (Str::startsWith($request->channel_name, 'private')) { return $this->decodePusherResponse($this->pusher->socket_auth($request->channel_name, $request->socket_id)); } else { return $this->decodePusherResponse($this->pusher->presence_auth($request->channel_name, $request->socket_id, $request->user()->id, $result)); } }
/** * Crawl and process a single URL. * @param $url string * @return mixed|null */ protected function crawlUrl($url, $parentUrl = null) { if (!$url || $this->crawled->search($url) !== false || Str::startsWith($url, "#")) { return null; } $this->log("Crawling URL: " . $url); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $this->agent); curl_setopt($ch, CURLOPT_HEADER, 1); $response = curl_exec($ch); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = $this->parseHeader(substr($response, 0, $headerSize)); $body = substr($response, $headerSize); curl_close($ch); $this->crawled->push($url); if (!$this->validate($header, $body, $url, $parentUrl)) { return null; } $processed = $this->processHtml($url, HtmlDomParser::str_get_html($body)); $this->add($processed); // Recursively crawl other URLs that were found. foreach ($processed['urls'] as $href) { $this->crawlUrl($href, $url); } }
/** * @return string */ protected function getType() { if ($this->type) { return $this->type; } return Str::startsWith(\Route::currentRouteName(), 'admin.plugins') ? self::TYPE_PLUGINS : self::TYPE_WIDGETS; }
/** * Determines if is on adminisBootable. * * @param $path * @param null $routePrefix * @return bool */ public function isBootable($path, $routePrefix = null) { if (App::runningInConsole() || App::runningUnitTests()) { return true; } return $path == $routePrefix || Str::startsWith($path, $routePrefix . '/'); }
/** * Add a root if the URL is relative (helper method of the hasLink function). * * @param string $url * @return string */ protected function addRootToRelativeUrl($url) { if (!Str::startsWith($url, ['http', 'https'])) { return $this->app->make('url')->to($url); } return $url; }
protected function registerBladeExtensions() { static $templateStack = []; $blade = $this->app['blade.compiler']; $blade->directive('beautymail', function ($expression) { if (Str::startsWith($expression, '(')) { $expression = substr($expression, 1, -1); } return "<?php echo \$__env->make('beautymail::templates.'.{$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }); $blade->directive('startBeautymail', function ($expression) use(&$templateStack) { if (Str::startsWith($expression, '(')) { $expression = substr($expression, 1, -1); } $matcher = preg_match('#^\'([^\']+)\'(.*)$#', $expression, $matches); $templateName = $matches[1]; $args = $matches[2]; $templateStack[] = $templateName; return "<?php echo \$__env->make('beautymail::templates.{$templateName}Start' {$args}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }); $blade->directive('endBeautymail', function ($args) use(&$templateStack) { if (Str::startsWith($args, '(')) { $args = substr($args, 1, -1); } $templateName = array_pop($templateStack); return "<?php echo \$__env->make('beautymail::templates.{$templateName}End' {$args}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }); }
/** * Get the authorization bearer token from the headers, useful when AUTHing a user hitting the API that * has already logged in. */ public function getTokenFromHeaders() { $bearer = Request::header('authorization'); if (Str::startsWith($bearer, 'Bearer ')) { $this->token = Str::substr($bearer, 7); } }
/** * Gets the value of an environment variable. Supports boolean, empty and null. * * @param string $key * @param mixed $default * * @return mixed */ function env($key, $default = null) { $value = getenv($key); if ($value === false) { return value($default); } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'empty': case '(empty)': return ''; case 'null': case '(null)': return; } if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { return substr($value, 1, -1); } return $value; }
/** * Authenticate the incoming request for a given channel. * * @param \Illuminate\Http\Request $request * @return mixed */ public function auth($request) { if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && !$request->user()) { throw new HttpException(403); } return parent::verifyUserCanAccessChannel($request, str_replace(['private-', 'presence-'], '', $request->channel_name)); }
public function testMap() { $router = new Router(new Dispatcher()); $mapper = $this->make(); $mapper->map($router); $routes = $router->getRoutes(); $controllers = $this->getControllers(); $this->assertGreaterThan(0, $routes->count(), 'Each mapper should define at least one route.'); /** @var Route $route */ foreach ($routes as $route) { $name = $route->getPath(); // Check that it has a controller if (!array_key_exists('controller', $route->getAction())) { $this->fail('Route: ' . $name . ' has an invalid handler.' . ' Only use controller handlers.'); } $parts = explode('@', $route->getAction()['controller']); // Check that it is controller@method definition if (count($parts) < 2) { $this->fail('Route: ' . $name . ' has an invalid handler: ' . $route->getActionName() . '. Only use controller@method handlers.'); } // Check it begins with an HTTP method if (!Str::startsWith($parts[1], $this->methods)) { $this->fail('Route: ' . $name . ' has an invalid handler name: ' . $route->getActionName() . '. The handler name should begin with an HTTP method.'); } // Make sure the controller is white-listed if (!in_array($parts[0], $controllers)) { $this->fail('Route: ' . $name . ' has an invalid controller' . '. Make sure the test matches the directory controllers.'); } // Make sure the class method exists if (!method_exists($parts[0], $parts[1])) { $this->fail('Route: ' . $name . ' has an invalid handler.' . ' Make sure the method exists.'); } } }
/** * Add a root if the URL is relative (helper method of the hasLink function). * * @return string */ protected function absoluteUrl() { if (!Str::startsWith($this->url, ['http', 'https'])) { return URL::to($this->url); } return $this->url; }
/** * @author bigsinoos <*****@*****.**> * Check that if a magic method argument is findable or not * * @param $method * @return bool */ private function isFindable($method) { if (Str::startsWith($method, 'findBy')) { return true; } return false; }
/** * Validate the requests authorization header for the provider. * * @param \Illuminate\Http\Request $request * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * * @return bool */ public function validateAuthorizationHeader(Request $request) { if (Str::startsWith(strtolower($request->headers->get('shield')), $this->getAuthorizationMethod())) { return true; } throw new BadRequestHttpException(); }
/** * Authenticate the request for channel access. * * @param \Illuminate\Http\Request $request * @return void */ public function authenticate(Request $request) { if (Str::startsWith($request->channel_name, 'presence-') && !$request->user()) { abort(403); } return Broadcast::auth($request); }
/** * Execute the console command. * * @return void */ public function fire() { // Check file exists if (!File::exists($this->argument('file'))) { $this->comment('No coverage file found, skipping.'); return 0; } // Open serialised file $serialised = File::get($this->argument('file')); if (!Str::startsWith($serialised, '<?php')) { $coverage = unserialize($serialised); // Require PHP object in file } else { $coverage = (require $this->argument('file')); } // Check coverage percentage $total = $coverage->getReport()->getNumExecutableLines(); $executed = $coverage->getReport()->getNumExecutedLines(); $percentage = nf($executed / $total * 100, 2); // Compare percentage to threshold $threshold = $this->argument('threshold'); if ($percentage >= $threshold) { $this->info("Code Coverage of {$percentage}% is higher than the minimum threshold required {$threshold}%!"); return; } // Throw error $this->error("Code Coverage of {$percentage}% is below than the minimum threshold required {$threshold}%!"); return 1; }
private function registerDirectives() { Blade::directive('allowed', function ($expression) { if (Str::startsWith($expression, '(')) { $expression = substr($expression, 1, -1); } return "<?php if (app('rbac')->checkAccess(\\Auth::user(), {$expression})): ?>"; }); if (Config::get('rbac.shortDirectives')) { foreach (Rbac::getRepository() as $name => $item) { $directiveName = $item->type == Item::TYPE_PERMISSION ? 'allowed' : 'is'; $directiveName .= Str::studly(str_replace('.', ' ', $name)); Blade::directive($directiveName, function ($expression) use($name) { $expression = trim($expression, '()'); if (!empty($expression)) { $expression = ', ' . $expression; } return "<?php if (app('rbac')->checkAccess(\\Auth::user(), '{$name}'{$expression})): ?>"; }); } } Blade::directive('endallowed', function ($expression) { return "<?php endif; ?>"; }); }
/** * Try to parse the token from the request header. * * @param \Illuminate\Http\Request $request * * @return null|string */ public function parse(Request $request) { $header = $request->headers->get($this->header, $this->fromAltHeaders($request)); if ($header && Str::startsWith(strtolower($header), $this->prefix)) { return trim(str_ireplace($this->prefix, '', $header)); } }
/** * Determine if the given controller method is routable. * * @param \ReflectionMethod $method * @return bool */ public function isRoutable(ReflectionMethod $method) { if ($method->class == 'Illuminate\\Routing\\Controller') { return false; } return Str::startsWith($method->name, $this->verbs); }
/** * Parse the frontmatter file. * * @param string $content * @param null|string $formatter * * @return bool */ public function parse($content, $formatter = null) { if ($formatter === null) { $formatter = self::YAML; } $parser = new $formatter(); // If the file doesn't immediately begin with a separator then this isn't a Frontmatter file. if (!Str::startsWith($content, '---')) { throw new InvalidFrontmatterFormatException('A valid Frontmatter document is expected to start with "---"'); } // Split the document into three sections. $doc = explode('---', $content); if (count($doc) <= 1) { // Empty Document $this->content = ''; } elseif (count($doc) === 2) { // Only Frontmatter $this->frontmatter = trim($doc[1]); } else { // Frontmatter and content // It's possible that the Markdown content contains a HR (---) tag. We should merge these values back together. $content = $doc[2]; if (count($doc) > 3) { $content = ''; for ($i = 3; $i < count($doc); $i++) { $content .= $doc[$i]; } } $this->frontmatter = trim($doc[1]); $this->content = ltrim($content); } // Parse the Frontmatter content. $this->data = $parser->deserialize($this->frontmatter); return $this; }
/** * Get the encryption key for the application. * * @return string */ protected static function getKey() { $key = config('app.key'); if (Str::startsWith($key, 'base64:')) { $key = base64_decode(substr($key, 7)); } return $key; }
/** * Display the user's biography * * @return string */ public function website() { $website = $this->entity->website; if (!Str::startsWith($website, ['http://', 'https://'])) { $website = 'http://' . $website; } return $website; }
/** * Extract all of the options from the tokens. * * @param array $tokens * @return array */ protected static function options(array $tokens) { return array_values(array_filter(array_map(function ($token) { if (Str::startsWith($token, '{--')) { return static::parseOption(ltrim(trim($token, '{}'), '-')); } }, $tokens))); }
public function getClassNamespace($name) { $name = Utils::switchToNamespaceSlashes($name); if (Str::startsWith($name, $this->getRootNamespace())) { return $name; } return $this->getRootNamespace() . '\\' . $name; }
/** * Create a token repository instance based on the given configuration. * * @param array $config * @return \Illuminate\Auth\Passwords\TokenRepositoryInterface */ protected function createTokenRepository(array $config) { $key = $this->app['config']['app.key']; if (Str::startsWith($key, 'base64:')) { $key = base64_decode(substr($key, 7)); } return new DatabaseTokenRepository($this->app['db']->connection(), $config['table'], $key, $config['expire']); }
/** * {@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()); }
/** * Authenticate the incoming request for a given channel. * * @param \Illuminate\Http\Request $request * @return mixed */ public function auth($request) { if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && !$request->user()) { throw new HttpException(403); } $channelName = Str::startsWith($request->channel_name, 'private-') ? Str::replaceFirst('private-', '', $request->channel_name) : Str::replaceFirst('presence-', '', $request->channel_name); return parent::verifyUserCanAccessChannel($request, $channelName); }
/** * Register the service provider. * * @return void */ public function register() { $methods = get_class_methods($this); foreach ($methods as $method) { if (Str::startsWith($method, "register") and $method != "register") { $this->{$method}(); } } }
public function all() { $routes = collect($this->getRoutes()->getRoutes()); return $routes->filter(function (\Illuminate\Routing\Route $route) { return !Str::startsWith($route->uri(), config('arcanesoft.foundation.routes-viewer.uris.hide', [])); })->transform(function (\Illuminate\Routing\Route $route) { return ['methods' => $this->prepareMethods($route), 'domain' => $route->domain(), 'uri' => $route->uri(), 'name' => $route->getName(), 'action' => $route->getActionName(), 'middlewares' => $this->prepareMiddlewares($route)]; }); }
/** * Always check if the key is generated. * * @author Cali */ protected function generateKeyIfNotGiven() { $config = $this->app->make('config')->get('app'); if (!Str::startsWith($config['key'], 'base64:')) { $key = 'base64:' . base64_encode(random_bytes($config['cipher'] == 'AES-128-CBC' ? 16 : 32)); env_put('APP_KEY', $key); $this->app['config']['app.key'] = $key; } }
/** * Controller Auto-Router * * @param string $controller eg. 'Admin\\UserController' * @param array $request_methods eg. array('get', 'post', 'put', 'delete') * @param string $prefix eg. admin.users * @param array $disallowed eg. array('private_method that starts with one of request methods) * @return Closure */ public static function autoRoute($controller, $request_methods, $disallowed = array(), $prefix = '') { return function () use($controller, $prefix, $disallowed, $request_methods) { //get all defined functions $methods = get_class_methods(App::make($controller)); //laravel methods to disallow by default $disallowed_methods = array('getBeforeFilters', 'getAfterFilters', 'getFilterer'); //build list of functions to not allow if (is_array($disallowed)) { $disallowed_methods = array_merge($disallowed_methods, $disallowed); } //if there is a index method then lets just bind it and fill the gap in route_names if (in_array('getIndex', $methods)) { Lara::fillRouteGaps($prefix, $controller . '@getIndex'); } //over all request methods, get, post, etc foreach ($request_methods as $type) { //filter functions that starts with request method and not in disallowed list $actions = array_filter($methods, function ($action) use($type, $disallowed_methods) { return Str::startsWith($action, $type) && !in_array($action, $disallowed_methods); }); foreach ($actions as $action) { $controller_route = $controller . '@' . $action; // Admin\\Controller@get_login $url = Str::snake(str_replace($type, '', $action)); // login; snake_case //double check and dont bind to already bound gaps filled index if (in_array($action, $methods) && $action !== 'getIndex') { $route = str_replace('..', '.', $prefix . '.' . Str::snake($action)); Route::$type($url, array('as' => $route, 'uses' => $controller_route)); } } } }; }