* @copyright 2009 Fx NION * @link http://fxnion.free.fr * @license http://www.php.net/license/3_0.txt PHP License 3.0 */ class PHP_Beautifier_Filter_phpDoc extends PHP_Beautifier_Filter { protected $aFilterTokenFunctions = array( T_CLASS => 't_class', T_FUNCTION => 't_function', T_INTERFACE => 't_interface', ); protected $sDescription = 'A simple but powerfull phpDoc filter'; protected $aSettings = array( 'license' => 'none' ); public $aAllowedLicenses = array( "php" => "php", "bsd" => "bsd", "gpl" => "gpl", "pear" => "pear", "apache" => "apache" ); public function __construct(PHP_Beautifier $oBeaut, $aSettings = array()) { parent::__construct($oBeaut, $aSettings); $this->addSettingDefinition('license', 'text', 'Top php files license'); } /** * Add a standard php 3 licence at the begining of a php script. * @param * @return */ function addPhpdoc_license_php() { $this->oBeaut->add("/**"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * PHP version 5"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * LICENSE: This source file is subject to version 3.0 of the PHP license"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * that is available through the world-wide-web at the following URI:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * http://www.php.net/license/3_0.txt. If you did not receive a copy of"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * the PHP License and are unable to obtain it through the web, please"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * send a note to license@php.net so we can mail you a copy immediately."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @category PHP"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @package"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @subpackage Filter"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @author FirstName LastName "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @copyright 2009 FirstName LastName"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @link"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @license http://www.php.net/license/3_0.txt PHP License 3.0"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @version CVS: $Id:$"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Add a standard bsd licence at the begining of a php script. * @param * @return */ function addPhpdoc_license_bsd() { $this->oBeaut->add("/** ===================================================================="); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * BSD License"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Copyright (c) , "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * All rights reserved."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Redistribution and use in source and binary forms, with or without "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * modification, are permitted provided that the following conditions are met:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * - Redistributions of source code must retain the above copyright notice, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * this list of conditions and the following disclaimer. "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * - Redistributions in binary form must reproduce the above copyright notice, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * this list of conditions and the following disclaimer in the documentation "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * and/or other materials provided with the distribution. "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * - Neither the name of the nor the names of its contributors "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * may be used to endorse or promote products derived from this software "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * without specific prior written permission. "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * $Id:$"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Add a standard gpl licence at the begining of a php script. * @param * @return */ function addPhpdoc_license_gpl() { $this->oBeaut->add("/* ===================================================================="); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * GNU Lesser General Public License"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Version 2.1, February 1999"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Copyright (C) "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * This library is free software; you can redistribute it and/or"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * modify it under the terms of the GNU Lesser General Public"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * License as published by the Free Software Foundation; either"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * version 2.1 of the License, or (at your option) any later version."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * This library is distributed in the hope that it will be useful,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * but WITHOUT ANY WARRANTY; without even the implied warranty of"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Lesser General Public License for more details."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * You should have received a copy of the GNU Lesser General Public"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * License along with this library; if not, write to the Free Software"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * $Id:$"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Add a standard pear licence at the begining of a php script. * @param * @return */ function addPhpdoc_license_pear() { $this->oBeaut->add("/**"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Short description for file"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Long description for file (if any)..."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * PHP versions 4 and 5"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * LICENSE: This source file is subject to version 3.0 of the PHP license"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * that is available through the world-wide-web at the following URI:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * http://www.php.net/license/3_0.txt. If you did not receive a copy of"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * the PHP License and are unable to obtain it through the web, please"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * send a note to license@php.net so we can mail you a copy immediately."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @category CategoryName"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @package PackageName"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @author Original Author "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @author Another Author "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @copyright 1997-2005 The PHP Group"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @license http://www.php.net/license/3_0.txt PHP License 3.0"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @version CVS: $Id:$"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @link http://pear.php.net/package/PackageName"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @see NetOther, Net_Sample::Net_Sample()"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @since File available since Release 1.2.0"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @deprecated File deprecated in Release 2.0.0"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Add a standard apache licence at the begining of a php script. * @param * @return */ function addPhpdoc_license_apache() { $this->oBeaut->add("/* ===================================================================="); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * The Apache Software License, Version 1.1"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Copyright (c) 2000-2004 The Apache Software Foundation. All rights"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * reserved."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Redistribution and use in source and binary forms, with or without"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * modification, are permitted provided that the following conditions"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * are met:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * 1. Redistributions of source code must retain the above copyright"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * notice, this list of conditions and the following disclaimer."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * 2. Redistributions in binary form must reproduce the above copyright"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * notice, this list of conditions and the following disclaimer in"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * the documentation and/or other materials provided with the"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * distribution."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * 3. The end-user documentation included with the redistribution,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * if any, must include the following acknowledgment:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * \"This product includes software developed by the"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Apache Software Foundation (http://www.apache.org/)\"."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Alternately, this acknowledgment may appear in the software itself,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * if and wherever such third-party acknowledgments normally appear."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * 4. The names \"Apache\" and \"Apache Software Foundation\" must"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * not be used to endorse or promote products derived from this"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * software without prior written permission. For written"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * permission, please contact apache@apache.org."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * 5. Products derived from this software may not be called \"Apache\","); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * nor may \"Apache\" appear in their name, without prior written"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * permission of the Apache Software Foundation."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * SUCH DAMAGE."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * ===================================================================="); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * This software consists of voluntary contributions made by many"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * individuals on behalf of the Apache Software Foundation. For more"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * information on the Apache Software Foundation, please see"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * ."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" *"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * Portions of this software are based upon public domain software"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * originally written at the National Center for Supercomputing Applications,"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * University of Illinois, Urbana-Champaign."); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * \$Id:"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Add a standard phpDoc Tag before a function declaration. * It checks the parameters of the function and wether they have * a default value. * * @param $iNext[optional] default value : 2 * @return */ function addPhpdoc_Header_function($iNext = 2) { $sName = $this->oBeaut->getNextTokenContent($iNext); $params = ""; $pt = array(); $begin = intval($iNext + 2); while ($this->oBeaut->getNextTokenContent($begin) != ')') { $params = $params . ' ' . $this->oBeaut->getNextTokenContent($begin); $begin++; } $pt = explode(",", $params); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add("/**"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @todo Description of function " . $sName); foreach($pt as $param) { $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @param " . str_replace(" = ", "[optional]\t\tdefault value : ", $param)); } $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @return "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); } /** * Add a standard phpDoc Tag before a class declaration. * @param * @return */ function addPhpdoc_Header_class() { $sName = $this->oBeaut->getNextTokenContent(1); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add("/**"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @todo Description of class " . $sName); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @author "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @version "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @package "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @subpackage "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @category "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @link "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); } /** * Add a standard phpDoc Tag before an interface declaration. * @param none * @return none */ function addPhpdoc_Header_interface() { $sName = $this->oBeaut->getGetTokenContent(1); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add("/**"); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @todo Description of interface " . $sName); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @author "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @version "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @package "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @subpackage "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @category "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" * @link "); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add(" */"); } /** * Determine if the next($iNext) token is one of the T_ACCESS family. * @param $iNext[optional] default value : 1 * @return boolean */ function isNextTokenAccess($iNext = 1) { return ($this->oBeaut->isNextTokenConstant(T_PUBLIC, $iNext) || $this->oBeaut->isNextTokenConstant(T_PRIVATE, $iNext) || $this->oBeaut->isNextTokenConstant(T_PROTECTED, $iNext) || $this->oBeaut->isNextTokenConstant(T_STATIC, $iNext) || $this->oBeaut->isNextTokenConstant(T_ABSTRACT, $iNext) || $this->oBeaut->isNextTokenConstant(T_FINAL, $iNext)); } /** * Determine if the previous($iPrev) token is one of the T_ACCESS family. * @param $iPrev[optional] default value : 1 * @return boolean */ function isPreviousTokenAccess($iPrev = 1) { return ($this->oBeaut->isPreviousTokenConstant(T_PUBLIC, $iPrev) || $this->oBeaut->isPreviousTokenConstant(T_PRIVATE, $iPrev) || $this->oBeaut->isPreviousTokenConstant(T_PROTECTED, $iPrev) || $this->oBeaut->isPreviousTokenConstant(T_STATIC, $iPrev) || $this->oBeaut->isPreviousTokenConstant(T_ABSTRACT, $iPrev) || $this->oBeaut->isPreviousTokenConstant(T_FINAL, $iPrev)); } /** * Determine if when encountering a T_OPEN_TAG token a phpDoc licence is * to be inserted before. We check wether we are at the beginning of * the file, and if true, we insert a phpDoc licence. * * @param $sTag * @return */ function t_open_tag($sTag){ $sLicense = strtolower($this->getSetting('license')); if (strtolower($sLicense) == 'none') { return PHP_Beautifier_Filter::BYPASS; } $this->oBeaut->add($sTag); if (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->oBeaut->isNextTokenConstant(T_DOC_COMMENT) && !$this->oBeaut->isNextTokenConstant(T_COMMENT) && $this->oBeaut->getPreviousTokenContent() == "" ) { if (!array_key_exists($sLicense, $this->aAllowedLicenses)) { throw (new Exception("License " . $sLicense . " doesn't exists")); } $sMethod = "addPhpdoc_license_" . $sLicense; call_user_func_array(array( $this, $sMethod ),null); } $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } /** * Determine if when encountering a T_ACCESS token a phpDoc Tag is * to be inserted before. For this, we want to be on the first T_ACCESS * without previeous phpDoc Tag before. * * @param $sTag * @return */ function t_access($sTag) { if (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->isPreviousTokenAccess() && !$this->isNextTokenAccess()) { if ($this->oBeaut->isNextTokenConstant(T_FUNCTION)) $this->addPhpdoc_Header_function(); elseif ($this->oBeaut->isNextTokenConstant(T_CLASS)) $this->addPhpdoc_Header_class(); elseif ($this->oBeaut->isNextTokenConstant(T_INTERFACE)) $this->addPhpdoc_Header_interface(); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add($sTag . ' '); } elseif (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->isPreviousTokenAccess() && $this->isNextTokenAccess()) { if ($this->oBeaut->isNextTokenConstant(T_FUNCTION, 2)) $this->addPhpdoc_Header_function(3); elseif ($this->oBeaut->isNextTokenConstant(T_CLASS, 2)) $this->addPhpdoc_Header_class(); elseif ($this->oBeaut->isNextTokenConstant(T_INTERFACE, 2)) $this->addPhpdoc_Header_interface(); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add($sTag . ' '); } else { $this->oBeaut->add($sTag . ' '); } } /** * Determine if when encountering a T_CLASS token a phpDoc Tag is * to be inserted before.For this, we ensure that a previous Token * isn't a T_ACCESS one. In this case, the phpDoc Tag should have * been already inserted by function t_access($sTag) * * @param $sTag * @return */ function t_class($sTag) { if (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->isPreviousTokenAccess()) { $this->addPhpdoc_Header_class(); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add($sTag . ' '); } else { $this->oBeaut->add($sTag . ' '); } } /** * Determine if when encountering a T_INTERFACE token a phpDoc Tag is * to be inserted before.For this, we ensure that a previous Token * isn't a T_ACCESS one. In this case, the phpDoc Tag should have * been already inserted by function t_access($sTag) * * @param $sTag * @return */ function t_interface($sTag) { if (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->isPreviousTokenAccess()) { $this->addPhpdoc_Header_interface(); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add($sTag . ' '); } else { $this->oBeaut->add($sTag . ' '); } } /** * Determine if when encountering a T_FUNCTION token a phpDoc Tag has * to be inserted before.For this, we ensure that a previous Token * isn't a T_ACCESS one. In this case, the phpDoc Tag should have * been already inserted by function t_access($sTag) * * @param $sTag * @return */ function t_function($sTag) { if (!$this->oBeaut->isPreviousTokenConstant(T_DOC_COMMENT) && !$this->isPreviousTokenAccess()) { $this->addPhpdoc_Header_function(1); $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); $this->oBeaut->add($sTag . ' '); } else { $this->oBeaut->add($sTag . ' '); } } /** * Avoid newLines in class variables declarations * * @param $sTag * @return */ function t_semi_colon($sTag) { $this->oBeaut->removeWhitespace(); $this->oBeaut->add($sTag); if ($this->oBeaut->getControlParenthesis() != T_FOR && !$this->oBeaut->isPreviousTokenConstant(T_VARIABLE) && !$this->isPreviousTokenAccess(2)) { $this->oBeaut->addNewLine(); $this->oBeaut->addIndent(); } } } ?>