Example #1
0
 /**
  * Defines, processes and writes the File(s) derived from $data.
  *
  * @param array $data
  *   The data from which to generate new DefinitionInterface object(s).
  * @param ProcessorInterface $processor
  *   The processor to turn DefinitionInterface object(s) into File(s).
  */
 public function build(array $data, ProcessorInterface $processor)
 {
     $classes = [];
     foreach ($this->getDefinitionClasses() as $definitionClass) {
         /** @var $definitionClass \Classiphpy\Definition\DefinitionInterface */
         $classes += $definitionClass::iteratorFactory($data);
     }
     $this->getOutputMethod()->writeOut($processor->process($classes, $data));
     /* @todo determine how to define success/failure and return a boolean, or some message stack */
 }
 /**
  * {@inheritdoc}
  */
 public function process(array $classes, array $data)
 {
     $file = new File('composer', 'json', '');
     /** @var \Classiphpy\Definition\DefinitionInterface $class */
     $dependencies = [];
     foreach ($classes as $class) {
         $dependencies += $class->getDependencies();
     }
     $composer = ['name' => $this->name, 'license' => $this->license];
     if ($dependencies) {
         $composer['require'] = $dependencies;
     }
     $file->setContents(json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
     $files = $this->processor->process($classes, $data);
     $files['composer'] = $file;
     return $files;
 }