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 and uses the LHTML standard.
Create a PHPMarkup Element to instruct DOMElement processing.
/**
* Class MessagesElement
*/
class MessagesElement 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;
}
}
Process a DOM using the class created.
use Ouxsoft\PHPMarkup\Factory\ProcessorFactory;
$processor = ProcessorFactory::getInstance();
$processor->addElement(['xpath' => '//messages', 'class_name' => 'MessagesElement']);
$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 available on Packagist.
Install with Composer:
composer require ouxsoft/phpmarkup
Install with Git:
git clone git@github.com:Ouxsoft/phpmarkup.git
Read the docs phpmarkup.readthedocs.io.
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. Contributing is easy with phpmarkup-stack a docker based development environment with test suite.
Thanks to Matthew Heroux for leading the development of PHPMarkup. 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.