_apiUser->isAdmin()) { throw new HttpException("Forbidden", 403); } IF(V::get('DBG','',$_GET)){echo'
request->segments (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($request->segments);echo'
';} if (empty($request->segments) || !is_array($request->segments)) return; if (count($request->segments) < 1) { throw new HttpException("Data source and table name not specified", 400); } $this->_dataSourceName = array_shift($request->segments); if ('default_db' == $this->_dataSourceName) { $db = DB::getDB(); $limit = 1000; $tbls = array(); $sql = "show full tables"; $res = $db->query($sql); while ($r = $db->fetch($res)) { if ('BASE TABLE' == $r->Table_type) { $tblName = get_object_vars($r); $tblName = array_values($tblName); $tblName = reset($tblName); if ('DEALS_TABLE_2015_03_17_zest_dla_zubryka' == $tblName) { continue;// fields name 'grup_concat(...' } if ('KSIEG_DOKUMENTY' == $tblName) { continue;// fields name '201_...' } if ('KSIEG_DOKUMENTY_HIST' == $tblName) { continue;// fields name '201_...' } if ('Rozdzielcza_rurociag_wsg84' == $tblName) { continue;// fields name with space ' ' } $ds = new Data_Source(); $ds->set_table($tblName); $ds->get_cols(); $tbls[$tblName] = $ds; if (--$limit < 0) break; } } $xml = << _dataSourceName}="http://biuro.biall-net.pl/xmlschema_procesy5/{$this->_dataSourceName}" targetNamespace="http://biuro.biall-net.pl/xmlschema_procesy5/{$this->_dataSourceName}"> XMLEOF; foreach ($tbls as $tblName => $ds) { $xmlFields = array(); $tblFields = $ds->_col_types; foreach ($tblFields as $fldName => $colType) { $minOccurs = 0; $maxOccurs = 1; $colDefault = null; $xsdType = 'string'; //$xsdType = 'token'; //$xsdType = 'integer'; //$xsdType = 'double'; $xsdRestrictions = array(); if (false !== strpos($colType, ';')) { $colType = explode(';', $colType, 2); $colDefault = array_pop($colType); $colType = array_shift($colType); } //$xsdRestrictions[] = ''; if ($this->isIntegerField($colType)) { $xsdType = 'integer'; } else if ($this->isDecimalField($colType)) { $xsdType = 'double'; } else if ($this->isStringField($colType)) { $xsdType = 'string'; $maxLength = (int)str_replace(array(' ','(',')'), '', substr($colType, strpos($colType, '(') + 1, -1)); if ($maxLength > 0) { $xsdRestrictions[] = ''; } } else if ($this->isTextField($colType)) { $xsdType = 'string'; } else if ($this->isDateField($colType)) { $xsdType = 'token'; $xsdDatePattern = '[0-9]{4}-[0-9]{2}-[0-9]{2}'; $xsdRestrictions[] = ''; } else if ($this->isDateTimeField($colType)) { $xsdType = 'token'; $xsdDatePattern = '[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}'; $xsdRestrictions[] = ''; } else if (substr($colType, 0, 4) == 'year') { $xsdType = 'token'; $xsdDatePattern = '[0-9]{4}'; $xsdRestrictions[] = ''; } else if (substr($colType, 0, 4) == 'enum') { $xsdType = 'string'; $values = explode(',', str_replace(array('(',')',"'",'"'), '', substr($colType, 5))); foreach ($values as $val) { $xsdRestrictions[] = ''; } } else if ('polygon' == $colType) { $xsdType = 'string'; }// Wielokąt else if ('multipolygon' == $colType) { $xsdType = 'string'; }// Zbiór wielokątów else if ('linestring' == $colType) { $xsdType = 'string'; }// Krzywa z interpolacji liniowej pomiędzy punktami else if ('point' == $colType) { $xsdType = 'string'; }// Punkt w przestrzeni 2-wymiarowej else if ('geometry' == $colType) { $xsdType = 'string'; }// Typy, które mogą przechowywać geometrię dowolnego typu else if ('multipoint' == $colType) { $xsdType = 'string'; }// Zbiór punktów else if ('multilinestring' == $colType) { $xsdType = 'string'; }// Zbiór krzywych z interpolacji liniowej pomiędzy punktami else if ('geometrycollection' == $colType) { $xsdType = 'string'; }// Zbiór obiektów geometrycznych dowolnego typu else if ('timestamp' == substr($colType, 0, 9)) { $xsdType = 'string'; } else if ('time' == substr($colType, 0, 4)) { $xsdType = 'token'; $xsdDatePattern = '[0-9]{2}:[0-9]{2}:[0-9]{2}'; $xsdRestrictions[] = ''; } else if ('binary' == substr($colType, 0, 6) || 'varbinary' == substr($colType, 0, 9)) { $xsdType = 'hexBinary'; } else if ('blob' == substr($colType, 0, 4) || 'longblob' == substr($colType, 0, 8) || 'mediumblob' == substr($colType, 0, 10) || 'tinyblob' == substr($colType, 0, 8)) { $xsdType = 'hexBinary'; } else if (substr($colType, 0, 3) == 'set') { $xsdType = 'string'; $values = explode(',', str_replace(array('(',')',"'",'"'), '', substr($colType, 4))); foreach ($values as $val) { $xsdRestrictions[] = ''; } } else { $xsdType = 'unknown-Type-'.$colType.''; } $xmlFld = ''; $xmlFld .= ''; $xmlFld .= "\n\t\t\t\t" . ''; if (!empty($xsdRestrictions)) { $xmlFld .= "\n\t\t\t\t\t" . ''; $xmlFld .= "\n\t\t\t\t\t\t" . implode("\n\t\t\t\t\t\t", $xsdRestrictions); $xmlFld .= "\n\t\t\t\t\t" . ''; } else { $xmlFld .= "\n\t\t\t\t\t" . ''; } $xmlFld .= "\n\t\t\t\t" . ''; $xmlFld .= "\n\t\t\t" . ''; $xmlFields[] = $xmlFld; } $xmlFields = implode("\n\t\t\t", $xmlFields); $xml .= << {$xmlFields} XMLEOF; } $xml .= << XMLEOF; header('Content-Type: text/xml; charset=utf-8'); echo $xml; exit; //echo'
';print_r($tbls);echo'
'; } // return document tree - array of arrays } // FROM TableAcl { public function isIntegerField($type) { if (substr($type, 0, 3) == 'int' || substr($type, 0, 7) == 'tinyint' || substr($type, 0, 8) == 'smallint' || substr($type, 0, 9) == 'mediumint' || substr($type, 0, 6) == 'bigint' ) { return true; } return false; } public function isDecimalField($type) { if (substr($type, 0, 7) == 'decimal' || substr($type, 0, 7) == 'numeric' || substr($type, 0, 6) == 'double' || substr($type, 0, 5) == 'float' || substr($type, 0, 4) == 'real' ) { return true; } return false; } public function isDateField($type) { if (substr($type, 0, 4) == 'date' && substr($type, 0, 8) != 'datetime') { return true; } return false; } public function isDateTimeField($type) { if (substr($type, 0, 8) == 'datetime') { return true; } return false; } public function isStringField($type) { if (substr($type, 0, 7) == 'varchar' || substr($type, 0, 4) == 'char' ) { return true; } return false; } public function isTextField($type) { if (substr($type, 0, 4) == 'text' || substr($type, 0, 8) == 'tinytext' || substr($type, 0, 10) == 'mediumtext' || substr($type, 0, 8) == 'longtext' ) { return true; } return false; } // FROM } TableAcl private function getDataSource() { if (!$this->_dataSource) { // TODO: get data source from Factory { if ('default_db' == $this->_dataSourceName) { $this->_dataSource = new ApiDataSourceTodo($this->_dataSourceName); $this->_dataSource->setTable($this->_tblName); } else if ('931' == $this->_dataSourceName) { $this->_dataSource = new ApiDataSourceTodo($this->_dataSourceName); $this->_dataSource->setTable($this->_tblName); } } } return $this->_dataSource; } }