private function addApi($clientServiceId, $name, $config)
 {
     if (!$config['url']) {
         throw new \InvalidArgumentException("'url' must be defined");
     }
     $app = $this->app;
     $apiCallable = function () use($app, $clientServiceId, $config) {
         if (!isset($app[$clientServiceId])) {
             throw new \InvalidArgumentException("'{$clientServiceId}' service does not exists");
         }
         $url = $config['url'];
         $defaultParams = array();
         /**
          * resolve params to container services if applicable
          */
         foreach ($config['default_params'] as $param => $value) {
             $value = isset($app[$value]) ? $app[$value] : $value;
             $defaultParams[$param] = $value;
         }
         /**
          * create new Api
          */
         $api = new Api($app[$clientServiceId], $url);
         $api->setDefaultParams($defaultParams);
         return $api;
     };
     $this->app['devhelp_piwik.api.' . $name] = $this->app->share($apiCallable);
 }
Exemple #2
0
 /**
  * @test
  */
 public function it_returns_method()
 {
     $api = new Api($this->client->reveal(), 'http://my.piwik.pro');
     $this->assertInstanceOf('Devhelp\\Piwik\\Api\\Method\\Method', $api->getMethod('MyPlugin.myAction'));
 }