示例#1
0
文件: Kernel.php 项目: koolkode/k2
 public function __construct($contextName = 'development')
 {
     if (static::$containerStack === NULL) {
         static::$containerStack = new \SplStack();
     }
     $this->contextName = (string) $contextName;
     $this->directory = rtrim(str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $this->setupRootDirectory()), '/\\');
     $this->cacheDirectory = rtrim(str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $this->setupCacheDirectory()), '/\\');
     if ($this->projectDirectory === NULL) {
         $this->projectDirectory = $this->directory;
     }
     $this->komponents = new KomponentLoader();
     $this->komponents->registerKomponent(new Komponent());
     // Enable k2:// stream wrapper.
     ResourceStreamWrapper::register($this);
     $this->registerKomponents($this->komponents);
     $this->cache = $this->createKernelCache();
     $this->initialize();
 }
示例#2
0
 /**
  * Handle incoming HTTP request using K2.
  * 
  * Will display alittl info page when no Komponent has been found.
  */
 public function handleHttpRequest()
 {
     $this->system->launch();
     $request = $this->system->getTestkernel()->getEnvironment()->buildHttpRequest();
     // Display index page when no path info is given.
     if ($request->getPathInfo() === '') {
         header('Content-Type: text/html; charset="utf-8"');
         $settings = $this->settings;
         $settings['directory'] = str_replace('\\', '/', $settings['directory']);
         $settings['root'] = str_replace('\\', '/', $this->system->getTestKernel()->getDirectory());
         $composerFile = $this->system->getSystemDirectory() . DIRECTORY_SEPARATOR . 'composer.json';
         $params = ['system' => $this->system, 'ref' => new \ReflectionClass(get_class($this->system)), 'settings' => $settings, 'composerFile' => $composerFile, 'composerConfig' => json_decode(file_get_contents($composerFile), true), 'config' => $this->system->getSystemConfig()];
         call_user_func(function (array $__) {
             extract($__, EXTR_SKIP);
             require ResourceStreamWrapper::resolve('k2://koolkode/k2/index.phtml');
         }, $params);
         exit;
     }
     $this->system->getTestkernel()->handleWeb($request, true);
 }
 protected function resolveResourcePath($resource)
 {
     return ResourceStreamWrapper::resolve($resource);
 }