From d41c413384d5e731bc0433a2f93649e9afc8a1d9 Mon Sep 17 00:00:00 2001 From: ABGEO Date: Fri, 29 Mar 2019 22:05:21 +0400 Subject: [PATCH 1/3] Validate code with PHP CodeSniffer --- Cherry/Controller/ControllerTrait.php | 31 +++++++++++++++- Cherry/Kernel.php | 53 +++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/Cherry/Controller/ControllerTrait.php b/Cherry/Controller/ControllerTrait.php index 39648f8..0bfe54d 100644 --- a/Cherry/Controller/ControllerTrait.php +++ b/Cherry/Controller/ControllerTrait.php @@ -1,12 +1,41 @@ + * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT + * @link https://github.com/ABGEO07/cherry-core + */ namespace Cherry\Controller; +use Cherry\HttpUtils\Response; use Cherry\Templating\Templater; +/** + * Trait for Cherry Controllers. + * + * @category Library + * @package Cherry + * @author Temuri Takalandze + * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT + * @link https://github.com/ABGEO07/cherry-core + */ trait ControllerTrait { - private function render($template, $args = []) + /** + * Render the template. + * + * @param string $template Template filename for rendering + * @param array $args Arguments for passing in template + * + * @return Response + */ + protected function render($template, $args = []) { $te = new Templater(TEMPLATES_PATH); diff --git a/Cherry/Kernel.php b/Cherry/Kernel.php index ae00301..63fa487 100644 --- a/Cherry/Kernel.php +++ b/Cherry/Kernel.php @@ -1,9 +1,29 @@ + * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT + * @link https://github.com/ABGEO07/cherry-core + */ namespace Cherry; use Cherry\Routing\Router; +/** + * Application Kernel class. + * + * @category Library + * @package Cherry + * @author Temuri Takalandze + * @license https://github.com/ABGEO07/cherry-core/blob/master/LICENSE MIT + * @link https://github.com/ABGEO07/cherry-core + */ class Kernel { private $_appRoot; @@ -11,6 +31,11 @@ class Kernel public $router; public $logger; + /** + * Kernel constructor. + * + * @param string $appRoot Application root path. + */ public function __construct($appRoot) { define('__ROOT__', $appRoot); @@ -20,6 +45,11 @@ public function __construct($appRoot) $this->run(); } + /** + * Run application. + * + * @return void + */ public function run() { $this->_readConfig(); @@ -28,6 +58,11 @@ public function run() $this->logger = new Logger('app', LOGS_PATH); } + /** + * Read config from file. + * + * @return array + */ private function _getConfig() { $config = file_get_contents(__ROOT__ . '/config/config.json') @@ -36,6 +71,13 @@ private function _getConfig() return json_decode($config, 1); } + /** + * Check if needed keys isset in config file + * + * @param array $config Application Config + * + * @return void + */ private function _validateConfig(array $config) { $neededKeys = [ @@ -45,21 +87,26 @@ private function _validateConfig(array $config) 'LOGS_PATH' ]; - foreach ($neededKeys as $k) - { + foreach ($neededKeys as $k) { if (!isset($config[$k])) { die("Parameter \"{$k}\" don't found in config file!"); } } } + /** + * Define application config values as constants. + * + * @return void + */ private function _readConfig() { $config = $this->_getConfig(); $this->_validateConfig($config); - foreach ($config as $k => $v) + foreach ($config as $k => $v) { define($k, __ROOT__ . '/' . $v); + } } } \ No newline at end of file From 9e8213502b0fc737a5b92833f111c5612756d06c Mon Sep 17 00:00:00 2001 From: ABGEO Date: Fri, 29 Mar 2019 22:57:15 +0400 Subject: [PATCH 2/3] Update README --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index 262173a..0da9a29 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,69 @@ # Cherry-Core +The Cherry-project Core + +[![GitHub license](https://img.shields.io/github/license/abgeo07/cherry-core.svg)](https://github.com/ABGEO07/cherry-core/blob/master/LICENSE) + +[![GitHub release](https://img.shields.io/github/release/abgeo07/cherry-core.svg)](https://github.com/ABGEO07/cherry-core/releases) + +[![Packagist Version](https://img.shields.io/packagist/v/cherry-project/core.svg "Packagist Version")](https://packagist.org/packages/cherry-core/request "Packagist Version") + +------------ + +This is core for Cherry-Project that contains Cherry [Request](https://github.com/ABGEO07/cherry-request), +[Response](https://github.com/ABGEO07/cherry-response), [Router](https://github.com/ABGEO07/cherry-router), +[Templater](https://github.com/ABGEO07/cherry-templater) and [Logger](https://github.com/ABGEO07/cherry-logger). + +In root of your application you must define main file and call application Core Kernel class: + +```php +render('index'); +``` **2019 © Cherry-project** From 752fdd6f12fc6ab5fc7805b388ab35c0fe193475 Mon Sep 17 00:00:00 2001 From: ABGEO Date: Fri, 29 Mar 2019 23:08:37 +0400 Subject: [PATCH 3/3] Create CHANGELOG --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..790a92f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# Cherry-core Changelog + +## [v1.0.0](https://github.com/ABGEO07/cherry-core/releases/tag/v1.0.0 "v1.0.0") (2019-03-29) +#### The first stable version + +- Package available on: `composer require cherry-project/core` + +- Core contains all cherry-project sub-packages + - [Request](https://github.com/ABGEO07/cherry-request) + - [Response](https://github.com/ABGEO07/cherry-response) + - [Router](https://github.com/ABGEO07/cherry-router) + - [Templater](https://github.com/ABGEO07/cherry-templater) + - [Logger](https://github.com/ABGEO07/cherry-logger)