/** * Magic method for static calls * @param string $name * @param array $arguments * @return mixed */ public static function __callstatic($name, $arguments) { // Get global services or entity services $services = Client::getServices(isset($arguments['context']) ? $arguments['context'] : null); if (array_key_exists($name, $services)) { $service = $services[$name]; switch ($service['type']) { case 'collection': return new Cursor($service, Client::getInstance(), isset($arguments['context']) ? $arguments['context'] : null); break; case 'entity': return new Entity($service, Client::getInstance(), isset($arguments[0]) ? $arguments[0] : null); break; // $name represents an action on an entity // $name represents an action on an entity case 'action': return new Action($service, $arguments['context'], Client::getInstance()); break; default: throw new \Exception("Don't know of any service type named '{$name}'"); break; } } else { throw new \Exception("can't find service definition for '{$name}'"); } }
/** * Register the service provider * @return XacAPI */ public function register() { $this->app['arrowsphere.client'] = $this->app->share(function ($app) { //Set apiKey and baseUrl on client. xACClient::setApiKey(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIKEY')); xACClient::setApiBaseUrl(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_URL')); xACClient::setApiVersion(Config::get('arrowsphere-client.' . APP::environment() . '.XAC_APIVERSION')); return xACClient::getInstance(); }); $this->app['command.arrowsphere.list'] = $this->app->share(function ($app) { return new servicesListCommand($app['config'], $app['files'], $app['view']); }); $this->app['command.arrowsphere.refresh'] = $this->app->share(function ($app) { return new refreshListCommand($app['files']); }); $this->commands('command.arrowsphere.list', 'command.arrowsphere.refresh'); $this->app->bind('Arrowsphere\\Client\\xAC', 'arrowsphere.client'); }
public function testInstanceIsSingleton() { $this->assertEquals(xAC::getInstance(), $this->client); }