[Eis-commits] SF.net SVN: eis: [204] trunk
Status: Pre-Alpha
Brought to you by:
baslijnse
|
From: <bas...@us...> - 2007-09-10 09:10:36
|
Revision: 204
http://eis.svn.sourceforge.net/eis/?rev=204&view=rev
Author: baslijnse
Date: 2007-09-10 02:10:29 -0700 (Mon, 10 Sep 2007)
Log Message:
-----------
Finished service error mechanism. It is simple for now but can be extended later
Modified Paths:
--------------
trunk/lib/base/service.lib.php
trunk/lib/engine/engine.lib.php
trunk/mod/eis_engine/elements/AddApplication.php
trunk/mod/eis_engine/services/ConfigService.php
Modified: trunk/lib/base/service.lib.php
===================================================================
--- trunk/lib/base/service.lib.php 2007-09-05 10:01:41 UTC (rev 203)
+++ trunk/lib/base/service.lib.php 2007-09-10 09:10:29 UTC (rev 204)
@@ -4,12 +4,11 @@
*/
class Service {
- var $e; /**< variable for the engine */
- var $moduleConfig = array(); /**< array containing moduleconfig */
+ var $e; /**< variable for the engine */
+ var $error; /**< Last error*/
+ var $moduleConfig; /**< array containing moduleconfig */
+ var $mc;
- var $errors; /**< array containig errors */
- var $objects; /**< variable containing objects */
-
/**
*This function parameters are assigned to variable
*@param engine the engine reference for the service
@@ -18,34 +17,43 @@
function Service(&$engine, $moduleConfig) {
$this->e =& $engine;
- $this->errors = array();
+ $this->error = null;
$this->moduleConfig = $moduleConfig;
+
+ $this->mc =& $this->moduleConfig;
}
- /**
- *This function sets the error array of the service
- */
- function setErrors($errors) {
- if(is_array($errors)) {
- $this->errors = $errors;
- }
+ function setError($code = 0, $string = null, $replacements = null) {
+ $this->error = array(
+ 'code' => $code,
+ 'string' => $string,
+ 'replacements' => $replacements);
}
+ function clearError() {
+ $this->error = null;
+ }
+ function success() {
+ return !is_array($this->error);
+ }
+ function getError() {
+ return $this->error;
+ }
+
/**
- *This function retrieves the errors from the engine
- *Every service should handle errors the same, so therefore this base method
- *@result array containing errors
+ * This function retrieves an array with error strings from the engine
+ * This was the old way of error passing in services. It is now replaced by 'set/getError' and 'success' methods
+ * It is still available for backward compatibility
+ *
+ * @return array containing error strings
*/
function getErrors() {
- return $this->errors;
+ if(is_array($this->error)) {
+ return array($this->error['string']);
+ } else {
+ return array();
+ }
}
- function getFirstError() {
- return $this->errors[0];
- }
- function success() {
- return (count($this->errors) == 0);
- }
-
/**
*This function retrieves objects from a databasetable via a Mysql query
*@param table the name of the table from which the objects should be retrieved
Modified: trunk/lib/engine/engine.lib.php
===================================================================
--- trunk/lib/engine/engine.lib.php 2007-09-05 10:01:41 UTC (rev 203)
+++ trunk/lib/engine/engine.lib.php 2007-09-10 09:10:29 UTC (rev 204)
@@ -1173,8 +1173,8 @@
*Make a link to the current page
*@return href to current page
*/
- function hrefCurrentPage() {
- return $this->hrefPage($this->getPath());
+ function hrefCurrentPage($args = null) {
+ return $this->hrefPage($this->getPath(),$args);
}
/**
*Make a link to the parent page
@@ -1182,8 +1182,8 @@
*@see hrefPage hrefAction hrefView hrefDetach hrefImage hrefPreviousPage
*@result return parent page to hrefPage function
*/
- function hrefParentPage($steps = 1) {
- return $this->hrefPage(array_slice($this->getPath(), 0, -1 * $steps));
+ function hrefParentPage($steps = 1, $args = null) {
+ return $this->hrefPage(array_slice($this->getPath(), 0, -1 * $steps),$args);
}
/**
*Makes a link to the previous page
@@ -1275,6 +1275,10 @@
$this->session->save();
}
+ function showServiceError($error) {
+ $this->showError($error['string'],$error['replacements']);
+ }
+
function getMessage() {
$msg = $this->session->get('message','engine');
$this->session->clear('message','engine');
Modified: trunk/mod/eis_engine/elements/AddApplication.php
===================================================================
--- trunk/mod/eis_engine/elements/AddApplication.php 2007-09-05 10:01:41 UTC (rev 203)
+++ trunk/mod/eis_engine/elements/AddApplication.php 2007-09-10 09:10:29 UTC (rev 204)
@@ -67,7 +67,7 @@
$this->e->redirect($this->e->hrefParentPage());
} else {
$this->setPost($form);
- $this->e->showError($sConfig->getFirstError());
+ $this->e->showServiceError($sConfig->getError());
$this->e->redirect($this->e->hrefCurrentPage());
}
}
Modified: trunk/mod/eis_engine/services/ConfigService.php
===================================================================
--- trunk/mod/eis_engine/services/ConfigService.php 2007-09-05 10:01:41 UTC (rev 203)
+++ trunk/mod/eis_engine/services/ConfigService.php 2007-09-10 09:10:29 UTC (rev 204)
@@ -27,42 +27,47 @@
}
function verifyApplication($obj, $new = false) {
- $err = array();
if(!isset($obj['module']) || $obj['module'] == '') {
- $err[] = 'eis_engine.e.missing.module';
+ $this->setError(0,'eis_engine.e.missing.module');
+ return false;
}
if(!isset($obj['application']) || $obj['application'] == '') {
- $err[] = 'eis_engine.e.missing.application';
+ $this->setError(0,'eis_engine.e.missing.application');
+ return false;
}
if(!isset($obj['name']) || $obj['name'] == '') {
- $err[] = 'eis_engine.e.missing.mountpoint';
+ $this->setError(0,'eis_engine.e.missing.mountpoint');
+ return false;
} else {
//Check format of mountpoint
if(!ereg("^[a-zA-Z0-9_\-]+$",$obj['name'])) {
- $err[] = 'eis_engine.e.illegalformat.mountpoint';
+ $this->setError(0,'eis_engine.e.illegalformat.mountpoint');
+ return false;
} else {
//Check if the application is already
if($this->getApplication($obj['name']) != null) {
if($new) {
- $err[] = 'eis_engine.e.application.duplicate.mountpoint';
+ $this->setError(0,'eis_engine.e.application.duplicate.mountpoint',array($obj['name']));
+ return false;
}
} else {
if(!$new) {
- $err[] = 'eis_engine.e.application.nonexistent.mountpoint';
+ $this->setError(0,'eis_engine.e.application.nonexistent.mountpoint',array($obj['name']));
+ return false;
}
}
}
}
if(!isset($obj['environment']) || $obj['environment'] == '') {
- $err[] = 'eis_engine.e.missing.environment';
+ $this->setError(0,'eis_engine.e.missing.environment');
+ return false;
}
- return $err;
+ return true;
}
function createApplication($obj) {
- if($err = $this->verifyApplication($obj,true)) {
- $this->setErrors($err);
- return null;
+ if(!$this->verifyApplication($obj,true)) {
+ return 0;
}
$applications = $this->_loadApplications();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|