Example #1
0
 public function testInstansiation()
 {
     $service = new Service();
     $service->register($this->continer, new Config('sampleLoggerName'));
     $loggerService = $this->continer->get(Config::getServiceName());
     $this->assertEquals('sampleLoggerName', $loggerService->getName());
 }
Example #2
0
 public function testInstansiation()
 {
     $service = new Service();
     $service->register($this->container, $this->hateoasConfig);
     $hateoasService = $this->container->get(Config::getServiceName());
     $this->assertInstanceOf('\\Hateoas\\Hateoas', $hateoasService);
 }
 public function testContainerHasInstantiatedAMailProviderInterface()
 {
     $mailServiceProvider = new MailServiceProvider();
     $mailServiceProvider->setContainer($this->container);
     $mailServiceProvider->register();
     $this->assertInstanceOf('JGimeno\\TaskReporter\\Domain\\Service\\MailProviderInterface', $this->container->get('JGimeno\\TaskReporter\\Domain\\Service\\MailProviderInterface'));
 }
Example #4
0
 /**
  * Execute a request
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function execute(Request $request = null)
 {
     $this->request = $request ?: $this->getRequest();
     $router = $this->container->get(RouteCollection::class);
     $response = $router->getDispatcher()->dispatch($this->request->getMethod(), $this->request->getPathInfo());
     $response->send();
 }
Example #5
0
 /**
  * This is for the pthreads compatibility - for some reason the DB just goes t**s up when using pthreads
  * and PDO.. Hence the __wakeup() call, that restarts the database.
  * No numbers on it, but it more than likely adds quite a bit of latency.
  */
 public function __wakeup()
 {
     $this->container = getContainer();
     $this->log = $this->container->get('log');
     $this->config = $this->container->get('config');
     $this->pdo = $this->connect();
 }
Example #6
0
 public function resolve($handler)
 {
     if (is_array($handler) and is_string($handler[0])) {
         $this->container->share($handler[0])->withArguments([$this->container]);
         $handler[0] = $this->container->get($handler[0]);
     }
     return $handler;
 }
 /** @inheritDoc */
 public function execute(CommandInterface $command)
 {
     $className = get_class($command);
     if (array_key_exists($className, $this->commandNameToHandlerMap) === false) {
         throw new CommandNotFoundException($className);
     }
     $handler = $this->container->get($this->commandNameToHandlerMap[$className]);
     return $handler->execute($command);
 }
Example #8
0
 protected function prepareRequest(Request $request)
 {
     $session = $this->container->get(Session::class);
     $request->setSession($session);
     if ($request->getContentType() == 'json') {
         if ($data = json_decode($request->getContent(), true)) {
             $request->request->replace($data);
         }
     }
     $this->container->add(Request::class, $request);
 }
 /**
  * @param Container $container
  * @param Request|null $request
  */
 public function __construct(Container $container, Request $request = null)
 {
     $this->container = $container;
     $this->logger = $container->get('logger');
     $this->view = new View($this->container);
     $this->config = $container->get('config');
     if ($request === null) {
         $this->request = new Request();
     } else {
         $this->request = $request;
     }
 }
Example #10
0
 /**
  * Sends response.
  */
 public function run()
 {
     /** @var RouteCollection $route */
     $route = $this->container->get(RouteCollection::class);
     /** @var ServerRequestInterface $request */
     $request = $this->container->get(ServerRequestInterface::class);
     /** @var ResponseInterface $response */
     $response = $this->container->get(ResponseInterface::class);
     /** @var EmitterInterface $emitter */
     $emitter = $this->container->get(EmitterInterface::class);
     $response = $route->dispatch($request, $response);
     $emitter->emit($response);
 }
 public function testProvider()
 {
     $container = new Container();
     $container->add('config', ['flysystem' => ['file' => ['League\\Flysystem\\Adapter\\Local', [__DIR__]], 'null' => ['League\\Flysystem\\Adapter\\NullAdapter']]]);
     $container->addServiceProvider(new FlysystemProvider());
     $default = $container->get('League\\Flysystem\\FilesystemInterface');
     $manager = $container->get('League\\Flysystem\\MountManager');
     $byName = $container->get('flysystem.adapter.null');
     $this->assertTrue($default instanceof FilesystemInterface);
     $this->assertTrue($manager instanceof MountManager);
     $this->assertTrue($byName instanceof NullAdapter);
     $this->assertTrue($manager->getAdapter('file://') instanceof Local);
     $this->assertTrue($manager->getAdapter('null://') instanceof NullAdapter);
 }
Example #12
0
 public function testProvider()
 {
     $container = new Container();
     $container->add('config', ['connections' => [['name' => 'default', 'dsn' => 'mysql://root:@localhost/nodb'], ['name' => 'mysql2', 'dsn' => 'mysql://root:@localhost/nodb2']]]);
     $container->addServiceProvider(new SpotProvider());
     $config = $container->get('Spot\\Config');
     $locator = $container->get('Spot\\Locator');
     $config2 = $container->get('spot.config.default');
     $locator2 = $container->get('spot.locator.default');
     $this->assertTrue($locator instanceof \Spot\Locator);
     $this->assertTrue($locator2 instanceof \Spot\Locator);
     $this->assertTrue($config instanceof \Spot\Config);
     $this->assertTrue($config2 instanceof \Spot\Config);
 }
Example #13
0
 public function testProvider()
 {
     $container = new Container();
     $container->addServiceProvider(new MailerProvider());
     $container['config.mailer'] = ['server' => 'Laasti\\Mailer\\Servers\\NullServer'];
     $container->get('Laasti\\Mailer\\Mailer');
 }
 /**
  * {@inheritdoc}
  */
 public function resolve($handler)
 {
     // Only attempt to resolve uninstantiated objects.
     if (is_array($handler) && is_string($handler[0])) {
         // Retrieve the route handler class from the dependency injection
         // container. This ensures that the instantiated handler class
         // receives all of the correct dependencies.
         $handler_object = $this->container->get($handler[0]);
         // Manually set the response and request dependencies.
         $handler_object->setRequest($this->container->get('Symfony\\Component\\HttpFoundation\\Request'));
         $handler_object->setResponse($this->container->get('Symfony\\Component\\HttpFoundation\\Response'));
         // Pass the object back.
         $handler[0] = $handler_object;
     }
     return $handler;
 }
Example #15
0
 /**
  * @param string $alias
  * @param array  $args
  *
  * @return mixed|object
  */
 public function get($alias, array $args = [])
 {
     if (!$this->hasShared($alias) && array_key_exists($alias, $this->interopDefinitions)) {
         $this->shared[$alias] = $this->resolve($alias, $this->interopDefinitions[$alias]);
     }
     return parent::get($alias, $args);
 }
 public function testProvider()
 {
     $container = new Container();
     $container->add('config.session', ['storage_class' => 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage', 'storage_args' => ['SESSMOCK_LAASTI']]);
     $container->addServiceProvider(new SymfonySessionProvider());
     $session = $container->get('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface');
     $this->assertTrue(\PHPUnit_Framework_Assert::readAttribute($session, 'storage') instanceof MockArraySessionStorage);
 }
 /**
  * Gets the default commands that should always be available.
  *
  * @return array An array of default Command instances
  */
 protected function getDefaultCommands()
 {
     // Keep the core default commands to have the HelpCommand
     // which is used when using the --help option
     $defaultCommands = parent::getDefaultCommands();
     $container = new Container();
     $defaultCommands[] = $container->get('Gradcracker\\Console\\Command\\MySQLDumperCommand');
     return $defaultCommands;
 }
 public function testProvider()
 {
     $container = new Container();
     $container->add('config.gregwarImage', ['cache_dir' => __DIR__ . '/cache']);
     $container->addServiceProvider(new GregwarImageProvider());
     $image = $container->get('Gregwar\\Image\\Image');
     $cache = \PHPUnit_Framework_Assert::readAttribute($image, 'cache');
     $this->assertTrue(\PHPUnit_Framework_Assert::readAttribute($cache, 'cacheDirectory') === __DIR__ . '/cache');
 }
Example #19
0
 public function register(Container $app)
 {
     $app->share('view', function () use($app) {
         $config = $app->get('config');
         $supportView = new ViewSupport($app);
         $view = new View($config->get("environment.host"), $supportView);
         return $view;
     });
 }
 public function testProvidesSlugifyUsingSharedProvider()
 {
     $container = new Container();
     $ruleProvider = $this->getRuleProviderMock();
     $container->share(RuleProviderInterface::class, $ruleProvider);
     $container->addServiceProvider(new SlugifyServiceProvider());
     $slugify = $container->get(SlugifyInterface::class);
     $this->assertAttributeSame($ruleProvider, 'provider', $slugify);
 }
 public function testConfig()
 {
     $container = new Container();
     $container->add('config', ['translation' => ['locale' => 'fr', 'resources' => ['fr' => [['array', ['okay' => 'correct']]], 'en' => [['array', ['scared' => 'scaredy cat', 'okay' => 'okay']]]]]]);
     $container->addServiceProvider(new SymfonyTranslationProvider());
     $translator = $container->get('Symfony\\Component\\Translation\\Translator');
     $this->assertTrue($translator->trans('okay') === 'correct');
     $this->assertTrue($translator->trans('scared') === 'scaredy cat');
 }
Example #22
0
 public function register(Container $app)
 {
     $app->share('database', function () use($app) {
         //https://siipo.la/blog/how-to-use-eloquent-orm-migrations-outside-laravel
         $default = ['driver' => 'mysql', 'host' => 'localhost', 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'prefix' => ''];
         $config = $app->get('config');
         $env = $config->get('environment');
         $database = $config->get("environments.{$env}.bbdd");
         $properties = array_merge($default, $database);
         $capsule = new Manager();
         $capsule->addConnection($properties);
         $capsule->setAsGlobal();
         $capsule->bootEloquent();
         // set timezone for timestamps etc
         //date_default_timezone_set('UTC');
         return $capsule;
     });
     $app->get('database');
 }
Example #23
0
 public function register(Container $app)
 {
     $app->share('event', function () use($app) {
         $paths = $app->get('paths');
         $event = Event::getInstance();
         $event->loadListeners($paths['listeners']);
         $event->setResolver(new EventResolver($app));
         return $event;
     });
 }
 public function testProviderConfig()
 {
     $container = new Container();
     $container->addServiceProvider(new PaginationProvider());
     $container['config.pagination'] = ['per_page' => 5, 'neighbours' => 2, 'base_url' => 'http://acme.com/pages/'];
     $pagination = $container->get('Laasti\\Pagination\\Pagination', [1, 50]);
     $this->assertTrue($pagination->getTotalPages() === 10);
     $this->assertTrue(count($pagination) === 3);
     $this->assertTrue($pagination->last()->link() === 'http://acme.com/pages/10');
 }
Example #25
0
 public function register(Container $app)
 {
     $app->share('commands', function () use($app) {
         $paths = $app->get('paths');
         $commands = $this->getCommands($paths['commands']);
         return array_map(function ($commandName) use($app) {
             $app->add($commandName);
             return $app->get($commandName)->setContainer($app);
         }, $commands);
     });
 }
 public function testContainerFactoryConfig()
 {
     $container = new Container();
     $container->addServiceProvider(new PaginationProvider());
     $container->add('Laasti\\Pagination\\Tests\\FakePaginationAware')->withMethodCall('setContainer', ['League\\Container\\ContainerInterface']);
     $paginationAware = $container->get('Laasti\\Pagination\\Tests\\FakePaginationAware');
     $pagination = $paginationAware->createPagination(1, 15, 5, 'http://acme.com/pages/', 1);
     $this->assertTrue(count($pagination) === 2);
     $this->assertTrue($pagination->getTotalPages() === 3);
     $this->assertTrue($pagination->next()->link() === 'http://acme.com/pages/2');
 }
Example #27
0
 public function register(Container $app)
 {
     //$app->share('mailhandler', function() use ($app){
     //    $config = $app->get('config');
     //    $paths = $config->get('paths');
     //    $options = $config->get('mail');
     //    $options['spool_directory'] = $paths['storage'] . '/spool';
     //    return new SwiftMailerHandler($options);
     //});
     $config = $app->get('config');
     //$r = $app->get('Symfony\Component\HttpFoundation\Request');
     AppSupport::setConfig($config);
     //AppSupport::initialize($r->getPathInfo());
     //AppSupport::loadLang($config->get('lang'));
     //$mail = Mail::getInstance();
     //$mail->setHandler($app->get('mailhandler'));
     Encode::$key = $config->get('encode.key');
     Encode::setAlgorithm($config->get('encode.algorithm'));
     DB::setCapsule($app->get('database'));
 }
Example #28
0
 /**
  * init
  *
  * @param Container $container
  */
 public function init(Container $container)
 {
     $dispatcher = $container->get(Services::APPLICATION_DISPATCHER);
     $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
         $command = $event->getCommand();
         if ($command instanceof BaseCommand && $command->getName() == 'timeline:migrate') {
             $timeline = $command->getContainer()->get(Services::TIMELINE);
             $comparator = $command->getContainer()->get(Services::COMPARATOR);
             $this->registerDomainEvent($timeline, $comparator, $event->getOutput());
         }
     });
 }
Example #29
0
 public function register(Container $app)
 {
     $app->share('config', function () use($app) {
         $paths = $app->get('paths');
         $configs = (require_once $paths['config']);
         $app_path = $paths['app'];
         $autoloads = ["files" => [$app_path . '/helpers.php']];
         $config = new Config($configs, $autoloads);
         $request = $app->get('current_request');
         $environment = $this->getEnvironment($request, $config->get('environments'));
         $config->set('environment', $environment ?: $config->get('environment'));
         $debugMode = $config->get('environment.development');
         $config->set("paths", $paths);
         $handle = new HandleError($debugMode, $paths['log']);
         $config->setupErrors($handle);
         $this->setHandlers($config);
         $this->setScope($config, $request->getPathInfo());
         $this->loadLang($config);
         return $config;
     });
 }
Example #30
0
 /**
  * @return void
  * @throws NotFoundException
  */
 public function play()
 {
     $this->container->get('sessionHandler');
     $this->router = new Router("/", $this->config->get("routes.dir"));
     try {
         $dispatchRoute = $this->router->match($this->request);
         $this->container->add('currentRoute', $dispatchRoute, true);
         Dispatcher::handle($dispatchRoute, $this->request, $this->container);
     } catch (NotFoundException $exception) {
         $this->notFound($exception);
     }
 }