6 declare(strict_types=1);
29 private $componentRegistrar;
42 \
Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
46 $this->readFactory = $readFactory;
48 $this->samples = $samples;
58 public function getSize(
string $entityName)
60 $directoryRead = $this->getDirectoryRead($entityName);
61 $filePath = $this->getPath($entityName);
62 $fileSize = isset($directoryRead->stat($filePath)[
'size'])
63 ? $directoryRead->stat($filePath)[
'size'] :
null;
77 $directoryRead = $this->getDirectoryRead($entityName);
78 $filePath = $this->getPath($entityName);
80 return $directoryRead->readFile($filePath);
87 private function getPath(
string $entityName): string
89 $moduleName = $this->getModuleName($entityName);
90 $directoryRead = $this->getDirectoryRead($entityName);
91 $moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
92 $fileAbsolutePath = $moduleDir .
'/Files/Sample/' . $entityName .
'.csv';
94 $filePath = $directoryRead->getRelativePath($fileAbsolutePath);
96 if (!$directoryRead->isFile($filePath)) {
107 private function getDirectoryRead(
string $entityName): ReadInterface
109 $moduleName = $this->getModuleName($entityName);
110 $moduleDir = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
111 $directoryRead = $this->readFactory->create($moduleDir);
113 return $directoryRead;
121 private function getModuleName(
string $entityName): string
123 if (!isset($this->samples[$entityName])) {
124 throw new NoSuchEntityException();
127 return $this->samples[$entityName];
getSize(string $entityName)
getFileContents(string $entityName)
__construct(\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, \Magento\Framework\Component\ComponentRegistrar $componentRegistrar, array $samples=[])