meta2xsd.php

Go to the documentation of this file.
00001 #!/usr/bin/php
00002 <?php
00003     /* $Id: meta2xsd.php 4687 2007-12-09 18:57:18Z voxus $ */
00004     
00005     function help()
00006     {
00007 ?>
00008 Usage: meta2xsd.php [options] [project-configuration-file.inc.php] [metaconfiguration.xml]
00009 
00010 Possible options:
00011 
00012     --without-soap:
00013         generate schema without soap ns, types, etc
00014 
00015 <?php
00016         exit(1);
00017     }
00018     
00019     function init()
00020     {
00021         define('ONPHP_META_BUILDERS', ONPHP_META_PATH.'builders'.DIRECTORY_SEPARATOR);
00022         define('ONPHP_META_PATTERNS', ONPHP_META_PATH.'patterns'.DIRECTORY_SEPARATOR);
00023         define('ONPHP_META_TYPES', ONPHP_META_PATH.'types'.DIRECTORY_SEPARATOR);
00024         
00025         set_include_path(
00026             get_include_path().PATH_SEPARATOR
00027             .ONPHP_META_BUILDERS.PATH_SEPARATOR
00028             .ONPHP_META_PATTERNS.PATH_SEPARATOR
00029             .ONPHP_META_TYPES.PATH_SEPARATOR
00030         );
00031     }
00032     
00033     // paths
00034     $pathConfig = $pathMeta = null;
00035     
00036     // switches
00037     $withoutSoap = false;
00038     
00039     $args = $_SERVER['argv'];
00040     array_shift($args);
00041     
00042     if ($args) {
00043         foreach ($args as $arg) {
00044             if ($arg[0] == '-') {
00045                 switch ($arg) {
00046                     case '--without-soap':
00047                         $withoutSoap = true;
00048                         break;
00049                     
00050                     default:
00051                         stop('Unknown switch: '.$arg);
00052                 }
00053             } else {
00054                 if (file_exists($arg)) {
00055                     $extension = pathinfo($arg, PATHINFO_EXTENSION);
00056                     
00057                     // respecting paths order described in help()
00058                     if (!$pathConfig) {
00059                         $pathConfig = $arg;
00060                     } elseif (!$pathMeta) {
00061                         $pathMeta = $arg;
00062                     } else {
00063                         stop('Unknown path: '.$arg);
00064                     }
00065                 } else {
00066                     stop('Unknown option: '.$arg);
00067                 }
00068             }
00069         }
00070     }
00071     
00072     // manual includes due to unincluded yet project's config
00073     $metaRoot =
00074         dirname(dirname($_SERVER['argv'][0]))
00075         .DIRECTORY_SEPARATOR
00076         .'classes'
00077         .DIRECTORY_SEPARATOR;
00078     
00079     require $metaRoot.'ConsoleMode.class.php';
00080     require $metaRoot.'MetaOutput.class.php';
00081     require $metaRoot.'TextOutput.class.php';
00082     require $metaRoot.'ColoredTextOutput.class.php';
00083     
00084     if (
00085         isset($_SERVER['TERM'])
00086         && (
00087             $_SERVER['TERM'] == 'xterm'
00088             || $_SERVER['TERM'] == 'linux'
00089         )
00090     ) {
00091         $out = new ColoredTextOutput();
00092     } else {
00093         $out = new TextOutput();
00094     }
00095     
00096     $out = new MetaOutput($out);
00097     
00098     if (!$pathConfig) {
00099         $out->warning('Trying to guess path to project\'s configuration file: ');
00100         
00101         foreach (
00102             array(
00103                 'config.inc.php',
00104                 'src/config.inc.php'
00105             )
00106             as $path
00107         ) {
00108             if (file_exists($path)) {
00109                 $pathConfig = $path;
00110                 
00111                 $out->remark($path)->logLine('.');
00112                 
00113                 break;
00114             }
00115         }
00116         
00117         if (!$pathConfig) {
00118             $out->errorLine('failed.');
00119         }
00120     }
00121     
00122     if (!$pathMeta) {
00123         $out->warning('Trying to guess path to MetaConfiguration file: ');
00124         
00125         foreach (
00126             array(
00127                 'config.xml',
00128                 'meta/config.xml'
00129             )
00130             as $path
00131         ) {
00132             if (file_exists($path)) {
00133                 $pathMeta = $path;
00134                 
00135                 $out->remark($path)->logLine('.');
00136                 
00137                 break;
00138             }
00139         }
00140         
00141         if (!$pathMeta) {
00142             $out->errorLine('failed.');
00143         }
00144     }
00145     
00146     if ($pathMeta && $pathConfig) {
00147         require $pathConfig;
00148         
00149         init();
00150         
00151         try {
00152             $meta =
00153                 MetaConfiguration::me()->
00154                 setOutput($out)->
00155                 setDryRun(false)->
00156                 load($pathMeta)->
00157                 setForcedGeneration(false)->
00158                 toXsd($withoutSoap);
00159 
00160         } catch (BaseException $e) {
00161             $out->
00162                 newLine()->
00163                 errorLine($e->getMessage(), true)->
00164                 newLine()->
00165                 logLine(
00166                     $e->getTraceAsString()
00167                 );
00168         }
00169     } else {
00170         $out->getOutput()->resetAll()->newLine();
00171         
00172         stop('Can not continue.');
00173     }
00174     
00175     $out->getOutput()->resetAll();
00176 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4