Exemple #1
0
 public function validate($value)
 {
     if ($value == null) {
         return true;
     }
     if ($this->length != null && strlen($value) > $this->length) {
         return false;
     } elseif ($this->regex != null && !Core\Tools::match($value, $this->regex)) {
         return false;
     }
     return true;
 }
Exemple #2
0
 /**
  * Main module function, executed right after module loading by Orion.
  * Handles route parsing and function callbacks.
  */
 public function load()
 {
     if ($this->route == null) {
         if (!\Orion::config()->defined('ROUTING_AUTO') || \Orion::config()->get('ROUTING_AUTO') == false) {
             $this->sendError(self::E_ROUTE_NO);
         }
         $this->route = new Route();
         $function = $this->route->decodeAuto();
     } else {
         $function = $this->route->decode();
     }
     if (Core\Tools::startWith($function->getName(), '__')) {
         $this->sendError(self::E_FUNCTION_NO);
     }
     if (Core\Tools::startWith($function->getName(), self::FUNCTION_PREFIX)) {
         $this->sendError(self::E_FUNCTION_NO);
     }
     if (!is_callable(array($this, self::FUNCTION_PREFIX . $function->getName()))) {
         $this->sendError(self::E_FUNCTION_NO);
     }
     Core\Tools::callClassMethod($this, self::FUNCTION_PREFIX . $function->getName(), $function->getArgs());
 }
Exemple #3
0
 /**
  * Parse query-resulting object to build linked objects from joined fields' syntax.<br />
  * In other words, convert "L_FIELD_SLUG.$linkedfield.L_FIELD_SEP.$fieldname" into linked Object.
  * @param \Orion\Core\Model|\Orion\Core\Object
  */
 protected function parseJoinFields(&$object)
 {
     if (is_array($object)) {
         $c = count($object);
         for ($i = 0; $i < $c; $i++) {
             self::parseJoinFields($object[$i]);
         }
         return;
     }
     $linkedFields = Core\Tools::extractArrayKeysStartingWith(get_object_vars($object), self::L_FIELD_SLUG);
     $l_field_len = strlen(self::L_FIELD_SLUG);
     foreach ($linkedFields as $key => $value) {
         $tmp = explode(self::L_FIELD_SEP, substr($key, $l_field_len));
         $field = $tmp[0];
         $subfield = $tmp[1];
         if (!$object->{$field} instanceof Core\Model || !$object->{$field} instanceof Core\Object) {
             if ($this->hasModel($field)) {
                 $model = $this->model;
                 if (!$model::isLinked($field)) {
                     $object->{$field} = new Object();
                 } else {
                     $linkedClass = $model::getField($field)->getModel();
                     $object->{$field} = new $linkedClass();
                 }
             } else {
                 $object->{$field} = new Object();
             }
         }
         $object->{$field}->{$subfield} = $value;
         unset($object->{$key});
     }
 }