| 1 | <?php |
||
| 12 | class SplashRequestFetcher implements ParameterFetcher |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Returns whether this fetcher factory can handle the parameter passed in parameter for the url $url. |
||
| 16 | * |
||
| 17 | * @param ReflectionParameter $reflectionParameter |
||
| 18 | * @param string $url |
||
| 19 | * |
||
| 20 | * @return bool |
||
| 21 | */ |
||
| 22 | public function canHandle(ReflectionParameter $reflectionParameter, string $url = null) : bool |
||
| 23 | { |
||
| 24 | $class = $reflectionParameter->getClass(); |
||
| 25 | if ($class === null) { |
||
| 26 | return false; |
||
| 27 | } |
||
| 28 | $name = $class->getName(); |
||
|
|
|||
| 29 | // Check type of requested parameter; Only interfaces are allowed in an action of a controller. |
||
| 30 | if ($name === 'Psr\\Http\\Message\\RequestInterface' || $name === 'Psr\\Http\\Message\\ServerRequestInterface') { |
||
| 31 | return true; |
||
| 32 | } else { |
||
| 33 | return false; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Returns some data needed by this fetcher to fetch data from the request. |
||
| 39 | * This data MUST be serializable (and will be serialized). This function will be called only once |
||
| 40 | * and data cached. You can perform expensive computation in this function. |
||
| 41 | * |
||
| 42 | * @param ReflectionParameter $reflectionParameter |
||
| 43 | * @param string|null $url |
||
| 44 | * |
||
| 45 | * @return mixed |
||
| 46 | */ |
||
| 47 | public function getFetcherData(ReflectionParameter $reflectionParameter, string $url = null) |
||
| 48 | { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Returns the value to be injected in this parameter. |
||
| 54 | * |
||
| 55 | * @param mixed $data The data generated by "getFetcherData" |
||
| 56 | * @param SplashRequestContext $context |
||
| 57 | * |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function fetchValue($data, SplashRequestContext $context) |
||
| 64 | } |
||
| 65 |