Tebru\Retrofit\Adapter\Rest\RestAdapter::create PHP Method

create() public method

Create a new service
public create ( string | mixed $service ) : mixed
$service string | mixed
return mixed $service
    public function create($service)
    {
        // if it's an object, we just want to return it
        if (is_object($service)) {
            return $service;
        }
        // if it's not a string, we don't know how to handle this type
        if (!is_string($service)) {
            throw new RetrofitException(sprintf('Could not create client. Expected object or string, got "%s"', gettype($service)));
        }
        // get the class as a string
        // if $service is already a class, use that, otherwise,
        if (class_exists($service)) {
            $class = $service;
        } elseif (interface_exists($service)) {
            $class = Retrofit::NAMESPACE_PREFIX . '\\' . $service;
        } else {
            throw new RetrofitException(sprintf('Could not create client. "%s" should be a class or interface.', $service));
        }
        return new $class($this->baseUrl, $this->httpClient, $this->eventDispatcher, $this->serializerAdapter, $this->deserializerAdapter);
    }

Usage Example

Example #1
0
 public function account()
 {
     if (null === $this->accountClient) {
         $this->accountClient = $this->restAdapter->create('Tebru\\Stripe\\Client\\AccountClient');
     }
     return $this->accountClient;
 }
All Usage Examples Of Tebru\Retrofit\Adapter\Rest\RestAdapter::create