/** * Create a new driver if a factory is present, otherwise throw. * * @return Driver * * @throws \Exception If no factory is set or no driver returned from factory. */ private static function createDriver() { if (self::$factory === null) { throw new \Exception("No loop driver factory set; Either pass a driver to Loop::execute or set a factory."); } $driver = self::$factory->create(); if (!$driver instanceof Driver) { $type = is_object($driver) ? "an instance of " . get_class($driver) : gettype($driver); throw new \Exception("Loop driver factory returned {$type}, but must return an instance of Driver."); } return $driver; }