function loadFromCache(CachingFileCompiler $cache, $sourceFile) { global $usrlz_ctx, $usrlz_inj; // Preserve the current context. $prev_ctx = $usrlz_ctx; $usrlz_ctx = $this->context->makeSubcontext(); $usrlz_inj = $this->injector; $compiled = $cache->get($sourceFile, function ($source) use($sourceFile) { $root = $this->compile($source); if ($root instanceof CompositeComponent) { $root->templateUrl = $sourceFile; } return $root; }); // Restore the current context. $usrlz_ctx = $prev_ctx; if ($this->rootClass) { /** @var CompositeComponent $root */ $root = $this->injector->make($this->rootClass); $root->setContext($this->context->makeSubcontext()); $root->setShadowDOM($compiled); return $root; } return $compiled; }
function configure(InjectorInterface $injector, ModuleServices $module, LoginSettings $settings, RouterInterface $router) { $injector->share(LoginSettings::class); $this->settings = $settings; $this->router = $router; $module->provideTranslations()->provideViews()->registerRouter($this, 'login', 'platform'); }
function getEngine($engineClass, $options = []) { // The engine class may receive this instance as a $view parameter on the constructor (optional). /** @var ViewEngineInterface $engine */ $engine = $this->injector->make($engineClass, [':view' => $this]); if ($options) { $engine->configure($options); } return $engine; }
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { $URL = $request->getAttribute('virtualUri'); if ($URL == '') { $URL = 'index'; } elseif (substr($URL, -1) == '/') { $URL = $URL . 'index'; } try { $routable = page($URL); $handler = $this->injector->execute($routable); return $handler($request, $response); } catch (FileNotFoundException $e) { return $next(); } }
/** * @param string $rootDir */ private function setupDebugging($rootDir) { // Disabled the shutdown handler to prever interference with Symfony console's error handling. // register_shutdown_function ([$this, 'shutdown']); set_error_handler([$this, 'errorHandler']); set_exception_handler([$this, 'exceptionHandler']); $this->injector->defineParam('devEnv', false); $this->injector->defineParam('webConsole', false); }
/** * @param string $seeder The class name, which should equals the file name. * @return SeederInterface */ private function loadSeederClass($seeder) { if (!class_exists($seeder, false)) { $path = "{$this->seedsPath}/{$seeder}.php"; if (!file_exists($path)) { throw new \RuntimeException("Migration file {$path} was not found"); } require $path; if (!class_exists($seeder, false)) { throw new \RuntimeException("Migration file {$path} doesn't define a class named {$seeder}"); } } return $this->injector->make($seeder); }
/** * DocumentContext constructor. * * @param AssetsService $assetsService * @param BlocksService $blocksService * @param MacrosService $macrosService * @param DataBinderInterface $dataBinder * @param InjectorInterface $injector * @param MatisseSettings $matisseSettings * @param ViewServiceInterface $viewService */ function __construct(AssetsService $assetsService, BlocksService $blocksService, MacrosService $macrosService, DataBinderInterface $dataBinder, InjectorInterface $injector, MatisseSettings $matisseSettings, ViewServiceInterface $viewService) { $this->tags = self::$coreTags; $this->dataBinder = $dataBinder; $this->assetsService = $assetsService; $this->blocksService = $blocksService; $this->macrosService = $macrosService; $this->injector = $injector; $this->viewService = $viewService; $this->matisseSettings = $matisseSettings; $this->presets = map($matisseSettings->getPresets(), function ($class) { return $this->injector->make($class); }); $matisseSettings->initContext($this); }
/** * @param string $rootDir */ private function setupDebugging($rootDir) { set_exception_handler([$this, 'exceptionHandler']); $devEnv = env('DEV'); $this->injector->defineParam('devEnv', $devEnv); $webConsole = env('CONSOLE'); $this->injector->defineParam('webConsole', $webConsole); ErrorConsole::init($devEnv, $rootDir); ErrorConsole::setAppName($this->kernelSettings->appName); // Note: the editorUrl can't be set yet. See: WebServer. $settings = new DebugConsoleSettings(); $settings->defaultPanelTitle = 'Inspector'; $settings->defaultPanelIcon = 'fa fa-search'; DebugConsole::init($devEnv, $settings); // Temporarily set framework path mapping here for errors thrown during modules loading. ErrorConsole::setPathsMap($this->kernelSettings->getMainPathMap()); }
/** * @param SymfonyConsole $app * @param string $className */ protected function mergeTasks($app, $className) { $commandNames = array_filter(get_class_methods($className), function ($m) use($className) { $method = new \ReflectionMethod($className, $m); return !in_array($m, ['__construct']) && !$method->isStatic(); // Reject constructors and static methods. }); $passThrough = $this->passThroughArgs; foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); $command->setCode(function (InputInterface $input, OutputInterface $output) use($className, $commandName, $passThrough) { // get passthru args $args = $input->getArguments(); array_shift($args); if ($passThrough) { $args[key(array_slice($args, -1, 1, true))] = $passThrough; } $args[] = $input->getOptions(); // Robo Command classes can access the current output via Config::get('output') // This output may have been customized for a specific command, usually when being run internally with // output capture. Config::setOutput($output); $roboTasks = $this->injector->make($className); $res = call_user_func_array([$roboTasks, $commandName], $args); // Restore the setting to the main output stream. Config::setOutput($this->io->getOutput()); if (is_int($res)) { return $res; } if (is_bool($res)) { return $res ? 0 : 1; } if ($res instanceof Result) { return $res->getExitCode(); } return $res; }); $app->add($command); } }
/** * Invokes a request handler. * * <p>The router does not call handlers directly; instead, it does it trough this method, so that calls can be * intercepted, validated and logged. * * > This method also functions as a router extension point. * * @param callable $handler * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable $next * @return ResponseInterface */ protected function callHandler(callable $handler, ServerRequestInterface $request, ResponseInterface $response, callable $next) { $this->currentRequestMutator->set($request); if ($handler instanceof RenderableInterface) { $class = $handler->getContextClass(); $handler->setContext($this->injector->make($class)); } /*try { $response = $handler ($request, $response, $next); } catch (HttpException $error) { // Convert HTTP exceptions to normal responses $msg = $error->getTitle () ?: str_segmentsFirst ($error->getMessage (), "\n"); // use only the first line of text return $response->withStatus ($error->getCode (), $msg); }*/ $response = $handler($request, $response, $next); if (!$response) { throw new \RuntimeException(sprintf("Request handler <span class=__type>%s</span> did not return a response.", Debug::getType($handler))); } if (!$response instanceof ResponseInterface) { throw new \RuntimeException(sprintf("Response from request handler <span class=__type>%s</span> is not a <span class=type>ResponseInterface</span> implementation.", Debug::getType($handler))); } return $response; }
/** * Retrieves a custom renderer instance for 'text/html' responses of a specific HTTP status code. * * @param int $status The HTTP status code. * @return RequestHandlerInterface|null */ function getCustomRenderer($status) { $renderer = get($this->customRenderers, $status); return $renderer ? $this->injector->make($renderer) : null; }
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) { if (!$this->webConsole) { // In case the middleware was registered. return $next(); } //------------------------------------------------------------------ /** @var ResponseInterface $response */ $response = $next(); $contentType = $response->getHeaderLine('Content-Type'); $status = $response->getStatusCode(); if ($status >= 300 && $status < 400 || $contentType && $contentType != 'text/html') { return $response; } $response->getBody()->rewind(); //------------------ // Logging panel //------------------ if (extension_loaded('xdebug')) { DebugConsole::defaultLogger()->write('<#alert><b>Warning:</b> When running with Xdebug enabled, the framework\'s performance is severely degraded, especially on debug mode.</#alert>' . '<p class=__comment>Refer to the framework\'s documentation for more information.</p>'); } //------------------ // Request panel //------------------ $log = DebugConsole::logger('request'); if (!$log->hasRequest()) { $log->setRequest($request); } //------------------ // Response panel //------------------ DebugConsole::logger('response')->setResponse($response); //------------------ // Routing panel //------------------ $router = $this->injector->make(ApplicationRouterInterface::class); $handlers = $router->__debugInfo()['handlers']; $rootR = $handlers ? implode('', map($handlers, function ($r) { return sprintf('<#row><#type>%s</#type></#row>', is_string($r) ? $r : typeOf($r)); })) : '<#i><i>empty</i></#i>'; $logger = $this->injector->make(RoutingLogger::class); $log = $logger->getContent(); DebugConsole::logger('routes')->write("<#section|REGISTERED ROUTERS>{$rootR}</#section>" . "<#section|APPLICATION MIDDLEWARE STACK ┊ RUN HISTORY>")->write($log)->write("<#row>Return from ")->typeName($this)->write("</#row>")->write("<#row><i>(log entries from this point on can't be displayed)</i></#row>")->write("</#indent>")->write("<#row>Exit stack 1</#row>")->write("<#row>End of routing log</#row>")->write("</#section>"); //------------------ // Navigation panel //------------------ if ($this->injector->provides(NavigationInterface::class)) { try { /** @var NavigationInterface $navigation */ $navigation = $this->injector->make(NavigationInterface::class); DebugConsole::logger('navigation')->withFilter(function ($k, $v, $o) use($navigation) { if ($k === 'parent' || $k === 'request') { return '...'; } if ($k === 'IDs' && $o != $navigation->rootLink()) { return '...'; } return true; }, $navigation); } catch (\Exception $e) { } } //------------------ // Config. panel //------------------ DebugConsole::logger('config')->inspect($this->kernelSettings); //------------------ // Session panel //------------------ if ($this->injector->provides(SessionInterface::class)) { DebugConsole::logger('session')->write('<button type="button" class="__btn __btn-default" style="position:absolute;right:5px;top:5px" onclick="location.href=\'logout\'">Log out</button>')->inspect($this->injector->make(SessionInterface::class)); } //------------------ // Tracing panel //------------------ $trace = DebugConsole::logger('trace'); if ($trace->hasContent()) { DebugConsole::registerPanel('trace', $trace); } return DebugConsole::outputContentViaResponse($request, $response, true); }
/** * @param InjectorInterface $injector * @return mixed A routable instance. */ function __invoke(InjectorInterface $injector) { return $injector->execute($this->fn); }