Explorar o código

updated Schema class to force always create

Piotr Labudda %!s(int64=10) %!d(string=hai) anos
pai
achega
05065c672a
Modificáronse 2 ficheiros con 25 adicións e 16 borrados
  1. 8 2
      SE/se-lib/Schema/TableBase.php
  2. 17 14
      SE/se-lib/Schema/TableFactory.php

+ 8 - 2
SE/se-lib/Schema/TableBase.php

@@ -3,7 +3,12 @@
 // @docs in Schema_TableFactory
 class Schema_TableBase {
 
-	public function __construct() {
+	public $idDatabase;
+	public $tblName;
+
+	public function __construct($idDatabase, $tblName) {
+		$this->idDatabase = $idDatabase;
+		$this->tblName = strtolower($tblName);
 		$this->_types = array();
 		$this->_restrictions = array();
 		$this->initTypes();
@@ -17,7 +22,7 @@ class Schema_TableBase {
 	}
 
 	public function fixTypes($types) {
-		if (!is_array($this->_types)) return;
+		if (empty($this->_types)) return $types;
 		foreach ($types as $fldName => $type) {
 			if (array_key_exists($fldName, $this->_types)) {
 				$types[$fldName]['simpleType'] = $this->_types[$fldName];
@@ -25,6 +30,7 @@ class Schema_TableBase {
 			if (array_key_exists($fldName, $this->_restrictions)) {
 				$types[$fldName]['restrictions'] = $this->_restrictions[$fldName];
 			}
+			// TODO: add default xsdElementType('simpleType', 'complexType'), xsdType(p5Type:...), ... for every field
 		}
 		return $types;
 	}

+ 17 - 14
SE/se-lib/Schema/TableFactory.php

@@ -14,13 +14,12 @@ class Schema_TableFactory {
 
 	public static function build($tableName, $idSource = null, $hostName = '') {
 		//_schemaClass
+		$objectClassName = 'Schema_TableBase';
 		$cleanHostName = str_replace(array(".", "-"), '_', $hostName);
 		$cleanTableName = strtolower($tableName);
 		$cleanSourceName = ($idSource == DB::getPDO()->getZasobId())? 'default_db' : "p5_{$idSource}";
 
-		DBG::_('DBG_SCH', '>2', "cleanHostName", $cleanHostName, __CLASS__, __FUNCTION__, __LINE__);
-		DBG::_('DBG_SCH', '>2', "cleanTableName", $cleanTableName, __CLASS__, __FUNCTION__, __LINE__);
-		DBG::_('DBG_SCH', '>2', "cleanSourceName", $cleanSourceName, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::_('DBG_SCH', '>2', "Schema({$tableName}): cleanHostName({$cleanHostName}) cleanTableName({$cleanTableName}) cleanSourceName({$cleanSourceName})", null, __CLASS__, __FUNCTION__, __LINE__);
 		// TODO: fetch form widgets from file config
 		//       "schema/gui/core/{$cleanSourceName}.{$cleanTableName}.php";
 		//       class Schema_Core_{$cleanSourceName}_{$cleanTableName};
@@ -28,21 +27,25 @@ class Schema_TableFactory {
 		//         "schema/gui/{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}.php";
 		//         class Schema_{$cleanHostName}_{$cleanSourceName}_{$cleanTableName};
 		$pathCoreClass = APP_PATH_SCHEMA . "/gui/core/{$cleanSourceName}.{$cleanTableName}.php";
-		if (!file_exists($pathCoreClass)) throw new SchemaException("Core Class file not found '{$cleanSourceName}.{$cleanTableName}'");
-		require_once $pathCoreClass;
-		$coreClassName = "Schema__Core__{$cleanSourceName}__{$cleanTableName}";
-		if (!class_exists($coreClassName)) throw new SchemaException("Config error for schema core class {$cleanSourceName}:{$cleanTableName}");
+		//if (!file_exists($pathCoreClass)) throw new SchemaException("Core Class file not found '{$cleanSourceName}.{$cleanTableName}'");
+		if (file_exists($pathCoreClass)) {
+			require_once $pathCoreClass;
+			$coreClassName = "Schema__Core__{$cleanSourceName}__{$cleanTableName}";
+			if (!class_exists($coreClassName)) throw new SchemaException("Config error for schema core class {$cleanSourceName}:{$cleanTableName}");
 
-		if ($cleanHostName) {
 			$pathCompanyClass = APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}.php";
 			$companyClassName = "Schema__{$cleanHostName}__{$cleanSourceName}__{$cleanTableName}";
-			if (!file_exists($pathCompanyClass)) throw new SchemaException("Host Class file not found '{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}'");
-			require_once $pathCompanyClass;
-			if (!class_exists($companyClassName)) throw new SchemaException("Config error for schema company class {$cleanSourceName}:{$cleanTableName}");
-			return new $companyClassName();
-		} else {
-			return new $coreClassName();
+			//if (!file_exists($pathCompanyClass)) throw new SchemaException("Host Class file not found '{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}'");
+			if ($cleanHostName && file_exists($pathCompanyClass)) {
+				require_once $pathCompanyClass;
+				if (!class_exists($companyClassName)) throw new SchemaException("Config error for schema company class {$cleanSourceName}:{$cleanTableName}");
+				$objectClassName = $companyClassName;
+			} else {
+				$objectClassName = $coreClassName;
+			}
 		}
+		DBG::_('DBG_SCH', '>2', "Schema({$tableName}): objectClassName('{$objectClassName}')", null, __CLASS__, __FUNCTION__, __LINE__);
+		return new $objectClassName($idSource, $cleanTableName);
 	}
 
 }