/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($type != $this->getName()) { return FALSE; } $bytes = null; $headerData = fread($fileHandle, self::HEADER_LENGTH); $header = $processor->getParser()->parseHeader($headerData); if (isset($header['data_length_in_block']) && !feof($fileHandle)) { $bytes = fread($fileHandle, $header['data_length_in_block'] - self::HEADER_LENGTH); } do { $row = $processor->buildDataRow($bytes); if ($row) { $processor->addDataRow($row); } $bytes = substr($bytes, $processor->getParser()->getLastParseLength()); } while (isset($bytes[self::TRAILER_LENGTH + 1])); $trailer = $processor->getParser()->parseTrailer($bytes); //align the readhead if (self::RECORD_ALIGNMENT - $header['data_length_in_block'] > 0) { fread($fileHandle, self::RECORD_ALIGNMENT - $header['data_length_in_block']); } //add trailer data $processorData =& $processor->getData(); $processorData['trailer'] = $this->updateBlockData($trailer, $header, $processorData['trailer']); return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processorData =& $processor->getData(); $bytes = ''; do { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } while (!feof($fileHandle)); $parsedData = Asn_Base::parseASNString($bytes); $processorData['header'] = $processor->buildHeader($parsedData); //$bytes = substr($bytes, $processor->getParser()->getLastParseLength()); if (!isset($this->tap3Config[$this->fileVersion])) { Billrun_Factory::log("Processing tap3 file {$processor->filename} with non supported version : {$this->fileVersion}", Zend_log::NOTICE); throw new Exception("Processing tap3 file {$processor->filename} with non supported version : {$this->fileVersion}"); } $trailer = $processor->buildTrailer($parsedData); $this->initExchangeRates($trailer); if (empty($this->currentFileHeader['notification']) || !empty($this->currentFileHeader['header'])) { foreach ($parsedData->getData() as $record) { if (in_array($record->getType(), $this->tap3Config['config']['data_records'])) { foreach ($record->getData() as $key => $data) { $row = $processor->buildDataRow($data); if ($row) { $row['file_rec_num'] = $key + 1; $processorData['data'][] = $row; } } } else { if (!isset($this->tap3Config['header'][$record->getType()]) && !isset($this->tap3Config['trailer'][$record->getType()])) { Billrun_Factory::log()->log('No config for type : ' . $record->getType(), Zend_Log::DEBUG); } } } } else { Billrun_Factory::log()->log('Got notification/empty file : ' . $processor->filename . ' , moving on...', Zend_Log::INFO); } $processorData['trailer'] = $trailer; return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($type != $this->getName()) { return FALSE; } $bytes = null; $headerData = fread($fileHandle, self::HEADER_LENGTH); $header = $processor->getParser()->parseHeader($headerData); if (isset($header['data_length_in_block']) && !feof($fileHandle)) { $bytes = fread($fileHandle, $header['data_length_in_block'] - self::HEADER_LENGTH); } if (in_array($header['format_version'], $this->nsnConfig['block_config']['supported_versions'])) { do { $row = $processor->buildDataRow($bytes); if ($row) { $processor->addDataRow($row); } $bytes = substr($bytes, $processor->getParser()->getLastParseLength()); } while (isset($bytes[self::TRAILER_LENGTH + 1])); } else { Billrun_Factory::log()->log("Got NSN block with unsupported version : {$header['format_version']} , block header data : " . print_r($header, 1), Zend_log::CRIT); } $trailer = $processor->getParser()->parseTrailer($bytes); //align the readhead $alignment = self::RECORD_ALIGNMENT * max(1, $header['charging_block_size']); if ($alignment - $header['data_length_in_block'] > 0) { fread($fileHandle, $alignment - $header['data_length_in_block']); } //add trailer data $processorData =& $processor->getData(); $processorData['trailer'] = $this->updateBlockData($trailer, $header, $processorData['trailer']); return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processedData =& $processor->getData(); $processedData['header'] = $processor->buildHeader(fread($fileHandle, self::HEADER_LENGTH)); $bytes = null; while (true) { if (!feof($fileHandle) && !isset($bytes[self::MAX_CHUNKLENGTH_LENGTH])) { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } if (!isset($bytes[self::HEADER_LENGTH])) { break; } $row = $processor->buildDataRow($bytes); if ($row) { $row['stamp'] = md5($bytes); $processedData['data'][] = $row; } //Billrun_Factory::log()->log( $processor->getParser()->getLastParseLength(), Zend_Log::DEBUG); $advance = $processor->getParser()->getLastParseLength(); $bytes = substr($bytes, $advance <= 0 ? 1 : $advance); } $processedData['trailer'] = $processor->buildTrailer($bytes); return true; }
/** * @see Billrun_Plugin_Interface_IProcessor::processData */ public function processData($type, $fileHandle, \Billrun_Processor &$processor) { if ($this->getName() != $type) { return FALSE; } $processorData =& $processor->getData(); $bytes = ''; do { $bytes .= fread($fileHandle, self::FILE_READ_AHEAD_LENGTH); } while (!feof($fileHandle)); $parsedData = Asn_Base::parseASNString($bytes); $processorData['header'] = $processor->buildHeader($parsedData); //$bytes = substr($bytes, $processor->getParser()->getLastParseLength()); foreach ($parsedData->getData() as $record) { if (in_array($record->getType(), $this->nsnConfig['config']['data_records'])) { foreach ($record->getData() as $key => $data) { $row = $processor->buildDataRow($data); if ($row) { $row['file_rec_num'] = $key; $processorData['data'][] = $row; } } } else { //Billrun_Factory::log()->log(print_r($record,1) , Zend_Log::DEBUG); } } $processorData['trailer'] = $processor->buildTrailer($parsedData); return true; }