diff --git a/composer.json b/composer.json index 319664f..f008514 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "lanlin/nylas-php", - "description": "Nylas PHP SDK (api version 2.2)", + "description": "Nylas PHP SDK (api version 2.3)", "license": "MIT", "authors" : [ { @@ -16,9 +16,9 @@ "zbateson/mail-mime-parser": "^2.0" }, "require-dev": { + "fakerphp/faker": "^1.19", "phpunit/phpunit": "^9.5", "mockery/mockery": "^1.4", - "fzaninotto/faker": "dev-master", "nunomaduro/collision": "^6.1", "roave/security-advisories": "dev-latest" }, diff --git a/src/Client.php b/src/Client.php index c696876..6eea276 100644 --- a/src/Client.php +++ b/src/Client.php @@ -10,6 +10,7 @@ * Nylas Client * ---------------------------------------------------------------------------------- * + * @property Utilities\Options Options * @property Authentication\Abs Authentication * @property Calendars\Abs Calendars * @property Contacts\Abs Contacts @@ -29,17 +30,12 @@ * @property Webhooks\Abs Webhooks * * @author lanlin - * @change 2022/01/27 + * @change 2022/03/09 */ class Client { // ------------------------------------------------------------------------------ - /** - * @var Options - */ - public Options $options; - /** * @var array */ @@ -62,7 +58,7 @@ class Client */ public function __construct(array $options) { - $this->options = new Options($options); + $this->objects['Options'] = new Options($options); } // ------------------------------------------------------------------------------ @@ -90,12 +86,14 @@ public function __get(string $name): object */ private function callSubClass(string $name): object { + $name = \ucfirst($name); + if (!empty($this->objects[$name])) { return $this->objects[$name]; } - $apiClass = __NAMESPACE__.'\\'.\ucfirst($name).'\\Abs'; + $apiClass = __NAMESPACE__.'\\'.$name.'\\Abs'; // check class exists if (!\class_exists($apiClass)) @@ -103,7 +101,7 @@ private function callSubClass(string $name): object throw new NylasException(null, "class {$apiClass} not found!"); } - return $this->objects[$name] = new $apiClass($this->options); + return $this->objects[$name] = new $apiClass($this->objects['Options']); } // ------------------------------------------------------------------------------ diff --git a/src/Utilities/Options.php b/src/Utilities/Options.php index 9f53367..de1bbdf 100644 --- a/src/Utilities/Options.php +++ b/src/Utilities/Options.php @@ -100,7 +100,7 @@ public function setHandler(?callable $handler): void /** * get access token * - * @return string + * @return null|callable */ public function getHandler(): ?callable { diff --git a/tests/AbsCase.php b/tests/AbsCase.php index d784900..aaf9242 100644 --- a/tests/AbsCase.php +++ b/tests/AbsCase.php @@ -186,7 +186,7 @@ protected function mockResponse(array $data, array $header = [], int $code = 200 $mock = new MockHandler([new Response($code, $header, $body)]); - $this->client->options->setHandler($mock); + $this->client->Options->setHandler($mock); } // ------------------------------------------------------------------------------