Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
98900ed
Overhaul of routing methods. Now allows for regular expressions and b…
Aug 24, 2011
dcb6dcc
Passed current var_stack to the hasAccess method
Aug 24, 2011
a8fe502
Minor changes to redirect, views and db update methods
Aug 28, 2011
29dd427
Replaced undefined variable with correct one
Aug 28, 2011
3df6887
Minor bugfixes
Sep 13, 2011
e0c3fa1
Bugfixes to router and upgrade of Twig library to 1.3.0
Oct 13, 2011
f682ce2
Changed default argument for Wave_Utils::redirect() to be null (do no…
Oct 17, 2011
d8c0477
Added CSRF protection support to base controller.
Oct 26, 2011
26e07ac
Bug fix to inflector to stop truncation of last two letters when maki…
Oct 26, 2011
cfaf906
Wave_View updated to allow post-init loading of globals and filters.
Oct 26, 2011
4d781a1
Updates to router and controller
Dec 4, 2011
efecd11
Added ability to filter relation queries (optional $args array passed…
Dec 21, 2011
d62e2b3
Added ability for validator check membership to take arrays
Dec 21, 2011
8603246
Added LOCK_EX to generator file writing to try avoid source errors on…
Jan 10, 2012
31f0c30
Lock file fix for generating models syntax error
Jan 11, 2012
9456cda
Changed the do to correctly namespace class names when building relat…
Jan 23, 2012
c147e08
Added namespace to relation getters to scope the ->from() function co…
Jan 23, 2012
13f8f0a
Multiple fixes to DB generator, added new Debug class
Jan 24, 2012
7567b48
Changes to Auth and DB
Feb 8, 2012
782a373
Fixed comparison that meant values couldn't be set to null in update …
Feb 11, 2012
6fcbfc1
Added ability for validator to return the object when checking it exists
Feb 14, 2012
85edc1a
Added exception when trying to use RequiresLevel without declaring a …
Feb 20, 2012
e273a1d
Fix where is_subclass_of failed to detect Wave_IAuthable instances. C…
Apr 17, 2012
ba2c395
Added new internal response method
Jun 5, 2012
471661b
Changed response_method to be a member property not a singleton
Jun 8, 2012
3f0b35c
Created Wave_DB::basicStatement
Jun 20, 2012
ccc0fc4
Fix for possible infinite loop when the response_method was empty
Jun 20, 2012
0787ed6
Changed handling when lock file already exists when generating models…
Jun 20, 2012
add0655
Added case to convert floats correctly from the database
Jun 20, 2012
690a427
Changes to validator datatypes, email and int
Jun 20, 2012
506025f
Added ability to specify the script name instead of it being deduced …
Jun 20, 2012
509add6
Added Events autoloading.
Jun 20, 2012
a40254a
Added a few extra descriptions and removed deprecated method trigger()
Jun 20, 2012
e18fd20
Updated DB changed (from MC)
Jun 28, 2012
b847afe
Added the sleep timer back in there to avoid the errors for invalid s…
Jul 3, 2012
2f43fa2
Made the check for an empty array in the where clause escape both loo…
Jul 3, 2012
f1d4f25
Changes to validator
Jul 3, 2012
734b1af
Added regex validator type
Jul 6, 2012
dc49d9d
Change to error message thrown when an undeclared static property is …
Jul 16, 2012
c35185e
added new configuration flag for boolean data types in the validator …
Jul 16, 2012
dfe5929
New functionality to bind hooks to actions within the Wave Core
phindmarsh Aug 8, 2012
8cfcd67
Bugfix where no primary key on a table would cause an infinite loop. …
phindmarsh Aug 29, 2012
4c264cf
Added DB save, update and delete methods. Now saves relationships aut…
phindmarsh Sep 4, 2012
6d4c408
Bug fixes to new save functionality
phindmarsh Sep 5, 2012
48a28cc
Fix for datatype caster in db class
phindmarsh Sep 28, 2012
b31c32c
Changes to support new db configuration file format
phindmarsh Oct 8, 2012
e742519
Removed old library code
phindmarsh Oct 8, 2012
c96289c
Fix to not init the database connection every time.
phindmarsh Oct 10, 2012
d64575c
Fix for PDO exception mode and more reliable detection of the last in…
phindmarsh Oct 20, 2012
72a016c
Added DATETIME conversion to mysql driver
phindmarsh Oct 20, 2012
e82af40
Made shorten filter in views html safe
phindmarsh Oct 21, 2012
3b15ebe
Fixer ORM object builder to not create relation objects multiple time…
phindmarsh Oct 22, 2012
dd5ff41
Made the shorten filter escape data properly before use.
phindmarsh Oct 22, 2012
a31e40b
Added check for cache directory existing before generating view caches.
phindmarsh Oct 24, 2012
a4acd09
Updated cookies to allow secure and httponly flags to be set
phindmarsh Nov 13, 2012
58fbfb0
Merge pull request #2 from pricemaker/new_router
phindmarsh Nov 20, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
2 changes: 1 addition & 1 deletion Annotation/RequiresLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function validate($class) {
}

public function build(){
$this->inherit = true;
if(isset($this->parameters['inherit'])){
$this->inherit = $this->parameters['inherit'] == 'true';
unset($this->parameters['inherit']);
}

$this->methods = $this->parameters;
}

Expand Down
8 changes: 1 addition & 7 deletions Annotation/RespondsWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ public function validate($class) {


public function build(){
$this->inherit = false;
if(isset($this->parameters['inherit'])){
$this->inherit = $this->parameters['inherit'] == 'true';
unset($this->parameters['inherit']);
}

$this->methods = $this->parameters;
}

public function addMethods($methods){
foreach($methods as $method){
if(array_search($method, $this->methods) === false)
$this->methods[] = $method;
}
}
}


Expand Down
29 changes: 16 additions & 13 deletions Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class Wave_Auth {

public static $_is_loaded = false;

public static function registerHandler($class){
public static function registerHandler($class, $autoload = true){
if(!class_implements($class))
throw new Wave_Exception('Auth Handler class ('.$class.') must implement Wave_IAuthable');

$class::loadPersistentAuth();
if($autoload) $class::loadPersistentAuth();

self::$_handler = $class;

Expand All @@ -39,13 +39,15 @@ public static function checkIdentity($primary, $secondary){
$_is_valid = true;
// check the secondary credentials
foreach($secondary as $key => $value){
if(!isset($auth_object->$key) || $auth_object->$key != $value){
self::$_auth_problems['secondary'][$key] = array(
'value' => $auth_object->$key,
'reason' => self::FAILURE_BAD_CREDENTIAL,
'match' => $value);
$_is_valid = false;
}
if((is_callable($value) && $value($auth_object->$key))
|| (isset($auth_object->$key) && $auth_object->$key == $value))
continue;

self::$_auth_problems['secondary'][$key] = array(
'value' => $auth_object->$key,
'reason' => self::FAILURE_BAD_CREDENTIAL,
'match' => $value);
$_is_valid = false;
}

if($_is_valid){
Expand All @@ -68,7 +70,7 @@ public static function registerIdentity($identity){
return Wave_Registry::store('__wave_identity', $identity);
}

public static function deregisterIdentity($identity){
public static function deregisterIdentity(){
return Wave_Registry::destroy('__wave_identity');
}

Expand All @@ -86,15 +88,16 @@ public static function persistIdentity($identity, $type = null, $expires = null)
$identity,
strtotime($expires),
$config->cookie->path,
$config->cookie->domain
$config->cookie->domain,
isset($config->cookie->secure) ? $config->cookie->secure : false,
isset($config->cookie->httponly) ? $config->cookie->httponly : true
);
}


}

public static function ceaseIdentity($type = null){

public static function ceaseIdentity($type = null){
$config = Wave_Config::get('deploy')->auth;
if($type === null)
$type = $config->persist_type;
Expand Down
14 changes: 10 additions & 4 deletions Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function register(){
static public function autoload($class){
$search_paths = array();
$skip_app = false;

if (substr($class, 0, 5) === 'Wave_') {
$filename = substr($class, 5);
$search_paths[] = WAVE_CORE_PATH . strtr($filename, '_', DS).'.php';
Expand All @@ -33,23 +33,29 @@ static public function autoload($class){
$path = Wave_Config::get('wave')->path->third_party . 'twig' . DS . 'lib' . DS;
$path .= str_replace('_', '/', $class).'.php';
$search_paths[] = $path;
} else if (0 === strpos($class, 'Event_')) {
$path = Wave_Config::get('wave')->path->events;
$path .= substr(str_replace('_', DS, $class), 6).'.php';
$search_paths[] = $path;
} else {
$search_paths[] = Wave_Config::get('wave')->path->models . strtr($class, '_', DS) . '.php';
$search_paths[] = Wave_Config::get('wave')->path->libraries . strtr($class, '_', DS) . '.php';
}

foreach ($search_paths as $search_path){
if(file_exists($search_path) && include_once($search_path)){
//debug()->addUsedFile($search_path, __FUNCTION__);
Wave_Debug::getInstance()->addUsedFile($search_path, __FUNCTION__);
return;
}
}

//if still not found, try with alias for model
if(Wave_DB::get() !== null){
$alias_class = Wave_DB::get()->getNamespace().Wave_DB::NS_SEPARATOR.$class;
if(Wave_DB::getDefaultNamespace() !== null){
$alias_class = Wave_DB::getDefaultNamespace().Wave_DB::NS_SEPARATOR.$class;

$filename = Wave_Config::get('wave')->path->models . strtr($alias_class, '_', DS) . '.php';
if(file_exists($filename) && include_once($filename)){
Wave_Debug::getInstance()->addUsedFile($filename, __FUNCTION__);
class_alias($alias_class, $class);
}
}
Expand Down
81 changes: 54 additions & 27 deletions Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
class Wave_Controller {


protected static $_response_method;
protected $_response_method;

protected $_data;
protected $_action;

protected $_is_post = false;
protected $_is_get = false;
protected $_check_csrf = false;
//protected $_response_method;

public static final function invoke($action, $data, $router = null){
Expand All @@ -21,7 +22,7 @@ public static final function invoke($action, $data, $router = null){
$invoke[1] = Wave_Config::get('wave')->controller->default_method;

if(class_exists($invoke[0], true)){

$controller = new $invoke[0]();

if($router instanceof Wave_Router){
Expand All @@ -33,27 +34,28 @@ public static final function invoke($action, $data, $router = null){
else if($router->request_method == Wave_Method::POST){
$data = array_merge($_POST, $data);
$controller->_is_post = true;
$controller->_check_csrf = Wave_Config::get('deploy')->auth->csrf->enabled;
}
else if($router->request_method == Wave_Method::CLI){
$data = array_merge($_SERVER['argv'], $data);
}

$controller->_request_uri = $router->request_uri;

self::$_response_method = $router->response_method;
$controller->_response_method = $router->response_method;

}

$controller->_data = $data;
$controller->_action = $action;
unset($data, $router);

if(self::$_response_method == null)
self::$_response_method = Wave_Config::get('wave')->controller->default_response;
if($controller->_response_method == null)
$controller->_response_method = Wave_Config::get('wave')->controller->default_response;

if(method_exists($controller, $invoke[1])){
$controller->init();
$controller->{$invoke[1]}();
return true;
return $controller->{$invoke[1]}();
}
else
throw new Wave_Exception('Could not invoke action '.$action.'. Method '.$invoke[0].'::'.$invoke[1].'() does not exist');
Expand All @@ -80,7 +82,9 @@ protected function inputValid($schema, $data = null) {
$schema_name = strtr($schema, '_', DS);
$schema_file = sprintf(Wave_Config::get('wave')->schemas->file_format, $schema_name);
$schema_path = Wave_Config::get('wave')->path->schemas . $schema_file;


if(!$this->confirmCSRFToken($data)) return false;

$v = new Wave_Validator($data, $schema_path);
$r = $v->validate();
$this->_sanitized = $v->getSanitizedData();
Expand All @@ -89,13 +93,27 @@ protected function inputValid($schema, $data = null) {
unset($v);
return $r == Wave_Validator::RESULT_VALID;
}

public function confirmCSRFToken($data = null){
if($data == null)
$data = $this->_data;

if($this->_check_csrf && isset($this->_identity) && $this->_identity instanceof Wave_IAuthable){
$field_name = Wave_Config::get('deploy')->auth->csrf->form_name;
if(!isset($this->_data[$field_name]) || !$this->_identity->confirmCSRFKey($this->_data[$field_name])){
$this->_input_errors = array($field_name => array('reason' => Wave_Validator::ERROR_INVALID));
return false;
}
}
return true;
}

public static function _setResponseMethod($method){
self::$_response_method = $method;
public function _setResponseMethod($method){
$this->_response_method = $method;
}

public static function _getResponseMethod(){
return self::$_response_method;
public function _getResponseMethod(){
return $this->_response_method;
}


Expand All @@ -122,16 +140,9 @@ protected function _buildPayload($status, $message = '', $payload = null){
}

protected function _buildDataSet(){
$response = array(
'assets' => Wave_Config::get('deploy')->assets,
'_request_uri' => isset($this->_request_uri) ? $this->_request_uri : $_SERVER['REQUEST_URI'],
'_identity' => $this->_identity,
'input' => isset($this->_sanitized) ? $this->_sanitized : $this->_data,
'errors' => isset($this->_input_errors) ? $this->_input_errors : array()
);

$this->_setTemplatingGlobals();
$properties = $this->_getResponseProperties();
return array_merge($properties, $response);
return array_merge($properties);
}

protected function _getResponseProperties(){
Expand All @@ -143,7 +154,13 @@ protected function _getResponseProperties(){
}
return $arr;
}


protected function _setTemplatingGlobals(){
Wave_View::registerGlobal('input', isset($this->_sanitized) ? $this->_sanitized : $this->_data);
Wave_View::registerGlobal('errors', isset($this->_input_errors) ? $this->_input_errors : array());
Wave_View::registerGlobal('_identity', $this->_identity);
Wave_View::registerGlobal('_request_uri', isset($this->_request_uri) ? $this->_request_uri : $_SERVER['REQUEST_URI']);
}

final protected function respond(){
return $this->_invoke('respond');
Expand All @@ -154,19 +171,19 @@ final protected function request(){
}

final private function _invoke($type){
$response_method = $type.strtoupper(self::$_response_method);
if(method_exists($this, $response_method))
$response_method = $type.strtoupper($this->_response_method);
if(method_exists($this, $response_method) && $response_method !== $type)
return $this->{$response_method}();
else
throw new Wave_Exception(
'The action "'.$this->_action.'" tried to respond with "'.
self::$_response_method.'" but the method does not exist'
$this->_response_method.'" but the method does not exist'
);
}

protected function respondHTML(){
if(!isset($this->_template))
throw new Wave_Exception('Template not set for '.self::$_response_method.' in action '.$this->_action);
throw new Wave_Exception('Template not set for '.$this->_response_method.' in action '.$this->_action);

header('Content-type: text/html; charset=utf-8');
echo Wave_View::getInstance()->render($this->_template, $this->_buildDataSet());
Expand Down Expand Up @@ -223,6 +240,16 @@ protected function requestXML(){
if(!isset($this->_message)) $this->_message = Wave_Response::getMessageForCode($this->_status);
return $this->respondXML();
}

protected function respondInternal(){
if(isset($this->_input_errors)){
$this->validation = $this->_input_errors;
}
return $this->_getResponseProperties();
}
protected function requestInternal(){
return $this->respondInternal();
}

}

Expand Down
9 changes: 5 additions & 4 deletions Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

class Wave_Core {

const MODE_DEVELOPMENT = 1;
const MODE_PRODUCTION = 2;

static $_MODE = self::MODE_PRODUCTION;
const MODE_TEST = 'test';
const MODE_DEVELOPMENT = 'development';
const MODE_PRODUCTION = 'production';

static $_MODE = self::MODE_PRODUCTION;

public static function bootstrap($mode = null){

if($mode == null)
Expand Down
Loading