本文整理汇总了PHP中yii\helpers\FileHelper::normalizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::normalizePath方法的具体用法?PHP FileHelper::normalizePath怎么用?PHP FileHelper::normalizePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\FileHelper
的用法示例。
在下文中一共展示了FileHelper::normalizePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionGenerate
/**
* Сгенерировать карту классов для автоподгрузки.
*/
public function actionGenerate()
{
$root = '@app';
$root = Yii::getAlias($root);
$root = FileHelper::normalizePath($root);
$mapFile = '@app/config/classes.php';
$mapFile = Yii::getAlias($mapFile);
$options = ['filter' => function ($path) {
if (is_file($path)) {
$file = basename($path);
if ($file[0] < 'A' || $file[0] > 'Z') {
return false;
}
}
return;
}, 'only' => ['*.php'], 'except' => ['/views/', '/vendor/', '/config/', '/tests/']];
$files = FileHelper::findFiles($root, $options);
$map = [];
foreach ($files as $file) {
if (strpos($file, $root) !== 0) {
throw new \Exception("Something wrong: {$file}\n");
}
$path = str_replace('\\', '/', substr($file, strlen($root)));
$map['app' . substr(str_replace('/', '\\', $path), 0, -4)] = $file;
}
$this->generateMapFile($mapFile, $map);
}
示例2: init
/**
* @inheritdoc
*/
public function init()
{
if ($this->path === null) {
throw new InvalidConfigException("Empty \"{$this->path}\".");
}
$this->path = FileHelper::normalizePath($this->path) . DIRECTORY_SEPARATOR;
}
示例3: applyTo
/**
* @inheritdoc
*/
public function applyTo($path)
{
$pathMap = $this->pathMap;
if (empty($pathMap)) {
if (($basePath = $this->getBasePath()) === null) {
throw new InvalidConfigException('The "basePath" property must be set.');
}
$pathMap = [Yii::$app->getBasePath() => [$basePath]];
}
$module = Yii::$app->controller->module;
if (!$module instanceof \yii\web\Application) {
$pathMap['@app/modules/' . $module->id . '/views'] = [$pathMap['@app/views'][0] . '/' . $module->id];
}
#debug
// echo '<pre>';
// print_r(Yii::$app->controller->module);
// echo '</pre>';
#end debug
#debug
echo '<pre>';
print_r($pathMap);
echo '</pre>';
#end debug
$path = FileHelper::normalizePath($path);
#debug
echo 'path: ', $path, '<br/>';
#end debug
foreach ($pathMap as $from => $tos) {
$from = FileHelper::normalizePath(Yii::getAlias($from)) . DIRECTORY_SEPARATOR;
#debug
echo 'from: ', $from, '<br/>';
#end debug
if (strpos($path, $from) === 0) {
$n = strlen($from);
foreach ((array) $tos as $to) {
$to = FileHelper::normalizePath(Yii::getAlias($to)) . DIRECTORY_SEPARATOR;
#debug
echo 'to: ', $to, '<br/>';
#end debug
$file = $to . substr($path, $n);
if (is_file($file)) {
#debug
echo 'return file: ', $file, '<br/>';
if (strpos($path, 'layouts')) {
exit;
}
#end debug
return $file;
}
}
}
}
#debug
echo 'return path: ', $path, '<br/>';
if (strpos($path, 'layouts')) {
exit;
}
#end debug
return $path;
}
示例4: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->uploadDir = !empty(\Yii::$app->getModule('core')->fileUploadPath) ? \Yii::$app->getModule('core')->fileUploadPath : $this->uploadDir;
$this->uploadDir = FileHelper::normalizePath(\Yii::getAlias($this->uploadDir));
$this->additionalRenderData['uploadDir'] = $this->uploadDir;
}
示例5: getFromUrl
/**
* Returns UploadFile created from url
* Notice that this file cannot be saved by move_uploaded_file
* @param $url
* @throws \yii\base\InvalidConfigException
*/
public static function getFromUrl($url)
{
$tmpFile = null;
if (static::isExternalUrl($url)) {
//External url
$tmpFile = static::downloadToTmp($url);
} else {
//File must be in static folder
$staticPath = Yii::getAlias('@static/');
$path = str_replace(Yii::getAlias('@staticUrl/'), Yii::getAlias('@static/'), Yii::getAlias($url), $count);
//If we can replace static url to path
if ($count > 0) {
//Check staticPath after normalize
$path = FileHelper::normalizePath($path);
if (strpos($path, $staticPath) === 0) {
if (file_exists($path)) {
$tmpFile = tempnam(sys_get_temp_dir(), 'CURL');
if (!copy($path, $tmpFile)) {
$tmpFile = null;
}
}
}
}
}
if ($tmpFile) {
return new static(['name' => basename($url), 'tempName' => $tmpFile, 'type' => FileHelper::getMimeType($tmpFile), 'size' => filesize($tmpFile), 'error' => UPLOAD_ERR_OK]);
}
return null;
}
示例6: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->uploadDir = Yii::$app->getModule('core')->visitorsFileUploadPath;
$this->uploadDir = FileHelper::normalizePath(Yii::getAlias($this->uploadDir));
$this->additionalRenderData['uploadDir'] = $this->uploadDir;
}
示例7: run
public function run($id)
{
$id = (int) $id;
$userId = Adver::getUserIdFromAdver($id);
$output = [];
if ($userId != Yii::$app->getUser()->id) {
$output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'The requested page does not exist.') . '</div>'];
}
if (empty($output) && !Gallery::checkLimitation($id)) {
$output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'Image limitation per advertisement reached!') . '</div>'];
}
if (empty($output)) {
$model = new Gallery(['scenario' => 'new']);
if ($model->load(Yii::$app->request->post())) {
$model->image = UploadedFile::getInstance($model, 'image');
if ($model->image) {
$model->name = Yii::$app->helper->safeFile($model->image->baseName) . '-' . Yii::$app->getSecurity()->generateRandomString(6) . '-' . time() . '.' . $model->image->extension;
$path = $model->getImagePath($id) . DIRECTORY_SEPARATOR . $model->name;
$path = FileHelper::normalizePath($path);
$model->adver_id = $id;
if ($model->validate() && $model->image->saveAs($path, false)) {
if ($model->save()) {
$output = ['error' => false, 'message' => '<div class="alert alert-success">' . Yii::t('app', 'Image saved!') . '</div>'];
} else {
$output = ['error' => true, 'message' => '<div class="alert alert-danger">' . Yii::t('app', 'Error on saving image.') . '</div>'];
}
}
}
}
if (empty($output)) {
$output = ['error' => true, 'message' => \yii\helpers\Html::errorSummary($model, ["class" => "alert alert-danger"])];
}
}
return \yii\helpers\Json::encode($output);
}
示例8: attach
/**
* @inheritdoc
*/
public function attach($owner)
{
parent::attach($owner);
if (!is_array($this->attributes) || empty($this->attributes)) {
throw new InvalidParamException('Invalid or empty attributes array.');
} else {
foreach ($this->attributes as $attribute => $config) {
if (!isset($config['path']) || empty($config['path'])) {
throw new InvalidParamException('Path must be set for all attributes.');
}
if (!isset($config['tempPath']) || empty($config['tempPath'])) {
throw new InvalidParamException('Temporary path must be set for all attributes.');
}
if (!isset($config['url']) || empty($config['url'])) {
$config['url'] = $this->publish($config['path']);
}
$this->attributes[$attribute]['path'] = FileHelper::normalizePath(Yii::getAlias($config['path'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['tempPath'] = FileHelper::normalizePath(Yii::getAlias($config['tempPath'])) . DIRECTORY_SEPARATOR;
$this->attributes[$attribute]['url'] = rtrim($config['url'], '/') . '/';
$validator = Validator::createValidator('string', $this->owner, $attribute);
$this->owner->validators[] = $validator;
unset($validator);
}
}
}
示例9: isPhpSafe
/**
* @inheritdoc
* @param \yii\gii\CodeFile $file
*/
protected function isPhpSafe($file)
{
$actions = $this->getActionIDs();
$viewFile = $this->getViewFile(reset($actions) ?: 'index');
$viewFileDir = FileHelper::normalizePath(dirname($viewFile));
return FileHelper::normalizePath(dirname($file->path)) === $viewFileDir;
}
示例10: getPrefixedPath
/**
* Get prefixed path.
*
* @param string $path
* @param string $prefix
*
* @return string
*/
protected function getPrefixedPath($path, $prefix)
{
if (substr($path, 0, 1) !== '/') {
$path = '/' . $path;
}
$path = FileHelper::normalizePath($path);
$prefixedPath = Yii::getAlias($prefix . $path);
return $prefixedPath;
}
示例11: findFiles
/**
* @inheritdoc
*/
protected function findFiles($path, $except = [])
{
if (empty($except)) {
$except = ['README.md'];
}
$path = FileHelper::normalizePath($path);
$options = ['only' => ['*.md'], 'except' => $except];
return FileHelper::findFiles($path, $options);
}
示例12: getImagePath
public static function getImagePath($adverId)
{
$path = Yii::getAlias('@common/assets/images/gallery/' . (string) ((int) ($adverId / 10000) + 1) . '/' . $adverId);
$path = FileHelper::normalizePath($path);
if (!is_dir($path)) {
FileHelper::createDirectory($path);
}
return $path;
}
示例13: loadTemplate
public static function loadTemplate($path)
{
$path = Yii::getAlias(self::TEMPLATES_ALIAS . '/' . $path);
$path = FileHelper::normalizePath($path);
$model = new self();
$model->templatePath = $path;
$model->getTemplateContents();
return $model;
}
示例14: getAttachmentPath
public static function getAttachmentPath($adverId)
{
$path = Yii::getAlias('@common/assets/attachment/' . (string) ((int) ($adverId / 10000) + 1) . '/' . $adverId);
$path = FileHelper::normalizePath($path);
if (!is_file($path)) {
FileHelper::createDirectory($path);
}
return $path;
}
示例15: init
public function init()
{
if ($this->caseSensitivity) {
Analyzer::setDefault(new Utf8());
} else {
Analyzer::setDefault(new CaseInsensitive());
}
$this->indexDirectory = FileHelper::normalizePath(Yii::getAlias($this->indexDirectory));
$this->luceneIndex = $this->getLuceneIndex($this->indexDirectory);
}