filesystem = $filesystem; $this->simpleFactory = $simpleFactory; $this->themeFactory = $themeFactory; $this->moduleFactory = $moduleFactory; $this->modularSwitchFactory = $modularSwitchFactory; } /** * Retrieve newly created fallback rule for locale files, such as CSV translation maps * * @return RuleInterface */ protected function createLocaleFileRule() { return $this->themeFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => ""])] ); } /** * Retrieve newly created fallback rule for template files * * @return RuleInterface */ protected function createTemplateFileRule() { return $this->modularSwitchFactory->create( ['ruleNonModular' => $this->themeFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/templates"])] ), 'ruleModular' => new Composite( [ $this->themeFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "//templates"])] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view//templates"])] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view/base/templates"])] ), ] )] ); } /** * Retrieve newly created fallback rule for dynamic view files * * @return RuleInterface */ protected function createFileRule() { return $this->modularSwitchFactory->create( ['ruleNonModular' => $this->themeFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => ""])] ), 'ruleModular' => new Composite( [ $this->themeFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/"])] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view/"])] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view/base"])] ), ] )] ); } /** * Retrieve newly created fallback rule for static view files, such as CSS, JavaScript, images, etc. * * @return RuleInterface */ protected function createViewFileRule() { $libDir = rtrim($this->filesystem->getDirectoryRead(DirectoryList::LIB_WEB)->getAbsolutePath(), '/'); return $this->modularSwitchFactory->create( ['ruleNonModular' => new Composite( [ $this->themeFactory->create( ['rule' => new Composite( [ $this->simpleFactory ->create([ 'pattern' => "/web/i18n/", 'optionalParams' => ['locale'] ]), $this->simpleFactory ->create(['pattern' => "/web"]), $this->simpleFactory ->create([ 'pattern' => "", 'optionalParams' => ['theme_pubstatic_dir'] ]), ] )] ), $this->simpleFactory->create(['pattern' => $libDir]), ] ), 'ruleModular' => new Composite( [ $this->themeFactory->create( ['rule' => new Composite( [ $this->simpleFactory->create( [ 'pattern' => "//web/i18n/", 'optionalParams' => ['locale'], ] ), $this->simpleFactory->create( ['pattern' => "//web"] ), ] )] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create( [ 'pattern' => "/view//web/i18n/", 'optionalParams' => ['locale'] ] )] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create( [ 'pattern' => "/view/base/web/i18n/", 'optionalParams' => ['locale'] ] )] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view//web"])] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view/base/web"])] ), ] )] ); } /** * Retrieve newly created fallback rule for email templates. * * Emails are only loaded in a modular context, so a non-modular rule is not specified. * * @return RuleInterface */ protected function createEmailTemplateFileRule() { return new Composite( [ $this->themeFactory->create( ['rule' => $this->simpleFactory->create( ['pattern' => "//email"] )] ), $this->moduleFactory->create( ['rule' => $this->simpleFactory->create(['pattern' => "/view//email"])] ), ] ); } /** * Get rule by type * * @param string $type * @return RuleInterface * @throws \InvalidArgumentException */ public function getRule($type) { if (isset($this->rules[$type])) { return $this->rules[$type]; } switch ($type) { case self::TYPE_FILE: $rule = $this->createFileRule(); break; case self::TYPE_LOCALE_FILE: $rule = $this->createLocaleFileRule(); break; case self::TYPE_TEMPLATE_FILE: $rule = $this->createTemplateFileRule(); break; case self::TYPE_STATIC_FILE: $rule = $this->createViewFileRule(); break; case self::TYPE_EMAIL_TEMPLATE: $rule = $this->createEmailTemplateFileRule(); break; default: throw new \InvalidArgumentException("Fallback rule '$type' is not supported"); } $this->rules[$type] = $rule; return $this->rules[$type]; } }