/** * 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; }