Issues (29)

src/ServiceProvider.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: hugh.li
5
 * Date: 2021/4/18
6
 * Time: 10:32 下午.
7
 */
8
9
namespace HughCube\Laravel\OTS;
10
11
use HughCube\Laravel\OTS\Cache\Store;
12
use HughCube\Laravel\OTS\Commands\CacheGc;
13
use HughCube\Laravel\OTS\Commands\ClearTableCommand;
14
use Illuminate\Cache\CacheManager;
15
use Illuminate\Database\DatabaseManager;
16
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
17
18
class ServiceProvider extends IlluminateServiceProvider
19
{
20
    /**
21
     * Boot the provider.
22
     */
23
    public function boot()
24
    {
25
    }
26
27
    /**
28
     * Register the provider.
29
     */
30
    public function register()
31
    {
32
        $this->registerDatabaseExtend();
33
        $this->registerCacheExtend();
34
        $this->registerCommand();
35
    }
36
37
    protected function registerDatabaseExtend()
38
    {
39
        $this->app->resolving('db', function ($db) {
40
            /** @var DatabaseManager $db */
41
            $db->extend('ots', function ($config, $name) {
42
                $config['name'] = $name;
43
44
                return new Connection($config);
45
            });
46
        });
47
    }
48
49
    protected function registerCacheExtend()
50
    {
51
        $this->app->resolving('cache', function ($cache) {
52
            /** @var CacheManager $cache */
53
            $cache->extend('ots', function ($app, $config) {
54
                /** @var CacheManager $this */
55
56
                /** @var Connection $connection */
57
                $connection = $app['db']->connection($config['connection']);
58
59
                $prefix = $config['prefix'] ?? $app['config']['cache.prefix'];
60
                $indexTable = $config['index_table'] ?? null;
61
                $store = new Store($connection, $config['table'], $prefix, $indexTable);
62
63
                return $this->repository($store);
0 ignored issues
show
The method repository() does not exist on HughCube\Laravel\OTS\ServiceProvider. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
                return $this->/** @scrutinizer ignore-call */ repository($store);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
            });
65
        });
66
    }
67
68
    protected function registerCommand()
69
    {
70
        $this->commands([
71
            CacheGc::class,
72
            ClearTableCommand::class,
73
        ]);
74
    }
75
}
76