/** * @param string $path The path of the DAL to load. * @param string[] $stack The stack of paths that have been loaded since the current call. * * @throws \Exception * * @return AbstractDal */ private function doLoad($path, array $stack) { if (!isset($this->layers[$path])) { if ($this->isDebug || !file_exists($this->getFilename($path))) { $file = $this->repository->get($path); if (!$file instanceof FileResource) { throw new \Exception(sprintf('The path "%s" should reference a file.', $path)); } $ast = $this->syntax->read($file->getBody(), ['path' => $path]); $compiler = new Compiler(); $compiler->compile($ast['definition']); $this->filesystem->dumpFile($this->getMetaFilename($path), serialize($ast['metadata'])); $this->filesystem->dumpFile($this->getFilename($path), $compiler->getSource()); } $this->layers[$path] = $this->loadLayerAndCheck($path, $stack); } return $this->layers[$path]; }
/** * {@inheritdoc} */ public function compile(Compiler $compiler) { $compiler->write('/**')->write(' * This file has been generated by Phn and should not be edited by hand.')->write(' * Just don\'t do it. I dare you! I double dare you!')->write(' *')->write(' * @author Phn <*****@*****.**>')->write(' */')->write('return new class($mapper, $blueprint) extends \\Phn\\Dal\\Language\\AbstractDal')->write('{')->indent()->write('/**')->write(' * Constructor.')->write(' *')->write(' * @param \\Phn\\Mapping\\HierarchicalMapper $mapper')->write(' * @param \\Phn\\Dal\\HierarchicalBlueprint $blueprint')->write(' */')->write('public function __construct(\\Phn\\Mapping\\HierarchicalMapper $mapper, \\Phn\\Dal\\HierarchicalBlueprint $blueprint)')->write('{')->indent()->each($this->definition, function (NodeInterface $definition) use($compiler) { $compiler->compile($definition)->nl(); })->write('parent::__construct($blueprint);')->outdent()->write('}')->outdent()->write('};'); }