Пример #1
0
 public static function falloff_retry_ex()
 {
     $response = '';
     $url = "http://www.reddit.com/.json";
     Consistency::falloff_retry(function () use($url, &$response) {
         if (rand(0, 2) == 0) {
             $response = file_get_contents($url);
         } else {
             throw new Exception("Intermittent failure");
         }
     });
     echo md5($response) . "\n";
 }
Пример #2
0
 /**
  * Dynamic new, a simple factory.
  * It loads and constructs a class, with provided arguments.
  *
  * @param   bool     $classname    Classname.
  * @param   array    $arguments    Arguments for the constructor.
  * @return  object
  */
 public static function dnew($classname, array $arguments = [])
 {
     $classname = ltrim($classname, '\\');
     if (false === Consistency::entityExists($classname, false)) {
         spl_autoload_call($classname);
     }
     $class = new \ReflectionClass($classname);
     if (empty($arguments) || false === $class->hasMethod('__construct')) {
         return $class->newInstance();
     }
     return $class->newInstanceArgs($arguments);
 }