|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BEAR\Package\Context; |
|
6
|
|
|
|
|
7
|
|
|
use BEAR\Package\Context\Provider\ProdCacheProvider; |
|
8
|
|
|
use BEAR\Package\Provide\Error\ErrorPageFactoryInterface; |
|
9
|
|
|
use BEAR\Package\Provide\Error\ProdVndErrorPageFactory; |
|
10
|
|
|
use BEAR\Package\Provide\Logger\ProdMonologProvider; |
|
11
|
|
|
use BEAR\RepositoryModule\Annotation\Storage; |
|
12
|
|
|
use BEAR\Resource\NullOptionsRenderer; |
|
13
|
|
|
use BEAR\Resource\RenderInterface; |
|
14
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
15
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
|
16
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
17
|
|
|
use Doctrine\Common\Cache\Cache; |
|
18
|
|
|
use Doctrine\Common\Cache\CacheProvider; |
|
19
|
|
|
use Psr\Log\LoggerInterface; |
|
20
|
|
|
use Ray\Compiler\DiCompileModule; |
|
21
|
|
|
use Ray\Di\AbstractModule; |
|
22
|
|
|
use Ray\Di\Scope; |
|
23
|
|
|
|
|
24
|
|
|
use function microtime; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @codeCoverageIgnore |
|
28
|
|
|
*/ |
|
29
|
|
|
class ProdModule extends AbstractModule |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function configure(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->bind(ErrorPageFactoryInterface::class)->to(ProdVndErrorPageFactory::class); |
|
37
|
|
|
$this->bind(LoggerInterface::class)->toProvider(ProdMonologProvider::class)->in(Scope::SINGLETON); |
|
38
|
|
|
$this->disableOptionsMethod(); |
|
39
|
|
|
// prod cache namespace (override in AppInjector) |
|
40
|
|
|
$this->bind()->annotatedWith('cache_namespace')->toInstance(microtime()); |
|
41
|
|
|
// generic cache for user |
|
42
|
|
|
$this->bind(Cache::class)->toProvider(ProdCacheProvider::class)->in(Scope::SINGLETON); |
|
43
|
|
|
// query repository (shared-server) cache |
|
44
|
|
|
$this->bind(CacheProvider::class)->annotatedWith(Storage::class)->toProvider(ProdCacheProvider::class)->in(Scope::SINGLETON); |
|
45
|
|
|
// prod annotation reader |
|
46
|
|
|
$this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class); |
|
47
|
|
|
$this->bind(Cache::class)->annotatedWith('annotation_cache')->toProvider(ProdCacheProvider::class)->in(Scope::SINGLETON); |
|
48
|
|
|
$this->bind(Reader::class)->toConstructor( |
|
49
|
|
|
CachedReader::class, |
|
50
|
|
|
'reader=annotation_reader' |
|
51
|
|
|
); |
|
52
|
|
|
$this->install(new DiCompileModule(true)); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Disable OPTIONS resource request method in production |
|
57
|
|
|
* |
|
58
|
|
|
* OPTIONS method return 405 Method Not Allowed error code. To enable OPTIONS in `prod` context, |
|
59
|
|
|
* Install BEAR\Resource\Module\OptionsMethodModule() in your ProdModule. |
|
60
|
|
|
*/ |
|
61
|
|
|
private function disableOptionsMethod(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->bind(RenderInterface::class)->annotatedWith('options')->to(NullOptionsRenderer::class); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: