| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- class Type_InstanceConfig {
- var $_data = []; // { id, namespace, rootNamespace, _createdAt, SOURCE, VERSION, A_STATUS, tableName }
- static function build($instanceRow = []) {
- if (!$instanceRow) throw new Exception("Missing data in build Type InstanceConfig");
- // if (!$instanceRow['ID']) throw new Exception("Missing ID in Type RefConfig build"); // TODO: allow missing ID?
- $instanceConfig = new Type_InstanceConfig();
- $instanceConfig->id = (int)$instanceRow['id'];
- $instanceConfig->namespace = $instanceRow['namespace'];
- $instanceConfig->rootNamespace = $instanceRow['rootNamespace'];
- $instanceConfig->source = $instanceRow['SOURCE'];
- $instanceConfig->status = $instanceRow['A_STATUS'];
- $instanceConfig->version = $instanceRow['VERSION'];
- $instanceConfig->tableName = self::generateTableName($instanceConfig->id, $instanceConfig->source);
- return $instanceConfig;
- }
- static function generateTableName($id, $source) { // @return string | null
- switch ($source) {
- case 'table': return "CRM__#INSTANCE_TABLE__{$id}";
- case 'view': return "CRM__#INSTANCE_TABLE__{$id}_VIEW";
- default: return null;
- }
- }
- 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))
- );
- }
- }
|