SchemaFactory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. class SchemaFactory {
  3. public static function loadDefaultObject($name) {
  4. static $_cache = [];
  5. if (array_key_exists($name, $_cache)) return $_cache[$name];
  6. $objClassName = "Schema_{$name}StorageAcl";
  7. if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented - storage object not found '{$name}'", 501);
  8. $_cache[$name] = new $objClassName();
  9. return $_cache[$name];
  10. }
  11. public static function loadTableObject($tableName, $name) {
  12. $className = "Schema_DefaultDb_{$tableName}_{$name}StorageAcl";// TODO: load by Factory class which build from schema file
  13. // list($nsUri, $prefix, $name) = Api_WfsNs::parseObjectNsUri('default_objects/AccessOwner');
  14. $path = implode('/', [
  15. APP_PATH_LIB,
  16. 'Schema',
  17. 'DefaultDb',
  18. strtolower($tableName),
  19. implode('/', explode('_', $name)).'StorageAcl.php',
  20. ]);
  21. if (file_exists($path)) {
  22. require_once $path;
  23. } else {
  24. $path = implode('/', [
  25. APP_PATH_LIB,
  26. 'Schema',
  27. 'DefaultDb',
  28. strtolower($tableName),
  29. $name.'StorageAcl.php',
  30. ]);
  31. if (file_exists($path)) {
  32. require_once $path;
  33. }
  34. }
  35. if (!class_exists($className)) {
  36. throw new HttpException("Not implemented - default db storage object not found 'default_db/{$tableName}/{$name}'", 501);
  37. }
  38. return new $className;
  39. }
  40. }