本文整理汇总了PHP中Magento\Framework\Filesystem::getUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getUri方法的具体用法?PHP Filesystem::getUri怎么用?PHP Filesystem::getUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getUri方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConfig
/**
* Return Wysiwyg config as \Magento\Framework\DataObject
*
* Config options description:
*
* enabled: Enabled Visual Editor or not
* hidden: Show Visual Editor on page load or not
* use_container: Wrap Editor contents into div or not
* no_display: Hide Editor container or not (related to use_container)
* translator: Helper to translate phrases in lib
* files_browser_*: Files Browser (media, images) settings
* encode_directives: Encode template directives with JS or not
*
* @param array|\Magento\Framework\DataObject $data Object constructor params to override default config values
* @return \Magento\Framework\DataObject
*/
public function getConfig($data = [])
{
$config = new \Magento\Framework\DataObject();
$config->setData(['enabled' => $this->isEnabled(), 'hidden' => $this->isHidden(), 'use_container' => false, 'add_variables' => true, 'add_widgets' => true, 'no_display' => false, 'encode_directives' => true, 'baseStaticUrl' => $this->_assetRepo->getStaticViewFileContext()->getBaseUrl(), 'baseStaticDefaultUrl' => str_replace('index.php/', '', $this->_backendUrl->getBaseUrl()) . $this->filesystem->getUri(DirectoryList::STATIC_VIEW) . '/', 'directives_url' => $this->_backendUrl->getUrl('cms/wysiwyg/directive'), 'popup_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/dialog.css'), 'content_css' => $this->_assetRepo->getUrl('mage/adminhtml/wysiwyg/tiny_mce/themes/advanced/skins/default/content.css'), 'width' => '100%', 'height' => '500px', 'plugins' => []]);
$config->setData('directives_url_quoted', preg_quote($config->getData('directives_url')));
if ($this->_authorization->isAllowed('Magento_Cms::media_gallery')) {
$config->addData(['add_images' => true, 'files_browser_window_url' => $this->_backendUrl->getUrl('cms/wysiwyg_images/index'), 'files_browser_window_width' => $this->_windowSize['width'], 'files_browser_window_height' => $this->_windowSize['height']]);
}
if (is_array($data)) {
$config->addData($data);
}
if ($config->getData('add_variables')) {
$settings = $this->_variableConfig->getWysiwygPluginSettings($config);
$config->addData($settings);
}
if ($config->getData('add_widgets')) {
$settings = $this->_widgetConfig->getPluginSettings($config);
$config->addData($settings);
}
return $config;
}
示例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 Filesystem $filesystem
* @param bool $secure
* @return string|bool
*/
protected function _getMediaScriptUrl(Filesystem $filesystem, $secure)
{
if (!$this->getConfig(self::XML_PATH_USE_REWRITES) && $this->_coreFileStorageDatabase->checkDbUsage()) {
$baseUrl = $this->getBaseUrl(UrlInterface::URL_TYPE_WEB, $secure);
return $baseUrl . $filesystem->getUri(DirectoryList::PUB) . '/' . self::MEDIA_REWRITE_SCRIPT;
}
return false;
}
示例3: testGetUri
public function testGetUri()
{
$uri = 'http://example.com';
$this->_setupDirectoryListMock(array('uri' => $uri));
$this->assertEquals($uri, $this->_filesystem->getUri(AppFilesystem::ROOT_DIR));
}
示例4: validate
/**
* @param \Magento\Framework\Object $processingParams
* @param \Magento\Catalog\Model\Product\Option $option
* @return array
* @throws LocalizedException
* @throws ProductException
* @throws \Exception
* @throws \Magento\Framework\Exception\InputException
* @throws \Magento\Framework\Validator\Exception
* @throws \Zend_File_Transfer_Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function validate($processingParams, $option)
{
$upload = $this->httpFactory->create();
$file = $processingParams->getFilesPrefix() . 'options_' . $option->getId() . '_file';
try {
$runValidation = $option->getIsRequire() || $upload->isUploaded($file);
if (!$runValidation) {
throw new \Magento\Framework\Validator\Exception(__('Validation failed. Required options were not filled or file was not uploaded.'));
}
$fileInfo = $upload->getFileInfo($file)[$file];
$fileInfo['title'] = $fileInfo['name'];
} catch (\Magento\Framework\Validator\Exception $e) {
throw $e;
} catch (\Exception $e) {
// when file exceeds the upload_max_filesize, $_FILES is empty
if ($this->validateContentLength()) {
$value = $this->fileSize->getMaxFileSizeInMb();
throw new LocalizedException(__('The file you uploaded is larger than %1 Megabytes allowed by server', $value));
} else {
throw new ProductException(__('Option required.'));
}
}
/**
* Option Validations
*/
$upload = $this->buildImageValidator($upload, $option);
/**
* Upload process
*/
$this->initFilesystem();
$userValue = [];
if ($upload->isUploaded($file) && $upload->isValid($file)) {
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
$filePath = $dispersion;
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
$fileHash = md5($tmpDirectory->readFile($tmpDirectory->getRelativePath($fileInfo['tmp_name'])));
$filePath .= '/' . $fileHash . '.' . $extension;
$fileFullPath = $this->mediaDirectory->getAbsolutePath($this->quotePath . $filePath);
$upload->addFilter(new \Zend_Filter_File_Rename(['target' => $fileFullPath, 'overwrite' => true]));
if ($this->product !== null) {
$this->product->getTypeInstance()->addFileQueue(['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(DirectoryList::MEDIA);
$userValue = ['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, $option);
if (count($errors) > 0) {
throw new LocalizedException(__(implode("\n", $errors)));
}
} else {
throw new LocalizedException(__('Please specify the product\'s required option(s).'));
}
return $userValue;
}
示例5: testGetUri
public function testGetUri()
{
$this->_directoryListMock->expects($this->once())->method('getUrlPath')->with('code')->willReturn('result');
$this->assertEquals('result', $this->_filesystem->getUri('code'));
}
示例6: saveFile
/**
* @param ImageContentInterface $imageContent
* @return string
*/
protected function saveFile(ImageContentInterface $imageContent)
{
$uri = $this->filesystem->getUri(DirectoryList::MEDIA);
$filePath = $this->imageProcessor->processImageContent($this->destinationFolder, $imageContent);
return $uri . $this->destinationFolder . $filePath;
}