Ejemplo n.º 1
0
 /**
  * 	method:	runManagedHandler
  *
  * 	todo: write documentation
  *
  * 	NOTE: the code is ready however the system is not
  * 	NOTE: the problem is that service handlers are not programmed to understand the extra attributes
  * 	NOTE: the other problem is that service import/export definitions are not programmed as well
  * 	NOTE: so the idea will have to stay here until I can dedicate time to implementing those.
  *
  * 	NOTE: this method is no longer working because I broke the $object variable and I'm not sure what to replace it with
  */
 protected function runManagedHandler($rules, $callback, &$source)
 {
     //	This method needs to exist on the object to retrieve the validation rules
     $getRules = array($object, "getValidationRules");
     //	continue only if the method is available to call
     if (!method_exists($getRules)) {
         return false;
     }
     $rules = call_user_func($getRules, $rules);
     //	continue only if the rules are valid and a non-empty array
     if (!$rules || !is_array($rules) || empty($rules)) {
         return false;
     }
     //	Now lets execute the handler!
     $v = new Amslib_Validator($source);
     $v->addRules($rules);
     $s = $v->execute();
     $d = $v->getValidData();
     if ($s) {
         //	Set the source to the valid data
         $source = $d;
         //	Here we call the handler, this is a SUCCESS only handler, although the data might fail, the data was valid
         return $this->runHandler($callback, $source);
     } else {
         $service->setValidationData($object, $d);
         $service->setValidationErrors($object, $v->getErrors());
     }
     $service->setDatabaseErrors($object, $object->getDBErrors());
     return false;
 }
Ejemplo n.º 2
0
 public function setConnectionDetails($details = NULL)
 {
     $s = $d = false;
     if ($details) {
         $v = new Amslib_Validator($details);
         $v->add("username", "text", true);
         $v->add("password", "text", true);
         $v->add("database", "text", true);
         $v->add("server", "text", true);
         $v->add("encoding", "text", true, array("default" => "utf8", "limit-input" => $this->validEncoding));
         $s = $v->execute();
         $d = $v->getValid();
         $e = $v->getErrors();
         if (!$s) {
             if (isset($e["password"])) {
                 $e["password"]["value"] = "*CENSORED*";
             }
             Amslib_Debug::log("database details were invalid", $e);
         }
     }
     $this->connectionDetails = $s ? $d : false;
     return $this->getConnectionDetails();
 }
Ejemplo n.º 3
0
 /**
  * 	method:	__construct
  *
  * 	todo: write documentation
  */
 public function __construct($source)
 {
     $this->route = false;
     $this->import = false;
     $this->valid = false;
     $v = new Amslib_Validator($source);
     $v->add("lang", "text", true);
     $v->add("route", "text", true);
     $v->add("route_type", "text", true);
     $v->add("options", "text", true);
     $v->add("options_input", "text", true);
     $v->add("options_output", "text", true);
     $v->add("options_record", "text", true);
     $v->add("options_failure", "text", true);
     $v->add("url", "text", true);
     $v->add("param", "text", true);
     $v->add("param_type", "text", true);
     $v->add("handler", "text", true);
     $v->add("handler_type", "text", true);
     $v->add("database", "instanceof", true, array("type" => "Amslib_Database_MySQL"));
     $s = $v->execute();
     $d = $v->getValid();
     $e = $v->getErrors();
     if ($s) {
         try {
             $this->database = $d["database"];
             $this->table = $d;
             unset($this->table["database"]);
             $this->processPath();
             $this->processService();
             $this->processConfig();
             $this->valid = true;
         } catch (Exception $e) {
             Amslib_Debug::log("Exception: ", $e->getMessage());
             Amslib_Debug::log("stack_trace");
         }
     }
 }