Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 51 → Rev 52

/trunk/Db/MySQLDB.php
2,8 → 2,6
 
namespace PointedEars\PHPX\Db;
 
require_once __DIR__ . '/Database.php';
 
class MySQLDB extends Database
{
/**
/trunk/Db/Database.php
3,7 → 3,6
namespace PointedEars\PHPX\Db;
 
require_once __DIR__ . '/../global.inc';
require_once __DIR__ . '/../AbstractModel.php';
 
/**
* Generic database model class using PDO (PHP Data Objects)
/trunk/Db/Mapper.php
2,9 → 2,6
 
namespace PointedEars\PHPX\Db;
 
require_once __DIR__ . '/../AbstractModel.php';
require_once __DIR__ . '/Table.php';
 
/**
* Generic abstract database mapper class
*
/trunk/Db/Table.php
2,9 → 2,6
 
namespace PointedEars\PHPX\Db;
 
require_once __DIR__ . '/../Application.php';
require_once __DIR__ . '/../AbstractModel.php';
 
use \PointedEars\PHPX\Application;
 
/**
/trunk/Model.php
1,6 → 1,6
<?php
 
require_once __DIR__ . '/AbstractModel.php';
namespace PointedEars\PHPX;
 
/**
* Abstract model class for Object-Relational Mapping
10,7 → 10,7
*
* @author Thomas Lahn
*/
abstract class Model extends AbstractModel
abstract class Model extends \PointedEars\PHPX\AbstractModel
{
/**
* The <code>Table</code> for instances of this model
69,11 → 69,11
else
{
$table = new $value();
if (!($table instanceof Table))
if (!($table instanceof Db\Table))
{
throw new \InvalidArgumentException(
'Expected Table instance or string for table name, saw '
. (\get_class($value) || \gettype($value))
'Parameter does not specify a subclass of \\PointedEars\\PHPX\\Table: '
. $value
);
}
 
125,7 → 125,7
public function find ()
{
$result = $this->persistentTable->find(
$this->{$this->__persistentId});
$this->{$this->_persistentId});
if ($result)
{
return $this->map($result);
/trunk/Application.php
2,9 → 2,21
 
namespace PointedEars\PHPX;
 
require_once __DIR__ . '/AbstractModel.php';
require_once __DIR__ . '/Registry.php';
function autoload ($class)
{
if (\strpos($class, '..'))
{
throw new \InvalidArgumentException(
'Refusing to load unsafe class ' . $class);
}
 
require_once \preg_replace('#\\\#', '/',
\preg_replace('#^' . \preg_quote(__NAMESPACE__) .'#', __DIR__, $class)
) . '.php';
}
 
\spl_autoload_register(__NAMESPACE__ . '\\autoload');
 
/**
* Basic application class
*
43,7 → 55,7
*/
private static $_instance;
 
protected function __construct()
protected function __construct ()
{
/* Singleton pattern */
}
57,7 → 69,7
* already initialized.
* @return Application
*/
public static function getInstance(Application $instance = null)
public static function getInstance (Application $instance = null)
{
if (self::$_instance === null)
{
74,23 → 86,23
* @throws ModelPropertyException
* @return mixed
*/
public function __get($name)
public function __get ($name)
{
/* Support for Object-Relational Mappers */
if (strpos($name, 'persistent') === 0)
if (\strpos($name, 'persistent') === 0)
{
$class = get_class($this);
$class = \get_class($this);
return $class::${$name};
}
 
$method = 'get' . ucfirst($name);
$method = 'get' . \ucfirst($name);
 
if (method_exists($this, $method))
if (\method_exists($this, $method))
{
return $this->$method();
}
 
if (property_exists($this, "_$name"))
if (\property_exists($this, "_$name"))
{
return $this->{"_$name"};
}
105,16 → 117,16
* @param mixed $value The new property value before assignment
* @throws ModelPropertyException
*/
public function __set($name, $value)
public function __set ($name, $value)
{
$method = 'set' . ucfirst($name);
$method = 'set' . \ucfirst($name);
 
if (method_exists($this, $method))
if (\method_exists($this, $method))
{
return $this->$method($value);
}
 
if (property_exists($this, "_$name"))
if (\property_exists($this, "_$name"))
{
$this->{"_$name"} = $value;
return $this->{"_$name"};
127,7 → 139,7
* Runs the application, setting up session management and
* constructing the controller indicated by the URI
*/
public function run()
public function run ()
{
$this->startSession();
 
137,7 → 149,7
$controller = $this->_defaultController;
}
 
$controller = ucfirst($controller);
$controller = \ucfirst($controller);
 
$controller = $controller . 'Controller';
require_once "{$this->_controllerPath}/{$controller}.php";
146,9 → 158,9
return $this;
}
 
protected function startSession()
protected function startSession ()
{
session_start();
\session_start();
}
 
/**
163,7 → 175,7
* <code>null</code> if there is no such <var>$key</var>
* in <var>$array</var>
*/
public static function getParam($key, array $array = null)
public static function getParam ($key, array $array = null)
{
if ($array === null)
{
202,7 → 214,7
* @param Controller $controller
* @return Application
*/
public function setCurrentController(Controller $controller)
public function setCurrentController (Controller $controller)
{
$this->_currentController = $controller;
return $this;
213,7 → 225,7
*
* @return Controller
*/
public function getCurrentController()
public function getCurrentController ()
{
return $this->_currentController;
}
223,7 → 235,7
*
* @return Database
*/
public function getDefaultDatabase()
public function getDefaultDatabase ()
{
return Registry::get($this->_defaultDatabase);
}
236,7 → 248,7
* @param string[optional] $action
* @param int[optional] $id
*/
public function getURL($controller = null, $action = null, $id = null)
public function getURL ($controller = null, $action = null, $id = null)
{
/* Apache module */
$url = self::getParam('SCRIPT_URL', $_SERVER);
248,7 → 260,7
{
/* Server/PHP too old, compute URI */
$url = self::getParam('REQUEST_URI', $_SERVER);
if (preg_match('/^[^?]+/', $url, $matches) > 0)
if (\preg_match('/^[^?]+/', $url, $matches) > 0)
{
$url = $matches[0];
}
258,7 → 270,7
$url = self::getParam('SCRIPT_NAME', $_SERVER);
if ($url === null)
{
throw new Exception(
throw new \Exception(
'None of $_SERVER["SCRIPT_URL"], $_SERVER["URL"],'
. ' $_SERVER["REQUEST_URI"], or $_SERVER["SCRIPT_NAME"]'
. ' is available, cannot continue.');
277,13 → 289,13
/**
* Performs a server-side redirect within the application
*/
public static function redirect($query = '')
public static function redirect ($query = '')
{
$script_uri = self::getParam('SCRIPT_URI', $_SERVER);
if ($script_uri === null)
{
/* Server/PHP too old, compute URI */
if (preg_match('/^[^?]+/',
if (\preg_match('/^[^?]+/',
self::getParam('REQUEST_URI', $_SERVER), $matches) > 0)
{
$query_prefix = $matches[0];
302,7 → 314,7
. $query_prefix;
}
 
header('Location: ' . $script_uri
\header('Location: ' . $script_uri
. ($query ? (substr($query, 0, 1) === '?' ? '' : '?') . $query : ''));
}
}
}
/trunk/View.php
2,9 → 2,6
 
namespace PointedEars\PHPX;
 
require_once __DIR__ . '/Application.php';
require_once __DIR__ . '/AbstractModel.php';
 
/**
* A general view handled by a controller according to the MVC pattern
*
/trunk/Controller.php
2,9 → 2,6
 
namespace PointedEars\PHPX;
 
require_once __DIR__ . '/Application.php';
require_once __DIR__ . '/View.php';
 
/**
* A general controller that can handle views according to
* the MVC pattern
/trunk/AbstractModel.php
8,10 → 8,10
interface ILocalizable
{
/**
* Localizes this model. The actual implementation is left to the model class
* implementing this interface.
* Localizes this model. The actual implementation is left to
* the model class implementing this interface.
*/
function localize();
function localize ();
}
 
/**
30,7 → 30,7
* @param array $data Initialization data (optional)
* @param array $mapping Mapping for initialization data (optional)
*/
protected function __construct(array $data = null, array $mapping = null)
protected function __construct (array $data = null, array $mapping = null)
{
if (!is_null($data))
{
45,14 → 45,14
* @throws ModelPropertyException
* @return mixed
*/
public function __get($name)
public function __get ($name)
{
/* Support for Object-Relational Mappers */
if (strpos($name, 'persistent') === 0)
{
$class = get_class($this);
return $class::${$name};
}
// if (strpos($name, 'persistent') === 0)
// {
// $class = get_class($this);
// return $class::${$name};
// }
 
$method = 'get' . ucfirst($name);
 
76,7 → 76,7
* @param mixed $value The new property value before assignment
* @throws ModelPropertyException
*/
public function __set($name, $value)
public function __set ($name, $value)
{
$method = 'set' . ucfirst($name);
 
102,7 → 102,7
* @return boolean
* @see getPropertyVars()
*/
private static function _isPropertyVar($varName)
private static function _isPropertyVar ($varName)
{
return preg_match('/^_\\w/', $varName) > 0;
}
115,7 → 115,7
* @return string
* @see getPropertyVars()
*/
private static function _toPropertyVar($varName)
private static function _toPropertyVar ($varName)
{
return preg_replace('/^_(\\w)/', '\\1', $varName);
}
126,7 → 126,7
*
* @return array
*/
public function getPropertyVars()
public function getPropertyVars ()
{
return array_map(
array('self', '_toPropertyVar'),
159,7 → 159,7
* @return AbstractModel
* The modified object
*/
public function map(array $data, array $mapping = null, $exclusive = false)
public function map (array $data, array $mapping = null, $exclusive = false)
{
if (is_null($mapping))
{