protected function testRule($name, $value)
 {
     if (!preg_match('~^test~', $value)) {
         throw new Exception(I18n::text("The 'status' is invalid."));
     }
     return $value;
 }
 protected function emulateAction($query = '')
 {
     if (empty($this->actionToTest)) {
         throw new Exception(I18n::text("Argument 'actionToTest' is invalid."));
     }
     $this->request->removeAll();
     $this->response->removeAll();
     parse_str($query, $parameters);
     foreach ($parameters as $key => $value) {
         $_REQUEST[$key] = $value;
     }
     $this->testerAction->forwardTo($this->actionToTest);
 }
 /**
  *
  * @param string $propertyName
  * @param mixed $propertyValue
  */
 public function setPropertyValue($propertyName, $propertyValue)
 {
     if (!is_string($propertyName) || trim($propertyName) == '') {
         throw new InvalidArgumentException(I18n::text("Argument 'propertyName' is invalid."));
     }
     if ($this->reflectionClass->hasProperty($propertyName)) {
         $property = $this->reflectionClass->getProperty($propertyName);
         $property->setAccessible(true);
         $property->setValue($this->object, $propertyValue);
         $property->setAccessible(false);
     } else {
         $reflection = $this->reflectionClass;
         while ($reflection = $reflection->getParentClass()) {
             if ($reflection->hasProperty($propertyName)) {
                 break;
             }
         }
         if ($reflection != false && $reflection->hasProperty($propertyName)) {
             $property = $reflection->getProperty($propertyName);
             $property->setAccessible(true);
             $property->setValue($this->object, $propertyValue);
             $property->setAccessible(false);
         }
     }
 }
 private function writeActions()
 {
     $success = file_put_contents(self::ActionsFile, json_encode($this->actions, JSON_PRETTY_PRINT));
     if ($success === false) {
         throw new Exception(I18n::text("Couldn't write to the file."));
     }
     return $success;
 }
Exemple #5
0
 /**
  *
  * @param string $actionName
  */
 public function removePreFilter($actionName)
 {
     if (!is_string($actionName)) {
         throw new InvalidArgumentException(I18n::text("Argument 'actionName' is invalid."));
     }
     $this->preFilters[] = $actionName;
     if (($key = array_search($actionName, $this->preFilters)) !== false) {
         unset($this->preFilters[$key]);
     }
 }
Exemple #6
0
 /**
  *
  * @param string $attribute
  */
 public function validate($attribute = null)
 {
     $reflection = new ReflectionClass(get_class($this));
     if (is_null($attribute) || $attribute == '') {
         foreach ($reflection->getProperties() as $p) {
             $p->setAccessible(true);
             $name = $p->getName();
             $value = $p->getValue($this);
             if (!isset($this->validators[$name])) {
                 continue;
             }
             foreach ($this->validators[$name] as $validator) {
                 $value = $this->{$validator}($name, $value);
             }
             $p->setValue($this, $value);
             $p->setAccessible(false);
         }
     } else {
         if (is_string($attribute)) {
             $p = $reflection->getProperty($attribute);
             $p->setAccessible(true);
             $name = $p->getName();
             $value = $p->getValue($this);
             if (!isset($this->validators[$name])) {
                 return;
             }
             foreach ($this->validators[$name] as $validator) {
                 $value = $this->{$validator}($name, $value);
             }
             $p->setValue($this, $value);
             $p->setAccessible(false);
         } else {
             throw new InvalidArgumentException(I18n::text("Argument 'attribute' is invalid."));
         }
     }
 }
Exemple #7
0
 /**
  *
  * @param string $template
  * @throws InvalidArgumentException
  */
 public function template($template)
 {
     if (!is_string($template) || trim($template) == '') {
         throw new InvalidArgumentException(I18n::text("Argument 'template' is invalid."));
     }
     $this->template = $template;
 }
Exemple #8
0
 /**
  *
  * @param string $key
  * @return bool
  */
 public function has($key)
 {
     if (!is_string($key) || trim($key) == '') {
         throw new InvalidArgumentException(I18n::text("Argument 'key' is invalid."));
     }
     return array_key_exists($key, $_SESSION);
 }
 /**
  * 
  * @param string $filename
  * @param string $content
  * @return bool
  * @throws Exception
  * @throws InvalidArgumentException
  */
 public function writeFile($filename, $content, $mode = 'w')
 {
     if (!is_string($filename) || trim($filename) == '') {
         throw new InvalidArgumentException(I18n::text("Argument 'filename' is invalid."));
     }
     if (!is_string($content)) {
         throw new InvalidArgumentException(I18n::text("Argument 'content' is invalid."));
     }
     $file = @fopen($filename, $mode);
     if (!$file) {
         throw new Exception(I18n::text("Couldn't open the file."));
     }
     $success = fwrite($file, $content);
     if (!$success) {
         throw new Exception(I18n::text("Couldn't write to the file."));
     }
     $success = fclose($file);
     if (!$success) {
         throw new Exception(I18n::text("Couldn't close the file."));
     }
     return $success;
 }
Exemple #10
0
 /**
  *
  * @param string $key
  * @return boolean
  */
 public function remove($key)
 {
     if (!is_string($key) || trim($key) == '') {
         throw new InvalidArgumentException(I18n::text("Argument 'key' is invalid."));
     }
     if (array_key_exists($key, $_REQUEST)) {
         unset($_REQUEST[$key]);
     }
     return true;
 }