承接 moonspot/component 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

moonspot/component

最新稳定版本:1.0.2

Composer 安装命令:

composer require moonspot/component

包简介

Library for creating HTML components in PHP

README 文档

README

A library for creating HTML components in PHP.

Creating consitent HTML components is important for good user experience. This library aims to make creating those components easier. It is the result of work I have done for years on different projects. A prime reason for this library and some of the techniques it uses is performance.

Example

Text Input

use Moonspot\Component\ComponentAbstract;

class TextInput extends ComponentAbstract {

    // Define the attributes for the component as public properties
    // id and class are defined in the parent class for all components.
    public string   $type      = 'text';
    public string   $name      = '';
    public bool     $required  = false;
    public int|null $minlength = null;
    public int|null $maxlength = null;
    public int|null $size      = null;

    // For other settings, define them as protected properties
    protected string $label = '';

    // function where the markup is defined
    public function markup() {
        ?>
        <label for="<?=htmlspecialchars($this->id)?>"><?=htmlspecialchars($this->label)?></label><br> 
        <input <?=$this->attributes()?> />
        <?php
    }

    // An inline style or a link tag to a css file can be used here.
    // Either way, it will only be included once in the output. There
    // is also a similar function named "script" for loading script tags.
    public static function css() {
        ?>
        <style>
            input[type=text] {
                font-size: 14px;
            }
        </style>
        <?php
    }
}

TextInput::render(attributes: [
    'id' => 'myinput1'
]);

TextInput::render(attributes: [
    'id' => 'myinput2'
]);

Output:

        <style>
            input[type=text] {
                font-size: 14px;
            }
        </style>
        <input id="myinput1" type="text" />
        <input id="myinput2" type="text" />

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-06-16