コード例 #1
0
 /**
  *  Change the order of the tables to use Topological Order
  *
  *  @access public
  *  @param CompositeInterface $compiler
  *  @param CompilerInterface  $cmp
  *  @link using breath search algorithm first http://en.wikipedia.org/wiki/Topological_sorting
  */
 public function process(CompositeInterface $composite, CompilerInterface $cmp)
 {
     $graph = $cmp->getGraph();
     # Find table nodes with no out-edges.
     foreach ($graph->getNodes() as $node) {
         if ($node->getValue() instanceof TableNode || $node->getValue() instanceof FormatterNode) {
             $tmp_nodes = $node->getOutEdges();
             $table_node_count = 0;
             # count how many outer edges are just tables
             foreach ($tmp_nodes as $tmpnode) {
                 if ($tmpnode->getDestNode()->getValue() instanceof TableNode || $tmpnode->getDestNode()->getValue() instanceof FormatterNode) {
                     $table_node_count += 1;
                 }
             }
             # test if no tables found in outer edges
             if ($table_node_count === 0) {
                 $this->nodesNoOutEdges[] = $node;
             }
             $tmp_nodes = null;
         }
     }
     # Call breath first search on each table node with no outer-edges
     # As we have a directed acyclic graph there is guarantee of minimum 1 node without outer-edges.
     foreach ($this->nodesNoOutEdges as $node) {
         $this->visitNode($node);
     }
     $this->sortComposite($composite, $this->newOrder);
     # clear for another possible pass
     $this->clear();
 }
コード例 #2
0
 /**
  *  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 CompilerInterface  $cmp
  */
 public function process(CompositeInterface $composite, CompilerInterface $cmp)
 {
     # find nodes that are Columns
     foreach ($cmp->getGraph()->getNodes() as $node) {
         $compositeNode = $node->getValue();
         if ($compositeNode instanceof ColumnNode) {
             $innerEdges = $node->getInEdges();
             $cache = new GeneratorCache();
             //once cache per column
             #assign cache to foreign keys assocaited with this column.
             foreach ($innerEdges as $inEdge) {
                 $compositeType = $inEdge->getSourceNode()->getValue();
                 if ($compositeType instanceof ForeignKeyNode) {
                     # set the cache if the silent option not true
                     # if all relations are set to silent no cache
                     # will be set on the original Column.
                     if ($compositeType->getUseCache() === true) {
                         $compositeType->setResultCache($cache);
                         # assign cache to column that assigned to the FK
                         # do it here as don't know if a column has foreignkeys
                         # until matched.
                         if ($compositeNode->getResultCache() === null) {
                             $compositeNode->setResultCache($cache);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
 /**
  *  Will Check the relationships for Circular References 
  *
  *  The References should be valid as
  *  missing ones will not cause error, run KeysExistPass first
  *
  *  A circular reference means that b requires a and a requires b and impossible situation or
  *  a requires b and requires c but c requires a, a giant circle.
  *
  *  @param CompositeInterface $composite
  *  @param CompilerInterface $cmp
  */
 public function process(CompositeInterface $composite, CompilerInterface $cmp)
 {
     $graph = $cmp->getGraph();
     foreach ($graph->getNodes() as $id => $node) {
         $this->current_id = $id;
         $this->current_path = array($id);
         $this->checkOutEdges($node->getOutEdges());
     }
 }
コード例 #4
0
 /**
  *  Builds a SchemaNode
  *
  *  @access public
  *  @return Faker\Components\Engine\DB\Composite/SchemaNode
  */
 public function end()
 {
     $node = $this->getNode();
     $children = $this->children();
     $compiiler = $this->compiler;
     foreach ($children as $child) {
         $node->addChild($child);
     }
     # run validation routines
     $this->event->dispatch(BuildEvents::onValidationStart, new BuildEvent($this, 'Started validation of entity ' . $this->name));
     $node->validate();
     $this->event->dispatch(BuildEvents::onValidationEnd, new BuildEvent($this, 'Finished validation of entity ' . $this->name));
     # run compiler
     $this->event->dispatch(BuildEvents::onCompileStart, new BuildEvent($this, 'Started compile of entity ' . $this->name));
     $this->compiler->compile($node);
     $this->event->dispatch(BuildEvents::onCompileEnd, new BuildEvent($this, 'Finished compile of entity ' . $this->name));
     $this->event->dispatch(BuildEvents::onBuildingEnd, new BuildEvent($this, 'Finished build of entity ' . $this->name));
     return $node;
 }