Loading Please wait...

ormMapParser Class Reference
[Parser.Database Connectivity]

This file is part of Zigmoyd PHP Framework. More...

Inheritance diagram for ormMapParser:

Inheritance graph
[legend]
Collaboration diagram for ormMapParser:

Collaboration graph
[legend]

Public Member Functions

 ormMapParser ()
 __construct ()
 parse_var_list ($str)
 explode_token ($token_str)
 parseMap ($map)
 The Raw Parser Goes through the Orm Map and Generates a Raw Array of Tokens and returns that You must supply the Full Path to Orm Map to work.
 loadMap ($map_path)
 Gets the file onced parsed by the parseMap() and Uses its returned array as the input and generates another easy to understand object and stores it into $this->__struct However you must supply the full path to orm map.

Data Fields

 $__map_file_name
 $__struct

Detailed Description

This file is part of Zigmoyd PHP Framework.

Copyright (C) 2008 Neel Basu (Sunanda Bose)

Zigmoyd PHP Framework is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Zigmoyd PHP Framework is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Zigmoyd PHP Framework. If not, see <http://www.gnu.org/licenses/>. Parses the orm Map and generates and Intermediate code on $this->__struct that the Child class(s) can access and use

Definition at line 31 of file prs_orm.php.


Constructor & Destructor Documentation

ormMapParser::__construct (  ) 

Reimplemented from zCore.

Definition at line 38 of file prs_orm.php.

Referenced by orm_CodeGen::orm_CodeGen(), and ormMapParser().

00038                         {
00039     parent::__construct();
00040     $this->__struct = new stdClass();
00041   }


Member Function Documentation

ormMapParser::ormMapParser (  ) 

Definition at line 35 of file prs_orm.php.

References __construct().

00035                          {
00036     $this->__construct();
00037   }

Here is the call graph for this function:

ormMapParser::parse_var_list ( str  ) 

Definition at line 42 of file prs_orm.php.

Referenced by parseMap().

00042                                {
00043     trim(&$str);
00044     if(strlen($str) < 3){
00045       return false;
00046     }
00047     $carry_char = '';
00048     $__list = array();
00049     for($offset = 0;$offset<strlen($str);$offset++){
00050       switch(true){
00051         case ($str[$offset] == ':'):
00052             $current_token = trim($carry_char.$str[$offset], "\r\n\t :");
00053             $carry_char = '';
00054           break;
00055         case ($str[$offset] == "\r"):
00056         case ($str[$offset] == "\n"):
00057         case ($offset == strlen($str)-1):
00058             $__list[$current_token] = trim($carry_char.$str[$offset], "\r\n\t :");
00059             $carry_char = '';
00060           break;
00061         default:
00062           $carry_char .= $str[$offset];
00063       }
00064     }
00065     return $__list;
00066   }

ormMapParser::explode_token ( token_str  ) 

Definition at line 67 of file prs_orm.php.

References perror().

Referenced by parseMap().

00067                                     {
00068     trim(&$token_str);
00069     $__token = array();
00070     $tmp = preg_split('~\s+~', $token_str);
00071     if(count($tmp) < 2){
00072       perror('EROOER PARSING ORM Map on file '.$this->__map_file_name.' near <br />'.$token_str.'<br />ELEMENT Must be in `STRING as STRING` format');
00073     }
00074     $__token['type'] = $tmp[0];
00075     switch($__token['type']){
00076       case 'connection':
00077           $__token['alias'] = $tmp[count($tmp)-1];
00078         break;
00079       case 'table':
00080           $__token['element'] = $tmp[1];
00081           $__token['alias'] = $tmp[count($tmp)-1];
00082         break;
00083       case 'readonly':
00084       case 'writable':
00085           $__token['type'] = 'attribute';
00086           $__token['permession'] = $tmp[0];
00087           $__token['element'] = $tmp[1];
00088           $__token['alias'] = $tmp[count($tmp)-1];
00089         break;
00090       default:
00091         perror('EROOER PARSING ORM Map on file '.$this->__map_file_name.' near <br />'.$token_str.'<br />Unexpected TOKEN TYPE '.$__token['type']);
00092     }
00093     return $__token;
00094   }

Here is the call graph for this function:

ormMapParser::parseMap ( map  ) 

The Raw Parser Goes through the Orm Map and Generates a Raw Array of Tokens and returns that You must supply the Full Path to Orm Map to work.

Parameters:
$map string
Returns:
array

Definition at line 103 of file prs_orm.php.

References $__struct, explode_token(), parse_var_list(), and perror().

Referenced by loadMap().

00103                          {
00104     if(!file_exists($map)){
00105       perror('ERROR While Parsing the ORM Map The File '.$map.' Doesn\'t exists');
00106       exit;
00107     }
00108     $this->__map_file_name = $map;
00109     $handle = fopen($map, "r");
00110     $buffer = '';
00111     $offset = 0;
00112     $previous_char = null;
00113     $pstk = array();//Perent Stack Array
00114     $carrier = '';
00115     $__token = array();
00116     $__tree = array();//Holds the Tree Structure of Parent Child Reletionship
00117     $p = 0;
00118     //{ Primary Tokenization Completed
00119     while(!feof($handle)){
00120       $buffer = fread($handle, 1);
00121       //{{ Handle the Current Character
00122       switch($buffer){
00123         case '{':
00124             $pstk[trim($offset-strlen($offset))] = trim($carrier);
00125             $tmp = array_keys($pstk);
00126               $__tree[$p]['self'] = $pstk[$tmp[count($tmp)-1]];
00127               if(isset($tmp[count($tmp)-2]) && isset($pstk[$tmp[count($tmp)-2]])){
00128                 $__tree[$p]['parent'] = $pstk[$tmp[count($tmp)-2]];
00129               }else{
00130                 $__tree[$p]['parent'] = false;
00131               }
00132               $p++;
00133             $carrier = '';
00134           break;
00135         case '}':
00136             $__token[trim(array_pop($pstk))] = trim($carrier);
00137             $carrier = '';
00138           break;
00139         default:
00140             $carrier .= $buffer;
00141       }
00142       //}}
00143       $offset++;
00144       $previous_char = $buffer;
00145     }
00146     //}
00147     $__struct = array();//an array that Holds the Structure
00148     $__uid = array();//an array that Stores Unique ID of each Token
00149     $__cptr = array();//array of Child Location Pointers;
00150     $p = 0;
00151     $t = 0;//Token Pointer to carry on the uniqueness of each token in token stream
00152     foreach($__tree as $lxr){
00153       $self = &$lxr['self'];
00154       $parent = &$lxr['parent'];
00155       if(!$parent){//Element Under root
00156         $__struct[$p] = array('token' => $this->explode_token($self), 'value' => $this->parse_var_list($__token[$self]), 'child' => false);
00157         $__uid[$self] = $t;
00158         $__cptr[$t] = &$__struct[$p]['child'];
00159         ++$p;
00160       }else{//Element non root
00161         $p_id = $__uid[$parent];
00162         $__cptr[$p_id][] = array('token' => $this->explode_token($self), 'value' => $this->parse_var_list($__token[$self]), 'child' => false);
00163         $__uid[$self] = $t;
00164       }
00165       $t++;
00166     }
00167     fclose($handle);
00168     return $__struct;
00169   }

Here is the call graph for this function:

ormMapParser::loadMap ( map_path  ) 

Gets the file onced parsed by the parseMap() and Uses its returned array as the input and generates another easy to understand object and stores it into $this->__struct However you must supply the full path to orm map.

Parameters:
$map_path string

Definition at line 177 of file prs_orm.php.

References parseMap(), and perror().

00177                              {
00178     $__token_table = $this->parseMap($map_path);
00179     //{ Parse the Cnnection
00180     if($__token_table[0]['token']['type'] != 'connection'){
00181       perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' Unexpected Token `'.$__token_table[0]['token']['type'].'` at the Begening');
00182     }
00183     $this->__struct->connection->alias = $__token_table[0]['token']['alias'];
00184 //    foreach($__token_table[0]['value'] as $key => $val){
00185 //      $this->__struct->connection->{$key} = $val;
00186 //    }
00187     //}
00188     //{ Parse The Tables
00189     for($i=1;$i<count($__token_table);$i++){
00190       if($__token_table[$i]['token']['type'] != 'table'){
00191         perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' Unexpected Token `'.$__token_table[$i]['token']['type'].'` at '.$i.' Parent Node <br />Expecting table');
00192         exit;
00193       }
00194       $this->__struct->tables->$__token_table[$i]['token']['element'] = new stdClass();
00195       $link = &$this->__struct->tables->$__token_table[$i]['token']['element'];
00196       $link->alias = $__token_table[$i]['token']['alias'];
00197       //{{ Parse The Fields
00198       if(!is_array($__token_table[$i]['child'])){
00199         perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' No Child Attributes Found For Table '.$__token_table[$i]['token']['element']);
00200         exit;
00201       }
00202       $link->Attributes = array();
00203       foreach($__token_table[$i]['child'] as $j => $child){
00204         if($child['token']['type'] != 'attribute'){
00205           perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' Unexpected Token '.$child['token']['type'].' Expecting attribute near '.$child['token']['permession'].' '.$child['token']['element'].' as '.$child['token']['alias']);
00206           exit;
00207         }
00208         $link->Attributes[$child['token']['element']] = new stdClass();
00209         $link->Attributes[$child['token']['element']]->alias = $child['token']['alias'];
00210         $link->Attributes[$child['token']['element']]->permission = $child['token']['permession'];
00211         //{{{ Parse The Criteria
00212         switch($child['token']['permession']){
00213           case 'readonly':
00214             if(is_array($child['value'])){
00215               perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' a Read only Field `'.$child['token']['element'].'` can not Contain Criteria cause No data is going to be written on that Field By the Layer or By you');
00216               exit;
00217             }
00218           break;
00219           case 'writable':
00220             if(is_array($child['value'])){
00221               $link->Attributes[$child['token']['element']]->criteria = array();
00222               foreach($child['value'] as $criteria => $err_msg){
00223                 if($criteria == 'required' && isset($link->Attributes[$child['token']['element']]->default)){
00224                   perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.'<br />You cannot use a default Value if you use required as a criteria Use optional criteria Instead<br />near<br />'.$criteria.': '.$err_msg.' under Attribute '.$child['token']['element']);
00225                 }
00226                 if($criteria != '__default'){
00227                   $link->Attributes[$child['token']['element']]->criteria[$criteria] = $err_msg;
00228                 }else{
00229                   $link->Attributes[$child['token']['element']]->default = $err_msg;
00230                 }
00231               }
00232             }
00233             break;
00234           default:
00235             perror('ERROR While Parsing the ORM Map on file '.$this->__map_file_name.' Unexpected Permission Type '.$child['token']['permession']);
00236             exit;
00237         }
00238         //}}}
00239       }
00240       //}}
00241     }
00242     //}
00243   }

Here is the call graph for this function:


Field Documentation

ormMapParser::$__map_file_name

Definition at line 32 of file prs_orm.php.

ormMapParser::$__struct

Definition at line 33 of file prs_orm.php.

Referenced by parseMap().


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:11 2008 for zigmoyd.kdevelop by doxygen 1.5.6