Skip to content

Commit cdb99d9

Browse files
authored
Merge pull request #1 from ABGEO07/develop
v1.0.0
2 parents cfb1d25 + 752fdd6 commit cdb99d9

File tree

4 files changed

+159
-4
lines changed

4 files changed

+159
-4
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Cherry-core Changelog
2+
3+
## [v1.0.0](https://github.com/ABGEO07/cherry-core/releases/tag/v1.0.0 "v1.0.0") (2019-03-29)
4+
#### The first stable version
5+
6+
- Package available on: `composer require cherry-project/core`
7+
8+
- Core contains all cherry-project sub-packages
9+
- [Request](https://github.com/ABGEO07/cherry-request)
10+
- [Response](https://github.com/ABGEO07/cherry-response)
11+
- [Router](https://github.com/ABGEO07/cherry-router)
12+
- [Templater](https://github.com/ABGEO07/cherry-templater)
13+
- [Logger](https://github.com/ABGEO07/cherry-logger)

Cherry/Controller/ControllerTrait.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
<?php
2+
/**
3+
* The file contains ControllerTrait.
4+
*
5+
* PHP version 5
6+
*
7+
* @category Library
8+
* @package Cherry
9+
* @author Temuri Takalandze <[email protected]>
10+
* @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
11+
* @link https://github.com/ABGEO07/cherry-core
12+
*/
213

314
namespace Cherry\Controller;
415

16+
use Cherry\HttpUtils\Response;
517
use Cherry\Templating\Templater;
618

19+
/**
20+
* Trait for Cherry Controllers.
21+
*
22+
* @category Library
23+
* @package Cherry
24+
* @author Temuri Takalandze <[email protected]>
25+
* @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
26+
* @link https://github.com/ABGEO07/cherry-core
27+
*/
728
trait ControllerTrait
829
{
9-
private function render($template, $args = [])
30+
/**
31+
* Render the template.
32+
*
33+
* @param string $template Template filename for rendering
34+
* @param array $args Arguments for passing in template
35+
*
36+
* @return Response
37+
*/
38+
protected function render($template, $args = [])
1039
{
1140
$te = new Templater(TEMPLATES_PATH);
1241

Cherry/Kernel.php

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
<?php
2+
/**
3+
* The file contains application Kernel class.
4+
*
5+
* PHP version 5
6+
*
7+
* @category Library
8+
* @package Cherry
9+
* @author Temuri Takalandze <[email protected]>
10+
* @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
11+
* @link https://github.com/ABGEO07/cherry-core
12+
*/
213

314
namespace Cherry;
415

516
use Cherry\Routing\Router;
617

18+
/**
19+
* Application Kernel class.
20+
*
21+
* @category Library
22+
* @package Cherry
23+
* @author Temuri Takalandze <[email protected]>
24+
* @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT
25+
* @link https://github.com/ABGEO07/cherry-core
26+
*/
727
class Kernel
828
{
929
private $_appRoot;
1030

1131
public $router;
1232
public $logger;
1333

34+
/**
35+
* Kernel constructor.
36+
*
37+
* @param string $appRoot Application root path.
38+
*/
1439
public function __construct($appRoot)
1540
{
1641
define('__ROOT__', $appRoot);
@@ -20,6 +45,11 @@ public function __construct($appRoot)
2045
$this->run();
2146
}
2247

48+
/**
49+
* Run application.
50+
*
51+
* @return void
52+
*/
2353
public function run()
2454
{
2555
$this->_readConfig();
@@ -28,6 +58,11 @@ public function run()
2858
$this->logger = new Logger('app', LOGS_PATH);
2959
}
3060

61+
/**
62+
* Read config from file.
63+
*
64+
* @return array
65+
*/
3166
private function _getConfig()
3267
{
3368
$config = file_get_contents(__ROOT__ . '/config/config.json')
@@ -36,6 +71,13 @@ private function _getConfig()
3671
return json_decode($config, 1);
3772
}
3873

74+
/**
75+
* Check if needed keys isset in config file
76+
*
77+
* @param array $config Application Config
78+
*
79+
* @return void
80+
*/
3981
private function _validateConfig(array $config)
4082
{
4183
$neededKeys = [
@@ -45,21 +87,26 @@ private function _validateConfig(array $config)
4587
'LOGS_PATH'
4688
];
4789

48-
foreach ($neededKeys as $k)
49-
{
90+
foreach ($neededKeys as $k) {
5091
if (!isset($config[$k])) {
5192
die("Parameter \"{$k}\" don't found in config file!");
5293
}
5394
}
5495
}
5596

97+
/**
98+
* Define application config values as constants.
99+
*
100+
* @return void
101+
*/
56102
private function _readConfig()
57103
{
58104
$config = $this->_getConfig();
59105

60106
$this->_validateConfig($config);
61107

62-
foreach ($config as $k => $v)
108+
foreach ($config as $k => $v) {
63109
define($k, __ROOT__ . '/' . $v);
110+
}
64111
}
65112
}

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
11
# Cherry-Core
2+
The Cherry-project Core
3+
4+
[![GitHub license](https://img.shields.io/github/license/abgeo07/cherry-core.svg)](https://github.com/ABGEO07/cherry-core/blob/master/LICENSE)
5+
6+
[![GitHub release](https://img.shields.io/github/release/abgeo07/cherry-core.svg)](https://github.com/ABGEO07/cherry-core/releases)
7+
8+
[![Packagist Version](https://img.shields.io/packagist/v/cherry-project/core.svg "Packagist Version")](https://packagist.org/packages/cherry-core/request "Packagist Version")
9+
10+
------------
11+
12+
This is core for Cherry-Project that contains Cherry [Request](https://github.com/ABGEO07/cherry-request),
13+
[Response](https://github.com/ABGEO07/cherry-response), [Router](https://github.com/ABGEO07/cherry-router),
14+
[Templater](https://github.com/ABGEO07/cherry-templater) and [Logger](https://github.com/ABGEO07/cherry-logger).
15+
16+
In root of your application you must define main file and call application Core Kernel class:
17+
18+
```php
19+
<?php
20+
21+
require_once __DIR__ . '/../vendor/autoload.php';
22+
23+
$kernel = new Cherry\Kernel(__DIR__);
24+
```
25+
26+
`Kernel` class takes only one argument - your application root path.
27+
28+
With main file you mast have directories `config`, `controllers`, `templates`:
29+
30+
```
31+
root
32+
└─ config/
33+
└─ controllers/
34+
└─ templates/
35+
```
36+
37+
### Config
38+
39+
`config` directory is a 'home' for application config and router files:
40+
```
41+
config/
42+
└─ config.json
43+
└─ routes.json
44+
```
45+
46+
`config.json` contains application environmental parameters:
47+
```json
48+
{
49+
"ROUTES_FILE": "path-to-routes.json",
50+
"CONTROLLERS_PATH": "path-to-controllers-directory",
51+
"TEMPLATES_PATH": "path-to-templates-directory",
52+
"LOGS_PATH": "path-to-logs-directory"
53+
}
54+
```
55+
56+
### Controller
57+
58+
Controller is a simple PHP class that contains public methods mapped on route:
59+
```
60+
"action": "Cherry\\Controller\\DefaultController::index"
61+
```
62+
63+
Every method returns Cherry\HttpUtils\Response object.
64+
65+
```php
66+
$this->render('index');
67+
```
268

369
**2019 &copy; Cherry-project**

0 commit comments

Comments
 (0)