Download the PHP package webfiori/php-structs without Composer
On this page you can find all versions of the php package webfiori/php-structs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-structs
WebFiori UI Package
A PHP library for creating HTML documents and DOM manipulation with an object-oriented approach. Build dynamic web pages, forms, tables, and complex UI components programmatically with clean, readable code.
✨ Features
- 🏗️ Object-Oriented DOM Creation - Build HTML elements using intuitive PHP classes
- 🎨 Template System - Support for both HTML templates with slots and PHP templates
- 🔄 Iterator Support - Traverse child nodes using foreach loops
- 🎯 Type Safety - Full type hints and comprehensive PHPDoc documentation
- 🛡️ Security First - Built-in HTML entity escaping
- 🌐 XML Support - Generate both HTML and XML documents
📋 Table of Contents
- Installation
- Quick Start
- Core Concepts
- HTML Document Creation
- Working with Elements
- Forms and Input
- Tables and Data
- Lists and Navigation
- Images and Media
- Template System
- Styling and CSS
- Advanced Features
- Performance Tips
- API Reference
- Examples
- Contributing
🚀 Installation
Install via Composer:
Or add to your composer.json
:
Requirements
- PHP 8.1 or higher
- No additional dependencies required
⚡ Quick Start
Create Your First HTML Document
Build Elements Programmatically
🧠 Core Concepts
HTMLNode - The Foundation
Every HTML element is represented by an HTMLNode
object:
Method Chaining
Most methods return the HTMLNode instance, enabling fluent interfaces:
Parent-Child Relationships
📄 HTML Document Creation
Complete Document Structure
Head Section Management
🔧 Working with Elements
Element Creation and Manipulation
Attribute Management
Text Content and HTML Entities
Element Traversal and Manipulation
📝 Forms and Input
Complete Form Creation
Advanced Input Types
📊 Tables and Data
Dynamic Data Tables
📋 Lists and Navigation
Navigation Menus
Nested Lists
🖼️ Images and Media
Image Galleries and Media Components
🎨 Template System
HTML Templates with Slots
Create reusable HTML templates with placeholder slots:
template.html:
Using the template:
PHP Templates with Logic
Create dynamic templates with PHP logic:
blog-post.php:
Using the PHP template:
🎨 Styling and CSS
CSS Management
Responsive Design
🚀 Advanced Features
Iterator and Countable Interfaces
WebFiori UI implements PHP's Iterator and Countable interfaces for seamless traversal:
XML Document Generation
⚡ Performance Tips
Optimizing HTML Output
Memory Management
Efficient Styling
📚 API Reference
Core Classes
HTMLNode
The foundation class for all HTML elements.
Constructor:
Key Methods:
Method | Parameters | Return | Description |
---|---|---|---|
addChild() |
$node, $attrs = [], $chainOnParent = false |
HTMLNode |
Adds a child element |
setAttribute() |
string $name, mixed $val = null |
HTMLNode |
Sets an attribute |
setAttributes() |
array $attrs |
HTMLNode |
Sets multiple attributes |
getAttribute() |
string $name |
string\|null |
Gets attribute value |
hasAttribute() |
string $name |
bool |
Checks if attribute exists |
removeAttribute() |
string $name |
HTMLNode |
Removes an attribute |
setStyle() |
array $styles, bool $override = false |
HTMLNode |
Sets CSS styles |
setClassName() |
string $class, bool $override = true |
HTMLNode |
Sets CSS class |
applyClass() |
string $class, bool $override = true |
HTMLNode |
Applies CSS class |
text() |
string $text, bool $escEntities = true |
HTMLNode |
Sets text content |
setText() |
string $text, bool $escEntities = true |
HTMLNode |
Sets text content |
getText() |
- | string |
Gets text content |
toHTML() |
bool $formatted = false, int $initTab = 0 |
string |
Generates HTML |
toXML() |
bool $formatted = false |
string |
Generates XML |
Element Creation Methods:
Method | Parameters | Return | Description |
---|---|---|---|
div() |
array $attrs = [] |
HTMLNode |
Creates div element |
form() |
array $attrs = [] |
HTMLNode |
Creates form element |
input() |
string $type = 'text', array $attrs = [] |
HTMLNode |
Creates input element |
table() |
array $attrs = [] |
HTMLNode |
Creates table element |
tr() |
array $data = [], array $attrs = [], bool $headerRow = false |
HTMLNode |
Creates table row |
ul() |
array $items = [], array $attrs = [] |
HTMLNode |
Creates unordered list |
ol() |
array $items = [], array $attrs = [] |
HTMLNode |
Creates ordered list |
li() |
$body, array $attrs = [] |
HTMLNode |
Creates list item |
img() |
array $attrs = [] |
HTMLNode |
Creates image element |
anchor() |
string\|HTMLNode $body, array $attrs = [] |
HTMLNode |
Creates anchor element |
paragraph() |
string\|HTMLNode $body = '', array $attrs = [], bool $escEntities = true |
HTMLNode |
Creates paragraph |
HTMLDoc
Represents a complete HTML document.
Constructor:
Key Methods:
Method | Parameters | Return | Description |
---|---|---|---|
getBody() |
- | HTMLNode |
Gets the body element |
getHeadNode() |
- | HeadNode |
Gets the head element |
setPageTitle() |
string $title |
HTMLDoc |
Sets document title |
getPageTitle() |
- | string |
Gets document title |
setLanguage() |
string $lang |
HTMLDoc |
Sets document language |
getLanguage() |
- | string |
Gets document language |
HeadNode
Represents the HTML head section.
Key Methods:
Method | Parameters | Return | Description |
---|---|---|---|
addCSS() |
string $href, array $attrs = [] |
HeadNode |
Adds CSS file |
addJs() |
string $src, array $attrs = [] |
HeadNode |
Adds JavaScript file |
addMeta() |
string $name, string $content, array $attrs = [] |
HeadNode |
Adds meta tag |
setPageTitle() |
string $title |
HeadNode |
Sets page title |
Constants
Constant | Value | Description |
---|---|---|
HTMLNode::COMMENT_NODE |
'#COMMENT' |
Identifies comment nodes |
HTMLNode::TEXT_NODE |
'#TEXT' |
Identifies text nodes |
HTMLNode::VOID_TAGS |
array |
List of void HTML tags |
Static Methods
Method | Parameters | Return | Description |
---|---|---|---|
HTMLNode::fromFile() |
string $path, array $vars = [] |
HTMLNode\|HTMLDoc\|array |
Creates nodes from template |
Interfaces
WebFiori UI implements standard PHP interfaces:
- Iterator: Allows foreach loops over child nodes
- Countable: Enables
count()
function on nodes
🎯 Examples
Complete Web Page
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Clone the repository
- Install dependencies:
composer install
- Run tests:
composer test
- Check code style:
composer cs-check
📄 License
This library is licensed under the MIT License. See the LICENSE file for details.