-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1345 from opengeek/foundHandler
Add foundHandler that implements a new InvocationStrategyInterface
- Loading branch information
Showing
5 changed files
with
127 additions
and
6 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
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,41 @@ | ||
<?php | ||
/* | ||
* This file is part of the slim package. | ||
* | ||
* Copyright (c) Jason Coward <jason@opengeek.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slim\Handlers\Strategies; | ||
|
||
|
||
use Interop\Container\ContainerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Slim\Interfaces\InvocationStrategyInterface; | ||
|
||
class RequestResponse implements InvocationStrategyInterface | ||
{ | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @param array $route | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* | ||
* @return mixed | ||
*/ | ||
public function invoke( | ||
ContainerInterface $container, | ||
array $route, | ||
ServerRequestInterface $request, | ||
ResponseInterface $response | ||
) { | ||
foreach ($route[2] as $k => $v) { | ||
$request = $request->withAttribute($k, urldecode($v)); | ||
} | ||
return $route[1]($request, $response, []); | ||
} | ||
} |
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 slim package. | ||
* | ||
* Copyright (c) Jason Coward <jason@opengeek.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Slim\Handlers\Strategies; | ||
|
||
|
||
use Interop\Container\ContainerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Slim\Interfaces\InvocationStrategyInterface; | ||
|
||
class RequestResponseArgs implements InvocationStrategyInterface | ||
{ | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @param array $route | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* | ||
* @return mixed | ||
*/ | ||
public function invoke(ContainerInterface $container, array $route, ServerRequestInterface $request, ResponseInterface $response) | ||
{ | ||
$arguments = [$request, $response]; | ||
foreach ($route[2] as $k => $v) { | ||
$decoded = urldecode($v); | ||
$request = $request->withAttribute($k, $decoded); | ||
array_push($arguments, $decoded); | ||
} | ||
return call_user_func_array($route[1], $arguments); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
/** | ||
* Slim Framework (http://slimframework.com) | ||
* | ||
* @link https://github.com/codeguy/Slim | ||
* @copyright Copyright (c) 2011-2015 Josh Lockhart | ||
* @license https://github.com/codeguy/Slim/blob/master/LICENSE (MIT License) | ||
*/ | ||
namespace Slim\Interfaces; | ||
|
||
|
||
use Interop\Container\ContainerInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
interface InvocationStrategyInterface | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @param array $route | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* | ||
* @return mixed | ||
*/ | ||
public function invoke(ContainerInterface $container, array $route, ServerRequestInterface $request, ResponseInterface $response); | ||
} |