1: <?php
2:
3: namespace PHPixie\BundleFramework\Configuration\ORM;
4:
5: 6: 7:
8: class Wrappers implements \PHPixie\ORM\Wrappers
9: {
10: 11: 12:
13: protected $wrappersMap;
14:
15: 16: 17:
18: protected $maps = array();
19:
20: 21: 22:
23: protected $names;
24:
25: 26: 27: 28:
29: public function __construct($bundlesOrm)
30: {
31: $types = array(
32: 'databaseRepositories',
33: 'databaseQueries',
34: 'databaseEntities',
35: 'embeddedEntities'
36: );
37:
38: $this->maps = array_fill_keys($types, array());
39:
40: foreach($bundlesOrm->wrappersMap() as $bundleName => $ormWrappers) {
41: foreach($types as $type) {
42: foreach($ormWrappers->$type() as $name) {
43: $this->maps[$type][$name] = $ormWrappers;
44: }
45: }
46: }
47:
48: foreach($this->maps as $type => $map) {
49: $this->names[$type] = array_keys($map);
50: }
51: }
52:
53: 54: 55:
56: public function databaseRepositories()
57: {
58: return $this->names['databaseRepositories'];
59: }
60:
61: 62: 63:
64: public function databaseQueries()
65: {
66: return $this->names['databaseQueries'];
67: }
68:
69: 70: 71:
72: public function databaseEntities()
73: {
74: return $this->names['databaseEntities'];
75: }
76:
77: 78: 79:
80: public function embeddedEntities()
81: {
82: return $this->names['embeddedEntities'];
83: }
84:
85: 86: 87:
88: public function databaseRepositoryWrapper($repository)
89: {
90: return $this
91: ->wrappers('databaseRepositories', $repository->modelName())
92: ->databaseRepositoryWrapper($repository);
93: }
94:
95: 96: 97:
98: public function databaseQueryWrapper($query)
99: {
100: return $this
101: ->wrappers('databaseQueries', $query->modelName())
102: ->databaseQueryWrapper($query);
103: }
104:
105: 106: 107:
108: public function databaseEntityWrapper($entity)
109: {
110: return $this
111: ->wrappers('databaseEntities', $entity->modelName())
112: ->databaseEntityWrapper($entity);
113: }
114:
115: 116: 117:
118: public function embeddedEntityWrapper($entity)
119: {
120: return $this
121: ->wrappers('embeddedEntities', $entity->modelName())
122: ->embeddedEntityWrapper($entity);
123: }
124:
125: 126: 127: 128: 129:
130: protected function wrappers($type, $modelName)
131: {
132: return $this->maps[$type][$modelName];
133: }
134: }