PHP_Beautifier
[ class tree: PHP_Beautifier ] [ index: PHP_Beautifier ] [ all elements ]

Source for file phpBB.filter.php

Documentation is available at phpBB.filter.php

  1. <?php
  2. /**
  3.  * Filter the code to make it compatible with phpBB Coding Standards
  4.  *
  5.  * PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  * @category   PHP
  13.  * @package PHP_Beautifier
  14.  * @subpackage Filter
  15.  * @author Jim Wigginton <terrafrost@php.net>
  16.  * @copyright  2008 Jim Wigginton
  17.  * @link     http://pear.php.net/package/PHP_Beautifier
  18.  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
  19.  * @version    CVS: $Id:$
  20.  */
  21. /**
  22.  * Require PEAR_Config
  23.  */
  24. require_once ('PEAR/Config.php');
  25. /**
  26.  * Filter the code to make it compatible with phpBB Coding Standards
  27.  *
  28.  * Among other differences from the PEAR Coding Standards, the phpBB coding standards use BSD style indenting.
  29.  *
  30.  * @category   PHP
  31.  * @package PHP_Beautifier
  32.  * @subpackage Filter
  33.  * @author Jim Wigginton <terrafrost@php.net>
  34.  * @copyright  2008 Jim Wigginton
  35.  * @link     http://pear.php.net/package/PHP_Beautifier
  36.  * @license    http://www.gnu.org/licenses/lgpl.html  LGPL
  37.  * @version    Release: 0.0.1
  38.  */
  39. {
  40.     protected $sDescription = 'Filter the code to make it compatible with phpBB Coding Standards';
  41.     private $iNestedIfs = 0;
  42.     public function __construct(PHP_Beautifier $oBeaut$aSettings = array())
  43.     {
  44.         parent::__construct($oBeaut$aSettings);
  45.         $oBeaut->setIndentChar("\t");
  46.         $oBeaut->setIndentNumber(1);
  47.         $oBeaut->setNewLine(PHP_EOL);
  48.     }
  49.     function t_open_brace($sTag)
  50.     {
  51.         $this->oBeaut->addNewLineIndent();
  52.         $this->oBeaut->add($sTag);
  53.         $this->oBeaut->incIndent();
  54.         $this->oBeaut->addNewLineIndent();
  55.     }
  56.     function t_close_brace($sTag)
  57.     {
  58.         if ($this->oBeaut->getMode('string_index'or $this->oBeaut->getMode('double_quote')) {
  59.             $this->oBeaut->add($sTag);
  60.         else {
  61.             $this->oBeaut->removeWhitespace();
  62.             $this->oBeaut->decIndent();
  63.             $this->oBeaut->addNewLineIndent();
  64.             $this->oBeaut->add($sTag);
  65.             $this->oBeaut->addNewLineIndent();
  66.         }
  67.     }
  68.     function t_else($sTag)
  69.     {
  70.         $this->oBeaut->add($sTag);
  71.         if (!$this->oBeaut->isNextTokenContent('{')) {
  72.             $this->oBeaut->addNewLineIndent();
  73.             $this->oBeaut->add('{');
  74.             $this->oBeaut->incIndent();
  75.             $this->oBeaut->addNewLineIndent();
  76.             $this->iNestedIfs++;
  77.         }
  78.     }
  79.     function t_semi_colon($sTag)
  80.     {
  81.         $this->oBeaut->removeWhitespace();
  82.         $this->oBeaut->add($sTag);
  83.         if ($this->oBeaut->getControlParenthesis(!= T_FOR{
  84.             if ($this->iNestedIfs > 0{
  85.                 $this->oBeaut->decIndent();
  86.                 $this->oBeaut->addNewLineIndent();
  87.                 $this->oBeaut->add('}');
  88.                 $this->iNestedIfs--;
  89.             }
  90.             $this->oBeaut->addNewLineIndent();
  91.         }
  92.     }
  93.     function preProcess()
  94.     {
  95.         $this->iNestedIfs = 0;
  96.     }
  97. }
  98. ?>

Documentation generated on Sun, 22 Jun 2008 05:00:28 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.