2017 © Pedro Peláez
 

library fluentdom

A fluent api for the php dom extension.

image

fluentdom/fluentdom

A fluent api for the php dom extension.

  • Sunday, July 15, 2018
  • by ThomasWeinert
  • Repository
  • 16 Watchers
  • 284 Stars
  • 68,211 Installations
  • PHP
  • 18 Dependents
  • 0 Suggesters
  • 19 Forks
  • 8 Open issues
  • 31 Versions
  • 14 % Grown

The README.md

FluentDOM

CI, (*1)

License Total Downloads Latest Stable Version Latest Unstable Version, (*2)

Copyright: 2009-2018 FluentDOM Contributors
License: The MIT License
, (*3)

FluentDOM provides extended XML handling classes for PHPs DOM, XMLReader and XMLWriter. Additionally, it contains a easy to use jQuery like, fluent interface for DOM., (*4)

Here are loaders and serializers for different formats like JSON, YAML, JsonML and others. More (like HTML5) can be installed as additional packages., (*5)

FluentDOM is a test driven project. We write tests before and during the development. You will find the PHPUnit tests in the tests/ subdirectory., (*6)

Table Of Contents

  • Examples
  • Support
  • Requirements
  • Packagist
  • Usage
  • Backwards Compatibility Breaks

Examples

Many examples can be found in the examples/ subdirectory. Here are some for an initial impression:, (*7)

$document = FluentDOM::load(
  $htmlFile,
  'text/html',
  [FluentDOM\Loader\Options::ALLOW_FILE => TRUE]
);
foreach ($document('//a[@href]') as $a) {
  $links[] = [
    'caption' => (string)$a,
    'href' => $a['href']
  ];
}
var_dump($links);

Create a Select From an Array

$_ = FluentDOM::create();
$_->formatOutput = TRUE;
echo $_(
  'select',
  ['name' => 'example'],
  $_->each(
    ['One', 'Two', 'Three'],
    function($text, $index) use ($_) {
      return $_('option', ['value' => $index], $text);
    }
  )
)->document->saveHTML();

Read Large XML Files (FluentDOM 6.2)

$reader = new FluentDOM\XMLReader();
$reader->open('sitemap.xml');
$reader->registerNamespace('s', 'http://www.sitemaps.org/schemas/sitemap/0.9');

foreach (new FluentDOM\XMLReader\SiblingIterator($reader, 's:url') as $url) {
  /** @var FluentDOM\DOM\Element $url */
  var_dump(
    [
      'location' => $url('string(s:loc)'),
      'updated' => $url('string(s:lastmod)')
    ]
  );
}

Support

The wiki provides information and usage examples., (*8)

If you find a bug or have a feature request please report it in the issue tracker., (*9)

You can check out the Gitter chat, too., (*10)

Be ware that the release packages (downloads) do not include the examples or tests. They are not needed to use the library. If you clone the repository, they will be included., (*11)

Security Issues

If you find a bug that has security implications, you can send an email directly to thomas@weinert.info., (*12)

Requirements

PHP

  • PHP >= 7.0
  • ext/dom
  • Optional
    • ext/xmlreader
    • ext/xmlwriter

FluentDOM needs at least PHP 7.0 and the DOM extension. For some features additional extensions might be needed, like ext/json to load JSON strings., (*13)

To use the extended XMLReader/XMLWriter you will need the respective PHP extensions, of course., (*14)

HHVM

FluentDOM 5.2 and later requires HHVM 3.5., (*15)

FluentDOM 4.0 to 5.1 work with HHVM 3.3 but it was limited. If you like to use HHVM it is strongly suggest to use newer releases., (*16)

FluentDOM 7.0 and later has not support for HHVM any more., (*17)

Packagist

FluentDOM is available on Packagist.org, just add the dependency to your composer.json., (*18)

{
  "require": {
    "fluentdom/fluentdom": "^7.0"
  }
}

Usage

The following examples load the sample.xml file, look for tags <h1> with the attribute "id" that has the value "title", set the content of these tags to "Hello World" and output the manipulated document., (*19)

Extended DOM (FluentDOM >= 5.2)

Using the FluentDOM\Document class:, (*20)

$fd = FluentDOM::load('sample.xml');
foreach ($fd('//h1[@id = "title"]') as $node) {
  $node->nodeValue = 'Hello World!';
}

echo $fd->saveXml();

jQuery Style API

Using the FluentDOM\Query class:, (*21)

echo FluentDOM('sample.xml')
  ->find('//h1[@id = "title"]')
  ->text('Hello World!');

CSS Selectors

If you install a CSS selector to Xpath translation library into a project, you can use the FluentDOM::QueryCss() function. It returns a FluentDOM\Query instance supporting CSS 3 selectors., (*22)

$fd = FluentDOM::QueryCss('sample.xml')
  ->find('h1#title')
  ->text('Hello World!');

Read more about it in the Wiki, (*23)

Creating XML

New features in FluentDOM make it easy to create XML, even XML with namespaces. Basically you can register XML namespaces on the document and methods without direct namespace support (like createElement()) will resolve the namespace and call the namespace aware variant (like createElementNS())., (*24)

Check the Wiki for an example., (*25)

Backwards Compatibility Breaks

From 6.2 to 7.0

The minimum required PHP version now is 7.0. HHVM is not supported any more. Scalar type hints and return types were added., (*26)

Moved the extended DOM classes into the FluentDOM\DOM namespace. (FluentDOM\Document -> FluentDOM\DOM\Document). FluentDOM\Nodes\Creator was moved to FluentDOM\Creator. Several internal classes were moved into a FluentDOM\Utiltity namespace., (*27)

FluentDOM\Query::get() now return a DOMNodeis the position was provided, not an array any more., (*28)

FluentDOM\DOM\Element::find() was removed, use FluentDOM($element)->find()., (*29)

Previous BC breaks are documented in the Wiki., (*30)

The Versions

15/07 2018

dev-master

9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *

 

xml jquery dom xpath xmlreader xmlwriter

10/05 2018

dev-cleanup

dev-cleanup http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *

 

xml jquery dom xpath xmlreader xmlwriter

01/10 2017

7.0.x-dev

7.0.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *

 

xml jquery dom xpath xmlreader xmlwriter

01/10 2017

7.0.0

7.0.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=7.0
  • ext-dom *

 

xml jquery dom xpath xmlreader xmlwriter

29/07 2017

6.2.x-dev

6.2.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

29/07 2017

6.2.0

6.2.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

30/06 2017

6.1.x-dev

6.1.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

30/06 2017

6.1.0

6.1.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

14/01 2017

dev-feature_nodeiterator

dev-feature_nodeiterator http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

24/12 2016

6.0.x-dev

6.0.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

24/12 2016

6.0.1

6.0.1.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

22/12 2016

6.0.0

6.0.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-dom *

 

xml jquery dom xpath

07/07 2015

5.3.0

5.3.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-dom *

 

xml jquery dom xpath

07/03 2015

5.3.x-dev

5.3.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-dom *

 

xml jquery dom xpath

05/02 2015

5.2.x-dev

5.2.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

05/02 2015

5.2.1

5.2.1.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

01/02 2015

5.2.0

5.2.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

03/10 2014

5.1.x-dev

5.1.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

03/10 2014

5.1.1

5.1.1.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

20/09 2014

5.1.0

5.1.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

11/08 2014

5.0.x-dev

5.0.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

11/08 2014

5.0.2

5.0.2.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

09/08 2014

5.0.1

5.0.1.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

31/07 2014

5.0.0

5.0.0.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

29/07 2014

4.1.x-dev

4.1.9999999.9999999-dev http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

xml jquery dom

29/07 2014

4.1.5

4.1.5.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

xml jquery dom

22/06 2014

5.0.0-RC3

5.0.0.0-RC3 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

30/05 2014

4.1.4

4.1.4.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

xml jquery dom

30/05 2014

5.0.0-RC2

5.0.0.0-RC2 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom

30/05 2014

4.1.3

4.1.3.0 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.2.0

 

xml jquery dom

29/05 2014

5.0.0-RC1

5.0.0.0-RC1 http://fluentdom.org

A fluent api for the php dom extension.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

xml jquery dom