1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gewaer\Providers; |
||
6 | |||
7 | use function Gewaer\Core\envValue; |
||
8 | use Phalcon\Di\ServiceProviderInterface; |
||
9 | use Phalcon\DiInterface; |
||
10 | use Phalcon\Mvc\Model\MetaData\Libmemcached; |
||
11 | use Phalcon\Mvc\Model\Metadata\Memory as MemoryMetaDataAdapter; |
||
12 | use Gewaer\Constants\Flags; |
||
13 | |||
14 | class ModelsMetadataProvider implements ServiceProviderInterface |
||
15 | { |
||
16 | /** |
||
17 | * @param DiInterface $container |
||
18 | */ |
||
19 | 11 | public function register(DiInterface $container) |
|
20 | { |
||
21 | 4 | $config = $container->getShared('config'); |
|
22 | |||
23 | 4 | $container->setShared( |
|
24 | 4 | 'modelsMetadata', |
|
25 | function () use ($config) { |
||
26 | 11 | if (strtolower($config->app->env) != Flags::PRODUCTION) { |
|
27 | 11 | return new MemoryMetaDataAdapter(); |
|
28 | } |
||
29 | |||
30 | $prefix = 'metadata'; |
||
31 | $backOptions = [ |
||
32 | 'servers' => [ |
||
33 | 0 => [ |
||
34 | 'host' => envValue('DATA_API_MEMCACHED_HOST', '127.0.0.1'), |
||
35 | 'port' => envValue('DATA_API_MEMCACHED_PORT', 11211), |
||
36 | 'weight' => envValue('DATA_API_MEMCACHED_WEIGHT', 100), |
||
37 | ], |
||
38 | ], |
||
39 | 'client' => [ |
||
40 | \Memcached::OPT_HASH => \Memcached::HASH_MD5, |
||
41 | \Memcached::OPT_PREFIX_KEY => 'bakaapi-', |
||
42 | ], |
||
43 | 'lifetime' => 3600, |
||
44 | 'prefix' => $prefix . '-', |
||
45 | ]; |
||
46 | |||
47 | return new Libmemcached($backOptions); |
||
48 | 4 | } |
|
49 | ); |
||
50 | 4 | } |
|
51 | } |
||
52 |