forked from HubSpot/hubspot-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request HubSpot#11 from HubSpot/sdk-factory
Move logic of auto-discovering to a Factory Base class
- Loading branch information
Showing
3 changed files
with
41 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace HubSpot\Factory; | ||
|
||
use GuzzleHttp\Client; | ||
use HubSpot\Client\Crm\Owners\Configuration; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
class 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 | ||
* | ||
* @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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters