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();
 }
 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);
     };
 }
Example #3
0
 /**
  * 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 A container instance
  */
 public function register(Container $pimple)
 {
     $config = $this->configuration;
     $pimple['translator'] = function ($c) use($config) {
         $translator = new Translator($config);
         return $translator;
     };
     /*
      * Translate függvény és a getLocale függvény biztosítása a twighez
      */
     $pimple->extend('twig', function ($twig, $c) {
         /** @var Twig $mytwig */
         $mytwig = $twig;
         /** @var Translator $translator */
         $translator = $c["translator"];
         // Translate függvény biztosítása
         $translate = new \Twig_SimpleFunction('translate', function ($message, $params = [], $domain = null, $locale = null) use($translator) {
             return $translator->trans($message, $params, $domain, $locale);
         });
         $mytwig->getTwigEnvironment()->addFunction($translate);
         // Aktuális locale biztosítása
         $get_locale = new \Twig_SimpleFunction('get_locale', function () use($translator) {
             return $translator->getLocale();
         });
         $mytwig->getTwigEnvironment()->addFunction($get_locale);
         // Aktuális locale-ok biztosítása
         $get_locales = new \Twig_SimpleFunction('get_locales', function () use($translator) {
             return $translator->getFallbackLocales();
         });
         $mytwig->getTwigEnvironment()->addFunction($get_locales);
         return $mytwig;
     });
 }
 public function register(Container $app)
 {
     $app['menu_manager'] = function ($app) {
         return new MenuManager($app, $app['menu']);
     };
     $app['menu_manager.security'] = function ($app) {
         return new MenuSecurityService($app);
     };
     $app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($filesystem, $app) {
         $filesystem->addPath(__DIR__ . '/../Resource/views', 'MenuManager');
         return $filesystem;
     });
     $app['twig'] = $app->extend('twig', function ($twig, $app) {
         $twig->addFunction(new \Twig_SimpleFunction('menu', function ($which = 'main', Item $item = null, $paramList = [], $activeOnly = false) use($app) {
             return $app['menu_manager']->render($which, $item, $paramList, $activeOnly);
         }));
         $twig->addFunction(new \Twig_SimpleFunction('breadcrumb', function ($paramList = []) use($app) {
             return $app['menu_manager']->renderBreadcrumb($paramList);
         }));
         return $twig;
     });
     // Current route name
     $app->before(function (Request $request) use($app) {
         $app['menu_manager']->setCurrentRoute($request->get('_route'));
     });
 }
 public function register(Container $pimple)
 {
     $pimple['Auth'] = function ($pimple) {
         $auth = new Auth($pimple->config('accessKey'), $pimple->config('secretKey'));
         return $auth;
     };
 }
 public function it_resolve_commands(Container $container, $command1, $command2)
 {
     $container->keys()->willReturn(['test1.command', 'test2.command']);
     $container->offsetGet('test1.command')->willReturn($command1);
     $container->offsetGet('test2.command')->willReturn($command2);
     $this->commands()->shouldReturn([$command1, $command2]);
 }
Example #7
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * set context inside container
      */
     $this->container->register(new LoggerProvider($output));
     try {
         /** @var LoggerInterface $logger */
         $logger = $this->container['logger'];
         $connection = ['host' => $input->getArgument('host'), 'port' => $input->getArgument('port'), 'user' => $input->getArgument('username'), 'password' => $input->getArgument('password')];
         $client = $this->container['curl_client_factory']->createClient($connection);
         $queueManager = $this->container['manager_rabbitmq_queue'];
         $exchangeManager = $this->container['manager_rabbitmq_exchange'];
         $policygeManager = $this->container['manager_rabbitmq_policy'];
         $manager = new DeleteManager($exchangeManager, $queueManager, $policygeManager, $logger);
         if ($input->hasOption('queues') && null !== $input->getOption('queues')) {
             $queueManager->setClient($client);
             $manager->deleteQueues($input->getOption('vhost'), $input->getOption('queues'));
         }
         if ($input->hasOption('exchanges') && null !== $input->getOption('exchanges')) {
             $exchangeManager->setClient($client);
             $manager->deleteExchanges($input->getOption('vhost'), $input->getOption('exchanges'));
         }
         if ($input->hasOption('policies') && null !== $input->getOption('policies')) {
             $policygeManager->setClient($client);
             $manager->deletePolicies($input->getOption('vhost'), $input->getOption('policies'));
         }
     } catch (\Exception $e) {
         $logger->critical($e->getMessage());
         return 1;
     }
     return 0;
 }
Example #8
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);
     });
     return $container;
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app['paginator.default_options'] = ['page_name' => 'page', 'page_range' => 5, 'sort_field_name' => 'sort', 'sort_direction_name' => 'direction', 'filter_field_name' => 'filterField', 'filter_value_name' => 'filterValue', 'distinct' => true, 'template' => ['pagination' => 'sliding.html.twig', 'sortable' => 'sortable_link.html.twig', 'filtration' => 'filtration.html.twig']];
     $app['paginator.helper.processor'] = function ($app) {
         return new Processor($app['url_generator'], $app['translator']);
     };
     $app['paginator'] = function ($app) {
         $reflClass = new \ReflectionClass('Knp\\Bundle\\PaginatorBundle\\KnpPaginatorBundle');
         $path = sprintf('%s/Resources/views/Pagination', dirname($reflClass->getFileName()));
         $app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($path));
         $paginator = new Paginator($app['dispatcher']);
         $paginator->setDefaultPaginatorOptions(['pageParameterName' => $app['paginator.default_options']['page_name'], 'sortFieldParameterName' => $app['paginator.default_options']['sort_field_name'], 'sortDirectionParameterName' => $app['paginator.default_options']['sort_direction_name'], 'filterFieldParameterName' => $app['paginator.default_options']['filter_field_name'], 'filterValueParameterName' => $app['paginator.default_options']['filter_value_name'], 'distinct' => $app['paginator.default_options']['distinct']]);
         return $paginator;
     };
     $app['paginator.subscriber.paginate'] = function () {
         return new PaginationSubscriber();
     };
     $app['paginator.subscriber.sortable'] = function () {
         return new SortableSubscriber();
     };
     $app['paginator.subscriber.filtration'] = function () {
         return new FiltrationSubscriber();
     };
     $app['paginator.subscriber.sliding_pagination'] = function ($app) {
         $templateOptions = $app['paginator.default_options']['template'];
         $options = ['defaultPaginationTemplate' => $templateOptions['pagination'], 'defaultSortableTemplate' => $templateOptions['sortable'], 'defaultFiltrationTemplate' => $templateOptions['filtration'], 'defaultPageRange' => $app['paginator.default_options']['page_range']];
         return new SlidingPaginationSubscriber($options);
     };
     $app->extend('twig', function (\Twig_Environment $twig, $app) {
         $twig->addExtension(new PaginationExtension($app['paginator.helper.processor']));
         return $twig;
     });
 }
Example #10
0
 public function register(Container $app)
 {
     $app['restapi.storage'] = function () use($app) {
         return new HashedStorage($app['restapi']['storage_path']);
     };
     $app['restapi.service'] = function () use($app) {
         $api = new RestApi($app['db'], $app['restapi']['schema_cache']);
         $api->setStorage($app['restapi.storage']);
         $api->setDebug($app['debug']);
         return $api;
     };
     if (isset($app['restapi']['auth'])) {
         $app['restapi.auth'] = function () use($app) {
             $auth = new AuthService($app['restapi']['auth']['users']);
             $auth->setTokenOptions($app['restapi']['auth']['token']);
             $auth->setCookieOptions($app['restapi']['auth']['cookie']);
             return $auth;
         };
         $app['restapi.listener.auth_checker'] = $app->protect(function (Request $request) use($app) {
             if (!($user = $app['restapi.auth']->getAuthenticatedUserFromRequest($request))) {
                 return new Response(null, 401, ['Content-Type' => 'application/json']);
             }
             $app['restapi.service']->setUser($user);
         });
     }
     if (isset($app['restapi']['cors'])) {
         $app['restapi.middleware.cors'] = function () use($app) {
             return new CorsMiddleware($app['restapi']['cors']);
         };
     }
 }
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param  Container $container The Pimple DI container.
  * @return void
  */
 public function register(Container $container)
 {
     /**
      * @param  Container $container The Pimple DI Container.
      * @return ConfigInterface
      */
     $container['admin/config'] = function (Container $container) {
         $appConfig = $container['config'];
         return new AdminConfig($appConfig['admin']);
     };
     $container->extend('admin/config', function (ConfigInterface $adminConfig, Container $container) {
         $adminConfig['elfinder'] = new Config($adminConfig['elfinder']);
         return $adminConfig;
     });
     /**
      * @param  Container $container The Pimple DI Container.
      * @return ConfigInterface
      */
     $container['elfinder/config'] = function (Container $container) {
         return $container['admin/config']['elfinder'];
     };
     $this->registerAuthenticator($container);
     $this->registerAuthorizer($container);
     $this->registerUtilities($container);
     // Register Access-Control-List (acl)
     $container->register(new AclServiceProvider());
 }
 public function testDump()
 {
     $container = new Container();
     $container['debug'] = false;
     $container['charset'] = 'utf-8';
     $logger = $this->getLogger();
     $container['logger'] = $logger;
     $container->register(new TwigServiceProvider());
     $twigPath = $this->getTwigPath();
     $container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) use($twigPath) {
         $twigLoaderFilesystem->addPath($twigPath, 'SaxulumAsseticTwig');
         return $twigLoaderFilesystem;
     });
     $container->register(new AsseticTwigProvider(), array('assetic.asset.root' => $this->getFixturesPath(), 'assetic.asset.asset_root' => $this->getAssetPath()));
     /** @var Dumper $dumper */
     $dumper = $container['assetic.asset.dumper'];
     $dumper->dump();
     if (count($logger->entries)) {
         var_dump($logger->entries);
     }
     $this->assertCount(0, $logger->entries);
     $this->fileComparsion('css/test-copyfile.css');
     $this->fileComparsion('image/test.png');
     $this->fileComparsion('css/test-less.css');
     $this->fileComparsion('css/test-scss.css');
     $this->fileComparsion('css/test-cssmin.css');
     $this->fileComparsion('css/test-csscompress.css');
     $this->fileComparsion('js/test.js');
 }
Example #13
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 test()
 {
     $container = new Container();
     $container->register(new HttpClientProvider());
     $this->assertInstanceOf('Metfan\\RabbitSetup\\Factory\\CurlClientFactory', $container['curl_client_factory']);
     $this->assertInstanceOf('Metfan\\RabbitSetup\\Http\\ClientPool', $container['http_client_pool']);
 }
 public function register(Container $container)
 {
     $container['simpleform.config.path'] = '';
     $container['simpleform.config.cache_path'] = '';
     $container['simpleform.config.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Config';
     $container['simpleform.forms.class'] = 'PhpGo\\SimpleAdminBundle\\Form\\Forms';
     $container['simpleform.custom_fields'] = [];
     $container['form.types'] = function () {
         return [new StringType()];
     };
     $container['simpleform.config'] = function (Container $container) {
         //            $coreFieldsNamespace = 'PhpGo\\SimpleAdminBundle\\Form\\Field\\';
         $coreFields = ['PhpGo\\SimpleAdminBundle\\Form\\Field\\StringField'];
         Forms::registerFields($coreFields);
         Forms::registerFields($container['simpleform.custom_fields']);
         $container->extend('form.types', function ($types, $container) {
             /** @var FieldAbstract $field */
             foreach ($container['simpleform.custom_fields'] as $field) {
                 if ($type = $field::getType()) {
                     $types[] = $type;
                 }
             }
             return $types;
         });
         $config = $container['simpleform.config.class']::createFromYaml($container['simpleform.config.path']);
         return $config;
     };
     $container['forms'] = function ($container) {
         /** @var Forms $forms */
         $forms = new $container['simpleform.forms.class']($container['simpleform.config'], $container['form.factory']);
         return $forms;
     };
 }
 public function register(Container $app)
 {
     $app['router.options'] = [];
     $app['router.loader_resolver'] = function () {
         $fileLocator = new FileLocator();
         $loaderResolver = new LoaderResolver([new XmlFileLoader($fileLocator), new PhpFileLoader($fileLocator), new ClosureLoader()]);
         if (class_exists('Symfony\\Component\\Yaml\\Parser')) {
             $loaderResolver->addLoader(new YamlFileLoader($fileLocator));
         }
         return $loaderResolver;
     };
     $app['router'] = function (Application $app) {
         $router = new Router(new ClosureLoader(), function () use($app) {
             if (isset($app['router.resource'])) {
                 $userLoader = new DelegatingLoader($app['router.loader_resolver']);
                 $userRoutes = $userLoader->load($app['router.resource']);
                 $app['routes']->addCollection($userRoutes);
             }
             $app->flush();
             return $app['routes'];
         }, $app['router.options'] + ['debug' => isset($app['debug']) ? $app['debug'] : false, 'matcher_base_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher', 'matcher_class' => 'Silex\\Provider\\Routing\\RedirectableUrlMatcher'], $app['request_context'], $app['logger']);
         return $router;
     };
     $app['request_matcher'] = function (Application $app) {
         return $app['router'];
     };
     $app['url_generator'] = function (Application $app) {
         return $app['router'];
     };
 }
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  */
 public function register(Container $app)
 {
     $app['security.jwt_retrieval.authorization_bearer.strategy'] = function () {
         return new AuthorizationBearerStrategy();
     };
     $app['security.jwt_retrieval.query_parameter.strategy'] = function () {
         return new QueryParameterStrategy();
     };
     $app['security.jwt_retrieval.chain.strategy'] = function () use($app) {
         return new ChainStrategy([$app['security.jwt_retrieval.authorization_bearer.strategy'], $app['security.jwt_retrieval.query_parameter.strategy']]);
     };
     $app['security.entry_point.jwt._proto'] = $app->protect(function () use($app) {
         return function () {
             return new JWTAuthenticationEntryPoint();
         };
     });
     $app['security.authentication_listener.factory.jwt'] = $app->protect(function ($name, $options) use($app) {
         $app['security.authentication_provider.' . $name . '.jwt'] = function () use($app, $options) {
             $encoder = new JWTEncoder($options['secret_key'], reset($options['allowed_algorithms']));
             $decoder = new JWTDecoder($options['secret_key'], $options['allowed_algorithms']);
             $converter = new SecurityUserConverter();
             $userBuilder = new JWTUserBuilder($decoder, $encoder, $converter);
             return new JWTAuthenticationProvider($userBuilder);
         };
         $app['security.authentication_listener.' . $name . '.jwt'] = function () use($app, $name, $options) {
             $strategyName = isset($options['retrieval_strategy']) ? $options['retrieval_strategy'] : 'authorization_bearer';
             return new JWTListener($app['security.token_storage'], $app['security.authentication_manager'], $app['security.jwt_retrieval.' . $strategyName . '.strategy']);
         };
         $app['security.entry_point.' . $name . '.jwt'] = $app['security.entry_point.jwt._proto']($name, $options);
         return array('security.authentication_provider.' . $name . '.jwt', 'security.authentication_listener.' . $name . '.jwt', 'security.entry_point.' . $name . '.jwt', 'pre_auth');
     });
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     // Load defaults
     foreach ($this->settings as $key => $value) {
         $key = 'captcha.' . $key;
         if (!isset($app[$key])) {
             $app[$key] = $value;
         }
     }
     // Instance of builder
     $app['captcha.builder'] = function (Application $app) {
         return new CaptchaBuilder($app['captcha.phrase'], $app['captcha.phrase_builder']);
     };
     // Checks captcha
     $app['captcha.test'] = $app->protect(function ($phrase) use($app) {
         /** @var $builder CaptchaBuilder */
         $builder = $app['captcha.builder'];
         /** @var $session Session */
         $session = $app['session'];
         $builder->setPhrase($session->get($app['captcha.session_key']));
         return $builder->testPhrase($phrase);
     });
     // Returns absolute URL to the image
     $app['captcha.image_url'] = $app->protect(function () use($app) {
         /** @var $urlGenerator UrlGenerator */
         $urlGenerator = $app['url_generator'];
         return $urlGenerator->generate($app['captcha.route_name'], array(), UrlGenerator::ABSOLUTE_URL);
     });
 }
 /**
  * @param Container|Application $app
  */
 public function register(Container $app)
 {
     ini_set('log_errors', 1);
     strtoupper(env('APP_ENV')) === 'PRODUCTION' ? ini_set('display_errors', 0) : ini_set('display_errors', 1);
     $app['debug'] = env('DEBUG');
     !$app['debug'] ?: ($app['dump'] = $app->protect(function ($var) {
         return (new VarDumper())::dump($var);
     }));
     /** Register the app error factory */
     $app->error(function (\Exception $e) use($app) {
         // handle HTTP exceptions
         if (get_class($e) === NotFoundHttpException::class) {
             /** @var NotFoundHttpException $e */
             /** @noinspection DegradedSwitchInspection */
             switch ($e->getStatusCode()) {
                 case 404:
                     return response(view('404.html', ['error' => '404 - Page Not Found.']), 404);
                     break;
                 default:
                     $message = 'We are sorry, but something went terribly wrong.';
             }
             return new Response($message);
         }
         // not an HTTP exception
         throw $e;
     });
     if ($app['debug']) {
         error_reporting(E_ALL);
         ini_set('display_errors', 1);
         # core debug utilities
         # note that debug requires that the environment has been loaded
         include_once BOOT . 'assets/debug.php';
     }
 }
 /**
  * @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']);
         });
     }
 }
 /**
  * @param Container $pimple
  */
 public function register(Container $pimple)
 {
     // Default extractor, inflector and middleware setup
     $pimple['tactician.extractor'] = new ClassNameExtractor();
     $pimple['tactician.inflector'] = new HandleInflector();
     $pimple['tactician.middleware'] = [new LockingMiddleware()];
     // Set (default tactician) locator only when not already set before
     if (!$pimple->offsetExists('tactician.locator')) {
         $pimple['tactician.locator'] = function () {
             return new InMemoryLocator();
         };
     }
     // Setup command bus
     $pimple['tactician.command_bus'] = function () use($pimple) {
         if (is_string($pimple['tactician.extractor'])) {
             $pimple['tactician.extractor'] = new $pimple['tactician.extractor']();
         }
         if (is_string($pimple['tactician.inflector'])) {
             $pimple['tactician.inflector'] = new $pimple['tactician.inflector']();
         }
         // Add handler middleware to existing set of middleware
         $middleware = $pimple['tactician.middleware'];
         $middleware[] = new CommandHandlerMiddleware($pimple['tactician.extractor'], $pimple['tactician.locator'], $pimple['tactician.inflector']);
         return new CommandBus($middleware);
     };
 }
 public function testCreateTemplating()
 {
     $pimple = new Container(['debug' => false, 'charset' => '']);
     $pimple->register(new TwigEngineServiceProvider());
     $pimple->register(new TwigServiceProvider());
     $this->assertInstanceOf(TwigEngine::class, $pimple['templating']);
 }
 public function register(Container $c)
 {
     // TODO dar opção de mudar o loader, não só annotations
     $c['extra.options'] = array('root_dir' => null, 'controller_namespace' => null, 'cache_dir' => sys_get_temp_dir());
     $c['extra.route_loader'] = function ($c) {
         return new AnnotationDirectoryLoader(new FileLocator($c['extra.options']['root_dir']), new AnnotatedRouteControllerLoader($c['annotation.reader']));
     };
     $c['extra.router'] = function ($c) {
         $router = new Router($c['routes'], $c['extra.route_loader'], $c['extra.options']['controller_namespace'], array('cache_dir' => $c['extra.options']['cache_dir'], 'debug' => $c['debug'], 'generator_dumper_class' => 'Symfony\\Component\\Routing\\Generator\\Dumper\\PhpGeneratorDumper', 'generator_cache_class' => 'BrodaUrlGenerator', 'matcher_dumper_class' => 'Symfony\\Component\\Routing\\Matcher\\Dumper\\PhpMatcherDumper', 'matcher_cache_class' => 'BrodaRequestMatcher', 'resource_type' => 'annotation'), $c['routing.request_context']);
         return $router;
     };
     $c->extend('routing.url_generator', function ($generator, $c) {
         /* @var $router Router */
         $router = $c['extra.router'];
         $router->setOption('generator_class', get_class($generator));
         $router->setOption('generator_base_class', get_class($generator));
         return $router;
     });
     $c->extend('routing.request_matcher', function ($matcher, $c) {
         /* @var $router Router */
         $router = $c['extra.router'];
         $router->setOption('matcher_class', get_class($matcher));
         $router->setOption('matcher_base_class', get_class($matcher));
         return $router;
     });
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     if (!isset($app['console'])) {
         throw new \LogicException('You must register the ConsoleServiceProvider to use the DoctrineConsoleServiceProvider.');
     }
     if (!isset($app['orm'])) {
         throw new \LogicException('You must register the DoctrineOrmServiceProvider to use the DoctrineConsoleServiceProvider.');
     }
     $app['console'] = $app->extend('console', function (ConsoleApplication $console) use($app) {
         $helper = $console->getHelperSet();
         $helper->set(new ConnectionHelper($app['db']), 'db');
         $helper->set(new EntityManagerHelper($app['orm']), 'em');
         $console->add(new ImportCommand());
         $console->add(new ReservedWordsCommand());
         $console->add(new RunSqlCommand());
         $console->add(new MetadataCommand());
         $console->add(new ResultCommand());
         $console->add(new QueryCommand());
         $console->add(new CreateCommand());
         $console->add(new UpdateCommand());
         $console->add(new DropCommand());
         $console->add(new EnsureProductionSettingsCommand());
         $console->add(new ConvertDoctrine1SchemaCommand());
         $console->add(new GenerateRepositoriesCommand());
         $console->add(new GenerateEntitiesCommand());
         $console->add(new GenerateProxiesCommand());
         $console->add(new ConvertMappingCommand());
         $console->add(new RunDqlCommand());
         $console->add(new ValidateSchemaCommand());
         $console->add(new InfoCommand());
         $console->add(new MappingDescribeCommand());
         return $console;
     });
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app->extend('form.types', function (array $types, $app) {
         $types[] = new EntityHiddenType($app['doctrine']);
         return $types;
     });
 }
 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();
     });
 }
Example #27
0
 public function configure(Container $pimple, $resource)
 {
     $parameters = $this->loader->load($resource);
     foreach ($parameters as $k => $v) {
         $pimple->offsetSet($k, $v);
     }
 }
 /**
  * @param Container $container A Pimple DI container.
  * @return void
  */
 public function register(Container $container)
 {
     $container->register(new DashboardServiceProvider());
     $container->register(new FormServiceProvider());
     $container->register(new LayoutServiceProvider());
     $container->register(new MenuServiceProvider());
 }
Example #29
0
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     $app['puli.factory'] = function () {
         $factoryClass = PULI_FACTORY_CLASS;
         return new $factoryClass();
     };
     $app['puli.repository'] = function ($app) {
         return $app['puli.factory']->createRepository();
     };
     $app['puli.discovery'] = function ($app) {
         return $app['puli.factory']->createDiscovery();
     };
     $app['puli.url_generator'] = function ($app) {
         return $app['puli.factory']->createUrlGenerator($app['puli.discovery']);
     };
     if (isset($app['twig'])) {
         if (interface_exists('Puli\\UrlGenerator\\Api\\UrlGenerator')) {
             $app->extend('twig', function ($twig, $app) {
                 $twig->addExtension(new PuliExtension($app['puli.repository'], $app['puli.url_generator']));
                 return $twig;
             });
         }
         $app->extend('twig.loader', function ($loader, $app) {
             $loader->addLoader(new PuliTemplateLoader($app['puli.repository']));
             return $loader;
         });
     }
 }
 /**
  * @param Container $container
  */
 public function register(Container $container)
 {
     if (!$container instanceof Application) {
         throw new \InvalidArgumentException("invalid application");
     }
     /**
      * pimple aware event dispatcher
      */
     $container->register(new PimpleAwareEventDispatcherServiceProvider());
     /**
      * alias for auto injection
      */
     $container[PimpleAwareEventDispatcher::class] = function () use($container) {
         return $container["dispatcher"];
     };
     /**
      * register default event subscriber
      */
     $container->registerSubscriber(ExceptionHandler::class, function () use($container) {
         return new ExceptionHandler($container["config"], $container["monolog"]);
     });
     $container->registerSubscriber(CliExceptionHandler::class, function () use($container) {
         return new CliExceptionHandler($container["config"], $container["monolog"]);
     });
 }