Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NewFolder.php
Go to the documentation of this file.
1 <?php
8 
10 
15 {
19  protected $resultJsonFactory;
20 
24  private $directoryResolver;
25 
32  public function __construct(
33  \Magento\Backend\App\Action\Context $context,
34  \Magento\Framework\Registry $coreRegistry,
35  \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
36  \Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
37  ) {
38  parent::__construct($context, $coreRegistry);
39  $this->resultJsonFactory = $resultJsonFactory;
40  $this->directoryResolver = $directoryResolver
41  ?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
42  }
43 
50  public function execute()
51  {
52  try {
53  $this->_initAction();
54  $name = $this->getRequest()->getPost('name');
55  $path = $this->getStorage()->getSession()->getCurrentPath();
56  if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
57  throw new \Magento\Framework\Exception\LocalizedException(
58  __('Directory %1 is not under storage root path.', $path)
59  );
60  }
61  $result = $this->getStorage()->createDirectory($name, $path);
62  } catch (\Exception $e) {
63  $result = ['error' => true, 'message' => $e->getMessage()];
64  }
66  $resultJson = $this->resultJsonFactory->create();
67 
68  return $resultJson->setData($result);
69  }
70 }
__()
Definition: __.php:13
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver=null)
Definition: NewFolder.php:32
if(!isset($_GET['name'])) $name
Definition: log.php:14