Skip to content

Commit

Permalink
Accommodating Numeric Key Changes in Options
Browse files Browse the repository at this point in the history
For some scenarios, you might override your Options to change option at
key 0 to key ‘foo’ for direct Var comparison when configuring the URL.
When you do that, the numeric keys start at 1 instead of 0, so finding
lowest numeric key to start at is required.
  • Loading branch information
MichaelJ2324 committed Apr 29, 2017
1 parent 807897e commit 0562425
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Endpoint/Abstracts/AbstractEndpoint.php
Expand Up @@ -342,6 +342,14 @@ protected function configureURL(array $options)
$urlArr = explode("/",$url);
$optional = FALSE;
$optionNum = 0;
$keys = array_keys($options);
sort($keys);
foreach($options as $key => $value){
if (is_numeric($key)){
$optionNum = $key;
break;
}
}
foreach($urlArr as $key => $urlPart){
$replace = NULL;
if (strpos($urlPart,static::$_URL_VAR_CHARACTER) !== FALSE){
Expand Down
8 changes: 7 additions & 1 deletion tests/Endpoint/AbstractEndpointTest.php
Expand Up @@ -279,7 +279,7 @@ public function testInvalidUrl(){
public function testConfigureUrl(){
$Endpoint = new BasicEndpoint();
$Class = new \ReflectionClass('MRussell\REST\Tests\Stubs\Endpoint\BasicEndpoint');
$method = $Class->getMethod('configureUrl');
$method = $Class->getMethod('configureURL');
$method->setAccessible(TRUE);
$this->assertEquals($Endpoint,$Endpoint->setProperty('url','$foo'));
$this->assertEquals('bar',$method->invoke($Endpoint,array('bar')));
Expand All @@ -297,6 +297,12 @@ public function testConfigureUrl(){
1 => 1234
)
));
$this->assertEquals('bar/foo/1234',$method->invoke($Endpoint,array(
'foo' => 'bar',
3 => 'foo',
4 => 1234
)
));

$this->assertEquals($Endpoint,$Endpoint->setProperty('url','$foo/$bar/$:baz/$:foz'));
$this->assertEquals('bar/foo/foz/1234',$method->invoke($Endpoint,array(
Expand Down

0 comments on commit 0562425

Please sign in to comment.