samedi 6 octobre 2018

API Reflection Class with __call magic method - IDE

I am building a basic API package to an external service, using a structure based off a few other packages I have looked through;

MyPacakge.php

public function __construct($key)
{
    $this->key = $key
}

protected function getApiInstance($method)
{
    $class = "\\My\\MyPackage\\Api\\".ucwords($method);
    if (class_exists($class) && ! (new \ReflectionClass($class))->isAbstract()) {
        return new $class($this->key);
    }
    throw new \BadMethodCallException("Undefined method [{$method}] called.");
}

public function __call($method, array $parameters)
{
    return $this->getApiInstance($method);
}

Index.php

$myPackage = new MyPackage;
$myPackage->Class()->method();

Is there any way to get my IDE (phpstorm) to recognise the class and its methods, while using the ReflectionClass function?

Aucun commentaire:

Enregistrer un commentaire