-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFieldRegistry.php
More file actions
81 lines (69 loc) · 2.16 KB
/
Copy pathFieldRegistry.php
File metadata and controls
81 lines (69 loc) · 2.16 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
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
<?php
namespace NeuroSYS\DoctrineDatatables;
use NeuroSYS\DoctrineDatatables\Field\Entity;
use NeuroSYS\DoctrineDatatables\Field\AbstractField;
class FieldRegistry
{
/**
* @var string[]
*/
private $types = array();
public function __construct()
{
$this->registerStandardFields();
}
/**
* Register new field type
*
* @param $type
* @param $class
*/
public function register($type, $class)
{
$this->types[$type] = $class;
}
/**
* @param $type
* @param $name
* @param array $options
* @return Field
* @throws \Exception
*/
public function resolve($type, Table $table, $options = array())
{
if (empty($type)) {
$type = 'text';
}
if (!array_key_exists($type, $this->types)) {
throw new \Exception(sprintf("Field type '%s' does not exist!", $type));
}
$class = $this->types[$type];
//$path = explode('.', $path);
//$size = count($path);
//for ($i = 0; $i < $size; $i++) {
/**
* @var AbstractField $field
*/
//if (isset($path[$i+1])) {
// $field = $parent->addJoin($path[$i]);
//} else {
$field = new $class($table, $options);
//$field->setPath($path);
//}
//$parent = $field;
//}
// return last generated field;
return $field;
}
protected function registerStandardFields()
{
$this->register("empty", '\\NeuroSYS\\DoctrineDatatables\\Field\\EmptyField');
$this->register("text", '\\NeuroSYS\\DoctrineDatatables\\Field\\TextField');
$this->register("number", '\\NeuroSYS\\DoctrineDatatables\\Field\\NumberField');
$this->register("choice", '\\NeuroSYS\\DoctrineDatatables\\Field\\ChoiceField');
$this->register("boolean", '\\NeuroSYS\\DoctrineDatatables\\Field\\BooleanField');
$this->register("date", '\\NeuroSYS\\DoctrineDatatables\\Field\\DateField');
$this->register("entity", '\\NeuroSYS\\DoctrineDatatables\\Field\\Entity');
return $this;
}
}