Skip to content

Commit a1feffe

Browse files
authored
Merge pull request #19 from 8fold/elemental
BC: Remove Buildable contract and implementation
2 parents d189ea5 + 8acb22b commit a1feffe

File tree

13 files changed

+102
-209
lines changed

13 files changed

+102
-209
lines changed

.github/workflows/php82.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: PHP 8.2
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Setup PHP Action
17+
uses: shivammathur/[email protected]
18+
with:
19+
php-version: '8.2'
20+
21+
- name: Validate composer.json and composer.lock
22+
run: composer validate
23+
24+
- name: Install dependencies
25+
run: composer install --prefer-dist --no-progress
26+
27+
- name: Run style check
28+
run: composer run style
29+
30+
- name: Run static analyzer
31+
run: composer run stan
32+
33+
- name: Run tests
34+
run: composer run test

README.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# 8fold XML Builder for PHP
22

33
XML Builder is designed to build a `string`, not a document object model (DOM)
4-
or abstract syntax tree (AST). If you are looking to achieve either a DOM or AST,
5-
there are other libraries and native implementations to do so
6-
([PHP:DOM](https://www.php.net/manual/en/simplexml.examples-basic.php) and
7-
[SimpleXML](https://www.php.net/manual/en/simplexml.examples-basic.php), for example).
4+
or abstract syntax tree (AST).
5+
6+
For DOM or AST, there are other libraries and native implementations (ex. [PHP:DOM](https://www.php.net/manual/en/book.dom.php) and [SimpleXML](https://www.php.net/manual/en/simplexml.examples-basic.php)).
87

98
You might use XML Builder to generate a string you feed into either PHP:DOM or
109
Simple XML. Or, use the string as the body of an HTTP response.
1110

12-
Use the `Element` class to create individual nodes within the document itself.
11+
Use the `Element` class to create individual nodes within the document.
1312

1413
Use the `Document` class to generate the doctype declaration and root level element.
1514

@@ -52,10 +51,9 @@ Output (formatted):
5251
</root>
5352
```
5453

55-
Alternatively, there is a shorthand variation that can also be used.
54+
Alternatively, there is a shorthand variation.
5655

57-
The shorthand method uses the `__callStatic` PHP magic method to use the method
58-
name called as the document and element name, respectively.
56+
The shorthand method uses the `__callStatic` PHP magic method.
5957

6058
```php
6159
use Eightfold\XMLBuilder\Document;
@@ -72,7 +70,7 @@ Document::root(
7270
// output: Same as previous example.
7371
```
7472

75-
Both the `Document` and `Element` classes can be converted directly to a `string` using the `__toString()` magic method.
73+
Both the `Document` and `Element` classes can be converted directly to a `string` using the `__toString()` PHP magic method.
7674

7775
```php
7876
use Eightfold\XMLBuilder\Document;
@@ -89,7 +87,7 @@ echo Document::root(
8987
// output: Same as previous example.
9088
```
9189

92-
Comments are also available:
90+
Comments are available:
9391

9492
```php
9593
use Eightfold\XMLBuilder\Document;
@@ -121,16 +119,11 @@ Output (unformatted):
121119

122120
## Details
123121

124-
This library primarily came about from an experiment in which PHP was viewed
125-
without the additional capability of being a template engine. No need to parse a
126-
string to generate a complete string and future response.
122+
The origins of this library was an experiment where PHP was viewed as a "pure" programming language, not a template engine that grew into being a language.
127123

128-
The secondary pain point was to keep the feel of writing human-friendly XML
129-
(tabs and spaces) while reducing the potential for human error; specifically,
130-
mismatched beginning and ending tags.
124+
The primary pain point was to maintain the feel of writing human-readable XML (tabs and spaces) while reducing the risk of human error; specifically, mismatched beginning and end tags.
131125

132-
Finally, working with PHP:DOM and SimpleXML felt cumbersome when generating HTML
133-
and XML documents.
126+
The secondary pain point was that PHP:DOM and SimpleXML felt cumbersome when generating XML and HTML documents.
134127

135128
## Other
136129

src/Cdata.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
namespace Eightfold\XMLBuilder;
66

7-
use Eightfold\XMLBuilder\Contracts\Buildable;
7+
use Stringable;
88

9-
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
10-
11-
class Cdata implements Buildable
9+
class Cdata implements Stringable
1210
{
13-
use BuildableImp;
14-
1511
public static function create(string $content): static
1612
{
1713
return new static($content);

src/Comment.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44

55
namespace Eightfold\XMLBuilder;
66

7-
use Eightfold\XMLBuilder\Contracts\Buildable;
7+
use Stringable;
88

9-
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
10-
11-
class Comment implements Buildable
9+
class Comment implements Stringable
1210
{
13-
use BuildableImp;
14-
1511
public static function create(string $content): static
1612
{
1713
return new static($content);

src/Concatenate.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33

44
namespace Eightfold\XMLBuilder;
55

6-
use Eightfold\XMLBuilder\Contracts\Buildable;
7-
use Eightfold\XMLBuilder\Contracts\ContentWithoutElement;
8-
96
use Stringable;
107

11-
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
8+
use Eightfold\XMLBuilder\Contracts\ContentWithoutElement;
9+
1210
use Eightfold\XMLBuilder\Implementations\ContentWithoutElement as ContentWithoutElementImp;
1311

14-
class Concatenate implements Buildable, ContentWithoutElement
12+
class Concatenate implements Stringable, ContentWithoutElement
1513
{
16-
use BuildableImp;
1714
use ContentWithoutElementImp;
1815

1916
public function __toString(): string

src/Contracts/Buildable.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Document.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@
44

55
namespace Eightfold\XMLBuilder;
66

7-
use Eightfold\XMLBuilder\Contracts\Buildable;
8-
use Eightfold\XMLBuilder\Contracts\Contentable;
9-
107
use Stringable;
118

9+
use Eightfold\XMLBuilder\Contracts\Contentable;
10+
1211
use Eightfold\XMLBuilder\Concatenate;
1312

1413
use Eightfold\XMLBuilder\Callables\PropertyArrayToString;
1514

1615
use Eightfold\XMLBuilder\Implementations\Properties as PropertiesImp;
17-
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
1816
use Eightfold\XMLBuilder\Implementations\Contentable as ContentableImp;
1917

20-
class Document implements Buildable, Contentable
18+
class Document implements Stringable, Contentable
2119
{
2220
use PropertiesImp;
23-
use BuildableImp;
2421
use ContentableImp;
2522

2623
private string $version = '1.0';
@@ -38,28 +35,12 @@ public function withVersion(string|float|int $version): self
3835
return $this;
3936
}
4037

41-
/**
42-
* @deprecated 1.4 Use `withVersion` instead.
43-
*/
44-
public function setVersion(string|float|int $version): self
45-
{
46-
return $this->withVersion($version);
47-
}
48-
4938
public function withEncoding(string $encoding): self
5039
{
5140
$this->encoding = $encoding;
5241
return $this;
5342
}
5443

55-
/**
56-
* @deprecated 1.4 Use `withEncoding` instead.
57-
*/
58-
public function setEncoding(string $encoding): self
59-
{
60-
return $this->withEncoding($encoding);
61-
}
62-
6344
public function removeEncoding(): self
6445
{
6546
$this->encoding = '';
@@ -72,14 +53,6 @@ public function withStandalone(bool $standalone): self
7253
return $this;
7354
}
7455

75-
/**
76-
* @deprecated 1.4 Use `withStandalone` instead.
77-
*/
78-
public function setStandalone(bool $standalone = true): self
79-
{
80-
return $this->withStandalone($standalone);
81-
}
82-
8356
public function removeStandalone(): self
8457
{
8558
$this->standalone = '';

src/Element.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44

55
namespace Eightfold\XMLBuilder;
66

7-
use Eightfold\XMLBuilder\Contracts\Buildable;
8-
use Eightfold\XMLBuilder\Contracts\Contentable;
9-
107
use Stringable;
118

9+
use Eightfold\XMLBuilder\Contracts\Contentable;
10+
1211
use Eightfold\XMLBuilder\Concatenate;
1312

1413
use Eightfold\XMLBuilder\Implementations\Properties as PropertiesImp;
15-
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
1614
use Eightfold\XMLBuilder\Implementations\Contentable as ContentableImp;
1715

18-
class Element implements Buildable, Contentable
16+
class Element implements Stringable, Contentable
1917
{
2018
use PropertiesImp;
21-
use BuildableImp;
2219
use ContentableImp;
2320

2421
private bool $omitEndTag = false;

src/Implementations/Buildable.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/CdataBaselineTest.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,14 @@
1010

1111
class CdataBaselineTest extends TestCase
1212
{
13-
/**
14-
*@test
15-
*/
16-
public function cdata_is_stringable(): void
17-
{
18-
$this->assertEquals(
19-
(string) Cdata::create('content'),
20-
'<![CDATA[content]]>'
21-
);
22-
}
23-
2413
/**
2514
*@test
2615
*/
2716
public function cdata_can_be_initialized_statically(): void
2817
{
29-
$this->assertEquals(
30-
Cdata::create('content')->build(),
31-
'<![CDATA[content]]>'
18+
$this->assertSame(
19+
'<![CDATA[content]]>',
20+
(string) Cdata::create('content')
3221
);
3322
}
34-
35-
/**
36-
*@test
37-
*/
38-
public function cdata_exists(): void
39-
{
40-
$this->assertTrue(class_exists(Cdata::class));
41-
}
4223
}

tests/CommentBaselineTest.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,14 @@
1010

1111
class CommentBaselineTest extends TestCase
1212
{
13-
/**
14-
*@test
15-
*/
16-
public function comment_is_stringable(): void
17-
{
18-
$this->assertEquals(
19-
(string) Comment::create('content'),
20-
"\n" . '<!-- content -->' . "\n"
21-
);
22-
}
23-
2413
/**
2514
*@test
2615
*/
2716
public function comment_can_be_initialized_statically(): void
2817
{
29-
$this->assertEquals(
30-
Comment::create('content')->build(),
31-
"\n" . '<!-- content -->' . "\n"
18+
$this->assertSame(
19+
"\n" . '<!-- content -->' . "\n",
20+
(string) Comment::create('content')
3221
);
3322
}
34-
35-
/**
36-
*@test
37-
*/
38-
public function comment_exists(): void
39-
{
40-
$this->assertTrue(class_exists(Comment::class));
41-
}
4223
}

0 commit comments

Comments
 (0)