Install the latest version:
$ composer require ouxsoft/phpmarkup
Create an Element class containing DOMElement processing instructions.
<?php
namespace App\Elements;
class Messages extends Ouxsoft\PHPMarkup\Element
{
private $messages;
public function onLoad() : void
{
$this->messages = $this->db->query('SELECT `msg` FROM `messages`;');
}
public function onRender(): string
{
$out = '';
foreach($this->messages as $row){
$out .= $row['msg'] . $this->getArgByName('delimiter');
}
return $out;
}
}
Configure a Processor to process a DOM using the Element class created.
<?php
use Ouxsoft\PHPMarkup\Factory\ProcessorFactory;
use App\Elements\Messages;
$processor = ProcessorFactory::getInstance();
$processor->addElement(['xpath' => '//messages', 'class_name' => App\Elements\Messages::class]);
$processor->addRoutine(['method' => 'onLoad']);
$processor->addRoutine(['method' => 'onRender', 'execute' => 'RETURN_CALL']);
$processor->addProperty('db', new PDO('sqlite:/example.db'));
$processor->parseBuffer();
?>
<html lang="en">
<messages>
<arg name="delimiter">;</arg>
</messages>
</html>
PHPMarkup is a lightweight markup processor written in PHP. It facilitates the extraction of markup into a data structure, orchestrated manipulation of said structure, and output as (optimized) markup. It is based on the LHTML standard.
Matthew Heroux
See also the list of contributors who participated in this project.
PHPMarkup is an open source project. If you find a problem or want to discuss new features or improvements please create an issue, and/or if possible create a pull request. Easily contribute using test docker image.
PHPMarkup is licensed under the MIT License - see the LICENSE file for details.
Thanks to Andy Beak for providing code reviews. Thanks to Bob Crowley for providing Project Management advising. Thanks to Aswin Vijayakumar for their useful comments. Thanks to Alexander Romanovich of White Whale Web Services for his work on the free class XPHP. All of have led to changes to this implementation.