Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
199 lars 1
<?php namespace Clockwork\Support\Lumen;
2
 
3
use Clockwork\DataSource\LumenDataSource;
4
use Clockwork\Support\Laravel\ClockworkServiceProvider as LaravelServiceProvider;
5
 
6
use Illuminate\Support\Facades\Facade;
7
 
8
// Clockwork Lumen service provider
9
class ClockworkServiceProvider extends LaravelServiceProvider
10
{
11
	// Register Clockwork configuration
12
	protected function registerConfiguration()
13
	{
14
		$this->app->configure('clockwork');
15
		$this->mergeConfigFrom(__DIR__ . '/../Laravel/config/clockwork.php', 'clockwork');
16
	}
17
 
18
	// Register Clockwork components
19
	protected function registerClockwork()
20
	{
21
		parent::registerClockwork();
22
 
23
		$this->app->singleton('clockwork.support', function ($app) {
24
			return new ClockworkSupport($app);
25
		});
26
 
27
		if ($this->isRunningWithFacades() && ! class_exists('Clockwork')) {
28
			class_alias(\Clockwork\Support\Laravel\Facade::class, 'Clockwork');
29
		}
30
	}
31
 
32
	// Register Clockwork data sources
33
	protected function registerDataSources()
34
	{
35
		parent::registerDataSources();
36
 
37
		$this->app->singleton('clockwork.lumen', function ($app) {
38
			return (new LumenDataSource(
39
				$app,
40
				$app['clockwork.support']->isFeatureEnabled('log'),
41
				$app['clockwork.support']->isFeatureEnabled('views'),
42
				$app['clockwork.support']->isFeatureEnabled('routes')
43
			));
44
		});
45
	}
46
 
47
	// Register Clockwork components aliases for type hinting
48
	protected function registerAliases()
49
	{
50
		parent::registerAliases();
51
 
52
		$this->app->alias('clockwork.lumen', LumenDataSource::class);
53
	}
54
 
55
	// Register event listeners
56
	protected function registerEventListeners()
57
	{
58
		$this->app['clockwork.support']->addDataSources()->listenToEvents();
59
	}
60
 
61
	// Register Clockwork middleware
62
	public function registerMiddleware()
63
	{
64
		$this->app->middleware([ ClockworkMiddleware::class ]);
65
	}
66
 
67
	// Register Clockwork REST api routes
68
	public function registerRoutes()
69
	{
70
		$router = isset($this->app->router) ? $this->app->router : $this->app;
71
 
72
		$router->get('/__clockwork/{id:(?:[0-9-]+|latest)}/extended', 'Clockwork\Support\Lumen\Controller@getExtendedData');
73
		$router->get('/__clockwork/{id:(?:[0-9-]+|latest)}[/{direction:(?:next|previous)}[/{count:\d+}]]', 'Clockwork\Support\Lumen\Controller@getData');
74
		$router->put('/__clockwork/{id}', 'Clockwork\Support\Lumen\Controller@updateData');
75
		$router->post('/__clockwork/auth', 'Clockwork\Support\Lumen\Controller@authenticate');
76
	}
77
 
78
	// Register Clockwork app routes
79
	public function registerWebRoutes()
80
	{
81
		$router = isset($this->app->router) ? $this->app->router : $this->app;
82
 
83
		$this->app['clockwork.support']->webPaths()->each(function ($path) use ($router) {
84
			$router->get("{$path}", 'Clockwork\Support\Lumen\Controller@webRedirect');
85
			$router->get("{$path}/app", 'Clockwork\Support\Lumen\Controller@webIndex');
86
			$router->get("{$path}/{path:.+}", 'Clockwork\Support\Lumen\Controller@webAsset');
87
		});
88
	}
89
 
90
	// Check whether we are running with facades enabled
91
	protected function isRunningWithFacades()
92
	{
93
		return Facade::getFacadeApplication() !== null;
94
	}
95
}