本文整理汇总了PHP中Magento\Framework\App\Filesystem::getUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getUri方法的具体用法?PHP Filesystem::getUri怎么用?PHP Filesystem::getUri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getUri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _checkUrl
/**
* Check validity of a base URL
*
* @param string $baseUrl
* @return void
* @throws \Magento\Framework\Model\Exception
* @throws \Exception
*/
protected function _checkUrl($baseUrl)
{
try {
$staticFile = $this->_findFirstFileRelativePath('', '/.+\\.(html?|js|css|gif|jpe?g|png)$/');
$staticUrl = $baseUrl . $this->_filesystem->getUri(\Magento\Framework\App\Filesystem::PUB_DIR) . '/' . $staticFile;
$client = new \Magento\Framework\HTTP\ZendClient($staticUrl);
$response = $client->request('GET');
} catch (\Exception $e) {
$this->messageManager->addError(__('The URL "%1" is not accessible.', $baseUrl));
throw $e;
}
if ($response->getStatus() != 200) {
$this->messageManager->addError(__('The URL "%1" is invalid.', $baseUrl));
throw new \Magento\Framework\Model\Exception(__('Response from the server is invalid.'));
}
}
示例2: _getMediaScriptUrl
/**
* Retrieve URL for media catalog
*
* If we use Database file storage and server doesn't support rewrites (.htaccess in media folder)
* we have to put name of fetching media script exactly into URL
*
* @param \Magento\Framework\App\Filesystem $filesystem
* @param bool $secure
* @return string|bool
*/
protected function _getMediaScriptUrl(\Magento\Framework\App\Filesystem $filesystem, $secure)
{
if (!$this->_getConfig(self::XML_PATH_USE_REWRITES) && $this->_coreFileStorageDatabase->checkDbUsage()) {
return $this->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, $secure) . $filesystem->getUri(\Magento\Framework\App\Filesystem::PUB_DIR) . '/' . self::MEDIA_REWRITE_SCRIPT;
}
return false;
}
示例3: _validateUploadedFile
/**
* Validate uploaded file
*
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
protected function _validateUploadedFile()
{
$option = $this->getOption();
$processingParams = $this->_getProcessingParams();
/**
* Upload init
*/
$upload = new \Zend_File_Transfer_Adapter_Http();
$file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file';
$maxFileSize = $this->getFileSizeService()->getMaxFileSize();
try {
$runValidation = $option->getIsRequire() || $upload->isUploaded($file);
if (!$runValidation) {
$this->setUserValue(null);
return $this;
}
$fileInfo = $upload->getFileInfo($file);
$fileInfo = $fileInfo[$file];
$fileInfo['title'] = $fileInfo['name'];
} catch (\Exception $e) {
// when file exceeds the upload_max_filesize, $_FILES is empty
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $maxFileSize) {
$this->setIsValid(false);
$value = $this->getFileSizeService()->getMaxFileSizeInMb();
throw new Exception(__("The file you uploaded is larger than %1 Megabytes allowed by server", $value));
} else {
switch ($this->getProcessMode()) {
case \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL:
throw new Exception(__('Please specify the product\'s required option(s).'));
break;
default:
$this->setUserValue(null);
break;
}
return $this;
}
}
/**
* Option Validations
*/
// Image dimensions
$_dimentions = array();
if ($option->getImageSizeX() > 0) {
$_dimentions['maxwidth'] = $option->getImageSizeX();
}
if ($option->getImageSizeY() > 0) {
$_dimentions['maxheight'] = $option->getImageSizeY();
}
if (count($_dimentions) > 0) {
$upload->addValidator('ImageSize', false, $_dimentions);
}
// File extension
$_allowed = $this->_parseExtensionsString($option->getFileExtension());
if ($_allowed !== null) {
$upload->addValidator('Extension', false, $_allowed);
} else {
$_forbidden = $this->_parseExtensionsString($this->getConfigData('forbidden_extensions'));
if ($_forbidden !== null) {
$upload->addValidator('ExcludeExtension', false, $_forbidden);
}
}
// Maximum filesize
$upload->addValidator('FilesSize', false, array('max' => $maxFileSize));
/**
* Upload process
*/
$this->_initFilesystem();
if ($upload->isUploaded($file) && $upload->isValid($file)) {
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
$fileName = \Magento\Core\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
$dispersion = \Magento\Core\Model\File\Uploader::getDispretionPath($fileName);
$filePath = $dispersion;
$tmpDirectory = $this->_filesystem->getDirectoryRead(\Magento\Framework\App\Filesystem::SYS_TMP_DIR);
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
$filePath .= '/' . $fileHash . '.' . $extension;
$fileFullPath = $this->_mediaDirectory->getAbsolutePath($this->_quotePath . $filePath);
$upload->addFilter('Rename', array('target' => $fileFullPath, 'overwrite' => true));
$this->getProduct()->getTypeInstance()->addFileQueue(array('operation' => 'receive_uploaded_file', 'src_name' => $file, 'dst_name' => $fileFullPath, 'uploader' => $upload, 'option' => $this));
$_width = 0;
$_height = 0;
if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) {
$_imageSize = getimagesize($fileInfo['tmp_name']);
if ($_imageSize) {
$_width = $_imageSize[0];
$_height = $_imageSize[1];
}
}
$uri = $this->_filesystem->getUri(\Magento\Framework\App\Filesystem::MEDIA_DIR);
$this->setUserValue(array('type' => $fileInfo['type'], 'title' => $fileInfo['name'], 'quote_path' => $uri . $this->_quotePath . $filePath, 'order_path' => $uri . $this->_orderPath . $filePath, 'fullpath' => $fileFullPath, 'size' => $fileInfo['size'], 'width' => $_width, 'height' => $_height, 'secret_key' => substr($fileHash, 0, 20)));
} elseif ($upload->getErrors()) {
$errors = $this->_getValidatorErrors($upload->getErrors(), $fileInfo);
if (count($errors) > 0) {
$this->setIsValid(false);
throw new Exception(implode("\n", $errors));
//.........这里部分代码省略.........