Loading Please wait...

vldMapParser Class Reference
[Parser.validation.]

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

Inheritance diagram for vldMapParser:

Inheritance graph
[legend]
Collaboration diagram for vldMapParser:

Collaboration graph
[legend]

Public Member Functions

 tokenize ($map, $extFlag=false)
 Parses a validation Map if $extFlag is set to true you need to suppkly the extension else it thinks that the extension is .vld.map.php.
 deTokenize ($vldToken)

Private Member Functions

 offset_position ($map_table, $offset)
 offset_table ($map)

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/>.

Validation Map Parser

Definition at line 25 of file prs_validation.php.


Member Function Documentation

vldMapParser::offset_position ( map_table,
offset 
) [private]

For internal use only.

Definition at line 30 of file prs_validation.php.

Referenced by tokenize().

00030                                                {
00031     $i=0;
00032     $pos = 0;
00033     while($offset > $pos){
00034       $pos += $map_table[$i];
00035       $i++;
00036       if($i >= count($map_table)){
00037         break;
00038       }
00039     }
00040     $line = $i;
00041     $column = $map_table[$i] - ($pos-$offset);
00042     return array('line' => $line, 'col' => $column);
00043   }

vldMapParser::offset_table ( map  )  [private]

For internal use only.

Definition at line 48 of file prs_validation.php.

Referenced by tokenize().

00048                              {
00049     $map_contents = str_replace("\r\n", "\n", file_get_contents($map));
00050     $map_contents = preg_replace("~\#.+[\r\n]~", "\n", $map_contents);//Remove the Comments(#)
00051     $table = array();
00052     for($i=0;$i<strlen($map_contents);$i++){
00053       if($i==strlen($map_contents)-1 || $map_contents[$i] == "\n"){
00054           $table[] = @strlen($line_str)+1;
00055           $line_str = '';
00056       }else{
00057         if(!isset($line_str)){$line_str = '';}
00058         $line_str .= $map_contents[$i];
00059       }
00060     }
00061     return $table;
00062   }

vldMapParser::tokenize ( map,
extFlag = false 
)

Parses a validation Map if $extFlag is set to true you need to suppkly the extension else it thinks that the extension is .vld.map.php.

Parameters:
$map string
$extFlag boolean
Returns:
array

Logic ----- $map must be projectName.mapName the /projects/prjDir/etc/conf.d/mapName.vld.map.php file will be parsed

Definition at line 71 of file prs_validation.php.

References $val, offset_position(), offset_table(), and perror().

Referenced by validationCore::parseCriteria().

00071                                          {
00078     if(!preg_match('~(\w+)\.(.+)~', $map, $mapPath)){
00079       $mapPath = array(Z_PROJECT_NAME.".$map", Z_PROJECT_NAME, $map);
00080     }
00081     //$mapPath[1] = Projectname;$mapPath[2] = MapName;
00082     $map = (!$extFlag) ? ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.Z_DIR_ETC_CONF.DRS.$mapPath[2].'.vld.map.php' : ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.Z_DIR_ETC_CONF.DRS.$mapPath[2];
00083     if(!file_exists($map)){
00084       perror('<code>zigmoyd.validation.parser</code><br />The File '.$map.' could not be parsed as a Validation Map as The file doesn\'t exists');
00085       return false;
00086     }
00087     if(!is_readable($map)){
00088       perror('<code>zigmoyd.validation.parser</code><br />The File '.$map.' could not be parsed as a Validation Map as The file couldn\'t be read Check the file permission');
00089       return false;
00090     }
00091     //$map = '/media/sda5/zigmoyd/etc/conf.d/map.ini.php';
00092     $contents = str_replace("\r\n", "\n", file_get_contents($map));
00093     $contents = $contents."\n[]\n\tdummy: null";
00094     $contents = preg_replace("~\#.+[\r\n]~", "\n", $contents);//Remove the Comments(#)
00095     $map_str_len = strlen($contents);
00096     $token = array();
00097     $field_fetched = false;
00098     for($i=0;$i<$map_str_len;$i++){
00099       if($contents[$i] == '[' || $i == $map_str_len-1){//Check wheather its a normal [ or a [ for field Name
00100         //If its a [ for Field Name either its the first element or it would be Preceded by a \r or \n Character
00101         if(!isset($contents[$i-1])  ||  //Its the First character
00102             $contents[$i-1] == "\r" ||  //\r Character
00103             $contents[$i-1] == "\n"){
00104           $start_offset = $i;
00105           $field_name = '';//Initiate the Temporary variable that will hold the Field Name
00106           //The string is going to be a field name
00107           while($contents[$i] != ']'){//ending ] not yet fetched
00108             if($i == $map_str_len){
00109               if(!isset($map_table)){$map_table = $this->offset_table($map);}
00110               list($line, $col) = $this->offset_position($map_table, $start_offset);
00111               perror('<code>zigmoyd.validation.parser</code><br />ERROR while Parsing the Validation Map on File $file_name as <br /><span style=\'color: green;font-size: 15px;font-weight: normal\'>The Ending "]" not found for the Starting "[" at offset '.$start_offset." near Line $line Character $col\n<span>");
00112               break;
00113               return false;
00114             }else{
00115               if($contents[$i] == "\r" || $contents[$i] == "\n"){
00116                 if(!isset($map_table)){$map_table = $this->offset_table($map);}
00117                 $err_pos = $this->offset_position($map_table, $start_offset);
00118                 perror('<code>zigmoyd.validation.parser</code><br />ERROR While Parsing the Validation Map on File $file_name<br />'."\n".'Field name can not contain new line character<br />'."\n".'<span style=\'color: green;font-size: 15px;font-weight: normal\'>Unexpected Newline or return Character Exexpected "]" after "[" on Line '.($err_pos['line']+1).' near Character : '.($err_pos['col']-1)."\n</span>");
00119                 break;
00120                 return false;
00121               }else{
00122                 $field_name .= $contents[$i];
00123               }
00124             }
00125             $i++;
00126           }
00127           $field_fetched = true;
00128           //{ Put the Pre made Criteria string into the array
00129           if(isset($criteria) && isset($token)){
00130             $tmp_key = array_keys($token);
00131             $tmp_key = $tmp_key[max(array_keys($tmp_key))];
00132             //{{ Parse the Critaria
00133             $criteria_res = array();
00134             $criteria_str = trim(str_replace("\r\n", "\n", $criteria));
00135             $j=0;
00136             $token_str = '';
00137             for($cr=0;$cr<strlen($criteria_str);$cr++){
00138               if(($criteria_str[$cr] == "\n" || $cr == strlen($criteria_str)-1) && strlen(trim($token_str)) > 0){
00139                 $criteria_res[$j][0] = $token_str;//Put the Line in Index 0
00140                 //{ Parse the Token String into an array[criteria] = Error Message
00141                 $token_criteria = '';//initilize the Criteria Token
00142                 $token_errmsg = '';//Initialize the Error Message Token
00143                 $token_criteria_fetched_sep = false;//Initilize the Separator Flag to false
00144                 $token_str .= $criteria_str[$cr];
00145                 for($k=0;$k<strlen($token_str);$k++){
00146                   if($token_str[$k] == ':' || $k == strlen($token_str)-1){
00147                     if($k == strlen($token_str)-1 && !$token_criteria_fetched_sep){
00148                       perror('<code>zigmoyd.validation.parser</code><br />ERROR While Parsing Validation map of file $file_name <br />'."\nError Message Can not be Blank Use CRITERIA: '__NULL__' To set a Blank Error Message<br /><span style='color: green;font-size: 15px;font-weight: normal'>Unexpected End of the Line Expecting ': ERROR MESSAGE' near `$token_str`</span>");
00149                     }
00150                     if(!$token_criteria_fetched_sep){
00151                       $criteria_res[$j][1] = trim($token_criteria);
00152                       $token_criteria_fetched_sep = true;
00153                     }else{
00154                       $token_errmsg .= $token_str[$k];
00155                       $token_errmsg = trim($token_errmsg);
00156                       if($token_errmsg == "__NULL__"){
00157                         $criteria_res[$j][2] = null;
00158                       }else{
00159                         $criteria_res[$j][2] = $token_errmsg;
00160                       }
00161                       $token_criteria_fetched_sep = false;
00162                     }
00163                   }else{
00164                     if(!$token_criteria_fetched_sep){
00165                       $token_criteria .= $token_str[$k];
00166                     }else{
00167                       $token_errmsg .= $token_str[$k];
00168                     }
00169                   }
00170                 }
00171                 //}
00172                 $token_str = '';//Initilize the String Token
00173                 $j++;
00174               }else{//Normal Line (\n not fetched) Grab The Total line
00175                 $token_str .= $criteria_str[$cr];
00176               }
00177             }
00178             //}}
00179             $criteria = array();
00180             foreach($criteria_res as $key => $val){
00181               if(isset($criteria_res[$key][1])){
00182                 $criteria[trim($criteria_res[$key][1])] = @trim($val[2]);
00183               }
00184             }
00185             $token[$tmp_key] = $criteria;
00186           }
00187           //}
00188 
00189           $token[ltrim($field_name, '[')] = array();
00190           $criteria = '';//Initialize the Criteria string
00191         }else{
00192           //Normal Criteria String that contain a [ symbol
00193           if($field_fetched){//Some field is already fetched (Do not fetch Critery If no Field is fetched so far)
00194             $criteria .= $contents[$i];
00195           }
00196         }
00197       }else{
00198         //Normal Criteria String
00199         if($field_fetched){//Some field is already fetched (Do not fetch Critery If no Field is fetched so far)
00200           $criteria .= $contents[$i];
00201         }
00202       }
00203     }
00204     array_pop($token);
00205     return $token;
00206   }

Here is the call graph for this function:

vldMapParser::deTokenize ( vldToken  ) 

Definition at line 207 of file prs_validation.php.

00207                                 {
00208     $outStr = '';
00209     foreach($vldToken as $key => $elemObj){
00210       $outStr .= "[$key]".endl;
00211       foreach($elemObj as $criteria => $errMsg){
00212         is_null($errMsg) ? $errMsg = '__NULL__' : false;
00213         $outStr .= "\t$criteria: $errMsg\n";
00214       }
00215     }
00216     return $outStr;
00217   }


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

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