From 32eddcff0350947a3582cd878487e29a181fc275 Mon Sep 17 00:00:00 2001
From: Gordon Heydon <gordon@heydon.com.au>
Date: Sun, 18 Aug 2013 15:55:12 +1000
Subject: [PATCH] Issue #2068145 by gordon: Added Extend libraries to use
 Drupal's build in class loader for PSR0 compatible
 libraries.

---
 libraries.api.php | 5 +++++
 libraries.module  | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libraries.api.php b/libraries.api.php
index ee6efa7..a5a381f 100644
--- a/libraries.api.php
+++ b/libraries.api.php
@@ -66,6 +66,8 @@
  *     - css: A list of CSS files to load, using the same syntax as Drupal
  *       core's hook_library().
  *     - php: A list of PHP files to load.
+ *       If the PHP is actually a PSR0 library then you can set the namespace for
+ *       this libaray and it will be registered using Drupal's current class loader.
  *   - dependencies: An array of libraries this library depends on. Similar to
  *     declaring module dependencies, the dependency declaration may contain
  *     information on the supported version. Examples of supported declarations:
@@ -216,6 +218,9 @@ function hook_libraries_info() {
       'php' => array(
         'exlib.php',
         'exlib.inc',
+        'exlib2.php' => array(
+          'namespace' => 'exlib2', // spedify the name space for a PSR0 compatible library.
+        ),
       ),
     ),
     // Optional: Specify alternative variants of the library, if available.
diff --git a/libraries.module b/libraries.module
index 943449b..95e216c 100644
--- a/libraries.module
+++ b/libraries.module
@@ -678,10 +678,15 @@ function libraries_load_files($library) {
 
   // Load PHP files.
   if (!empty($library['files']['php'])) {
-    foreach ($library['files']['php'] as $file => $array) {
+    foreach ($library['files']['php'] as $file => $options) {
       $file_path = DRUPAL_ROOT . '/' . $path . '/' . $file;
       if (file_exists($file_path)) {
-        require_once $file_path;
+        if (empty($options['namespace'])) {
+          require_once $file_path;
+        }
+        else {
+          drupal_classloader()->add($options['namespace'], DRUPAL_ROOT . '/' . $path);
+        }
         $count++;
       }
     }
-- 
1.7.12.4 (Apple Git-37)

