1
|
|
|
<?php namespace Limoncello\Core\Routing\Traits; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2016 [email protected] (www.neomerx.com) |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Limoncello\Core\Application\Application; |
20
|
|
|
use LogicException; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @package Limoncello\Core |
24
|
|
|
* |
25
|
|
|
* @method bool isCallableToCache($value); |
26
|
|
|
* @method string getCallableToCacheMessage(); |
27
|
|
|
*/ |
28
|
|
|
trait HasRequestFactoryTrait |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var callable|false|null |
32
|
|
|
*/ |
33
|
|
|
private $requestFactory = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param callable|null $requestFactory |
37
|
|
|
* |
38
|
|
|
* @return $this |
39
|
|
|
*/ |
40
|
18 |
|
public function setRequestFactory(callable $requestFactory = null) |
41
|
|
|
{ |
42
|
18 |
|
if ($requestFactory !== null && $this->isCallableToCache($requestFactory) === false) { |
43
|
2 |
|
throw new LogicException($this->getCallableToCacheMessage()); |
44
|
|
|
} |
45
|
16 |
|
$this->requestFactory = $requestFactory; |
46
|
|
|
|
47
|
16 |
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return bool |
52
|
|
|
*/ |
53
|
12 |
|
protected function isRequestFactorySet() |
54
|
|
|
{ |
55
|
12 |
|
return $this->requestFactory !== false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return callable |
|
|
|
|
60
|
|
|
* |
61
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
62
|
|
|
*/ |
63
|
5 |
|
protected function getDefaultRequestFactory() |
64
|
|
|
{ |
65
|
5 |
|
return Application::getDefaultRequestFactory(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.