<?php
 namespace App\ExportData\Output; abstract class FileTxtAbstract extends \App\ExportData\OutputAbstract { protected function checkOutputType($output) { if (is_string($output)) { return true; } return false; } public function saveOutput() { $locationDir = $this->getFileDestinationDir(); $fileName = $this->getFileName(); if (!$locationDir) { $this->ok = false; $this->messagesCollector->addError(sprintf('The class `%s` may not be correctly configured in terms of the location where the files are stored - method `getFileDestinationDir()`.', get_called_class())); } if (!$fileName) { $this->ok = false; $this->messagesCollector->addError(sprintf('The class `%s` may not be correctly configured in terms of the output file name - method `getFileName()`.', get_called_class())); } $outputFileName = $locationDir.$fileName; if (!\Engine\Dir::check($locationDir) and !\Engine\Dir::create($locationDir)) { $this->ok = false; $this->messagesCollector->addError(sprintf('The execution of the export data output class `%s` seems to be ok but the directory that stores the exported files could not be created probably due to access rights.', get_called_class())); } if (!\Engine\File::create($outputFileName, $this->getFileContent())) { $this->ok = false; $this->messagesCollector->addError(sprintf('The execution of the export data output class `%s` seems to be ok but the original XML file could not be confirmed probably due to access rights.', get_called_class())); } } abstract public function getFileDestinationDir(); protected function getFileContent() { return $this->output; } protected function getUniqueFileNameWithoutExtension() { $microtime = microtime(true); return date("Y-m-d_H-i-s").substr(($microtime-floor($microtime)), 1); } protected function getFileName() { return $this->getUniqueFileNameWithoutExtension().'.txt'; } } 