Example #1
0
 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  */
 public function boot(Application $app)
 {
     if ($app->offsetExists('facade.aliases')) {
         $aliases = $app->offsetGet('facade.aliases');
         ClassAliaser::register($aliases);
     }
 }
 public function testBasePathAndUrls()
 {
     $app = new Application();
     $app->register(new AssetServiceProvider(), ['assets' => ['base_path' => '/', 'base_urls' => ['//exemple.com']]]);
     $this->setExpectedException('LogicException');
     $app->offsetGet('asset.packages');
 }
 public function offsetGet($id)
 {
     if (parent::offsetExists($id)) {
         return parent::offsetGet($id);
     }
     return $this->phpdi->get($id);
 }
Example #4
0
 /**
  * Gets a parameter or an object.
  *
  * @param  string $id The unique identifier for the parameter or object
  * @return mixed      The value of the parameter or an object
  * @throws \InvalidArgumentException if the identifier is not defined
  */
 public function offsetGet($id)
 {
     $instance = parent::offsetGet($id);
     if ($instance instanceof PimpleAwareInterface) {
         $instance->setContainer($this);
     }
     return $instance;
 }
Example #5
0
 /**
  * Override Pimple's offsetGet to add support for initializers
  *
  * @param  string $id The unique identifier for the parameter or object
  * @return mixed      The value of the parameter or an object
  */
 public function offsetGet($id)
 {
     $value = parent::offsetGet($id);
     if (is_object($value)) {
         $this->initialize($value);
     }
     return $value;
 }
 public function offsetGet($id)
 {
     if ($this->isPublicScope() && false === $this->isServicePublished($id)) {
         throw new PrivateScopeViolationException($id);
     }
     $scope = $this->enterPrivateScope();
     $service = parent::offsetGet($id);
     $this->leavePrivateScope($scope);
     return $service;
 }
 public function it_handles_authorization_refusal(AuthorizeControllerInterface $oauth2AuthorizeController, ParameterBag $requestBag, Application $app, Request $request, TokenStorageInterface $tokenStorage)
 {
     $app->offsetGet('security.token_storage')->willReturn($tokenStorage);
     $requestBag->all()->willReturn(['authorize' => '0']);
     $responseArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Response');
     $requestArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Request');
     $oauth2AuthorizeController->handleAuthorizeRequest($requestArgument, $responseArgument, false, null)->shouldBeCalled();
     $response = $this->__invoke($app, $request);
     $response->shouldHaveType('OAuth2\\HttpFoundationBridge\\Response');
     $response->getStatusCode()->shouldReturn(200);
 }
 public function it_renders_authenticated_authorize_view(UrlGeneratorInterface $urlGenerator, AuthorizeControllerInterface $oauth2AuthorizeController, AuthorizeRenderer $authorizeRenderer, Application $app, Request $request, ParameterBag $queryBag, BridgeResponse $response, TokenStorageInterface $tokenStorage, TokenInterface $token)
 {
     $responseArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Response');
     $requestArgument = Argument::type('OAuth2\\HttpFoundationBridge\\Request');
     $oauth2AuthorizeController->validateAuthorizeRequest($requestArgument, $responseArgument)->willReturn(true);
     $urlGenerator->generate('oauth2_authorize_handler', Argument::any())->willReturn('/url');
     $queryBag->all()->willReturn(['client_id' => 'clientId', 'response_type' => 'responseType']);
     $app->offsetGet('security.token_storage')->willReturn($tokenStorage);
     $tokenStorage->getToken()->willReturn($token);
     $token->getUser()->willReturn('user');
     $authorizeRenderer->render('/url', 'clientId', 'responseType', 'user')->willReturn($response);
     $this->__invoke($app, $request)->shouldReturn($response);
 }
 /**
  * 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(Application $app)
 {
     if ($app->offsetGet('api.version') === false) {
         throw new \Exception('Missing api version');
     }
     $app['rest_normalizer.builder'] = $app->protect(function ($object = null) use($app) {
         $request = $app['request'];
         // @var $request Request
         $builder = ResponseBuilder::create($app['api.version'], HttpMethod::valueOf($request->getMethod()), $object);
         foreach ($request->request->all() as $key => $value) {
             $parameter = Parameter::create($key, $value);
             $builder->addParameter($parameter);
         }
         return $builder;
     });
 }
 /**
  * Registers services on the given app.
  *
  * @param Application $app
  */
 public function register(Application $app)
 {
     $app["debesha.doctrine_extra_profiler.logger"] = $app->share(function () use($app) {
         return new HydrationLogger($app->offsetGet("orm.em"));
     });
     $app['debesha.class.hydrationDataCollector'] = 'SilexDoctrineHydrationProfile\\Fix\\DataCollector';
     $app["debesha.doctrine_extra_profiler.data_collector"] = $app->share(function () use($app) {
         $class = $app['debesha.class.hydrationDataCollector'];
         return new $class($app->offsetGet("debesha.doctrine_extra_profiler.logger"));
     });
     if ($app->offsetExists(self::ORM_EM_OPTIONS)) {
         $options = $app->offsetGet(self::ORM_EM_OPTIONS);
     } else {
         $options = array();
     }
     $overwrite = array('class.configuration' => 'SilexDoctrineHydrationProfile\\Fix\\LoggingConfiguration', 'class.entityManager' => 'Debesha\\DoctrineProfileExtraBundle\\ORM\\LoggingEntityManager', 'class.driver.yml' => 'Doctrine\\ORM\\Mapping\\Driver\\YamlDriver', 'class.driver.simple_yml' => 'Doctrine\\ORM\\Mapping\\Driver\\SimplifiedYamlDriver', 'class.driver.xml' => 'Doctrine\\ORM\\Mapping\\Driver\\XmlDriver', 'class.driver.simple_xml' => 'Doctrine\\ORM\\Mapping\\Driver\\SimplifiedXmlDriver', 'class.driver.php' => 'Doctrine\\Common\\Persistence\\Mapping\\Driver\\StaticPHPDriver');
     foreach ($overwrite as $key => $className) {
         if (!isset($options[$key])) {
             $options[$key] = $className;
         }
     }
     $app[self::ORM_EM_OPTIONS] = $options;
     $app['orm.ems'] = $app->share(function ($app) {
         /**
          * @var \Pimple $app
          */
         $app['orm.ems.options.initializer']();
         $ems = new \Pimple();
         foreach ($app['orm.ems.options'] as $name => $options) {
             if ($app['orm.ems.default'] === $name) {
                 // we use shortcuts here in case the default has been overridden
                 $config = $app['orm.em.config'];
             } else {
                 $config = $app['orm.ems.config'][$name];
             }
             $ems[$name] = $app->share(function () use($app, $options, $config) {
                 /**
                  * @var $entityManagerClassName \Doctrine\ORM\EntityManager
                  */
                 $entityManagerClassName = $options['class.entityManager'];
                 return $entityManagerClassName::create($app['dbs'][$options['connection']], $config, $app['dbs.event_manager'][$options['connection']]);
             });
         }
         return $ems;
     });
     $app['orm.ems.config'] = $app->share(function (\Pimple $app) {
         $app['orm.ems.options.initializer']();
         $configs = new \Pimple();
         foreach ($app['orm.ems.options'] as $name => $options) {
             /**
              * @var $config \Doctrine\ORM\Configuration
              */
             $configurationClassName = $options['class.configuration'];
             $config = new $configurationClassName();
             $app['orm.cache.configurer']($name, $config, $options);
             $config->setProxyDir($app['orm.proxies_dir']);
             $config->setProxyNamespace($app['orm.proxies_namespace']);
             $config->setAutoGenerateProxyClasses($app['orm.auto_generate_proxies']);
             $config->setCustomStringFunctions($app['orm.custom.functions.string']);
             $config->setCustomNumericFunctions($app['orm.custom.functions.numeric']);
             $config->setCustomDatetimeFunctions($app['orm.custom.functions.datetime']);
             $config->setCustomHydrationModes($app['orm.custom.hydration_modes']);
             $config->setClassMetadataFactoryName($app['orm.class_metadata_factory_name']);
             $config->setDefaultRepositoryClassName($app['orm.default_repository_class']);
             $config->setEntityListenerResolver($app['orm.entity_listener_resolver']);
             $config->setRepositoryFactory($app['orm.repository_factory']);
             $config->setNamingStrategy($app['orm.strategy.naming']);
             $config->setQuoteStrategy($app['orm.strategy.quote']);
             /**
              * @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $chain
              */
             $chain = $app['orm.mapping_driver_chain.locator']($name);
             foreach ((array) $options['mappings'] as $entity) {
                 if (!is_array($entity)) {
                     throw new \InvalidArgumentException("The 'orm.em.options' option 'mappings' should be an array of arrays.");
                 }
                 if (!empty($entity['resources_namespace'])) {
                     if ($app->offsetExists('psr0_resource_locator')) {
                         $entity['path'] = $app['psr0_resource_locator']->findFirstDirectory($entity['resources_namespace']);
                     } else {
                         throw new \InvalidArgumentException('Not exist psr0_resource_locator');
                     }
                 }
                 if (isset($entity['alias'])) {
                     $config->addEntityNamespace($entity['alias'], $entity['namespace']);
                 }
                 if ('annotation' === $entity['type']) {
                     $useSimpleAnnotationReader = isset($entity['use_simple_annotation_reader']) ? $entity['use_simple_annotation_reader'] : true;
                     $driver = $config->newDefaultAnnotationDriver((array) $entity['path'], $useSimpleAnnotationReader);
                 } else {
                     $driver = $app['orm.driver.factory']($entity, $options);
                 }
                 $chain->addDriver($driver, $entity['namespace']);
             }
             $config->setMetadataDriverImpl($chain);
             foreach ((array) $options['types'] as $typeName => $typeClass) {
                 if (Type::hasType($typeName)) {
                     Type::overrideType($typeName, $typeClass);
                 } else {
                     Type::addType($typeName, $typeClass);
                 }
             }
             $configs[$name] = $config;
         }
         return $configs;
     });
     $app['orm.driver.factory'] = $app->share(function () {
         $simpleList = array('simple_yml', 'simple_xml');
         return function ($entity, $options) use($simpleList) {
             if (isset($options['class.driver.' . $entity['type']])) {
                 $className = $options['class.driver.' . $entity['type']];
                 if (in_array($entity['type'], $simpleList)) {
                     $param = array($entity['path'] => $entity['namespace']);
                 } else {
                     $param = $entity['path'];
                 }
                 return new $className($param);
             }
             throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
         };
     });
 }
 public function testJWTListenerService()
 {
     $this->register();
     $this->app->boot();
     $jwtListener = $this->app->offsetGet('security.authentication_listener.all.jwt');
     $this->assertInstanceOf(JWTListener::class, $jwtListener);
 }