-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdapterFactory.php
More file actions
45 lines (34 loc) · 1.07 KB
/
AdapterFactory.php
File metadata and controls
45 lines (34 loc) · 1.07 KB
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
<?php
namespace Barbet;
require_once dirname(__FILE__) . "\Exceptions.php";
require_once dirname(__FILE__) . "\Adapter\QueryFactoryAdapter.php";
require_once dirname(__FILE__) . "\Adapter\WriterAdapter.php";
require_once dirname(__FILE__) . "\Adapter\SyntaxAdapter.php";
use Barbet\BarbetExceptions;
use Barbet\WriterAdapter;
use Barbet\SyntaxAdapter;
use Barbet\Query\QueryFactoryAdapter;
class AdapterFactory
{
public function createAdapter($type = null)
{
try {
if ($type == null) {
throw new BarbetExceptions("BarbetQueryBuilder Error : Instance of registered writer class is required as parameter to create adapter");
}
if ($type instanceof Query\QueryFactory) {
return new QueryFactoryAdapter($type);
}
if ($type instanceof QueryWriter) {
return new WriterAdapter($type);
}
if ($type instanceof SyntaxWriter) {
return new SyntaxAdapter($type);
}
throw new BarbetExceptions("BarbetQueryBuilder Error : Class of " . get_class($type) . " is an invalid class");
} catch(BarbetExceptions $e) {
echo $e->getMessage();
}
}
}
?>