/** * Instanciate and execute all functions as blade extends * * @param Application $app The current application */ public static function attach(Application $app) { /** @var \Illuminate\View\Compilers\BladeCompiler $blade */ $blade = $app->make('view')->getEngineResolver()->resolve('blade')->getCompiler(); $config = $app->make('config'); $class = new static(); if (!isset($class->directivesFile)) { $class->directivesFile = __DIR__ . '/../directives.php'; } $blacklist = isset($class->blacklist) ? $class->blacklist : $config->get('blade_extensions.blacklist'); $directives = isset($class->directives) ? $class->directives : $app->make('files')->getRequire($class->directivesFile); $overrides = isset($class->overrides) ? $class->overrides : $config->get('blade_extensions.overrides', []); foreach ($overrides as $method => $override) { if (!isset($directives[$method])) { continue; } if (isset($override['pattern'])) { $directives[$method]['pattern'] = $override['pattern']; } if (isset($override['replacement'])) { $directives[$method]['replacement'] = $override['replacement']; } } foreach ($directives as $name => $directive) { $method = 'directive' . ucfirst($name); if (is_array($blacklist) && in_array($name, $blacklist, true) || !method_exists($class, $method)) { continue; } $blade->extend(function ($value) use($class, $method, $directive, $app, $blade) { return $class->{$method}($value, $directive['pattern'], $directive['replacement'], $app, $blade); }); } }
/** * @param $name * @throws UnexpectedValueException * @return \LaravelCommode\Bladed\Interfaces\IBladedCommand */ public function getNamespace($name) { if (!array_key_exists($name, $this->namespaces)) { throw new UnexpectedValueException("Unknown blade command namespace - {$name}."); } return $this->application->make("{$this->iocRegistry}.{$name}"); }
/** * @param string $key * * @return RepositoryInterface */ public function build($key) { $class = $this->registry->get($key); if ($class) { return $this->application->make($class); } }
public function subscribe(Dispatcher $event) { if (static::$called) { return; } // only actively do something in case the default cache driver has been changed if ($this->settings->get('hyn.cache.driver', 'file') != 'file') { /** @var \Illuminate\Contracts\Config\Repository $config */ $config = $this->application->make('config'); $cacheConfig = ['driver' => $this->settings->get('hyn.cache.driver')]; switch ($this->settings->get('hyn.cache.driver')) { case 'database': $merge = ['table' => $this->settings->get('hyn.cache.table', 'cache'), 'connection' => $this->settings->get('hyn.cache.connection')]; break; case 'redis': $merge = ['connection' => $this->settings->get('hyn.cache.connection')]; break; case 'memcached': // @todo.. break; default: $merge = []; } // merges driver specific settings into the config $cacheConfig = array_merge($cacheConfig, $merge); // sets the cache store $config->set('cache.stores.hyn-cache', $cacheConfig); $config->set('cache.driver', 'hyn-cache'); } }
public function __construct($memcached, Application $app) { $this->memcached = $memcached; //force expiry to be in seconds from minutes $this->sessionExpiry = $app->make('config')->get('session.lifetime') * 60; $this->sessionPrefix = $app->make('config')->get('session.cookie'); }
/** * Add a command, resolving through the application. * * @param string $command * * @return \Symfony\Component\Console\Command\Command */ public function resolve($command) { if (is_null($this->container)) { $this->container = Container::getInstance(); } return $this->add($this->container->make($command)); }
/** * {@inheritdoc} */ protected function getMiddleware(Application $app) { $pipe = new MiddlewarePipe(); $path = config('hyn.laravel-flarum.paths.api'); // if ($app->isInstalled() && $app->isUpToDate()) { $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody')); $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\FakeHttpMethods')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithHeader')); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale')); event(new ConfigureMiddleware($pipe, $path, $this)); $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.api.routes')])); $pipe->pipe($path, $app->make('Flarum\\Api\\Middleware\\HandleErrors')); // } else { // $pipe->pipe($path, function () { // $document = new Document; // $document->setErrors([ // [ // 'code' => 503, // 'title' => 'Service Unavailable' // ] // ]); // // return new JsonApiResponse($document, 503); // }); // } return $pipe; }
/** * {@inheritdoc} */ public function getAbstractionLayer($modelName) { $modelInstance = $this->getModelInstance($modelName); $args = ['model' => $modelInstance]; $dbal = $this->app->make('ANavallaSuiza\\Laravel\\Database\\Dbal\\Eloquent\\AbstractionLayer', $args); return $dbal; }
/** * Register the user verification. * * @param \Illuminate\Contracts\Foundation\Application $app * @return void */ protected function registerUserVerification(Application $app) { $app->bind('user.verification', function ($app) { return new UserVerification($app->make('mailer'), $app->make('db')->connection()->getSchemaBuilder()); }); $app->alias('user.verification', UserVerification::class); }
/** * Load configures from config file. */ protected function loadConfig() { $config = $this->app->make('config'); /** * How many entries per page. */ $this->cacheLive = $config->get('housekeeper.repository.cache.live', 300); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { if ($this->validator->validateRequest($request)) { $request = $this->app->make('Dingo\\Api\\Contract\\Http\\Request')->createFromIlluminate($request); return $this->sendRequestThroughRouter($request); } return $next($request); }
/** * Bootstrap the given application. * * @param \Illuminate\Contracts\Foundation\Application $app * * @return void */ public function bootstrap(Application $app) { if ($app->make('orchestra.extension.status')->is('safe')) { $app->make('orchestra.messages')->extend(function (MessageBag $messages) { $messages->add('info', trans('orchestra/foundation::response.safe-mode')); }); } }
/** * Function to boot indexer * @see */ public function boot() { $this->events = $this->app->make('events'); // Loop events foreach ($this->eloquentEvents as $event) { $this->events->listen('eloquent.' . $event . '*', ElasticListener::class . '@' . $event); } }
/** * Call the given URI and return a Response. * * @param string $uri * * @return \Illuminate\Http\Response */ protected function call($uri) { $request = Request::create($uri, 'GET'); $kernel = $this->app->make(HttpKernel::class); $response = $kernel->handle($request); $kernel->terminate($request, $response); return $response; }
private function getAllHooksImplementations() { $this->implementations = []; foreach ($this->getAllHooks() as $hookClass) { $this->implementations[] = $this->app->make($hookClass); } return $this->implementations; }
/** * Handle the analysis has completed event. * * We have a 1 in 16 chance of performing a cleanup. * * @param \StyleCI\StyleCI\Events\Analysis\AnalysisHasCompletedEvent $event * * @return void */ public function handle(AnalysisHasCompletedEvent $event) { if (random_int(0, 15) > 0) { return; } $path = $this->app->make('path.storage'); $factory = $this->app->make('git.factory'); $factory->gc("{$path}/repos", 14); }
/** * @param string $providerName 'meetup' * @param string $providerClass 'Your\Name\Space\ClassNameProvider' must extend * either Laravel\Socialite\Two\AbstractProvider or Laravel\Socialite\One\AbstractProvider * @param string $oauth1Server 'Your\Name\Space\ClassNameServer' must extend League\OAuth1\Client\Server\Server * * @throws InvalidArgumentException */ public function extendSocialite($providerName, $providerClass, $oauth1Server = null) { /** @var SocialiteManager $socialite */ $socialite = $this->app->make('Laravel\\Socialite\\Contracts\\Factory'); $provider = $this->buildProvider($socialite, $providerName, $providerClass, $oauth1Server); $socialite->extend($providerName, function () use($provider) { return $provider; }); }
/** * Call the terminate method on any terminable middleware. * * @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Response $response * @return void */ public function terminate($request, $response) { foreach ($this->middleware as $middleware) { $instance = $this->app->make($middleware); if ($instance instanceof TerminableMiddleware) { $instance->terminate($request, $response); } } }
/** * Attach access policy events. * * @param \Illuminate\Contracts\Foundation\Application $app * * @return void */ protected function attachAccessPolicyEvents(Application $app) { // Orchestra Platform should be able to watch any changes to Role model // and sync the information to "orchestra.acl". Role::observe($app->make(RoleObserver::class)); // Orchestra Platform should be able to determine admin and member roles // dynamically. Role::setDefaultRoles($app->make('config')->get('orchestra/foundation::roles')); }
/** * Returns the model set in auth config * * @return mixed Instantiated object of the 'auth.model' class */ public function model() { if (!$this->model) { $this->model = $this->app->make('config')->get('auth.model'); } if ($this->model) { return $this->app->make($this->model); } throw new \Exception("Wrong model specified in config/auth.php", 639); }
/** * Gets the tokens to trigger build for the Docker Hub images. * * @param \Illuminate\Contracts\Foundation\Application $app * @return array */ public static function getTokens(Application $app) { $file = $app->make('config')->get('services.dockerhub.tokens'); $fs = $app->make('filesystem')->disk('local'); if ($fs->exists($file)) { $content = $fs->get($file); return json_decode($content, true); } return []; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $correlationalId = $request->attributes->get(CorrelationalId::HEADER); if ($this->application->bound('sentry')) { /** @var Raven_Client $sentry */ $sentry = $this->application->make('sentry'); $sentry->tags_context([self::TAG_NAME => $correlationalId]); } /** @var Response $response */ $response = $next($request); return $response; }
/** * {@inheritdoc} */ public function __construct(Application $app) { $this->config = $app->make('config'); $this->cache = $app->make('cache'); $this->request = $app->make('request'); $this->localeModel = $app->make($this->getConfigLocaleModel()); $this->translationModel = $app->make($this->getConfigTranslationModel()); // Set the default locale to the current application locale $this->setLocale($this->getConfigDefaultLocale()); // Set the cache time from the configuration $this->setCacheTime($this->getConfigCacheTime()); }
/** * Register a module with this dashboard. * * @param string $moduleClassName * * @throws CoreException * @throws InvalidArgumentException */ public function register($moduleClassName) { Arguments::contain(Boa::string())->check($moduleClassName); $instance = $this->application->make($moduleClassName); if (!$instance instanceof Module) { throw new InvalidArgumentException('The provided class should extend the Module class.'); } try { $instance->boot(); $this->modules[$instance->getName()] = $instance; } catch (Exception $e) { $this->failedModules[$instance->getName()] = $e; } }
/** * Build your sidebar implementation here */ public function build() { $sidebars = array_merge($this->config->get('administr.modules'), $this->config->get('administr.sidebars')); foreach ($sidebars as $module) { $class = studly_case($module); if (!class_exists($class)) { $class = "Administr\\{$class}\\SidebarExtender"; } if (!class_exists($class)) { continue; } $extender = $this->app->make($class); $this->menu->add($extender->extendWith($this->menu)); } }
/** * Set current theme for request. * * @param \Illuminate\Contracts\Foundation\Application $app * @param \Orchestra\Contracts\Theme\Theme $theme * * @return void */ protected function setCurrentTheme(Application $app, Theme $theme) { $memory = $app->make('orchestra.memory')->makeOrFallback(); $events = $app->make('events'); // By default, we should consider all request to use "frontend" // theme and only convert to use "backend" routing when certain // event is fired. $theme->setTheme($memory->get('site.theme.frontend')); $events->listen('orchestra.started: admin', function () use($theme, $memory) { $theme->setTheme($memory->get('site.theme.backend')); }); $events->listen('composing: *', function () use($theme) { $theme->boot(); }); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { try { if ($this->validator->validateRequest($request)) { $this->app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', function ($app) { return $app['Dingo\\Api\\Exception\\Handler']; }); $request = $this->app->make('Dingo\\Api\\Contract\\Http\\Request')->createFromIlluminate($request); return $this->sendRequestThroughRouter($request); } } catch (Exception $exception) { return $this->exception->handle($exception); } return $next($request); }
/** * Get the Artisan application instance. * * @return \Illuminate\Console\Application */ protected function getArtisan() { if (is_null($this->artisan)) { return $this->artisan = (new Artisan($this->app, $this->app->make('events'), $this->app->version()))->resolveCommands($this->getCommands()); } return $this->artisan; }
/** * Make multiple objects using the container. * * @param array $classes * * @return object[] */ protected function bootstrap(array $classes) { foreach ($classes as $index => $class) { $classes[$index] = $this->app->make($class)->bootstrap(); } return $classes; }
/** * Call the terminate method on middlewares. * * @return void */ public function terminate($request, $response) { if (!($request = $this->app['request']) instanceof HttpRequest) { return; } // Laravel's route middlewares can be terminated just like application // middleware, so we'll gather all the route middleware here. // On Lumen this will simply be an empty array as it does // not implement terminable route middleware. $middlewares = $this->gatherRouteMiddlewares($request); // Because of how middleware is executed on Lumen we'll need to merge in the // application middlewares now so that we can terminate them. Laravel does // not need this as it handles things a little more gracefully so it // can terminate the application ones itself. if (class_exists('Laravel\\Lumen\\Application', false)) { $middlewares = array_merge($middlewares, $this->middleware); } foreach ($middlewares as $middleware) { list($name, $parameters) = $this->parseMiddleware($middleware); $instance = $this->app->make($name); if (method_exists($instance, 'terminate')) { $instance->terminate($request, $response); } } }