This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBridge.php
76 lines (63 loc) · 2.19 KB
/
Bridge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace WeProvide\Aviate\Magento2;
use Magento\Framework\View\Design\ThemeInterface;
use Magento\Framework\View\DesignInterface;
use Magento\Framework\View\Element\Template;
use Magento\Store\Model\ScopeInterface;
use WeProvide\Aviate\Aviate;
use Magento\Framework\App\State;
use \Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\View\Element\Template\Context;
use Magento\Theme\Model\Theme\ThemeProvider;
class Bridge extends Aviate {
protected $directoryList;
protected $developerMode;
protected $storeManager;
protected $scopeConfig;
protected $themeProvider;
protected $template;
public function __construct(
Context $context,
DirectoryList $directoryList,
ThemeProvider $themeProvider,
Template $template
) {
$state = $context->getAppState();
$this->storeManager = $context->getStoreManager();
$this->scopeConfig = $context->getScopeConfig();
$this->directoryList = $directoryList;
$this->themeProvider = $themeProvider;
$this->template = $template;
$this->developerMode = $state->getMode() === $state::MODE_DEVELOPER;
}
public function isDevMode(): bool {
return $this->developerMode;
}
public function getTheme(): ThemeInterface
{
$themeId = $this->scopeConfig->getValue(
DesignInterface::XML_PATH_THEME_ID,
ScopeInterface::SCOPE_STORE,
$this->storeManager->getStore()->getId()
);
/** @var $theme ThemeInterface */
$theme = $this->themeProvider->getThemeById($themeId);
return $theme;
}
public function getProjectRoot(): string
{
return $this->directoryList->getRoot();
}
public function getFiles(): array
{
$types = parent::getFiles();
$themePath = $this->getTheme()->getThemePath();
if($this->isDevMode()) {
$types['js'][] = $this->getDevServerUrl($themePath . '.js');
$types['css'][] = $this->getDevServerUrl($themePath . '.css');
return $types;
}
$types['css'][] = $this->template->getViewFileUrl('dist/' . $themePath . '.css' );
return $types;
}
}