/** * @param string $filename */ public function setFilename($filename) { Assertion::string($filename, 'Invalid filename.'); Assertion::directory(dirname($filename), 'The selected directory does not exist.'); Assertion::writeable(dirname($filename), 'The selected directory is not writable.'); $this->filename = $filename; }
/** * @return string */ public function save(\PHPExcel $excel, $id) { Assertion::notEmpty($id); Assertion::string($id); Assertion::writeable($this->directory); $filePath = $this->directory . $id; $pathinfo = pathinfo($id); if (!isset($pathinfo['extension'])) { throw new \RuntimeException("Extension was expected for report id: '{$id}'. Unable to determine excel type."); } $writerType = self::extensionToType($pathinfo['extension']); $excelWriter = \PHPExcel_IOFactory::createWriter($excel, $writerType); $excelWriter->save($filePath); return $filePath; }
public function testWriteable() { Assertion::writeable(sys_get_temp_dir()); $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_WRITEABLE); Assertion::writeable(__DIR__ . '/does-not-exist'); }