| 199 |
lars |
1 |
<?php namespace Clockwork\Support\Lumen;
|
|
|
2 |
|
|
|
3 |
use Clockwork\Support\Laravel\ClockworkSupport as LaravelSupport;
|
|
|
4 |
|
|
|
5 |
use Laravel\Lumen\Application;
|
|
|
6 |
use Symfony\Component\HttpFoundation\Response;
|
|
|
7 |
|
|
|
8 |
// Support class for the Lumen integration
|
|
|
9 |
class ClockworkSupport extends LaravelSupport
|
|
|
10 |
{
|
|
|
11 |
// Lumen application instance
|
|
|
12 |
protected $app;
|
|
|
13 |
|
|
|
14 |
public function __construct(Application $app)
|
|
|
15 |
{
|
|
|
16 |
$this->app = $app;
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
// Resolves the framework data source from the container
|
|
|
20 |
protected function frameworkDataSource()
|
|
|
21 |
{
|
|
|
22 |
return $this->app['clockwork.lumen'];
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
// Process an http request and response, resolves the request, sets Clockwork headers and cookies
|
|
|
26 |
public function process($request, $response)
|
|
|
27 |
{
|
|
|
28 |
if (! $response instanceof Response) {
|
|
|
29 |
$response = new Response((string) $response);
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
return parent::process($request, $response);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
// Set response on the framework data source
|
|
|
36 |
protected function setResponse($response)
|
|
|
37 |
{
|
|
|
38 |
$this->app['clockwork.lumen']->setResponse($response);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
// Check whether Clockwork is enabled
|
|
|
42 |
public function isEnabled()
|
|
|
43 |
{
|
|
|
44 |
return $this->getConfig('enable')
|
|
|
45 |
|| $this->getConfig('enable') === null && env('APP_DEBUG', false);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
// Check whether a particular feature is available
|
|
|
49 |
public function isFeatureAvailable($feature)
|
|
|
50 |
{
|
|
|
51 |
if ($feature == 'database') {
|
|
|
52 |
return $this->app->bound('db') && $this->app['config']->get('database.default');
|
|
|
53 |
} elseif ($feature == 'emails') {
|
|
|
54 |
return $this->app->bound('mailer');
|
|
|
55 |
} elseif ($feature == 'redis') {
|
|
|
56 |
return $this->app->bound('redis') && method_exists(\Illuminate\Redis\RedisManager::class, 'enableEvents');
|
|
|
57 |
} elseif ($feature == 'queue') {
|
|
|
58 |
return $this->app->bound('queue') && method_exists(\Illuminate\Queue\Queue::class, 'createPayloadUsing');
|
|
|
59 |
} elseif ($feature == 'xdebug') {
|
|
|
60 |
return in_array('xdebug', get_loaded_extensions());
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
return true;
|
|
|
64 |
}
|
|
|
65 |
}
|