Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezptopologicalsort.php
Go to the documentation of this file.
1 <?php
15 class ezpTopologicalSort
16 {
17 protected $nodes = array();
18
37 function __construct( $dependencies = array() )
38 {
39 foreach ( $dependencies as $dependency => $modules ) {
40 if (! isset( $this->nodes[$dependency] ) )
41 $this->nodes[$dependency] = new ezpTopologicalSortNode( $dependency );
42 foreach ( (array) $modules as $module ) {
43 if (! isset( $this->nodes[$module] ) )
44 $this->nodes[$module] = new ezpTopologicalSortNode( $module );
45 $this->nodes[$module]->registerChild( $this->nodes[$dependency] );
46 $this->nodes[$dependency]->registerParent( $this->nodes[$module] );
47 }
48 }
49 }
50
56 function sort()
57 {
58 $rootNodes = $this->getRootNodes();
59
60 $sorted = array();
61 while ( count( $this->nodes ) > 0 ) {
62 // check for circular reference
63 if ( count( $rootNodes ) === 0 )
64 return false;
65
66 // remove this node from rootNodes and add it to the output
67 $current = array_shift( $rootNodes );
68 $sorted[] = $current->name;
69
70 // for each of its children queue the new node and remove the original
71 while ( $child = $current->popChild() )
72 {
73 $child->unregisterParent( $this->nodes[$current->name] );
74 // if this child has no more parents, add it to the root nodes list
75 if ( $child->parentCount() === 0 )
76 $rootNodes[] = $child;
77 }
78
79 unset( $this->nodes[$current->name] );
80 }
81 return $sorted;
82 }
83
89 private function getRootNodes()
90 {
91 $output = array();
92 foreach( $this->nodes as $node )
93 if (! $node->parentCount() )
94 $output[] = $node;
95 return $output;
96 }
97 }
98 ?>
$modules
foreach( $categories as $category) $modules
Definition: bugedit.php:496
$module
$module
Definition: classes/admin/linkselect.php:219
ezpTopologicalSortNode
Definition: ezptopologicalsortnode.php:18
ezpTopologicalSort
Definition: ezptopologicalsort.php:16
ezpTopologicalSort\sort
sort()
Definition: ezptopologicalsort.php:56
ezpTopologicalSort\__construct
__construct( $dependencies=array())
Definition: ezptopologicalsort.php:37
ezpTopologicalSort\$nodes
$nodes
Definition: ezptopologicalsort.php:17
ezpTopologicalSort\getRootNodes
getRootNodes()
Definition: ezptopologicalsort.php:89
$output
$output
Definition: formpreview.php:81
$current
$current
Definition: slideshow.php:97
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.