From 2ab1478fba92e23af94a1d7b7889815a9b0553f6 Mon Sep 17 00:00:00 2001
From: Marco Antonio Villegas Vega <marvil07@gmail.com>
Date: Wed, 10 Feb 2010 02:50:09 -0500
Subject: [PATCH] autoload integration, aka avoid manual requires

- update info file with autoload dependency
- implement hook_autoload_info()
- split test backend classes on new file to avoid a not defined class, because
autoload is executed __after__ bootstrap, where drupal_load get all php

thanks autoload
---
 commitlog/commitlog.module                         |    3 -
 includes/VersioncontrolAccount.php                 |    3 -
 includes/VersioncontrolBranch.php                  |    2 -
 includes/VersioncontrolItem.php                    |    2 -
 includes/VersioncontrolLabel.php                   |    2 -
 includes/VersioncontrolOperation.php               |    4 -
 includes/VersioncontrolRepository.php              |    4 -
 includes/VersioncontrolTag.php                     |    2 -
 ...VersioncontrolRepositoryManagementTestCase.test |    2 +-
 ...ersioncontrolRepositoryUnitTestingTestCase.test |    2 +-
 tests/versioncontrol_test.inc                      |   37 ++++++++++
 tests/versioncontrol_test.module                   |   77 ++++++--------------
 versioncontrol.admin.inc                           |    5 --
 versioncontrol.info                                |    1 +
 versioncontrol.module                              |   35 ++++++++-
 versioncontrol.pages.inc                           |    4 -
 .../versioncontrol_account_status.test             |    2 +-
 .../versioncontrol_fakevcs.module                  |    2 -
 18 files changed, 94 insertions(+), 95 deletions(-)
 create mode 100644 tests/versioncontrol_test.inc

diff --git a/commitlog/commitlog.module b/commitlog/commitlog.module
index 42c8243..76daa2d 100644
--- a/commitlog/commitlog.module
+++ b/commitlog/commitlog.module
@@ -9,9 +9,6 @@
  * Copyright 2007, 2008, 2009 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
  */
 
-//TODO: define if we want to do the load each time, per use, or all-in-one like views.inc
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolAccount.php';
-
 /**
  * Implementation of hook_menu().
  */
diff --git a/includes/VersioncontrolAccount.php b/includes/VersioncontrolAccount.php
index 59939d4..eca4465 100644
--- a/includes/VersioncontrolAccount.php
+++ b/includes/VersioncontrolAccount.php
@@ -5,9 +5,6 @@
  * Account class
  */
 
-require_once 'VersioncontrolAccount.php';
-require_once 'VersioncontrolRepository.php';
-
 /**
  * Account class
  *
diff --git a/includes/VersioncontrolBranch.php b/includes/VersioncontrolBranch.php
index 3efc386..5981437 100644
--- a/includes/VersioncontrolBranch.php
+++ b/includes/VersioncontrolBranch.php
@@ -5,8 +5,6 @@
  * Repo Branch class
  */
 
-require_once 'VersioncontrolLabel.php';
-
 /**
  * Represents a branch of code
  */
diff --git a/includes/VersioncontrolItem.php b/includes/VersioncontrolItem.php
index 80c2d7a..625bce3 100644
--- a/includes/VersioncontrolItem.php
+++ b/includes/VersioncontrolItem.php
@@ -5,8 +5,6 @@
  * Item class
  */
 
-require_once 'VersioncontrolRepository.php';
-
 /**
  * @name VCS item types.
  */
diff --git a/includes/VersioncontrolLabel.php b/includes/VersioncontrolLabel.php
index 22d21bc..f2726f8 100644
--- a/includes/VersioncontrolLabel.php
+++ b/includes/VersioncontrolLabel.php
@@ -5,8 +5,6 @@
  * Repo Label class
  */
 
-require_once 'VersioncontrolRepository.php';
-
 /**
  * @name VCS label types
  * Use same values as VERSIONCONTROL_OPERATION_* for backward compatibility
diff --git a/includes/VersioncontrolOperation.php b/includes/VersioncontrolOperation.php
index 2c89a2e..5177e3b 100644
--- a/includes/VersioncontrolOperation.php
+++ b/includes/VersioncontrolOperation.php
@@ -5,10 +5,6 @@
  * Operation class
  */
 
-require_once 'VersioncontrolItem.php';
-require_once 'VersioncontrolBranch.php';
-require_once 'VersioncontrolTag.php';
-
 /**
  * @name VCS operations
  * a.k.a. stuff that is recorded for display purposes.
diff --git a/includes/VersioncontrolRepository.php b/includes/VersioncontrolRepository.php
index 06eca90..574568e 100644
--- a/includes/VersioncontrolRepository.php
+++ b/includes/VersioncontrolRepository.php
@@ -5,10 +5,6 @@
  * Repo class
  */
 
-
-require_once 'VersioncontrolOperation.php';
-require_once 'VersioncontrolBackend.php';
-
 /**
  * Contain fundamental information about the repository.
  */
diff --git a/includes/VersioncontrolTag.php b/includes/VersioncontrolTag.php
index dcf94c1..b0b2229 100644
--- a/includes/VersioncontrolTag.php
+++ b/includes/VersioncontrolTag.php
@@ -5,8 +5,6 @@
  * Repo Tag class
  */
 
-require_once 'VersioncontrolLabel.php';
-
 /**
  * Represents a tag of code(not changing state)
  */
diff --git a/tests/VersioncontrolRepositoryManagementTestCase.test b/tests/VersioncontrolRepositoryManagementTestCase.test
index 4831a37..dea7eb5 100644
--- a/tests/VersioncontrolRepositoryManagementTestCase.test
+++ b/tests/VersioncontrolRepositoryManagementTestCase.test
@@ -29,7 +29,7 @@ class VersioncontrolRepositoryManagementTestCase extends DrupalWebTestCase {
    */
   function setUp() {
     // load core and fake test backend modules
-    parent::setUp('versioncontrol', 'versioncontrol_test');
+    parent::setUp('autoload', 'versioncontrol', 'versioncontrol_test');
 
     // Create and login the admin user
     $this->admin_user = $this->drupalCreateUser(array('administer version control systems'));
diff --git a/tests/VersioncontrolRepositoryUnitTestingTestCase.test b/tests/VersioncontrolRepositoryUnitTestingTestCase.test
index 21d077e..f30c94c 100644
--- a/tests/VersioncontrolRepositoryUnitTestingTestCase.test
+++ b/tests/VersioncontrolRepositoryUnitTestingTestCase.test
@@ -29,7 +29,7 @@ class VersioncontrolRepositoryUnitTestingTestCase extends DrupalWebTestCase {
    */
   function setUp() {
     // load core and fake test backend modules
-    parent::setUp('versioncontrol', 'versioncontrol_test');
+    parent::setUp('autoload', 'versioncontrol', 'versioncontrol_test');
     require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolRepository.php';
     $this->repoCache = VersioncontrolRepositoryCache::getInstance();
   }
diff --git a/tests/versioncontrol_test.inc b/tests/versioncontrol_test.inc
new file mode 100644
index 0000000..59a39b4
--- /dev/null
+++ b/tests/versioncontrol_test.inc
@@ -0,0 +1,37 @@
+<?php
+// $Id$
+/**
+ * @file
+ * We need to declare this file to avoid a not defined class, because autoload
+ * is executed __after__ bootstrap, where drupal_load get all php
+ */
+
+class VersioncontrolTestBackend extends VersioncontrolBackend {
+  public function __construct() {
+    $this->name = 'TestVCS';
+    $this->description = t('TestVCS backend for Version Control API.');
+    $this->capabilities = array(
+      // Use the commit hash for to identify the commit instead of an individual
+      // revision for each file.
+      VERSIONCONTROL_CAPABILITY_ATOMIC_COMMITS
+    );
+    $this->classes = array(
+      'repo' => 'VersioncontrolTestRepository',
+      'account' => 'VersioncontrolTestAccount',
+      'operation' => 'VersioncontrolTestOperation',
+      'item' => 'VersioncontrolTestItem',
+    );
+  }
+}
+
+class VersioncontrolTestRepository extends VersioncontrolRepository {
+}
+
+class VersioncontrolTestAccount extends VersioncontrolAccount {
+}
+
+class VersioncontrolTestOperation extends VersioncontrolOperation {
+}
+
+class VersioncontrolTestItem extends VersioncontrolItem {
+}
diff --git a/tests/versioncontrol_test.module b/tests/versioncontrol_test.module
index e9f9fcf..01fb0ec 100644
--- a/tests/versioncontrol_test.module
+++ b/tests/versioncontrol_test.module
@@ -6,9 +6,6 @@
  * Helper for testing Version Control core
  */
 
-require_once drupal_get_path('module', 'versioncontrol') . '/includes/VersioncontrolBackend.php';
-require_once drupal_get_path('module', 'versioncontrol') . '/includes/VersioncontrolRepository.php';
-require_once drupal_get_path('module', 'versioncontrol') . '/includes/VersioncontrolAccount.php';
 
 /**
  * Implementation of hook_versioncontrol_backends().
@@ -19,57 +16,25 @@ function versioncontrol_test_versioncontrol_backends() {
   );
 }
 
-class VersioncontrolTestBackend extends VersioncontrolBackend {
-  public function __construct() {
-    $this->name = 'TestVCS';
-    $this->description = t('TestVCS backend for Version Control API.');
-    $this->capabilities = array(
-      // Use the commit hash for to identify the commit instead of an individual
-      // revision for each file.
-      VERSIONCONTROL_CAPABILITY_ATOMIC_COMMITS
-    );
-    $this->classes = array(
-      'repo' => 'VersioncontrolTestRepository',
-      'account' => 'VersioncontrolTestAccount',
-      'operation' => 'VersioncontrolTestOperation',
-      'item' => 'VersioncontrolTestItem',
-    );
-  }
-}
-
-class VersioncontrolTestRepository extends VersioncontrolRepository {
-}
-
-class VersioncontrolTestAccount extends VersioncontrolAccount {
-}
-
-class VersioncontrolTestOperation extends VersioncontrolOperation {
-
-  /**
-   * Implementation of abstract method.
-   */
-  public function getSelectedLabel($target_item) {
-    return $operation->labels[0];
-  }
-
-}
-
-class VersioncontrolTestItem extends VersioncontrolItem {
-
-  /**
-   * Implementation of abstract method.
-   * Now we do not test fecth from repo, so this method is empty. So,
-   * when it's needed see fakevcs backend implementation for reference.
-   */
-  public function getSelectedLabelFromItem(&$other_item, $other_item_tags = array()) {
-    $_repo = array(
-      'name' => 'A test repo',
-      'vcs'  => 'fakevcs',
-      'root' => '/path/to/the/repo',
-      'authorization_method' => 'versioncontrol_admin',
-    );
-    $repo = new VersioncontrolTestRepository(1, $_repo, FALSE);
-    return new VersioncontrolBranch('HEAD', NULL, '1', $repo);
-  }
-
+/**
+ * Implementation of hook_autoload_info().
+ */
+function versioncontrol_test_autoload_info() {
+  return array(
+    'VersioncontrolTestAccount' => array(
+      'file' => 'versioncontrol_test.inc',
+    ),
+    'VersioncontrolTestBackend' => array(
+      'file' => 'versioncontrol_test.inc',
+    ),
+    'VersioncontrolTestItem' => array(
+      'file' => 'versioncontrol_test.inc',
+    ),
+    'VersioncontrolTestOperation' => array(
+      'file' => 'versioncontrol_test.inc',
+    ),
+    'VersioncontrolTestRepository' => array(
+      'file' => 'versioncontrol_test.inc',
+    ),
+  );
 }
diff --git a/versioncontrol.admin.inc b/versioncontrol.admin.inc
index 9c30f96..ec4279a 100644
--- a/versioncontrol.admin.inc
+++ b/versioncontrol.admin.inc
@@ -12,11 +12,6 @@
  * Copyright 2007, 2008, 2009 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
  */
 
-//TODO: define if we want to do the load each time, per use, or all-in-one like views.inc
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolAccount.php';
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolRepository.php';
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolOperation.php';
-
 /**
  * Form callback for "admin/project/versioncontrol-settings/general":
  * Provide a form for settings of Version Control API itself.
diff --git a/versioncontrol.info b/versioncontrol.info
index 540a8ed..d2d1488 100644
--- a/versioncontrol.info
+++ b/versioncontrol.info
@@ -1,6 +1,7 @@
 ; $Id: versioncontrol.info,v 1.3 2009/10/16 14:15:26 sdboyer Exp $
 name = "Version Control API"
 description = "An interface to version control systems whose functionality is provided by pluggable back-end modules."
+dependencies[] = autoload
 package = Version Control
 core = 6.x
 php = 5.2
diff --git a/versioncontrol.module b/versioncontrol.module
index 77f1acc..6784d66 100644
--- a/versioncontrol.module
+++ b/versioncontrol.module
@@ -74,9 +74,6 @@ define('VERSIONCONTROL_USER_ASSOCIATED_ACTIVE', 2);
 /** Used internally by the repository and account admin pages. Private constant. */
 define('VERSIONCONTROL_FORM_CREATE', FALSE);
 
-//TODO: define if we want to do the load each time, per use, or all-in-one like views.inc
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolAccount.php';
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/classes.inc';
 /**
  * Implementation of hook_init():
  * Code that is run on every page request, except for cached ones.
@@ -1580,3 +1577,35 @@ function _versioncontrol_get_string_presets() {
 
   return $presets;
 }
+
+function versioncontrol_autoload_info() {
+  return array(
+    'VersioncontrolAccount' => array(
+      'file' => 'includes/VersioncontrolAccount.php',
+    ),
+    'VersioncontrolBackend' => array(
+      'file' => 'includes/VersioncontrolBackend.php',
+    ),
+    'VersioncontrolBranch' => array(
+      'file' => 'includes/VersioncontrolBranch.php',
+    ),
+    'VersioncontrolItem' => array(
+      'file' => 'includes/VersioncontrolItem.php',
+    ),
+    'VersioncontrolLabel' => array(
+      'file' => 'includes/VersioncontrolLabel.php',
+    ),
+    'VersioncontrolOperation' => array(
+      'file' => 'includes/VersioncontrolOperation.php',
+    ),
+    'VersioncontrolRepository' => array(
+      'file' => 'includes/VersioncontrolRepository.php',
+    ),
+    'VersioncontrolRepositoryCache' => array(
+      'file' => 'includes/classes.inc',
+    ),
+    'VersioncontrolTag' => array(
+      'file' => 'includes/VersioncontrolTag.php',
+    ),
+  );
+}
diff --git a/versioncontrol.pages.inc b/versioncontrol.pages.inc
index fd44e73..93545f2 100644
--- a/versioncontrol.pages.inc
+++ b/versioncontrol.pages.inc
@@ -16,10 +16,6 @@
 // demonstrate how the various registration messages are being used.
 define('VERSIONCONTROL_REGISTER_DEMO', -1);
 
-//TODO: define if we want to do the load each time, per use, or all-in-one like views.inc
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolAccount.php';
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolRepository.php';
-
 /**
  * Form callback for "versioncontrol/register[/$register_uid[/$register_at_repo_id]]":
  * Provide an indirection that leads to an account registration form.
diff --git a/versioncontrol_account_status/versioncontrol_account_status.test b/versioncontrol_account_status/versioncontrol_account_status.test
index 85bf663..cb25fae 100644
--- a/versioncontrol_account_status/versioncontrol_account_status.test
+++ b/versioncontrol_account_status/versioncontrol_account_status.test
@@ -31,7 +31,7 @@ class VersioncontrolAccountStatusTestCase extends DrupalWebTestCase {
    */
   function setUp() {
     // load core and fake test backend modules
-    parent::setUp('versioncontrol', 'versioncontrol_test', 'versioncontrol_account_status');
+    parent::setUp('autoload', 'versioncontrol', 'versioncontrol_test', 'versioncontrol_account_status');
 
     // Create our users
     $this->admin_user = $this->drupalCreateUser(array('administer version control systems'));
diff --git a/versioncontrol_fakevcs/versioncontrol_fakevcs.module b/versioncontrol_fakevcs/versioncontrol_fakevcs.module
index 30f5b41..a41980d 100644
--- a/versioncontrol_fakevcs/versioncontrol_fakevcs.module
+++ b/versioncontrol_fakevcs/versioncontrol_fakevcs.module
@@ -14,8 +14,6 @@ define('VERSIONCONTROL_FAKEVCS_UPDATE_SCRIPT', 1);
 
 // The admin pages.
 include_once(drupal_get_path('module', 'versioncontrol_fakevcs') .'/versioncontrol_fakevcs.admin.inc');
-include_once(drupal_get_path('module', 'versioncontrol_fakevcs') .'/includes/classes.inc');
-require_once drupal_get_path('module', 'versioncontrol') .'/includes/VersioncontrolAccount.php';
 
 /**
  * Implementation of hook_versioncontrol_backends().
-- 
1.6.6.1

