|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Kotori.php |
|
4
|
|
|
* |
|
5
|
|
|
* A Tiny Model-View-Controller PHP Framework |
|
6
|
|
|
* |
|
7
|
|
|
* This content is released under the Apache 2 License |
|
8
|
|
|
* |
|
9
|
|
|
* Copyright (c) 2015-2017 Kotori Technology. All rights reserved. |
|
10
|
|
|
* |
|
11
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
12
|
|
|
* you may not use this file except in compliance with the License. |
|
13
|
|
|
* You may obtain a copy of the License at |
|
14
|
|
|
* |
|
15
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
16
|
|
|
* |
|
17
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
18
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
19
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
20
|
|
|
* See the License for the specific language governing permissions and |
|
21
|
|
|
* limitations under the License. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Application Controller Class |
|
26
|
|
|
* |
|
27
|
|
|
* This class object is the super class . |
|
28
|
|
|
* |
|
29
|
|
|
* @package Kotori |
|
30
|
|
|
* @subpackage Core |
|
31
|
|
|
* @author Kokororin |
|
32
|
|
|
* @link https://kotori.love |
|
33
|
|
|
*/ |
|
34
|
|
|
namespace Kotori\Core; |
|
35
|
|
|
|
|
36
|
|
|
use Kotori\Debug\Hook; |
|
37
|
|
|
|
|
38
|
|
|
class Controller |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* DB selector |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $key |
|
44
|
|
|
* @return \Kotori\Core\Database |
|
45
|
|
|
*/ |
|
46
|
2 |
|
protected function db($key = null) |
|
47
|
|
|
{ |
|
48
|
2 |
|
return Database::getInstance($key); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Class constructor |
|
53
|
|
|
* |
|
54
|
|
|
* Initialize view and database classes. |
|
55
|
|
|
*/ |
|
56
|
2 |
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
2 |
|
$this->view = new View(); |
|
|
|
|
|
|
59
|
2 |
|
$this->response = Container::get('response'); |
|
|
|
|
|
|
60
|
2 |
|
$this->request = Container::get('request'); |
|
|
|
|
|
|
61
|
2 |
|
$this->route = Container::get('route'); |
|
|
|
|
|
|
62
|
2 |
|
$this->db = $this->db(); |
|
|
|
|
|
|
63
|
2 |
|
$this->model = Container::get('model/provider'); |
|
|
|
|
|
|
64
|
2 |
|
$this->config = Container::get('config'); |
|
|
|
|
|
|
65
|
2 |
|
$this->cache = Container::get('cache'); |
|
|
|
|
|
|
66
|
2 |
|
$this->logger = Container::get('logger'); |
|
|
|
|
|
|
67
|
2 |
|
Hook::listen(__CLASS__); |
|
68
|
2 |
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: