From aa8f070a007e21714d261f5184b3edd84dd9acf3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 4 Feb 2019 13:47:22 +0100 Subject: [PATCH] BpConfig: Don't die due to circular references --- library/Businessprocess/BpConfig.php | 36 ++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/library/Businessprocess/BpConfig.php b/library/Businessprocess/BpConfig.php index 6fdc733..3a41eba 100644 --- a/library/Businessprocess/BpConfig.php +++ b/library/Businessprocess/BpConfig.php @@ -437,13 +437,18 @@ class BpConfig return $this->nodes; } - public function hasNode($name) + public function hasNode($name, &$usedConfigs = null) { if (array_key_exists($name, $this->nodes)) { return true; } elseif (! empty($this->importedConfigs)) { + $usedConfigs[$this->getName()] = true; foreach ($this->importedConfigs as $config) { - if ($config->hasNode($name)) { + if (isset($usedConfigs[$config->getName()])) { + continue; + } + + if ($config->hasNode($name, $usedConfigs)) { return true; } } @@ -498,12 +503,17 @@ class BpConfig return $this; } - public function listInvolvedHostNames() + public function listInvolvedHostNames(&$usedConfigs = null) { $hosts = $this->hosts; if (! empty($this->importedConfigs)) { + $usedConfigs[$this->getName()] = true; foreach ($this->importedConfigs as $config) { - $hosts += array_flip($config->listInvolvedHostNames()); + if (isset($usedConfigs[$config->getName()])) { + continue; + } + + $hosts += array_flip($config->listInvolvedHostNames($usedConfigs)); } } @@ -590,11 +600,12 @@ class BpConfig } /** - * @param $name - * @return Node - * @throws Exception + * @param string $name + * @param array $usedConfigs + * @return Node + * @throws Exception */ - public function getNode($name) + public function getNode($name, &$usedConfigs = null) { if ($name === '__unbound__') { return $this->getUnboundBaseNode(); @@ -603,9 +614,14 @@ class BpConfig if (array_key_exists($name, $this->nodes)) { return $this->nodes[$name]; } elseif (! empty($this->importedConfigs)) { + $usedConfigs[$this->getName()] = true; foreach ($this->importedConfigs as $config) { - if ($config->hasNode($name)) { - return $config->getNode($name); + if (isset($usedConfigs[$config->getName()])) { + continue; + } + + if ($config->hasNode($name, $usedConfigs)) { + return $config->getNode($name, $usedConfigs); } } }