Ejemplo n.º 1
1
 protected function setUp()
 {
     $this->app = $app = new Container();
     $db_config = ['driver' => 'pdo_sqlite', 'dbname' => 'sqlite:///:memory:'];
     $models = ['post.model' => function () use($app) {
         return new Post($app);
     }, 'comment.model' => 'Comment'];
     $app['db'] = function () use($db_config) {
         $db = \Doctrine\DBAL\DriverManager::getConnection($db_config);
         $sql = file_get_contents(codecept_data_dir() . '/dump.sql');
         $db->exec($sql);
         return $db;
     };
     foreach ($models as $name => $class) {
         if (is_callable($class)) {
             $callable = $class;
         } else {
             $callable = function () use($class, $app) {
                 return new $class($app);
             };
         }
         $app[$name] = $app->factory($callable);
     }
     $this->loadFixtures();
 }
 /**
  * @param Application|Container $app
  *
  */
 public function boot($app)
 {
     // only if enabled
     if ($app['config']['view.blade.enabled']) {
         // default blade context to simplify creating a new Blade|BladeView object.
         $app['blade.context'] = function ($app) {
             return new BladeConfigurationSet(['engine' => $app['blade.engine'], 'events' => $app['illuminate.events'], 'factory' => $app['blade.factory'], 'finder' => $app['view.finder'], 'global' => $app['global.scope'], 'paths' => $app['paths'], 'settings' => $app['blade.settings']]);
         };
         $this->container->add([BladeConfigurationSet::class, BladeViewConfigurationInterface::class], function () use($app) {
             return $app['blade.context'];
         });
         $this->container->add([BladeView::class, 'BladeView'], function () use($app) {
             return new BladeView($this->app['blade.context']);
         });
         // for dependency injection. ie: DI::make(BladeView::class)
         $app[BladeViewConfigurationInterface::class] = function ($app) {
             return $app['blade.context'];
         };
         $app['blade'] = $app->factory(function () {
             return new Blade($this->app['blade.context']);
         });
         $app['blade.view'] = $app->factory(function () {
             return new BladeView($this->app['blade.context']);
         });
     }
 }
Ejemplo n.º 3
0
 /**
  * Registers all modules
  * @return void
  */
 public function registerModules()
 {
     $container = $this;
     $this->container['twig_loader'] = function ($c) use($container) {
         return $container->registerTwigLoader($c);
     };
     $this->container['twig'] = function ($c) use($container) {
         return $container->registerTwigEnviroment($c);
     };
     $this->container['admin_router'] = function ($c) use($container) {
         return $container->registerAdminRouter($c);
     };
     $this->container['router'] = function ($c) use($container) {
         return $container->registerPublicRouter($c);
     };
     $this->container['list_table'] = $this->container->factory(function ($c) use($container) {
         return $container->registerListTable($c);
     });
     $this->container['ajax'] = $this->container->factory(function ($c) use($container) {
         return $container->registerAjax($c);
     });
     $this->container['post_type'] = $this->container->factory(function ($c) use($container) {
         return $container->registerPostType($c);
     });
     $this->container['request'] = $this->container->factory(function ($c) use($container) {
         return $container->registerRequest($c);
     });
 }
 public function register(Container $app)
 {
     $app['ramlToSilex.initializer'] = $app->protect(function () use($app) {
         if (!is_readable($ramlFile = $app['ramlToSilex.raml_file'])) {
             throw new \RuntimeException("API config file is not readable");
         }
         $configFile = json_decode(file_get_contents($app['ramlToSilex.config_file']));
         $app['ramlToSilex.apiDefinition'] = (new Parser())->parse($ramlFile, false);
         $app['ramlToSilex.routes'] = $app['ramlToSilex.apiDefinition']->getResourcesAsUri()->getRoutes();
         if (property_exists($configFile, 'routeAccess')) {
             $app['ramlToSilex.routeAccess'] = $configFile->routeAccess;
         }
         if (property_exists($configFile, 'controllers')) {
             $app['ramlToSilex.customControllerMapping'] = $configFile->controllers;
         }
         $app['ramlToSilex.restController'] = $app->factory(function () use($app) {
             return new RestController($app);
         });
         $app['ramlToSilex.routeBuilder'] = $app->factory(function () {
             return new RouteBuilder();
         });
     });
     $app['ramlToSilex.builder'] = function () use($app) {
         $app['ramlToSilex.initializer']();
         $controllers = $app['ramlToSilex.routeBuilder']->build($app, 'ramlToSilex.restController');
         $app['controllers']->mount('', $controllers);
     };
 }
 public function register(Container $app)
 {
     $app['di.container'] = function () use($app) {
         return new ContainerBuilder(new ParameterBag($app['di.parameters']));
     };
     $app['di.loader.yml'] = $app->factory(function (Container $app) {
         return new YamlFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.xml'] = $app->factory(function (Container $app) {
         return new XmlFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.ini'] = $app->factory(function (Container $app) {
         return new IniFileLoader($app['di.container'], new FileLocator());
     });
     $app['di.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app['di.container'], new FileLocator());
     });
     $app['di.resolver'] = function () use($app) {
         return new LoaderResolver([$app['di.loader.yml'], $app['di.loader.xml'], $app['di.loader.php'], $app['di.loader.ini'], $app['di.loader.directory']]);
     };
     $app['di.loader'] = function () use($app) {
         return new DelegatingLoader($app['di.resolver']);
     };
     $app['di.parameters'] = [];
 }
 private function addServiceToContainer(ServiceDefinition $definition)
 {
     $factory = $this->createFactory($definition);
     if (!$definition->isSingleton()) {
         $factory = $this->container->factory($factory);
     }
     $this->container[$definition->getName()] = $factory;
 }
Ejemplo n.º 7
0
 /**
  * Register providers
  *
  * @access public
  * @param  \Pimple\Container $container
  * @return \Pimple\Container
  */
 public function register(Container $container)
 {
     $container['commentEventJob'] = $container->factory(function ($c) {
         return new CommentEventJob($c);
     });
     $container['subtaskEventJob'] = $container->factory(function ($c) {
         return new SubtaskEventJob($c);
     });
     $container['taskEventJob'] = $container->factory(function ($c) {
         return new TaskEventJob($c);
     });
     $container['taskFileEventJob'] = $container->factory(function ($c) {
         return new TaskFileEventJob($c);
     });
     $container['taskLinkEventJob'] = $container->factory(function ($c) {
         return new TaskLinkEventJob($c);
     });
     $container['projectFileEventJob'] = $container->factory(function ($c) {
         return new ProjectFileEventJob($c);
     });
     $container['notificationJob'] = $container->factory(function ($c) {
         return new NotificationJob($c);
     });
     $container['projectMetricJob'] = $container->factory(function ($c) {
         return new ProjectMetricJob($c);
     });
     $container['userMentionJob'] = $container->factory(function ($c) {
         return new UserMentionJob($c);
     });
     return $container;
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app['uploader.controller_class'] = 'Pulsar\\Uploader\\Controller\\UploaderController';
     $app['uploader.options'] = [];
     $app['uploader.default_options'] = ['storage' => 'filesystem', 'route_prefix' => '', 'namer' => 'uniqid'];
     $app['uploader.storage.filesystem'] = $app->factory(function () {
         return new FilesystemStorage();
     });
     $app['uploader.namer.uniqid'] = $app->factory(function () {
         return new UniqidNamer();
     });
 }
Ejemplo n.º 9
0
 /**
  * @param string $key
  * @param mixed $val
  * @param string $type (optional)
  */
 static function set($key, $val, $type = null)
 {
     if (!static::$pimple) {
         throw new \LogicException('\\Pimple\\Container not set, call init() or setPimple() before using set().');
     }
     if ('factory' == $type) {
         static::$pimple[$key] = static::$pimple->factory($val);
     } elseif ('protect' == $type) {
         static::$pimple[$key] = static::$pimple->protect($val);
     } else {
         static::$pimple[$key] = $val;
     }
 }
 /**
  * @param Container $app
  */
 public function register(Container $app)
 {
     $app['config.initializer'] = $app->protect(function () use($app) {
         static $initialized = false;
         if ($initialized) {
             return;
         }
         $initialized = true;
         $filenames = (array) $app['config.filenames'];
         foreach ($filenames as $path) {
             $path = $app['config.replacements.resolver']($path);
             $app['config.loader']->load($path);
         }
     });
     $app['config.replacements.resolver'] = $app->protect(function ($value) use($app) {
         $replacements = $app['config.replacements'];
         if ([] === $replacements) {
             return $value;
         }
         if (is_array($value)) {
             return array_map(function ($value) use($app) {
                 return $app['config.replacements.resolver']($value);
             }, $value);
         }
         if (!is_string($value)) {
             return $value;
         }
         return $this->resolveString($value, $replacements);
     });
     $app['config.locator'] = function () {
         return new FileLocator();
     };
     $app['config.loader.yml'] = $app->factory(function (Container $app) {
         return new YamlFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app, $app['config.locator']);
     });
     $app['config.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app, $app['config.locator']);
     });
     $app['config.loader.resolver'] = function (Container $app) {
         return new LoaderResolver([$app['config.loader.yml'], $app['config.loader.directory'], $app['config.loader.php']]);
     };
     $app['config.loader'] = function (Container $app) {
         return new DelegatingLoader($app['config.loader.resolver']);
     };
     $app['config.filenames'] = [];
     $app['config.replacements'] = [];
 }
Ejemplo n.º 11
0
 /**
  * Register provider
  *
  * Register the PHP Template Loader as the tempalte loader to the DIC.
  *
  * @param \Pimple\Container $container DIC
  * @return void
  */
 public function register(Container $container)
 {
     if ($container["config.service"]["view.loader"] !== "Twig") {
         return;
     }
     $container["tplLoader.service"] = function (Container $container) {
         return new \SlaxWeb\ViewTwig\Loader\Twig($container["response.service"], $container["logger.service"](), $container["twig.service"]);
     };
     $container["twig.service"] = $container->factory(function (Container $cont) {
         return new \Twig_Environment($cont["twigFilesystemLoader.service"], ["cache" => $cont["config.service"]["twig.cacheDir"]]);
     });
     $container["twigFilesystemLoader.service"] = $container->factory(function (Container $cont) {
         return new \Twig_Loader_Filesystem($cont["config.service"]["twig.templateDir"]);
     });
 }
 /**
  * @param Container $container A pimple container instance.
  * @return void
  */
 public function register(Container $container)
 {
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\Email\EmailConfig
      */
     $container['email/config'] = function (Container $container) {
         $appConfig = $container['config'];
         $emailConfig = new EmailConfig($appConfig['email']);
         return $emailConfig;
     };
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\View\ViewInterface
      */
     $container['email/view'] = function (Container $container) {
         return $container['view'];
     };
     /**
      * @return \Charcoal\Factory\FactoryInterface
      */
     $container['email/factory'] = function (Container $container) {
         return new GenericFactory(['map' => ['email' => Email::class], 'base_class' => EmailInterface::class, 'default_class' => Email::class, 'arguments' => [['logger' => $container['logger'], 'config' => $container['email/config'], 'view' => $container['email/view'], 'template_factory' => $container['template/factory'], 'queue_item_factory' => $container['model/factory'], 'log_factory' => $container['model/factory']]]]);
     };
     /**
      * @param Container $container Pimple DI container.
      * @return \Charcoal\Email\EmailInterface
      */
     $container['email'] = $container->factory(function (Container $container) {
         return $container['email/factory']->create('email');
     });
 }
Ejemplo n.º 13
0
 /**
  * Settings section will be added once
  * any configuration is required.
  *
  * @inheritDoc
  */
 public function register(Container $container)
 {
     $container['security.encoder'] = function ($container) {
         return new MessageDigestPasswordEncoder();
     };
     $container['security.role_hierarchy'] = ['ROLE_SUPER_ADMIN' => array('ROLE_ADMIN', 'ROLE_USER')];
     $container['security.manager'] = function ($container) {
         return new SecurityManager($container);
     };
     $container['security.token_storage'] = function ($container) {
         return new TokenStorage();
     };
     $container['security.user_checker'] = function ($container) {
         return new UserChecker();
     };
     $container['member'] = $container->factory(function ($app) {
         if (null === ($token = $app['security.token_storage']->getToken())) {
             return null;
         }
         if (!is_object($user = $token->getUser())) {
             return null;
         }
         return $user;
     });
 }
Ejemplo n.º 14
0
 public function register(Container $app)
 {
     $app['mailer'] = function () {
         $mailer = new \PHPMailer();
         $mailer->CharSet = 'UTF-8';
         return $mailer;
     };
     $app['email'] = $app->factory(function ($c) {
         $mailConfig = $c['config']['mail'];
         $email = $c['mailer'];
         $email->From = $mailConfig['from'];
         if (is_array($mailConfig['to'])) {
             foreach ($mailConfig['to'] as $addr) {
                 $email->addAddress($addr);
             }
         } else {
             $email->addAddress($mailConfig['to']);
         }
         $email->isHTML(true);
         return $email;
     });
     $app['email:send'] = $app->protect(function ($subject, $body) use($app) {
         $email = $app['email'];
         if ($subject and $body) {
             $email->Subject = $subject;
             $email->Body = $body;
         }
         return $email->send();
     });
 }
Ejemplo n.º 15
0
 public function register(Container $container)
 {
     $cid = $this->cid;
     $container[$cid] = $container->factory(function () use($cid, $container) {
         $get = function ($key, $default = null) use($container, $cid) {
             $key = $cid . '.' . $key;
             return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
         };
         $adapterName = $get('adapter');
         switch ($adapterName) {
             case 'redis':
                 $adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]);
                 break;
             case 'file':
                 $adapter = new AdapterFile($get('dir'));
                 break;
             default:
                 $adapter = new AdapternotCache();
                 break;
         }
         foreach ($get('options', []) as $k => $v) {
             $adapter->setOption($k, $v);
         }
         return new Cache($adapter);
     });
 }
 public function register(Container $app)
 {
     $app['request_matcher_class'] = 'Silex\\Provider\\Routing\\RedirectableUrlMatcher';
     $app['routing.locator'] = function () {
         return new FileLocator();
     };
     $app['routing.loader.xml'] = $app->factory(function (Container $app) {
         return new XmlFileLoader($app['routing.locator']);
     });
     $app['routing.loader.php'] = $app->factory(function (Container $app) {
         return new PhpFileLoader($app['routing.locator']);
     });
     $app['routing.loader.yml'] = $app->factory(function (Container $app) {
         if (class_exists('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag')) {
             return new YamlFileLoader($app['routing.locator'], new ParameterBag($app['routing.replacements']));
         }
         return new YamlFileLoader($app['routing.locator']);
     });
     $app['routing.loader.directory'] = $app->factory(function (Container $app) {
         return new DirectoryLoader($app['routing.locator']);
     });
     $app['routing.loader.resolver'] = function (Container $app) {
         $loaders = [$app['routing.loader.xml'], $app['routing.loader.php'], $app['routing.loader.directory']];
         if (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
             $loaders[] = $app['routing.loader.yml'];
         }
         return new LoaderResolver($loaders);
     };
     $app['routing.loader'] = function (Container $app) {
         return new DelegatingLoader($app['routing.loader.resolver']);
     };
     $app['router'] = function (Container $app) {
         $options = ['debug' => $app['debug'], 'cache_dir' => $app['routing.cache_dir'], 'matcher_base_class' => $app['request_matcher_class'], 'matcher_class' => $app['request_matcher_class']];
         return new Router($app['routing.loader'], $app['routing.resource'], $options, $app['request_context'], $app['logger']);
     };
     $app['request_matcher'] = $app->extend('request_matcher', function ($matcher, $app) {
         $matchers = [$app['router'], $matcher];
         return new ChainUrlMatcher($matchers, $app['request_context']);
     });
     $app['url_generator'] = $app->extend('url_generator', function ($generator, $app) {
         $generators = [$app['router'], $generator];
         return new ChainUrlGenerator($generators, $app['request_context']);
     });
     $app['routing.resource'] = null;
     $app['routing.cache_dir'] = null;
     $app['routing.replacements'] = [];
 }
Ejemplo n.º 17
0
 /**
  * @param Container $c
  */
 public function addToContainer(Container $c)
 {
     $function = function ($c) {
         $svc = new PersonService($c);
         return $svc;
     };
     $c['service.person'] = $c->factory($function);
 }
Ejemplo n.º 18
0
 /**
  * @param Container $c
  */
 public function addToContainer(Container $c)
 {
     $function = function ($c) {
         $svc = new ExpensesService($c);
         return $svc;
     };
     $c['service.expenses'] = $c->factory($function);
 }
Ejemplo n.º 19
0
 public function register(Container $container)
 {
     foreach ($this->classes as $namespace => $classes) {
         foreach ($classes as $name) {
             $class = '\\' . $namespace . '\\' . $name;
             $container[lcfirst($name)] = function ($c) use($class) {
                 return new $class($c);
             };
         }
     }
     $container['paginator'] = $container->factory(function ($c) {
         return new Paginator($c);
     });
     $container['oauth'] = $container->factory(function ($c) {
         return new OAuth2($c);
     });
 }
Ejemplo n.º 20
0
 public function register(Container $app)
 {
     include_once APP . 'routes.php';
     $app->register(new InjectingControllerServiceProvider($this->app));
     $app->register(new ServiceControllerServiceProvider());
     $app[Request::class] = $app->factory(function () {
         return Request::createFromGlobals();
     });
     $app['request'] = $app->factory(function ($app) {
         return $app[Request::class];
     });
     $this->container->add(Request::class, function () use($app) {
         return $app[Request::class];
     });
     $app->register(new HttpCacheServiceProvider(), ['http_cache.cache_dir' => $app['config']['core.http_cache_dir']]);
     $app->register(new HttpFragmentServiceProvider());
     $app->register(new UrlGeneratorServiceProvider());
 }
Ejemplo n.º 21
0
 public function register(Container $app)
 {
     $app['bourinator'] = $app->factory(function () {
         return new Bourinator();
     });
     $app['stopwords'] = function () {
         return new StopWords();
     };
 }
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container $pimple An Container instance
  */
 public function register(Container $pimple)
 {
     $pimple['param'] = 'value';
     $pimple['service'] = function () {
         return new Service();
     };
     $pimple['factory'] = $pimple->factory(function () {
         return new Service();
     });
 }
Ejemplo n.º 23
0
 /**
  * The given closure is call the first time the given service is queried.
  * The closure has to return the instance for the given service.
  * Created instance will be cached in case $shared is true.
  *
  * @param string $name name of the service to register another backend for
  * @param \Closure $closure the closure to be called on service creation
  * @param bool $shared
  */
 function registerService($name, \Closure $closure, $shared = true)
 {
     if (!empty($this[$name])) {
         unset($this[$name]);
     }
     if ($shared) {
         $this[$name] = $closure;
     } else {
         $this[$name] = parent::factory($closure);
     }
 }
 /** {@inheritdoc} **/
 public function register(Container $app)
 {
     $app['route_class'] = CorsRoute::class;
     $app['cors'] = function ($app) {
         return new CorsService($app['routes']);
     };
     $controllers_factory = function () use($app, &$controllers_factory) {
         return new CorsControllerCollection($app['route_factory'], $app['routes_factory'], $controllers_factory);
     };
     $app['controllers_factory'] = $app->factory($controllers_factory);
 }
Ejemplo n.º 25
0
 public function register(Container $container)
 {
     $cid = $this->cid;
     $container[$cid] = $container->factory(function () use($cid, $container) {
         $get = function ($key, $default = null) use($container, $cid) {
             $key = $cid . '.' . $key;
             return $container->offsetExists($key) ? $container->offsetGet($key) : $default;
         };
         $pdo = new Database($get('dsn'), $get('user'), $get('password'), $get('options', []));
         return new Db($pdo);
     });
 }
 /**
  * Register the service provider.
  *
  * @param Container $app
  */
 public function register(Container $app)
 {
     $app['injector'] = $injector = $app->factory(function () {
         return $this->container->make(Reflector::class);
     });
     $this->container->add([Reflector::class, 'injector'], function () {
         return new Reflector($this->container, Request::createFromGlobals());
     });
     $app->extend('resolver', function ($resolver, $app) {
         return new InjectingControllerResolver($this->container, $app['injector'], $resolver, $app['callback_resolver']);
     });
 }
 public function register(Application $app)
 {
     if (!$app['resolver'] instanceof ServiceControllerResolver) {
         throw new \RuntimeException('Register ServiceControllerServiceProvider first.');
     }
     foreach (array('cget', 'post', 'get', 'put', 'patch', 'delete') as $method) {
         $app['rest.methods.' . $method] = $method;
     }
     $app['rest'] = $app->factory(function ($app) {
         return new RestService($app);
     });
 }
Ejemplo n.º 28
0
 public function register(Container $app)
 {
     $app['route_class'] = 'Silex\\Route';
     $app['route_factory'] = $app->factory(function ($app) {
         return new $app['route_class']();
     });
     $app['routes_factory'] = $app->factory(function () {
         return new RouteCollection();
     });
     $app['routes'] = function ($app) {
         return $app['routes_factory'];
     };
     $app['url_generator'] = function ($app) {
         return new UrlGenerator($app['routes'], $app['request_context']);
     };
     $app['request_matcher'] = function ($app) {
         return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
     };
     $app['request_context'] = function ($app) {
         $context = new RequestContext();
         $context->setHttpPort(isset($app['request.http_port']) ? $app['request.http_port'] : 80);
         $context->setHttpsPort(isset($app['request.https_port']) ? $app['request.https_port'] : 443);
         return $context;
     };
     $app['controllers'] = function ($app) {
         return $app['controllers_factory'];
     };
     $app['controllers_factory'] = $app->factory(function ($app) {
         return new ControllerCollection($app['route_factory'], $app['routes_factory']);
     });
     $app['routing.listener'] = function ($app) {
         $urlMatcher = new LazyRequestMatcher(function () use($app) {
             return $app['request_matcher'];
         });
         if (Kernel::VERSION_ID >= 20800) {
             return new RouterListener($urlMatcher, $app['request_stack'], $app['request_context'], $app['logger']);
         }
         return new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']);
     };
 }
Ejemplo n.º 29
0
 /**
  * Register the service provider.
  *
  * @param Container $app
  */
 public function register(Container $app)
 {
     $this->registerFactories();
     $app['db'] = function () {
         return $this->container['db'];
     };
     $app['db.connection'] = $app->factory(function () {
         return $this->container['db.connection'];
     });
     $app['db.factory'] = function () {
         return $this->container['db.factory'];
     };
 }
 public function init()
 {
     $container = new Container();
     $closure = function ($c) {
         return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory();
     };
     $prototype = $container->factory(function ($c) {
         return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory();
     });
     $container['bicycle_factory'] = $closure;
     $container['bicycle_factory_prototype'] = $prototype;
     $this->container = $container;
 }