Skip to content

Commit 02f3e5d

Browse files
committed
Share code for creating of database
- use same code for both code paths - properly handle return values Signed-off-by: Michal Čihař <[email protected]>
1 parent c3642c5 commit 02f3e5d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/ShapeFile.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ private function _saveRecords() {
356356
if (file_exists($dbf_name)) {
357357
unlink($dbf_name);
358358
}
359-
if (!($this->DBFFile = @dbase_create($dbf_name, $this->DBFHeader))) {
360-
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));
359+
$this->DBFFile = $this->_createDBFFile();
360+
if ($this->DBFFile === false) {
361361
return false;
362362
}
363363

@@ -417,6 +417,23 @@ private function _closeSHXFile() {
417417
}
418418
}
419419

420+
/**
421+
* Creates DBF file
422+
*
423+
* @return int|false
424+
*/
425+
private function _createDBFFile()
426+
{
427+
$dbf_name = $this->_getFilename('.dbf');
428+
$result = @dbase_create($dbf_name, $this->DBFHeader);
429+
if ($result === false ) {
430+
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));
431+
return false;
432+
}
433+
return $result;
434+
435+
}
436+
420437
/**
421438
* Loads DBF file if supported
422439
*
@@ -429,8 +446,7 @@ private function _openDBFFile($toWrite = false) {
429446
$dbf_name = $this->_getFilename('.dbf');
430447
$checkFunction = $toWrite ? 'is_writable' : 'is_readable';
431448
if (($toWrite) && (!file_exists($dbf_name))) {
432-
if (!@dbase_create($dbf_name, $this->DBFHeader)) {
433-
$this->setError(sprintf('It wasn\'t possible to create the DBase file "%s"', $dbf_name));
449+
if ($this->_createDBFFile() === false) {
434450
return false;
435451
}
436452
}

0 commit comments

Comments
 (0)