SchemaFactory.php 1.3 KB

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