Skip to content

Commit b05e635

Browse files
committed
fixed url redirections. close #33
1 parent 8444efa commit b05e635

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

Embed/Embed.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public static function create($url, array $options = null)
1919
throw new \InvalidArgumentException("Embed::create only accepts instances of Embed\\Request or strings");
2020
}
2121

22-
//Resolve special redirections
23-
UrlRedirect::resolve($url);
24-
2522
if (!$url->isValid()) {
2623
return false;
2724
}

Embed/Request.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ public function setUrl($url)
6161
if ($url instanceof RequestResolvers\RequestResolverInterface) {
6262
$this->resolver = $url;
6363
} else {
64-
$this->resolver = new self::$resolverClass($url);
64+
$this->resolver = new self::$resolverClass(UrlRedirect::resolve($url));
6565
}
6666

6767
if (self::$resolverConfig) {
6868
$this->resolver->setConfig(self::$resolverConfig);
6969
}
7070

71-
$this->parseUrl($url);
71+
$this->parseUrl($this->getUrl());
7272
$this->updateUrl();
7373
}
7474

Embed/UrlRedirect.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ class UrlRedirect
1616
/**
1717
* Resolve the url redirection
1818
*
19-
* @param Url $url Url to resolve
19+
* @param string $oldUrl Url to resolve
2020
*
21-
* @return boolean True if the url has changed, false if not
21+
* @return string The new url
2222
*/
23-
public static function resolve(Url $url)
23+
public static function resolve($oldUrl)
2424
{
25+
$url = new Url($oldUrl);
26+
2527
foreach (static::$urls as $method => $matches) {
2628
if ($url->match($matches)) {
2729
static::$method($url);
2830

29-
return true;
31+
break;
3032
}
3133
}
3234

33-
return false;
35+
return $url->getUrl();
3436
}
3537

3638

tests/EmbedTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,14 @@ public function testRedirections()
138138
'image' => 'http://www.heise.de/imgs/18/1/2/6/2/0/9/3/urn-newsml-dpa-com-20090101-140212-99-03856_large_4_3-2f16ffb85099e6ad.jpeg'
139139
)
140140
);
141+
142+
143+
$info1 = Embed\Embed::create('http://rd.io/x/Q1IjXC8s');
144+
$info2 = Embed\Embed::create('http://www.rdio.com/artist/Soundgarden/album/Superunknown/');
145+
$this->assertEquals($info1->code, $info2->code);
146+
147+
$info1 = Embed\Embed::create('https://twitter.com/#!/twitter/status/99530515043983360');
148+
$info2 = Embed\Embed::create('https://twitter.com/twitter/status/99530515043983360');
149+
$this->assertEquals($info1->code, $info2->code);
141150
}
142151
}

0 commit comments

Comments
 (0)