本文整理汇总了PHP中Magento\Framework\App\State::getMode方法的典型用法代码示例。如果您正苦于以下问题:PHP State::getMode方法的具体用法?PHP State::getMode怎么用?PHP State::getMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\State
的用法示例。
在下文中一共展示了State::getMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* @param string $sourceFilePath
* @return string
*/
public function process($sourceFilePath)
{
$options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
try {
$parser = new \Less_Parser($options);
$parser->parseFile($sourceFilePath, '');
return $parser->getCss();
} catch (\Exception $e) {
$messagePrefix = 'CSS compilation from LESS ';
$this->logger->critical($messagePrefix . $e->getMessage());
return $messagePrefix . $e->getMessage();
}
}
示例2: aroundRenderResult
/**
* @param \Magento\Framework\Controller\ResultInterface $subject
* @param callable $proceed
* @param ResponseHttp $response
* @return \Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response)
{
$result = $proceed($response);
$usePlugin = $this->registry->registry('use_page_cache_plugin');
if (!$usePlugin || !$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
return $result;
}
if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
$cacheControlHeader = $response->getHeader('Cache-Control');
if ($cacheControlHeader instanceof \Zend\Http\Header\HeaderInterface) {
$response->setHeader('X-Magento-Cache-Control', $cacheControlHeader->getFieldValue());
}
$response->setHeader('X-Magento-Cache-Debug', 'MISS', true);
}
$tagsHeader = $response->getHeader('X-Magento-Tags');
$tags = [];
if ($tagsHeader) {
$tags = explode(',', $tagsHeader->getFieldValue());
$response->clearHeader('X-Magento-Tags');
}
$tags = array_unique(array_merge($tags, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]));
$response->setHeader('X-Magento-Tags', implode(',', $tags));
$this->kernel->process($response);
return $result;
}
示例3: isEnabled
/**
* Check whether asset minification is on for specified content type
*
* @param string $contentType
* @return bool
*/
public function isEnabled($contentType)
{
if (!isset($this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType])) {
$this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType] = $this->appState->getMode() != State::MODE_DEVELOPER && (bool) $this->scopeConfig->isSetFlag(sprintf(self::XML_PATH_MINIFICATION_ENABLED, $contentType), $this->scope);
}
return $this->configCache[self::XML_PATH_MINIFICATION_ENABLED][$contentType];
}
示例4: ensureSourceFile
/**
* Make sure the aggregated configuration is materialized
*
* By default write the file if it doesn't exist, but in developer mode always do it.
*
* @param string $relPath
* @return void
*/
private function ensureSourceFile($relPath)
{
$dir = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER || !$dir->isExist($relPath)) {
$dir->writeFile($relPath, $this->config->getConfig());
}
}
示例5: process
/**
* @param string $sourceFilePath
* @return string
*/
public function process($sourceFilePath)
{
$options = ['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER];
$parser = new \Less_Parser($options);
$parser->parseFile($sourceFilePath, '');
return $parser->getCss();
}
示例6: testProcess
public function testProcess()
{
$sourceFilePath = realpath(__DIR__ . '/_files/oyejorge.less');
$expectedCss = $this->state->getMode() === State::MODE_DEVELOPER ? file_get_contents(__DIR__ . '/_files/oyejorge_dev.css') : file_get_contents(__DIR__ . '/_files/oyejorge.css');
$actualCss = $this->model->process($sourceFilePath);
$this->assertEquals($this->cutCopyrights($expectedCss), $actualCss);
}
示例7: getValue
/**
* Retrieve deployment version of static files
*
* @return string
*/
public function getValue()
{
if (!$this->cachedValue) {
$this->cachedValue = $this->readValue($this->appState->getMode());
}
return $this->cachedValue;
}
示例8: processContent
/**
* @inheritdoc
* @throws ContentProcessorException
*/
public function processContent(File $asset)
{
$path = $asset->getPath();
try {
$parser = new \Less_Parser(['relativeUrls' => false, 'compress' => $this->appState->getMode() !== State::MODE_DEVELOPER]);
$content = $this->assetSource->getContent($asset);
if (trim($content) === '') {
return '';
}
$tmpFilePath = $this->temporaryFile->createFile($path, $content);
gc_disable();
$parser->parseFile($tmpFilePath, '');
$content = $parser->getCss();
gc_enable();
if (trim($content) === '') {
$errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path;
$this->logger->critical($errorMessage);
throw new ContentProcessorException(new Phrase($errorMessage));
}
return $content;
} catch (\Exception $e) {
$errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
$this->logger->critical($errorMessage);
throw new ContentProcessorException(new Phrase($errorMessage));
}
}
示例9: _callObserverMethod
/**
* @param \Magento\Framework\Event\ObserverInterface $object
* @param Observer $observer
* @return $this
* @throws \LogicException
*/
protected function _callObserverMethod($object, $observer)
{
if ($object instanceof \Magento\Framework\Event\ObserverInterface) {
$object->execute($observer);
} elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
throw new \LogicException(sprintf('Observer "%s" must implement interface "%s"', get_class($object), 'Magento\\Framework\\Event\\ObserverInterface'));
}
return $this;
}
示例10: _callObserverMethod
/**
* Performs non-existent observer method calls protection
*
* @param object $object
* @param string $method
* @param Observer $observer
* @return $this
* @throws \LogicException
*/
protected function _callObserverMethod($object, $method, $observer)
{
if (method_exists($object, $method) && is_callable([$object, $method])) {
$object->{$method}($observer);
} elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
throw new \LogicException('Method "' . $method . '" is not defined in "' . get_class($object) . '"');
}
return $this;
}
示例11: afterToHtml
/**
* Wrap template with the debugging hints in comments
*
* @param Template $subject
* @param string $result
*
* @return string
*/
public function afterToHtml(Template $subject, $result)
{
if ($this->scopeConfig->getValue(self::XML_PATH_DEBUG_TEMPLATE_HINTS, ScopeInterface::SCOPE_STORE) && $this->appState->getMode() === State::MODE_DEVELOPER) {
$name = $subject->getNameInLayout();
$template = $subject->getTemplateFile();
$class = get_class($subject);
$result = "<!-- BEGIN {$name} using {$template} \n" . $class . '-->' . $result . "<!-- END {$name} using {$template} -->";
}
return $result;
}
示例12: beforeDispatch
/**
* Add new theme from filesystem
*
* @param AbstractAction $subject
* @param RequestInterface $request
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeDispatch(AbstractAction $subject, RequestInterface $request)
{
try {
if ($this->appState->getMode() != AppState::MODE_PRODUCTION) {
$this->themeRegistration->register();
}
} catch (LocalizedException $e) {
$this->logger->critical($e);
}
}
示例13: aroundDispatch
/**
* @param \Magento\Framework\App\FrontControllerInterface $subject
* @param callable $proceed
* @param \Magento\Framework\App\RequestInterface $request
* @return false|\Magento\Framework\App\Response\Http|\Magento\Framework\Controller\ResultInterface
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
{
$response = $proceed($request);
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled() && $response instanceof \Magento\Framework\App\Response\Http) {
$this->version->process();
if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
$response->setHeader('X-Magento-Debug', 1);
}
}
return $response;
}
示例14: publish
/**
* {@inheritdoc}
*/
public function publish(Asset\LocalInterface $asset)
{
if ($this->appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) {
return false;
}
$dir = $this->filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::STATIC_VIEW_DIR);
if ($dir->isExist($asset->getPath())) {
return true;
}
return $this->publishAsset($asset);
}
示例15: aroundRenderResult
/**
* @param \Magento\Framework\Controller\ResultInterface $subject
* @param callable $proceed
* @param ResponseHttp $response
* @return \Magento\Framework\Controller\ResultInterface
*/
public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response)
{
$proceed($response);
$usePlugin = $this->registry->registry('use_page_cache_plugin');
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled() && $usePlugin) {
$this->version->process();
if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
$response->setHeader('X-Magento-Debug', 1);
}
}
return $subject;
}