예제 #1
0
 /**
  * You can modify the container here before it is dumped to PHP code.
  *
  * @param ContainerBuilder $container
  *
  * @api
  */
 public function process(ContainerBuilder $container)
 {
     try {
         $chainRouter = $container->getDefinition("router.chainRequest");
     } catch (InvalidArgumentException $e) {
         return;
     }
     foreach ($container->findTaggedServiceIds("router.register") as $id => $attributes) {
         $priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0;
         $router = $container->getDefinition($id);
         $router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher" . $id)));
         $router->addMethodCall("setOption", array("generator_cache_class", $container::camelize("ProjectUrlGenerator" . $id)));
         $chainRouter->addMethodCall("add", array(new Reference($id), $priority));
     }
     if (defined("THELIA_INSTALL_MODE") === false) {
         $modules = \Thelia\Model\ModuleQuery::getActivated();
         foreach ($modules as $module) {
             $moduleBaseDir = $module->getBaseDir();
             $routingConfigFilePath = $module->getAbsoluteBaseDir() . DS . "Config" . DS . "routing.xml";
             if (file_exists($routingConfigFilePath)) {
                 $definition = new Definition($container->getParameter("router.class"), array(new Reference("router.module.xmlLoader"), $routingConfigFilePath, array("cache_dir" => $container->getParameter("kernel.cache_dir"), "debug" => $container->getParameter("kernel.debug"), "matcher_cache_class" => $container::camelize("ProjectUrlMatcher" . $moduleBaseDir), "generator_cache_class" => $container::camelize("ProjectUrlGenerator" . $moduleBaseDir)), new Reference("request.context")));
                 $container->setDefinition("router." . $moduleBaseDir, $definition);
                 $chainRouter->addMethodCall("add", array(new Reference("router." . $moduleBaseDir), 150));
             }
         }
     }
 }
예제 #2
0
파일: Module.php 프로젝트: alex63530/thelia
 /**
  * Process theliaModule template inclusion function
  *
  * This function accepts two parameters:
  *
  * - location : this is the location in the admin template. Example: folder-edit'. The function will search for
  *   AdminIncludes/<location>.html file, and fetch it as a Smarty template.
  * - countvar : this is the name of a template variable where the number of found modules includes will be assigned.
  *
  * @param array                     $params
  * @param \Smarty_Internal_Template $template
  * @internal param \Thelia\Core\Template\Smarty\Plugins\unknown $smarty
  *
  * @return string
  */
 public function theliaModule($params, \Smarty_Internal_Template $template)
 {
     $content = null;
     $count = 0;
     if (false !== ($location = $this->getParam($params, 'location', false))) {
         if ($this->debug === true && $this->request->get('SHOW_INCLUDE')) {
             echo sprintf('<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">%s</div>', $location);
         }
         $moduleLimit = $this->getParam($params, 'module', null);
         $modules = ModuleQuery::getActivated();
         /** @var \Thelia\Model\Module $module */
         foreach ($modules as $module) {
             if (null !== $moduleLimit && $moduleLimit != $module->getCode()) {
                 continue;
             }
             $file = $module->getAbsoluteAdminIncludesPath() . DS . $location . '.html';
             if (file_exists($file)) {
                 $output = trim(file_get_contents($file));
                 if (!empty($output)) {
                     $content .= $output;
                     $count++;
                 }
             }
         }
     }
     if (false !== ($countvarname = $this->getParam($params, 'countvar', false))) {
         $template->assign($countvarname, $count);
     }
     if (!empty($content)) {
         return $template->fetch(sprintf("string:%s", $content));
     }
     return "";
 }
예제 #3
0
 protected function getModuleChoices()
 {
     $choices = array();
     $modules = ModuleQuery::getActivated();
     /** @var Module $module */
     foreach ($modules as $module) {
         $choices[$module->getId()] = $module->getTitle();
     }
     return $choices;
 }
예제 #4
0
 protected function getModuleChoices()
 {
     $choices = array();
     $modules = ModuleQuery::getActivated();
     /** @var Module $module */
     foreach ($modules as $module) {
         // Check if module defines a hook ID
         if (ModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0 || IgnoredModuleHookQuery::create()->filterByModuleId($module->getId())->count() > 0) {
             $choices[$module->getId()] = $module->getTitle();
         }
     }
     asort($choices);
     return $choices;
 }
예제 #5
0
 protected function listDirectoryContent($requiredExtension)
 {
     $list = array();
     $dir = $this->getTemplateHelper()->getActiveMailTemplate()->getAbsolutePath();
     $finder = Finder::create()->files()->in($dir)->ignoreDotFiles(true)->sortByName()->name("*.{$requiredExtension}");
     foreach ($finder as $file) {
         $list[] = $file->getBasename();
     }
     // Add modules templates
     $modules = ModuleQuery::getActivated();
     /** @var Module $module */
     foreach ($modules as $module) {
         $dir = $module->getAbsoluteTemplateBasePath() . DS . TemplateDefinition::EMAIL_SUBDIR . DS . 'default';
         if (file_exists($dir)) {
             $finder = Finder::create()->files()->in($dir)->ignoreDotFiles(true)->sortByName()->name("*.{$requiredExtension}");
             foreach ($finder as $file) {
                 $fileName = $file->getBasename();
                 if (!in_array($fileName, $list)) {
                     $list[] = $fileName;
                 }
             }
         }
     }
     return $list;
 }
예제 #6
0
 /**
  *
  * Load some configuration
  * Initialize all plugins
  *
  */
 protected function loadConfiguration(ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . "/../Config/Resources"));
     $finder = Finder::create()->name('*.xml')->depth(0)->in(__DIR__ . "/../Config/Resources");
     /** @var \SplFileInfo $file */
     foreach ($finder as $file) {
         $loader->load($file->getBaseName());
     }
     if (defined("THELIA_INSTALL_MODE") === false) {
         $modules = ModuleQuery::getActivated();
         $translationDirs = array();
         /** @var Module $module */
         foreach ($modules as $module) {
             try {
                 $definition = new Definition();
                 $definition->setClass($module->getFullNamespace());
                 $definition->addMethodCall("setContainer", array(new Reference('service_container')));
                 $container->setDefinition("module." . $module->getCode(), $definition);
                 $compilers = call_user_func(array($module->getFullNamespace(), 'getCompilers'));
                 foreach ($compilers as $compiler) {
                     if (is_array($compiler)) {
                         $container->addCompilerPass($compiler[0], $compiler[1]);
                     } else {
                         $container->addCompilerPass($compiler);
                     }
                 }
                 $loader = new XmlFileLoader($container, new FileLocator($module->getAbsoluteConfigPath()));
                 $loader->load("config.xml", "module." . $module->getCode());
                 $envConfigFileName = sprintf("config_%s.xml", $this->environment);
                 $envConfigFile = sprintf('%s%s%s', $module->getAbsoluteConfigPath(), DS, $envConfigFileName);
                 if (is_file($envConfigFile) && is_readable($envConfigFile)) {
                     $loader->load($envConfigFileName, "module." . $module->getCode());
                 }
             } catch (\Exception $e) {
                 Tlog::getInstance()->addError(sprintf("Failed to load module %s: %s", $module->getCode(), $e->getMessage()), $e);
             }
         }
         /** @var ParserInterface $parser */
         $parser = $container->getDefinition('thelia.parser');
         /** @var \Thelia\Core\Template\TemplateHelperInterface $templateHelper */
         $templateHelper = $container->get('thelia.template_helper');
         /** @var Module $module */
         foreach ($modules as $module) {
             try {
                 $this->loadModuleTranslationDirectories($module, $translationDirs, $templateHelper);
                 $this->addStandardModuleTemplatesToParserEnvironment($parser, $module);
             } catch (\Exception $e) {
                 Tlog::getInstance()->addError(sprintf("Failed to load module %s: %s", $module->getCode(), $e->getMessage()), $e);
             }
         }
         // Load core translation
         $translationDirs['core'] = THELIA_LIB . 'Config' . DS . 'I18n';
         // Load core translation
         $translationDirs[Translator::GLOBAL_FALLBACK_DOMAIN] = THELIA_LOCAL_DIR . 'I18n';
         // Standard templates (front, back, pdf, mail)
         /** @var TemplateDefinition $templateDefinition */
         foreach ($templateHelper->getStandardTemplateDefinitions() as $templateDefinition) {
             if (is_dir($dir = $templateDefinition->getAbsoluteI18nPath())) {
                 $translationDirs[$templateDefinition->getTranslationDomain()] = $dir;
             }
         }
         if ($translationDirs) {
             $this->loadTranslation($container, $translationDirs);
         }
     }
 }
예제 #7
0
파일: Thelia.php 프로젝트: alex63530/thelia
 /**
  *
  * Load some configuration
  * Initialize all plugins
  *
  */
 protected function loadConfiguration(ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, new FileLocator(THELIA_ROOT . "/core/lib/Thelia/Config/Resources"));
     $finder = Finder::create()->name('*.xml')->depth(0)->in(THELIA_ROOT . "/core/lib/Thelia/Config/Resources");
     /** @var \SplFileInfo $file */
     foreach ($finder as $file) {
         $loader->load($file->getBaseName());
     }
     if (defined("THELIA_INSTALL_MODE") === false) {
         $modules = ModuleQuery::getActivated();
         $translationDirs = array();
         /** @var ParserInterface $parser */
         $parser = $container->getDefinition('thelia.parser');
         /** @var Module $module */
         foreach ($modules as $module) {
             try {
                 $definition = new Definition();
                 $definition->setClass($module->getFullNamespace());
                 $definition->addMethodCall("setContainer", array(new Reference('service_container')));
                 $container->setDefinition("module." . $module->getCode(), $definition);
                 $compilers = call_user_func(array($module->getFullNamespace(), 'getCompilers'));
                 foreach ($compilers as $compiler) {
                     if (is_array($compiler)) {
                         $container->addCompilerPass($compiler[0], $compiler[1]);
                     } else {
                         $container->addCompilerPass($compiler);
                     }
                 }
                 $loader = new XmlFileLoader($container, new FileLocator($module->getAbsoluteConfigPath()));
                 $loader->load("config.xml", "module." . $module->getCode());
                 // Core module translation
                 if (is_dir($dir = $module->getAbsoluteI18nPath())) {
                     $translationDirs[$module->getTranslationDomain()] = $dir;
                 }
                 // Admin includes translation
                 if (is_dir($dir = $module->getAbsoluteAdminIncludesI18nPath())) {
                     $translationDirs[$module->getAdminIncludesTranslationDomain()] = $dir;
                 }
                 // Module back-office template, if any
                 $templates = TemplateHelper::getInstance()->getList(TemplateDefinition::BACK_OFFICE, $module->getAbsoluteTemplateBasePath());
                 foreach ($templates as $template) {
                     $translationDirs[$module->getBackOfficeTemplateTranslationDomain($template->getName())] = $module->getAbsoluteBackOfficeI18nTemplatePath($template->getName());
                 }
                 // Module front-office template, if any
                 $templates = TemplateHelper::getInstance()->getList(TemplateDefinition::FRONT_OFFICE, $module->getAbsoluteTemplateBasePath());
                 foreach ($templates as $template) {
                     $translationDirs[$module->getFrontOfficeTemplateTranslationDomain($template->getName())] = $module->getAbsoluteFrontOfficeI18nTemplatePath($template->getName());
                 }
                 $this->addStandardModuleTemplatesToParserEnvironment($parser, $module);
             } catch (\InvalidArgumentException $e) {
                 Tlog::getInstance()->addError(sprintf("Failed to load module %s: %s", $module->getCode(), $e->getMessage()), $e);
                 throw $e;
             }
         }
         // Load core translation
         $translationDirs['core'] = THELIA_ROOT . 'core' . DS . 'lib' . DS . 'Thelia' . DS . 'Config' . DS . 'I18n';
         // Standard templates (front, back, pdf, mail)
         $th = TemplateHelper::getInstance();
         /** @var TemplateDefinition $templateDefinition */
         foreach ($th->getStandardTemplateDefinitions() as $templateDefinition) {
             if (is_dir($dir = $templateDefinition->getAbsoluteI18nPath())) {
                 $translationDirs[$templateDefinition->getTranslationDomain()] = $dir;
             }
         }
         if ($translationDirs) {
             $this->loadTranslation($container, $translationDirs);
         }
     }
 }