/** * {@inheritdoc} */ public function export() { if (!DirectoryCreator::create($this->exportDir)) { throw new \RuntimeException("Unable to create dir: {$this->exportDir}"); } $api = array('api' => array(), 'types' => array()); if (isset($this->api['controllers'])) { foreach ($this->api['controllers'] as $controller) { $api['api'][] = $this->extractControllerData($controller); } } $fileToWrite = $this->exportDir . DIRECTORY_SEPARATOR . $this->filename; if (file_put_contents($fileToWrite, $this->generateOutput($api)) === false) { throw new \RuntimeException(sprintf("Unable to write file: %s", $fileToWrite)); } }
/** * Write a file, creates dir if needed. * * @param string $fileToWrite full path to the file write * @param string $contents contents of the file */ private function writeFile($fileToWrite, $contents) { $dirName = dirname($fileToWrite); if (!DirectoryCreator::create($dirName)) { throw new \RuntimeException("Unable to create directory: {$dirName}"); } if (file_put_contents($fileToWrite, $contents) === false) { throw new \RuntimeException(sprintf("Unable to write file: %s", $fileToWrite)); } }