예제 #1
0
 public function registerAutoload(callable $function)
 {
     spl_autoload_register(function ($class) use($function) {
         $function($class);
         if (class_exists($class, false)) {
             if (isset(class_uses($class)[Model::class])) {
                 ModelRegistry::getInstance()->registerClass($class);
             }
             try {
                 $classReflector = new \ReflectionClass($class);
                 $methodReflector = $classReflector->getMethod("__static");
                 if ($methodReflector->getDeclaringClass()->getName() == $classReflector->getName()) {
                     $methodReflector->setAccessible(true);
                     $methodReflector->invoke(new \stdClass());
                 }
             } catch (\ReflectionException $e) {
             }
         }
     });
 }
예제 #2
0
 public function __debugInfo()
 {
     $debugInfoRecursionHelper = ModelRegistry::getInstance()->getDebugInfoRecursionHelper();
     $debugInfoRecursionHelper[$this] = true;
     $retval = [];
     foreach ($this as $name => $value) {
         if ($name == "__foreignKeyValues") {
             continue;
         }
         $retval[$name] = $value;
     }
     foreach (self::$__foreignKeys as $name => $class) {
         if (PHP_MAJOR_VERSION == 5) {
             if (($value = $this->__get($name)) !== null) {
                 $retval[$name] = isset($debugInfoRecursionHelper[$value]) ? "*RECURSION*" : $value->__debugInfo();
             } else {
                 $retval[$name] = null;
             }
         } else {
             $retval[$name] = $this->__get($name);
         }
     }
     unset($debugInfoRecursionHelper[$this]);
     return $retval;
 }
예제 #3
0
 public function executeInTransaction(callable $call, callable $onError = null, $selectForUpdate = null)
 {
     try {
         ModelRegistry::getInstance()->activateTransactionalCache();
         $this->beginTransaction($selectForUpdate);
         $retval = $call();
         if ($this->inTransaction()) {
             $this->commit();
         }
         ModelRegistry::getInstance()->deactivateTransactionalCache();
     } catch (\PDOException $e) {
         $this->rollBack();
         ModelRegistry::getInstance()->deactivateTransactionalCache();
         if ($onError && $onError($e)) {
             return $this->executeInTransaction($call, $onError, $selectForUpdate);
         }
         throw $e;
     } catch (\Exception $e) {
         $this->rollBack();
         ModelRegistry::getInstance()->deactivateTransactionalCache();
         throw $e;
     } catch (\Error $e) {
         $this->rollBack();
         ModelRegistry::getInstance()->deactivateTransactionalCache();
         throw $e;
     }
     return $retval;
 }