From d0a1f58a7d7fc8799bae4a1bfe21f1bb734a6495 Mon Sep 17 00:00:00 2001 From: Shay Anderson Date: Sat, 16 Jun 2018 09:37:25 -0400 Subject: [PATCH] add services; add db/model update ignore; minor fixes --- LICENSE | 2 +- README.md | 1 + app/com/bootstrap.php | 2 +- app/com/conf/eco.conf.php | 9 -- app/com/model.php | 2 +- app/com/service.php | 9 ++ app/vendor/Eco/Cache.php | 2 +- app/vendor/Eco/Factory.php | 2 +- app/vendor/Eco/Form.php | 2 +- app/vendor/Eco/Http.php | 2 +- app/vendor/Eco/Model.php | 2 +- app/vendor/Eco/System.php | 97 +++++++++++-------- app/vendor/Eco/System/Breadcrumb.php | 2 +- app/vendor/Eco/System/Database.php | 22 ++++- app/vendor/Eco/System/Database/Connection.php | 2 +- app/vendor/Eco/System/Database/Model.php | 19 +++- app/vendor/Eco/System/Database/Pagination.php | 7 +- app/vendor/Eco/System/Filter.php | 2 +- app/vendor/Eco/System/Format.php | 2 +- app/vendor/Eco/System/Keep.php | 2 +- app/vendor/Eco/System/Log.php | 2 +- app/vendor/Eco/System/ModelRegistry.php | 79 --------------- app/vendor/Eco/System/Registry.php | 87 +++++++++++++++++ app/vendor/Eco/System/Registry/Model.php | 23 +++++ app/vendor/Eco/System/Registry/Service.php | 23 +++++ app/vendor/Eco/System/Request.php | 2 +- app/vendor/Eco/System/Router.php | 2 +- app/vendor/Eco/System/Session.php | 2 +- app/vendor/Eco/System/Session/Flash.php | 2 +- app/vendor/Eco/System/Validate.php | 2 +- app/vendor/Eco/System/View.php | 2 +- app/vendor/Eco/Table.php | 2 +- app/vendor/Eco/helper/alias.php | 2 +- app/vendor/Eco/helper/eco.php | 12 ++- app/vendor/Eco/helper/factory.php | 2 +- app/vendor/Eco/helper/flash.php | 2 +- app/vendor/Eco/helper/redirect.php | 4 +- app/vendor/Eco/helper/request.php | 2 +- app/vendor/Eco/helper/view.php | 2 +- app/vendor/Eco/version.php | 4 +- docs/helper.md | 1 + docs/model.md | 2 +- docs/service.md | 22 +++++ 43 files changed, 308 insertions(+), 165 deletions(-) create mode 100644 app/com/service.php delete mode 100644 app/vendor/Eco/System/ModelRegistry.php create mode 100644 app/vendor/Eco/System/Registry.php create mode 100644 app/vendor/Eco/System/Registry/Model.php create mode 100644 app/vendor/Eco/System/Registry/Service.php create mode 100644 docs/service.md diff --git a/LICENSE b/LICENSE index 7ba003f..f110bfd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2017 Shay Anderson +Copyright (c) 2015-2018 Shay Anderson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9ca9eed..cc96d45 100644 --- a/README.md +++ b/README.md @@ -352,6 +352,7 @@ Eco offers the following methods: - [`eco::route($route, $action)`](#routing) - map route - [`eco::router()`](https://github.com/shayanderson/eco/blob/master/docs/router.md) - access core Router class - `eco::run()` - run the application +- [`eco::service()`](https://github.com/shayanderson/eco/blob/master/docs/service.md) - Service class loader ([`service()`](https://github.com/shayanderson/eco/blob/master/docs/helper.md#core-helper-functions) helper function available) - [`eco::session()`](https://github.com/shayanderson/eco/blob/master/docs/session.md) - access Session class ([`session()`](https://github.com/shayanderson/eco/blob/master/docs/helper.md#alias-helper-functions) helper function available) - [`eco::set($key, $value)`](https://github.com/shayanderson/eco/blob/master/docs/vars.md) - set a global variable - `eco::stop()` - gracefully stop the application ([`stop()`](https://github.com/shayanderson/eco/blob/master/docs/helper.md#core-helper-functions) helper function available) diff --git a/app/com/bootstrap.php b/app/com/bootstrap.php index 8167abf..a8f10dc 100644 --- a/app/com/bootstrap.php +++ b/app/com/bootstrap.php @@ -12,7 +12,7 @@ class eco extends \Eco\System {} PATH_VENDOR ]); -// load configuration settings +// load Eco configuration settings eco::conf(PATH_CONF . 'eco.conf.php'); // load helper functions (optional) diff --git a/app/com/conf/eco.conf.php b/app/com/conf/eco.conf.php index f0a0770..6a7e027 100644 --- a/app/com/conf/eco.conf.php +++ b/app/com/conf/eco.conf.php @@ -1,13 +1,4 @@ - * @license MIT License - * @link - */ - /** * Eco configuration settings */ diff --git a/app/com/model.php b/app/com/model.php index 03308c9..161c69b 100644 --- a/app/com/model.php +++ b/app/com/model.php @@ -6,4 +6,4 @@ /** * @property Example\Class $example */ -class EcoModelRegistry extends \Eco\System\ModelRegistry {} \ No newline at end of file +class EcoModelRegistry extends \Eco\System\Registry\Model {} \ No newline at end of file diff --git a/app/com/service.php b/app/com/service.php new file mode 100644 index 0000000..1a28c3f --- /dev/null +++ b/app/com/service.php @@ -0,0 +1,9 @@ + + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/Factory.php b/app/vendor/Eco/Factory.php index 9f98ad1..40b91cd 100644 --- a/app/vendor/Eco/Factory.php +++ b/app/vendor/Eco/Factory.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/Form.php b/app/vendor/Eco/Form.php index 7b32e9d..a90d331 100644 --- a/app/vendor/Eco/Form.php +++ b/app/vendor/Eco/Form.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/Http.php b/app/vendor/Eco/Http.php index 60b64b8..5eeb3d3 100644 --- a/app/vendor/Eco/Http.php +++ b/app/vendor/Eco/Http.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/Model.php b/app/vendor/Eco/Model.php index 80897a8..b3deb17 100644 --- a/app/vendor/Eco/Model.php +++ b/app/vendor/Eco/Model.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System.php b/app/vendor/Eco/System.php index 1185182..c2c6897 100644 --- a/app/vendor/Eco/System.php +++ b/app/vendor/Eco/System.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -80,6 +80,53 @@ final public static function arrayToObject($array) return $array; } + /** + * Registry loader + * + * @staticvar array $registry + * @param string $class + * @return \Eco\System\Registry + */ + private static function __registry($type, $class) + { + static $registry; + + if(!isset($registry[$type])) + { + require_once PATH_COM . $type . '.php'; + + if(!class_exists($class)) + { + throw new \Exception(__METHOD__ . ': ' . $type . ' load failed, \'' . $class . '\'' + . ' class not found'); + } + + // parse class annotations + preg_match_all('#@property\s([^\s]+)\s\$([\w]+)#', // match '@property $' + (new \ReflectionClass($class))->getDocComment(), $m); + + if(isset($m[1]) && $m[1]) + { + foreach($m[1] as $k => $v) + { + if(isset($m[2][$k])) // name + { + $registry[$type][trim($m[2][$k])] = trim($v); + } + } + } + + unset($m); + + if($registry[$type]) // initialize + { + $class::getInstance()->__init($registry[$type]); + } + } + + return $class::getInstance(); + } + /** * Class autoloader * @@ -370,47 +417,11 @@ final public static function log() /** * Model loader + registry * - * @staticvar array $registry * @return \EcoModelRegistry */ final public static function model() { - static $registry; - - if(!$registry) - { - require_once PATH_COM . 'model.php'; - - if(!class_exists('\EcoModelRegistry')) - { - throw new \Exception(__METHOD__ . ': model load failed, \'\EcoModelRegistry\'' - . ' class not found'); - } - - // parse class annotations - preg_match_all('#@property\s([^\s]+)\s\$([\w]+)#', // match '@property $' - (new \ReflectionClass('\EcoModelRegistry'))->getDocComment(), $m); - - if(isset($m[1]) && $m[1]) - { - foreach($m[1] as $k => $v) - { - if(isset($m[2][$k])) // name - { - $registry[trim($m[2][$k])] = trim($v); - } - } - } - - unset($m); - - if($registry) // initialize - { - \EcoModelRegistry::getInstance()->__init($registry); - } - } - - return \EcoModelRegistry::getInstance(); + return self::__registry(\Eco\System\Registry\Model::ID, '\EcoModelRegistry'); } /** @@ -496,6 +507,16 @@ final public static function run() Router::getInstance()->dispatch(); } + /** + * Service loader + registry + * + * @return \EcoServiceRegistry + */ + final public static function service() + { + return self::__registry(\Eco\System\Registry\Service::ID, '\EcoServiceRegistry'); + } + /** * Session object getter * diff --git a/app/vendor/Eco/System/Breadcrumb.php b/app/vendor/Eco/System/Breadcrumb.php index d5e9911..209f544 100644 --- a/app/vendor/Eco/System/Breadcrumb.php +++ b/app/vendor/Eco/System/Breadcrumb.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Database.php b/app/vendor/Eco/System/Database.php index 676db5b..6ee629f 100644 --- a/app/vendor/Eco/System/Database.php +++ b/app/vendor/Eco/System/Database.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -837,9 +837,10 @@ public function truncate($table) * * @param string $table_or_sql * @param array $params + * @param boolean $ignore * @return int (affected) */ - public function update($table_or_sql, array $params = null) + public function update($table_or_sql, array $params, $is_ignore = false) { $p = []; $values = []; @@ -874,8 +875,21 @@ public function update($table_or_sql, array $params = null) $table_or_sql = substr($table_or_sql, 0, $pos); } - return $this->__getConn()->query('UPDATE ' . $table_or_sql . ' SET ' - . implode(', ', $values) . $sql, $p, Connection::QUERY_RETURN_TYPE_AFFECTED); + return $this->__getConn()->query('UPDATE ' . ( $is_ignore ? 'IGNORE ' : null ) + . $table_or_sql . ' SET ' . implode(', ', $values) . $sql, $p, + Connection::QUERY_RETURN_TYPE_AFFECTED); + } + + /** + * Update with ignore + * + * @param string $table_or_sql + * @param array $params + * @return int (affected) + */ + public function updateIgnore($table_or_sql, array $params) + { + return $this->update($table_or_sql, $params, true); } /** diff --git a/app/vendor/Eco/System/Database/Connection.php b/app/vendor/Eco/System/Database/Connection.php index a67cf00..3f571c5 100644 --- a/app/vendor/Eco/System/Database/Connection.php +++ b/app/vendor/Eco/System/Database/Connection.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Database/Model.php b/app/vendor/Eco/System/Database/Model.php index c1339f2..681b7e3 100644 --- a/app/vendor/Eco/System/Database/Model.php +++ b/app/vendor/Eco/System/Database/Model.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -310,9 +310,10 @@ public function truncate() * * @param mixed $id_or_sql * @param array $params + * @param boolean $is_ignore * @return int (affected) */ - public function update($id_or_sql, array $params) + public function update($id_or_sql, array $params, $is_ignore = false) { if(is_numeric($id_or_sql)) { @@ -321,7 +322,19 @@ public function update($id_or_sql, array $params) } return $this->__db()->update($this->__name . ' ' . $this->__addWhereKeyword($id_or_sql), - $params); + $params, $is_ignore); + } + + /** + * Update with ignore (WHERE keyword optional) + * + * @param mixed $id_or_sql + * @param array $params + * @return int (affected) + */ + public function updateIgnore($id_or_sql, array $params) + { + return $this->update($id_or_sql, $params, true); } /** diff --git a/app/vendor/Eco/System/Database/Pagination.php b/app/vendor/Eco/System/Database/Pagination.php index bec1ec3..ba4806c 100644 --- a/app/vendor/Eco/System/Database/Pagination.php +++ b/app/vendor/Eco/System/Database/Pagination.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -221,6 +221,11 @@ public function get() $this->__conf->wrapper->next); } + if(!$html) + { + return ''; + } + return isset($this->__conf->wrapper->group) ? str_replace('{$group}', $html, $this->__conf->wrapper->group) : $html; } diff --git a/app/vendor/Eco/System/Filter.php b/app/vendor/Eco/System/Filter.php index 90c9f93..185d30b 100644 --- a/app/vendor/Eco/System/Filter.php +++ b/app/vendor/Eco/System/Filter.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Format.php b/app/vendor/Eco/System/Format.php index 8d71a0b..667e45a 100644 --- a/app/vendor/Eco/System/Format.php +++ b/app/vendor/Eco/System/Format.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Keep.php b/app/vendor/Eco/System/Keep.php index 8e2170b..bd3bc7e 100644 --- a/app/vendor/Eco/System/Keep.php +++ b/app/vendor/Eco/System/Keep.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Log.php b/app/vendor/Eco/System/Log.php index 28b6dc8..ac1ad1a 100644 --- a/app/vendor/Eco/System/Log.php +++ b/app/vendor/Eco/System/Log.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/ModelRegistry.php b/app/vendor/Eco/System/ModelRegistry.php deleted file mode 100644 index 55923a0..0000000 --- a/app/vendor/Eco/System/ModelRegistry.php +++ /dev/null @@ -1,79 +0,0 @@ - - * @license MIT License - * @link - */ -namespace Eco\System; - -/** - * Model registry - * - * @author Shay Anderson - */ -abstract class ModelRegistry extends \Eco\Factory -{ - /** - * Model registry - * - * @var array - */ - private static $__registry; - - /** - * Model getter - * - * @param string $name - * @return mixed - * @throws \Exception (model or model class does not exist) - */ - public function __get($name) - { - static $model = []; - - if(isset($model[$name])) - { - return $model[$name]; - } - - if(isset(self::$__registry[$name])) // lazy load - { - if(!class_exists(self::$__registry[$name])) - { - throw new \Exception(__METHOD__ . ': failed to find model class \'' - . self::$__registry[$name] . '\''); - } - - $model[$name] = new self::$__registry[$name]; - return $model[$name]; - } - - throw new \Exception(__METHOD__ . ': failed to find model \'' . $name . '\''); - } - - /** - * Initialize registry - * - * @param array $registry - */ - public function __init(array &$registry) - { - if(!self::$__registry) - { - self::$__registry = &$registry; - } - } - - /** - * Registry getter - * - * @return array - */ - public function get() - { - return self::$__registry; - } -} \ No newline at end of file diff --git a/app/vendor/Eco/System/Registry.php b/app/vendor/Eco/System/Registry.php new file mode 100644 index 0000000..742922f --- /dev/null +++ b/app/vendor/Eco/System/Registry.php @@ -0,0 +1,87 @@ + + * @license MIT License + * @link + */ +namespace Eco\System; + +/** + * Registry + * + * @author Shay Anderson + */ +class Registry extends \Eco\Factory +{ + /** + * Registry child ID + */ + const ID = null; + + /** + * Class registry + * + * @var array + */ + private static $__registry; + + /** + * Class getter + * + * @param string $name + * @return mixed + * @throws \Exception (class or object does not exist) + */ + public function __get($name) + { + static $reg = []; + + if(isset($reg[static::ID][$name])) + { + return $reg[static::ID][$name]; + } + + if(isset(self::$__registry[static::ID][$name])) // lazy load + { + if(!class_exists(self::$__registry[static::ID][$name])) + { + throw new \Exception(__METHOD__ . ': failed to find ' . static::ID . ' class \'' + . self::$__registry[static::ID][$name] . '\''); + } + + $class = self::$__registry[static::ID][$name]; + + $reg[static::ID][$name] = new $class; + + return $reg[static::ID][$name]; + } + + throw new \Exception(__METHOD__ . ': failed to find ' . static::ID . ' \'' . $name . '\''); + } + + /** + * Initialize registry + * + * @param array $registry + */ + public function __init(array &$registry) + { + if(!isset(self::$__registry[static::ID])) + { + self::$__registry[static::ID] = &$registry; + } + } + + /** + * Registry getter + * + * @return array + */ + public function get() + { + return self::$__registry[static::ID]; + } +} \ No newline at end of file diff --git a/app/vendor/Eco/System/Registry/Model.php b/app/vendor/Eco/System/Registry/Model.php new file mode 100644 index 0000000..1462e9a --- /dev/null +++ b/app/vendor/Eco/System/Registry/Model.php @@ -0,0 +1,23 @@ + + * @license MIT License + * @link + */ +namespace Eco\System\Registry; + +/** + * Model registry + * + * @author Shay Anderson + */ +class Model extends \Eco\System\Registry +{ + /** + * Registry ID + */ + const ID = 'model'; +} \ No newline at end of file diff --git a/app/vendor/Eco/System/Registry/Service.php b/app/vendor/Eco/System/Registry/Service.php new file mode 100644 index 0000000..7c6671d --- /dev/null +++ b/app/vendor/Eco/System/Registry/Service.php @@ -0,0 +1,23 @@ + + * @license MIT License + * @link + */ +namespace Eco\System\Registry; + +/** + * Service registry + * + * @author Shay Anderson + */ +class Service extends \Eco\System\Registry +{ + /** + * Registry ID + */ + const ID = 'service'; +} \ No newline at end of file diff --git a/app/vendor/Eco/System/Request.php b/app/vendor/Eco/System/Request.php index b1578ca..6545215 100644 --- a/app/vendor/Eco/System/Request.php +++ b/app/vendor/Eco/System/Request.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Router.php b/app/vendor/Eco/System/Router.php index c20ae87..7112cb9 100644 --- a/app/vendor/Eco/System/Router.php +++ b/app/vendor/Eco/System/Router.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Session.php b/app/vendor/Eco/System/Session.php index 8cfe5c2..7298e8c 100644 --- a/app/vendor/Eco/System/Session.php +++ b/app/vendor/Eco/System/Session.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Session/Flash.php b/app/vendor/Eco/System/Session/Flash.php index b07b32a..65da6b0 100644 --- a/app/vendor/Eco/System/Session/Flash.php +++ b/app/vendor/Eco/System/Session/Flash.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/Validate.php b/app/vendor/Eco/System/Validate.php index 353459a..4436768 100644 --- a/app/vendor/Eco/System/Validate.php +++ b/app/vendor/Eco/System/Validate.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/System/View.php b/app/vendor/Eco/System/View.php index a8abd00..b29ebe0 100644 --- a/app/vendor/Eco/System/View.php +++ b/app/vendor/Eco/System/View.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/Table.php b/app/vendor/Eco/Table.php index 2e86882..0cc1097 100644 --- a/app/vendor/Eco/Table.php +++ b/app/vendor/Eco/Table.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/helper/alias.php b/app/vendor/Eco/helper/alias.php index 5a4a923..d50f7c3 100644 --- a/app/vendor/Eco/helper/alias.php +++ b/app/vendor/Eco/helper/alias.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/helper/eco.php b/app/vendor/Eco/helper/eco.php index 9c92a78..d41f6c4 100644 --- a/app/vendor/Eco/helper/eco.php +++ b/app/vendor/Eco/helper/eco.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -76,6 +76,16 @@ function pa($v = null) : ( PHP_SAPI === 'cli' ? print_r($v, true) : '
' . print_r($v, true) . '
' ); } +/** + * Service object getter + * + * @return \EcoServiceRegistry + */ +function service() +{ + return System::service(); +} + /** * Session exists flag getter * diff --git a/app/vendor/Eco/helper/factory.php b/app/vendor/Eco/helper/factory.php index 8abd3c3..8809601 100644 --- a/app/vendor/Eco/helper/factory.php +++ b/app/vendor/Eco/helper/factory.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/helper/flash.php b/app/vendor/Eco/helper/flash.php index eb792fa..1e369e4 100644 --- a/app/vendor/Eco/helper/flash.php +++ b/app/vendor/Eco/helper/flash.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/helper/redirect.php b/app/vendor/Eco/helper/redirect.php index ca3e17c..9d847d9 100644 --- a/app/vendor/Eco/helper/redirect.php +++ b/app/vendor/Eco/helper/redirect.php @@ -3,11 +3,13 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ +use Eco\System; + /** * Redirect helper * diff --git a/app/vendor/Eco/helper/request.php b/app/vendor/Eco/helper/request.php index 98b81db..5131599 100644 --- a/app/vendor/Eco/helper/request.php +++ b/app/vendor/Eco/helper/request.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/helper/view.php b/app/vendor/Eco/helper/view.php index 0f0ee20..3f1451f 100644 --- a/app/vendor/Eco/helper/view.php +++ b/app/vendor/Eco/helper/view.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ diff --git a/app/vendor/Eco/version.php b/app/vendor/Eco/version.php index 93b3969..4d7be4d 100644 --- a/app/vendor/Eco/version.php +++ b/app/vendor/Eco/version.php @@ -3,7 +3,7 @@ * Eco is a PHP Framework for PHP 5.5+ * * @package Eco - * @copyright 2015-2017 Shay Anderson + * @copyright 2015-2018 Shay Anderson * @license MIT License * @link */ @@ -11,4 +11,4 @@ /** * Eco version */ -const ECO_VERSION = '1.3.4'; \ No newline at end of file +const ECO_VERSION = '1.3.5'; \ No newline at end of file diff --git a/docs/helper.md b/docs/helper.md index 80cd854..7476468 100644 --- a/docs/helper.md +++ b/docs/helper.md @@ -16,6 +16,7 @@ The core helper functions are mostly used to quickly access Eco methods (shortha - `logger()` - `eco::log()` alias - `model()` - `eco::model()` alias - `pa($v)` - HTML or CLI friendly printer for all PHP types +- `service()` - `eco::service()` alias - `session_exists()` - determine if a PHP session exists - `stop()` - `eco::stop()` alias - `view($template, $view_params)` - `eco::view()` alias diff --git a/docs/model.md b/docs/model.md index 2d6759e..9243665 100644 --- a/docs/model.md +++ b/docs/model.md @@ -27,7 +27,7 @@ First, model classes need to be "registered" in the *model registry* in the `app * @property App\Model\Document\Entity $doc_entity * @property App\Model\User $user */ -class EcoModelRegistry extends \Eco\System\ModelRegistry {} +class EcoModelRegistry extends \Eco\System\Registry\Model {} ``` Now each of these registered model classes can be accessed using the `eco::model()` method or the helper function `model()` (used in examples below). diff --git a/docs/service.md b/docs/service.md new file mode 100644 index 0000000..9997d99 --- /dev/null +++ b/docs/service.md @@ -0,0 +1,22 @@ +# Using Services +Services can be used with classes to simplify accessibility. + +### Basic Usage +First, classes used as services need to be "registered" in the *service registry* in the `app/com/service.php` file. Each class is added in the comment block above the `EcoServiceRegistry` class using the `@property ` syntax, for example: +```php +/** + * @property App\Service\Session $session + * @property App\Service\User $user + */ +class EcoServiceRegistry extends \Eco\System\Registry\Service {} +``` +Now each of these registered classes can be accessed using the `eco::service()` method or the helper function `service()` (used in examples below). +```php +// use session service (auto instantiation) +$session_id = service()->session->getId(); + +// service classes can also be manually instantiated +service()->user = new \App\Service\User($user_id); +service()->user->load(); +$name = service()->user->getName(); +```