Skip to content

A Processor for Markup written in PHP. Allows for server side rendering of DOM.

License

Notifications You must be signed in to change notification settings

Ouxsoft/phpmarkup

Repository files navigation

Build Status Codacy grade Codecov Documentation Status

GitHub release (latest by date) PHP Versions Supported LICENSE

About

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.

Instructions

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>

Installation

Via Composer

PHPMarkup is available on Packagist.

Install with Composer:

composer require ouxsoft/phpmarkup

Via Git

Install with Git:

git clone git@github.com:Ouxsoft/phpmarkup.git

Documentation

Read the docs phpmarkup.readthedocs.io.

Contributing

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.

Acknowledgement

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.