本文整理汇总了PHP中Magento\Framework\App\State类的典型用法代码示例。如果您正苦于以下问题:PHP State类的具体用法?PHP State怎么用?PHP State使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read
/**
* Read configuration by code
*
* @param string $code
* @return array
*/
public function read($code = null)
{
if ($this->_appState->isInstalled()) {
if (empty($code)) {
$store = $this->_storeManager->getStore();
} elseif ($code == \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT) {
$store = $this->_storeManager->getDefaultStoreView();
} else {
$store = $this->_storeFactory->create();
$store->load($code);
}
if (!$store->getCode()) {
throw NoSuchEntityException::singleField('storeCode', $code);
}
$websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, $store->getWebsite()->getCode())->getSource();
$config = array_replace_recursive($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
$collection = $this->_collectionFactory->create(array('scope' => \Magento\Store\Model\ScopeInterface::SCOPE_STORES, 'scopeId' => $store->getId()));
$dbStoreConfig = array();
foreach ($collection as $item) {
$dbStoreConfig[$item->getPath()] = $item->getValue();
}
$config = $this->_converter->convert($dbStoreConfig, $config);
} else {
$websiteConfig = $this->_scopePool->getScope(\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE, \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT)->getSource();
$config = $this->_converter->convert($websiteConfig, $this->_initialConfig->getData("stores|{$code}"));
}
return $config;
}
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode('catalog');
$connection = $this->attributeResource->getConnection();
$attributeTables = $this->getAttributeTables();
$progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables));
$progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%');
$this->attributeResource->beginTransaction();
try {
// Find and remove unused attributes
foreach ($attributeTables as $attributeTable) {
$progress->setMessage($attributeTable . ' ');
$affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable);
if (count($affectedIds) > 0) {
$connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]);
}
$progress->advance();
}
$this->attributeResource->commit();
$output->writeln("");
$output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
$output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>");
} catch (\Exception $exception) {
$this->attributeResource->rollBack();
$output->writeln("");
$output->writeln("<error>{$exception->getMessage()}</error>");
}
}
示例3: build
/**
* @param array $buildSubject
* @return mixed
*/
public function build(array $buildSubject)
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$order = $paymentDataObject->getOrder();
$storeId = $order->getStoreId();
$request = [];
if ($this->adyenHelper->getAdyenCcConfigDataFlag('cse_enabled', $storeId)) {
$request['additionalData']['card.encrypted.json'] = $payment->getAdditionalInformation("encrypted_data");
} else {
$requestCreditCardDetails = ["expiryMonth" => $payment->getCcExpMonth(), "expiryYear" => $payment->getCcExpYear(), "holderName" => $payment->getCcOwner(), "number" => $payment->getCcNumber(), "cvc" => $payment->getCcCid()];
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
}
/**
* if MOTO for backend is enabled use MOTO as shopper interaction type
*/
$enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE && $enableMoto) {
$request['shopperInteraction'] = "Moto";
}
// if installments is set add it into the request
if ($payment->getAdditionalInformation('number_of_installments') && $payment->getAdditionalInformation('number_of_installments') > 0) {
$request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments');
}
return $request;
}
示例4: get
/**
* Get config value by key
*
* @param null|string $path
* @param null|mixed $default
* @return null|mixed
*/
public function get($path = null, $default = null)
{
if (!$this->_appState->isInstalled() && !in_array($this->_configScope->getCurrentScope(), array('global', 'install'))) {
return $default;
}
return parent::get($path, $default);
}
示例5: 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);
}
示例6: 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];
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->appState->setAreaCode('catalog');
/** @var ProductCollection $productCollection */
$productCollection = $this->productCollectionFactory->create();
$productIds = $productCollection->getAllIds();
if (!count($productIds)) {
$output->writeln("<info>No product images to resize</info>");
return;
}
try {
foreach ($productIds as $productId) {
try {
/** @var Product $product */
$product = $this->productRepository->getById($productId);
} catch (NoSuchEntityException $e) {
continue;
}
/** @var ImageCache $imageCache */
$imageCache = $this->imageCacheFactory->create();
$imageCache->generate($product);
$output->write(".");
}
} catch (\Exception $e) {
$output->writeln("<error>{$e->getMessage()}</error>");
return;
}
$output->write("\n");
$output->writeln("<info>Product images resized successfully</info>");
}
示例8: testNotUnlockProcessInProductionMode
public function testNotUnlockProcessInProductionMode()
{
$this->stateMock->expects(self::exactly(2))->method('getMode')->willReturn(State::MODE_PRODUCTION);
$this->filesystemMock->expects(self::never())->method('getDirectoryWrite');
$this->lockerProcess->lockProcess(self::LOCK_NAME);
$this->lockerProcess->unlockProcess();
}
示例9: 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();
}
示例10: 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;
}
示例11: beforeLaunch
/**
* Perform required checks before cron run
*
* @param \Magento\Framework\App\Cron $subject
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws \Magento\Framework\Exception
*/
public function beforeLaunch(\Magento\Framework\App\Cron $subject)
{
$this->_sidResolver->setUseSessionInUrl(false);
if (false == $this->_appState->isInstalled()) {
throw new \Magento\Framework\Exception('Application is not installed yet, please complete the installation first.');
}
}
示例12: testWidgetDirective
/**
* @return void
*/
public function testWidgetDirective()
{
$result = 'some text';
$construction = ['{{widget type="Widget\\Link" anchor_text="Test" template="block.phtml" id_path="p/1"}}', 'widget', ' type="" anchor_text="Test" template="block.phtml" id_path="p/1"'];
$this->appStateMock->expects($this->once())->method('emulateAreaCode')->with('frontend', [$this->filterEmulate, 'generateWidget'], [$construction])->willReturn($result);
$this->assertSame($result, $this->filterEmulate->widgetDirective($construction));
}
示例13: 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));
}
}
示例14: 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());
}
}
示例15: load
/**
* Load design
*
* @return void
*/
public function load()
{
$area = $this->_areaList->getArea($this->appState->getAreaCode());
$area->load(\Magento\Framework\App\Area::PART_DESIGN);
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
$area->detectDesign($this->_request);
}