3 # Include PEAR::Console_Getopt
4 require_once 'Console/Getopt.php';
6 $command = new Command;
7 print_r($command->command());
10 $config->load($command->config());
20 private $short_format_config = 'hc:s:t:';
21 private $syntax_config = array('ccl', 'cql', 'pqf');
24 public function __construct() {
25 $args = Console_Getopt::readPHPArgv();
27 if ( PEAR::isError($args) ) {
28 fwrite(STDERR,$args->getMessage()."\n");
32 // Compatibility between "php script.php" and "./script.php"
33 if ( realpath($_SERVER['argv'][0]) == __FILE__ ) {
35 = Console_Getopt::getOpt($args, $this->short_format_config);
38 = Console_Getopt::getOpt2($args, $this->short_format_config);
41 // Check for invalid options
42 if ( PEAR::isError($this->options) ) {
43 fwrite(STDERR, $this->options->getMessage()."\n");
47 $this->command = array();
49 // Loop through the user provided options
50 foreach ( $this->options[0] as $option ) {
51 switch ( $option[0] ) {
56 $this->command['syntax'] = $option[1];
59 $this->command['transform'] = $option[1];
62 $this->command['config'] = $option[1];
67 // Loop through the user provided options
68 foreach ($this->options[1] as $argument ) {
69 $this->command['query'] .= ' ' . $argument;
74 public function help() {
75 fwrite(STDERR, " Usage:\n");
76 fwrite(STDERR, " ./experiment-query-config-translate.php -s syntax -t transform -c config.xml query\n");
77 fwrite(STDERR, " Experiment with general query configuration syntax and transformations.\n");
78 fwrite(STDERR, " -c config.xml XML config file\n");
79 fwrite(STDERR, " -s syntax Syntax of source query language, 'ccl', 'cql', 'pqf'\n");
80 fwrite(STDERR, " -t transform Syntax of transformed query language, 'ccl', 'cql', 'pqf'\n");
81 fwrite(STDERR, " -h Display help\n");
82 fwrite(STDERR, " query Valid query in specified syntax\n");
86 public function command() {
87 return $this->command;
90 public function syntax() {
91 return $this->command['syntax'];
94 public function transform() {
95 return $this->command['transform'];
98 public function config() {
99 return $this->command['config'];
102 public function query() {
103 return $this->commamd['query'];
111 public function load($xml_file){
112 $this->xml_conf = @simplexml_load_file($xml_file)
113 or die("Unable to load XML config file '" . $xml_file ."'\n");
114 $this->xml_conf->registerXPathNamespace('iq',
115 'http://indexdata.com/query');
118 public function parse(){
119 //foreach ($this->xml_conf->xpath('//desc') as $desc) {
122 $namespaces = $this->xml_conf->getNamespaces(true);
123 foreach ($namespaces as $ns){
124 print("namespace '" . $ns . "'\n");
128 foreach ($this->xml_conf->xpath('//iq:syntax') as $syntax){
129 print("syntax '" . $syntax['name'] . "'\n");