/** * Get the extension used by the view file. * * @param string $path * * @return string|null */ protected function getExtension(string $path) { $extensions = array_keys($this->extensions); return Arr::first($extensions, function ($key, $value) use($path) { return Str::endsWith($path, $value); }); }
/** * Get the environment argument from the console. * * @param array $args * * @return string|null */ protected function getEnvironmentArgument(array $args) { return Arr::first($args, function ($k, $v) { return Str::startsWith($v, '--env'); }); }
/** * Get the first item from the collection. * * @param callable|null $callback * @param mixed $default * * @return mixed */ public function first(callable $callback = null, $default = null) { return Arr::first($this->items, $callback, $default); }
/** * Parse the route action into a standard array. * * @param callable|array|null $action * * @throws \UnexpectedValueException * * @return array */ protected function parseAction($action) : array { // If no action is passed in right away, we assume the user will make use of // fluent routing. In that case, we set a default closure, to be executed // if the user never explicitly sets an action to handle the given uri. if (is_null($action)) { return ['uses' => function () { throw new LogicException(sprintf('Route for [%s] has no action.', $this->uri)); }]; } // If the action is already a Closure instance, we will just set that instance // as the "uses" property. if (is_callable($action)) { return ['uses' => $action]; } // If no "uses" property has been set, we will dig through the array to find a // Closure instance within this list. We will set the first Closure we come across. if (!isset($action['uses'])) { $action['uses'] = Arr::first($action, function ($key, $value) { return is_callable($value) && is_numeric($key); }); } if (is_string($action['uses']) && strpos($action['uses'], '::') === false) { if (!method_exists($action, '__invoke')) { throw new UnexpectedValueException(sprintf('Invalid route action: [%s]', $action['uses'])); } $action['uses'] = $action . '::__invoke'; } return $action; }