SchemaReader.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. Lib::loadClass('Core_Config_INI');
  3. Lib::loadClass('SchemaReaderProcess');
  4. class SchemaReader {
  5. private $_schemaPathProcess;
  6. private $_configIniSuffix;
  7. private $_configs = null;
  8. public function __construct() {
  9. $this->_schemaPathProcess = APP_PATH_SCHEMA . DS . 'process';
  10. $this->_configIniSuffix = '.ini.php';
  11. }
  12. public function getAll() {
  13. if (!is_array($this->_configs)) {
  14. $this->_configs = array();
  15. $fileGlob = "{$this->_schemaPathProcess}/*{$this->_configIniSuffix}";
  16. $files = glob($fileGlob);
  17. foreach ($files as $file) {
  18. $this->_parseIniFile($file);
  19. }
  20. }
  21. }
  22. private function _parseIniFile($file) {
  23. $fileName = basename($file, $this->_configIniSuffix);
  24. $config = new Core_Config_INI($file);
  25. $configData = $config->getData();
  26. $type = $config->get('type', 'CONFIG');
  27. if (!$type) {
  28. return;
  29. }
  30. $className = "SchemaReader" . ucfirst(strtolower($type));
  31. if (!class_exists($className)) {
  32. return;
  33. }
  34. $reader = new $className();
  35. if (!$reader->parseIniConfig($config)) {
  36. return;
  37. }
  38. $this->_configs[$fileName] = $reader;
  39. }
  40. public function hasProcessConfigs() {
  41. return !empty($this->_configs);
  42. }
  43. public function getProcessConfigs() {
  44. return $this->_configs;
  45. }
  46. public function findTblInfoByUri($uri) {
  47. }
  48. public static function buildProcessStepFromIni($stepNr, $configData) {
  49. $className = "SchemaReaderProcessStep";
  50. if (!Lib::loadClass($className)) {
  51. return null;
  52. }
  53. $step = new $className($stepNr);
  54. if (!$step->parseIniConfig($configData)) {
  55. return null;
  56. }
  57. return $step;
  58. }
  59. public static function buildFromIni($resourceUri, $configData) {
  60. $resourceType = V::get('type', '', $configData);
  61. if (!$resourceType) {
  62. throw new Exception("Wrong resource type - cannot build from ini file");
  63. }
  64. $className = "SchemaReaderResource{$resourceType}";
  65. if (!Lib::loadClass($className)) {
  66. return null;
  67. }
  68. $resource = new $className($resourceUri);
  69. if (!$resource->parseIniConfig($configData)) {
  70. return null;
  71. }
  72. return $resource;
  73. }
  74. }