[ Index ] |
PHP Cross Reference of Automap |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================================= 3 // 4 // Copyright Francois Laupretre <automap@tekwire.net> 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 // 18 //============================================================================= 19 /** 20 * @copyright Francois Laupretre <automap@tekwire.net> 21 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 22 * @category Automap 23 * @package Automap 24 *///========================================================================== 25 26 //============================================================================= 27 /** 28 * This class contains the methods we include in the PHK PHP runtime, but 29 * not in the PECL extension. 30 * 31 * As it is included in the PHK runtime, the code may reference PHK, but not Phool. 32 * 33 * API status: Public 34 * Included in the PHK PHP runtime: Yes 35 * Implemented in the extension: No 36 *///========================================================================== 37 38 namespace Automap\Tools { 39 40 if (!class_exists('\Automap\Tools\Display',false)) 41 { 42 class Display // Static only 43 { 44 //--------- 45 // Display the content of a map 46 47 public static function show(\Automap\Map $map,$format=null 48 ,$subfile_to_url_function=null) 49 { 50 if (is_null($format)||($format='auto')) 51 { 52 \PHK::needPhpRuntime(); 53 $format=(\PHK\Tools\Util::envIsWeb() ? 'html' : 'text'); 54 } 55 56 switch($format) 57 { 58 case 'text': 59 self::showText($map,$subfile_to_url_function); 60 break; 61 62 case 'html': 63 self::showHtml($map,$subfile_to_url_function); 64 break; 65 66 default: 67 throw new \Exception("Unknown display format ($format)"); 68 } 69 } 70 71 //--------- 72 73 private static function sortMethod($s1,$s2) 74 { 75 return strcmp($s1['symbol'],$s2['symbol']); 76 } 77 78 //--------- 79 80 private static function showText(\Automap\Map $map,$subfile_to_url_function=null) 81 { 82 echo "\n* Global information :\n\n"; 83 echo ' Map version : '.$map->version()."\n"; 84 echo ' Min reader version : '.$map->minVersion()."\n"; 85 echo ' Symbol count : '.$map->symbolCount()."\n"; 86 87 echo "\n* Options :\n\n"; 88 89 $opts=$map->options(); 90 if (count($opts)) 91 { 92 foreach($opts as $name => $value) 93 echo "$name: $value\n"; 94 } 95 else echo "<None>\n"; 96 97 echo "\n* Symbols :\n\n"; 98 99 $stype_len=$symbol_len=4; 100 $rpath_len=10; 101 102 $symbols=$map->symbols(); 103 usort($symbols,array(__CLASS__,'sortMethod')); 104 foreach($symbols as $s) 105 { 106 $stype_len=max($stype_len,strlen(\Automap\Mgr::typeToString($s['stype']))+2); 107 $symbol_len=max($symbol_len,strlen($s['symbol'])+2); 108 $rpath_len=max($rpath_len,strlen($s['rpath'])+2); 109 } 110 111 echo str_repeat('-',$stype_len+$symbol_len+$rpath_len+8)."\n"; 112 echo '|'.str_pad('Type',$stype_len,' ',STR_PAD_BOTH); 113 echo '|'.str_pad('Name',$symbol_len,' ',STR_PAD_BOTH); 114 echo '| T '; 115 echo '|'.str_pad('Defined in',$rpath_len,' ',STR_PAD_BOTH); 116 echo "|\n"; 117 echo '|'.str_repeat('-',$stype_len); 118 echo '|'.str_repeat('-',$symbol_len); 119 echo '|---'; 120 echo '|'.str_repeat('-',$rpath_len); 121 echo "|\n"; 122 123 foreach($symbols as $s) 124 { 125 echo '| '.str_pad(ucfirst(\Automap\Mgr::typeToString($s['stype'])),$stype_len-1,' ',STR_PAD_RIGHT) 126 .'| '.str_pad($s['symbol'],$symbol_len-1,' ',STR_PAD_RIGHT) 127 .'| '.$s['ptype'].' ' 128 .'| '.str_pad($s['rpath'],$rpath_len-1,' ',STR_PAD_RIGHT) 129 ."|\n"; 130 } 131 } 132 133 //--- 134 // The same in HTML 135 136 private static function showHtml(\Automap\Map $map,$subfile_to_url_function=null) 137 { 138 echo "<h2>Global information</h2>"; 139 140 echo '<table border=0>'; 141 echo '<tr><td>Map version: </td><td>' 142 .htmlspecialchars($map->version()).'</td></tr>'; 143 echo '<tr><td>Min reader version: </td><td>' 144 .htmlspecialchars($map->minVersion()).'</td></tr>'; 145 echo '<tr><td>Symbol count: </td><td>' 146 .$map->symbolCount().'</td></tr>'; 147 echo '</table>'; 148 149 echo "<h2>Options</h2>"; 150 151 $opts=$map->options(); 152 if (count($opts)) 153 { 154 echo '<table border=0>'; 155 foreach ($opts as $name => $value) 156 { 157 echo '<tr><td>'.htmlspecialchars($name).': </td><td>' 158 .htmlspecialchars($value).'</td></tr>'; 159 } 160 echo '</table>'; 161 } 162 else echo "\n<p><None></p>\n"; 163 164 echo "<h2>Symbols</h2>"; 165 166 echo '<table border=1 bordercolor="#BBBBBB" cellpadding=3 ' 167 .'cellspacing=0 style="border-collapse: collapse"><tr><th>Type</th>' 168 .'<th>Name</th><th>FT</th><th>Defined in</th></tr>'; 169 $symbols=$map->symbols(); 170 usort($symbols,array(__CLASS__,'sortMethod')); 171 foreach($symbols as $s) 172 { 173 echo '<tr><td>'.ucfirst(\Automap\Mgr::typeToString($s['stype'])).'</td><td>' 174 .htmlspecialchars($s['symbol']) 175 .'</td><td align=center>'.$s['ptype'].'</td><td>'; 176 if (!is_null($subfile_to_url_function)) 177 echo '<a href="'.call_user_func($subfile_to_url_function,$s['rpath']).'">'; 178 echo htmlspecialchars($s['rpath']); 179 if (!is_null($subfile_to_url_function)) echo '</a>'; 180 echo '</td></tr>'; 181 } 182 echo '</table>'; 183 } 184 185 //--- 186 } // End of class 187 //=========================================================================== 188 } // End of class_exists 189 //=========================================================================== 190 } // End of namespace 191 //=========================================================================== 192 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jun 4 18:32:29 2015 | Cross-referenced by PHPXref 0.7.1 |