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); }
protected function handler(IResource $resource) { $source = Neon::decode($resource->get()); $root = new Node(); $this->walk($source, $root); return $root; }
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(); }); }
/** * @return string */ public function getUri() { return $this->resource->getUri(); }
public function addResource(IResource $resource, $required = true) { $this->resourceList[$resource->getUri()] = [$resource, $required]; return $this; }