Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Dec 8, 2024
2 parents 2377b80 + 76a519a commit 7d8bb8b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
- Drop support for PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0 and PHP 8.1

## [3.1.0] - YYYY-MM-DD

### Added

- Adds a toggle to allow shape files with no dbf (#41)

## [3.0.2] - 2023-09-11
### Added
- Support for PHP 8.3
Expand Down Expand Up @@ -121,6 +127,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Initial release based on bfShapeFiles

[Unreleased]: https://github.com/phpmyadmin/shapefile/compare/3.0.2...HEAD
[3.1.0]: https://github.com/phpmyadmin/shapefile/compare/3.0.2...3.1.x
[3.0.2]: https://github.com/phpmyadmin/shapefile/compare/3.0.1...3.0.2
[3.0.1]: https://github.com/phpmyadmin/shapefile/compare/3.0.0...3.0.1
[3.0.0]: https://github.com/phpmyadmin/shapefile/compare/2.1...3.0.0
Expand Down
Binary file modified data/no-dbf.shp
Binary file not shown.
Binary file modified data/no-dbf.shx
Binary file not shown.
3 changes: 1 addition & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.25.0@01a8eb06b9e9cc6cfb6a320bf9fb14331919d505">
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="src/ShapeFile.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->shpFile]]></code>
Expand All @@ -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
31 changes: 27 additions & 4 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 @@ class ShapeFile
/** @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 __construct(
) {
}

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

/**
* Loads shapefile and dbase (if supported).
*
Expand Down Expand Up @@ -304,7 +316,16 @@ public function getIndexFromDBFData(string $field, string $value): int
*/
private function loadDBFHeader(): array
{
$dbfFile = fopen($this->getFilename('.dbf'), 'r');
if (! self::supportsDbase()) {
return [];
}

$dbfName = $this->getFilename('.dbf');
if (! file_exists($dbfName)) {
return [];
}

$dbfFile = fopen($dbfName, 'r');
if ($dbfFile === false) {
return [];
}
Expand Down Expand Up @@ -390,9 +411,7 @@ private function loadHeaders(): bool
$this->boundingBox['mmin'] = Util::loadData('d', $this->readSHP(8));
$this->boundingBox['mmax'] = Util::loadData('d', $this->readSHP(8));

if (self::supportsDbase()) {
$this->dbfHeader = $this->loadDBFHeader();
}
$this->dbfHeader = $this->loadDBFHeader();

return true;
}
Expand Down Expand Up @@ -613,6 +632,10 @@ private function openDBFFile(): bool

$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
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.*'));
}
}

0 comments on commit 7d8bb8b

Please sign in to comment.