forked from ezsystems/ezpublish-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Handler.php
220 lines (194 loc) · 5.96 KB
/
Handler.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* File containing the Handler in memory implementation
*
* @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
* @version //autogentag//
*/
namespace eZ\Publish\Core\Persistence\InMemory;
use eZ\Publish\SPI\Persistence\Handler as HandlerInterface;
use eZ\Publish\Core\Persistence\FieldTypeRegistry;
use eZ\Publish\Core\Base\Exceptions\MissingClass;
/**
* The main handler for in memory Storage Engine
*/
class Handler implements HandlerInterface
{
/**
* Instances of handlers
*
* @var object[]
*/
protected $serviceHandlers = array();
/**
* Instance of in-memory backend that reads data from js files into memory and writes to memory
*
* @var \eZ\Publish\Core\Persistence\InMemory\Backend
*/
protected $backend;
/**
* FieldType registry
*
* @var \eZ\Publish\Core\Persistence\FieldTypeRegistry
*/
protected $fieldTypeRegistry;
/**
* Setup instance with an instance of Backend class
*/
public function __construct( FieldTypeRegistry $fieldTypeRegistry = null )
{
$this->backend = new Backend( json_decode( file_get_contents( __DIR__ . '/data.json' ), true ) );
$this->fieldTypeRegistry = $fieldTypeRegistry;
}
/**
* @return Backend
*/
public function getBackend()
{
return $this->backend;
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Handler
*/
public function contentHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\ContentHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Search\Handler
*/
public function searchHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\SearchHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Type\Handler
*/
public function contentTypeHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\ContentTypeHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Language\Handler
*/
public function contentLanguageHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\LanguageHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Location\Handler
*/
public function locationHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\LocationHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Location\Search\Handler
*/
public function locationSearchHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\LocationSearchHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\ObjectState\Handler
*/
public function objectStateHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\ObjectStateHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\User\Handler
*/
public function userHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\UserHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Section\Handler
*/
public function sectionHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\SectionHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler
*/
public function trashHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\TrashHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\UrlAlias\Handler
*/
public function urlAliasHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\UrlAliasHandler' );
}
/**
* @return \eZ\Publish\SPI\Persistence\Content\UrlWildcard\Handler
*/
public function urlWildcardHandler()
{
return $this->serviceHandler( 'eZ\\Publish\\Core\\Persistence\\InMemory\\UrlWildcardHandler' );
}
/**
* Begin transaction
*
* Begins an transaction, make sure you'll call commit or rollback when done,
* otherwise work will be lost.
*/
public function beginTransaction()
{
$this->backend->beginTransaction();
}
/**
* Commit transaction
*
* Commit transaction, or throw exceptions if no transactions has been started.
*
* @throws \RuntimeException If no transaction has been started
*/
public function commit()
{
$this->backend->commit();
}
/**
* Rollback transaction
*
* Rollback transaction, or throw exceptions if no transactions has been started.
*
* @throws \RuntimeException If no transaction has been started
*/
public function rollback()
{
$this->backend->rollback();
}
/**
* Get/create instance of service handler objects
*
* @param string $className
*
* @throws \eZ\Publish\Core\Base\Exceptions\MissingClass
*
* @return object
*/
protected function serviceHandler( $className )
{
if ( isset( $this->serviceHandlers[$className] ) )
return $this->serviceHandlers[$className];
if ( class_exists( $className ) )
{
switch ( $className )
{
case 'eZ\\Publish\\Core\\Persistence\\InMemory\\ContentHandler':
$handler = new $className( $this, $this->backend, $this->fieldTypeRegistry );
break;
default:
$handler = new $className( $this, $this->backend );
}
return $this->serviceHandlers[$className] = $handler;
}
throw new MissingClass( $className, 'service handler' );
}
}