summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDracony <draconyster@gmail.com>2013-01-10 16:25:50 +0200
committerDracony <draconyster@gmail.com>2013-01-10 16:25:50 +0200
commit4161d1d639dee2df73a30f4872e5280205e5da2d (patch)
tree0e791ba6b4a7853fb66bbf947ab49880e47c07cf
parenta5d20f2082ac7de829996d8df23af6bbc27a91d5 (diff)
downloadPHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.zip
PHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.tar.gz
PHPixie-4161d1d639dee2df73a30f4872e5280205e5da2d.tar.bz2
New format for config files.
Writing of config files now supported
-rw-r--r--application/config.php25
-rw-r--r--application/config/core.php12
-rw-r--r--application/config/database.php16
-rw-r--r--modules/.gitignore1
-rw-r--r--modules/database/classes/database/expression.php61
-rw-r--r--modules/database/classes/database/query.php1
-rw-r--r--modules/database/classes/database/result.php147
-rw-r--r--modules/database/classes/db.php255
-rw-r--r--modules/database/classes/driver/mysql/db.php175
-rw-r--r--modules/database/classes/driver/mysql/query.php1
-rw-r--r--modules/database/classes/driver/mysql/result.php93
-rw-r--r--modules/database/classes/driver/pdo/db.php1
-rw-r--r--modules/database/classes/driver/pdo/query.php5
-rw-r--r--modules/database/classes/driver/pdo/result.php93
-rw-r--r--modules/orm/classes/orm.php1
-rw-r--r--modules/orm/classes/ormresult.php225
-rw-r--r--system/bootstrap.php20
-rw-r--r--system/classes/config.php195
-rw-r--r--system/classes/misc.php46
-rw-r--r--system/classes/view.php191
20 files changed, 840 insertions, 724 deletions
diff --git a/application/config.php b/application/config.php
deleted file mode 100644
index e0c1463..0000000
--- a/application/config.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-Config::$data = array(
- 'routes' => array(
- array('default', '(/<controller>(/<action>(/<id>)))', array(
- 'controller' => 'home',
- 'action' => 'index'
- )
- )
- ),
- 'modules'=>array('database','orm'),
- 'database' => array(
- 'default' => array(
- 'user'=>'root',
- 'password' => '',
- 'driver' => 'mysql',
-
- //'Connection' is required if you use the PDO driver
- 'connection'=>'mysql:host=localhost;dbname=phpixie',
-
- // 'db' and 'host' are required if you use Mysql driver
- 'db' => 'phpixie',
- 'host'=>'localhost'
- )
- )
-); \ No newline at end of file
diff --git a/application/config/core.php b/application/config/core.php
new file mode 100644
index 0000000..a0393be
--- /dev/null
+++ b/application/config/core.php
@@ -0,0 +1,12 @@
+<?php
+
+return array(
+ 'routes' => array(
+ array('default', '(/<controller>(/<action>(/<id>)))', array(
+ 'controller' => 'home',
+ 'action' => 'index'
+ )
+ )
+ ),
+ 'modules' => array('database', 'orm','email')
+);
diff --git a/application/config/database.php b/application/config/database.php
new file mode 100644
index 0000000..3a04f14
--- /dev/null
+++ b/application/config/database.php
@@ -0,0 +1,16 @@
+<?php
+
+return array(
+ 'default' => array(
+ 'user'=>'root',
+ 'password' => '',
+ 'driver' => 'mysql',
+
+ //'Connection' is required if you use the PDO driver
+ 'connection'=>'mysql:host=localhost;dbname=phpixie',
+
+ // 'db' and 'host' are required if you use Mysql driver
+ 'db' => 'phpixie',
+ 'host'=>'localhost'
+ )
+);
diff --git a/modules/.gitignore b/modules/.gitignore
new file mode 100644
index 0000000..ff73f0a
--- /dev/null
+++ b/modules/.gitignore
@@ -0,0 +1 @@
+email/* \ No newline at end of file
diff --git a/modules/database/classes/database/expression.php b/modules/database/classes/database/expression.php
index bc8cea5..e987d52 100644
--- a/modules/database/classes/database/expression.php
+++ b/modules/database/classes/database/expression.php
@@ -1,31 +1,32 @@
-<?php
-
-/**
- * This class allows you to wrap fields or values that you don't want to be escaped
- * inside the query
- */
-class Expression_Database{
-
- /**
- * Part of query that should not be escaped
- * @var mixed
- * @access public
- */
- public $value;
-
- /**
- * Marks a part of query as a database specific expression,
- * e.g. calls to SQL functions like MAX(), SUBSTR() etc.
- * Example
- * <code>
- * $q->fields(DB::expr('COUNT(*)'));
- * </code>
- *
- * @param mixed $value Part of query that should not be escaped
- * @return Expression_Database
- * @access public
- */
- public function __construct($value){
- $this->value=$value;
- }
+<?php
+
+/**
+ * This class allows you to wrap fields or values that you don't want to be escaped
+ * inside the query
+ * @package Database
+ */
+class Expression_Database{
+
+ /**
+ * Part of query that should not be escaped
+ * @var mixed
+ * @access public
+ */
+ public $value;
+
+ /**
+ * Marks a part of query as a database specific expression,
+ * e.g. calls to SQL functions like MAX(), SUBSTR() etc.
+ * Example
+ * <code>
+ * $q->fields(DB::expr('COUNT(*)'));
+ * </code>
+ *
+ * @param mixed $value Part of query that should not be escaped
+ * @return Expression_Database
+ * @access public
+ */
+ public function __construct($value){
+ $this->value=$value;
+ }
} \ No newline at end of file
diff --git a/modules/database/classes/database/query.php b/modules/database/classes/database/query.php
index 5728514..8558499 100644
--- a/modules/database/classes/database/query.php
+++ b/modules/database/classes/database/query.php
@@ -25,6 +25,7 @@
*
* @method mixed type(string $type = null) Set query type. Available types: select, update, insert, delete, count.
* Without arguments returns current type argument, returns self otherwise.
+ * @package Database
*/
abstract class Query_Database {
diff --git a/modules/database/classes/database/result.php b/modules/database/classes/database/result.php
index ba83f25..8b80ac2 100644
--- a/modules/database/classes/database/result.php
+++ b/modules/database/classes/database/result.php
@@ -1,74 +1,75 @@
-<?php
-
-/**
- * Allows to access database results in a unified way and
- * provides iterator support, so it can be used inside loops like 'foreach'
- */
-abstract class Result_Database implements Iterator {
-
- /**
- * Current row number
- * @var integer
- * @access protected
- */
- protected $_position = 0;
-
- /**
- * Database result object
- * @var mixed
- * @access protected
- */
- protected $_result;
-
- /**
- * Current row
- * @var object
- * @access protected
- */
- protected $_row;
-
-
- /**
- * Returns current row
- *
- * @return object Current row in result set
- * @access public
- */
- public function current() {
- return $this->_row;
- }
-
- /**
- * Gets the number of the current row
- *
- * @return integer Row number
- * @access public
- */
- public function key() {
- return $this->_position;
- }
-
- /**
- * Check if current row exists.
- *
- * @return bool True if row exists
- * @access public
- */
- public function valid() {
- return $this->_row!=null;
- }
-
- /**
- * Returns all rows as array
- *
- * @return array Array of rows
- * @access public
- */
- public function as_array() {
- $arr = array();
- foreach($this as $row)
- $arr[] = $row;
- return $arr;
- }
-
+<?php
+
+/**
+ * Allows to access database results in a unified way and
+ * provides iterator support, so it can be used inside loops like 'foreach'
+ * @package Database
+ */
+abstract class Result_Database implements Iterator {
+
+ /**
+ * Current row number
+ * @var integer
+ * @access protected
+ */
+ protected $_position = 0;
+
+ /**
+ * Database result object
+ * @var mixed
+ * @access protected
+ */
+ protected $_result;
+
+ /**
+ * Current row
+ * @var object
+ * @access protected
+ */
+ protected $_row;
+
+
+ /**
+ * Returns current row
+ *
+ * @return object Current row in result set
+ * @access public
+ */
+ public function current() {
+ return $this->_row;
+ }
+
+ /**
+ * Gets the number of the current row
+ *
+ * @return integer Row number
+ * @access public
+ */
+ public function key() {
+ return $this->_position;
+ }
+
+ /**
+ * Check if current row exists.
+ *
+ * @return bool True if row exists
+ * @access public
+ */
+ public function valid() {
+ return $this->_row!=null;
+ }
+
+ /**
+ * Returns all rows as array
+ *
+ * @return array Array of rows
+ * @access public
+ */
+ public function as_array() {
+ $arr = array();
+ foreach($this as $row)
+ $arr[] = $row;
+ return $arr;
+ }
+
} \ No newline at end of file
diff --git a/modules/database/classes/db.php b/modules/database/classes/db.php
index 6e8c145..854b06f 100644
--- a/modules/database/classes/db.php
+++ b/modules/database/classes/db.php
@@ -1,128 +1,129 @@
-<?php
-
-/**
- * Database related functions. Creates connections,
- * executes queries and returns results. It is also the
- * generic connection class used by drivers.
- */
-abstract class DB {
-
- /**
- * An associative array of connections to databases
- * @var array
- * @access private
- * @static
- */
- private static $_instances=array();
-
- /**
- * Executes a prepared statement query
- *
- * @param string $query A prepared statement query
- * @param array $params Parameters for the query
- * @return Result_Database
- * @access public
- * @see Result_Database
- */
- public abstract function execute($query, $params = array());
-
- /**
- * Builds a new Query to the database
- *
- * @param string $type Query type. Available types: select, update, insert, delete, count
- * @return Result_Database
- * @access public
- * @see Query_Database
- */
- public abstract function build_query($type);
-
- /**
- * Gets the id of the last inserted row.
- *
- * @return mixed The id of the last inserted row
- * @access public
- */
- public abstract function get_insert_id();
-
- /**
- * Executes a named query where parameters are passed as an associative array
- * Example:
- * <code>
- * $result=$db->namedQuery("SELECT * FROM fairies where name = :name",array('name'=>'Tinkerbell'));
- * </code>
- *
- * @param string $query A named query
- * @param array $params Associative array of parameters
- * @return Result_Database Current drivers implementation of Result_Database
- * @access public
- */
- public function namedQuery($query, $params=array()) {
- $bind = array();
- preg_match_all('#:(\w+)#is', $query, $matches,PREG_SET_ORDER);
- foreach($matches as $match)
- if(isset($params[$match[1]])){
- $query = preg_replace("#{$match[0]}#", '?', $query, 1);
- $bind[] = $params[$match[1]];
- }
- return $this->execute($query,$bind);
- }
-
- /**
- * Returns an Expression_Database representation of the value.
- * Values wrapped inside Expression_Database are not escaped in queries
- *
- * @param mixed $value Value to be wrapped
- * @return Expression_Database Raw value that will not be escaped during query building
- * @access public
- * @static
- */
- public static function expr($value){
- return new Expression_Database($value);
- }
-
- /**
- * Builds a query for specified connection.
- *
- * @param string $type Query type. Available types: select,update,insert,delete,count
- * @param string $config Configuration name of the connection.
- * Defaults to 'default'.
- * @return Query_Database Driver implementation of the Query_Database class.
- * @access public
- * @static
- */
- public static function query($type,$config = 'default') {
- return DB::instance($config)->build_query($type);
- }
-
- /**
- * Gets the id of the last inserted row
- *
- * @param string $config Configuration name of the connection.
- * Defaults to 'default'.
- * @return mixed Id of the last inserted row
- * @access public
- * @static
- */
- public static function insert_id($config = 'default') {
- return DB::instance($config)->get_insert_id();
- }
-
- /**
- * Gets an instance of a connection to the database
- *
- * @param string $config Configuration name of the connection.
- * Defaults to 'default'.
- * @return DB Driver implementation of the DB class.
- * @access public
- * @static
- */
- public static function instance($config='default'){
- if (!isset(DB::$_instances[$config])) {
- $driver = Config::get("database.{$config}.driver");
- $driver="DB_{$driver}_Driver";
- DB::$_instances[$config] = new $driver($config);
- }
- return DB::$_instances[$config];
- }
-
+<?php
+
+/**
+ * Database related functions. Creates connections,
+ * executes queries and returns results. It is also the
+ * generic connection class used by drivers.
+ * @package Database
+ */
+abstract class DB {
+
+ /**
+ * An associative array of connections to databases
+ * @var array
+ * @access private
+ * @static
+ */
+ private static $_instances=array();
+
+ /**
+ * Executes a prepared statement query
+ *
+ * @param string $query A prepared statement query
+ * @param array $params Parameters for the query
+ * @return Result_Database
+ * @access public
+ * @see Result_Database
+ */
+ public abstract function execute($query, $params = array());
+
+ /**
+ * Builds a new Query to the database
+ *
+ * @param string $type Query type. Available types: select, update, insert, delete, count
+ * @return Result_Database
+ * @access public
+ * @see Query_Database
+ */
+ public abstract function build_query($type);
+
+ /**
+ * Gets the id of the last inserted row.
+ *
+ * @return mixed The id of the last inserted row
+ * @access public
+ */
+ public abstract function get_insert_id();
+
+ /**
+ * Executes a named query where parameters are passed as an associative array
+ * Example:
+ * <code>
+ * $result=$db->namedQuery("SELECT * FROM fairies where name = :name",array('name'=>'Tinkerbell'));
+ * </code>
+ *
+ * @param string $query A named query
+ * @param array $params Associative array of parameters
+ * @return Result_Database Current drivers implementation of Result_Database
+ * @access public
+ */
+ public function namedQuery($query, $params=array()) {
+ $bind = array();
+ preg_match_all('#:(\w+)#is', $query, $matches,PREG_SET_ORDER);
+ foreach($matches as $match)
+ if(isset($params[$match[1]])){
+ $query = preg_replace("#{$match[0]}#", '?', $query, 1);
+ $bind[] = $params[$match[1]];
+ }
+ return $this->execute($query,$bind);
+ }
+
+ /**
+ * Returns an Expression_Database representation of the value.
+ * Values wrapped inside Expression_Database are not escaped in queries
+ *
+ * @param mixed $value Value to be wrapped
+ * @return Expression_Database Raw value that will not be escaped during query building
+ * @access public
+ * @static
+ */
+ public static function expr($value){
+ return new Expression_Database($value);
+ }
+
+ /**
+ * Builds a query for specified connection.
+ *
+ * @param string $type Query type. Available types: select,update,insert,delete,count
+ * @param string $config Configuration name of the connection.
+ * Defaults to 'default'.
+ * @return Query_Database Driver implementation of the Query_Database class.
+ * @access public
+ * @static
+ */
+ public static function query($type,$config = 'default') {
+ return DB::instance($config)->build_query($type);
+ }
+
+ /**
+ * Gets the id of the last inserted row
+ *
+ * @param string $config Configuration name of the connection.
+ * Defaults to 'default'.
+ * @return mixed Id of the last inserted row
+ * @access public
+ * @static
+ */
+ public static function insert_id($config = 'default') {
+ return DB::instance($config)->get_insert_id();
+ }
+
+ /**
+ * Gets an instance of a connection to the database
+ *
+ * @param string $config Configuration name of the connection.
+ * Defaults to 'default'.
+ * @return DB Driver implementation of the DB class.
+ * @access public
+ * @static
+ */
+ public static function instance($config='default'){
+ if (!isset(DB::$_instances[$config])) {
+ $driver = Config::get("database.{$config}.driver");
+ $driver="DB_{$driver}_Driver";
+ DB::$_instances[$config] = new $driver($config);
+ }
+ return DB::$_instances[$config];
+ }
+
} \ No newline at end of file
diff --git a/modules/database/classes/driver/mysql/db.php b/modules/database/classes/driver/mysql/db.php
index 553cfb9..879d1b8 100644
--- a/modules/database/classes/driver/mysql/db.php
+++ b/modules/database/classes/driver/mysql/db.php
@@ -1,88 +1,89 @@
-<?php
-
-/**
- * Mysqli Database Implementation
- */
-class DB_Mysql_Driver extends DB{
-
- /**
- * Mysqli database connection object
- * @var mysqli
- * @access public
- * @link http://php.net/manual/en/class.mysqli.php
- */
- public $conn;
-
- /**
- * Initializes database connection
- *
- * @param string $config Name of the connection to initialize
- * @return void
- * @access public
- */
- public function __construct($config) {
- $this->conn = mysqli_connect(
- Config::get("database.{$config}.host",'localhost'),
- Config::get("database.{$config}.user",''),
- Config::get("database.{$config}.password",''),
- Config::get("database.{$config}.db")
- );
- }
-
- /**
- * Builds a new Query implementation
- *
- * @param string $type Query type. Available types: select,update,insert,delete,count
- * @return Query_Mysql_Driver Returns a Mysqli implementation of a Query.
- * @access public
- * @see Query_Database
- */
- public function build_query($type) {
- return new Query_Mysql_Driver($this,$type);
- }
-
- /**
- * Gets the id of the last inserted row.
- *
- * @return mixed Row id
- * @access public
- */
- public function get_insert_id() {
- return $this->conn->insert_id;
- }
-
- /**
- * Executes a prepared statement query
- *
- * @param string $query A prepared statement query
- * @param array $params Parameters for the query
- * @return Result_Mysql_Driver Mysqli implementation of a database result
- * @access public
- * @throws Exception If the query resulted in an error
- * @see Database_Result
- */
- public function execute($query, $params = array()) {
- $cursor = $this->conn->prepare($query);
- if (!$cursor)
- throw new Exception("Database error: {$this->conn->error} \n in query:\n{$query}");
- $types = '';
- $bind = array();
- $refs = array();
- if(!empty($params)){
- foreach($params as $key=>$param) {
- $refs[$key]=is_array($param)?$param[0]:$param;
- $bind[]=&$refs[$key];
- $types.=is_array($param)?$param[1]:'s';
- }
- array_unshift($bind, $types);
-
- call_user_func_array(array($cursor, 'bind_param'), $bind);
- }
- $cursor->execute();
- $res = $cursor->get_result();
- if (is_object($res)){
- $res=new Result_Mysql_Driver($res);
- }
- return $res;
- }
+<?php
+
+/**
+ * Mysqli Database Implementation
+ * @package Database
+ */
+class DB_Mysql_Driver extends DB{
+
+ /**
+ * Mysqli database connection object
+ * @var mysqli
+ * @access public
+ * @link http://php.net/manual/en/class.mysqli.php
+ */
+ public $conn;
+
+ /**
+ * Initializes database connection
+ *
+ * @param string $config Name of the connection to initialize
+ * @return void
+ * @access public
+ */
+ public function __construct($config) {
+ $this->conn = mysqli_connect(
+ Config::get("database.{$config}.host",'localhost'),
+ Config::get("database.{$config}.user",''),
+ Config::get("database.{$config}.password",''),
+ Config::get("database.{$config}.db")
+ );
+ }
+
+ /**
+ * Builds a new Query implementation
+ *
+ * @param string $type Query type. Available types: select,update,insert,delete,count
+ * @return Query_Mysql_Driver Returns a Mysqli implementation of a Query.
+ * @access public
+ * @see Query_Database
+ */
+ public function build_query($type) {
+ return new Query_Mysql_Driver($this,$type);
+ }
+
+ /**
+ * Gets the id of the last inserted row.
+ *
+ * @return mixed Row id
+ * @access public
+ */
+ public function get_insert_id() {
+ return $this->conn->insert_id;
+ }
+
+ /**
+ * Executes a prepared statement query
+ *
+ * @param string $query A prepared statement query
+ * @param array $params Parameters for the query
+ * @return Result_Mysql_Driver Mysqli implementation of a database result
+ * @access public
+ * @throws Exception If the query resulted in an error
+ * @see Database_Result
+ */
+ public function execute($query, $params = array()) {
+ $cursor = $this->conn->prepare($query);
+ if (!$cursor)
+ throw new Exception("Database error: {$this->conn->error} \n in query:\n{$query}");
+ $types = '';
+ $bind = array();
+ $refs = array();
+ if(!empty($params)){
+ foreach($params as $key=>$param) {
+ $refs[$key]=is_array($param)?$param[0]:$param;
+ $bind[]=&$refs[$key];
+ $types.=is_array($param)?$param[1]:'s';
+ }
+ array_unshift($bind, $types);
+
+ call_user_func_array(array($cursor, 'bind_param'), $bind);
+ }
+ $cursor->execute();
+ $res = $cursor->get_result();
+ if (is_object($res)){
+ $res=new Result_Mysql_Driver($res);
+ }
+ return $res;
+ }
} \ No newline at end of file
diff --git a/modules/database/classes/driver/mysql/query.php b/modules/database/classes/driver/mysql/query.php
index e0ceacd..48b140e 100644
--- a/modules/database/classes/driver/mysql/query.php
+++ b/modules/database/classes/driver/mysql/query.php
@@ -2,6 +2,7 @@
/**
* Mysqli implementation of the database Query
+ * @package Database
*/
class Query_Mysql_Driver extends Query_PDO_Driver {
diff --git a/modules/database/classes/driver/mysql/result.php b/modules/database/classes/driver/mysql/result.php
index 0fbb645..a461c81 100644
--- a/modules/database/classes/driver/mysql/result.php
+++ b/modules/database/classes/driver/mysql/result.php
@@ -1,47 +1,48 @@
-<?php
-
-/**
- * Database result implementation for Mysqli
- */
-class Result_Mysql_Driver extends Result_Database {
-
- /**
- * Initializes new result object
- *
- * @param mysqli_result $result Mysqli Result
- * @return void
- * @access public
- * @link http://php.net/manual/en/class.mysqli-result.php
- */
- public function __construct($result) {
- $this->_result = $result;
- $this->_row=$this->_result->fetch_object();
- }
-
- /**
- * Throws exception if rewind is attempted.
- *
- * @return void
- * @access public
- * @throws Exception If rewind is attempted
- */
- public function rewind() {
- if($this->_position!=0)
- throw new Exception('Mysqli result cannot be rewound for unbuffered queries.');
- }
-
- /**
- * Iterates to the next row in the result set
- *
- * @return void
- * @access public
- */
- public function next() {
-
- $this->_position++;
- $this->_row=$this->_result->fetch_object();
- if ($this->_row == null)
- $this->_result->free();
- }
-
+<?php
+
+/**
+ * Database result implementation for Mysqli
+ * @package Database
+ */
+class Result_Mysql_Driver extends Result_Database {
+
+ /**
+ * Initializes new result object
+ *
+ * @param mysqli_result $result Mysqli Result
+ * @return void
+ * @access public
+ * @link http://php.net/manual/en/class.mysqli-result.php
+ */
+ public function __construct($result) {
+ $this->_result = $result;
+ $this->_row=$this->_result->fetch_object();
+ }
+
+ /**
+ * Throws exception if rewind is attempted.
+ *
+ * @return void
+ * @access public
+ * @throws Exception If rewind is attempted
+ */
+ public function rewind() {
+ if($this->_position!=0)
+ throw new Exception('Mysqli result cannot be rewound for unbuffered queries.');
+ }
+
+ /**
+ * Iterates to the next row in the result set
+ *
+ * @return void
+ * @access public
+ */
+ public function next() {
+
+ $this->_position++;
+ $this->_row=$this->_result->fetch_object();
+ if ($this->_row == null)
+ $this->_result->free();
+ }
+
} \ No newline at end of file
diff --git a/modules/database/classes/driver/pdo/db.php b/modules/database/classes/driver/pdo/db.php
index 18f278d..59705f7 100644
--- a/modules/database/classes/driver/pdo/db.php
+++ b/modules/database/classes/driver/pdo/db.php
@@ -2,6 +2,7 @@
/**
* PDO Database implementation.
+ * @package Database
*/
class DB_PDO_Driver extends DB{
diff --git a/modules/database/classes/driver/pdo/query.php b/modules/database/classes/driver/pdo/query.php
index 1102b44..662ce71 100644
--- a/modules/database/classes/driver/pdo/query.php
+++ b/modules/database/classes/driver/pdo/query.php
@@ -2,6 +2,7 @@
/**
* PDO implementation of the database Query
+ * @package Database
*/
class Query_PDO_Driver extends Query_Database {
@@ -218,11 +219,11 @@ class Query_PDO_Driver extends Query_Database {
}else {
$param = $this->escape_value($p['value'],$params);
}
- return $this->escape_field($p['field']).' '.$p['operator'].' '.$param;
+ return $this->escape_field($p['field']).' '.$p['operator'].' '.$param.' ';
}
if (isset($p['logic'])) {
return ($skip_first_operator?'':strtoupper($p['logic'])).' '
- .$this->get_condition_query($p['conditions'],$params,false,$value_is_field);
+ .$this->get_condition_query($p['conditions'],$params,false,$value_is_field).' ';
}
$conds = '';
diff --git a/modules/database/classes/driver/pdo/result.php b/modules/database/classes/driver/pdo/result.php
index 3270231..fec0652 100644
--- a/modules/database/classes/driver/pdo/result.php
+++ b/modules/database/classes/driver/pdo/result.php
@@ -1,47 +1,48 @@
-<?php
-
-/**
- * Database result implementation for PDO
- */
-class Result_PDO_Driver extends Result_Database {
-
- /**
- * Initializes new result object
- *
- * @param PDOStatement $stmt PDO Statement
- * @return void
- * @access public
- * @link http://php.net/manual/en/class.pdostatement.php
- */
- public function __construct($stmt) {
- $this->_result = $stmt;
- $this->_row=$this->_result->fetchObject();
- }
-
- /**
- * Throws exception if rewind is attempted.
- *
- * @return void
- * @access public
- * @throws Exception If rewind is attempted
- */
- public function rewind() {
- if($this->_position!=0)
- throw new Exception('PDO statement cannot be rewound for unbuffered queries');
- }
-
- /**
- * Iterates to the next row in the result set
- *
- * @return void
- * @access public
- */
- public function next() {
-
- $this->_position++;
- $this->_row=$this->_result->fetchObject();
- if ($this->_row == false)
- $this->_result->closeCursor();
- }
-
+<?php
+
+/**
+ * Database result implementation for PDO
+ * @package Database
+ */
+class Result_PDO_Driver extends Result_Database {
+
+ /**
+ * Initializes new result object
+ *
+ * @param PDOStatement $stmt PDO Statement
+ * @return void
+ * @access public
+ * @link http://php.net/manual/en/class.pdostatement.php
+ */
+ public function __construct($stmt) {
+ $this->_result = $stmt;
+ $this->_row=$this->_result->fetchObject();
+ }
+
+ /**
+ * Throws exception if rewind is attempted.
+ *
+ * @return void
+ * @access public
+ * @throws Exception If rewind is attempted
+ */
+ public function rewind() {
+ if($this->_position!=0)
+ throw new Exception('PDO statement cannot be rewound for unbuffered queries');
+ }
+
+ /**
+ * Iterates to the next row in the result set
+ *
+ * @return void
+ * @access public
+ */
+ public function next() {
+
+ $this->_position++;
+ $this->_row=$this->_result->fetchObject();
+ if ($this->_row == false)
+ $this->_result->closeCursor();
+ }
+
} \ No newline at end of file
diff --git a/modules/orm/classes/orm.php b/modules/orm/classes/orm.php
index 4165df6..569ddec 100644
--- a/modules/orm/classes/orm.php
+++ b/modules/orm/classes/orm.php
@@ -17,6 +17,7 @@
* @method mixed where(mixed $key, mixed $operator = null, mixed $val = null) behaves just like Query_Database::where()
*
* @see Query_Database::where()
+ * @package ORM
*/
class ORM {
diff --git a/modules/orm/classes/ormresult.php b/modules/orm/classes/ormresult.php
index 4297550..39553ef 100644
--- a/modules/orm/classes/ormresult.php
+++ b/modules/orm/classes/ormresult.php
@@ -1,113 +1,114 @@
-<?php
-
-/**
- * Allows iterating over ORM objects inside loops lie 'foreach',
- * while preserving performance by working with only a single row
- * at a time. It wraps conveniently wraps around Database_Result class
- * returning ORM object instead of just data object.
- *
- * @see Database_Result
- */
-class ORMResult implements Iterator {
-
- /**
- * Name of the model that the rows belong to
- * @var string
- * @access private
- */
- private $_model;
-
- /**
- * Database result
- * @var Result_Database
- * @access private
- */
- private $_dbresult;
-
- /**
- * Initialized an ORMResult with which model to use and which result to
- * iterate over
- *
- * @param string $model Model name
- * @param Result_Database $dbresult Database result
- * @return void
- * @access public
- */
- public function __construct($model,$dbresult){
- $this->_model=$model;
- $this->_dbresult = $dbresult;
- }
-
- /**
- * Rewinds database cursor to the first row
- *
- * @return void
- * @access public
- */
- function rewind() {
- $this->_dbresult->rewind();
- }
-
- /**
- * Gets an ORM Model of the current row
- *
- * @return ORM Model of the current row of the result set
- * @access public
- */
- function current() {
- $model = new $this->_model;
- if (!$this->_dbresult->valid())
- return $model;
- $model->values((array)$this->_dbresult->current(),true);
- return $model;
- }
-
- /**
- * Gets current rows' index number
- *
- * @return int Row number
- * @access public
- */
- function key() {
- return $this->_dbresult->key();
- }
-
- /**
- * Iterates to the next row in the result
- *
- * @return void
- * @access public
- */
- function next() {
- $this->_dbresult->next();
- }
-
- /**
- * Checks if current row is valid.
- *
- * @return bool returns false if we reach the end of the result set.
- * @access public
- */
- function valid() {
- return $this->_dbresult->valid();
- }
-
- /**
- * Returns an array of all rows as ORM objects if $rows is False,
- * or just an array of result rows with each row being a standard object,
- * this can be useful for functions like json_encode.
- *
- * @param boolean $rows Whether to return just rows and not ORM objects
- * @return array Array of ORM objects or standard objects representing rows
- * @access public
- */
- public function as_array($rows = false) {
- if ($rows)
- return $this->_dbresult->as_array();
- $arr = array();
- foreach($this as $row)
- $arr[] = $row;
- return $arr;
- }
-
+<?php
+
+/**
+ * Allows iterating over ORM objects inside loops lie 'foreach',
+ * while preserving performance by working with only a single row
+ * at a time. It wraps conveniently wraps around Database_Result class
+ * returning ORM object instead of just data object.
+ *
+ * @see Database_Result
+ * @package ORM
+ */
+class ORMResult implements Iterator {
+
+ /**
+ * Name of the model that the rows belong to
+ * @var string
+ * @access private
+ */
+ private $_model;
+
+ /**
+ * Database result
+ * @var Result_Database
+ * @access private
+ */
+ private $_dbresult;
+
+ /**
+ * Initialized an ORMResult with which model to use and which result to
+ * iterate over
+ *
+ * @param string $model Model name
+ * @param Result_Database $dbresult Database result
+ * @return void
+ * @access public
+ */
+ public function __construct($model,$dbresult){
+ $this->_model=$model;
+ $this->_dbresult = $dbresult;
+ }
+
+ /**
+ * Rewinds database cursor to the first row
+ *
+ * @return void
+ * @access public
+ */
+ function rewind() {
+ $this->_dbresult->rewind();
+ }
+
+ /**
+ * Gets an ORM Model of the current row
+ *
+ * @return ORM Model of the current row of the result set
+ * @access public
+ */
+ function current() {
+ $model = new $this->_model;
+ if (!$this->_dbresult->valid())
+ return $model;
+ $model->values((array)$this->_dbresult->current(),true);
+ return $model;
+ }
+
+ /**
+ * Gets current rows' index number
+ *
+ * @return int Row number
+ * @access public
+ */
+ function key() {
+ return $this->_dbresult->key();
+ }
+
+ /**
+ * Iterates to the next row in the result
+ *
+ * @return void
+ * @access public
+ */
+ function next() {
+ $this->_dbresult->next();
+ }
+
+ /**
+ * Checks if current row is valid.
+ *
+ * @return bool returns false if we reach the end of the result set.
+ * @access public
+ */
+ function valid() {
+ return $this->_dbresult->valid();
+ }
+
+ /**
+ * Returns an array of all rows as ORM objects if $rows is False,
+ * or just an array of result rows with each row being a standard object,
+ * this can be useful for functions like json_encode.
+ *
+ * @param boolean $rows Whether to return just rows and not ORM objects
+ * @return array Array of ORM objects or standard objects representing rows
+ * @access public
+ */
+ public function as_array($rows = false) {
+ if ($rows)
+ return $this->_dbresult->as_array();
+ $arr = array();
+ foreach($this as $row)
+ $arr[] = $row;
+ return $arr;
+ }
+
} \ No newline at end of file
diff --git a/system/bootstrap.php b/system/bootstrap.php
index 73fb866..b7b52a8 100644
--- a/system/bootstrap.php
+++ b/system/bootstrap.php
@@ -15,10 +15,14 @@ class Bootstrap{
* @static
*/
public static function autoload($class) {
- $file = Misc::find_file('class', $class);
- if (!$file)
- throw new Exception("Class {$class} not found.");
- require_once($file);
+
+ $path = array_reverse(explode('_', strtolower($class)));
+ $file = array_pop($path);
+ $path = 'classes/'.implode('/',$path);
+ $file = Misc::find_file($path, $file);
+
+ if($file)
+ require_once($file);
}
/**
@@ -58,15 +62,11 @@ class Bootstrap{
* Configuration handler
*/
require_once('classes/config.php');
-
- /**
- * Applications configuration file
- */
- require_once('application/config.php');
+ Config::load_group('core', 'application/config/core.php');
spl_autoload_register('Bootstrap::autoload');
Debug::init();
- foreach(Config::get('routes') as $route)
+ foreach(Config::get('core.routes') as $route)
Route::add($route[0],$route[1],$route[2]);
}
} \ No newline at end of file
diff --git a/system/classes/config.php b/system/classes/config.php
index b0550b4..7d32f69 100644
--- a/system/classes/config.php
+++ b/system/classes/config.php
@@ -1,51 +1,146 @@
-<?php
-
-/**
- * Handles retrieving of the configuration options.
- * You can add any configuration values to your /application/config.php file
- * as associative array and get those values using the get() method.
- */
-class Config {
-
- /**
- * Array of configuration options
- * @var array
- * @access public
- * @static
- */
- public static $data=array();
-
- /**
- * Retrieves a configuration value. You can use a dot notation
- * to access properties in nested arrays like this:
- * <code>
- * Config::get('database.default.user');
- * </code>
- *
- * @param string $key Configuration key to retrieve.
- * @param string $default Default value to return if the key is not found.
- * @return mixed Configuration value
- * @access public
- * @throws Exception If default value is not specified and the key is not found
- * @static
- */
- public static function get() {
- $p = func_get_args();
- $keys = explode('.', $p[0]);
- $group=Config::$data;
- for ($i = 0; $i < count($keys); $i++) {
- if ($i == count($keys) - 1) {
- if (isset($group[$keys[$i]]))
- return $group[$keys[$i]];
- break;
- }
- $group = Misc::arr($group, $keys[$i], null);
- if (!is_array($group))
- break;
- }
- if (isset($p[1]))
- return $p[1];
- throw new Exception("Configuration not set for {$p[0]}.");
- }
-
+<?php
+
+/**
+ * Handles retrieving of the configuration options.
+ * You can add configuration files to /application/config folder
+ * and later access them via the get() method.
+ * @package Core
+ */
+class Config {
+
+ /**
+ * Array of configuration files and values loaded from them
+ * @var array
+ * @access protected
+ * @static
+ */
+ protected static $groups = array();
+
+ /**
+ * Loads a group configuration file it has not been loaded before
+ * and returns its options.
+ *
+ * @param string $name Name of the configuration group to load
+ * @return array Array of options for this group
+ * @access public
+ * @throws Exception If a configuration file for this group does not exist
+ * @static
+ */
+ public static function get_group($name) {
+
+ if (!isset(Config::$groups[$name])) {
+
+ $file = Misc::find_file('config', $name);
+
+ if (!$file)
+ throw new Exception("Configuration file {$name}.php was not found.");
+
+ Config::load_group($name,$file);
+ }
+
+ return Config::$groups[$name]['options'];
+ }
+
+ /**
+ * Loads group from file
+ *
+ * @param string $name Name to assign the loaded group
+ * @param string $file File to load
+ * @access public
+ * @static
+ */
+ public static function load_group($name, $file) {
+
+ Config::$groups[$name] = array(
+ 'file' => $file,
+ 'options' => include($file)
+ );
+ }
+
+ /**
+ * Retrieves a configuration value. You can use a dot notation
+ * to access properties in group arrays. The first part of the key
+ * specifies the configuration file from which options should be loaded from
+ * <code>
+ * //Loads ['default']['user'] option
+ * //from database.php configuration file
+ * Config::get('database.default.user');
+ * </code>
+ *
+ * @param string $key Configuration key to retrieve.
+ * @param string $default Default value to return if the key is not found.
+ * @return mixed Configuration value
+ * @access public
+ * @throws Exception If default value is not specified and the key is not found
+ * @static
+ */
+ public static function get() {
+ $p = func_get_args();
+
+ $keys = explode('.', $p[0]);
+ $group_name = array_shift($keys);
+ $group = Config::get_group($group_name);
+
+ for ($i = 0; $i < count($keys); $i++) {
+ if ($i == count($keys) - 1) {
+ if (isset($group[$keys[$i]]))
+ return $group[$keys[$i]];
+ break;
+ }
+ $group = Misc::arr($group, $keys[$i], null);
+ if (!is_array($group))
+ break;
+ }
+
+ if (isset($p[1]))
+ return $p[1];
+
+ throw new Exception("Configuration not set for {$p[0]}.");
+ }
+
+ /**
+ * Sets a configuration option.
+ *
+ * @param string $key Configuration key to set
+ * @param string $value Value to set for this option
+ * @access public
+ * @static
+ */
+ public static function set($key,$value){
+ $keys = explode('.', $key);
+ $group_name = array_shift($keys);
+ $group = Config::get_group($group_name);
+ $subgroup = & $group;
+
+ foreach($keys as $i => $key) {
+
+ if ($i == count($keys) - 1) {
+
+ $subgroup[$key] = $value;
+
+ } else {
+
+ if(!isset($subgroup[$key])||!is_array($subgroup[$key]))
+ $subgroup[$key]=array();
+ $subgroup = & $subgroup[$key];
+
+ }
+ }
+
+ Config::$groups[$group_name]['options'] = $group;
+ }
+
+ /**
+ * Writes a configuration group back to the file it was loaded from
+ *
+ * @param string $group Name of the group to write
+ * @access public
+ * @static
+ */
+ public static function write($group){
+ Config::get_group($group);
+ $group=Config::$groups[$group];
+ file_put_contents($group['file'],"<?php\r\nreturn ".var_export($group['options'],true).";");
+ }
+
} \ No newline at end of file
diff --git a/system/classes/misc.php b/system/classes/misc.php
index 8aad4ec..b4dba6d 100644
--- a/system/classes/misc.php
+++ b/system/classes/misc.php
@@ -22,40 +22,42 @@ class Misc{
}
/**
- * Find full path to either a class or view by name.
- * It will search in the /application folder first, then all enabled modules
+ * Finds full path to a specified file
+ * It will search in the /application folder first, then in all enabled modules
* and then the /system folder
*
- * @param string $type Type of the file to find. Either 'class' or 'view'
- * @param string $name Name of the file to find
- * @return boolean Return Full path to the file or False if it is not found
+ * @param string $subfolder Subfolder to search in e.g. 'classes' or 'views'
+ * @param string $name Name of the file without extension
+ * @param string $extension File extension
+ * @param boolean $return_all If 'true' returns all mathced files as array,
+ * otherwise returns the first file found
+ * @return mixed Full path to the file or False if it is not found
* @access public
* @static
*/
- public static function find_file($type, $name) {
+ public static function find_file($subfolder, $name, $extension = 'php', $return_all = false ) {
+
$folders = array(APPDIR);
- foreach(Config::get('modules') as $module)
- $folders[] = MODDIR.$module.'/';
- $folders[]=SYSDIR;
- if($type=='class'){
- $subfolder = 'classes/';
- $dirs = array_reverse(explode('_', strtolower($name)));
- $fname = array_pop($dirs);
- $subfolder.=implode('/',$dirs).'/';
- }
- if ($type == 'view') {
- $subfolder = 'views/';
- $fname=$name;
- }
+ foreach(Config::get('core.modules',array()) as $module)
+ $folders[] = MODDIR.$module.'/';
+ $folders[] = SYSDIR;
- foreach($folders as $folder) {
- $file = $folder.$subfolder.$fname.'.php';
+ $fname=$name.'.'.$extension;
+ $found_files = array();
+ foreach($folders as $folder) {
+ $file = $folder.$subfolder.'/'.$fname;
if (file_exists($file)) {
- return($file);
+ if(!$return_all)
+ return($file);
+ $found_files[]=$file;
}
}
+
+ if(!empty($found_files))
+ return $found_files;
+
return false;
}
} \ No newline at end of file
diff --git a/system/classes/view.php b/system/classes/view.php
index 5b7b6e7..8dbb85e 100644
--- a/system/classes/view.php
+++ b/system/classes/view.php
@@ -1,95 +1,98 @@
-<?php
-
-/**
- * Manages passing variables to templates and rendering them
- */
-class View{
-
- /**
- * Full path to template file
- * @var string
- * @access private
- */
- private $path;
-
- /**
- * The name of the view.
- * @var string
- * @access public
- */
- public $name;
-
- /**
- * Stores all the variables passed to the view
- * @var array
- * @access private
- */
- private $_data = array();
-
- /**
- * Manages storing the data passed to the view as properties
- *
- * @param string $key Property name
- * @param string $val Property value
- * @return void
- * @access public
- */
- public function __set($key, $val) {
- $this->_data[$key]=$val;
- }
-
- /**
- * Manages accessing passed data as properties
- *
- * @param string $key Property name
- * @return mixed Property value
- * @access public
- * @throws Exception If the property is not found
- */
- public function __get($key){
- if (isset($this->_data[$key]))
- return $this->_data[$key];
- throw new Exception("Value {$key} not set for view {$name}");
- }
-
- /**
- * Renders the template, all dynamically set properties
- * will be available inside the view file as variables.
- * Example:
- * <code>
- * $view = View::get('frontpage');
- * $view->title = "Page title";
- * echo $view->render();
- * </code>
- *
- * @return string Rendered template
- * @access public
- */
- public function render() {
- extract($this->_data);
- ob_start();
- include($this->path);
- $out = ob_get_contents();
- ob_end_clean();
- return $out;
- }
-
- /**
- * Constructs the view
- *
- * @param string $name The name of the template to use
- * @return View
- * @access public
- * @throws Exception If specified template is not found
- * @static
- */
- public static function get($name){
- $view = new View();
- $view->name = $name;
- $file = Misc::find_file('view', $name);
- if ($file == false)
- throw new Exception("View {$name} not found.");
- $view->path=$file;
- return $view;
- }
+<?php
+
+/**
+ * Manages passing variables to templates and rendering them
+ * @package Core
+ */
+class View{
+
+ /**
+ * Full path to template file
+ * @var string
+ * @access private
+ */
+ private $path;
+
+ /**
+ * The name of the view.
+ * @var string
+ * @access public
+ */
+ public $name;
+
+ /**
+ * Stores all the variables passed to the view
+ * @var array
+ * @access private
+ */
+ private $_data = array();
+
+ /**
+ * Manages storing the data passed to the view as properties
+ *
+ * @param string $key Property name
+ * @param string $val Property value
+ * @return void
+ * @access public
+ */
+ public function __set($key, $val) {
+ $this->_data[$key]=$val;
+ }
+
+ /**
+ * Manages accessing passed data as properties
+ *
+ * @param string $key Property name
+ * @return mixed Property value
+ * @access public
+ * @throws Exception If the property is not found
+ */
+ public function __get($key){
+ if (isset($this->_data[$key]))
+ return $this->_data[$key];
+ throw new Exception("Value {$key} not set for view {$name}");
+ }
+
+ /**
+ * Renders the template, all dynamically set properties
+ * will be available inside the view file as variables.
+ * Example:
+ * <code>
+ * $view = View::get('frontpage');
+ * $view->title = "Page title";
+ * echo $view->render();
+ * </code>
+ *
+ * @return string Rendered template
+ * @access public
+ */
+ public function render() {
+ extract($this->_data);
+ ob_start();
+ include($this->path);
+ $out = ob_get_contents();
+ ob_end_clean();
+ return $out;
+ }
+
+ /**
+ * Constructs the view
+ *
+ * @param string $name The name of the template to use
+ * @return View
+ * @access public
+ * @throws Exception If specified template is not found
+ * @static
+ */
+ public static function get($name){
+ $view = new View();
+ $view->name = $name;
+ $file = Misc::find_file('views', $name);
+
+ if ($file == false)
+ throw new Exception("View {$name} not found.");
+
+ $view->path=$file;
+ return $view;
+ }
} \ No newline at end of file