magento/dom
Composer 安装命令:
composer require magento/dom
包简介
The modern DOM API for PHP 7 projects.
README 文档
README
Modern DOM API.
Built on top of PHP's native DOMDocument, this project provides access to modern DOM APIs, as you would expect working with client-side code in the browser.
Performing DOM manipulation in your server-side code enhances the way dynamic pages can be built. Utilising a standardised object-oriented interface means the page can be ready-processed, benefitting browsers, webservers and content delivery networks.
Example usage: Hello, you!
Important note: the example shown here is for illustrative purposes, but using the DOM to directly set data to elements' values tightly couples the logic to the view, which is considered bad practice. Please see the DomTemplate library for a more robust solution to binding data to the DOM.
Consider a page with a form, with an input element to enter your name. When the form is submitted, the page should greet you by your name.
This is a simple example of how source HTML files can be treated as templates. This can easily be applied to more advanced template pages to provide dynamic content, without requiring non-standard techniques such as {{curly braces}} for placeholders, or echo '<div class='easy-mistake'>' . $content['opa'] . '</div>' horrible HTML construction from within PHP.
Source HTML (name.html)
<!doctype html> <h1> Hello, <span class="name-output">you</span> ! </h1> <form> <input name="name" placeholder="Your name, please" required /> <button>Submit</button> </form>
PHP used to inject your name (index.php)
<?php require "vendor/autoload.php"; $html = file_get_contents("name.html"); $document = new \Gt\Dom\HTMLDocument($html); if(isset($_GET["name"])) { $document->querySelector(".name-output")->innerText = $_GET["name"]; } echo $document->saveHTML();
Features at a glance
- DOM level 4 classes:
HTMLDocumentElementHTMLCollection- and more extended DOM classes
- Standardised traits to add functionality in accordance with W3C
- Reference elements using CSS selectors via
querySelector(All) - Add/remove/toggle elements' classes using
ClassList ElementNodes within the document traversable with W3C properties:Element::remove()to detach it from the document- Add elements around another using
Element::before()andElement::after() - Replace an element in place using
Element::replaceWith() - Standard collection properties on the
HTMLDocument:
Page template features
This repository is intended to be as accurate to the DOM specification as possible. An extension to the repository is available at https://php.gt/domtemplate which adds page templating through custom elements and template attributes, introducing serverside functionality similar to that of WebComponents.
magento/dom 适用场景与选型建议
magento/dom 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04M 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 magento/dom 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 magento/dom 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.04M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-24
