SchemaReader.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("!resourceType");echo'</pre>';
  63. return null;
  64. }
  65. $className = "SchemaReaderResource{$resourceType}";
  66. if (!Lib::loadClass($className)) {
  67. return null;
  68. }
  69. $resource = new $className($resourceUri);
  70. if (!$resource->parseIniConfig($configData)) {
  71. return null;
  72. }
  73. return $resource;
  74. }
  75. }