public function it_should_register_new_options(DIContainer $container, ExpressionReader $expressionReader, ExpressionFunction $expressionFunction) { $this->config->debugMode()->willReturn(false); $this->config->includePaths()->willReturn(array()); $this->config->cachePath()->willReturn('/home/cache'); $closure = function () { return 1; }; $this->registerExpressionFunction($expressionFunction); $this->registerExpressionFunction($expressionFunction); $this->registerSecurityType('security1', $closure); $this->registerSecurityType('security2', $closure); $this->registerSecurityPolicy('policy1', $closure); $this->registerSecurityPolicy('policy2', $closure); $this->registerUserFactory('user1', $closure); $this->registerUserFactory('user2', $closure); $this->registerResourceFactory('resource1', $closure); $this->registerResourceFactory('resource2', $closure); $container->register('expressionReader', $expressionReader)->shouldBeCalledTimes(1); $container->registerSecurityType('standard', Argument::type('callable'))->shouldBeCalledTimes(1); $container->register('security', Argument::type('Dgafka\\AuthorizationSecurity\\Application\\Api\\Security'))->shouldBeCalledTimes(1); $container->register('cachePath', '/home/cache')->shouldBeCalledTimes(1); $container->register('includePaths', array())->shouldBeCalledTimes(1); $container->register('debugMode', false)->shouldBeCalledTimes(1); $container->registerSecurityType('security1', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerSecurityType('security2', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerSecurityPolicy('policy1', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerSecurityPolicy('policy2', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerUserFactory('user1', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerUserFactory('user2', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerResourceFactory('resource1', Argument::type('callable'))->shouldBeCalledTimes(1); $container->registerResourceFactory('resource2', Argument::type('callable'))->shouldBeCalledTimes(1); $expressionReader->registerFunction($expressionFunction)->shouldBeCalledTimes(2); $this->initialize($container, $expressionReader, $closure); $this->initialize($container, $expressionReader, $closure); }
/** * Initialize application, should not be called directly. * * @param DIContainer $container * @param ExpressionReader $expressionReader * * @throws RuntimeException * @internal */ public function initialize(DIContainer $container, ExpressionReader $expressionReader) { if ($this->isLoaded) { return; } $container->register('expressionReader', $expressionReader); $container->register('security', new Security($container)); $container->registerSecurityType('standard', function () { return new StandardSecurity(); }); $container->register('cachePath', $this->config()->cachePath()); $container->register('debugMode', $this->config()->debugMode()); $container->register('includePaths', $this->config()->includePaths()); foreach ($this->expressionFunctions as $expressionFunction) { $expressionReader->registerFunction($expressionFunction); } foreach ($this->securityTypes as $type) { $container->registerSecurityType($type['name'], $type['closure']); } foreach ($this->securityPolicies as $policy) { $container->registerSecurityPolicy($policy['name'], $policy['closure']); } foreach ($this->userFactories as $userFactory) { $container->registerUserFactory($userFactory['name'], $userFactory['closure']); } foreach ($this->resourceFactories as $resourceFactory) { $container->registerResourceFactory($resourceFactory['name'], $resourceFactory['closure']); } $this->isLoaded = true; }