Skip to content
Thomas Weinert edited this page Feb 1, 2015 · 3 revisions

Loader Plugins

You can define you own loaders in separate Composer packages. Here are several reasons for this approach.

  1. Special formats that are not needed often.
  2. Dependencies to 3rd party libraries
  3. Separate updates and releases

The composer.json of the plugin should require the FluentDOM package and add a file based autoloader.

{
  "require": {
    "fluentdom/fluentdom": "~5.2",
  },
  "autoload": {
     "files" : ["src/plugin.php"]
  }
}

The file based autoloader triggers the plugin registration.

namespace FluentDOM\HTML5 {
  if (class_exists('\\FluentDOM')) {
    \FluentDOM::registerLoader(
      new \FluentDOM\Loader\Lazy(
        [
          'text/html5' => function () {
             return new Loader;
          },
          'html5' => function () {
             return new Loader;
          }
        ]
      )
    );
  }
}
Clone this wiki locally