Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue #71: PSR-0 support is complete.

A default autoloader has been added.
  • Loading branch information...
commit 0f1e595f1c34b47b56ed206ae28aa0216151bb6a 1 parent 06f31fb
@technosophos authored
Showing with 46 additions and 31 deletions.
  1. +46 −31 src/qp.php
View
77 src/qp.php
@@ -16,43 +16,58 @@
* ?>
* @endcode
*
- * If no autoloader is currently operating, this will attempt to
- * require the entire QueryPath library.
+ * If no autoloader is currently operating, this will use
+ * QueryPath's default autoloader **unless**
+ * QP_NO_AUTOLOADER is defined, in which case all of the
+ * files will be statically required in.
*/
// This is sort of a last ditch attempt to load QueryPath if no
// autoloader is used.
if (!class_exists('\QueryPath\QueryPath')) {
- define('QP_NO_AUTOLOADER', TRUE);
- // This is all (and only) the required classes for QueryPath.
- // Extensions are not loaded automatically.
- require __DIR__ . '/QueryPath/Exception.php';
- require __DIR__ . '/QueryPath/ParseException.php';
- require __DIR__ . '/QueryPath/IOException.php';
- require __DIR__ . '/QueryPath/CSS/ParseException.php';
- require __DIR__ . '/QueryPath/CSS/NotImplementedException.php';
- require __DIR__ . '/QueryPath/CSS/EventHandler.php';
- require __DIR__ . '/QueryPath/CSS/SimpleSelector.php';
- require __DIR__ . '/QueryPath/CSS/Selector.php';
- require __DIR__ . '/QueryPath/CSS/Traverser.php';
- require __DIR__ . '/QueryPath/CSS/DOMTraverser/PseudoClass.php';
- // require __DIR__ . '/QueryPath/CSS/DOMTraverser/PseudoElement.php';
- require __DIR__ . '/QueryPath/CSS/DOMTraverser/Util.php';
- require __DIR__ . '/QueryPath/CSS/DOMTraverser.php';
- require __DIR__ . '/QueryPath/CSS/Token.php';
- require __DIR__ . '/QueryPath/CSS/InputStream.php';
- require __DIR__ . '/QueryPath/CSS/Scanner.php';
- require __DIR__ . '/QueryPath/CSS/Parser.php';
- require __DIR__ . '/QueryPath/CSS/QueryPathEventHandler.php';
- require __DIR__ . '/QueryPath/Query.php';
- require __DIR__ . '/QueryPath/Entities.php';
- require __DIR__ . '/QueryPath/Extension.php';
- require __DIR__ . '/QueryPath/ExtensionRegistry.php';
- require __DIR__ . '/QueryPath/Options.php';
- require __DIR__ . '/QueryPath/QueryPathIterator.php';
- require __DIR__ . '/QueryPath/DOMQuery.php';
- require __DIR__ . '/QueryPath.php';
+ // If classloaders are explicitly disabled, load everything.
+ if (defined('QP_NO_AUTOLOADER')) {
+ // This is all (and only) the required classes for QueryPath.
+ // Extensions are not loaded automatically.
+ require __DIR__ . '/QueryPath/Exception.php';
+ require __DIR__ . '/QueryPath/ParseException.php';
+ require __DIR__ . '/QueryPath/IOException.php';
+ require __DIR__ . '/QueryPath/CSS/ParseException.php';
+ require __DIR__ . '/QueryPath/CSS/NotImplementedException.php';
+ require __DIR__ . '/QueryPath/CSS/EventHandler.php';
+ require __DIR__ . '/QueryPath/CSS/SimpleSelector.php';
+ require __DIR__ . '/QueryPath/CSS/Selector.php';
+ require __DIR__ . '/QueryPath/CSS/Traverser.php';
+ require __DIR__ . '/QueryPath/CSS/DOMTraverser/PseudoClass.php';
+ // require __DIR__ . '/QueryPath/CSS/DOMTraverser/PseudoElement.php';
+ require __DIR__ . '/QueryPath/CSS/DOMTraverser/Util.php';
+ require __DIR__ . '/QueryPath/CSS/DOMTraverser.php';
+ require __DIR__ . '/QueryPath/CSS/Token.php';
+ require __DIR__ . '/QueryPath/CSS/InputStream.php';
+ require __DIR__ . '/QueryPath/CSS/Scanner.php';
+ require __DIR__ . '/QueryPath/CSS/Parser.php';
+ require __DIR__ . '/QueryPath/CSS/QueryPathEventHandler.php';
+ require __DIR__ . '/QueryPath/Query.php';
+ require __DIR__ . '/QueryPath/Entities.php';
+ require __DIR__ . '/QueryPath/Extension.php';
+ require __DIR__ . '/QueryPath/ExtensionRegistry.php';
+ require __DIR__ . '/QueryPath/Options.php';
+ require __DIR__ . '/QueryPath/QueryPathIterator.php';
+ require __DIR__ . '/QueryPath/DOMQuery.php';
+ require __DIR__ . '/QueryPath.php';
+ }
+ else {
+ spl_autoload_register(function ($klass) {
+ $parts = explode('\\', $klass);
+ if ($parts[0] == 'QueryPath') {
+ $path = __DIR__ . '/' . implode('/', $parts) . '.php';
+ if (file_exists($path)) {
+ require $path;
+ }
+ }
+ });
+ }
}
/** @addtogroup querypath_core Core API
* Core classes and functions for QueryPath.
Please sign in to comment.
Something went wrong with that request. Please try again.