public function handle(IResource $resource, $mimeType = null)
 {
     if (!$this->canHandle($mimeType = $mimeType ?: $resource->getMimeType())) {
         throw new ResourceHandlerException(sprintf('Resource handler [%s] cannot handle resource type [%s].', static::class, $mimeType));
     }
     return $this->handler($resource);
 }
Ejemplo n.º 2
0
 protected function handler(IResource $resource)
 {
     $source = Neon::decode($resource->get());
     $root = new Node();
     $this->walk($source, $root);
     return $root;
 }
Ejemplo n.º 3
0
 public function render()
 {
     $template = new TempFile($cacheId = sha1($this->resource->getUri()));
     //			if (!$template->exists()) {
     $template->openForWrite();
     $template->write($this->cache->load($cacheId, function () use($cacheId) {
         $header = sprintf("<?php\n\t/**\n\t * stamp: %s\n\t *\n\t * layout:\n\t * %s", DateTimeUtils::from('now')->format('Y-m-d H:i:s'), $this->resource->getUri());
         if (!empty($this->resourceList)) {
             $header .= "\n\n\t * used templates:";
         }
         foreach ($this->resourceList as $resource) {
             $header .= "\n\t * - " . $resource->getUri() . "\n";
         }
         $header .= "\t */\n?>\n";
         return $this->cache->save($cacheId, $header . $this->compile());
     }));
     $template->close();
     //			}
     call_user_func(function () use($template) {
         require_once $template->getFullFileName();
     });
 }
Ejemplo n.º 4
0
 /**
  * @return string
  */
 public function getUri()
 {
     return $this->resource->getUri();
 }
Ejemplo n.º 5
0
 public function addResource(IResource $resource, $required = true)
 {
     $this->resourceList[$resource->getUri()] = [$resource, $required];
     return $this;
 }