// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //============================================================================= /** * @copyright Francois Laupretre * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 * @category Automap * @package Automap *///========================================================================== //============================================================================= /** * This class contains the methods we include in the PHK PHP runtime, but * not in the PECL extension. * * As it is included in the PHK runtime, the code may reference PHK, but not Phool. * * API status: Public * Included in the PHK PHP runtime: Yes * Implemented in the extension: No *///========================================================================== namespace Automap\Tools { if (!class_exists('\Automap\Tools\Display',false)) { class Display // Static only { //--------- // Display the content of a map public static function show(\Automap\Map $map,$format=null ,$subfile_to_url_function=null) { if (is_null($format)||($format='auto')) { \PHK::needPhpRuntime(); $format=(\PHK\Tools\Util::envIsWeb() ? 'html' : 'text'); } switch($format) { case 'text': self::showText($map,$subfile_to_url_function); break; case 'html': self::showHtml($map,$subfile_to_url_function); break; default: throw new \Exception("Unknown display format ($format)"); } } //--------- private static function sortMethod($s1,$s2) { return strcmp($s1['symbol'],$s2['symbol']); } //--------- private static function showText(\Automap\Map $map,$subfile_to_url_function=null) { echo "\n* Global information :\n\n"; echo ' Map version : '.$map->version()."\n"; echo ' Min reader version : '.$map->minVersion()."\n"; echo ' Symbol count : '.$map->symbolCount()."\n"; echo "\n* Options :\n\n"; $opts=$map->options(); if (count($opts)) { foreach($opts as $name => $value) echo "$name: $value\n"; } else echo "\n"; echo "\n* Symbols :\n\n"; $stype_len=$symbol_len=4; $rpath_len=10; $symbols=$map->symbols(); usort($symbols,array(__CLASS__,'sortMethod')); foreach($symbols as $s) { $stype_len=max($stype_len,strlen(\Automap\Mgr::typeToString($s['stype']))+2); $symbol_len=max($symbol_len,strlen($s['symbol'])+2); $rpath_len=max($rpath_len,strlen($s['rpath'])+2); } echo str_repeat('-',$stype_len+$symbol_len+$rpath_len+8)."\n"; echo '|'.str_pad('Type',$stype_len,' ',STR_PAD_BOTH); echo '|'.str_pad('Name',$symbol_len,' ',STR_PAD_BOTH); echo '| T '; echo '|'.str_pad('Defined in',$rpath_len,' ',STR_PAD_BOTH); echo "|\n"; echo '|'.str_repeat('-',$stype_len); echo '|'.str_repeat('-',$symbol_len); echo '|---'; echo '|'.str_repeat('-',$rpath_len); echo "|\n"; foreach($symbols as $s) { echo '| '.str_pad(ucfirst(\Automap\Mgr::typeToString($s['stype'])),$stype_len-1,' ',STR_PAD_RIGHT) .'| '.str_pad($s['symbol'],$symbol_len-1,' ',STR_PAD_RIGHT) .'| '.$s['ptype'].' ' .'| '.str_pad($s['rpath'],$rpath_len-1,' ',STR_PAD_RIGHT) ."|\n"; } } //--- // The same in HTML private static function showHtml(\Automap\Map $map,$subfile_to_url_function=null) { echo "

Global information

"; echo ''; echo ''; echo ''; echo ''; echo '
Map version: ' .htmlspecialchars($map->version()).'
Min reader version: ' .htmlspecialchars($map->minVersion()).'
Symbol count: ' .$map->symbolCount().'
'; echo "

Options

"; $opts=$map->options(); if (count($opts)) { echo ''; foreach ($opts as $name => $value) { echo ''; } echo '
'.htmlspecialchars($name).': ' .htmlspecialchars($value).'
'; } else echo "\n

<None>

\n"; echo "

Symbols

"; echo '' .''; $symbols=$map->symbols(); usort($symbols,array(__CLASS__,'sortMethod')); foreach($symbols as $s) { echo ''; } echo '
TypeNameFTDefined in
'.ucfirst(\Automap\Mgr::typeToString($s['stype'])).'' .htmlspecialchars($s['symbol']) .''.$s['ptype'].''; if (!is_null($subfile_to_url_function)) echo ''; echo htmlspecialchars($s['rpath']); if (!is_null($subfile_to_url_function)) echo ''; echo '
'; } //--- } // End of class //=========================================================================== } // End of class_exists //=========================================================================== } // End of namespace //=========================================================================== ?>