forked from Islandora/tuque
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepository.php
131 lines (115 loc) · 3.31 KB
/
Repository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @file
* This file defines an abstract repository that can be overridden and also
* defines a concrete implementation for Fedora.
*/
namespace Tuque;
use \AbstractRepository as AbstractRepository;
require_once 'AbstractRepository.php';
require_once 'Cache.php';
require_once 'Object.php';
require_once 'RepositoryException.php';
require_once 'includes/HttpConnection.php';
require_once 'includes/Decorator.php';
/**
* Implementation of a repository config.
*/
class RepositoryConfig {
/**
* Simple constructor definition for the repository.
*/
public function __construct($url, $username = NULL, $password = NULL, AbstractCache $cache = NULL) {
$this->url = $url;
$this->username = $username;
$this->password = $password;
if ($cache == NULL) {
$this->cache = new SimpleCache();
}
}
}
/**
* This class acts as a wrapper for the actual Repository implementation.
*/
class Repository extends Decorator implements AbstractRepository {
/**
* The decorator class to wrap the objects that have not yet been ingested.
* @var string
*/
protected $newObjectDecorator = 'Tuque\NewObject';
/**
* The decorator class to wrap existing objects.
* @var string
*/
protected $objectDecorator = 'Tuque\Object';
/**
* Constructor for the Repository object.
*
* @param RepositoryConfig $config
* The configuration setting that defines what kind of repository to
* instantiate.
*/
public function __construct(RepositoryConfig $config) {
require_once 'implementations/RepositoryFactory.php';
parent::__construct(RepositoryFactory::getRepository($config));
}
/**
* Create a new object that has not been ingested and return it decorated.
*
* @see AbstractRepository::constructObject
*/
public function constructObject($id = NULL, $create_uuid = FALSE) {
$object = parent::constructObject($id, $create_uuid);
return new $this->newObjectDecorator($object);
}
/**
* Ingest a new object into the repository and return it decorated.
*
* @see AbstractRepository::ingestObject
*/
public function ingestObject(AbstractObject &$object) {
$object = parent::ingestObject($object);
return new $this->objectDecorator($object);
}
/**
* Gets a object from the repository and return it decorated.
*
* @see AbstractRepository::getObject
*/
public function getObject($id) {
$object = parent::getObject($id);
return new $this->objectDecorator($object);
}
/**
* Returns basic information about the Repository.
*
* @see AbstractRepository::describe
*/
public function describe() {
return parent::describe();
}
/**
* Removes an object from the repository.
*
* @see AbstractRepository::purgeObject
*/
public function purgeObject($id) {
return parent::purgeObject($id);
}
/**
* Search the repository for objects.
*
* @see AbstractRepository::findObjects
*/
public function findObjects(array $search) {
return parent::findObjects($search);
}
/**
* Will return an unused identifier for an object.
*
* @see AbstractRepository::getNextIdentifier
*/
public function getNextIdentifier($namespace = NULL, $create_uuid = FALSE, $number_of_identifiers = 1) {
return parent::getNextIdentifier($namespace, $create_uuid, $number_of_identifiers);
}
}