mirror of
https://github.com/php/php-src.git
synced 2026-03-25 08:42:29 +01:00
This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
114 lines
2.4 KiB
PHP
Executable File
114 lines
2.4 KiB
PHP
Executable File
<?php
|
|
|
|
/** @file class_tree.php
|
|
* @brief Class Tree example
|
|
* @ingroup Examples
|
|
* @author Marcus Boerger
|
|
* @date 2003 - 2008
|
|
* @version 1.1
|
|
*
|
|
* Usage: php class_tree.php \<class\>
|
|
*
|
|
* Simply specify the root class or interface to tree with parameter \<class\>.
|
|
*/
|
|
|
|
if ($argc < 2) {
|
|
echo <<<EOF
|
|
Usage: php ${_SERVER['PHP_SELF']} <class>
|
|
|
|
Displays a graphical tree for the given <class>.
|
|
|
|
<class> The class or interface for which to generate the tree graph.
|
|
|
|
|
|
EOF;
|
|
exit(1);
|
|
}
|
|
|
|
if (!class_exists("RecursiveTreeIterator", false)) require_once("recursivetreeiterator.inc");
|
|
|
|
/** \brief Collects sub classes for given class or interface
|
|
*/
|
|
class SubClasses extends RecursiveArrayIterator
|
|
{
|
|
/** @param base base class to collect sub classes for
|
|
* @param check_interfaces whether we deal with interfaces
|
|
*/
|
|
function __construct($base, $check_interfaces = false)
|
|
{
|
|
foreach(get_declared_classes() as $cname)
|
|
{
|
|
$parent = get_parent_class($cname);
|
|
if (strcasecmp($parent, $base) == 0)
|
|
{
|
|
$this->offsetSet($cname, new SubClasses($cname));
|
|
}
|
|
if ($check_interfaces)
|
|
{
|
|
if ($parent)
|
|
{
|
|
$parent_imp = class_implements($parent);
|
|
}
|
|
foreach(class_implements($cname) as $iname)
|
|
{
|
|
if (strcasecmp($iname, $base) == 0)
|
|
{
|
|
if (!$parent || !in_array($iname, $parent_imp))
|
|
{
|
|
$this->offsetSet($cname, new SubClasses($cname));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($check_interfaces)
|
|
{
|
|
foreach(get_declared_interfaces() as $cname)
|
|
{
|
|
foreach(class_implements($cname) as $iname)
|
|
{
|
|
if (strcasecmp($iname, $base) == 0)
|
|
{
|
|
$this->offsetSet($cname, new SubClasses($cname, true));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$this->uksort('strnatcasecmp');
|
|
}
|
|
|
|
/** @return key() since that is the name we need
|
|
*/
|
|
function current()
|
|
{
|
|
$result = parent::key();
|
|
$parent = get_parent_class($result);
|
|
if ($parent)
|
|
{
|
|
$interfaces = array_diff(class_implements($result), class_implements($parent));
|
|
if ($interfaces)
|
|
{
|
|
$implements = array();
|
|
foreach($interfaces as $interface)
|
|
{
|
|
$implements = array_merge($implements, class_implements($interface));
|
|
}
|
|
$interfaces = array_diff($interfaces, $implements);
|
|
natcasesort($interfaces);
|
|
$result .= ' (' . join(', ', $interfaces) . ')';
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
$it = new RecursiveTreeIterator(new SubClasses($argv[1], true));
|
|
|
|
echo $argv[1]."\n";
|
|
foreach($it as $c=>$v)
|
|
{
|
|
echo "$v\n";
|
|
}
|
|
|
|
?>
|