hstanleycrow/easyphpwebcomponents 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hstanleycrow/easyphpwebcomponents

Composer 安装命令:

composer require hstanleycrow/easyphpwebcomponents

包简介

Free PHP web components library like lists, buttons, dropdowns, and more.

README 文档

README

English | Español

EasyPHPWebComponents

PHP library for building web components such as lists, buttons, dropdowns, and more.

Requirements

  • PHP 8.0 or higher
  • Composer
  • A web server (Apache) or PHP's built-in server

The library generates plain HTML and does not depend on any CSS framework. Bootstrap is just an example used in examples.php; any framework (or none) works via addClass().

Installation

# Clone this repository
$ git clone https://github.com/hstanleycrow/EasyPHPWebComponents.git
cd EasyPHPWebComponents
composer install

Or using Composer

$ composer require hstanleycrow/easyphpwebcomponents

Usage

Components render plain HTML; you add CSS classes yourself with addClass(). The examples.php example uses Bootstrap 5.3.8 and Font Awesome 6.4.2, but they are optional, not a requirement of the library.

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" crossorigin="anonymous">

Quick example

use hstanleycrow\EasyPHPWebComponents\Icon;
use hstanleycrow\EasyPHPWebComponents\Button;

require 'vendor/autoload.php';

$buttonText = (new Icon('fa fa-home', 'Submit'))->render();

echo (new Button($buttonText))
    ->addClass('btn btn-primary')
    ->setId('my-button')
    ->render();
A full example is available in `examples.php`.

Available components

  • Icon – Renders an icon with text using CSS classes (e.g. Font Awesome).
  • Button – A button with HTML content, classes, and attributes.
  • Link – An anchor with HTML content and attributes (e.g. target, class).
  • Select – A <select> dropdown with options and a selected value.
  • UnorderedList – A <ul> list with a bullet type.
  • OrderedList – An <ol> list with a numbering type.

All of them implement Renderable (render(): string). To build your own component without modifying the library, just implement that interface:

use hstanleycrow\EasyPHPWebComponents\Renderable;

class Badge implements Renderable
{
    public function __construct(private string $text) {}

    public function render(): string
    {
        return '<span class="badge">' . $this->text . '</span>';
    }
}

Public methods

Icon

Method Description
__construct(string $iconClass, string $buttonText, string $iconPosition = 'left') Creates the icon. Throws InvalidArgumentException if $iconClass/$buttonText are empty or $iconPosition is not left/right.
render(): string Returns the icon's HTML.

Button

Method Description
__construct(string $buttonText, ?string $type = 'button') Throws InvalidArgumentException if $buttonText is empty.
addClass(string $class): self Adds CSS classes.
setId(string $id): self Sets the id.
setDisabled(bool $disabled): self Toggles the disabled attribute.
render(): string Returns the button's HTML.

Link

Method Description
__construct(string $href, string $linkContent) Throws InvalidArgumentException if $href/$linkContent are empty.
addClass(string $class): self Adds CSS classes.
setRel(string $rel): self Sets rel.
setTarget(string $target): self Sets target (default _self).
setDownload(string $download): self Sets download.
render(): string Returns the link's HTML.

Select

Method Description
__construct(array $options = [], ?string $selected = null) $options is [value => label].
addClass(string $class): self Adds CSS classes.
setId(string $id): self / getId(): string Select's id.
setName(string $name): self / getName(): string The name attribute.
setDisabled(bool $disabled): self Toggles disabled.
setMultiple(bool $multiple): self Toggles multiple selection.
render(): string Returns the <select> HTML with its <option>s.

OrderedList

Method Description
__construct(?string $type = '1') Numbering type (1, a, A, i, I).
addItem(string $item): self Adds a <li>.
setType(string $type): self Changes the numbering type.
render(): string Returns the list's HTML.

UnorderedList

Method Description
__construct(?string $type = 'circle') list-style-type value (circle, disc, square, none...).
addItem(string $item): self Adds a <li>.
setType(string $type): self Changes the list-style-type.
addClass(string $class): self Adds CSS classes.
setId(string $id): self Sets the id.
render(): string Returns the list's HTML.

Tests

composer test

See tests/ for the cases covered (happy path and errors) per component.

AI assistant documentation

See AI_USAGE.md.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固