/** * Passes arguments on to the instance gotten from Phi * * @throws InvalidArgumentException If $_binding wasn't set in the subclass * * @param string $name The function to call * @param array $arguments The arguments to pass to the binding * * @returns mixed The return value of the function */ public static function __callStatic($name, array $arguments) { // Throw an exception if $_binding wasn't set in the subclass if (!isset(static::$_binding)) { throw new InvalidArgumentException(get_called_class() . ' must set "protected static $_binding".'); } // Grab the instance and call the function $instance = Phi::instance()->make(static::$_binding); return call_user_func_array([$instance, $name], $arguments); }
public function testMultipleCustomResolver() { $phi = Phi::instance(); $phi->addResolver(new CustomResolver()); $phi->addResolver(new CustomResolver2()); $instance = $phi->make('A'); $this->assertInstanceOf('B', $instance); $instance = $phi->make('B'); $this->assertInstanceOf('A', $instance); $instance = $phi->make('NoConstructor'); $this->assertInstanceOf('NoConstructor', $instance); }