Jyxo\Rpc\Server::registerClass PHP Method

registerClass() public method

Registers class public methods.
public registerClass ( string $class, boolean $useFullName = true ) : self
$class string Class name
$useFullName boolean Register with class name
return self
    public function registerClass(string $class, bool $useFullName = true) : self
    {
        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class %s does not exist.', $class));
        }
        $reflection = new \ReflectionClass($class);
        foreach ($reflection->getMethods() as $method) {
            // Only public methods
            if ($method->isPublic()) {
                $func = $class . '::' . $method->getName();
                // Save short name as an alias
                if (!$useFullName) {
                    $this->aliases[$method->getName()] = $func;
                    $func = $method->getName();
                }
                $this->register($func);
            }
        }
        return $this;
    }

Usage Example

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