예제 #1
0
 public function __call($name, $args)
 {
     $attributes = array();
     $addto = null;
     $id = null;
     $content = null;
     if (count($args) > 0) {
         foreach ($args as $arg) {
             if (!ctype_digit($arg) && !is_array($arg) && HTMLUTIL::startswith(trim($arg), "{")) {
                 $attributes = json_decode($arg, true);
             } elseif (is_int($arg) && $arg > 0) {
                 $id = $arg;
             } elseif (is_array($arg) && count($arg) == 1) {
                 $addto = $arg[0];
             }
         }
     }
     if ($id === $addto) {
         $id = null;
     }
     $element = array("id" => $id, "name" => $name, "attributes" => $attributes, "content" => $content, "addto" => $this->parent_id($addto));
     $this->__id++;
     if ($this->__id == 0) {
         $element['id'] = 0;
         $element['addto'] = -1;
     }
     $this->__config[$this->__id] = $element;
     return $this;
 }
예제 #2
0
 private function get_function($name, $property, $alias = "")
 {
     $dbalias = $this->__database_alias;
     $db = $this->__database;
     if (!is_object($property)) {
         $property = is_string($property) ? $this->get_variable($property) : $property;
         if ($name == "_limit") {
             if (is_array($property) && count($property) >= 2) {
                 $this->{$alias}->limit($property[0] - 1, $property[1]);
             } else {
                 $this->{$alias}->limit($property);
             }
         } elseif ($name == "_join") {
             if (is_array($property)) {
                 if (is_array($property[0])) {
                     foreach ($property as $properties) {
                         $this->get_function($name, $properties, $alias);
                     }
                 } elseif (count($property) >= 3 && (is_string($property[0]) && is_string($property[1]) && is_string($property[2]))) {
                     $new_operator = E::$dbalias($property[1]);
                     $_links = [$property[0] => $property[1] . ":" . $property[2]];
                     $this->{$alias}->addLinks($_links);
                     $this->{$alias}->joinAdd($new_operator);
                     if (isset($property[3])) {
                         $this->{$alias}->selectAs($new_operator, $property[3]);
                     }
                 }
             }
             if (is_string($property)) {
                 $new_operator = E::$dbalias($property);
                 $this->{$alias}->joinAdd($new_operator);
             }
         } elseif ($name == "_order" || $name == "_group") {
             $function = ltrim($name, "_") . "By";
             $this->{$alias}->{$function}($property);
         } else {
             $database_functions = ["md5", "concat"];
             $function = ltrim($name, "_");
             if (in_array($function, $database_functions)) {
                 $args = [];
                 if (strtolower($function) == "concat") {
                     if (is_array($property)) {
                         foreach ($property as $arg) {
                             $args[] = $this->set_item($alias, $arg);
                         }
                     }
                 }
                 if (strtolower($function) == "md5") {
                     $args[] = $this->set_item($alias, $property);
                 }
                 $return = call_user_func_array($db . "::" . $function, $args);
                 return $return;
             }
         }
     } else {
         foreach ($property as $tablename => $values) {
             foreach ($this->__rowarray__ as $aliasname => $value) {
                 if ($this->{$aliasname}->tablename() == $db::tablename($tablename)) {
                     $this->get_function($name, $values, $aliasname);
                 }
             }
             if (UTIL::startswith($tablename, "_")) {
                 if (is_object($values)) {
                     $function = $this->get_function($tablename, $values, $aliasname);
                     $function = $this->get_function($tablename, $function, $aliasname);
                 } else {
                     $function = $this->get_function($tablename, $values, $aliasname);
                 }
                 return $function;
             }
         }
     }
 }
예제 #3
0
 public static function register_database($name, array $config = [])
 {
     if (empty(self::$defaults)) {
         self::defaults();
     }
     if (isset($config['type']) && isset($config['host']) && isset($config['db']) && isset($config['user']) && isset($config['password'])) {
         $config['usepdo'] = isset($config['usepdo']) && $config['usepdo'] != "" ? DBUTIL::bool_val($config['usepdo']) : true;
         $config['casesensitive'] = isset($config['casesensitive']) && $config['casesensitive'] != "" ? DBUTIL::bool_val($config['casesensitive']) : true;
         $config['tmp'] = isset($config['tmp']) && $config['tmp'] != "" ? $config['tmp'] : "/tmp";
         $config['errorlogcallback'] = isset($config['errorlogcallback']) && $config['errorlogcallback'] != "" ? $config['errorlogcallback'] : null;
         $config['querylogcallback'] = isset($config['querylogcallback']) && $config['querylogcallback'] != "" ? $config['querylogcallback'] : null;
         $config['tablenamecallback'] = isset($config['tablenamecallback']) && $config['tablenamecallback'] != "" ? $config['tablenamecallback'] : null;
         $config['prefix'] = isset($config['prefix']) && $config['prefix'] != "" ? $config['prefix'] : null;
         $config['usedescriptor'] = isset($config['usedescriptor']) && $config['usedescriptor'] != "" ? DBUTIL::bool_val($config['usedescriptor']) : false;
         $config['tablecolumns'] = isset($config['tablecolumns']) && $config['tablecolumns'] != "" ? $config['tablecolumns'] : [];
         $config['dateformat'] = isset($config['dateformat']) && $config['dateformat'] != "" ? $config['dateformat'] : "%d-%m-%Y";
         $config['sequencesuffix'] = isset($config['sequencesuffix']) && $config['sequencesuffix'] != "" ? $config['sequencesuffix'] : "";
         $config['sequences'] = isset($config['sequences']) && !empty($config['sequences']) ? $config['sequences'] : [];
         $config['tablelinks'] = isset($config['tablelinks']) && !empty($config['tablelinks']) ? $config['tablelinks'] : [];
         self::$databases[$name] = $config;
         self::load_class($name);
         $namespace = __NAMESPACE__ . "\\" . $name;
         $namespace::getdatabasedata();
     }
 }