/** * {@inheritdoc} */ public function load($resource, $type = null) { if (!$this->filesystem->exists($resource)) { throw new \InvalidArgumentException(sprintf('Given theme metadata file "%s" does not exists!', $resource)); } $themeData = $this->transformResourceContentsToArray($this->filesystem->getFileContents($resource)); $theme = $this->themeFactory->createFromArray($themeData); $theme->setPath(substr($resource, 0, strrpos($resource, '/'))); return $theme; }
function it_loads_valid_theme_file(FilesystemInterface $filesystem, ThemeFactoryInterface $themeFactory, ThemeInterface $theme) { $filesystem->exists('/themes/SampleTheme/theme.json')->willReturn(true); $filesystem->getFileContents('/themes/SampleTheme/theme.json')->willReturn('{ "name": "Sample Theme", "slug": "sylius/sample-theme", "description": "Lorem ipsum dolor sit amet." }'); $themeFactory->createFromArray(["name" => "Sample Theme", "slug" => "sylius/sample-theme", "description" => "Lorem ipsum dolor sit amet."])->willReturn($theme); $theme->setPath('/themes/SampleTheme')->shouldBeCalled(); $this->load('/themes/SampleTheme/theme.json')->shouldReturn($theme); }
/** * {@inheritdoc} */ public function load($path) { $this->assertFileExists($path); $contents = $this->filesystem->getFileContents($path); return array_merge(['path' => dirname($path)], json_decode($contents, true)); }
function it_loads_json_file(FilesystemInterface $filesystem) { $filesystem->exists('/directory/composer.json')->willReturn(true); $filesystem->getFileContents('/directory/composer.json')->willReturn('{ "name": "example/sylius-theme" }'); $this->load('/directory/composer.json')->shouldReturn(['path' => '/directory', 'name' => 'example/sylius-theme']); }