everton3x/html-object-model

Library for creating object-oriented HTML entities, in the Document Object Model style.

v1.0.0-stable 2020-03-24 11:07 UTC

This package is auto-updated.

Last update: 2024-05-24 22:06:03 UTC


README

It provides web developers with an abstraction for html entities similar to the Document Object Model.

Anyone who uses PHP for web development is used to using object orientation daily. However, when the developer goes on to create the user interface, he invariably has to leave object orientation to write markup code. Even if the web developer uses some template tools, like Twig, even so, he needs to have a lot of work with HTML making the models, besides needing to use a whole library of templates, usually bigger and with more features than necessary.

It is for this context that the Html Object Model was conceived: to make it possible to develop user interfaces in fully object-oriented HTML. Html Object Model is inspired by the PHP Object Model Document and allows the web developer to create HTML in an object-oriented way.

Installation

The standard method of installation is through Composer:

composer require everton3x/html-object-model

Use

The Html Object Model workflow follows the following scheme:

Create -> Configure -> Build

See an example:

<?php

require_once 'vendor/autoload.php';// Don't forget to include the Composer Autoloader.

// Create
$entity = new HtmlObjectModel\Element('input');

// Configure
$entity->setAttribute('id', 'entity1')
    ->setAttribute('class', 'mystyle')
    ->setAttribute('name', 'myfield');

// Build
echo $entity->build();

The generated html code should look something like:

<input id="entity1" class="mystyle" name="myfield">

Html Object Model offers many other methods for manipulating attributes and children (nodes) in HTML entities created with this library. Be sure to read the documentation to learn about all the available features and about API.

How to contribute

Please, see the CONTRIBUTING section on project wiki.

Mantainer

Everton da Rosa