Skip to content

Commit cfb1d25

Browse files
committed
Add application Kernel class
0 parents  commit cfb1d25

File tree

12 files changed

+1888
-0
lines changed

12 files changed

+1888
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
vendor
3+
examples/var
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Cherry\Controller;
4+
5+
use Cherry\Templating\Templater;
6+
7+
trait ControllerTrait
8+
{
9+
private function render($template, $args = [])
10+
{
11+
$te = new Templater(TEMPLATES_PATH);
12+
13+
$content = $te->render($template, $args);
14+
15+
echo $content;
16+
17+
return $content;
18+
}
19+
}

Cherry/Kernel.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Cherry;
4+
5+
use Cherry\Routing\Router;
6+
7+
class Kernel
8+
{
9+
private $_appRoot;
10+
11+
public $router;
12+
public $logger;
13+
14+
public function __construct($appRoot)
15+
{
16+
define('__ROOT__', $appRoot);
17+
18+
$this->_appRoot = __ROOT__;
19+
20+
$this->run();
21+
}
22+
23+
public function run()
24+
{
25+
$this->_readConfig();
26+
27+
$this->router = new Router();
28+
$this->logger = new Logger('app', LOGS_PATH);
29+
}
30+
31+
private function _getConfig()
32+
{
33+
$config = file_get_contents(__ROOT__ . '/config/config.json')
34+
or die("Unable to open config file!");
35+
36+
return json_decode($config, 1);
37+
}
38+
39+
private function _validateConfig(array $config)
40+
{
41+
$neededKeys = [
42+
'ROUTES_FILE',
43+
'CONTROLLERS_PATH',
44+
'TEMPLATES_PATH',
45+
'LOGS_PATH'
46+
];
47+
48+
foreach ($neededKeys as $k)
49+
{
50+
if (!isset($config[$k])) {
51+
die("Parameter \"{$k}\" don't found in config file!");
52+
}
53+
}
54+
}
55+
56+
private function _readConfig()
57+
{
58+
$config = $this->_getConfig();
59+
60+
$this->_validateConfig($config);
61+
62+
foreach ($config as $k => $v)
63+
define($k, __ROOT__ . '/' . $v);
64+
}
65+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Temuri Takalandze
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cherry-Core
2+
3+
**2019 &copy; Cherry-project**

composer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "cherry-project/core",
3+
"description": "Core for Cherry-project",
4+
"type": "library",
5+
"keywords": ["cherry","core"],
6+
"homepage": "https://github.com/ABGEO07/cherry-core",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "ABGEO",
11+
"email": "[email protected]",
12+
"homepage": "http://www.abgeo.ga",
13+
"role": "Developer"
14+
}
15+
],
16+
"minimum-stability": "dev",
17+
"require": {
18+
"php": ">=5.6.0",
19+
"cherry-project/router": "dev-master",
20+
"cherry-project/templater": "dev-master",
21+
"cherry-project/logger": "dev-master",
22+
"ext-json": "*"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"Cherry\\": "Cherry/"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)