/** * Get storage instance * * @param array $arguments * @return \Magento\Store\Model\StoreManagerInterface * @throws \InvalidArgumentException */ public function get(array $arguments = array()) { $className = $this->_appState->isInstalled() ? $this->_installedStorageClassName : $this->_defaultStorageClassName; if (false == isset($this->_cache[$className])) { /** @var $storage \Magento\Store\Model\StoreManagerInterface */ $storage = $this->_objectManager->create($className, $arguments); if (false === $storage instanceof \Magento\Store\Model\StoreManagerInterface) { throw new \InvalidArgumentException($className . ' doesn\'t implement \\Magento\\Store\\Model\\StoreManagerInterface'); } $this->_cache[$className] = $storage; if ($className === $this->_installedStorageClassName) { $this->_reinitStores($storage, $arguments); $useSid = $this->_scopeConfig->isSetFlag(\Magento\Framework\Session\SidResolver::XML_PATH_USE_FRONTEND_SID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storage->getStore()); $this->_sidResolver->setUseSessionInUrl($useSid); $this->_eventManager->dispatch('core_app_init_current_store_after'); $store = $storage->getStore(true); $logActive = $this->_scopeConfig->isSetFlag('dev/log/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); if ($logActive || $this->_appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) { $logFile = $this->_scopeConfig->getValue('dev/log/file', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); $logExceptionFile = $this->_scopeConfig->getValue('dev/log/exception_file', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); $this->_log->unsetLoggers(); $this->_log->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM, $logFile, $this->_writerModel); $this->_log->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION, $logExceptionFile, $this->_writerModel); } } } return $this->_cache[$className]; }
public function testUnsetLoggers() { $key = 'test'; $fileOrWrapper = 'custom_file.log'; $this->model->addStreamLog($key, $fileOrWrapper); $this->assertTrue($this->model->hasLog($key)); $this->model->unsetLoggers(); $this->assertFalse($this->model->hasLog($key)); }
/** * Create package file compatible with previous version of Magento Connect Manager * * @return boolean */ public function createPackageV1x() { try { $this->writeDirectory->create('pear/'); } catch (\Magento\Framework\Filesystem\FilesystemException $e) { $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION); $this->logger->log($e->getMessage()); return false; } if (!$this->getPackageXml()) { $this->generatePackageXml(); } $this->getPackage()->saveV1x($this->writeDirectory->getAbsolutePath('pear/')); return true; }
/** * Build menu model from config * * @return \Magento\Backend\Model\Menu * @throws \Exception|\InvalidArgumentException * @throws \Exception * @throws \BadMethodCallException|\Exception * @throws \Exception|\OutOfRangeException */ public function getMenu() { if ($this->_scopeConfig->getValue('dev/log/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) { $this->_logger->addStreamLog(\Magento\Backend\Model\Menu::LOGGER_KEY); } try { $this->_initMenu(); return $this->_menu; } catch (\InvalidArgumentException $e) { $this->_logger->logException($e); throw $e; } catch (\BadMethodCallException $e) { $this->_logger->logException($e); throw $e; } catch (\OutOfRangeException $e) { $this->_logger->logException($e); throw $e; } catch (\Exception $e) { throw $e; } }
/** * Create destination folder if not exists and return full file path * * @param string $destination * @param string $newName * @return string * @throws \Exception */ protected function _prepareDestination($destination = null, $newName = null) { if (empty($destination)) { $destination = $this->_fileSrcPath; } else { if (empty($newName)) { $info = pathinfo($destination); $newName = $info['basename']; $destination = $info['dirname']; } } if (empty($newName)) { $newFileName = $this->_fileSrcName; } else { $newFileName = $newName; } $fileName = $destination . '/' . $newFileName; if (!is_writable($destination)) { try { $this->directoryWrite->create($this->directoryWrite->getRelativePath($destination)); } catch (\Magento\Framework\Filesystem\FilesystemException $e) { $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM); $this->logger->log($e->getMessage()); throw new \Exception('Unable to write file into directory ' . $destination . '. Access forbidden.'); } } return $fileName; }
/** * Validate merged layout * * @param string $cacheId * @param string $layout * @return $this */ protected function _validateMergedLayout($cacheId, $layout) { $layoutStr = '<handle id="handle">' . $layout . '</handle>'; if ($this->_appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) { if (!$this->_layoutValidator->isValid($layoutStr, Validator::LAYOUT_SCHEMA_MERGED, false)) { $messages = $this->_layoutValidator->getMessages(); //Add first message to exception $message = reset($messages); $this->_logger->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM); $this->_logger->log('Cache file with merged layout: ' . $cacheId . ': ' . $message, \Zend_Log::ERR); } } return $this; }
/** * Load layout updates by handles * * @param array|string $handles * @throws \Magento\Framework\Exception * @return $this */ public function load($handles = array()) { if (is_string($handles)) { $handles = array($handles); } elseif (!is_array($handles)) { throw new \Magento\Framework\Exception('Invalid layout update handle'); } $this->addHandle($handles); $cacheId = $this->_getCacheId(md5(implode('|', $this->getHandles()))); $result = $this->_loadCache($cacheId); if ($result) { $this->addUpdate($result); return $this; } foreach ($this->getHandles() as $handle) { $this->_merge($handle); } $layout = $this->asString(); $layoutStr = '<handle id="handle">' . $layout . '</handle>'; if ($this->_appState->getMode() === \Magento\Framework\App\State::MODE_DEVELOPER) { if (!$this->_layoutValidator->isValid($layoutStr, \Magento\Core\Model\Layout\Update\Validator::LAYOUT_SCHEMA_MERGED, false)) { $messages = $this->_layoutValidator->getMessages(); //Add first message to exception $message = array_shift($messages); $this->_logger->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM); $this->_logger->log('Cache file with merged layout: ' . $cacheId . ': ' . $message, \Zend_Log::ERR); } } $this->_saveCache($layout, $cacheId, $this->getHandles()); return $this; }