/** * @param ThemeInterface $theme * @param string $filepath */ public function __construct(ThemeInterface $theme, $filepath) { $this->name = $filepath; $parts = explode('.', basename($filepath), 3); if (3 !== count($parts)) { throw new \InvalidArgumentException(sprintf('Could not create a translation resource with filepath "%s".', $filepath)); } $this->domain = $parts[0]; $this->locale = $parts[1] . '_' . $theme->getCode(); $this->format = $parts[2]; }
function it_throws_an_invalid_argument_exception_if_failed_to_instantiate_with_given_filepath(ThemeInterface $theme) { $theme->getCode()->willReturn('themecode'); $this->beConstructedWith($theme, 'one.dot'); $this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation(); }
function it_returns_modified_path_if_its_referencing_bundle_asset(ThemeInterface $theme) { $theme->getCode()->willReturn("dead42beef"); $this->resolve('bundles/asset.min.js', $theme)->shouldReturn('bundles/_dead42beef/asset.min.js'); }
function it_returns_resources_locales_while_using_one_nested_theme(TranslationFilesFinderInterface $translationFilesFinder, ThemeRepositoryInterface $themeRepository, ThemeHierarchyProviderInterface $themeHierarchyProvider, ThemeInterface $mainTheme, ThemeInterface $parentTheme) { $themeRepository->findAll()->willReturn([$mainTheme]); $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]); $mainTheme->getPath()->willReturn('/main/theme/path'); $mainTheme->getCode()->willReturn('mainthemecode'); $parentTheme->getPath()->willReturn('/parent/theme/path'); $parentTheme->getCode()->willReturn('parentthemecode'); $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']); $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']); $this->getResourcesLocales()->shouldReturn(['en_mainthemecode']); }
/** * {@inheritdoc} */ public function resolve($path, ThemeInterface $theme) { return str_replace('bundles/', 'bundles/_' . $theme->getCode() . '/', $path); }