Skip to content

Commit

Permalink
fixed url redirections. close #33
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Jul 9, 2014
1 parent 8444efa commit b05e635
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 0 additions & 3 deletions Embed/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public static function create($url, array $options = null)
throw new \InvalidArgumentException("Embed::create only accepts instances of Embed\\Request or strings");
}

//Resolve special redirections
UrlRedirect::resolve($url);

if (!$url->isValid()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Embed/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function setUrl($url)
if ($url instanceof RequestResolvers\RequestResolverInterface) {
$this->resolver = $url;
} else {
$this->resolver = new self::$resolverClass($url);
$this->resolver = new self::$resolverClass(UrlRedirect::resolve($url));
}

if (self::$resolverConfig) {
$this->resolver->setConfig(self::$resolverConfig);
}

$this->parseUrl($url);
$this->parseUrl($this->getUrl());
$this->updateUrl();
}

Expand Down
12 changes: 7 additions & 5 deletions Embed/UrlRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ class UrlRedirect
/**
* Resolve the url redirection
*
* @param Url $url Url to resolve
* @param string $oldUrl Url to resolve
*
* @return boolean True if the url has changed, false if not
* @return string The new url
*/
public static function resolve(Url $url)
public static function resolve($oldUrl)
{
$url = new Url($oldUrl);

foreach (static::$urls as $method => $matches) {
if ($url->match($matches)) {
static::$method($url);

return true;
break;
}
}

return false;
return $url->getUrl();
}


Expand Down
9 changes: 9 additions & 0 deletions tests/EmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,14 @@ public function testRedirections()
'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'
)
);


$info1 = Embed\Embed::create('http://rd.io/x/Q1IjXC8s');
$info2 = Embed\Embed::create('http://www.rdio.com/artist/Soundgarden/album/Superunknown/');
$this->assertEquals($info1->code, $info2->code);

$info1 = Embed\Embed::create('https://twitter.com/#!/twitter/status/99530515043983360');
$info2 = Embed\Embed::create('https://twitter.com/twitter/status/99530515043983360');
$this->assertEquals($info1->code, $info2->code);
}
}

0 comments on commit b05e635

Please sign in to comment.