forked from eschnou/php-atom-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AtomDocumentAdapterFactory.php
40 lines (32 loc) · 1017 Bytes
/
AtomDocumentAdapterFactory.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
<?php
require_once 'AtomFeedAdapter.php';
class DocumentAdapterFactoryException extends Exception { }
class AtomDocumentAdapterFactory {
private static $_instance;
protected $_adapterTable;
/**
*
* @return AtomDocumentAdapterFactory
*/
public static function getInstance() {
if (!self::$_instance) {
self::$_instance = new AtomDocumentAdapterFactory();
}
return self::$_instance;
}
public function adapt($data, $data_is_url=false) {
$domObj = new SimpleXMLElement($data, null, $data_is_url);
$documentAdapter = $this->_adapterTable[$domObj->getName()];
if (isset($documentAdapter)) {
return new $documentAdapter($domObj);
}
else {
throw new DocumentAdapterFactoryException("No document adapter available for " . $domObj->getName() . " document!!");
}
}
private function __construct() {
$this->_adapterTable = array();
$this->_adapterTable[AtomNS::FEED_ELEMENT] = 'AtomFeedAdapter';
$this->_adapterTable[AtomNS::ENTRY_ELEMENT] = 'AtomEntryAdapter';
}
}