Pelzini

This is the code documentation for the Pelzini project

source of /viewer/php_code_renderer.php

Does code rendering for PHP
  1. <?php
  2. /*
  3. Copyright 2008 Josh Heidenreich
  4.  
  5. This file is part of Pelzini.
  6.  
  7. Pelzini is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. Pelzini is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. /**
  22.  * Does code rendering for PHP
  23.  *
  24.  * @package Viewer
  25.  * @author Josh Heidenreich
  26.  * @since 0.3
  27.  * @tag i18n-done
  28.  **/
  29.  
  30. /**
  31.  * Does code rendering for PHP
  32.  **/
  33. class PHPCodeRenderer
  34. {
  35.  
  36. /**
  37.   * Returns PHP code which can be used for extending the specified class
  38.   **/
  39. public function drawClassExtends($class_id)
  40. {
  41. $q = "SELECT name FROM classes WHERE id = {$class_id}";
  42. $res = db_query ($q);
  43. if (! $res) return;
  44. $class = db_fetch_assoc ($res);
  45.  
  46. $date = date('Y-m-d');
  47.  
  48. $out = '';
  49.  
  50. $out .= "<?php\n";
  51. $out .= "/**\n";
  52. $out .= "* " . str(STR_RENDER_NEW_CLASS_DESC) . "\n";
  53. $out .= "* \n";
  54. $out .= "* @author " . str(STR_RENDER_YOUR_NAME) . ", {$date}\n";
  55. $out .= "**/\n";
  56. $out .= "class " . str(STR_RENDER_NEW_CLASS_NAME) . " extends {$class['name']} {\n";
  57. $out .= " \n";
  58.  
  59. $q = "SELECT name, arguments, visibility, description
  60. FROM functions
  61. WHERE classid = {$class_id}
  62. AND final = 0";
  63. $res = db_query ($q);
  64. while ($row = db_fetch_assoc ($res)) {
  65. if ($row['description']) {
  66. $row['description'] = strip_tags($row['description']);
  67. $row['description'] = trim($row['description']);
  68. $row['description'] = str_replace("\n", "\n * ", $row['description']);
  69.  
  70. $out .= " /**\n";
  71. $out .= " * {$row['description']}\n";
  72. $out .= " **/\n";
  73. }
  74.  
  75. $out .= " {$row['visibility']} function {$row['name']} ({$row['arguments']}) {\n";
  76. $out .= " // " . str(STR_RENDER_METHOD_COMMENT) . "\n";
  77. $out .= " }\n";
  78. $out .= " \n";
  79. }
  80.  
  81. $out .= "}\n";
  82. $out .= "?>\n";
  83.  
  84. return $out;
  85. }
  86.  
  87.  
  88. }
  89.