Setter for static::$container.
public static setContainer ( Illuminate\Contracts\Container\Container $container ) : void | ||
$container | Illuminate\Contracts\Container\Container | The IoC container that will be used by mongolid. |
return | void |
public function testShouldCallMethodsPropertlywithFiveOrMoreArgument() { $container = m::mock(Container::class); $container->shouldReceive('method')->once()->with(1, 2, 3, 4, 5)->andReturn(true); Ioc::setContainer($container); Ioc::method(1, 2, 3, 4, 5); }
public function testShouldGetRawManager() { // Arrange $mongoManager = new Manager('mongodb://localhost:27017'); $container = m::mock(Container::class)->makePartial(); Ioc::setContainer($container); // Act $container->shouldReceive('make')->once()->with(Manager::class, m::any())->andReturn($mongoManager); // Assert $connection = new Connection(); $this->assertEquals($mongoManager, $connection->getRawManager()); }
/** * Register MongoDbConnector within the application. * * @return void */ public function registerConnector() { $config = $this->app->make('config'); MongolidIoc::setContainer($this->app); $connectionString = $this->buildConnectionString(); $connection = new Connection($connectionString); $pool = new Pool(); $eventService = new EventTriggerService(); $eventService->registerEventDispatcher($this->app->make(LaravelEventTrigger::class)); $pool->addConnection($connection); $this->app->instance(Pool::class, $pool); $this->app->instance(EventTriggerService::class, $eventService); $this->app->bind(CacheComponentInterface::class, function ($app) { return new LaravelCacheComponent($app[CacheRepository::class], $app[Serializer::class]); }); $connection->defaultDatabase = $config->get('database.mongodb.default.database', 'mongolid'); }
<?php include 'vendor/autoload.php'; if (!extension_loaded('mongodb')) { throw new Exception('MongoClient PHP extension required.', 1); } use Illuminate\Container\Container; use Mongolid\Container\Ioc; Ioc::setContainer(new Container());
/** * Initializes the Mongolid manager. * * @return void */ protected function init() { if ($this->container) { return; } $this->container = new Container(); $this->connectionPool = new Pool(); $this->cacheComponent = new CacheComponent(); $this->container->instance(Pool::class, $this->connectionPool); $this->container->instance(CacheComponentInterface::class, $this->cacheComponent); Ioc::setContainer($this->container); static::$singleton = $this; }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); Ioc::setContainer($this->app); }