/** * @param $fileName */ public function save($fileName) { if (!file_exists(dirname($fileName))) { throw new \RuntimeException('Can\'t write to location ' . $fileName); } $data = $this->view->drawField(); $res = file_put_contents($fileName, $data); if (false === $res) { throw new \RuntimeException(sprintf('File %s not written', $fileName)); } }
/** * @return mixed */ public function run() { $this->inputParameter['level_filename'] = (array) $this->inputParameter['level_filename']; foreach ($this->inputParameter['level_filename'] as $key => $urn) { if (is_dir($urn)) { $this->fileFinder->files()->in($urn); foreach ($this->gridFactory->getFileExtensions() as $ext) { $this->fileFinder->name('*.' . $ext); } foreach ($this->fileFinder as $file) { $this->inputParameter['level_filename'][] = $file->getRealpath(); } unset($this->inputParameter['level_filename'][$key]); } elseif (1 === preg_match(self::FILENAME_WILDCARD_REGEX, $urn, $matches)) { $lowerBorder = (int) $matches[1]; $upperBorder = (int) $matches[2]; foreach (range($lowerBorder, $upperBorder) as $number) { $this->inputParameter['level_filename'][] = preg_replace(self::FILENAME_WILDCARD_REGEX, $number, $urn); } unset($this->inputParameter['level_filename'][$key]); } } foreach ($this->inputParameter['level_filename'] as $urn) { try { $grid = $this->gridFactory->get($urn); $this->view->setGrid($grid); if (!($this->view instanceof ViewWritableInterface && $this->view->supportsMultiple())) { //execute after adding one $this->executeAction($urn); } } catch (\Exception $e) { echo $e->getMessage() . ': ' . $urn . PHP_EOL; continue; } } if ($this->view instanceof ViewWritableInterface && $this->view->supportsMultiple()) { //execute after adding multiple $this->executeAction($urn); } if (method_exists($this, 'finallyExecute')) { $this->finallyExecute(); } }