/** * @param iDirectivePath $directivePath * @param bool $throwException * @return iDirective|null * @throws NotFoundDirectiveException */ public function findByPath(iDirectivePath $directivePath, $throwException = false) { foreach ($this->iterateChildren() as $directive) { if ($directivePath->comparePath($directive->getPath())) { return $directive; } } if ($throwException) { $path = json_encode($directivePath->getPath()); throw new NotFoundDirectiveException("Directive by path does not exist: {$path}"); } return null; }
/** * Compare this iDirectivePath with another * @param iDirectivePath $directivePath * @return boolean true if paths identical */ public function comparePath(iDirectivePath $directivePath) { return $this->getArrayHash($this->getPath()) == $this->getArrayHash($directivePath->getPath()); }