{"id":20678905,"url":"https://github.com/phpgt/dom","last_synced_at":"2025-05-15T05:06:07.647Z","repository":{"id":37451234,"uuid":"49077458","full_name":"phpgt/Dom","owner":"phpgt","description":"Modern DOM API.","archived":false,"fork":false,"pushed_at":"2025-05-03T07:33:22.000Z","size":3139,"stargazers_count":121,"open_issues_count":4,"forks_count":28,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-11T20:57:26.929Z","etag":null,"topics":["css-selector","css-selectors","document-object-model","dom","dom-builder","dom-element","dom-elements","dom-library","dom-manipulation","phpgt","queryselector","w3c","webpage"],"latest_commit_sha":null,"homepage":"https://www.php.gt/dom","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["phpgt"]}},"created_at":"2016-01-05T16:19:20.000Z","updated_at":"2025-05-06T15:02:43.000Z","dependencies_parsed_at":"2023-11-30T10:26:18.213Z","dependency_job_id":"66d9e3a2-4995-48c9-bd5a-f47fd7e82bfb","html_url":"https://github.com/phpgt/Dom","commit_stats":{"total_commits":423,"total_committers":17,"mean_commits":24.88235294117647,"dds":0.182033096926714,"last_synced_commit":"bff9235d98d96d25b41cb3920c1711a3e14ac285"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/Dom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-selector","css-selectors","document-object-model","dom","dom-builder","dom-element","dom-elements","dom-library","dom-manipulation","phpgt","queryselector","w3c","webpage"],"created_at":"2024-11-16T21:23:00.698Z","updated_at":"2025-05-15T05:06:02.633Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","readme":"\u003cimg src=\"logo.png\" alt=\"The modern DOM API for PHP 7 projects\" align=\"right\" /\u003e\n\n# Modern DOM API.\n\nBuilt on top of PHP's native [DOMDocument](http://php.net/manual/en/book.dom.php), this project provides access to modern DOM APIs, as you would expect working with client-side code in the browser.\n\nPerforming 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, benefiting browsers, webservers and content delivery networks.\n\n***\n\n\u003ca href=\"https://github.com/PhpGt/Dom/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dom-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codacy.com/gh/PhpGt/Dom\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dom-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/PhpGt/Dom\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dom-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/Dom\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dom-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.php.gt/dom\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/dom-docs.svg\" alt=\"PHP.Gt/Dom documentation\" /\u003e\n\u003c/a\u003e\n\n## Example usage: Hello, you!\n\n\u003e **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](https://php.gt/domtemplate) library for a more robust solution to binding data to the DOM.\n\nConsider 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.\n\nThis 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 '\u003cdiv class='easy-mistake'\u003e' . $content['opa'] . '\u003c/div\u003e'` error-prone HTML construction from within PHP.\n\n### Source HTML (`name.html`)\n\n```html\n\u003c!doctype html\u003e\n\u003ch1\u003e\n\tHello, \u003cspan class=\"name-output\"\u003eyou\u003c/span\u003e !\n\u003c/h1\u003e\n\n\u003cform\u003e\n\t\u003cinput name=\"name\" placeholder=\"Your name, please\" required /\u003e\n\t\u003cbutton\u003eSubmit\u003c/button\u003e\n\u003c/form\u003e\n```\n\n### PHP used to inject your name (`index.php`)\n\n```php\n\u003c?php\nuse Gt\\Dom\\HTMLDocument;\nuse Gt\\Dom\\HTMLElement\\HTMLSpanElement;\nrequire \"vendor/autoload.php\";\n\n$html = file_get_contents(\"name.html\");\n$document = new HTMLDocument($html);\n\nif(isset($_GET[\"name\"])) {\n\t$span = $document-\u003equerySelector(\".name-output\");\n\t$span-\u003einnerText = $_GET[\"name\"];\n}\n\necho $document;\n```\n\n## Features at a glance\n\n+ Compatible with W3C's DOM Living Standard:\n\t+ The `Element` type represents all `HTMLElement` specifications, such as `HTMLAnchorElement` (`\u003ca\u003e`), `HTMLButtonElement` (`\u003cbutton\u003e`), `HTMLInputElement` (`\u003cinput\u003e`), `HTMLTableSectionElement` (`\u003cthead\u003e`, `\u003ctbody\u003e`, `\u003ctfoot\u003e`), etc. The particular type can be detected with `Element::getElementType()`, which returns one of the `ElementType` enum values.\n\t+ `DOMException` extensions for catching different types of exception, such as `EnumeratedValueException`, `HierarchyRequestError`, `IndexSizeException`, etc.\n\t+ Client-side functionality stubbed including classes for `FileList`, `StyleSheet`, `VideoTrackList`, `WindowProxy`, etc.\n+ DOM level 4+ functionality:\n\t+ Reference elements using CSS selectors via [`Element::querySelector()`][mdn-qs] and ([`Element::querySelectorAll()`][mdn-qsa])\n\t+ Add/remove/toggle elements' classes using [`ClassList`][mdn-classList]\n\t+ Traverse Element-only Nodes with [`Element::previousElementSibling`][mdn-pes], [`Element::nextElementSibling`][mdn-nes], [`Element::children`][mdn-children] and [`Element::lastElementChild`][mdn-lec] and [`firstElementChild`][mdn-fec], etc.\n\t+ Insert and remove child Nodes with [`ChildNode::remove()`][mdn-remove], [`ChildNode::before`][mdn-before], [`ChildNode::after`][mdn-after], [`ChildNode::replaceWith()`][mdn-replaceWith]\n+ Standard properties on the `HTMLDocument`:\n\t+ [`anchors`][mdn-anchors]\n\t+ [`forms`][mdn-forms]\n\t+ [`image`][mdn-images]\n\t+ [`links`][mdn-links]\n\t+ [`scripts`][mdn-scripts]\n\t+ [`title`][mdn-title]\n\n### Known limitations / W3C spec compliance\n\nThis repository aims to be as accurate as possible to the DOM specification at https://dom.spec.whatwg.org/ - as of v4.0.0 all functionality is implemented with the following minor but unavoidable deviations from the standard:\n\n+ Elements' `tagName` property is uppercase.\n+ To check the `HTMLElement` type, `Element::getElementType()` must be called - no subclasses of `Element` are available for usage with `instanceof`, for example.\n+ The DOM specification defines functionality that is only possible to implement on the client-side. For example, `HTMLInputElement::files` returns a `FileList` that enumerates all files that are selected by the user through the browser's interface. This kind of functionality is impossible to implement server-side, but has been stubbed out for consistency with the specification. Attempting to use client-side functionality within this library throws a `ClientSideOnlyFunctionalityException`.\n\n### Data binding and page template features\n\nThis 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 and data binding through custom elements and template attributes, introducing serverside functionality like that of WebComponents.\n\n## PHP 8.4 native HTMLDocument\n\nSince PHP 8.4's release, there has been a new native HTMLDocument class shipped in PHP natively. With this having native bindings, all operations are much faster. Work has been started to make PHPGT's Dom implementation utilise the new native code. Luckily, the DOM is a very well defined standard so whatever happens, minimal or no changes will be required to your code.\n\nTake a look at the benchmarks on the php84-benchmark branch for yourself: most operations are recorded to have a 90% or higher increase in speed by switching to the native implementation!\n\nMore information will be laid out in the readme when more work has been taken towards an implementation of the native classes.\n\n[mdn-HTMLDocument]: https://developer.mozilla.org/docs/Web/API/HTMLDocument\n[mdn-Element]: https://developer.mozilla.org/docs/Web/API/Element\n[mdn-HTMLCollection]: https://developer.mozilla.org/docs/Web/API/HTMLCollection\n[mdn-DOM-levels]: https://developer.mozilla.org/docs/DOM_Levels\n[mdn-qs]: https://developer.mozilla.org/docs/Web/API/Element/querySelector\n[mdn-qsa]: https://developer.mozilla.org/docs/Web/API/Element/querySelectorAll\n[mdn-classList]: https://developer.mozilla.org/docs/Web/API/Element/classList\n[mdn-pes]: https://developer.mozilla.org/docs/Web/API/NonDocumentTypeChildNode/previousElementSibling\n[mdn-nes]: https://developer.mozilla.org/en-US/docs/Web/API/NonDocumentTypeChildNode/nextElementSibling\n[mdn-children]: https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children\n[mdn-lec]: https://developer.mozilla.org/docs/Web/API/ParentNode/lastElementChild\n[mdn-fec]: https://developer.mozilla.org/docs/Web/API/ParentNode/firstElementChild\n[mdn-remove]: https://developer.mozilla.org/docs/Web/API/ChildNode/remove\n[mdn-before]: https://developer.mozilla.org/docs/Web/API/ChildNode/before\n[mdn-after]: https://developer.mozilla.org/docs/Web/API/ChildNode/after\n[mdn-replaceWith]: https://developer.mozilla.org/docs/Web/API/ChildNode/replaceWith\n[mdn-anchors]: https://developer.mozilla.org/docs/Web/API/Document/anchors\n[mdn-forms]: https://developer.mozilla.org/docs/Web/API/Document/forms\n[mdn-images]: https://developer.mozilla.org/docs/Web/API/Document/images\n[mdn-links]: https://developer.mozilla.org/docs/Web/API/Document/links\n[mdn-scripts]: https://developer.mozilla.org/docs/Web/API/Document/scripts\n[mdn-title]: https://developer.mozilla.org/docs/Web/API/Document/title\n","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Fdom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdom/lists"}