type = $type; $instance->minOccurs = V::get('minOccurs', 1, $field, 'int'); $instance->maxOccurs = ('unbounded' === V::get('maxOccurs', 1, $field)) ? 'unbounded' : V::get('maxOccurs', 1, $field); $instance->restrictions = (!empty($field['restrictions'])) ? self::parseRestriction($field['restrictions']) : [] ; $instance->appInfo = (!empty($field['appInfo'])) ? self::parseAppInfo($field['appInfo']) : [] ; $instance->source = self::getSourceFromAppInfo($instance->appInfo); return $instance; } static function parseRestriction($restriction) { $ret = []; if (!empty($restrictions)) { if (is_string($restrictions)) { $ret = @json_decode($restrictions, $assoc = true); if (null === $ret && 0 !== json_last_error()) { throw new Exception("Parse json error for restrictions: " . json_last_error()); } } else if (is_array($restrictions)) { $ret = $restrictions; } else { throw new Exception("Not upported restrictions"); } } return $ret; } static function parseAppInfo($appInfo) { $ret = []; if (!empty($appInfo)) { if (is_string($appInfo)) { $ret = @json_decode($appInfo, $assoc = true); if (null === $ret && 0 !== json_last_error()) { throw new Exception("Parse json error for appInfo: " . json_last_error()); } } else if (is_array($appInfo)) { $ret = $appInfo; } else { throw new Exception("Not upported appInfo"); } } return $ret; } static function getSourceFromAppInfo($appInfo) { if (!$appInfo) return 'table'; // [appInfo] => Array: // [flat_relation_cache] => Array: // [@backref_evaluate] => true // [source] => Array: // [@ref_engine] => view $source_view = (!empty($appInfo['flat_relation_cache']['source']) && 'view' === V::get('@ref_engine', '', $appInfo['flat_relation_cache']['source'])); $source_backRef = (!empty($appInfo['flat_relation_cache']) && V::get('@backref_evaluate', false, $appInfo['flat_relation_cache'])); if ($source_backRef) return 'backRef'; if ($source_view) return 'view'; return 'table'; } function __isset($name) { return (array_key_exists($name, $this->_data)); } function __get($name) { if (array_key_exists($name, $this->_data)) { return $this->_data[$name]; } return null; } function __set($name, $value) { $this->_data[$name] = $value; } function toArray() { return $this->_data; } function __toString() { return str_replace('"', '', str_replace([ '{', '}', '":', ',"' ], [ '{ ', ' }', ': ', ', ' ], json_encode($this->_data)) ); } } /* case: install Ref based on backRef - example namespace=default_db/BI_audit_ENERGA_PRACOWNICY/BI_audit_ENERGA_PRACOWNICY // [appInfo] => Array: // [flat_relation_cache] => Array: // [@backref_evaluate] => true // [source] => Array: // [@ref_engine] => view */