Permalink
Browse files

starting with backend class

  • Loading branch information...
1 parent aded0c9 commit 17d07b23abd8a594d4b621f5ee8b37ca0e9c0468 @marvil07 committed Jul 15, 2009
Showing with 56 additions and 35 deletions.
  1. +47 −30 includes/VersioncontrolBackend.php
  2. +8 −5 tests/versioncontrol_test.module
  3. +1 −0 versioncontrol.module
View
77 includes/VersioncontrolBackend.php
@@ -6,38 +6,55 @@
*
* @abstract
*/
-abstract class VersioncontrolBackend {
- // Attributes
- /**
- * simple name
- *
- * @var string
- */
- public $name;
+abstract class VersioncontrolBackend implements ArrayAccess {
+ // Attributes
+ /**
+ * simple name
+ *
+ * @var string
+ */
+ public $name;
- /**
- * simple description
- *
- * @var string
- */
- public $description;
+ /**
+ * simple description
+ *
+ * @var string
+ */
+ public $description;
- /**
- * what the backend can do, probably deprecated after interfaces approach
- *
- * @var array
- */
- public $capabilities;
+ /**
+ * what the backend can do, probably deprecated after interfaces approach
+ *
+ * @var array
+ */
+ public $capabilities;
- /**
- * XXX
- *
- * @var array
- */
- public $flags;
+ /**
+ * XXX
+ *
+ * @var array
+ */
+ public $flags;
- // Associations
- // Operations
-}
+ // Operations
+ public function __construct($name, $description, $capabilities=array(), $flags=array()) {
+ $this->name = $name;
+ $this->description = $description;
+ $this->capabilities = $capabilities;
+ $this->flags = $flags;
+ }
-?>
+ //ArrayAccess interface implementation
+ public function offsetExists($offset) {
+ return isset($this->$offset);
+ }
+ public function offsetGet($offset) {
+ return $this->$offset;
+ }
+ public function offsetSet($offset, $value) {
+ $this->$offset = $value;
+ }
+ public function offsetUnset($offset) {
+ unset($this->$offset);
+ }
+}
View
13 tests/versioncontrol_test.module
@@ -6,16 +6,19 @@
* Helper for testing Version Control core
*/
+require_once drupal_get_path('module', 'versioncontrol') . '/includes/VersioncontrolBackend.php';
+
/**
* Implementation of hook_versioncontrol_backends().
*/
function versioncontrol_test_versioncontrol_backends() {
return array(
- 'test' => array(
- 'name' => 'TestVCS',
- 'description' => t('TestVCS backend for Version Control API.'),
- 'capabilities' => array(),
- 'flags' => array(),
+ 'test' => new VersioncontrolTestBackend(
+ 'TestVCS',
+ t('TestVCS backend for Version Control API.')
),
);
}
+
+class VersioncontrolTestBackend extends VersioncontrolBackend {
+}
View
1 versioncontrol.module
@@ -444,6 +444,7 @@ function versioncontrol_user_accounts_load($uid, $include_unauthorized = FALSE)
*
* A real-life example of such a result array can be found
* in the FakeVCS example module.
+ * TODO make me static on VersioncontrolBackend
*/
function versioncontrol_get_backends() {
static $backends;

0 comments on commit 17d07b2

Please sign in to comment.