Download the PHP package gwa/dom-inspector without Composer

On this page you can find all versions of the php package gwa/dom-inspector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package dom-inspector

DOMInspector

PHP >= 5.4

Latest Stable Version Total Downloads Latest Unstable Version License

Build Status Scrutinizer Code Quality

The DOMInspector provides PHP methods for traversing and inspecting nodes in HTML markup.

Installation

Install using composer:

Example Usage

Consider the following markup in the variable $markup:

<select name="fruit" class="big">
    <option value="1">apples</option>
    <option value="2" selected>oranges</option>
    <option value="3">pears</option>
    <option value="4">kiwis</option>
</select>

In our unit tests we want to inspect the structure of the HTML.

// Create an Inspector instance, passing the markup.
$inspector = new \Gwa\DOMInspector\Inspector($markup);

The inspector represents a node that contains the nodes in the markup passed into it.

We expect there should be single child node, the select element.

// (We are using the PHPUnit test framework.)

// Test that there is one node
$this->assertEquals(1, $inspector->children()->count());
$select = $inspector->children()->get(0);

// Test the "tag name" of the first node
$this->assertEquals('select', $select->tagname());

// Test that the select has the class `big`
$this->assertTrue($select->hasClass('big'));

// Test the `name` attribute value
$this->assertEquals('fruit', $select->attr('name'));

The select element should expose four option nodes.

$this->assertTrue($select->contains(4, 'option'));
$this->assertEquals(4, $select->children()->count());

Selectors

A selector is a string with one of the following formats:

Methods

Inspector / Node

find($selector) NodeList

Returns a NodeList containing all child nodes that match the selector.

children($selector = null) NodeList

Returns a NodeList containing all direct child nodes, or a single Node if an numeric index is specified, or filtered nodes if a selector string is passed.

tagname() string

Returns the tag name of the node.

id() string|null

Returns the id attribute value of the node.

attr($attr) string|null

Returns the value of an attribute of the node.

html() string

Returns the "outer" HTML value of the node.

text() string

Returns the text value of the node.

For complex text, structure (p and br) is maintained. For example with the following markup

the text method

returns

hasClass($cssclass) boolean

Assert whether the node has the class passed as an attribute.

contains($selector) boolean

Assert whether the node has one or more direct child nodes that match the selector.

containsDeep($selector) boolean

Assert whether the node contains one or more child nodes that match the selector.

containsNum($selector) boolean

Assert whether the node has a certain number of direct child nodes that match the selector.

containsNumDeep($selector) boolean

Assert whether the node contains a certain number of child nodes that match the selector.

NodeList

The NodeList is a flat list of nodes. It is iterable, so you can do this:

count() integer

Returns the number of nodes in the list.

get($index) Node

Returns the Node at the zero-based index specified.

first() Node

Returns the first Node in the list.

last() Node

Returns the last Node in the list.

filter() NodeList

Returns a new NodeList created by filtering the current list using the selector passed.


Tests

Run tests using phpunit.

$ vendor/bin/phpunit -c tests/phpunit.xml tests

All versions of dom-inspector with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package gwa/dom-inspector contains the following files

Loading the files please wait ....