/**
  * Create new container
  *
  * @param array $values The parameters or objects.
  */
 public function __construct(array $values = [])
 {
     // Initialize container for Slim and Pimple
     parent::__construct($values);
     $this['config'] = isset($values['config']) ? $values['config'] : [];
     if (!isset($container['provider/factory'])) {
         $this['provider/factory'] = function (Container $container) {
             return new Factory(['base_class' => ServiceProviderInterface::class, 'resolver_options' => ['suffix' => 'ServiceProvider']]);
         };
     }
     $defaults = ['charcoal/app/service-provider/app' => [], 'charcoal/app/service-provider/cache' => [], 'charcoal/app/service-provider/database' => [], 'charcoal/app/service-provider/logger' => [], 'charcoal/app/service-provider/translator' => [], 'charcoal/app/service-provider/view' => []];
     if (!empty($this['config']['service_providers'])) {
         $providers = array_replace($defaults, $this['config']['service_providers']);
     } else {
         $providers = $defaults;
     }
     foreach ($providers as $provider => $values) {
         if (false === $values) {
             continue;
         }
         if (!is_array($values)) {
             $values = [];
         }
         $provider = $this['provider/factory']->get($provider);
         $this->register($provider, $values);
     }
 }
 public function __construct($settings = [])
 {
     parent::__construct($settings || ['settings' => ['displayErrorDetails' => true]]);
     $this['foundHandler'] = function () {
         return new \Slim\Handlers\Strategies\RequestResponseArgs();
     };
     $this['log'] = function ($container) {
         return new \App\Service\Logger();
     };
 }
示例#3
0
 /**
  * Settings constructor.
  *
  * @param array $settings
  */
 public function __construct(array $settings = [])
 {
     $settings = array_merge($this->default_settings, $settings);
     $DS = DIRECTORY_SEPARATOR;
     $this->document_root = !empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] . $DS : '';
     $this->root_path = !empty($this->document_root) ? dirname($this->document_root) . $DS : '';
     $config_directory = $this->root_path . $DS . trim($settings['config_directory'], '/');
     $this->config_directory = !empty($this->root_path) && is_dir($config_directory) ? $config_directory . $DS : '';
     $this->configureMode()->parseConfig();
     parent::__construct(['settings' => $this->settings]);
 }
示例#4
0
 public function __construct(array $settings = [])
 {
     parent::__construct($settings);
     $this['log'] = function ($container) {
         return new \App\Service\Logger();
     };
     $this['cacheDriver'] = function ($container) {
         $options = ['ttl' => 3600, 'namespace' => md5(__FILE__)];
         $driver = new Stash\Driver\Apc();
         $driver->setOptions($options);
         return $driver;
     };
     $this['cachePool'] = function ($container) {
         return new Stash\Pool($container['cacheDriver']);
     };
 }
示例#5
0
 public function __construct(array $settings = [])
 {
     parent::__construct($settings);
     $this['view'] = function ($container) {
         return new \Slim\Views\JsonView();
     };
     $this['log'] = function ($container) {
         return new \App\Service\Logger();
     };
     $this['errorHandler'] = function ($container) {
         return new \App\Handlers\Error($container['log']);
     };
     $this['friendship'] = function ($container) {
         $client = new Client(NEO4J_HOST, NEO4J_PORT);
         $client->getTransport()->setAuth(NEO4J_LOGIN, NEO4J_PASSWORD);
         return new \App\Service\Friendship($client);
     };
 }
 public function __construct()
 {
     parent::__construct();
     $this['errorHandler'] = function ($container) {
         return function (RequestInterface $request, $response, $exception) use($container) {
             switch ($request->getMethod()) {
                 case "POST":
                     return Reponse::postError($response, $exception);
                     break;
                 case "GET":
                     return Reponse::getError($response, $exception);
                     break;
                 default:
                     return Reponse::error($response, $exception);
                     break;
             }
         };
     };
 }