Example #1
0
 public function WillFire()
 {
     // Make sure the client is only performing an allowed action.
     $actions = array(self::ACTION_FETCH, self::ACTION_DELETE, self::ACTION_VALIDATE, self::ACTION_INSERT, self::ACTION_UPDATE);
     if (!in_array($this->input->action, $actions)) {
         $this->_Error(-1, 'Action not supported');
         return;
     }
     // Make sure the Model exists and can be validated.
     $classes = get_declared_classes();
     foreach ($classes as $class) {
         $mirror = new \ReflectionClass($class);
         if ($mirror->ImplementsInterface('\\phalanx\\data\\ValidatingModel')) {
             $validator_name = $mirror->GetMethod('ValidatorName')->Invoke(NULL);
             if ($validator_name == $this->input->model) {
                 if (is_array($this->input->data)) {
                     $this->model = $mirror->NewInstance(NULL);
                     $this->model->SetFrom($this->input->data);
                 } else {
                     $this->model = $mirror->NewInstance($this->input->data);
                 }
                 break;
             }
         }
     }
     if (!$this->model) {
         $this->_Error(-2, 'The model could not be created');
         return;
     }
     // Make sure the validator exists.
     $this->validator = $this->model->GetValidator();
     if (!$this->validator || !$this->validator instanceof ModelValidator) {
         $this->_Error(-3, 'The validator could not be created');
         return;
     }
 }