本文整理汇总了PHP中yii\helpers\FileHelper::localize方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::localize方法的具体用法?PHP FileHelper::localize怎么用?PHP FileHelper::localize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\FileHelper
的用法示例。
在下文中一共展示了FileHelper::localize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getText
public function getText()
{
$file = FileHelper::localize($this->textFile);
// FileHelper::getMimeType()
$f = file('uploads/' . $file->name);
return $f;
}
示例2: renderFile
public function renderFile($viewFile, $params = array(), $context = null)
{
$viewFile = \Yii::getAlias($viewFile);
if ($this->theme !== null) {
$viewFile = $this->theme->applyTo($viewFile);
}
if (is_file($viewFile)) {
$viewFile = \yii\helpers\FileHelper::localize($viewFile);
} else {
throw new \yii\base\InvalidParamException("The view file does not exist: {$viewFile}");
}
$oldContext = $this->context;
if ($context !== null) {
$this->context = $context;
}
$output = '';
if ($this->beforeRender($viewFile)) {
$ext = pathinfo($viewFile, PATHINFO_EXTENSION);
if (isset($this->renderers[$ext])) {
if (is_array($this->renderers[$ext])) {
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
}
/** @var ViewRenderer $renderer */
$renderer = $this->renderers[$ext];
$output = $renderer->render($this, $viewFile, $params);
} else {
$output = $this->renderPhpFile($viewFile, $params);
}
$this->afterRender($viewFile, $output);
}
$this->context = $oldContext;
return $output;
}
示例3: renderFile
/**
* Renders a view file.
*
* If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
* as it is available.
*
* The method will call [[FileHelper::localize()]] to localize the view file.
*
* If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
* Otherwise, it will simply include the view file as a normal PHP file, capture its output and
* return it as a string.
*
* @param string $viewFile
* the view file. This can be either an absolute file path or an alias of it.
* @param array $params
* the parameters (name-value pairs) that will be extracted and made available in the view file.
* @param object $context
* the context that the view should use for rendering the view. If null,
* existing [[context]] will be used.
* @return string the rendering result
* @throws InvalidParamException if the view file does not exist
*/
public function renderFile($viewFile, $params = [], $context = null)
{
$viewFile = $this->findViewFileByDefault($viewFile);
if (is_file($viewFile)) {
$viewFile = FileHelper::localize($viewFile);
} else {
throw new InvalidParamException("The view file does not exist: {$viewFile}");
}
$oldContext = $this->context;
if ($context !== null) {
$this->context = $context;
}
$output = '';
$this->_viewFiles[] = $viewFile;
if ($this->beforeRender($viewFile, $params)) {
Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
$ext = pathinfo($viewFile, PATHINFO_EXTENSION);
if (isset($this->renderers[$ext])) {
if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
}
/* @var $renderer ViewRenderer */
$renderer = $this->renderers[$ext];
$output = $renderer->render($this, $viewFile, $params);
} else {
$output = $this->renderPhpFile($viewFile, $params);
}
$this->afterRender($viewFile, $params, $output);
}
array_pop($this->_viewFiles);
$this->context = $oldContext;
return $output;
}
示例4: findViewFile
/**
* Changes:
*
* * if view file does not exist, find view file using $this as context.
*
* @inheritdoc
*/
protected function findViewFile($view, $context = null)
{
$path = parent::findViewFile($view, $context);
if ($this->theme !== null) {
$path = $this->theme->applyTo($path);
}
if (!is_file($path)) {
//find default view file
return $this->findDefaultViewFile($view, $context);
}
return FileHelper::localize($path);
}
示例5: renderFile
/**
* Renders a view file.
*
* If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long
* as it is available.
*
* The method will call [[FileHelper::localize()]] to localize the view file.
*
* If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file.
* Otherwise, it will simply include the view file as a normal PHP file, capture its output and
* return it as a string.
*
* @param string $viewFile the view file. This can be either an absolute file path or an alias of it.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @param object $context the context that the view should use for rendering the view. If null,
* existing [[context]] will be used.
* @return string the rendering result
* @throws InvalidParamException if the view file does not exist
*/
public function renderFile($viewFile, $params = [], $context = null)
{
$viewFile = Yii::getAlias($viewFile);
if ($this->theme !== null) {
$viewFile = $this->theme->applyTo($viewFile);
}
if (is_file($viewFile)) {
$viewFile = FileHelper::localize($viewFile);
} else {
if (strpos($viewFile, $context->getViewPath()) === 0) {
$viewFile = Yii::getAlias('@kalibao/views') . substr($viewFile, strlen($context->getViewPath()), strlen($viewFile));
}
if (!is_file($viewFile)) {
throw new InvalidParamException("The view file does not exist: {$viewFile}");
}
}
$oldContext = $this->context;
if ($context !== null) {
$this->context = $context;
}
$output = '';
$this->viewFiles[] = $viewFile;
if ($this->beforeRender($viewFile, $params)) {
Yii::trace("Rendering view file: {$viewFile}", __METHOD__);
$ext = pathinfo($viewFile, PATHINFO_EXTENSION);
if (isset($this->renderers[$ext])) {
if (is_array($this->renderers[$ext]) || is_string($this->renderers[$ext])) {
$this->renderers[$ext] = Yii::createObject($this->renderers[$ext]);
}
/* @var $renderer ViewRenderer */
$renderer = $this->renderers[$ext];
$output = $renderer->render($this, $viewFile, $params);
} else {
$output = $this->renderPhpFile($viewFile, $params);
}
$this->afterRender($viewFile, $params, $output);
}
array_pop($this->viewFiles);
$this->context = $oldContext;
return $output;
}
示例6: generateIndexYii1
protected function generateIndexYii1($source, $target, $version, $language, $type = 'guide')
{
$this->stdout('populating elasticsearch index...');
try {
// first delete all records for this version
$version = $this->version;
$chapters = [];
$sections = [];
$file = "{$source}/toc.txt";
$file = FileHelper::localize($file, $language, 'en');
$lines = file($file);
$chapter = '';
foreach ($lines as $line) {
// trim unicode BOM from line
$line = trim(ltrim($line, ""));
if ($line === '') {
continue;
}
if ($line[0] === '*') {
$chapter = trim($line, '* ');
} else {
if ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
$chapters[$chapter][$matches[1]] = $matches[2];
$sections[$matches[2]] = [$chapter, $matches[1]];
// elasticsearch
$file = $target . '/' . $matches[2] . '.html';
if (!file_exists($file)) {
echo "file not found: {$file}\n";
continue;
}
$html = file_get_contents($file);
SearchGuideSection::createRecord(basename($file, '.html'), $matches[1], $html, $this->version, $this->language, $type);
}
}
}
$file = $type == 'blog' ? "{$source}/start.overview.txt" : "{$source}/index.txt";
$file = FileHelper::localize($file, $language, 'en');
$lines = file($file);
if (($title = trim($lines[0])) === '') {
$title = $type == 'blog' ? 'Building a Blog System Using Yii' : 'The Definitive Guide for Yii';
}
$title = str_replace('Yii', "Yii {$version}", $title);
FileHelper::createDirectory($target);
file_put_contents("{$target}/index.data", serialize([$title, $chapters, $sections]));
$this->stdout("done.\n", Console::FG_GREEN);
} catch (\Exception $e) {
if (YII_DEBUG) {
$this->stdout("!!! FAILED !!! Search will not be available.\n", Console::FG_RED, Console::BOLD);
$this->stdout((string) $e . "\n\n");
} else {
throw $e;
}
}
}
示例7: testLocalizedDirectory
public function testLocalizedDirectory()
{
$this->createFileStructure(['views' => ['faq.php' => 'English FAQ', 'de-DE' => ['faq.php' => 'German FAQ']]]);
$viewFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'faq.php';
$sourceLanguage = 'en-US';
// Source language and target language are same. The view path should be unchanged.
$currentLanguage = $sourceLanguage;
$this->assertSame($viewFile, FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
// Source language and target language are different. The view path should be changed.
$currentLanguage = 'de-DE';
$this->assertSame($this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $currentLanguage . DIRECTORY_SEPARATOR . 'faq.php', FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage));
}
示例8: getToc
public function getToc()
{
if ($this->_toc === null) {
$file = $this->basePath . DIRECTORY_SEPARATOR . $this->tocFile . '.txt';
$file = FileHelper::localize($file, $this->language, 'en');
$lines = file($file);
$chapter = '';
foreach ($lines as $line) {
// trim unicode BOM from line
$line = trim(ltrim($line, ""));
if ($line === '') {
continue;
}
if ($line[0] === '*') {
$chapter = trim($line, '* ');
} elseif ($line[0] === '-' && preg_match('/\\[(.*?)\\]\\((.*?)\\)/', $line, $matches)) {
$this->_toc[$chapter][$matches[1]] = $matches[2];
$this->_sections[$matches[2]] = array($chapter, $matches[1]);
}
}
}
return $this->_toc;
}