Skip to content

Commit 34f6d40

Browse files
committed
Merge pull request #126 from AlexeyDsov/staticUrlParse
GenericUri::parse now static
2 parents 081d8de + 31b2134 commit 34f6d40

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

doc/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2012-09-12 Alexey S. Denisov
2+
* main/Net/GenericUri.class.php
3+
main/Net/HttpUrl.class.php
4+
main/Net/Url.class.php
5+
main/Net/Urn.class.php:
6+
GenericUri::parse now static
7+
18
2012-09-12 Alexey S. Denisov
29

310
* main/Flow/HttpRequest.class.php

main/Net/GenericUri.class.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,22 @@ public static function create()
4141
/**
4242
* @return GenericUri
4343
**/
44-
final public function parse($uri, $guessClass = false)
44+
final public static function parse($uri, $guessClass = false)
4545
{
46-
$schemePattern = '([^:/?#]+):';
47-
$authorityPattern = '(//([^/?#]*))';
48-
$restPattern = '([^?#]*)(\?([^#]*))?(#(.*))?';
46+
static $schemePattern = '([^:/?#]+):';
47+
static $authorityPattern = '(//([^/?#]*))';
48+
static $restPattern = '([^?#]*)(\?([^#]*))?(#(.*))?';
4949
$matches = array();
5050

5151
if (
5252
$guessClass
53-
&& ($knownSubSchemes = $this->getKnownSubSchemes())
53+
&& ($knownSubSchemes = static::getKnownSubSchemes())
5454
&& preg_match("~^{$schemePattern}~", $uri, $matches)
5555
&& isset($knownSubSchemes[strtolower($matches[1])])
5656
)
57-
$class = $knownSubSchemes[strtolower($matches[1])];
57+
$result = new $knownSubSchemes[strtolower($matches[1])];
5858
else
59-
$class = get_class($this);
60-
61-
$result = new $class;
59+
$result = new static;
6260

6361
if ($result instanceof Url)
6462
$pattern = "({$schemePattern}{$authorityPattern})?";
@@ -171,11 +169,11 @@ final public function transform(GenericUri $reference, $strict = true)
171169
return $result;
172170
}
173171

174-
public function getKnownSubSchemes()
172+
public static function getKnownSubSchemes()
175173
{
176174
return array_merge(
177-
Urn::create()->getKnownSubSchemes(),
178-
Url::create()->getKnownSubSchemes()
175+
Urn::getKnownSubSchemes(),
176+
Url::getKnownSubSchemes()
179177
);
180178
}
181179

main/Net/HttpUrl.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
**/
1515
final class HttpUrl extends Url
1616
{
17-
protected $knownSubSchemes = array();
17+
protected static $knownSubSchemes = array();
1818

1919
/**
2020
* @return HttpUrl

main/Net/Url.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
**/
1818
class Url extends GenericUri
1919
{
20-
protected $knownSubSchemes = array(
20+
protected static $knownSubSchemes = array(
2121
'http' => 'HttpUrl',
2222
'https' => 'HttpUrl',
2323
'ftp' => 'Url',
@@ -37,9 +37,9 @@ public static function create()
3737
return new self;
3838
}
3939

40-
public function getKnownSubSchemes()
40+
public static function getKnownSubSchemes()
4141
{
42-
return $this->knownSubSchemes;
42+
return static::$knownSubSchemes;
4343
}
4444

4545
public function isValid()

main/Net/Urn.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class Urn extends GenericUri
1818
{
1919
protected $schemeSpecificPart = null;
2020

21-
protected $knownSubSchemes = array(
21+
protected static $knownSubSchemes = array(
2222
'urn' => 'Urn',
2323
'mailto' => 'Urn',
2424
'news' => 'Urn',
@@ -35,9 +35,9 @@ public static function create()
3535
return new self;
3636
}
3737

38-
public function getKnownSubSchemes()
38+
public static function getKnownSubSchemes()
3939
{
40-
return $this->knownSubSchemes;
40+
return static::$knownSubSchemes;
4141
}
4242

4343
public function isValid()

test/main/GenericUriTest.class.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (C) 2007 by Ivan Khvostishkov *
44
55
***************************************************************************/
6-
/* $Id$ */
76

87
final class GenericUriTest extends TestCase
98
{
@@ -92,11 +91,9 @@ public function testParser()
9291

9392
if (!$parserClass)
9493
$parserClass = 'GenericUri';
95-
96-
$parser = new $parserClass;
9794

9895
try {
99-
$url = $parser->parse($testUrl, true);
96+
$url = ClassUtils::callStaticMethod("$parserClass::parse", $testUrl, true);
10097
} catch (WrongArgumentException $e) {
10198
$exception = $e;
10299
}

0 commit comments

Comments
 (0)