Skip to content

Instantly share code, notes, and snippets.

@tjlytle
Created May 13, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjlytle/5b5cc9df2555f8db6ad1 to your computer and use it in GitHub Desktop.
Save tjlytle/5b5cc9df2555f8db6ad1 to your computer and use it in GitHub Desktop.
<?php
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class ClientFactory implements AbstractFactoryInterface
{
protected $services = [
'Nexmo\Sms',
'Nexmo\Voice',
'Nexmo\Developer',
'Nexmo\Verify',
'Nexmo\Insight'
];
protected $config = [];
/**
* Determine if we can create a service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
if(!in_array($requestedName, $this->services)){
return false;
}
if(empty($this->config) AND !$serviceLocator->has('config')){
return false;
}
$this->config = $serviceLocator->get('config');
if(!isset($this->config['nexmo'])){
return false;
}
return true;
}
/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param $name
* @param $requestedName
* @return mixed
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return new $requestedName($this->config['nexmo']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment