Esempio n. 1
0
 /**
  *  Compile a Composite
  *
  *  @access public
  *  @param CompositeInterface $composite
  */
 public function compile(CompositeInterface $composite)
 {
     $composite->acceptVisitor($this->graphVisitor);
     $this->setGraph($this->graphVisitor->getResult());
     foreach ($this->passes as $pass) {
         $pass->process($composite, $this);
     }
     return $composite;
 }
 /**
  *  Create a path from the root node to the present node
  *
  *  @access public
  *  @return string the path
  */
 static function buildPath(CompositeInterface $node)
 {
     $paths = array();
     $paths[] = $node->getId();
     # build path from current node to root
     do {
         $node = $node->getParent();
         if ($node instanceof CompositeInterface) {
             $paths[] = $node->getId();
         }
     } while ($node instanceof CompositeInterface);
     # reverse path to get from schema to current node.
     array_reverse($paths);
     return $paths;
 }
Esempio n. 3
0
 /**
  *  Will inject a locale into composite, which locale is
  *  decided by the composite locale option.
  *
  *  @access public
  *  @para CompositeInterface $composite
  */
 public function visitLocaleInjector(CompositeInterface $node)
 {
     if ($node instanceof TypeInterface) {
         # whats the locale
         $locale = $node->getOption('locale');
         if (empty($locale)) {
             throw new CompositeException($node, 'Locale is empty');
         } else {
             # fetch flywight from factory
             $locale = $this->factory->create($locale);
         }
         # assign to the composite
         $node->setLocale($locale);
     }
     return $node;
 }
 public function visitDirectedGraphBuilder(CompositeInterface $composite)
 {
     $builder = $this->pathBuilder;
     $parentNode = $composite->getParent();
     if ($composite instanceof SchemaNode) {
         $this->graph->setRoot($composite);
     } elseif ($composite instanceof TableNode) {
         # if we have a table connect to schema
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof ColumnNode) {
         # if instance of column connect to table
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof FormatterNode) {
         # if instance of formatterNode connect to schema
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($parentNode), $parentNode);
     } elseif ($composite instanceof ForeignKeyNode) {
         # if have a fk connect two columns and tables as well as the FKNode to FKColumn
         $finder = new CompositeFinder();
         $parentTable = $finder->set($composite)->parentTable()->get();
         $parentColumn = $finder->set($composite)->parentColumn()->get();
         $fkTableName = $composite->getOption('foreignTable');
         $fkColumnName = $composite->getOption('foreignColumn');
         $fkTable = $finder->set($composite)->table($fkTableName)->get();
         # Does the foreign table exist
         if ($fkTable === null) {
             throw new CompositeException($composite, sprintf('The Foreign Table %s does not exist', $fkTableName));
         }
         # match the column
         $fkColumn = $finder->set($composite)->table($fkTableName)->column($fkColumnName)->get();
         if ($fkColumn === null) {
             return new CompositeException($composite, sprintf('The Foreign Column %s.%s does not exist', $fkTableName, $fkColumnName));
         }
         # a Column could be related to many others for examaple as a composite primary key so
         # the ResultCache can't be attached to a column but instead to the ForeignKeyNode child of the column
         $this->graph->connect($builder->buildPath($composite), $composite, $builder->buildPath($fkColumn), $fkColumn);
         # connect the two columns for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentColumn), $parentColumn, $builder->buildPath($fkColumn), $fkColumn);
         # tables are now related connect them for easy lookup for Circular Reference checks
         $this->graph->connect($builder->buildPath($parentTable), $parentTable, $builder->buildPath($fkTable), $fkTable);
     }
 }
Esempio n. 5
0
 protected function buildDirectedGraph(CompositeInterface $com)
 {
     $visitor = new DirectedGraphVisitor(new DirectedGraph(), new PathBuilder());
     $com->acceptVisitor($visitor);
     return $visitor->getResult();
 }
Esempio n. 6
0
 public function addChild(CompositeInterface $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
 }
 /**
  *  Will inject Cache into the composite
  *
  *  The References should be valid as
  *  missing ones will not cause error, run KeysExistPass first
  *
  *  @param CompositeInterface $composite
  *  @param Compiler $cmp
  */
 public function process(CompositeInterface $composite, CompilerInterface $cmp)
 {
     $composite->acceptVisitor($this->visitor);
 }
 public function visitGeneratorInjector(CompositeInterface $composite)
 {
     $seed = null;
     if ($composite instanceof SchemaNode) {
         # use the schema setting or keep the default global
         if ($composite->hasOption('randomGenerator') === true) {
             if ($composite->hasOption('generatorSeed') === true) {
                 $seed = $composite->getOption('generatorSeed');
             }
             # re-assign the global
             $this->headGenerator = $this->factory->create($composite->getOption('randomGenerator'), $seed);
         }
         # assign schema the default generator or the custom just setup above
         $composite->setGenerator($this->headGenerator);
     } else {
         # use the schema setting or keep the default global
         if ($composite->hasOption('randomGenerator') === true) {
             if ($composite->hasOption('generatorSeed') === true) {
                 $seed = $composite->getOption('generatorSeed');
             }
             # re-assign the global
             $this->headGenerator = $this->factory->create($composite->getOption('randomGenerator'), $seed);
         } else {
             $this->headGenerator = $composite->getParent()->getGenerator();
         }
         # re-assign the global
         $composite->setGenerator($this->headGenerator);
     }
 }
Esempio n. 9
0
 /**
  *  Set the composite Schema with new Table order
  *
  *  @access public
  *  @param CompositeInterface $composite
  *  @param array $order the node list
  */
 public function sortComposite(CompositeInterface $composite, array $order)
 {
     $composite->clearChildren();
     foreach ($order as $node) {
         $composite->addChild($node->getValue());
     }
 }
 public function visitDBALGatherer(CompositeInterface $node)
 {
     if ($node instanceof DBALTypeInterface) {
         $this->valueConverter->set($node->getId(), $node->getDBALType());
     }
 }