From aec1a60985b7d1ad1334bfb5bd5480a5101fe752 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Tue, 27 May 2014 17:56:46 +0400 Subject: [PATCH] Commit with composer.json --- Config.php | 10 ++++++---- app/FrontController.php | 2 +- app/router/Route.php | 2 ++ app/router/Router.php | 2 +- composer.json | 8 ++++++++ form/Form.php | 12 +++++++----- model/Db.php | 14 ++++++++------ model/DbStatement.php | 8 ++++---- model/Model.php | 24 +++++++++++++----------- model/MySQLiStatement.php | 12 ++++++------ model/SqlModel.php | 2 +- redis/RedisManager.php | 4 ++-- session/Session.php | 2 ++ validator/EqualValidator.php | 2 +- validator/MbStrlenValidator.php | 2 +- validator/NotEmptyValidator.php | 2 +- validator/RegexValidator.php | 2 +- validator/StrlenValidator.php | 2 +- validator/Validator.php | 2 ++ validator/iValidator.php | 2 ++ 20 files changed, 70 insertions(+), 46 deletions(-) create mode 100644 composer.json diff --git a/Config.php b/Config.php index 4d094bf..223fc81 100644 --- a/Config.php +++ b/Config.php @@ -7,7 +7,9 @@ * @since 2010-02-17 */ -class Config extends Registry +namespace Majestic; + +class Config extends \Registry { private static $_class_name = 'Config'; @@ -21,17 +23,17 @@ class Config extends Registry } } -class ConfigArray extends ArrayObject +class ConfigArray extends \ArrayObject { public function __construct($array) { - parent::__construct($array, ArrayObject::ARRAY_AS_PROPS); + parent::__construct($array, \ArrayObject::ARRAY_AS_PROPS); } public function offsetGet($index) { if (!$this->offsetExists($index)) { - throw new GeneralException('Configuration variable "' . $index . '" undefined'); + throw new \GeneralException('Configuration variable "' . $index . '" undefined'); } return parent::offsetGet($index); } diff --git a/app/FrontController.php b/app/FrontController.php index a8ef935..1b03064 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -29,7 +29,7 @@ class FrontController private function __construct() { - ErrorHandler::init(); +// ErrorHandler::init(); $this->router = new Router(); } diff --git a/app/router/Route.php b/app/router/Route.php index 92a59c8..5f8b456 100644 --- a/app/router/Route.php +++ b/app/router/Route.php @@ -7,6 +7,8 @@ * @since 2010-02-25 */ +namespace Majestic; + class Route { diff --git a/app/router/Router.php b/app/router/Router.php index 0a296c2..ec09a2a 100644 --- a/app/router/Router.php +++ b/app/router/Router.php @@ -33,7 +33,7 @@ class Router if (!$layout) { $layout = $this->default_layout; } - $this->routes[$name] = new Route($route, $action, $params, $layout); + $this->routes[$name] = new \Majestic\Route($route, $action, $params, $layout); } /** diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9179706 --- /dev/null +++ b/composer.json @@ -0,0 +1,8 @@ +{ + "name": "majestic/core", + "version": "0.1.0", + "dist": { + "type": "git", + "url": "git@dimti.ru:majestic.git" + } +} \ No newline at end of file diff --git a/form/Form.php b/form/Form.php index fd061b9..093ac5c 100644 --- a/form/Form.php +++ b/form/Form.php @@ -7,6 +7,8 @@ * @since 2010-04-24 */ +namespace Majestic; + abstract class Form { @@ -15,7 +17,7 @@ abstract class Form const ERROR = 'error'; /** - * @var FormField[] + * @var \FormField[] */ protected $fields = array(); @@ -36,18 +38,18 @@ abstract class Form /** * @param string $name * @param bool|string $message - * @return FormField + * @return \FormField */ protected function addField($name, $message = false) { - $this->fields[$name] = new FormField($message); + $this->fields[$name] = new \FormField($message); return $this->fields[$name]; } public function isValid($data) { if (!is_array($data)) { - throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array'); + throw new \InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array'); } foreach ($this->fields as $field_name => $field) { @@ -148,7 +150,7 @@ abstract class Form { $data['messages'] = $this->getMessages(); $data['values'] = $this->getSourceValues(); - Session::set(get_class($this), $data); + \Majestic\Session::set(get_class($this), $data); } abstract protected function init(); diff --git a/model/Db.php b/model/Db.php index df0ec5b..66f11cc 100644 --- a/model/Db.php +++ b/model/Db.php @@ -7,6 +7,8 @@ * @since 2010-02-16 */ +namespace Majestic; + class Db { @@ -35,14 +37,14 @@ class Db { if (!isset(self::$connections[$name])) { if (!$config) { - if (!is_object(Config::get(__CLASS__))) { - throw new InitializationException('Trying to get property of non-object'); + if (!is_object(\Majestic\Config::get(__CLASS__))) { + throw new \InitializationException('Trying to get property of non-object'); } - $config = Config::get(__CLASS__)->$name; + $config = \Majestic\Config::get(__CLASS__)->$name; } if (!is_array($config)) { - throw new InitializationException('Connection parameters must be an array'); + throw new \InitializationException('Connection parameters must be an array'); } $driver = 'MySQLiDriver'; @@ -53,8 +55,8 @@ class Db $connection = new $driver($config); - if (!$connection instanceof DbDriver) { - throw new InitializationException('Database driver must extends DbDriver'); + if (!$connection instanceof \DbDriver) { + throw new \InitializationException('Database driver must extends DbDriver'); } self::$connections[$name] = $connection; } diff --git a/model/DbStatement.php b/model/DbStatement.php index 6dbbf2c..40a2ad7 100644 --- a/model/DbStatement.php +++ b/model/DbStatement.php @@ -53,7 +53,7 @@ abstract class DbStatement * @param mixed $style * @return array */ - public function fetchAll($style = Db::FETCH_OBJ) + public function fetchAll($style = \Majestic\Db::FETCH_OBJ) { $data = array(); while ($row = $this->fetch($style)) { @@ -69,7 +69,7 @@ abstract class DbStatement public function fetchColumn($field) { $data = array(); - while ($row = $this->fetch(Db::FETCH_ASSOC)) { + while ($row = $this->fetch(\Majestic\Db::FETCH_ASSOC)) { $data[] = $row[$field]; } return $data; @@ -81,7 +81,7 @@ abstract class DbStatement */ public function fetchField($field) { - $row = $this->fetch(Db::FETCH_ASSOC); + $row = $this->fetch(\Majestic\Db::FETCH_ASSOC); if (isset($row[$field])) { return $row[$field]; } @@ -94,7 +94,7 @@ abstract class DbStatement abstract protected function assemble(); - abstract public function fetch($style = Db::FETCH_OBJ); + abstract public function fetch($style = \Majestic\Db::FETCH_OBJ); abstract public function fetchObject($class = 'stdClass'); diff --git a/model/Model.php b/model/Model.php index f063d17..30fba75 100644 --- a/model/Model.php +++ b/model/Model.php @@ -10,20 +10,22 @@ * @since 2010-02-16 */ +namespace Majestic; + abstract class Model { /** * DbDriver instance * - * @var DbDriver + * @var \DbDriver */ protected $db; /** * Cache instance * - * @var Cache + * @var \Cache */ protected $cache; @@ -48,7 +50,7 @@ abstract class Model public function __construct($connection = 'default') { - $this->db = Db::connect($connection); + $this->db = \Majestic\Db::connect($connection); } /** @@ -94,12 +96,12 @@ abstract class Model /* Cache workaround */ /** - * @return Cache + * @return \Cache */ public function getCache() { if (!$this->cache) { - $this->cache = Cacher::get(Config::get(__CLASS__, 'MemcacheCache')); + $this->cache = \Cacher::get(Config::get(__CLASS__, 'MemcacheCache')); } return $this->cache; } @@ -107,16 +109,16 @@ abstract class Model /** * @param string $name * @param array $params - * @return CacheKey + * @return \CacheKey */ protected function cacheKey($name, $params = array()) { $expire = (isset($this->cache_keys[$name])) ? ($this->cache_keys[$name] * 60) : 0; - return new CacheKey($this->getCache(), $name, $params, $expire); + return new \CacheKey($this->getCache(), $name, $params, $expire); } /** - * @param CacheKey $cache + * @param \CacheKey $cache */ protected function addCleanCache($cache) { @@ -152,21 +154,21 @@ abstract class Model * @param string $data Request * @param array $params Request parameters * @param string $field Requested field name - * @param CacheKey $cache_key Key for caching in + * @param \CacheKey $cache_key Key for caching in */ abstract protected function fetchField($data, $params = array(), $field, $cache_key = null); /** * @param string $data Request * @param array $params Request parameters - * @param CacheKey $cache_key Key for caching in + * @param \CacheKey $cache_key Key for caching in */ abstract protected function fetch($data, $params = array(), $cache_key = null); /** * @param string $data * @param array $params - * @param CacheKey $cache_key + * @param \CacheKey $cache_key */ abstract protected function fetchAll($data, $params = array(), $cache_key = null); } \ No newline at end of file diff --git a/model/MySQLiStatement.php b/model/MySQLiStatement.php index a57e0f3..9da6219 100644 --- a/model/MySQLiStatement.php +++ b/model/MySQLiStatement.php @@ -83,23 +83,23 @@ class MySQLiStatement extends DbStatement * @return mixed * @throws GeneralException */ - public function fetch($style = Db::FETCH_OBJ) + public function fetch($style = \Majestic\Db::FETCH_OBJ) { if (!$this->result) { return false; } switch ($style) { - case Db::FETCH_OBJ: + case \Majestic\Db::FETCH_OBJ: $row = $this->result->fetch_object(); break; - case Db::FETCH_NUM: + case \Majestic\Db::FETCH_NUM: $row = $this->result->fetch_array(MYSQLI_NUM); break; - case Db::FETCH_ASSOC: + case \Majestic\Db::FETCH_ASSOC: $row = $this->result->fetch_assoc(); break; - case Db::FETCH_BOTH: + case \Majestic\Db::FETCH_BOTH: $row = $this->result->fetch_array(MYSQLI_BOTH); break; default: @@ -123,7 +123,7 @@ class MySQLiStatement extends DbStatement public function fetchPairs() { $data = array(); - while ($row = $this->fetch(Db::FETCH_NUM)) { + while ($row = $this->fetch(\Majestic\Db::FETCH_NUM)) { $data[$row[0]] = $row[1]; } return $data; diff --git a/model/SqlModel.php b/model/SqlModel.php index a35f509..4a0dfef 100644 --- a/model/SqlModel.php +++ b/model/SqlModel.php @@ -13,7 +13,7 @@ /** * @property SqlDbDriver $db */ -abstract class SqlModel extends Model +abstract class SqlModel extends \Majestic\Model { /** * @param string $ident diff --git a/redis/RedisManager.php b/redis/RedisManager.php index 4c8479f..29b17d4 100644 --- a/redis/RedisManager.php +++ b/redis/RedisManager.php @@ -30,10 +30,10 @@ class RedisManager { if (!isset(self::$connections[$name])) { if (!$config) { - if (!is_object(Config::get('Redis'))) { + if (!is_object(\Majestic\Config::get('Redis'))) { throw new GeneralException('Redis config no existence'); } - $config = Config::get('Redis')->$name; + $config = \Majestic\Config::get('Redis')->$name; } if (!is_array($config)) { diff --git a/session/Session.php b/session/Session.php index 20e286c..c6bb514 100644 --- a/session/Session.php +++ b/session/Session.php @@ -7,6 +7,8 @@ * @since 2010-03-14 */ +namespace Majestic; + class Session { /** diff --git a/validator/EqualValidator.php b/validator/EqualValidator.php index 961672f..dadb28c 100644 --- a/validator/EqualValidator.php +++ b/validator/EqualValidator.php @@ -7,7 +7,7 @@ * @since 2010-04-26 */ -class EqualValidator extends Validator +class EqualValidator extends \Majestic\Validator { const NOT_EQUAL = 'not_match'; diff --git a/validator/MbStrlenValidator.php b/validator/MbStrlenValidator.php index 7f66555..4539fe9 100644 --- a/validator/MbStrlenValidator.php +++ b/validator/MbStrlenValidator.php @@ -9,7 +9,7 @@ * */ -class MbStrlenValidator extends Validator +class MbStrlenValidator extends \Majestic\Validator { const GREATHER_THAN = 'not_match'; diff --git a/validator/NotEmptyValidator.php b/validator/NotEmptyValidator.php index 13bded2..cf4b418 100644 --- a/validator/NotEmptyValidator.php +++ b/validator/NotEmptyValidator.php @@ -7,7 +7,7 @@ * @since 2010-04-26 */ -class NotEmptyValidator extends Validator +class NotEmptyValidator extends \Majestic\Validator { const IS_EMPTY = 'is_empty'; diff --git a/validator/RegexValidator.php b/validator/RegexValidator.php index a198db4..9f419cf 100644 --- a/validator/RegexValidator.php +++ b/validator/RegexValidator.php @@ -7,7 +7,7 @@ * @since 2010-04-26 */ -class RegexValidator extends Validator +class RegexValidator extends \Majestic\Validator { const NOT_MATCH = 'regex_not_match'; diff --git a/validator/StrlenValidator.php b/validator/StrlenValidator.php index a6ebcbc..12fd41e 100644 --- a/validator/StrlenValidator.php +++ b/validator/StrlenValidator.php @@ -9,7 +9,7 @@ * */ -class StrlenValidator extends Validator +class StrlenValidator extends \Majestic\Validator { const GREATHER_THAN = 'not_match'; diff --git a/validator/Validator.php b/validator/Validator.php index 3f875b9..d2ad29a 100644 --- a/validator/Validator.php +++ b/validator/Validator.php @@ -7,6 +7,8 @@ * @since 2010-04-24 */ +namespace Majestic; + abstract class Validator implements iValidator { diff --git a/validator/iValidator.php b/validator/iValidator.php index 2130ad6..c2b2b77 100644 --- a/validator/iValidator.php +++ b/validator/iValidator.php @@ -7,6 +7,8 @@ * @since 2010-04-25 */ +namespace Majestic; + interface iValidator { public function isValid($value, $context = null);