Skip to content

Commit

Permalink
add services; add db/model update ignore; minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanderson committed Jun 16, 2018
1 parent c5c9782 commit d0a1f58
Show file tree
Hide file tree
Showing 43 changed files with 308 additions and 165 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Shay Anderson <http://www.shayanderson.com>
Copyright (c) 2015-2018 Shay Anderson <http://www.shayanderson.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/com/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions app/com/conf/eco.conf.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<?php
/**
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/

/**
* Eco configuration settings
*/
Expand Down
2 changes: 1 addition & 1 deletion app/com/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
/**
* @property Example\Class $example
*/
class EcoModelRegistry extends \Eco\System\ModelRegistry {}
class EcoModelRegistry extends \Eco\System\Registry\Model {}
9 changes: 9 additions & 0 deletions app/com/service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Application service registry
*/

/**
* @property Example\Class $example
*/
class EcoServiceRegistry extends \Eco\System\Registry\Service {}
2 changes: 1 addition & 1 deletion app/vendor/Eco/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
97 changes: 59 additions & 38 deletions app/vendor/Eco/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down Expand Up @@ -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 <class> $<name>'
(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
*
Expand Down Expand Up @@ -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 <class> $<name>'
(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');
}

/**
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
22 changes: 18 additions & 4 deletions app/vendor/Eco/System/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
19 changes: 16 additions & 3 deletions app/vendor/Eco/System/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down Expand Up @@ -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))
{
Expand All @@ -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);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion app/vendor/Eco/System/Database/Pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Keep.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
2 changes: 1 addition & 1 deletion app/vendor/Eco/System/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Eco is a PHP Framework for PHP 5.5+
*
* @package Eco
* @copyright 2015-2017 Shay Anderson <http://www.shayanderson.com>
* @copyright 2015-2018 Shay Anderson <http://www.shayanderson.com>
* @license MIT License <https://github.com/shayanderson/eco/blob/master/LICENSE>
* @link <https://github.com/shayanderson/eco>
*/
Expand Down
Loading

0 comments on commit d0a1f58

Please sign in to comment.