forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf0e604
commit ae88a75
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\HttpClient\Plugin; | ||
|
||
use Guzzle\Common\Event; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class LanguageFilterPlugin implements EventSubscriberInterface | ||
{ | ||
private $language; | ||
|
||
public function __construct($language = 'en') | ||
{ | ||
$this->language = $language; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return array('request.before_send' => 'onBeforeSend'); | ||
} | ||
|
||
public function onBeforeSend(Event $event) | ||
{ | ||
$url = $event['request']->getUrl(true); | ||
|
||
$url->getQuery()->set('language', $this->language); | ||
|
||
$event['request']->setUrl($url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Tests\HttpClient\Plugin; | ||
|
||
use Guzzle\Common\Event; | ||
use Guzzle\Http\Message\Request; | ||
use Tmdb\HttpClient\Plugin\LanguageFilterPlugin; | ||
use Tmdb\Tests\TestCase; | ||
|
||
class LanguageFilterTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldAddToken() | ||
{ | ||
$request = new Request('GET', '/'); | ||
|
||
$event = new Event(); | ||
$event['request'] = $request; | ||
|
||
$plugin = new LanguageFilterPlugin(); | ||
|
||
$plugin->onBeforeSend($event); | ||
|
||
$this->assertEquals('/?language=en', $event['request']->getUrl()); | ||
} | ||
} |