Exemplo n.º 1
0
 public static function boot()
 {
     Cli::show("Start of execution", 'COMMENT');
     View::cleanCache();
     Database::cleanCache();
     Utils::cleanCache(true);
     Cli::show("End of execution", 'COMMENT');
 }
Exemplo n.º 2
0
 private function related($obj)
 {
     $settings = isAke(self::$config, "{$this->database}.{$this->table}");
     $relations = isAke($settings, 'relations');
     $params = $this->args;
     if (count($relations)) {
         foreach ($relations as $relation) {
             $field = $relation . '_id';
             if (is_string($field)) {
                 $value = $obj->{$field};
                 if (!is_callable($value)) {
                     $fk = $tableFk = $relation;
                     $fks = $fk . 's';
                     $cb = function ($object = true) use($value, $tableFk, $params) {
                         list($database, $table, $host, $username, $password) = $params;
                         $db = Database::instance($database, $tableFk, $host, $username, $password);
                         if ($db) {
                             return $db->find($value, $object);
                         }
                         return null;
                     };
                     $obj->event($fk, $cb);
                     $cb = function ($object = true) use($value, $tableFk, $params) {
                         list($database, $table, $host, $username, $password) = $params;
                         $db = Database::instance($database, $tableFk, $host, $username, $password);
                         if ($db) {
                             return $db->where($db->pk() . " = '" . addslashes($value) . "'")->exec($object);
                         }
                         return null;
                     };
                     $obj->event($fks, $cb);
                     $setter = lcfirst(Inflector::camelize("link_{$fk}"));
                     $cb = function (Container $fkObject) use($obj, $field, $fk) {
                         $obj->{$field} = $fkObject->id();
                         $newCb = function () use($fkObject) {
                             return $fkObject;
                         };
                         $obj->event($fk, $newCb);
                         return $obj;
                     };
                     $obj->event($setter, $cb);
                 }
             }
         }
     }
     return $obj;
 }