Beispiel #1
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'));
 }