Skip to content

Commit f132071

Browse files
authored
Issue #13 FoxPro memo field bugfix (#14)
* #13 - fix fox pro memo loading * #13 add throw annotations, doc etc * #13 foxpro write * #13 fix * #13 fix travis * #13 fix * #13 fix * #13 fix * #13 disable travis php 7.3
1 parent e87bd25 commit f132071

17 files changed

+187
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.tar
44
*.copy*
55
/composer.lock
6+
/tests/fixtures/materie-2.*

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
language: php
22
php:
3-
- 5.6
4-
- 5.5
53
- 5.4
4+
- 5.5
5+
- 5.6
66
- 7.0
77
- 7.1
88
- 7.2
9+
# - 7.3
910
- hhvm
1011
- nightly
1112

DEVELOP.md

+2
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ http://www.clicketyclick.dk/databases/xbase/format/dbf.html#DBF_STRUCT
4141
http://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm
4242

4343
http://www.digitalpreservation.gov/formats/fdd/fdd000325.shtml
44+
45+
http://web.tiscali.it/SilvioPitti/

src/Builder.php

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public static function fromTable(Table $table) {
8383
/**
8484
* @param string $filePath
8585
* @return \org\majkel\dbase\Builder
86+
* @throws Exception
8687
*/
8788
public static function fromFile($filePath) {
8889
return self::fromTable(Table::fromFile($filePath, Table::MODE_READ));
@@ -120,6 +121,7 @@ public function setMemoType($memoType) {
120121
/**
121122
* @param string $filePath
122123
* @return Table
124+
* @throws Exception
123125
*/
124126
public function build($filePath) {
125127
$header = $this->getHeader();

src/File.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function getSize() {
3434
* @param string $mode
3535
* @param string $class
3636
* @return \SplFileObject
37+
* @throws \ReflectionException
3738
*/
3839
public static function getObject($path, $mode, $class = '\org\majkel\dbase\File') {
3940
$reflection = new ReflectionClass($class);

src/Format.php

+30-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class Format {
3737

3838
/** @var \SplFileObject File handle */
3939
protected $file;
40-
/** @var \SplFileObject File handle */
40+
/** @var \org\majkel\dbase\memo\MemoInterface File handle */
4141
protected $memoFile;
4242
/** @var \org\majkel\dbase\Header */
4343
protected $header;
@@ -53,6 +53,7 @@ abstract class Format {
5353
/**
5454
* @param string $filePath
5555
* @param string $mode
56+
* @throws \ReflectionException
5657
*/
5758
public function __construct($filePath, $mode) {
5859
$this->mode = $mode;
@@ -61,6 +62,7 @@ public function __construct($filePath, $mode) {
6162

6263
/**
6364
* @return \org\majkel\dbase\Header
65+
* @throws Exception
6466
*/
6567
public function getHeader() {
6668
if (is_null($this->header)) {
@@ -71,6 +73,7 @@ public function getHeader() {
7173

7274
/**
7375
* @return boolean
76+
* @throws Exception
7477
*/
7578
public function isValid() {
7679
return $this->getHeader()->isValid();
@@ -85,6 +88,7 @@ public function getFileInfo() {
8588

8689
/**
8790
* @return \SplFileInfo
91+
* @throws Exception
8892
*/
8993
public function getMemoFileInfo() {
9094
return $this->getMemo()->getFileInfo();
@@ -100,6 +104,7 @@ public function getName() {
100104
/**
101105
* @param integer $index
102106
* @return Record
107+
* @throws Exception
103108
*/
104109
public function getRecord($index) {
105110
$records = $this->getRecords($index, 1);
@@ -117,13 +122,18 @@ public function getRecords($index, $length) {
117122
list($start, $stop) = $this->getReadBoundaries($index, $length);
118123
$file = $this->getFile();
119124
$rSz = $this->getHeader()->getRecordSize();
120-
$file->fseek($this->getHeader()->getHeaderSize() + $start * $rSz);
125+
$offset = $this->getHeader()->getHeaderSize() + $start * $rSz;
126+
$file->fseek($offset);
121127
$format = $this->getRecordFormat();
122128
$allData = $file->fread($rSz * $length);
123129
$records = array();
124130
for ($i = 0; $start < $stop; ++$start, ++$i) {
125-
$data = unpack($format, strlen($allData) === $rSz
126-
? $allData : substr($allData, $i * $rSz, $rSz));
131+
if (strlen($allData) === $rSz) {
132+
$recordData = $allData;
133+
} else {
134+
$recordData = substr($allData, $i * $rSz, $rSz);
135+
}
136+
$data = unpack($format, $recordData);
127137
$records[$start] = $this->createRecord($data);
128138
}
129139
return $records;
@@ -227,8 +237,8 @@ public function isTransaction() {
227237
}
228238

229239
/**
230-
* @return HeaderInterface
231240
* @return boolean
241+
* @throws Exception
232242
*/
233243
protected function checkIfTransaction() {
234244
$currentHeader = $this->readHeader();
@@ -241,6 +251,7 @@ protected function checkIfTransaction() {
241251

242252
/**
243253
* @param boolean $enabled
254+
* @throws Exception
244255
*/
245256
protected function setTransactionStatus($enabled) {
246257
$enabled = (boolean) $enabled;
@@ -312,6 +323,7 @@ public function markDeleted($index, $deleted) {
312323

313324
/**
314325
* @return string
326+
* @throws Exception
315327
*/
316328
protected function getWriteRecordFormat() {
317329
if (is_null($this->writeRecordFormat)) {
@@ -351,6 +363,7 @@ protected function serializeRecord(Record $record) {
351363
/**
352364
* @param integer $index
353365
* @return integer
366+
* @throws Exception
354367
*/
355368
private function getRecordOffset($index) {
356369
return $index * $this->getHeader()->getRecordSize() + $this->getHeader()->getHeaderSize();
@@ -359,6 +372,7 @@ private function getRecordOffset($index) {
359372
/**
360373
* @param \org\majkel\dbase\Record $data
361374
* @return integer
375+
* @throws Exception
362376
*/
363377
public function insert(Record $data) {
364378
$header = $this->getHeader();
@@ -378,9 +392,10 @@ public function insert(Record $data) {
378392
}
379393

380394
/**
381-
* @param integer $index
395+
* @param integer $index
382396
* @param \org\majkel\dbase\Record $data
383397
* @return void
398+
* @throws Exception
384399
*/
385400
public function update($index, Record $data) {
386401
list($offset) = $this->getReadBoundaries($index, 0);
@@ -405,6 +420,7 @@ protected function getWriteHeaderFormat() {
405420

406421
/**
407422
* @return void
423+
* @throws Exception
408424
*/
409425
protected function writeHeader() {
410426
$file = $this->getFile();
@@ -427,6 +443,7 @@ protected function writeHeader() {
427443

428444
/**
429445
* @return Header
446+
* @throws Exception
430447
*/
431448
protected function readHeader() {
432449
$file = $this->getFile();
@@ -497,6 +514,7 @@ protected function createField($data) {
497514

498515
/**
499516
* @return string
517+
* @throws Exception
500518
*/
501519
protected function getRecordFormat() {
502520
if (is_null($this->recordFormat)) {
@@ -512,6 +530,7 @@ protected function getRecordFormat() {
512530
/**
513531
* @param integer $index
514532
* @return string
533+
* @throws Exception
515534
*/
516535
protected function readMemoEntry($index) {
517536
return $this->getMemo()->getEntry($index);
@@ -520,6 +539,7 @@ protected function readMemoEntry($index) {
520539
/**
521540
* @param array $data
522541
* @return \org\majkel\dbase\Record
542+
* @throws Exception
523543
*/
524544
protected function createRecord($data) {
525545
$record = new Record;
@@ -553,6 +573,7 @@ abstract public function getType();
553573
/**
554574
* @param \org\majkel\dbase\Header $header
555575
* @return $this
576+
* @throws Exception
556577
*/
557578
public function create(Header $header) {
558579
$this->getFile()->ftruncate(0);
@@ -575,6 +596,7 @@ public function create(Header $header) {
575596

576597
/**
577598
* @return integer
599+
* @throws Exception
578600
*/
579601
protected function calculateRecordSize() {
580602
$result = 1;
@@ -586,6 +608,7 @@ protected function calculateRecordSize() {
586608

587609
/**
588610
* @return integer
611+
* @throws Exception
589612
*/
590613
protected function calculateHeaderSize() {
591614
$result = self::HEADER_SIZE + $this->getHeader()->getFieldsCount() * self::FIELD_SIZE + 2;
@@ -601,6 +624,7 @@ protected function getWriteFieldFormat() {
601624

602625
/**
603626
* @return void
627+
* @throws Exception
604628
*/
605629
protected function writeRecords() {
606630
$file = $this->getFile();

src/Header.php

+2
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,15 @@ public function offsetSet($offset, $value) {
297297

298298
/**
299299
* @param integer $offset
300+
* @throws Exception
300301
*/
301302
public function offsetUnset($offset) {
302303
$this->removeField($offset);
303304
}
304305

305306
/**
306307
* {@inheritdoc}
308+
* @throws Exception
307309
*/
308310
public function getField($name) {
309311
if ($this->offsetExists($name)) {

0 commit comments

Comments
 (0)