33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Cms \Helper \Wysiwyg ;
78
9+ use Exception ;
10+ use InvalidArgumentException ;
11+ use Magento \Backend \Helper \Data ;
812use Magento \Framework \App \Filesystem \DirectoryList ;
9- use Magento \Framework \Exception \ValidatorException ;
13+ use Magento \Framework \App \Helper \AbstractHelper ;
14+ use Magento \Framework \App \Helper \Context ;
15+ use Magento \Framework \Escaper ;
16+ use Magento \Framework \Exception \FileSystemException ;
17+ use Magento \Framework \Exception \LocalizedException ;
18+ use Magento \Framework \Filesystem ;
19+ use Magento \Framework \Filesystem \Directory \Read ;
20+ use Magento \Framework \Filesystem \Directory \Write ;
21+ use Magento \Framework \UrlInterface ;
22+ use Magento \Store \Model \StoreManagerInterface ;
23+ use Magento \Theme \Helper \Storage ;
1024
1125/**
1226 * Wysiwyg Images Helper.
1327 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1428 */
15- class Images extends \ Magento \ Framework \ App \ Helper \ AbstractHelper
29+ class Images extends AbstractHelper
1630{
1731 /**
1832 * Image directory subpath relative to media directory
@@ -23,12 +37,14 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
2337
2438 /**
2539 * Current directory path
40+ *
2641 * @var string
2742 */
2843 protected $ _currentPath ;
2944
3045 /**
3146 * Current directory URL
47+ *
3248 * @var string
3349 */
3450 protected $ _currentUrl ;
@@ -41,51 +57,51 @@ class Images extends \Magento\Framework\App\Helper\AbstractHelper
4157 protected $ _storeId ;
4258
4359 /**
44- * @var \Magento\Framework\Filesystem\Directory\ Write
60+ * @var Write
4561 */
4662 protected $ _directory ;
4763
4864 /**
4965 * Adminhtml data
5066 *
51- * @var \Magento\Backend\Helper\ Data
67+ * @var Data
5268 */
5369 protected $ _backendData ;
5470
5571 /**
5672 * Store manager
5773 *
58- * @var \Magento\Store\Model\ StoreManagerInterface
74+ * @var StoreManagerInterface
5975 */
6076 protected $ _storeManager ;
6177
6278 /**
6379 * String escaper
6480 *
65- * @var \Magento\Framework\ Escaper
81+ * @var Escaper
6682 */
6783 protected $ escaper ;
6884
6985 /**
70- * @var \Magento\Framework\Filesystem\Directory\ Read
86+ * @var Read
7187 */
7288 private $ _readDirectory ;
7389
7490 /**
7591 * Construct
7692 *
77- * @param \Magento\Framework\App\Helper\ Context $context
78- * @param \Magento\Backend\Helper\ Data $backendData
79- * @param \Magento\Framework\ Filesystem $filesystem
80- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
81- * @param \Magento\Framework\ Escaper $escaper
93+ * @param Context $context
94+ * @param Data $backendData
95+ * @param Filesystem $filesystem
96+ * @param StoreManagerInterface $storeManager
97+ * @param Escaper $escaper
8298 */
8399 public function __construct (
84- \ Magento \ Framework \ App \ Helper \ Context $ context ,
85- \ Magento \ Backend \ Helper \ Data $ backendData ,
86- \ Magento \ Framework \ Filesystem $ filesystem ,
87- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
88- \ Magento \ Framework \ Escaper $ escaper
100+ Context $ context ,
101+ Data $ backendData ,
102+ Filesystem $ filesystem ,
103+ StoreManagerInterface $ storeManager ,
104+ Escaper $ escaper
89105 ) {
90106 parent ::__construct ($ context );
91107 $ this ->_backendData = $ backendData ;
@@ -136,7 +152,7 @@ public function getStorageRootSubpath()
136152 */
137153 public function getBaseUrl ()
138154 {
139- return $ this ->_storeManager ->getStore ()->getBaseUrl (\ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA );
155+ return $ this ->_storeManager ->getStore ()->getBaseUrl (UrlInterface::URL_TYPE_MEDIA );
140156 }
141157
142158 /**
@@ -166,19 +182,19 @@ public function convertPathToId($path)
166182 *
167183 * @param string $id
168184 * @return string
169- * @throws \ InvalidArgumentException
185+ * @throws InvalidArgumentException
170186 */
171187 public function convertIdToPath ($ id )
172188 {
173- if ($ id === \ Magento \ Theme \ Helper \ Storage::NODE_ROOT ) {
189+ if ($ id === Storage::NODE_ROOT ) {
174190 return $ this ->getStorageRoot ();
175191 } else {
176192 $ path = $ this ->getStorageRoot () . $ this ->idDecode ($ id );
177193
178194 try {
179195 $ this ->_readDirectory ->getAbsolutePath ($ path );
180- } catch (\ Exception $ e ) {
181- throw new \ InvalidArgumentException ('Path is invalid ' );
196+ } catch (Exception $ e ) {
197+ throw new InvalidArgumentException ('Path is invalid ' );
182198 }
183199
184200 return $ path ;
@@ -192,7 +208,7 @@ public function convertIdToPath($id)
192208 */
193209 public function isUsingStaticUrlsAllowed ()
194210 {
195- $ checkResult = (object ) [];
211+ $ checkResult = (object )[];
196212 $ checkResult ->isAllowed = false ;
197213 $ this ->_eventManager ->dispatch (
198214 'cms_wysiwyg_images_static_urls_allowed ' ,
@@ -211,7 +227,7 @@ public function isUsingStaticUrlsAllowed()
211227 public function getImageHtmlDeclaration ($ filename , $ renderAsTag = false )
212228 {
213229 $ fileUrl = $ this ->getCurrentUrl () . $ filename ;
214- $ mediaUrl = $ this ->_storeManager ->getStore ()->getBaseUrl (\ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA );
230+ $ mediaUrl = $ this ->_storeManager ->getStore ($ this -> _storeId )->getBaseUrl (UrlInterface::URL_TYPE_MEDIA );
215231 $ mediaPath = str_replace ($ mediaUrl , '' , $ fileUrl );
216232 $ directive = sprintf ('{{media url="%s"}} ' , $ mediaPath );
217233 if ($ renderAsTag ) {
@@ -238,7 +254,7 @@ public function getImageHtmlDeclaration($filename, $renderAsTag = false)
238254 * Return path of the root directory for startup. Also try to create target directory if it doesn't exist
239255 *
240256 * @return string
241- * @throws \Magento\Framework\Exception\ LocalizedException
257+ * @throws LocalizedException
242258 */
243259 public function getCurrentPath ()
244260 {
@@ -268,21 +284,21 @@ public function getCurrentPath()
268284 * Create subdirectory if doesn't exist
269285 *
270286 * @param string $absPath Path of subdirectory to create
271- * @throws \Magento\Framework\Exception\ LocalizedException
287+ * @throws LocalizedException
272288 */
273289 private function createSubDirIfNotExist (string $ absPath )
274290 {
275291 $ relPath = $ this ->_directory ->getRelativePath ($ absPath );
276292 if (!$ this ->_directory ->isExist ($ relPath )) {
277293 try {
278294 $ this ->_directory ->create ($ relPath );
279- } catch (\ Magento \ Framework \ Exception \ FileSystemException $ e ) {
295+ } catch (FileSystemException $ e ) {
280296 $ message = __ (
281297 'Can \'t create %1 as subdirectory of %2, you might have some permission issue. ' ,
282298 $ relPath ,
283299 $ this ->_directory ->getAbsolutePath ()
284300 );
285- throw new \ Magento \ Framework \ Exception \ LocalizedException ($ message );
301+ throw new LocalizedException ($ message );
286302 }
287303 }
288304 }
@@ -299,7 +315,7 @@ public function getCurrentUrl()
299315 $ mediaUrl = $ this ->_storeManager ->getStore (
300316 $ this ->_storeId
301317 )->getBaseUrl (
302- \ Magento \ Framework \ UrlInterface::URL_TYPE_MEDIA
318+ UrlInterface::URL_TYPE_MEDIA
303319 );
304320 $ this ->_currentUrl = rtrim ($ mediaUrl . $ this ->_directory ->getRelativePath ($ path ), '/ ' ) . '/ ' ;
305321 }
0 commit comments