示例#1
0
 /**
  * {@inheritDoc}
  */
 public function integrate(Aurex $aurex)
 {
     $config = $aurex->getConfiguration(self::CONFIG_KEY);
     $logName = $config['log_name'] === null ? self::DEFAULT_LOG_NAME : $config['log_name'];
     $logFile = $config['log_file'] === null ? self::DEFAULT_LOG_FILE : $config['log_file'];
     $aurex->register(new MonologServiceProvider(), ['monolog.name' => $logName, 'monolog.logfile' => $logFile]);
 }
示例#2
0
 /**
  * {@inheritDoc}
  */
 public function integrate(Aurex $aurex)
 {
     $aurex['route_class'] = 'Aurex\\Framework\\Module\\Modules\\RoutingModule\\TemplateRoute';
     $aurex['dispatcher']->addSubscriber(new CustomRouteListener($aurex));
     $routes = $aurex->getConfiguration(self::CONFIG_KEY) ?: [];
     foreach ($routes as $name => $route) {
         $controllerName = sprintf('%s\\%s', self::CONTROLLER_NAMESPACE, $route['controller']);
         /** Match the controller class to the route, and bind a name accessible to urlGenerator and twig **/
         $controller = $aurex->match($route['pattern'], $controllerName)->bind($name);
         /** Map a HTTP Method requirement to this route that defaults to GET if none is provided **/
         $controller->method(isset($route['method']) ? $route['method'] : 'GET');
         /** Map a twig template to the route if one is provided so that the route only needs to return an array **/
         if (isset($route['template'])) {
             /** @var TemplateRoute $controller */
             $controller->template($route['template']);
         }
         /** Add any slug requirements to the route as regex that must be matched for each slug **/
         if (isset($route['regex'])) {
             foreach ($route['regex'] as $slugName => $regexRequirement) {
                 $controller->assert($slugName, $regexRequirement);
             }
         }
         /** Add any default slug variables if none are provided **/
         if (isset($route['default'])) {
             foreach ($route['default'] as $slugName => $defaultValue) {
                 $controller->value($slugName, $defaultValue);
             }
         }
     }
 }
示例#3
0
 /**
  * Add the ability to call {{ asset() }} within Twig templates
  *
  * @param Aurex $aurex
  */
 protected function addAssetFunction(Aurex $aurex)
 {
     $aurex['twig'] = $aurex->extend('twig', function ($twig, $aurex) {
         /** @var \Twig_Environment $twig */
         $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use($aurex) {
             /** @var RequestStack $requestStack */
             $requestStack = $aurex['request_stack'];
             return sprintf('%s/assets/%s', $requestStack->getCurrentRequest()->getBasePath(), ltrim($asset, '/'));
         }));
         return $twig;
     });
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function integrate(Aurex $aurex)
 {
     $config = $aurex->getConfiguration(self::CONFIG_KEY);
     $firewalls = $config['firewalls'];
     $hierarchy = $config['hierarchy'];
     $accessRules = $config['access_rules'];
     $firewalls['default']['users'] = function ($aurex) {
         /** @var EntityManager $orm */
         $orm = $aurex['orm.em'];
         return new UserRepository($orm, new ClassMetadata('Aurex\\Application\\Model\\Entity\\User'));
     };
     $aurex->register(new SecurityServiceProvider(), ['security.firewalls' => $firewalls, 'security.role_hierarchy' => $hierarchy, 'security.access_rules' => $accessRules]);
     $aurex['security.encoder.digest'] = function () {
         return new BCryptPasswordEncoder(10);
     };
 }
示例#5
0
 /**
  * Share any non-Silex objects around the application (the string is shared)
  */
 public function shareObjects()
 {
     $injector = $this->aurex->getInjector();
     $config = $this->aurex->getConfiguration(self::CONFIG_KEY);
     if (isset($config['share'])) {
         foreach ($config['share'] as $shareable) {
             $injector->share($shareable);
         }
     }
 }
示例#6
0
 /**
  * Load the module
  *
  * @param Aurex  $aurex
  * @param string $moduleName Either the module name if from the default namespace or fully qualified module
  *
  * @throws ModuleNotFoundException
  * @throws ModuleConfigurationNotFoundException
  *
  * @return void
  */
 public function load(Aurex $aurex, $moduleName)
 {
     $defaultModulePath = sprintf('%s\\%s\\%s', self::DEFAULT_NAMESPACE, $moduleName, $moduleName);
     /** Check for default modules or user provided ones **/
     if (!class_exists($defaultModulePath) && !class_exists($moduleName)) {
         throw new ModuleNotFoundException(sprintf('Unable to load module: %s - it does not exist', $moduleName));
     }
     /** @var ModuleInterface $module */
     $module = class_exists($moduleName) ? $aurex->getInjector()->make($moduleName) : new $defaultModulePath();
     if (!$module instanceof ModuleInterface) {
         throw new ModuleNotFoundException(sprintf('Module: %s does not implement ModuleInterface', $moduleName));
     }
     $configuration = $aurex->getConfiguration();
     $configurationKey = $module->usesConfigurationKey();
     if ($configurationKey !== null && (strlen($configurationKey) > 0 && !array_key_exists($configurationKey, $configuration))) {
         throw new ModuleConfigurationNotFoundException(sprintf('Module: %s requires configuration key: %s', $moduleName, $configurationKey));
     }
     /** Perform the module's individual logic **/
     $module->integrate($aurex);
     /** Store a list of which modules have been loaded **/
     $aurex->addLoadedModule($module);
 }
示例#7
0
 /**
  * {@inheritDoc}
  */
 public function integrate(Aurex $aurex)
 {
     $aurex->register(new FormServiceProvider());
     $aurex->register(new SessionServiceProvider());
     $aurex->register(new TranslationServiceProvider(), ['locale' => 'en']);
     $aurex['form.extensions'] = $aurex->extend('form.extensions', function ($extensions, $app) {
         $managerRegistry = new FormManagerRegistry(null, [], ['default'], null, null, '\\Doctrine\\ORM\\Proxy\\Proxy');
         $managerRegistry->setContainer($app);
         unset($extensions);
         return [new DoctrineOrmExtension($managerRegistry)];
     });
     $aurex->getInjector()->share($aurex['form.factory']);
 }
示例#8
0
 /**
  * {@inheritDoc}
  */
 public function integrate(Aurex $aurex)
 {
     $config = $aurex->getConfiguration(self::CONFIG_KEY);
     $aurex->register(new DoctrineServiceProvider(), ['db.options' => $config]);
     $configType = 'annotation';
     $entityDirectory = __DIR__ . '/../../../Application/Model/Entity';
     $entityNamespace = 'Aurex\\Application\\Model\\Entity';
     $cacheObject = !$aurex['debug'] && extension_loaded('apc') ? new ApcCache() : new ArrayCache();
     $cacheDirectory = __DIR__ . '/../../../Application/Cache/Doctrine';
     $cacheNamespace = 'Aurex\\Application\\Cache\\Doctrine';
     $mappings = ['mappings' => [['type' => $configType, 'path' => $entityDirectory, 'namespace' => $entityNamespace]]];
     $aurex->register(new DoctrineOrmServiceProvider(), ['orm.proxies_dir' => $cacheDirectory, 'orm.proxies_namespace' => $cacheNamespace, 'orm.cache' => $cacheObject, 'orm.auto_generate_proxies' => true, 'orm.em.options' => $mappings]);
     /** @var Connection $orm */
     $orm = $aurex['orm.em'];
     /** @var Configuration $ormConfig */
     $ormConfig = $orm->getConfiguration();
     $ormConfig->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), [$entityDirectory]));
     $aurex->getInjector()->share($aurex['orm.em']);
     $aurex->getInjector()->share($aurex['db']);
 }
示例#9
0
 /**
  * Unnecessarily aiming for 100% code coverage here
  */
 public function testEnvironmentGetterWorksInAurex()
 {
     $aurex = new Aurex($env = $this->factory->create('dev'), new Injector(), []);
     $this->assertSame($env, $aurex->getEnvironment());
 }