Exemple #1
0
 public function testParseServerArray()
 {
     $server = array('HTTP_HOST' => 'aether.raymond.raw.no', 'SERVER_NAME' => 'aether.raymond.raw.no', 'SERVER_PORT' => 80, 'AUTH_TYPE' => 'Basic', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/foobar/hello?foo', 'SCRIPT_NAME' => '/deployer.php', 'PHP_SELF' => '/deployer.php', 'REQUEST_TIME' => 1170332549);
     $parser = new AetherUrlParser();
     $parser->parseServerArray($server);
     $this->assertEquals($parser->get('scheme'), 'http');
     $this->assertEquals($parser->get('path'), '/foobar/hello');
     $server['PHP_AUTH_USER'] = '******';
     $server['PHP_AUTH_PW'] = 'bar';
     $parser->parseServerArray($server);
     $this->assertEquals($parser->get('user'), 'foo');
     $this->assertEquals($parser->get('pass'), 'bar');
     // Get as string again
     $this->assertEquals($parser->__toString(), 'http://*****:*****@aether.raymond.raw.no/foobar/hello');
 }
Exemple #2
0
 /**
  * Match an url against this config
  *
  * @access public
  * @return bool
  * @param AetherUrlParser $url
  */
 public function matchUrl(AetherUrlParser $url)
 {
     $configFilePath = $this->configFilePath;
     if (!file_exists($configFilePath)) {
         throw new AetherMissingFileException("Config file [{$configFilePath}] is missing.");
     }
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->load($configFilePath);
     $this->doc = $doc;
     $xpath = new DOMXPath($doc);
     /*
      * Find starting point of url rules, from this point on we
      * use recursion to decide on the correct rule to use
      */
     $sitename = $url->get('host');
     $xquery = "/config/site[@name='{$sitename}']";
     $xquery .= '/urlRules';
     $nodelist = $xpath->query($xquery);
     // Fallback to the "any" site qualifier
     if ($nodelist->length == 0) {
         $sitename = '*';
         $xquery = "/config/site[@name='{$sitename}']/urlRules";
         $nodelist = $xpath->query($xquery);
     }
     if ($nodelist->length == 0) {
         throw new AetherNoUrlRuleMatchException("No config entry matched site: {$sitename}");
     }
     $urlRules = $nodelist->item(0);
     // Subtract global options
     $ruleBase = " | /config/site[@name='{$sitename}']/urlRules/";
     $xquery = "/config/site[@name='{$sitename}']/option";
     $xquery .= $ruleBase . 'section';
     $xquery .= $ruleBase . 'template';
     $xquery .= $ruleBase . 'module';
     $xquery .= $ruleBase . 'option';
     $optionList = $xpath->query($xquery);
     if ($optionList->length > 0) {
         $this->readNodeConfiguration($optionList);
     }
     $path = $url->get('path');
     $explodedPath = explode('/', substr($path, 1));
     // Treat /foo/bar the same as /foo/bar/
     if (end($explodedPath) !== "") {
         $explodedPath[] = "";
     }
     /**
      * If AetherSlashMode is "keep", make sure $current is prefixed
      * with a slash as the slash is not maintained from earlier
      */
     if ($this->slashMode() == 'keep') {
         foreach ($explodedPath as $key => $part) {
             $explodedPath[$key] = '/' . $part;
         }
     }
     try {
         $node = $this->findMatchingConfigNode($urlRules, $explodedPath);
     } catch (AetherNoUrlRuleMatchException $e) {
         // No match found :( Send 404 and throw exception to logs
         header("Status: 404 Not Found");
         echo "<html><body><h1>404 Not found</h1></body></html>";
         throw new Exception("Technical error. No resource found on this url: " . (string) $url . ", " . $e);
     } catch (Exception $e) {
         // This is expected
         // Comment above was exceptionally not expected -- simeng 2011-10-10
     }
 }