• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / services / 6801533350

08 Nov 2023 04:34PM UTC coverage: 10.534% (-0.8%) from 11.327%
6801533350

push

github

twinh
ci: add PHP 8, remove PHP 7.2, 7.3

69 of 655 relevant lines covered (10.53%)

2.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Service/Laravel.php
1
<?php
2

3
namespace Miaoxing\Services\Service;
4

5
use Illuminate\Config\Repository;
6
use Illuminate\Database\DatabaseManager;
7
use Illuminate\Database\MySqlConnection;
8
use Illuminate\Foundation\Application;
9
use Illuminate\Queue\QueueManager;
10
use Illuminate\Redis\Connections\PhpRedisConnection;
11
use Illuminate\Redis\Connectors\PhpRedisConnector;
12
use Illuminate\Redis\RedisManager;
13
use Illuminate\Support\Facades\Facade;
14
use Miaoxing\Plugin\BaseService;
15
use Miaoxing\Services\Laravel\ConsoleKernel;
16
use Miaoxing\Services\Laravel\ConsoleSupportServiceProvider;
17
use Miaoxing\Services\Laravel\HttpKernel;
18

19
/**
20
 * @mixin \DbMixin
21
 * @mixin \QueueMixin
22
 * @mixin \LoggerMixin
23
 * @mixin \ConfigMixin
24
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25
 */
26
class Laravel extends BaseService
27
{
28
    /**
29
     * @var Application
30
     */
31
    protected $app;
32

33
    /**
34
     * @var bool
35
     */
36
    protected $bootstrapped = false;
37

38
    /**
39
     * Bootstrap Laravel application
40
     *
41
     * @return $this
42
     * @svc
43
     */
44
    protected function bootstrap()
45
    {
46
        if ($this->bootstrapped) {
×
47
            return $this;
×
48
        }
49
        $this->bootstrapped = true;
×
50

51
        if ('cli' === \PHP_SAPI) {
×
52
            $this->bootstrapConsole();
×
53
        } else {
54
            $this->bootstrapHttp();
×
55
        }
56

57
        $this->shareConfig();
×
58
        return $this;
×
59
    }
60

61
    /**
62
     * @return Application
63
     * @svc
64
     */
65
    protected function getApp()
66
    {
67
        if (!$this->app) {
×
68
            $this->app = $this->createApp();
×
69
        }
70
        return $this->app;
×
71
    }
72

73
    protected function createApp()
74
    {
75
        $app = new Application(realpath('.'));
×
76

77
        $app->singleton(\Illuminate\Contracts\Http\Kernel::class, HttpKernel::class);
×
78
        $app->singleton(\Illuminate\Contracts\Console\Kernel::class, ConsoleKernel::class);
×
79
        $app->singleton(
×
80
            \Illuminate\Contracts\Debug\ExceptionHandler::class,
×
81
            \Illuminate\Foundation\Exceptions\Handler::class
×
82
        );
×
83

84
        return $app;
×
85
    }
86

87
    protected function bootstrapHttp()
88
    {
89
        $app = $this->getApp();
×
90

91
        /** @var \Illuminate\Foundation\Http\Kernel $kernel */
92
        $kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
×
93

94
        $request = new \Illuminate\Http\Request();
×
95
        $app->instance('request', $request);
×
96
        Facade::clearResolvedInstance('request');
×
97

98
        $kernel->bootstrap();
×
99
    }
100

101
    protected function bootstrapConsole()
102
    {
103
        $this->config->preloadGlobal();
×
104

105
        $app = $this->getApp();
×
106

107
        $app->register(ConsoleSupportServiceProvider::class);
×
108

109
        /** @var ConsoleKernel $kernel */
110
        $kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class);
×
111
        $kernel->bootstrap();
×
112
    }
113

114
    protected function shareConfig()
115
    {
116
        $app = $this->getApp();
×
117

118
        // Logger
119
        $app['log'] = $this->logger;
×
120

121
        // Database
122
        /** @var Repository $config */
123
        $config = $app['config'];
×
124

125
        $config->set([
×
126
            'cache' => [
×
127
                'default' => 'file',
×
128
                'stores' => [
×
129
                    'file' => [
×
130
                        'driver' => 'file',
×
131
                        'path' => storage_path('framework/cache/data'),
×
132
                    ],
×
133
                ],
×
134
            ],
×
135
            'database' => [
×
136
                'default' => 'mysql',
×
137
                'connections' => [
×
138
                    'mysql' => [],
×
139
                ],
×
140
                'redis' => [
×
141
                    'default' => [],
×
142
                ],
×
143
            ],
×
144
        ]);
×
145

146
        $app->extend(DatabaseManager::class, function (DatabaseManager $manager) {
×
147
            $manager->extend('mysql', function () {
×
148
                return new MySqlConnection($this->db->getPdo(), $this->db->getDbname(), $this->db->getTablePrefix());
×
149
            });
×
150
            return $manager;
×
151
        });
×
152
        $app->extend(RedisManager::class, function (RedisManager $manager) {
×
153
            $manager->extend('phpredis', function () {
×
154
                return new class () extends PhpRedisConnector {
×
155
                    public function connect(array $config, array $options)
156
                    {
157
                        return new PhpRedisConnection(wei()->redis->getObject());
×
158
                    }
159
                };
×
160
            });
×
161
            return $manager;
×
162
        });
×
163

164
        // Queue
165
        $app->afterResolving(QueueManager::class, function () {
×
166
            $this->queue->setConfig();
×
167
        });
×
168
    }
169
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc