/**
  * @inheritdoc
  *
  * The argument in this implementation must be a Configuration object.
  *
  * This implementation automatically adds a ConfigTokenProcessor and an EngineTokenProcessor.
  */
 public function configure($overrides = null)
 {
     LoggerRegistry::debug('AbstractConfigurableModule::configure({overrides})', array('overrides' => TypeUtilities::describe($overrides)));
     $this->config = new Configuration($this->getConfigLoader());
     $this->config->addProcessor(new EngineTokenProcessor($this->getEngine(), 'engine'));
     $this->config->addProcessor(new ConfigTokenProcessor($this, 'config'));
     $engine = $this->getEngine();
     if ($engine instanceof ConfigurableInterface) {
         $this->config->addProcessor(new ConfigTokenProcessor($engine, 'engine-config'));
     }
     $roots = array('site' => $this->getEngine()->getSiteInfo()->getSiteRoot(), 'sitegear' => $this->getEngine()->getApplicationInfo()->getSitegearRoot(), 'engine' => $this->getEngine()->getEngineRoot(), 'module' => $this->getModuleRoot());
     $this->config->addProcessor(new IncludeTokenProcessor($roots, $this->getConfigLoader(), 'include'));
     $this->config->merge($this->defaults());
     if (!is_null($overrides)) {
         $this->config->merge($overrides);
     }
     return $this;
 }
 /**
  * @inheritdoc
  */
 protected function buildRoutes()
 {
     LoggerRegistry::debug('{class}::buildRoutes(), mounted to "{mountedUrl}"', array('class' => (new \ReflectionClass($this))->getShortName(), 'mountedUrl' => $this->getMountedUrl()));
     $routes = new RouteCollection();
     // Check for an index controller and add a route for the module root.
     if ((new \ReflectionObject($this))->hasMethod('indexController')) {
         $routes->add('index', new Route($this->getMountedUrl()));
     }
     // Load routes from file.
     $filename = sprintf('%s/%s/%s', $this->getModuleRoot(), ResourceLocations::RESOURCES_DIRECTORY, self::FILENAME_ROUTES);
     $container = new Configuration($this->getConfigLoader());
     $container->merge($filename);
     // Add a route for each record in the routes file.
     foreach ($container->all() as $name => $parameters) {
         $defaults = array();
         $requirements = array();
         $options = array();
         $path = sprintf('%s/%s', $this->getMountedUrl(), $this->config(sprintf('routes.%s', $name), $name));
         foreach ($parameters ?: array() as $parameter) {
             $parameterName = $parameter['name'];
             $path = sprintf('%s/{%s}', $path, $parameterName);
             if (isset($parameter['default'])) {
                 $defaults[$parameterName] = $parameter['default'];
             }
             if (isset($parameter['requirements'])) {
                 $requirements[$parameterName] = $parameter['requirements'];
             }
             if (isset($parameter['options'])) {
                 $options[$parameterName] = $parameter['options'];
             }
         }
         $routes->add($name, new Route($path, $defaults, $requirements, $options));
     }
     return $routes;
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testMergePrimitiveType()
 {
     $this->config->merge(42);
 }
Exemple #4
0
 /**
  * @param string $formKey
  * @param string $formUrl
  * @param ConfigurableInterface $module
  * @param string[] $paths
  *
  * @return FormInterface|null
  */
 protected function loadFormFromDefinitions($formKey, $formUrl, ConfigurableInterface $module, array $paths)
 {
     $path = FileUtilities::firstExistingPath($paths);
     if (!empty($path)) {
         // Setup the configuration container for the form definition.
         $config = new Configuration($this->formsModule->getConfigLoader());
         $config->addProcessor(new ArrayTokenProcessor($this->getValues($formKey), 'data'));
         $config->addProcessor(new EngineTokenProcessor($this->formsModule->getEngine(), 'engine'));
         $config->addProcessor(new ConfigTokenProcessor($this->formsModule->getEngine(), 'engine-config'));
         $config->addProcessor(new ConfigTokenProcessor($module, 'config'));
         // Merge the configuration defaults and form definition file contents.
         $config->merge($this->baseConfig);
         $config->merge(array('form-url' => $formUrl));
         $config->merge($path);
         // Build and return the form
         $builder = new FormBuilder($this->formsModule, $formKey);
         return $builder->buildForm($config->all());
     }
     return null;
 }