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\Symfony;
2
 
3
use Clockwork\Clockwork;
4
 
5
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
 
9
class ClockworkController extends AbstractController
10
{
11
	protected $clockwork;
12
	protected $support;
13
 
14
	public function __construct(Clockwork $clockwork, ClockworkSupport $support)
15
	{
16
		$this->clockwork = $clockwork;
17
		$this->support = $support;
18
	}
19
 
20
	public function authenticate(Request $request)
21
	{
22
		$this->ensureClockworkIsEnabled();
23
 
24
		$token = $this->clockwork->authenticator()->attempt($request->request->all());
25
 
26
		return new JsonResponse([ 'token' => $token ], $token ? 200 : 403);
27
	}
28
 
29
	public function getData(Request $request, $id = null, $direction = null, $count = null)
30
	{
31
		$this->ensureClockworkIsEnabled();
32
 
33
		return $this->support->getData($request, $id, $direction, $count);
34
	}
35
 
36
	public function webIndex(Request $request)
37
	{
38
		$this->ensureClockworkIsEnabled();
39
		$this->ensureClockworkWebIsEnabled();
40
 
41
		return $this->support->getWebAsset('index.html');
42
	}
43
 
44
	public function webAsset($path)
45
	{
46
		$this->ensureClockworkIsEnabled();
47
		$this->ensureClockworkWebIsEnabled();
48
 
49
		return $this->support->getWebAsset($path);
50
	}
51
 
52
	public function webRedirect(Request $request)
53
	{
54
		$this->ensureClockworkIsEnabled();
55
		$this->ensureClockworkWebIsEnabled();
56
 
57
		return $this->redirect('/' . $request->getPathInfo() . '/app');
58
	}
59
 
60
	protected function ensureClockworkIsEnabled()
61
	{
62
		if (! $this->support->isEnabled()) throw $this->createNotFoundException();
63
	}
64
 
65
	protected function ensureClockworkWebIsEnabled()
66
	{
67
		if (! $this->support->isWebEnabled()) throw $this->createNotFoundException();
68
	}
69
}