Browse Source

Commit with composer.json

namespace
Alexander Demidov 11 years ago
parent
commit
aec1a60985
  1. 10
      Config.php
  2. 2
      app/FrontController.php
  3. 2
      app/router/Route.php
  4. 2
      app/router/Router.php
  5. 8
      composer.json
  6. 12
      form/Form.php
  7. 14
      model/Db.php
  8. 8
      model/DbStatement.php
  9. 24
      model/Model.php
  10. 12
      model/MySQLiStatement.php
  11. 2
      model/SqlModel.php
  12. 4
      redis/RedisManager.php
  13. 2
      session/Session.php
  14. 2
      validator/EqualValidator.php
  15. 2
      validator/MbStrlenValidator.php
  16. 2
      validator/NotEmptyValidator.php
  17. 2
      validator/RegexValidator.php
  18. 2
      validator/StrlenValidator.php
  19. 2
      validator/Validator.php
  20. 2
      validator/iValidator.php

10
Config.php

@ -7,7 +7,9 @@
* @since 2010-02-17 * @since 2010-02-17
*/ */
class Config extends Registry
namespace Majestic;
class Config extends \Registry
{ {
private static $_class_name = 'Config'; 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) public function __construct($array)
{ {
parent::__construct($array, ArrayObject::ARRAY_AS_PROPS);
parent::__construct($array, \ArrayObject::ARRAY_AS_PROPS);
} }
public function offsetGet($index) public function offsetGet($index)
{ {
if (!$this->offsetExists($index)) { if (!$this->offsetExists($index)) {
throw new GeneralException('Configuration variable "' . $index . '" undefined');
throw new \GeneralException('Configuration variable "' . $index . '" undefined');
} }
return parent::offsetGet($index); return parent::offsetGet($index);
} }

2
app/FrontController.php

@ -29,7 +29,7 @@ class FrontController
private function __construct() private function __construct()
{ {
ErrorHandler::init();
// ErrorHandler::init();
$this->router = new Router(); $this->router = new Router();
} }

2
app/router/Route.php

@ -7,6 +7,8 @@
* @since 2010-02-25 * @since 2010-02-25
*/ */
namespace Majestic;
class Route class Route
{ {

2
app/router/Router.php

@ -33,7 +33,7 @@ class Router
if (!$layout) { if (!$layout) {
$layout = $this->default_layout; $layout = $this->default_layout;
} }
$this->routes[$name] = new Route($route, $action, $params, $layout);
$this->routes[$name] = new \Majestic\Route($route, $action, $params, $layout);
} }
/** /**

8
composer.json

@ -0,0 +1,8 @@
{
"name": "majestic/core",
"version": "0.1.0",
"dist": {
"type": "git",
"url": "git@dimti.ru:majestic.git"
}
}

12
form/Form.php

@ -7,6 +7,8 @@
* @since 2010-04-24 * @since 2010-04-24
*/ */
namespace Majestic;
abstract class Form abstract class Form
{ {
@ -15,7 +17,7 @@ abstract class Form
const ERROR = 'error'; const ERROR = 'error';
/** /**
* @var FormField[]
* @var \FormField[]
*/ */
protected $fields = array(); protected $fields = array();
@ -36,18 +38,18 @@ abstract class Form
/** /**
* @param string $name * @param string $name
* @param bool|string $message * @param bool|string $message
* @return FormField
* @return \FormField
*/ */
protected function addField($name, $message = false) protected function addField($name, $message = false)
{ {
$this->fields[$name] = new FormField($message);
$this->fields[$name] = new \FormField($message);
return $this->fields[$name]; return $this->fields[$name];
} }
public function isValid($data) public function isValid($data)
{ {
if (!is_array($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) { foreach ($this->fields as $field_name => $field) {
@ -148,7 +150,7 @@ abstract class Form
{ {
$data['messages'] = $this->getMessages(); $data['messages'] = $this->getMessages();
$data['values'] = $this->getSourceValues(); $data['values'] = $this->getSourceValues();
Session::set(get_class($this), $data);
\Majestic\Session::set(get_class($this), $data);
} }
abstract protected function init(); abstract protected function init();

14
model/Db.php

@ -7,6 +7,8 @@
* @since 2010-02-16 * @since 2010-02-16
*/ */
namespace Majestic;
class Db class Db
{ {
@ -35,14 +37,14 @@ class Db
{ {
if (!isset(self::$connections[$name])) { if (!isset(self::$connections[$name])) {
if (!$config) { 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)) { if (!is_array($config)) {
throw new InitializationException('Connection parameters must be an array');
throw new \InitializationException('Connection parameters must be an array');
} }
$driver = 'MySQLiDriver'; $driver = 'MySQLiDriver';
@ -53,8 +55,8 @@ class Db
$connection = new $driver($config); $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; self::$connections[$name] = $connection;
} }

8
model/DbStatement.php

@ -53,7 +53,7 @@ abstract class DbStatement
* @param mixed $style * @param mixed $style
* @return array * @return array
*/ */
public function fetchAll($style = Db::FETCH_OBJ)
public function fetchAll($style = \Majestic\Db::FETCH_OBJ)
{ {
$data = array(); $data = array();
while ($row = $this->fetch($style)) { while ($row = $this->fetch($style)) {
@ -69,7 +69,7 @@ abstract class DbStatement
public function fetchColumn($field) public function fetchColumn($field)
{ {
$data = array(); $data = array();
while ($row = $this->fetch(Db::FETCH_ASSOC)) {
while ($row = $this->fetch(\Majestic\Db::FETCH_ASSOC)) {
$data[] = $row[$field]; $data[] = $row[$field];
} }
return $data; return $data;
@ -81,7 +81,7 @@ abstract class DbStatement
*/ */
public function fetchField($field) public function fetchField($field)
{ {
$row = $this->fetch(Db::FETCH_ASSOC);
$row = $this->fetch(\Majestic\Db::FETCH_ASSOC);
if (isset($row[$field])) { if (isset($row[$field])) {
return $row[$field]; return $row[$field];
} }
@ -94,7 +94,7 @@ abstract class DbStatement
abstract protected function assemble(); 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'); abstract public function fetchObject($class = 'stdClass');

24
model/Model.php

@ -10,20 +10,22 @@
* @since 2010-02-16 * @since 2010-02-16
*/ */
namespace Majestic;
abstract class Model abstract class Model
{ {
/** /**
* DbDriver instance * DbDriver instance
* *
* @var DbDriver
* @var \DbDriver
*/ */
protected $db; protected $db;
/** /**
* Cache instance * Cache instance
* *
* @var Cache
* @var \Cache
*/ */
protected $cache; protected $cache;
@ -48,7 +50,7 @@ abstract class Model
public function __construct($connection = 'default') 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 */ /* Cache workaround */
/** /**
* @return Cache
* @return \Cache
*/ */
public function getCache() public function getCache()
{ {
if (!$this->cache) { if (!$this->cache) {
$this->cache = Cacher::get(Config::get(__CLASS__, 'MemcacheCache'));
$this->cache = \Cacher::get(Config::get(__CLASS__, 'MemcacheCache'));
} }
return $this->cache; return $this->cache;
} }
@ -107,16 +109,16 @@ abstract class Model
/** /**
* @param string $name * @param string $name
* @param array $params * @param array $params
* @return CacheKey
* @return \CacheKey
*/ */
protected function cacheKey($name, $params = array()) protected function cacheKey($name, $params = array())
{ {
$expire = (isset($this->cache_keys[$name])) ? ($this->cache_keys[$name] * 60) : 0; $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) protected function addCleanCache($cache)
{ {
@ -152,21 +154,21 @@ abstract class Model
* @param string $data Request * @param string $data Request
* @param array $params Request parameters * @param array $params Request parameters
* @param string $field Requested field name * @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); abstract protected function fetchField($data, $params = array(), $field, $cache_key = null);
/** /**
* @param string $data Request * @param string $data Request
* @param array $params Request parameters * @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); abstract protected function fetch($data, $params = array(), $cache_key = null);
/** /**
* @param string $data * @param string $data
* @param array $params * @param array $params
* @param CacheKey $cache_key
* @param \CacheKey $cache_key
*/ */
abstract protected function fetchAll($data, $params = array(), $cache_key = null); abstract protected function fetchAll($data, $params = array(), $cache_key = null);
} }

12
model/MySQLiStatement.php

@ -83,23 +83,23 @@ class MySQLiStatement extends DbStatement
* @return mixed * @return mixed
* @throws GeneralException * @throws GeneralException
*/ */
public function fetch($style = Db::FETCH_OBJ)
public function fetch($style = \Majestic\Db::FETCH_OBJ)
{ {
if (!$this->result) { if (!$this->result) {
return false; return false;
} }
switch ($style) { switch ($style) {
case Db::FETCH_OBJ:
case \Majestic\Db::FETCH_OBJ:
$row = $this->result->fetch_object(); $row = $this->result->fetch_object();
break; break;
case Db::FETCH_NUM:
case \Majestic\Db::FETCH_NUM:
$row = $this->result->fetch_array(MYSQLI_NUM); $row = $this->result->fetch_array(MYSQLI_NUM);
break; break;
case Db::FETCH_ASSOC:
case \Majestic\Db::FETCH_ASSOC:
$row = $this->result->fetch_assoc(); $row = $this->result->fetch_assoc();
break; break;
case Db::FETCH_BOTH:
case \Majestic\Db::FETCH_BOTH:
$row = $this->result->fetch_array(MYSQLI_BOTH); $row = $this->result->fetch_array(MYSQLI_BOTH);
break; break;
default: default:
@ -123,7 +123,7 @@ class MySQLiStatement extends DbStatement
public function fetchPairs() public function fetchPairs()
{ {
$data = array(); $data = array();
while ($row = $this->fetch(Db::FETCH_NUM)) {
while ($row = $this->fetch(\Majestic\Db::FETCH_NUM)) {
$data[$row[0]] = $row[1]; $data[$row[0]] = $row[1];
} }
return $data; return $data;

2
model/SqlModel.php

@ -13,7 +13,7 @@
/** /**
* @property SqlDbDriver $db * @property SqlDbDriver $db
*/ */
abstract class SqlModel extends Model
abstract class SqlModel extends \Majestic\Model
{ {
/** /**
* @param string $ident * @param string $ident

4
redis/RedisManager.php

@ -30,10 +30,10 @@ class RedisManager
{ {
if (!isset(self::$connections[$name])) { if (!isset(self::$connections[$name])) {
if (!$config) { if (!$config) {
if (!is_object(Config::get('Redis'))) {
if (!is_object(\Majestic\Config::get('Redis'))) {
throw new GeneralException('Redis config no existence'); throw new GeneralException('Redis config no existence');
} }
$config = Config::get('Redis')->$name;
$config = \Majestic\Config::get('Redis')->$name;
} }
if (!is_array($config)) { if (!is_array($config)) {

2
session/Session.php

@ -7,6 +7,8 @@
* @since 2010-03-14 * @since 2010-03-14
*/ */
namespace Majestic;
class Session class Session
{ {
/** /**

2
validator/EqualValidator.php

@ -7,7 +7,7 @@
* @since 2010-04-26 * @since 2010-04-26
*/ */
class EqualValidator extends Validator
class EqualValidator extends \Majestic\Validator
{ {
const NOT_EQUAL = 'not_match'; const NOT_EQUAL = 'not_match';

2
validator/MbStrlenValidator.php

@ -9,7 +9,7 @@
* *
*/ */
class MbStrlenValidator extends Validator
class MbStrlenValidator extends \Majestic\Validator
{ {
const GREATHER_THAN = 'not_match'; const GREATHER_THAN = 'not_match';

2
validator/NotEmptyValidator.php

@ -7,7 +7,7 @@
* @since 2010-04-26 * @since 2010-04-26
*/ */
class NotEmptyValidator extends Validator
class NotEmptyValidator extends \Majestic\Validator
{ {
const IS_EMPTY = 'is_empty'; const IS_EMPTY = 'is_empty';

2
validator/RegexValidator.php

@ -7,7 +7,7 @@
* @since 2010-04-26 * @since 2010-04-26
*/ */
class RegexValidator extends Validator
class RegexValidator extends \Majestic\Validator
{ {
const NOT_MATCH = 'regex_not_match'; const NOT_MATCH = 'regex_not_match';

2
validator/StrlenValidator.php

@ -9,7 +9,7 @@
* *
*/ */
class StrlenValidator extends Validator
class StrlenValidator extends \Majestic\Validator
{ {
const GREATHER_THAN = 'not_match'; const GREATHER_THAN = 'not_match';

2
validator/Validator.php

@ -7,6 +7,8 @@
* @since 2010-04-24 * @since 2010-04-24
*/ */
namespace Majestic;
abstract class Validator implements iValidator abstract class Validator implements iValidator
{ {

2
validator/iValidator.php

@ -7,6 +7,8 @@
* @since 2010-04-25 * @since 2010-04-25
*/ */
namespace Majestic;
interface iValidator interface iValidator
{ {
public function isValid($value, $context = null); public function isValid($value, $context = null);

Loading…
Cancel
Save