Example #1
0
 public static function fromDirective(Directive $directive)
 {
     $results = new static();
     foreach ($directive->getChildScope()->getDirectives() as $subDirective) {
         $results[$subDirective->getName()] = $subDirective->getValue();
     }
     return $results;
 }
Example #2
0
 private function process_directive($line)
 {
     $directives = array('require ' => new RequireFile($this->manifest_file), 'require_directory' => new RequireDirectory($this->manifest_file), 'require_tree' => new RequireTree($this->manifest_file), 'require_self' => new RequireSelf($this->manifest_file));
     foreach ($directives as $directive_name => $directive) {
         $param = $this->get_directive_param($directive_name, $line);
         if (!is_null($param)) {
             return $directive->process($param);
         }
     }
     $directive = new Directive($this->manifest_file);
     return $directive->process_basic($line);
 }
Example #3
0
 function add(Directive $directive)
 {
     $expectations = $directive->pattern()->expected()->all();
     foreach ($expectations as $expected) {
         if ($v = (string) $expected) {
             $this->raytraceLiteral[$v] = true;
         } else {
             $this->raytraceNonliteral[$expected->type()] = true;
         }
     }
     $this->directives[$directive->pattern()->specificity()][$directive->id()] = $directive;
     krsort($this->directives);
 }
 private static function newDirectiveWithoutScope($nameString, Text $configString)
 {
     $configString->inc();
     list($name, $value) = self::processText($nameString);
     $directive = new Directive($name, $value);
     $comment = self::checkRestOfTheLineForComment($configString);
     if (false !== $comment) {
         $directive->setComment($comment);
     }
     return $directive;
 }
Example #5
0
 /**
  * Set parent directive for this Scope.
  *
  * Sets parent directive for this Scope and also
  * sets the $parentDirective->setChildScope($this)
  *
  * @param Directive $parentDirective
  * @return $this
  */
 public function setParentDirective(Directive $parentDirective)
 {
     $this->parentDirective = $parentDirective;
     if ($parentDirective->getChildScope() !== $this) {
         $parentDirective->setChildScope($this);
     }
     return $this;
 }
Example #6
0
 function add(Directive $directive)
 {
     $this->directives[$directive->specificity()][] = $directive;
     krsort($this->directives);
 }
Example #7
0
 /**
  * Register a new directive handler
  *
  * @param $directive a directive handler
  */
 protected function registerDirective(Directive $directive)
 {
     $this->directives[$directive->getName()] = $directive;
 }
Example #8
0
 public function __toString()
 {
     $server = Directive::create('server');
     $childScope = Scope::create();
     foreach ($this->directives as $key => $value) {
         $childScope->addDirective(Directive::create($key, $value));
     }
     $server->setChildScope($childScope);
     foreach ($this->locations as $url => $location) {
         if ($location === null || !$location instanceof Location) {
             throw new \RuntimeException(sprintf('expected %s but got %s', Location::class, gettype($location)));
         }
         $directive = Directive::create('location', $url);
         $locationChildScope = Scope::create();
         foreach ($location as $key => $value) {
             if (!is_array($value)) {
                 $locationChildScope->addDirective(Directive::create($key, $value));
                 continue;
             }
             foreach ($value as $item) {
                 $locationChildScope->addDirective(Directive::create($key, $item));
             }
         }
         $directive->setChildScope($locationChildScope);
         $childScope->addDirective($directive);
     }
     return (string) Scope::create()->addDirective($server);
 }
 public function testCreate()
 {
     $config_string = (string) Scope::create()->addDirective(Directive::create('server')->setChildScope(Scope::create()->addDirective(Directive::create('listen', 8080))->addDirective(Directive::create('server_name', 'example.net'))->addDirective(Directive::create('root', 'C:/www/example_net'))->addDirective(Directive::create('location', '^~ /var/', Scope::create()->addDirective(Directive::create('deny', 'all')))->setCommentText('Deny access for location /var/'))))->__toString();
     $this->assertEquals($config_string, @file_get_contents('tests/scope_create_output.conf'));
 }