Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a toggle to allow shape files with no dbf #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/no-dbf.shp
Binary file not shown.
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<code><![CDATA[$this->records[$index]->getContentLength()]]></code>
</PossiblyNullOperand>
<PossiblyUnusedReturnValue>
<code><![CDATA[bool]]></code>
<code><![CDATA[bool]]></code>
<code><![CDATA[int]]></code>
</PossiblyUnusedReturnValue>
Expand Down
16 changes: 16 additions & 0 deletions src/ShapeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

use function chr;
use function count;
use function dbase_close;
use function dbase_create;
use function dbase_delete_record;
use function dbase_open;
use function dbase_pack;
use function extension_loaded;
use function fclose;
use function feof;
Expand Down Expand Up @@ -76,6 +81,8 @@
/** @var array<int, ShapeRecord> */
public array $records = [];

private bool $allowNoDbf = false;

/**
* Checks whether dbase manipulations are supported.
*/
Expand All @@ -101,6 +108,11 @@
) {
}

public function setAllowNoDbf(bool $allowNoDbf): void
{
$this->allowNoDbf = $allowNoDbf;
}

/**
* Loads shapefile and dbase (if supported).
*
Expand Down Expand Up @@ -613,6 +625,10 @@

$dbfName = $this->getFilename('.dbf');
if (! is_readable($dbfName)) {
if ($this->allowNoDbf) {
return true;
}

$this->setError(sprintf('It wasn\'t possible to find the DBase file "%s"', $dbfName));

return false;
Expand Down Expand Up @@ -654,7 +670,7 @@
*
* @param int<0, max> $bytes
*/
public function readSHP(int $bytes): string|false

Check failure on line 673 in src/ShapeFile.php

View workflow job for this annotation

GitHub Actions / lint-docs

int<min,max> has not the correct format on "PhpMyAdmin\ShapeFile\ShapeFile::readSHP"
{
if ($this->shpFile === false) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/ShapeRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

use function array_values;
use function count;
use function dbase_add_record;
use function dbase_get_record_with_names;
use function dbase_numrecords;
use function dbase_replace_record;
use function fwrite;
use function in_array;
use function is_array;
Expand Down
11 changes: 11 additions & 0 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,15 @@ public function testSearch(): void
$shp->getIndexFromDBFData('CNTRY_NAME', 'Czech Republic'),
);
}

public function testAllowsNoDbf(): void
{
if (! ShapeFile::supportsDbase()) {
self::markTestSkipped();
}

$shp = new ShapeFile(ShapeType::Null);
$shp->setAllowNoDbf(true);
self::assertTrue($shp->loadFromFile('data/no-dbf.*'));
}
}
Loading