Jyxo\Rpc\Server::registerMethod PHP Method

registerMethod() public method

Method does not necessarily have to exist if __call or __callStatic method is defined.
public registerMethod ( string $class, string $method, boolean $useFullName = true ) : self
$class string Class name
$method string Function name
$useFullName boolean Register with class name
return self
    public function registerMethod(string $class, string $method, bool $useFullName = true) : self
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Třída %s neexistuje.', $class));
        }
        // If magic methods exist, always register
        if (!method_exists($class, '__call') && !method_exists($class, '__callStatic')) {
            try {
                $reflection = new \ReflectionMethod($class, $method);
            } catch (\ReflectionException $e) {
                throw new \InvalidArgumentException(sprintf('Method %s::%s does not exist.', $class, $method));
            }
            // Only public methods
            if (!$reflection->isPublic()) {
                throw new \InvalidArgumentException(sprintf('Method %s::%s is not public.', $class, $method));
            }
        }
        $func = $class . '::' . $method;
        // Save short name as an alias
        if (!$useFullName) {
            $this->aliases[$method] = $func;
            $func = $method;
        }
        $this->register($func);
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * Tests registering a method of a non-existent class.
  */
 public function testRegisterMethodInNonExistingClass()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     $this->rpc->registerMethod('Dummy', 'dummy');
 }
All Usage Examples Of Jyxo\Rpc\Server::registerMethod