Skip to content

Commit

Permalink
Merge pull request magento#18 from magento-techdivision/MC-16991
Browse files Browse the repository at this point in the history
Mc 16991
  • Loading branch information
Lars Roettig authored Jul 2, 2019
2 parents 51eb876 + 0ad49f1 commit c3238e9
Show file tree
Hide file tree
Showing 27 changed files with 333 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public function __construct(ConverterInterface $converter, array $responseHandle
}

/**
* @param \Zend_Http_Response $response
* Get result from $response.
*
* @param \Zend_Http_Response $response
* @return bool|string
*/
public function getResult(\Zend_Http_Response $response)
Expand Down
33 changes: 28 additions & 5 deletions app/code/Magento/Backend/App/Area/FrontNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
use Magento\Backend\Setup\ConfigOptionsList;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\Store;
use Zend\Uri\UriInterface;

/**
* Class to get area front name.
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -59,19 +64,35 @@ class FrontNameResolver implements \Magento\Framework\App\Area\FrontNameResolver
*/
private $scopeConfig;

/**
* @var UriInterface
*/
private $uri;

/**
* @var RequestInterface
*/
private $request;

/**
* @param \Magento\Backend\App\Config $config
* @param DeploymentConfig $deploymentConfig
* @param ScopeConfigInterface $scopeConfig
* @param UriInterface $uri
* @param RequestInterface $request
*/
public function __construct(
\Magento\Backend\App\Config $config,
DeploymentConfig $deploymentConfig,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
UriInterface $uri = null,
RequestInterface $request = null
) {
$this->config = $config;
$this->defaultFrontName = $deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_BACKEND_FRONTNAME);
$this->scopeConfig = $scopeConfig;
$this->uri = $uri ?: ObjectManager::getInstance()->get(UriInterface::class);
$this->request = $request ?: ObjectManager::getInstance()->get(RequestInterface::class);
}

/**
Expand Down Expand Up @@ -104,7 +125,7 @@ public function isHostBackend()
} else {
$backendUrl = $this->scopeConfig->getValue(Store::XML_PATH_UNSECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
}
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
$host = $this->request->getServer('HTTP_HOST', '');
return stripos($this->getHostWithPort($backendUrl), (string) $host) !== false;
}

Expand All @@ -116,9 +137,11 @@ public function isHostBackend()
*/
private function getHostWithPort($url)
{
$scheme = parse_url(trim($url), PHP_URL_SCHEME);
$host = parse_url(trim($url), PHP_URL_HOST);
$port = parse_url(trim($url), PHP_URL_PORT);
$this->uri->parse($url);
$scheme = $this->uri->getScheme();
$host = $this->uri->getHost();
$port = $this->uri->getPort();

if (!$port) {
$port = isset($this->standardPorts[$scheme]) ? $this->standardPorts[$scheme] : null;
}
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Braintree/Model/LocaleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Magento\Framework\Locale\ResolverInterface;
use Magento\Braintree\Gateway\Config\PayPal\Config;

/**
* Resolve stores locale.
*/
class LocaleResolver implements ResolverInterface
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function __construct(

/**
* Gets image name from $value array.
*
* Will return empty string in a case when $value is not an array
*
* @param array $value Attribute value
Expand All @@ -86,6 +87,7 @@ private function getUploadedImageName($value)

/**
* Avoiding saving potential upload data to DB
*
* Will set empty image attribute value if image was not uploaded
*
* @param \Magento\Framework\DataObject $object
Expand Down Expand Up @@ -113,6 +115,8 @@ public function beforeSave($object)
}

/**
* Get Instance of Category Image Uploader.
*
* @return \Magento\Catalog\Model\ImageUploader
*
* @deprecated 101.0.0
Expand Down
27 changes: 21 additions & 6 deletions app/code/Magento/Catalog/Model/CategoryManagement.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model;

use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;

/**
* Handles the category tree.
*/
class CategoryManagement implements \Magento\Catalog\Api\CategoryManagementInterface
{
/**
Expand Down Expand Up @@ -47,7 +47,14 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param int $rootCategoryId
* @param int $depth
* @return \Magento\Catalog\Api\Data\CategoryTreeInterface
*
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getTree($rootCategoryId = null, $depth = null)
{
Expand Down Expand Up @@ -99,7 +106,15 @@ private function getTopLevelCategory()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param int $categoryId
* @param int $parentId
* @param int $afterId
* @return bool
*
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function move($categoryId, $parentId, $afterId = null)
{
Expand Down Expand Up @@ -128,7 +143,7 @@ public function move($categoryId, $parentId, $afterId = null)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getCount()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
/**
* Class AbstractModifier
*
* @api
*
* @SuppressWarnings(PHPMD.NumberOfChildren)
* @since 101.0.0
*/
Expand Down
59 changes: 47 additions & 12 deletions app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Magento\Cms\Helper\Wysiwyg\Images;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;

/**
* Wysiwyg Images model.
Expand Down Expand Up @@ -136,6 +137,20 @@ class Storage extends \Magento\Framework\DataObject
*/
protected $_uploaderFactory;

/**
* @var \Psr\Log\LoggerInterface|null
*/
private $logger;
/**
* @var \Magento\Framework\Filesystem\DriverInterface
*/
private $file;

/**
* @var \Magento\Framework\Filesystem\Io\File|null
*/
private $ioFile;

/**
* Construct
*
Expand All @@ -151,11 +166,15 @@ class Storage extends \Magento\Framework\DataObject
* @param \Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory
* @param \Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory $directoryDatabaseFactory
* @param \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory
* @param \Psr\Log\LoggerInterface|null $logger
* @param array $resizeParameters
* @param array $extensions
* @param array $dirs
* @param array $data
* @param \Magento\Framework\Filesystem\DriverInterface $file
* @param \Magento\Framework\Filesystem\Io\File|null $ioFile
*
* @throws \Magento\Framework\Exception\FileSystemException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -171,10 +190,13 @@ public function __construct(
\Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory,
\Magento\MediaStorage\Model\File\Storage\Directory\DatabaseFactory $directoryDatabaseFactory,
\Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
\Psr\Log\LoggerInterface $logger = null,
array $resizeParameters = [],
array $extensions = [],
array $dirs = [],
array $data = []
array $data = [],
\Magento\Framework\Filesystem\DriverInterface $file = null,
\Magento\Framework\Filesystem\Io\File $ioFile = null
) {
$this->_session = $session;
$this->_backendUrl = $backendUrl;
Expand All @@ -188,9 +210,14 @@ public function __construct(
$this->_storageDatabaseFactory = $storageDatabaseFactory;
$this->_directoryDatabaseFactory = $directoryDatabaseFactory;
$this->_uploaderFactory = $uploaderFactory;
$this->logger = $logger ?: ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
$this->_resizeParameters = $resizeParameters;
$this->_extensions = $extensions;
$this->_dirs = $dirs;
$this->file = $file ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\DriverInterface::class);
$this->ioFile = $ioFile ?: ObjectManager::getInstance()->get(
\Magento\Framework\Filesystem\Io\File::class
);
parent::__construct($data);
}

Expand Down Expand Up @@ -288,9 +315,12 @@ public function getDirsCollection($path)
/**
* Return files
*
* @param string $path Parent directory path
* @param string $type Type of storage, e.g. image, media etc.
* @return \Magento\Framework\Data\Collection\Filesystem
* @param string $path Parent directory path
* @param string $type Type of storage, e.g. image, media etc.
* @return \Magento\Framework\Data\Collection\Filesystem
*
* @throws \Magento\Framework\Exception\FileSystemException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getFilesCollection($path, $type = null)
{
Expand Down Expand Up @@ -328,7 +358,8 @@ public function getFilesCollection($path, $type = null)
$item->setName($item->getBasename());
$item->setShortName($this->_cmsWysiwygImages->getShortFilename($item->getBasename()));
$item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
$item->setSize(filesize($item->getFilename()));
$itemStats = $this->file->stat($item->getFilename());
$item->setSize($itemStats['size']);
$item->setMimeType(\mime_content_type($item->getFilename()));

if ($this->isImage($item->getBasename())) {
Expand All @@ -338,11 +369,15 @@ public function getFilesCollection($path, $type = null)
$thumbUrl = $this->_backendUrl->getUrl('cms/*/thumbnail', ['file' => $item->getId()]);
}

$size = @getimagesize($item->getFilename());
try {
$size = getimagesize($item->getFilename());

if (is_array($size)) {
$item->setWidth($size[0]);
$item->setHeight($size[1]);
if (is_array($size)) {
$item->setWidth($size[0]);
$item->setHeight($size[1]);
}
} catch (\Error $e) {
$this->logger->notice(sprintf("GetImageSize caused error: %s", $e->getMessage()));
}
} else {
$thumbUrl = $this->_assetRepo->getUrl(self::THUMB_PLACEHOLDER_PATH_SUFFIX);
Expand Down Expand Up @@ -589,7 +624,7 @@ public function resizeFile($source, $keepRatio = true)
$image->open($source);
$image->keepAspectRatio($keepRatio);
$image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']);
$dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME);
$dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)[PATHINFO_BASENAME];
$image->save($dest);
if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {
return $dest;
Expand Down Expand Up @@ -624,7 +659,7 @@ public function getThumbsPath($filePath = false)
$thumbnailDir = $this->getThumbnailRoot();

if ($filePath && strpos($filePath, (string) $mediaRootDir) === 0) {
$thumbnailDir .= dirname(substr($filePath, strlen($mediaRootDir)));
$thumbnailDir .= $this->file->getParentDirectory(substr($filePath, strlen($mediaRootDir)));
}

return $thumbnailDir;
Expand Down Expand Up @@ -674,7 +709,7 @@ public function isImage($filename)
if (!$this->hasData('_image_extensions')) {
$this->setData('_image_extensions', $this->getAllowedExtensions('image'));
}
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$ext = strtolower($this->ioFile->getPathInfo($filename)[PATHINFO_EXTENSION]);
return in_array($ext, $this->_getData('_image_extensions'));
}

Expand Down
7 changes: 6 additions & 1 deletion app/code/Magento/Customer/Model/Checkout/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Magento\Customer\Model\Form;
use Magento\Store\Model\ScopeInterface;

/**
* Provides some configurations for customer.
*/
class ConfigProvider implements ConfigProviderInterface
{
/**
Expand Down Expand Up @@ -57,7 +60,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getConfig()
{
Expand Down Expand Up @@ -96,6 +99,8 @@ protected function getLoginUrl()
* Whether redirect to login page is required
*
* @return bool
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
protected function isRedirectRequired()
{
Expand Down
Loading

0 comments on commit c3238e9

Please sign in to comment.