Exemplo n.º 1
0
 /**
  * Register the core services.
  *
  * @param Application $app
  */
 private function registerServices(Application $app)
 {
     foreach ($app->config->get('swap.services', []) as $name => $config) {
         if (false === $config) {
             continue;
         }
         $class = $this->getServiceClass($name);
         $serviceName = sprintf('swap.service.%s', $name);
         // The PhpArray service is a particular case
         if ('array' === $name) {
             return $app->singleton($serviceName, function () use($config) {
                 return new PhpArray($config);
             });
         }
         // Process the regular services
         if (!class_exists($class)) {
             throw new \RuntimeException(sprintf('The service "%s" does not exist.', $name));
         }
         if (!is_array($config)) {
             $config = [];
         }
         $app->singleton($serviceName, function ($app) use($class, $config) {
             return new $class($app['swap.http_client'], $app['swap.request_factory'], $config);
         });
         $app->tag($serviceName, 'swap.service');
     }
 }