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());
12 $config->cql_check_boolean("and");
13 $config->cql_check_boolean("notexist");
14 $config->cql_check_apt("cql", "all", "=");
15 $config->cql_check_apt("cql", "all", "notexist");
16 $config->cql_check_apt("cql", "notexist", "=");
17 $config->cql_check_apt("notexist", "all", "<>");
27 private $short_format_config = 'hc:s:t:';
28 private $syntax_config = array('ccl', 'cql', 'pqf');
31 public function __construct() {
32 $args = Console_Getopt::readPHPArgv();
34 if ( PEAR::isError($args) ) {
35 fwrite(STDERR,$args->getMessage()."\n");
39 // Compatibility between "php script.php" and "./script.php"
40 if ( realpath($_SERVER['argv'][0]) == __FILE__ ) {
42 = Console_Getopt::getOpt($args, $this->short_format_config);
45 = Console_Getopt::getOpt2($args, $this->short_format_config);
48 // Check for invalid options
49 if ( PEAR::isError($this->options) ) {
50 fwrite(STDERR, $this->options->getMessage()."\n");
54 $this->command = array();
56 // Loop through the user provided options
57 foreach ( $this->options[0] as $option ) {
58 switch ( $option[0] ) {
63 $this->command['syntax'] = $option[1];
66 $this->command['transform'] = $option[1];
69 $this->command['config'] = $option[1];
74 // Loop through the user provided options
75 foreach ($this->options[1] as $argument ) {
76 $this->command['query'] .= ' ' . $argument;
81 public function help() {
82 fwrite(STDERR, " Usage:\n");
83 fwrite(STDERR, " ./experiment-query-config-translate.php -s syntax -t transform -c config.xml query\n");
84 fwrite(STDERR, " Experiment with general query configuration syntax and transformations.\n");
85 fwrite(STDERR, " -c config.xml XML config file\n");
86 fwrite(STDERR, " -s syntax Syntax of source query language, 'ccl', 'cql', 'pqf'\n");
87 fwrite(STDERR, " -t transform Syntax of transformed query language, 'ccl', 'cql', 'pqf'\n");
88 fwrite(STDERR, " -h Display help\n");
89 fwrite(STDERR, " query Valid query in specified syntax\n");
93 public function command() {
94 return $this->command;
97 public function syntax() {
98 return $this->command['syntax'];
101 public function transform() {
102 return $this->command['transform'];
105 public function config() {
106 return $this->command['config'];
109 public function query() {
110 return $this->commamd['query'];
118 public function load($xml_file){
119 $this->xml_conf = @simplexml_load_file($xml_file)
120 or die("Unable to load XML config file '" . $xml_file ."'\n");
121 $this->xml_conf->registerXPathNamespace('iq',
122 'http://indexdata.com/query');
125 public function parse(){
126 //foreach ($this->xml_conf->xpath('//desc') as $desc) {
129 $namespaces = $this->xml_conf->getNamespaces(true);
130 foreach ($namespaces as $ns){
131 print("namespace '" . $ns . "'\n");
134 foreach ($this->xml_conf->xpath('//iq:syntax') as $syntax){
135 print("syntax '" . $syntax['name'] . "'\n");
140 public function cql_check_boolean($boolean){
141 foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:boolean")
143 if ($b['name'] == $boolean ){
144 print("CQL boolean '" . $boolean . "' exists\n");
148 print("CQL boolean '" . $boolean . "' error\n");
151 public function cql_check_apt($set, $index, $relation){
152 print("CQL APT set'" . $set . "' index '" . $index
153 . "' relation '" . $relation . "' check\n");
155 foreach ($this->xml_conf->xpath("//iq:syntax[@name='cql']//iq:set")
157 if ($s['name'] == $set ){
158 print("CQL APT set'" . $set . "' OK\n");
159 foreach ($set->xpath("//iq:index") as $i){
161 print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n");
165 print("CQL APT set'" . $set . "' OK index '" . $index . "' ERROR\n");
169 print("CQL APT set'" . $set . "' ERROR\n");