本文整理汇总了PHP中Magento\Framework\App\State::setAreaCode方法的典型用法代码示例。如果您正苦于以下问题:PHP State::setAreaCode方法的具体用法?PHP State::setAreaCode怎么用?PHP State::setAreaCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\State
的用法示例。
在下文中一共展示了State::setAreaCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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>");
// we must have an exit code higher than zero to indicate something was wrong
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
}
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>");
// we must have an exit code higher than zero to indicate something was wrong
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
}
$output->write("\n");
$output->writeln("<info>Product images resized successfully</info>");
}
示例2: 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>");
}
示例3: 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>");
}
}
示例4: launch
/**
* Run application
*
* @return ResponseInterface
*/
public function launch()
{
$this->_state->setAreaCode('crontab');
$this->_eventManager->dispatch('default');
$this->_response->setCode(0);
return $this->_response;
}
示例5: testEmulateAreaCodeException
/**
* @expectedException \Exception
* @expectedExceptionMessage Some error
*/
public function testEmulateAreaCodeException()
{
$areaCode = 'original code';
$emulatedCode = 'emulated code';
$this->scopeMock->expects($this->once())->method('setCurrentScope')->with($areaCode);
$this->model->setAreaCode($areaCode);
$this->model->emulateAreaCode($emulatedCode, [$this, 'emulateAreaCodeCallbackException']);
$this->assertEquals($this->model->getAreaCode(), $areaCode);
}
示例6: launch
/**
* {@inheritdoc}
**/
public function launch()
{
$areaCode = 'adminhtml';
$this->appState->setAreaCode($areaCode);
$this->objectManager->configure($this->configLoader->load($areaCode));
/** @var \Magento\Tools\SampleData\Logger $sampleDataLogger */
$sampleDataLogger = $this->objectManager->get('Magento\\Tools\\SampleData\\Logger');
$sampleDataLogger->setSubject($this->objectManager->get('Magento\\Setup\\Model\\ConsoleLogger'));
$this->installer->run($this->userFactory->create()->loadByUsername($this->adminUserName));
return $this->response;
}
示例7: launch
/**
* Run application
*
* @return ResponseInterface
*/
public function launch()
{
$this->_state->setAreaCode(Area::AREA_CRONTAB);
$configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
$this->objectManager->configure($configLoader->load(Area::AREA_CRONTAB));
/** @var \Magento\Framework\Event\ManagerInterface $eventManager */
$eventManager = $this->objectManager->get('Magento\\Framework\\Event\\ManagerInterface');
$eventManager->dispatch('default');
$this->_response->setCode(0);
return $this->_response;
}
示例8: execute
/**
* {@inheritdoc}
* @throws \InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$locale = $input->getOption(self::LOCALE_OPTION);
if (!$this->validator->isValid($locale)) {
throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales');
}
$area = $input->getOption(self::AREA_OPTION);
$theme = $input->getOption(self::THEME_OPTION);
$type = $input->getArgument(self::TYPE_ARGUMENT);
$this->state->setAreaCode($area);
$this->objectManager->configure($this->configLoader->load($area));
$sourceFileGenerator = $this->sourceFileGeneratorPool->create($type);
foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) {
$file .= '.' . $type;
$output->writeln("<info>Gathering {$file} sources.</info>");
$asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]);
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
$sourceFile = $this->assetSource->findSource($asset);
$relativePath = $rootDir->getRelativePath($sourceFile);
$content = $rootDir->readFile($relativePath);
$chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]);
$processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
$source = $rootDir->getRelativePath($processedCoreFile);
$destination = $asset->getPath();
$rootDir->copyFile($source, $destination, $targetDir);
$output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>");
}
}
示例9: launch
/**
* Run application
*
* @return \Magento\Framework\App\ResponseInterface
*/
public function launch()
{
$areaCode = 'install';
$this->_state->setAreaCode($areaCode);
$this->_objectManager->configure($this->_loader->load($areaCode));
if (isset($this->_arguments['uninstall'])) {
$sessionConsole = $this->_objectManager->create('\\Magento\\Framework\\Session\\SessionConsole');
$installerModel = $this->_objectManager->create('Magento\\Install\\Model\\Installer', ['session' => $sessionConsole]);
$installer = $this->_installerFactory->create(['installArgs' => $this->_arguments, 'installer' => $installerModel]);
} else {
$installer = $this->_installerFactory->create(array('installArgs' => $this->_arguments));
}
if (isset($this->_arguments['show_locales'])) {
$this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableLocales()));
} elseif (isset($this->_arguments['show_currencies'])) {
$this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableCurrencies()));
} elseif (isset($this->_arguments['show_timezones'])) {
$this->_output->readableOutput($this->_output->prepareArray($installer->getAvailableTimezones()));
} elseif (isset($this->_arguments['show_install_options'])) {
$this->_output->readableOutput(PHP_EOL . 'Required parameters:');
$this->_output->readableOutput($this->_output->alignArrayKeys($installer->getRequiredParams()));
$this->_output->readableOutput(PHP_EOL . 'Optional parameters:');
$this->_output->readableOutput($this->_output->alignArrayKeys($installer->getOptionalParams()));
$this->_output->readableOutput(PHP_EOL . 'Flag values are considered positive if set to 1, y, true or yes.' . 'Any other value is considered as negative.' . PHP_EOL);
} else {
$this->_handleInstall($installer);
}
$this->_response->setCode(0);
return $this->_response;
}
示例10: launch
/**
* Finds requested resource and provides it to the client
*
* @return \Magento\Framework\App\ResponseInterface
* @throws \Exception
*/
public function launch()
{
$appMode = $this->state->getMode();
if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) {
$this->response->setHttpResponseCode(404);
} else {
try {
$path = $this->request->get('resource');
$params = $this->parsePath($path);
$this->state->setAreaCode($params['area']);
$this->objectManager->configure($this->configLoader->load($params['area']));
$file = $params['file'];
unset($params['file']);
$asset = $this->assetRepo->createAsset($file, $params);
$this->response->setFilePath($asset->getSourceFile());
$this->publisher->publish($asset);
} catch (\Exception $e) {
if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
throw $e;
}
$this->response->setHttpResponseCode(404);
}
}
return $this->response;
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
//
// /** @var \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory */
// $eavSetupFactory = $objectManager->get('Magento\Eav\Setup\EavSetupFactory');
//
// $setup = $objectManager->get('Magento\Framework\Setup\ModuleDataSetupInterface');
//
// $eavSetup = $eavSetupFactory->create(['setup' => $setup]);
//
// for ($i = 1; $i < 400; $i++) {
// $eavSetup->addAttribute(
// \Magento\Catalog\Model\Product::ENTITY,
// substr(md5($i), 0, 5) . '_sample_attribute_' . $i,
// [
// 'type' => 'int',
// 'backend' => '',
// 'frontend' => '',
// 'label' => 'Sample Atrribute ' . $i,
// 'input' => '',
// 'class' => '',
// 'source' => '',
// 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
// 'visible' => true,
// 'required' => false,
// 'user_defined' => true,
// 'default' => '',
// 'searchable' => true,
// 'filterable' => true,
// 'comparable' => true,
// 'visible_on_front' => true,
// 'used_in_product_listing' => true,
// 'unique' => false,
// 'apply_to' => ''
// ]
// );
//
// echo $i . PHP_EOL;
// }
//
// die();
try {
$this->appState->setAreaCode('frontend');
} catch (\Exception $e) {
}
$collection = $this->indexCollectionFactory->create()->addFieldToFilter('is_active', 1);
/** @var \Mirasvit\Search\Model\Index $index */
foreach ($collection as $index) {
$output->write($index->getTitle() . ' [' . $index->getCode() . ']....');
try {
$index->getIndexInstance()->reindexAll();
$output->writeln("<info>Done</info>");
} catch (\Exception $e) {
$output->writeln("Error");
$output->writeln($e->getMessage());
}
}
}
示例12: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return null|int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->input = $input;
$this->output = $output;
try {
$area = $this->appState->getAreaCode();
if ($area != Area::AREA_ADMINHTML) {
$this->appState->setAreaCode(Area::AREA_ADMINHTML);
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->appState->setAreaCode(Area::AREA_ADMINHTML);
}
$area = $this->appState->getAreaCode();
$configLoader = $this->objectManager->get('Magento\\Framework\\ObjectManager\\ConfigLoaderInterface');
$this->objectManager->configure($configLoader->load($area));
$this->registry->register('isSecureArea', true);
}
示例13: __construct
public function __construct(ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, AppState $appState)
{
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
try {
$appState->setAreaCode('adminhtml');
} catch (\Exception $e) {
}
}
示例14: __construct
/**
* Productlist constructor.
* @param ProductTypeListInterface $productTypeList
* @param ProductRepositoryInterface $productRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param Status $productStatus
* @param \Magento\Framework\App\State $appState
*/
public function __construct(ProductTypeListInterface $productTypeList, ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, Status $productStatus, State $appState)
{
$this->productTypeList = $productTypeList;
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->productStatus = $productStatus;
// Fixes error that area code should be set when using active filter
$appState->setAreaCode('console');
}
示例15: launch
/**
* Run application
*
* @return ResponseInterface
*/
public function launch()
{
$areaCode = $this->_areaList->getCodeByFrontName($this->_request->getFrontName());
$this->_state->setAreaCode($areaCode);
$this->_objectManager->configure($this->_configLoader->load($areaCode));
$this->_response = $this->_objectManager->get('Magento\\Framework\\App\\FrontControllerInterface')->dispatch($this->_request);
// This event gives possibility to launch something before sending output (allow cookie setting)
$eventParams = array('request' => $this->_request, 'response' => $this->_response);
$this->_eventManager->dispatch('controller_front_send_response_before', $eventParams);
return $this->_response;
}