Download the PHP package dlindberg/dom-document-factory without Composer

On this page you can find all versions of the php package dlindberg/dom-document-factory. 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-document-factory

DOCFactory

Latest Version on Packagist Build Status Coverage Status Quality Score Total Downloads

The DOMDocument extension in PHP is very powerful and incredibly useful for manipulating HTML. However, there is just enough boilerplate code that having a little utility factory makes things just a little bit easier. I also find that what I frequently want to do is use HTMLPurifier to clean up some crufty HTML input, turn that into a DOMNode, manipulate it and then convert that back into a string. This is a simple factory to help with that workflow. It takes a string containing a fragment of HTML, purifies it, and turns it into a <body> DOMNode. There is also a very little bit of boiler plate in getting that string back out, so this can handle that too—optionally with different pass of HTMLPurifier on the way out (not frequently necessary, but occasionally helpful).

This factory is setup so that you can simply initialize and invoke it and get back a DOMNode. Manipulate the DOM however you need to and then stringify your DOMNode back out. Of course defaults are good, but flexibility is important. So you can inject a DOCFactoryConfig to adjust the settings as needed—useful if you would need to implement a factory anyway because of your use case.

Install

Via Composer

Usage

Basic Invocation

If all you really need to do is take a string of html and get a quickly usable DOMNode out of it, you can use the simply create an instance of the DOMDocumentFactory class and invoke it.

For an input of <p>This is some Text</p> if you made not further changes to your DOMNodes, the result would also be <p>this is some text</p>

Alternatively, there are two additional methods for invoking the factory. getNode(string $blob) and getDocument(string $blob). The getNode method does the same thing that invoking the class does, and returns the body from the fragment. Using getDocument will return the entire DOMDocument class. Note that you can always get to the parent DOMDocument even when using the getNode method by using DOMDocument's ownerDocument method.

If you have a section of HTML that has multiple immediate child nodes, for example:

Simply using:

would result in:

And using:

results in:

To get the same thing out that you put in you can use the stringifyFromList method. This returns an array of strings from each child node in a NodeList. If you need them as an array, you can simply use it as is. Or you can flatten the array using implode.

Custom Invocation

Sometimes you want to do something a little more complex, so the DOMDocumentFactory class constructor can take an instance DOMDocumentFactoryConfig class as its sole argument.

To create an instance of DOMDocumentFactoryConfig:

If you do not pass an instance of HTMLPurifier as $inputPurifier your settings for the HTMLPurifier will be used instead of a default HTMLPurifier object. By default no output purification is preformed. Should you want to purify the output an additional HTMLPurifier may be passed as $outputPurifier.

The configuration can also be modified after creating it:

The $settings array defaults to:

As a Static Function

You can also use this factory as a one off static function. You can provide an optional $DOMDocumentFactoryConfig when you do so. Internally the static methods spin up an instance of the DOMDocumentFactory class to do their work, so this method of use is mostly just a shortcut to actually integrating the factory into a project.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

The current tests are fairly basic; tests that more effectively attack possible edge cases or unexpected / unpredictable behaviors would be helpful.

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

The boiler plate for this project is based on The League of Extraordinary Packages' Skeleton package repository.

License

The MIT License (MIT). Please see License File for more information.


All versions of dom-document-factory with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
ext-dom Version *
ext-libxml Version *
ezyang/htmlpurifier Version ^4.10
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 dlindberg/dom-document-factory contains the following files

Loading the files please wait ....