Example #1
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->raw('new \\')->raw($this->class)->raw('(')->each($this->arguments, function ($argument, Loop $loop) use($compiler) {
         $compiler->repr($argument);
         if ($loop->isNotLast()) {
             $compiler->raw(', ');
         }
     })->raw(')');
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->write('$mapper->setCompositeType(')->string($this->typeName)->raw(', ')->repr($this->definition['mapping'])->raw(', ')->run(function () use($compiler) {
         $normalizer = null;
         if (isset($this->definition['options']['normalizer'])) {
             $normalizer = $this->definition['options']['normalizer'];
         }
         $compiler->repr($normalizer);
     })->raw(');');
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->write('$blueprint->setTemplate(')->string($this->templateName)->raw(', new \\Phn\\Dal\\Template(')->indent()->write('[')->indent()->each($this->arguments, function ($argument, Loop $loop) use($compiler) {
         $compiler->write('')->string($argument['argument'])->raw(' => ');
         if (isset($argument['default'])) {
             $compiler->raw('new \\Phn\\Dal\\Argument\\ArgumentWithDefault(')->string($argument['type'])->raw(', ')->compile($argument['default'])->raw(')');
         } else {
             $compiler->raw('new \\Phn\\Dal\\Argument\\Argument(')->string($argument['type'])->raw(')');
         }
         if ($loop->isNotLast()) {
             $compiler->raw(',');
         }
     })->outdent()->write('],')->write('')->compile($this->body)->outdent()->write('));');
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->write('$blueprint->setFunction(')->string($this->functionName)->raw(', new \\Phn\\Dal\\Func(')->indent()->write('[')->indent()->each($this->arguments, function ($argument, Loop $loop) use($compiler) {
         $compiler->write('')->string($argument['argument'])->raw(' => ');
         if (isset($argument['default'])) {
             $compiler->raw('new \\Phn\\Dal\\Argument\\ArgumentWithDefault(')->string($argument['type'])->raw(', ')->compile($argument['default'])->raw(')');
         } else {
             $compiler->raw('new \\Phn\\Dal\\Argument\\Argument(')->string($argument['type'])->raw(')');
         }
         if ($loop->isNotLast()) {
             $compiler->raw(',');
         }
     })->outdent()->write('],')->write('')->compile($this->body)->raw(',')->write('new \\Phn\\Dal\\ExecutionStrategy\\ReturnExpr(')->string($this->returnExpr['expr'])->raw(', ')->repr($this->returnExpr['field'] ?? null)->raw(', ')->repr($this->returnExpr['type'] ?? null)->raw(')')->outdent()->write('));');
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->write('$mapper->export(')->string($this->resourceName)->runIf($this->alias !== null, function () use($compiler) {
         $compiler->raw(', ')->string($this->alias);
     })->raw(');');
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->repr($this->value);
 }
Example #7
0
 /**
  * @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];
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function compile(Compiler $compiler)
 {
     $compiler->raw('function (\\Phn\\Template\\Environment $env, array $context = [], array $blocks = []) {')->indent()->write('$fragments = [];')->nl()->compile($this->root)->nl()->write('return new \\Phn\\Fragment\\Node($fragments);')->outdent()->write('}');
 }
Example #9
0
 /**
  * {@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('};');
 }