-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option for path/params combo when validating HTTP signatures.
Move request arguments resolution to new RequestArgumentsResolver class.
- Loading branch information
Showing
5 changed files
with
123 additions
and
61 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,34 @@ | ||
<?php | ||
|
||
namespace League\Glide\Http; | ||
|
||
use InvalidArgumentException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class RequestArgumentsResolver | ||
{ | ||
/** | ||
* Resolve request object. | ||
* @param array $args Array of supplied arguments. | ||
* @return Request The request object. | ||
*/ | ||
public function getRequest($args) | ||
{ | ||
if (isset($args[0]) and $args[0] instanceof Request) { | ||
return $args[0]; | ||
} | ||
|
||
if (isset($args[0]) and is_string($args[0])) { | ||
$path = $args[0]; | ||
$params = []; | ||
|
||
if (isset($args[1]) and is_array($args[1])) { | ||
$params = $args[1]; | ||
} | ||
|
||
return RequestFactory::create($path, $params); | ||
} | ||
|
||
throw new InvalidArgumentException('Not a valid path or Request object.'); | ||
} | ||
} |
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
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
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
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,53 @@ | ||
<?php | ||
|
||
namespace League\Glide\Http; | ||
|
||
class RequestArgumentsResolverTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $resolver; | ||
|
||
public function setUp() | ||
{ | ||
$this->resolver = new RequestArgumentsResolver(); | ||
} | ||
|
||
public function testCreateRequestArgumentsResolver() | ||
{ | ||
$this->assertInstanceOf( | ||
'League\Glide\Http\RequestArgumentsResolver', | ||
$this->resolver | ||
); | ||
} | ||
|
||
public function testRequestObjectArg() | ||
{ | ||
$request = $this->resolver->getRequest([ | ||
RequestFactory::create('image.jpg', ['w' => 100]), | ||
]); | ||
|
||
$this->assertEquals('image.jpg', $request->getPathInfo()); | ||
$this->assertEquals(['w' => 100], $request->query->all()); | ||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request); | ||
} | ||
|
||
public function testRequestParamsArgs() | ||
{ | ||
$request = $this->resolver->getRequest([ | ||
'image.jpg', ['w' => 100], | ||
]); | ||
|
||
$this->assertEquals('image.jpg', $request->getPathInfo()); | ||
$this->assertEquals(['w' => 100], $request->query->all()); | ||
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $request); | ||
} | ||
|
||
public function testInvalidArgs() | ||
{ | ||
$this->setExpectedException( | ||
'InvalidArgumentException', | ||
'Not a valid path or Request object.' | ||
); | ||
|
||
$this->resolver->getRequest([]); | ||
} | ||
} |