Skip to content
Merged
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ The `/comparisons` folder can be used to run performance tests locally to compar
4. PHP HTML Builder only (the Document class), and
5. PHP HTML Builder only using PSR-4 autoloading.

These results are from August 22nd, 2026 (running on PHP 8.5):

|Configuration |Average time in milliseconds |Median time in milliseconds |Transfer size in kilobytes |
|:---|---:|---:|---:|
|1 |0.0022 |0.0020 |2.7 |
|2 |0.0151 |0.0125 |1.99 |
|3 |0.4314 |0.3025 |1.82 |
|4 |1.4446 |0.3672 |1.74 |
|5 |0.9059 |0.6750 |1.74 |

These results are from February 26th, 2024:

|Configuration |Average time in milliseconds |Median time in milliseconds |Transfer size in kilobytes |
Expand Down
18 changes: 9 additions & 9 deletions comparisons/php-html-builder-document-psr4/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,22 @@

$sections = [];
foreach ($posts as $post) {
$sections[] = \Eightfold\HTMLBuilder\Element::section(
\Eightfold\HTMLBuilder\Element::h2($post['title']),
\Eightfold\HTMLBuilder\Element::p($post['description']),
\Eightfold\HTMLBuilder\Element::p(
\Eightfold\HTMLBuilder\Element::a($post['url']['text'])
$sections[] = \Eightfold\HtmlBuilder\Element::section(
\Eightfold\HtmlBuilder\Element::h2($post['title']),
\Eightfold\HtmlBuilder\Element::p($post['description']),
\Eightfold\HtmlBuilder\Element::p(
\Eightfold\HtmlBuilder\Element::a($post['url']['text'])
->props('href ' . $post['url']['href'])
)
);
}

print \Eightfold\HTMLBuilder\Document::create(
print \Eightfold\HtmlBuilder\Document::create(
$pageTitle
)->body(
\Eightfold\HTMLBuilder\Element::h1($pageTitle),
\Eightfold\HTMLBuilder\Element::a('time')->props('href #bottom'),
\Eightfold\HTMLBuilder\Element::article(...$sections)
\Eightfold\HtmlBuilder\Element::h1($pageTitle),
\Eightfold\HtmlBuilder\Element::a('time')->props('href #bottom'),
\Eightfold\HtmlBuilder\Element::article(...$sections)
);

$end = hrtime(true);
Expand Down
28 changes: 9 additions & 19 deletions comparisons/php-html-builder-document/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@

$start = hrtime(true);

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Contracts/Contentable.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Contracts/ContentWithoutElement.php');

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/Properties.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/Contentable.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/ContentWithoutElement.php');

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Concatenate.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Element.php');

require_once(__DIR__ . '/../../src/Document.php');
require_once(__DIR__ . '/../../src/Element.php');

Expand Down Expand Up @@ -106,22 +96,22 @@

$sections = [];
foreach ($posts as $post) {
$sections[] = \Eightfold\HTMLBuilder\Element::section(
\Eightfold\HTMLBuilder\Element::h2($post['title']),
\Eightfold\HTMLBuilder\Element::p($post['description']),
\Eightfold\HTMLBuilder\Element::p(
\Eightfold\HTMLBuilder\Element::a($post['url']['text'])
$sections[] = \Eightfold\HtmlBuilder\Element::section(
\Eightfold\HtmlBuilder\Element::h2($post['title']),
\Eightfold\HtmlBuilder\Element::p($post['description']),
\Eightfold\HtmlBuilder\Element::p(
\Eightfold\HtmlBuilder\Element::a($post['url']['text'])
->props('href ' . $post['url']['href'])
)
);
}

print \Eightfold\HTMLBuilder\Document::create(
print \Eightfold\HtmlBuilder\Document::create(
$pageTitle
)->body(
\Eightfold\HTMLBuilder\Element::h1($pageTitle),
\Eightfold\HTMLBuilder\Element::a('time')->props('href #bottom'),
\Eightfold\HTMLBuilder\Element::article(...$sections)
\Eightfold\HtmlBuilder\Element::h1($pageTitle),
\Eightfold\HtmlBuilder\Element::a('time')->props('href #bottom'),
\Eightfold\HtmlBuilder\Element::article(...$sections)
);

$end = hrtime(true);
Expand Down
22 changes: 6 additions & 16 deletions comparisons/php-html-builder-element/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@

$start = hrtime(true);

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Contracts/Contentable.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Contracts/ContentWithoutElement.php');

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/Properties.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/Contentable.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Implementations/ContentWithoutElement.php');

require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Concatenate.php');
require_once(__DIR__ . '/../../vendor/8fold/php-xml-builder/src/Element.php');

require_once(__DIR__ . '/../../src/Element.php');

$pageTitle = "Page title here";
Expand Down Expand Up @@ -105,11 +95,11 @@

$sections = [];
foreach ($posts as $post) {
$sections[] = \Eightfold\HTMLBuilder\Element::section(
\Eightfold\HTMLBuilder\Element::h2($post['title']),
\Eightfold\HTMLBuilder\Element::p($post['description']),
\Eightfold\HTMLBuilder\Element::p(
\Eightfold\HTMLBuilder\Element::a($post['url']['text'])
$sections[] = \Eightfold\HtmlBuilder\Element::section(
\Eightfold\HtmlBuilder\Element::h2($post['title']),
\Eightfold\HtmlBuilder\Element::p($post['description']),
\Eightfold\HtmlBuilder\Element::p(
\Eightfold\HtmlBuilder\Element::a($post['url']['text'])
->props('href ' . $post['url']['href'])
)
);
Expand All @@ -125,7 +115,7 @@
<body>
<h1><?php print($pageTitle); ?></h1>
<p><a href="#bottom">time</a></p>
<?php print \Eightfold\HTMLBuilder\Element::article(...$sections); ?>
<?php print \Eightfold\HtmlBuilder\Element::article(...$sections); ?>
<?php
$end = hrtime(true);

Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
}
],
"require": {
"php": "^8.4",
"8fold/php-xml-builder": "^3.0"
"php": "^8.4"
},
"require-dev": {
"phpstan/phpstan": "^2.2",
Expand All @@ -20,12 +19,12 @@
},
"autoload": {
"psr-4": {
"Eightfold\\HTMLBuilder\\": "./src"
"Eightfold\\HtmlBuilder\\": "./src"
}
},
"autoload-dev": {
"psr-4": {
"Eightfold\\HTMLBuilder\\Tests\\": "./tests"
"Eightfold\\HtmlBuilder\\Tests\\": "./tests"
}
},
"config": {
Expand Down
68 changes: 6 additions & 62 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ parameters:
paths:
- src
ignoreErrors:
- '#Call to an undefined static method Eightfold\\HTMLBuilder\\Element::(.*)#'
- '#Call to an undefined static method Eightfold\\HtmlBuilder\\Element::(.*)#'
24 changes: 24 additions & 0 deletions src/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Eightfold\HtmlBuilder;

use Stringable;

class Comment implements Stringable
{
public static function create(string $content): static
{
return new static($content);
}

final private function __construct(private string $content)
{
}

public function __toString(): string
{
return "\n" . '<!-- ' . $this->content . ' -->' . "\n";
}
}
4 changes: 2 additions & 2 deletions src/Components/Copyright.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;
namespace Eightfold\HtmlBuilder\Components;

use Stringable;

use Eightfold\HTMLBuilder\Element;
use Eightfold\HtmlBuilder\Element;

class Copyright implements Stringable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/FaviconMetroColors.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;
namespace Eightfold\HtmlBuilder\Components;

enum FaviconMetroColors: string
{
Expand Down
10 changes: 4 additions & 6 deletions src/Components/Favicons.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;
namespace Eightfold\HtmlBuilder\Components;

use Stringable;

use Eightfold\XMLBuilder\Concatenate;
use Eightfold\HtmlBuilder\Element;

use Eightfold\HTMLBuilder\Element;

use Eightfold\HTMLBuilder\Components\FaviconMetroColors;
use Eightfold\HtmlBuilder\Components\FaviconMetroColors;

/**
* We use https://realfavicongenerator.net to generate favicon-related assets.
Expand Down Expand Up @@ -186,6 +184,6 @@ public function __toString(): string
'content ' . $this->appName()
);
}
return (string) Concatenate::create(...$elements);
return (string) implode('', $elements);
}
}
4 changes: 2 additions & 2 deletions src/Components/PageTitle.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder\Components;
namespace Eightfold\HtmlBuilder\Components;

use Stringable;

use Eightfold\HTMLBuilder\Element;
use Eightfold\HtmlBuilder\Element;

class PageTitle implements Stringable
{
Expand Down
11 changes: 8 additions & 3 deletions src/Document.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
declare(strict_types=1);

namespace Eightfold\HTMLBuilder;
namespace Eightfold\HtmlBuilder;

use Stringable;

use Eightfold\HTMLBuilder\Element;
use Eightfold\HtmlBuilder\Element;

class Document implements Stringable
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public function bodyProps(string ...$props): Document
return $this;
}

public function __toString(): string
public function toString(): string
{
$pageTitle = $this->title();
if (
Expand All @@ -79,6 +79,11 @@ public function __toString(): string
return $doctype . $html;
}

public function __toString(): string
{
return $this->toString();
}

private function title(): string|Stringable
{
return $this->title;
Expand Down
Loading
Loading