1: <?php
2:
3: namespace PHPixie\BundleFramework\Configuration;
4:
5: use PHPixie\Slice\Type\ArrayData;
6:
7: 8: 9:
10: class ORM
11: {
12: 13: 14:
15: protected $slice;
16:
17: 18: 19:
20: protected $bundlesOrm;
21:
22: protected $instances = array();
23:
24: 25: 26: 27: 28:
29: public function __construct($slice, $bundlesOrm)
30: {
31: $this->slice = $slice;
32: $this->bundlesOrm = $bundlesOrm;
33: }
34:
35: 36: 37: 38:
39: public function configData()
40: {
41: return $this->instance('configData');
42: }
43:
44: 45: 46: 47:
48: public function wrappers()
49: {
50: return $this->instance('wrappers');
51: }
52:
53: 54: 55: 56:
57: protected function instance($name)
58: {
59: if(!array_key_exists($name, $this->instances)) {
60: $method = 'build'.ucfirst($name);
61: $this->instances[$name] = $this->$method();
62: }
63:
64: return $this->instances[$name];
65: }
66:
67: 68: 69:
70: protected function buildConfigData()
71: {
72: $configMap = $this->bundlesOrm->configMap();
73:
74: $models = array();
75: $relationships = array();
76:
77: foreach($configMap as $configData) {
78: $modelsData = $configData->get('models', array());
79: foreach($modelsData as $name => $modelData) {
80: $models[$name] = $modelData;
81: }
82:
83: $relationshipsData = $configData->get('relationships', array());
84: foreach($relationshipsData as $relationshipData) {
85: $relationships[] = $relationshipData;
86: }
87: }
88:
89: return $this->slice->arrayData(array(
90: 'models' => $models,
91: 'relationships' => $relationships
92: ));
93: }
94:
95: 96: 97:
98: protected function buildWrappers()
99: {
100: return new ORM\Wrappers($this->bundlesOrm);
101: }
102: }