1 | <?php |
||
24 | abstract class ThemeLoader extends Loader |
||
25 | { |
||
26 | /** |
||
27 | * @var FilesystemInterface |
||
28 | */ |
||
29 | private $filesystem; |
||
30 | |||
31 | /** |
||
32 | * @var ThemeFactoryInterface |
||
33 | */ |
||
34 | private $themeFactory; |
||
35 | |||
36 | /** |
||
37 | * @param FilesystemInterface $filesystem |
||
38 | * @param ThemeFactoryInterface $themeFactory |
||
39 | */ |
||
40 | public function __construct(FilesystemInterface $filesystem, ThemeFactoryInterface $themeFactory) |
||
41 | { |
||
42 | $this->filesystem = $filesystem; |
||
43 | $this->themeFactory = $themeFactory; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | public function load($resource, $type = null) |
||
50 | { |
||
51 | if (!$this->filesystem->exists($resource)) { |
||
52 | throw new \InvalidArgumentException(sprintf('Given theme metadata file "%s" does not exists!', $resource)); |
||
53 | } |
||
54 | |||
55 | $themeData = $this->transformResourceContentsToArray($this->filesystem->getFileContents($resource)); |
||
56 | |||
57 | $theme = $this->themeFactory->createFromArray($themeData); |
||
58 | $theme->setPath(substr($resource, 0, strrpos($resource, '/'))); |
||
59 | |||
60 | return $theme; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Returns theme data array from resource contents. |
||
65 | * |
||
66 | * @param string $contents |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | abstract protected function transformResourceContentsToArray($contents); |
||
71 | } |
||
72 |