Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/patientapps_support/modules/pkpCore/model/ |
Upload File : |
<?php
// Dependency management
// based loosely on https://www.electricmonk.nl/log/2008/08/07/dependency-resolving-algorithm/
class dependency_node {
private $resolved;
private $unresolved;
function __construct($name, $object) {
$this->name = $name;
$this->edges = [];
$this->resolved = 0;
$this->unresolved = 0;
$this->payload = $object;
}
function addEdge($node) { // $this->addEdge($node). '$this' depends on '$node'
$this->edges[] = $node;
}
function resolved() {
if (func_num_args()) {
$this->resolved = func_get_arg(0);
return $this;
} else {
return $this->resolved;
}
}
function unresolved() {
if (func_num_args()) {
$this->unresolved = func_get_arg(0);
return $this;
} else {
return $this->unresolved;
}
}
}
class DependencyManager {
private $main;
private $dependencycheck = TRUE;
function __construct() {
$this->main = new dependency_node('*', NULL); // main "dependency" depends on everything
}
public function Add($object) { // $object->tag = name of module, $object->depends = array of modules it depends on
$name = $object->tag();
if ($name == '') $name = 'node' . mt_rand(100000, 999999);
$node = new dependency_node($name, $object);
$this->main->addEdge($node);
$object->x_node = $node;
}
function getNodeByTag($tag) {
foreach($this->main->edges as $edge) {
if ($edge->name == $tag) return $edge;
}
return NULL;
}
// now that all objects have been added, we can look at the dependencies
private function _AddDependencies() {
foreach($this->main->edges as $source_node) {
$depends = $source_node->payload->depends();
foreach($depends as $depends_on) {
$tag = $source_node->payload->tag();
if ($depends_on != $tag) {
$parent = $this->getNodeByTag($depends_on);
if ($parent !== NULL) {
$source_node->addEdge($parent);
}
}
}
}
}
private function _resolve($node, &$resolved) {
$node->unresolved(TRUE);
foreach($node->edges as $edge) {
if (!$edge->resolved()) {
if ($edge->unresolved()) die("\ncircular reference: {$node->name} -> {$edge->name}\n");
$this->_resolve($edge, $resolved);
}
}
$node->resolved(TRUE)->unresolved(FALSE);
$resolved[] = $node;
}
public function Resolve() {
// add dependencies
if ($this->dependencycheck) {
$this->_AddDependencies();
$this->dependencycheck = FALSE;
}
// Resolve
$resolved = [];
$this->_resolve($this->main, $resolved);
$output = [];
foreach($resolved as $node) {
$output[] = $node->payload;
}
return $output;
}
}