diff --git a/doc/ChangeLog b/doc/ChangeLog index 961597ed1c..fec84171cc 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2012-09-12 Alexey S. Denisov + * main/Net/GenericUri.class.php + main/Net/HttpUrl.class.php + main/Net/Url.class.php + main/Net/Urn.class.php: + GenericUri::parse now static + 2012-09-12 Alexey S. Denisov * main/Flow/HttpRequest.class.php diff --git a/main/Net/GenericUri.class.php b/main/Net/GenericUri.class.php index 95eaef8e1b..2b05d40ae6 100644 --- a/main/Net/GenericUri.class.php +++ b/main/Net/GenericUri.class.php @@ -41,24 +41,22 @@ public static function create() /** * @return GenericUri **/ - final public function parse($uri, $guessClass = false) + final public static function parse($uri, $guessClass = false) { - $schemePattern = '([^:/?#]+):'; - $authorityPattern = '(//([^/?#]*))'; - $restPattern = '([^?#]*)(\?([^#]*))?(#(.*))?'; + static $schemePattern = '([^:/?#]+):'; + static $authorityPattern = '(//([^/?#]*))'; + static $restPattern = '([^?#]*)(\?([^#]*))?(#(.*))?'; $matches = array(); if ( $guessClass - && ($knownSubSchemes = $this->getKnownSubSchemes()) + && ($knownSubSchemes = static::getKnownSubSchemes()) && preg_match("~^{$schemePattern}~", $uri, $matches) && isset($knownSubSchemes[strtolower($matches[1])]) ) - $class = $knownSubSchemes[strtolower($matches[1])]; + $result = new $knownSubSchemes[strtolower($matches[1])]; else - $class = get_class($this); - - $result = new $class; + $result = new static; if ($result instanceof Url) $pattern = "({$schemePattern}{$authorityPattern})?"; @@ -171,11 +169,11 @@ final public function transform(GenericUri $reference, $strict = true) return $result; } - public function getKnownSubSchemes() + public static function getKnownSubSchemes() { return array_merge( - Urn::create()->getKnownSubSchemes(), - Url::create()->getKnownSubSchemes() + Urn::getKnownSubSchemes(), + Url::getKnownSubSchemes() ); } diff --git a/main/Net/HttpUrl.class.php b/main/Net/HttpUrl.class.php index 6254766d98..300cf42f23 100644 --- a/main/Net/HttpUrl.class.php +++ b/main/Net/HttpUrl.class.php @@ -14,7 +14,7 @@ **/ final class HttpUrl extends Url { - protected $knownSubSchemes = array(); + protected static $knownSubSchemes = array(); /** * @return HttpUrl diff --git a/main/Net/Url.class.php b/main/Net/Url.class.php index 24f4d4e00b..6cc44935b3 100644 --- a/main/Net/Url.class.php +++ b/main/Net/Url.class.php @@ -17,7 +17,7 @@ **/ class Url extends GenericUri { - protected $knownSubSchemes = array( + protected static $knownSubSchemes = array( 'http' => 'HttpUrl', 'https' => 'HttpUrl', 'ftp' => 'Url', @@ -37,9 +37,9 @@ public static function create() return new self; } - public function getKnownSubSchemes() + public static function getKnownSubSchemes() { - return $this->knownSubSchemes; + return static::$knownSubSchemes; } public function isValid() diff --git a/main/Net/Urn.class.php b/main/Net/Urn.class.php index 79f60586c0..a38bb3d19c 100644 --- a/main/Net/Urn.class.php +++ b/main/Net/Urn.class.php @@ -18,7 +18,7 @@ final class Urn extends GenericUri { protected $schemeSpecificPart = null; - protected $knownSubSchemes = array( + protected static $knownSubSchemes = array( 'urn' => 'Urn', 'mailto' => 'Urn', 'news' => 'Urn', @@ -35,9 +35,9 @@ public static function create() return new self; } - public function getKnownSubSchemes() + public static function getKnownSubSchemes() { - return $this->knownSubSchemes; + return static::$knownSubSchemes; } public function isValid() diff --git a/test/main/GenericUriTest.class.php b/test/main/GenericUriTest.class.php index 0d19828220..582008f892 100644 --- a/test/main/GenericUriTest.class.php +++ b/test/main/GenericUriTest.class.php @@ -3,7 +3,6 @@ * Copyright (C) 2007 by Ivan Khvostishkov * * dedmajor@oemdesign.ru * ***************************************************************************/ -/* $Id$ */ final class GenericUriTest extends TestCase { @@ -92,11 +91,9 @@ public function testParser() if (!$parserClass) $parserClass = 'GenericUri'; - - $parser = new $parserClass; try { - $url = $parser->parse($testUrl, true); + $url = ClassUtils::callStaticMethod("$parserClass::parse", $testUrl, true); } catch (WrongArgumentException $e) { $exception = $e; }