Skip to content

Commit

Permalink
Implement Arrayable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 4, 2022
1 parent 9bd5368 commit 380b3a1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased](https://github.com/inspirum/xml-php/compare/v2.0.0...master)


## [v2.1.0 (2022-07-04)](https://github.com/inspirum/xml-php/compare/v2.0.0...v2.1.0)
### Added
- Implement `\Arrayable` interface


## [v2.0.0 (2022-05-21)](https://github.com/inspirum/xml-php/compare/v1.0.1...v2.0.0)
### Changed
- Support only **PHP 8.1+**
Expand All @@ -25,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Factories for [XML builder](./src/Builder/Document.php) and [XML Reader](./src/Reader/Reader.php)
- Publicly available [`Formatter::nodeToArray`](./src/Formatter/Formatter.php) method


## [v1.0.1 (2020-01-18)](https://github.com/inspirum/xml-php/compare/v1.0.0...v1.0.1)
### Fixed
- Support "_" in elements name
Expand Down
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "inspirum/xml",
"description": "",
"description": "Simple XML writer and memory efficient XML reader with powerful xml-to-array cast",
"keywords": [
"inspirum",
"xml",
"xml-reader",
"xml-parser",
"xml-writer",
"xml-parser"
"xml-builder",
"xml-to-array"
],
"homepage": "https://github.com/inspirum/xml-php",
"license": "MIT",
Expand All @@ -22,19 +24,22 @@
"php": ">=8.1",
"ext-dom": "*",
"ext-json": "*",
"ext-xmlreader": "*"
"ext-xmlreader": "*",
"inspirum/arrayable": "^1.0"
},
"require-dev": {
"inspirum/coding-standard": "^1.0",
"phpstan/phpstan": "^1.6",
"inspirum/coding-standard": "^1.1",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6"
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {
"Inspirum\\XML\\": "src"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload-dev": {
"psr-4": {
"Inspirum\\XML\\Tests\\": "tests"
Expand Down
7 changes: 2 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" convertDeprecationsToExceptions="false">
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Unit">
Expand All @@ -13,9 +13,6 @@
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix="Interface.php">src</directory>
</exclude>
<report>
<clover outputFile="var/phpunit/logs/clover.xml"/>
<text outputFile="var/phpunit/coverage/coverage.txt"/>
Expand Down
14 changes: 13 additions & 1 deletion src/Builder/BaseNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,19 @@ public function toArray(?Config $config = null): array
}

/**
* @inheritDoc
* Convert to array
*
* @return array<int|string,mixed>
*/
public function __toArray(): array
{
return $this->toArray();
}

/**
* Convert to array
*
* @return array<int|string,mixed>
*/
public function jsonSerialize(): array
{
Expand Down
24 changes: 5 additions & 19 deletions src/Builder/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

use DOMDocument;
use DOMNode;
use Inspirum\Arrayable\Arrayable;
use Inspirum\XML\Formatter\Config;
use JsonSerializable;
use Stringable;

interface Node extends Stringable, JsonSerializable
/**
* @extends \Inspirum\Arrayable\Arrayable<int|string,mixed>
*/
interface Node extends Arrayable, Stringable, JsonSerializable
{
/**
* Add element to XML node
Expand Down Expand Up @@ -74,28 +78,10 @@ public function getNode(): ?DOMNode;
*/
public function toString(bool $formatOutput = false): string;

/**
* Convert to string
*
* @see toString()
*
* @return string
*/
public function __toString(): string;

/**
* Convert to array
*
* @return array<int|string,mixed>
*/
public function toArray(?Config $config = null): array;

/**
* Convert to array
*
* @see toArray()
*
* @return array<int|string,mixed>
*/
public function jsonSerialize(): array;
}

0 comments on commit 380b3a1

Please sign in to comment.