@@ -18,6 +18,7 @@ class Table
1818{
1919 /** @var int Table header length in bytes */
2020 const HEADER_LENGTH = 32 ;
21+
2122 /** @var int Record field length in bytes */
2223 const FIELD_LENGTH = 32 ;
2324
@@ -26,33 +27,70 @@ class Table
2627
2728 /** @var string Table filepath. */
2829 protected $ filepath ;
30+
2931 /** @var array|null */
3032 protected $ availableColumns ;
33+
3134 /** @var Stream */
3235 protected $ fp ;
36+
3337 /** @var int */
3438 protected $ filePos = 0 ;
39+
3540 /** @var int */
3641 protected $ recordPos = -1 ;
42+
3743 /** @var int */
3844 protected $ deleteCount = 0 ;
45+
3946 /** @var Record */
4047 protected $ record ;
48+
4149 /** @var string|null */
4250 protected $ convertFrom ;
4351
44- /** @var string */
52+ /**
53+ * @var string
54+ *
55+ * @deprecated in 1.2 and will be protected in 1.3. Use getVersion() method.
56+ */
4557 public $ version ;
46- /** @var int unixtime */
58+
59+ /**
60+ * @var int unixtime
61+ *
62+ * @deprecated in 1.2 and will be protected in 1.3. Use getModifyDate() method.
63+ */
4764 public $ modifyDate ;
48- /** @var int */
65+
66+ /**
67+ * @var int
68+ *
69+ * @deprecated in 1.2 and will be protected in 1.3. Use getRecordCount() method.
70+ */
4971 public $ recordCount ;
50- /** @var int */
72+
73+ /**
74+ * @var int
75+ *
76+ * @deprecated in 1.2 and will be protected in 1.3. Use getRecordByteLength() method.
77+ */
5178 public $ recordByteLength ;
52- /** @var bool */
79+
80+ /**
81+ * @var bool
82+ *
83+ * @deprecated in 1.2 and will be protected in 1.3. Use isInTransaction() method.
84+ */
5385 public $ inTransaction ;
54- /** @var bool */
86+
87+ /**
88+ * @var bool
89+ *
90+ * @deprecated in 1.2 and will be protected in 1.3. Use isEncrypted() method.
91+ */
5592 public $ encrypted ;
93+
5694 /** @var string */
5795 public $ mdxFlag ;
5896
@@ -64,17 +102,34 @@ class Table
64102 */
65103 public $ languageCode ;
66104
67- /** @var ColumnInterface[] */
105+ /**
106+ * @var ColumnInterface[]
107+ *
108+ * @deprecated in 1.2 and will be protected in 1.3. Use getColumns() method.
109+ */
68110 public $ columns ;
69- /** @var int */
111+
112+ /**
113+ * @var int
114+ *
115+ * @deprecated in 1.2 and will be protected in 1.3. Use getHeaderLength() method.
116+ */
70117 public $ headerLength ;
71- public $ backlist ;
118+
119+ protected $ backlist ;
120+
72121 /**
73122 * @var bool
74- * @deprecated since 1.1 and will be removed in 2.0. Use isFoxpro method instead.
123+ *
124+ * @deprecated since 1.1 and will be removed in 1.3. Use isFoxpro() method instead.
75125 */
76126 public $ foxpro ;
77- /** @var MemoInterface */
127+
128+ /**
129+ * @var MemoInterface|null
130+ *
131+ * @deprecated since 1.2 and will be removed in 1.3. Use getMemo() method instead.
132+ */
78133 public $ memo ;
79134
80135 /**
@@ -86,7 +141,7 @@ class Table
86141 *
87142 * @throws \Exception
88143 */
89- public function __construct ($ filepath , $ availableColumns = null , $ convertFrom = null )
144+ public function __construct (string $ filepath , $ availableColumns = null , $ convertFrom = null )
90145 {
91146 $ this ->filepath = $ filepath ;
92147 $ this ->availableColumns = $ availableColumns ;
@@ -325,16 +380,25 @@ private function setFilePos($offset)
325380 }
326381
327382 /**
328- * @return Record
383+ * @throws TableException
329384 */
330- public function getRecord ()
385+ private function checkHeaderTerminator ( int $ terminatorLength ): void
331386 {
332- return $ this ->record ;
333- }
387+ $ terminator = $ this ->fp ->read ($ terminatorLength );
388+ switch ($ terminatorLength ) {
389+ case 1 :
390+ if (chr (0x0D ) !== $ terminator ) {
391+ throw new TableException ('Expected header terminator not present at position ' .$ this ->fp ->tell ());
392+ }
393+ break ;
334394
335- public function getCodepage (): int
336- {
337- return ord ($ this ->languageCode );
395+ case 2 :
396+ $ unpack = unpack ('n ' , $ terminator );
397+ if (0x0D00 !== $ unpack [1 ]) {
398+ throw new TableException ('Expected header terminator not present at position ' .$ this ->fp ->tell ());
399+ }
400+ break ;
401+ }
338402 }
339403
340404 public function addColumn (ColumnInterface $ column )
@@ -349,14 +413,6 @@ public function addColumn(ColumnInterface $column)
349413 $ this ->columns [$ name ] = $ column ;
350414 }
351415
352- /**
353- * @return ColumnInterface[]
354- */
355- public function getColumns ()
356- {
357- return $ this ->columns ;
358- }
359-
360416 /**
361417 * @param $name
362418 *
@@ -373,6 +429,27 @@ public function getColumn($name)
373429 throw new \Exception (sprintf ('Column %s not found ' , $ name ));
374430 }
375431
432+ /**
433+ * @return Record
434+ */
435+ public function getRecord ()
436+ {
437+ return $ this ->record ;
438+ }
439+
440+ public function getCodepage (): int
441+ {
442+ return ord ($ this ->languageCode );
443+ }
444+
445+ /**
446+ * @return ColumnInterface[]
447+ */
448+ public function getColumns ()
449+ {
450+ return $ this ->columns ;
451+ }
452+
376453 /**
377454 * @return int
378455 */
@@ -457,25 +534,40 @@ public function isFoxpro(): bool
457534 return TableType::isFoxpro ($ this ->version );
458535 }
459536
537+ public function getModifyDate ()
538+ {
539+ return $ this ->modifyDate ;
540+ }
541+
460542 /**
461- * @throws TableException
543+ * @return bool
462544 */
463- private function checkHeaderTerminator ( int $ terminatorLength ): void
545+ public function isInTransaction ( ): bool
464546 {
465- $ terminator = $ this ->fp ->read ($ terminatorLength );
466- switch ($ terminatorLength ) {
467- case 1 :
468- if (chr (0x0D ) !== $ terminator ) {
469- throw new TableException ('Expected header terminator not present at position ' .$ this ->fp ->tell ());
470- }
471- break ;
547+ return $ this ->inTransaction ;
548+ }
472549
473- case 2 :
474- $ unpack = unpack ('n ' , $ terminator );
475- if (0x0D00 !== $ unpack [1 ]) {
476- throw new TableException ('Expected header terminator not present at position ' .$ this ->fp ->tell ());
477- }
478- break ;
479- }
550+ /**
551+ * @return bool
552+ */
553+ public function isEncrypted (): bool
554+ {
555+ return $ this ->encrypted ;
556+ }
557+
558+ /**
559+ * @return string
560+ */
561+ public function getMdxFlag (): string
562+ {
563+ return $ this ->mdxFlag ;
564+ }
565+
566+ /**
567+ * @return int
568+ */
569+ public function getHeaderLength (): int
570+ {
571+ return $ this ->headerLength ;
480572 }
481573}
0 commit comments