123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace Util\PHPExcel\Reader;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\ErrorCode;
- use Util\PHPExcel\Reader\IReader;
- use Util\PHPExcel\Reader\IReadFilter;
- abstract class ReaderAbstract implements IReader
- {
- protected $fileHandle = null;
-
- protected $readDataOnly = false;
-
- protected $readFilter;
-
- protected $loadSheetsOnly;
-
- public function canRead($pFilename)
- {
-
- $reuslt = $this->openFile($pFilename);
- if(!$reuslt->isSuccess()){
- return ResultWrapper::fail($reuslt->getData(), $reuslt->getErrorCode());
- }
- $readable = $this->isValidFormat();
- fclose($this->fileHandle);
- return ResultWrapper::success($readable);
- }
-
- protected function openFile($pFilename)
- {
-
- if (!file_exists($pFilename) || !is_readable($pFilename)) {
- return ResultWrapper::fail('文件不存在',$pFilename, ErrorCode::$notAllowAccess);
- }
-
- $this->fileHandle = fopen($pFilename, 'r');
- if ($this->fileHandle === false) {
- return ResultWrapper::fail('读取文件失败',$pFilename, ErrorCode::$notAllowAccess);
- }
- }
-
- public function getReadDataOnly()
- {
- return $this->readDataOnly;
- }
-
- public function setReadDataOnly($pValue = false)
- {
- $this->readDataOnly = $pValue;
- return $this;
- }
-
- public function securityScan($xml)
- {
- $pattern = '/\\0?' . implode('\\0?', str_split('<!DOCTYPE')) . '\\0?/';
- if (preg_match($pattern, $xml)) {
- throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
- }
- return $xml;
- }
-
- public function getReadFilter()
- {
- return $this->readFilter;
- }
-
- public function setReadFilter(IReadFilter $pValue)
- {
- $this->readFilter = $pValue;
- return $this;
- }
-
- public function getLoadSheetsOnly()
- {
- return $this->loadSheetsOnly;
- }
-
- public function setLoadSheetsOnly($value = null)
- {
- if ($value === null) {
- return $this->setLoadAllSheets();
- }
- $this->loadSheetsOnly = is_array($value) ? $value : array($value);
- return $this;
- }
-
- public function setLoadAllSheets()
- {
- $this->loadSheetsOnly = null;
- return $this;
- }
- }
|