コード例 #1
0
 /**
  * add InnerDirective in iInnerDirectiveAble
  * @param iDirective $directive
  * @throws NotAllowedContextException
  */
 public function appendInnedDirective(iDirective $directive)
 {
     if ($directive->getContext() !== $this) {
         throw new NotAllowedContextException("trying add inner directive in {$this->getName()} with context of another directive");
     }
     $this->innerDirectives[] = $directive;
 }
コード例 #2
0
 /**
  * detach innerDirective from iInnerDirectiveAble
  * @param iDirective $directive
  * @throws NotAllowedContextException
  */
 public function detachInnerDirective(iDirective $directive)
 {
     if ($this !== $directive->getContext()) {
         throw new NotAllowedContextException("Trying to detach from {$this->getName()} directive {$directive->getContext()} which is not its context");
     }
     foreach ($this->innerDirectives as $key => $innerDirective) {
         if ($directive === $innerDirective) {
             unset($this->innerDirectives[$key]);
         }
     }
 }
コード例 #3
0
 /**
  * converts directive object to plain with its inner directives as plain too
  * @param iDirective $directive
  * @param int $nestLevel
  * @return array
  */
 protected function directiveToPlain(iDirective $directive, $nestLevel = 0)
 {
     $tabulation = $nestLevel > 0 ? str_repeat("  ", $nestLevel) : "";
     if ($directive->isSection()) {
         $directiveText = $this->customFilter($directive, "<{$directive->getName()} {$directive->getValue()}>");
         $directivePlain = $tabulation . $directiveText . "\n";
         foreach ($directive->getInnerDirectives() as $innerDirective) {
             $directivePlain .= $this->directiveToPlain($innerDirective, $nestLevel + 1);
         }
         $directivePlain .= $tabulation . "</{$directive->getName()}>\n";
     } else {
         $directiveText = $this->customFilter($directive, "{$directive->getName()} {$directive->getValue()}");
         $directivePlain = $tabulation . $directiveText . "\n";
     }
     return $directivePlain;
 }