5 * Copyright (c) 2009-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
37 * @package PHP_TokenStream
38 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
39 * @copyright 2009-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
41 * @since File available since Release 1.0.0
44 require_once 'PHP/Token/Stream.php';
45 require_once 'ezc/Base/base.php';
47 function __autoload($className)
49 ezcBase::autoload($className);
53 * TextUI frontend for PHP_TokenStream.
55 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
56 * @copyright 2009-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
57 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
58 * @version Release: 1.0.1
59 * @link http://github.com/sebastianbergmann/php-token-stream/tree
60 * @since Class available since Release 1.0.0
62 class PHP_Token_Stream_TextUI_Command
67 public static function main()
69 $input = new ezcConsoleInput;
71 $input->registerOption(
75 ezcConsoleInput::TYPE_NONE,
88 $input->registerOption(
92 ezcConsoleInput::TYPE_NONE,
109 catch (ezcConsoleOptionException $e) {
110 print $e->getMessage() . "\n";
114 if ($input->getOption('help')->value) {
119 else if ($input->getOption('version')->value) {
120 self::printVersionString();
124 $arguments = $input->getArguments();
126 if (empty($arguments)) {
131 self::printVersionString();
133 print "Line Token Text\n" .
134 str_repeat('-', 79) . "\n";
136 foreach (new PHP_Token_Stream($arguments[0]) as $token) {
137 if ($token instanceof PHP_Token_WHITESPACE) {
140 $text = str_replace(array("\r", "\n"), '', (string)$token);
142 if (strlen($text) > 40) {
143 $text = explode("\n", wordwrap($text, 40));
151 str_replace('PHP_Token_', '', get_class($token)),
160 protected static function showHelp()
162 self::printVersionString();
165 Usage: phptok [switches] <file>
167 --help Prints this usage information.
168 --version Prints the version and exits.
174 * Prints the version string.
176 protected static function printVersionString()
178 print "phptok 1.0.1 by Sebastian Bergmann.\n\n";