Example #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);
 }
Example #2
0
 /**
  * 新しいチャイルドスコープを取得する
  */
 public function newScope($name = "child")
 {
     return Scope::create($this, $name);
 }
Example #3
0
 /**
  * マジック
  *
  * @covers ::__call
  * @covers ::hasComponent
  * @covers ::hasHelper
  * @covers ::initScopeComponents
  * @covers ::initScopeHelpers
  * @covers Nora\Core\Scope\Exception\InvalidMethodCalled::__construct
  * @expectedException Nora\Core\Scope\Exception\InvalidMethodCalled
  */
 public function testCall()
 {
     $s = Scope::create(null, 'parent')->setComponent('hoge', function () {
         return new \StdClass();
     })->setHelper('fuga', function () {
         return 'a';
     });
     $this->assertInstanceOf('StdClass', $s->newScope()->hoge());
     $this->assertEquals('a', $s->newScope()->fuga());
     $s->hogeho();
 }
 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'));
 }