diff --git a/lib/Factory/Base.php b/lib/Factory/Base.php new file mode 100644 index 00000000..835ced5f --- /dev/null +++ b/lib/Factory/Base.php @@ -0,0 +1,39 @@ +client = $client; + $this->config = $config; + } + + /** + * @param string $name + * @param mixed $args + * + * @throws ReflectionException + * + * @return mixed + */ + public function __call($name, $args) + { + $className = (new ReflectionClass(get_class($this)))->getShortName(); + $resource = '\\HubSpot\\Client\\Crm\\'.$className.'\\Api\\'.ucfirst($name); + + return new $resource($this->client, $this->config); + } +} diff --git a/lib/Factory/Objects.php b/lib/Factory/Objects.php index 0842d26b..bc29497f 100644 --- a/lib/Factory/Objects.php +++ b/lib/Factory/Objects.php @@ -2,47 +2,19 @@ namespace HubSpot\Factory; -use GuzzleHttp\Client; use HubSpot\Client\Crm\Objects\Api\AssociationsApi; use HubSpot\Client\Crm\Objects\Api\BasicApi; use HubSpot\Client\Crm\Objects\Api\BatchApi; use HubSpot\Client\Crm\Objects\Api\CreateNativeObjectsApi; use HubSpot\Client\Crm\Objects\Api\SearchApi; -use HubSpot\Client\Crm\Objects\Configuration; /** - * Class Objects. - * * @method AssociationsApi associationsApi() * @method BasicApi basicApi * @method BatchApi batchApi() * @method CreateNativeObjectsApi createNativeObjectsApi * @method SearchApi searchApi() */ -class Objects +class Objects extends Base { - /** @var Client */ - protected $client; - - /** @var Configuration */ - protected $config; - - public function __construct($client, $config) - { - $this->client = $client; - $this->config = $config; - } - - /** - * @param string $name - * @param mixed $args - * - * @return mixed - */ - public function __call($name, $args) - { - $resource = '\\HubSpot\\Client\\Crm\\Objects\\Api\\'.ucfirst($name); - - return new $resource($this->client, $this->config); - } } diff --git a/lib/Factory/Owners.php b/lib/Factory/Owners.php index cbfd192b..c39740f9 100644 --- a/lib/Factory/Owners.php +++ b/lib/Factory/Owners.php @@ -2,37 +2,11 @@ namespace HubSpot\Factory; -use GuzzleHttp\Client; use HubSpot\Client\Crm\Owners\Api\DefaultApi; -use HubSpot\Client\Crm\Owners\Configuration; /** * @method DefaultApi defaultApi() */ -class Owners +class Owners extends Base { - /** @var Client */ - protected $client; - - /** @var Configuration */ - protected $config; - - public function __construct($client, $config) - { - $this->client = $client; - $this->config = $config; - } - - /** - * @param string $name - * @param mixed $args - * - * @return mixed - */ - public function __call($name, $args) - { - $resource = '\\HubSpot\\Client\\Crm\\Owners\\Api\\'.ucfirst($name); - - return new $resource($this->client, $this->config); - } }