@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | chdir(dirname(__DIR__)); |
3 | 3 | |
4 | -if(php_sapi_name() == 'cli'){ |
|
4 | +if (php_sapi_name() == 'cli') { |
|
5 | 5 | return false; |
6 | 6 | } |
7 | 7 |
@@ -3,18 +3,18 @@ |
||
3 | 3 | use Bricks\ServiceLocator\Manager as Locator; |
4 | 4 | use Bricks\TemplateEngine\Php\Template; |
5 | 5 | |
6 | -abstract class Controller{ |
|
6 | +abstract class Controller { |
|
7 | 7 | protected $locator; |
8 | 8 | protected $controller; |
9 | 9 | protected $action; |
10 | 10 | |
11 | - public function __construct(Locator $locator, $controller, $action){ |
|
11 | + public function __construct(Locator $locator, $controller, $action) { |
|
12 | 12 | $this->locator = $locator; |
13 | 13 | $this->controller = $controller; |
14 | 14 | $this->action = $action; |
15 | 15 | } |
16 | 16 | |
17 | - public function template(){ |
|
17 | + public function template() { |
|
18 | 18 | $template = new Template($this->locator['loader']->path('Bricks\Frameworks\Base\Template\\' . $this->controller . '\\' . $this->action, 'html')); |
19 | 19 | $template->controller = $this->controller; |
20 | 20 | $template->action = $this->action; |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Bricks\Frameworks\Base\Controller; |
3 | 3 | |
4 | -class Index extends Controller{ |
|
5 | - public function index(){ |
|
4 | +class Index extends Controller { |
|
5 | + public function index() { |
|
6 | 6 | return $this->template(); |
7 | 7 | } |
8 | 8 | } |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | use Bricks\Http\Routing\RoutingException; |
10 | 10 | use Bricks\TemplateEngine\Php\Template; |
11 | 11 | |
12 | -class App{ |
|
13 | - public function run(){ |
|
12 | +class App { |
|
13 | + public function run() { |
|
14 | 14 | // Маршрутизация статичных ресурсов. |
15 | 15 | $request = new Request; |
16 | - if(strpos($request->path(), '.') !== false){ |
|
16 | + if (strpos($request->path(), '.') !== false) { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | $controller = 'Bricks\Frameworks\Base\Controller\\' . $controllerName; |
33 | 33 | $action = $match[1]; |
34 | 34 | |
35 | - if(!file_exists($locator['loader']->path($controller))){ |
|
35 | + if (!file_exists($locator['loader']->path($controller))) { |
|
36 | 36 | throw new RoutingException('Controller not found'); |
37 | 37 | } |
38 | 38 | |
39 | 39 | $controller = new $controller($locator, $controllerName, $action); |
40 | - if(!method_exists($controller, $action)){ |
|
40 | + if (!method_exists($controller, $action)) { |
|
41 | 41 | throw new RoutingException('Controller not found'); |
42 | 42 | } |
43 | 43 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $controllerName = ucfirst($match[0]); |
51 | 51 | $controller = 'Bricks\Frameworks\Base\Controller\\' . $controllerName; |
52 | 52 | |
53 | - if(!file_exists($locator['loader']->path($controller))){ |
|
53 | + if (!file_exists($locator['loader']->path($controller))) { |
|
54 | 54 | throw new RoutingException('Controller not found'); |
55 | 55 | } |
56 | 56 | |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | // Выполнение маршрутизации. |
76 | 76 | $locator['request'] = $request; |
77 | 77 | $locator['response'] = new Response; |
78 | - try{ |
|
78 | + try { |
|
79 | 79 | $responseBody = $locator['router']->run($locator['request'], $locator['response']); |
80 | 80 | } |
81 | 81 | // Обработка исключений. |
82 | - catch(RoutingException $exception){ |
|
82 | + catch (RoutingException $exception) { |
|
83 | 83 | $responseBody = new Template($locator['loader']->path('Bricks\Frameworks\Base\Template\404', 'html')); |
84 | 84 | } |
85 | - catch(\Exception $exception){ |
|
85 | + catch (\Exception $exception) { |
|
86 | 86 | $responseBody = new Template($locator['loader']->path('Bricks\Frameworks\Base\Template\500', 'html')); |
87 | 87 | } |
88 | 88 |
@@ -81,8 +81,7 @@ |
||
81 | 81 | // Обработка исключений. |
82 | 82 | catch(RoutingException $exception){ |
83 | 83 | $responseBody = new Template($locator['loader']->path('Bricks\Frameworks\Base\Template\404', 'html')); |
84 | - } |
|
85 | - catch(\Exception $exception){ |
|
84 | + } catch(\Exception $exception){ |
|
86 | 85 | $responseBody = new Template($locator['loader']->path('Bricks\Frameworks\Base\Template\500', 'html')); |
87 | 86 | } |
88 | 87 |