本文整理汇总了PHP中Magento\Framework\Filesystem\Directory\ReadInterface::readFile方法的典型用法代码示例。如果您正苦于以下问题:PHP ReadInterface::readFile方法的具体用法?PHP ReadInterface::readFile怎么用?PHP ReadInterface::readFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem\Directory\ReadInterface
的用法示例。
在下文中一共展示了ReadInterface::readFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: current
/**
* Current
*
* @return string
*/
public function current()
{
if (!isset($this->cached[$this->key()])) {
$this->cached[$this->key()] = $this->directoryRead->readFile($this->key());
}
return $this->cached[$this->key()];
}
示例2: getDictionary
/**
* Load and merge all phrases from language packs by specified code
*
* Takes into account inheritance between language packs
* Returns associative array where key is phrase in the source code and value is its translation
*
* @param string $languageCode
* @return array
*/
public function getDictionary($languageCode)
{
$languages = [];
$declarations = $this->dir->search('*/*/language.xml');
foreach ($declarations as $file) {
$xmlSource = $this->dir->readFile($file);
$languageConfig = $this->configFactory->create(['source' => $xmlSource]);
$this->packList[$languageConfig->getVendor()][$languageConfig->getPackage()] = $languageConfig;
if ($languageConfig->getCode() === $languageCode) {
$languages[] = $languageConfig;
}
}
// Collect the inherited packages with meta-information of sorting
$packs = [];
foreach ($languages as $languageConfig) {
$this->collectInheritedPacks($languageConfig, $packs);
}
uasort($packs, [$this, 'sortInherited']);
// Merge all packages of translation to one dictionary
$result = [];
foreach ($packs as $packInfo) {
/** @var Config $languageConfig */
$languageConfig = $packInfo['language'];
$dictionary = $this->readPackCsv($languageConfig->getVendor(), $languageConfig->getPackage());
$result = array_merge($result, $dictionary);
}
return $result;
}
示例3: get
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
switch ($scope) {
case 'global':
$iterator = $this->moduleReader->getConfigurationFiles($filename)->toArray();
$themeConfigFile = $this->currentTheme->getCustomization()->getCustomViewConfigPath();
if ($themeConfigFile && $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))) {
$iterator[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($themeConfigFile));
} else {
$designPath = $this->resolver->resolve(RulePool::TYPE_FILE, 'etc/view.xml', $this->area, $this->currentTheme);
if (file_exists($designPath)) {
try {
$designDom = new \DOMDocument();
$designDom->load($designPath);
$iterator[$designPath] = $designDom->saveXML();
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Could not read config file'));
}
}
}
break;
default:
$iterator = $this->iteratorFactory->create([]);
break;
}
return $iterator;
}
示例4: getContents
/**
* Returns contents of License file.
*
* @return string
*/
public function getContents()
{
if (!$this->dir->isFile(self::LICENSE_FILENAME)) {
return false;
}
return $this->dir->readFile(self::LICENSE_FILENAME);
}
示例5: getUrnDictionary
/**
* Get an array of URNs
*
* @param OutputInterface $output
* @return array
*/
private function getUrnDictionary(OutputInterface $output)
{
$files = $this->filesUtility->getXmlCatalogFiles('*.xml');
$files = array_merge($files, $this->filesUtility->getXmlCatalogFiles('*.xsd'));
$urns = [];
foreach ($files as $file) {
$content = $this->rootDirRead->readFile($this->rootDirRead->getRelativePath($file[0]));
$matches = [];
preg_match_all('/schemaLocation="(urn\\:magento\\:[^"]*)"/i', $content, $matches);
if (isset($matches[1])) {
$urns = array_merge($urns, $matches[1]);
}
}
$urns = array_unique($urns);
$paths = [];
foreach ($urns as $urn) {
try {
$paths[$urn] = $this->urnResolver->getRealPath($urn);
} catch (\Exception $e) {
// don't add unsupported element to array
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln($e->getMessage());
}
}
}
return $paths;
}
示例6: minify
/**
* Minify template file
*
* @param string $file
* @return void
*/
public function minify($file)
{
$file = $this->rootDirectory->getRelativePath($file);
$content = preg_replace('#(?<!]]>)\\s+</#', '</', preg_replace('#((?:<\\?php\\s+(?!echo|print|if|elseif|else)[^\\?]*)\\?>)\\s+#', '$1 ', preg_replace('#(?<!' . implode('|', $this->inlineHtmlTags) . ')\\> \\<#', '><', preg_replace('#(?ix)(?>[^\\S ]\\s*|\\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\\b))*+)' . '(?:<(?>textarea|pre|script)\\b|\\z))#', ' ', preg_replace('#(?<!:|\\\\|\'|")//(?!\\s*\\<\\!\\[)(?!\\s*]]\\>)[^\\n\\r]*#', '', preg_replace('#(?<!:)//[^\\n\\r]*(\\s\\?\\>)#', '$1', preg_replace('#//[^\\n\\r]*(\\<\\?php)[^\\n\\r]*(\\s\\?\\>)[^\\n\\r]*#', '', $this->rootDirectory->readFile($file))))))));
if (!$this->htmlDirectory->isExist()) {
$this->htmlDirectory->create();
}
$this->htmlDirectory->writeFile($file, rtrim($content));
}
示例7: getContents
/**
* Returns contents of License file.
*
* @return string|boolean
*/
public function getContents()
{
if ($this->dir->isFile(self::LICENSE_FILENAME)) {
return $this->dir->readFile(self::LICENSE_FILENAME);
} elseif ($this->dir->isFile(self::DEFAULT_LICENSE_FILENAME)) {
return $this->dir->readFile(self::DEFAULT_LICENSE_FILENAME);
} else {
return false;
}
}
示例8: downloadFileOption
/**
* Fetches and outputs file to user browser
* $info is array with following indexes:
* - 'path' - full file path
* - 'type' - mime type of file
* - 'size' - size of file
* - 'title' - user-friendly name of file (usually - original name as uploaded in Magento)
*
* @param \Magento\Framework\App\ResponseInterface $response
* @param string $filePath
* @param array $info
* @return bool
*/
public function downloadFileOption($response, $filePath, $info)
{
try {
$response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title'])->clearBody();
$response->sendHeaders();
echo $this->directory->readFile($this->directory->getRelativePath($filePath));
} catch (\Exception $e) {
return false;
}
return true;
}
示例9: getData
/**
* Get translation data
*
* @param string $themePath
* @return string[]
* @throws \Exception
* @throws \Magento\Framework\Exception
*/
public function getData($themePath)
{
$dictionary = [];
$files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath);
foreach ($files as $filePath) {
$content = $this->rootDirectory->readFile($this->rootDirectory->getRelativePath($filePath[0]));
foreach ($this->getPhrases($content) as $phrase) {
$translatedPhrase = (string) __($phrase);
if ($phrase != $translatedPhrase) {
$dictionary[$phrase] = $translatedPhrase;
}
}
}
return $dictionary;
}
示例10: read
/**
* Read Magento updater application jobs queue as a JSON string.
*
* @return string Queue file content (valid JSON string)
* @throws \RuntimeException
*/
public function read()
{
$queue = '';
if (!$this->reader->isExist($this->queueFileBasename)) {
return $queue;
}
$queueFileContent = $this->reader->readFile($this->queueFileBasename);
if ($queueFileContent) {
json_decode($queueFileContent);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException(sprintf('Content of "%s" must be a valid JSON.', $this->queueFileBasename));
}
$queue = $queueFileContent;
}
return $queue;
}
示例11: getComposerInfo
/**
* Checks existence of composer.lock and returns its contents
*
* @return array
* @throws \Exception
*/
private function getComposerInfo()
{
if (!$this->rootDir->isExist('composer.lock')) {
throw new \Exception('Cannot read \'composer.lock\' file');
}
return json_decode($this->rootDir->readFile('composer.lock'), true);
}
示例12: preProcess
/**
* Perform necessary preprocessing and materialization when the specified asset is requested
*
* Returns an array of two elements:
* - directory code where the file is supposed to be found
* - relative path to the file
*
* Automatically caches the obtained successful results or returns false if source file was not found
*
* @param LocalInterface $asset
* @return array|bool
*/
private function preProcess(LocalInterface $asset)
{
$sourceFile = $this->findSourceFile($asset);
$dirCode = DirectoryList::ROOT;
$path = $this->rootDir->getRelativePath($sourceFile);
$cacheId = $path . ':' . $asset->getPath();
$cached = $this->cache->load($cacheId);
if ($cached) {
return unserialize($cached);
}
$origContent = $path ? $this->rootDir->readFile($path) : '';
$origContentType = $this->getContentType($path) ?: $asset->getContentType();
$chain = $this->chainFactory->create(
[
'asset' => $asset,
'origContent' => $origContent,
'origContentType' => $origContentType,
'origAssetPath' => $path
]
);
$this->preProcessorPool->process($chain);
$chain->assertValid();
if ($chain->isChanged()) {
$dirCode = DirectoryList::VAR_DIR;
$path = DirectoryList::TMP_MATERIALIZATION_DIR . '/source/' . $chain->getTargetAssetPath();
$this->varDir->writeFile($path, $chain->getContent());
}
$result = [$dirCode, $path];
$this->cache->save(serialize($result), $cacheId);
return $result;
}
示例13: getContent
/**
* {@inheritdoc}
*/
public function getContent()
{
if (null === $this->path) {
$this->process();
}
return $this->staticViewDir->readFile($this->path);
}
示例14: getViewConfig
/**
* Render view config object for current package and theme
*
* @param array $params
* @return \Magento\Framework\Config\View
*/
public function getViewConfig(array $params = [])
{
$this->assetRepo->updateDesignParams($params);
/** @var $currentTheme \Magento\Framework\View\Design\ThemeInterface */
$currentTheme = $params['themeModel'];
$key = $currentTheme->getCode();
if (isset($this->viewConfigs[$key])) {
return $this->viewConfigs[$key];
}
$configFiles = $this->moduleReader->getConfigurationFiles(basename($this->filename))->toArray();
$themeConfigFile = $currentTheme->getCustomization()->getCustomViewConfigPath();
if (empty($themeConfigFile)
|| !$this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$themeConfigFile = $this->viewFileSystem->getFilename($this->filename, $params);
}
if ($themeConfigFile
&& $this->rootDirectory->isExist($this->rootDirectory->getRelativePath($themeConfigFile))
) {
$configFiles[$this->rootDirectory->getRelativePath($themeConfigFile)] = $this->rootDirectory->readFile(
$this->rootDirectory->getRelativePath($themeConfigFile)
);
}
$config = $this->viewFactory->create($configFiles);
$this->viewConfigs[$key] = $config;
return $config;
}
示例15: preProcess
/**
* Perform necessary preprocessing and materialization when the specified asset is requested
*
* Returns an array of two elements:
* - directory code where the file is supposed to be found
* - relative path to the file
*
* Automatically caches the obtained successful results or returns false if source file was not found
*
* @param LocalInterface $asset
* @return array|bool
*/
private function preProcess(LocalInterface $asset)
{
$sourceFile = $this->findSourceFile($asset);
if (!$sourceFile) {
return false;
}
$dirCode = \Magento\Framework\App\Filesystem::ROOT_DIR;
$path = $this->rootDir->getRelativePath($sourceFile);
$cacheId = $path . ':' . $asset->getPath();
$cached = $this->cache->load($cacheId);
if ($cached) {
return unserialize($cached);
}
$chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($asset, $this->rootDir->readFile($path), $this->getContentType($path));
$preProcessors = $this->preProcessorPool->getPreProcessors($chain->getOrigContentType(), $chain->getTargetContentType());
foreach ($preProcessors as $processor) {
$processor->process($chain);
}
$chain->assertValid();
if ($chain->isChanged()) {
$dirCode = \Magento\Framework\App\Filesystem::VAR_DIR;
$path = self::TMP_MATERIALIZATION_DIR . '/source/' . $asset->getPath();
$this->varDir->writeFile($path, $chain->getContent());
}
$result = array($dirCode, $path);
$this->cache->save(serialize($result), $cacheId);
return $result;
}