@@ -36,8 +36,12 @@ final class Factory
3636 * @throws \InvalidArgumentException for invalid DNS server address
3737 * @throws \UnderflowException when given DNS Config object has an empty list of nameservers
3838 */
39- public function create ($ config , LoopInterface $ loop = null )
39+ public function create ($ config , $ loop = null )
4040 {
41+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
42+ throw new \InvalidArgumentException ('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface ' );
43+ }
44+
4145 $ executor = $ this ->decorateHostsFileExecutor ($ this ->createExecutor ($ config , $ loop ?: Loop::get ()));
4246
4347 return new Resolver ($ executor );
@@ -59,8 +63,16 @@ public function create($config, LoopInterface $loop = null)
5963 * @throws \InvalidArgumentException for invalid DNS server address
6064 * @throws \UnderflowException when given DNS Config object has an empty list of nameservers
6165 */
62- public function createCached ($ config , LoopInterface $ loop = null , CacheInterface $ cache = null )
66+ public function createCached ($ config , $ loop = null , $ cache = null )
6367 {
68+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
69+ throw new \InvalidArgumentException ('Argument #2 ($loop) expected null|React\EventLoop\LoopInterface ' );
70+ }
71+
72+ if ($ cache !== null && !$ cache instanceof CacheInterface) { // manual type check to support legacy PHP < 7.1
73+ throw new \InvalidArgumentException ('Argument #3 ($cache) expected null|React\Cache\CacheInterface ' );
74+ }
75+
6476 // default to keeping maximum of 256 responses in cache unless explicitly given
6577 if (!($ cache instanceof CacheInterface)) {
6678 $ cache = new ArrayCache (256 );
0 commit comments