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 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 boot($rootDir, $urlDepth = 0, callable $onStartUp = null)
 {
     $rootDir = normalizePath($rootDir);
     // Initialize some settings from environment variables
     $dotenv = new Dotenv("{$rootDir}/.env");
     try {
         $dotenv->load();
     } catch (ConfigException $e) {
         echo $e->getMessage();
         return 1;
     }
     // Load the kernel's configuration.
     /** @var KernelSettings $kernelSettings */
     $kernelSettings = $this->kernelSettings = $this->injector->share(KernelSettings::class, 'app')->make(KernelSettings::class);
     $kernelSettings->isWebBased = true;
     $kernelSettings->setApplicationRoot($rootDir, $urlDepth);
     // Setup debugging (must be done before instantiating the kernel, but after instantiating its settings).
     $this->setupDebugging($rootDir);
     // Boot up the framework's kernel.
     $this->injector->execute([KernelModule::class, 'register']);
     // Boot up the framework's subsytems and the application's modules.
     /** @var KernelInterface $kernel */
     $kernel = $this->injector->make(KernelInterface::class);
     if ($onStartUp) {
         $onStartUp($kernel);
     }
     // Boot up all modules.
     try {
         $kernel->boot();
     } catch (ConfigException $e) {
         $NL = "<br>\n";
         echo $e->getMessage() . $NL . $NL;
         if ($e->getCode() == -1) {
             echo sprintf('Possile error causes:%2$s%2$s- the class name may be misspelled,%2$s- the class may no longer exist,%2$s- module %1$s may be missing or it may be corrupted.%2$s%2$s', str_match($e->getMessage(), '/from module (\\S+)/')[1], $NL);
         }
         $path = "{$kernelSettings->storagePath}/" . ModulesRegistry::REGISTRY_FILE;
         if (file_exists($path)) {
             echo "Tip: one possible solution is to remove the '{$path}' file and run 'workman' to rebuild the module registry.";
         }
     }
     // Finalize.
     if ($kernel->devEnv()) {
         $this->setDebugPathsMap($this->injector->make(ModulesRegistry::class));
     }
     return $kernel->getExitCode();
 }
 /**
  * @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 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 &nbsp;┊&nbsp; 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);
 }