*/ class Mtd_Manager { public $dirList = []; public $lastError; public function __construct( $dirList = [] ){ $this->dirList = $dirList; } public function register_dir( $path ){ array_push( $this->dirList, $path ); } public function get_mtd( $messageType ){ $this->lastError = ''; foreach ( $this->dirList as $dir ){ $path = "{$dir}/{$messageType}.yaml"; if ( file_exists( $path ) ){ $found = $path; break; } } if ( empty( $found ) ){ return FALSE; } try { $mtd = yaml_parse( file_get_contents( $found ) ); } catch( Exception $e ) { $this->lastError = $e->getMessage(); return FALSE; } if ( ! empty( $mtd['Inherits'] ) ){ $inherited = $this->get_mtd( $mtd['Inherits'] ); if ( ! $inherited ){ return FALSE; } $mtd = array_replace_recursive( $inherited, $mtd ); unset( $mtd['Inherits'] ); } return $mtd; } public function get_mtd_list( $type = 'request' ){ $this->lastError = ''; $mtdList = []; foreach ( $this->dirList as $dir ){ if ( ! chdir( $dir ) ){ continue; } foreach ( glob('*.yaml') as $file ){ try { $mtd = yaml_parse( file_get_contents( $file ) ); if ( empty( $mtd['Name'] ) || empty( $mtd['Type'] ) || ( $type && $mtd['Type'] != $type ) ){ continue; } $mtdList[] = $mtd['Name']; } catch( Exception $e ) { continue; } } } return $mtdList; } } // end of file mtd_manager.class.php