@@ -87,6 +87,9 @@ class ShapeFile
87
87
/** @var array */
88
88
public $ records = [];
89
89
90
+ /** @var bool */
91
+ private $ allowNoDbf = false ;
92
+
90
93
/**
91
94
* Checks whether dbase manipulations are supported.
92
95
*/
@@ -121,6 +124,11 @@ public function __construct(
121
124
$ this ->fileLength = 50 ;
122
125
}
123
126
127
+ public function setAllowNoDbf (bool $ allowNoDbf ): void
128
+ {
129
+ $ this ->allowNoDbf = $ allowNoDbf ;
130
+ }
131
+
124
132
/**
125
133
* Loads shapefile and dbase (if supported).
126
134
*
@@ -326,8 +334,16 @@ public function getIndexFromDBFData(string $field, $value): int
326
334
*/
327
335
private function loadDBFHeader (): array
328
336
{
329
- $ DBFFile = fopen ($ this ->getFilename ('.dbf ' ), 'r ' );
337
+ if (! self ::supportsDbase ()) {
338
+ return [];
339
+ }
330
340
341
+ $ dbfName = $ this ->getFilename ('.dbf ' );
342
+ if (! file_exists ($ dbfName )) {
343
+ return [];
344
+ }
345
+
346
+ $ DBFFile = fopen ($ dbfName , 'r ' );
331
347
$ result = [];
332
348
$ i = 1 ;
333
349
$ inHeader = true ;
@@ -405,9 +421,7 @@ private function loadHeaders(): bool
405
421
$ this ->boundingBox ['mmin ' ] = Util::loadData ('d ' , $ this ->readSHP (8 ));
406
422
$ this ->boundingBox ['mmax ' ] = Util::loadData ('d ' , $ this ->readSHP (8 ));
407
423
408
- if (self ::supportsDbase ()) {
409
- $ this ->dbfHeader = $ this ->loadDBFHeader ();
410
- }
424
+ $ this ->dbfHeader = $ this ->loadDBFHeader ();
411
425
412
426
return true ;
413
427
}
@@ -620,6 +634,10 @@ private function openDBFFile(): bool
620
634
621
635
$ dbfName = $ this ->getFilename ('.dbf ' );
622
636
if (! is_readable ($ dbfName )) {
637
+ if ($ this ->allowNoDbf ) {
638
+ return true ;
639
+ }
640
+
623
641
$ this ->setError (sprintf ('It wasn \'t possible to find the DBase file "%s" ' , $ dbfName ));
624
642
625
643
return false ;
0 commit comments