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

Source for file ClassList.php

Documentation is available at ClassList.php

  1. <?php
  2.  
  3. /**
  4. * Class and method list for a given package directory.
  5. *
  6. * Don't list:
  7. * - doc|docs directory
  8. * - examples
  9. * - test|tests
  10. *
  11. @category QA
  12. @package  QA_Peardoc_Coverage
  13. @author   Christian Weiske <cweiske@php.net>
  14. @license  http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
  15. @version  CVS: $Id: ClassList.php,v 1.3 2007/07/18 18:52:44 cweiske Exp $
  16. @link     http://pear.php.net/package/QA_Peardoc_Coverage
  17. */
  18. {
  19.     protected static $arBadFiles = array(
  20.         '/tests/',
  21.         '/test/',
  22.         '/test.php',
  23.         '/test_.+.php',
  24.         '/data/',
  25.         '/cases/',
  26.         '/demo/',
  27.         '/doc/',
  28.         '/docs/',
  29.         '/example/',
  30.         '/examples/',
  31.         '/Examples/',
  32.         '/example.php',
  33.         '/.+_example.php',
  34.         '/.+Example.php',
  35.         '/scripts/',
  36.  
  37.         '/buildPackage.php',
  38.         '/compileAll.php',
  39.         '/createPackageXml.php',
  40.         '/generate_package_xml.php',
  41.         '/generate_package2_xml.php',
  42.         '/generatePackage.xml.php',
  43.         'constants.php',
  44.         '/makepackage.php',
  45.         '/package.php',
  46.         '/package_.+.php',
  47.         '/test.+.php',
  48.         '/updatePear.php',
  49.         /*
  50.         '/DBA_Relational/Toolbox.php',
  51.         '/DB_DOM/DB_DOM.php',
  52.         '/fix.+Files.php',
  53.         '/Gtk_Styled/Buttons.php',
  54.         '/HTTP_WebDAV_Client/Client.php',
  55.         '/HTTP_WebDAV_Server/file.php',
  56.         '/MDB_Frontend/Common.php',
  57.         '/MDB_Frontend/Dump.php',
  58.         '/MDB_Frontend/Frontend.php',
  59.         '/MDB_Frontend/Login.tpl.php',
  60.         '/MDB_Frontend/Update.php',
  61.         '/PDBPLUS/pdbplus.php',
  62.         '/PDBPLUS/readline.php',
  63.         '/PEAR/PEAR.php',
  64.         '/PEAR_Frontend_Web/WebInstaller.php',
  65.         '/PHPDoc/front-end.php',
  66.         '/PHPDoc/index.php',
  67.         '/PHPDoc/prepend.php',
  68.         '/PHP_Parser/skeleton.php',
  69.         '/PHP_ParserGenerator/Lemon.php',
  70.         '/PHP_ParserGenerator/parsephp.php',
  71.         '/PhpDocumentor/phpdoc.php',
  72.         '/SOAP_Interop/',
  73.         '/SQL_Parser/Dialect_.+.php',
  74.         '/SQL_Parser/ctype.php',
  75.         '/Science_Chemistry/Chemistry.php',
  76.         '/Services_Weather/buildMetarDB.php',
  77.         '/Translation/translation.str_mgmt.php',
  78.         '/XML_HTMLSax/XML_HTMLSax.php',
  79.         '/Auth/Auth/Auth.php',
  80.         '/DBA/DBA/Compatibility.php',
  81.         '/DB_DataObject/DataObject/createTables.php',
  82.         '/Forum/',
  83.         '/HTML_AJAX/js/build.php',
  84.         '/HTML_Page/Page/Doctypes.php',
  85.         '/HTML_Page/Page/Namespaces.php',
  86.         '/HTML_Page2/Page2/Doctypes.php',
  87.         '/HTML_Page2/Page2/Namespaces.php',
  88.         '/HTTP_SessionServer/SessionServer/SaveHandler.php',
  89.         '/I18N/Messages/determineLanguage.inc.php',
  90.         '/I18Nv2/.+/.+.php',
  91.         '/Image_Graph/Graph/Config.php',
  92.         '/Image_Graph/Graph/Constants.php',
  93.         '/Image_Transform/Driver/.+.php',
  94.         '/Image_Transform/imgtests/.+.php',
  95.         '/MDB/MDB/reverse_engineer_xml_schema.php',
  96.         '/Math_Fibonacci/Fibonacci/_fibonacciTable.php',
  97.         '/Message/misc/.+.php',
  98.         '/Net_GameServerQuery/GameServerQuery/Games.php',
  99.         '/Net_SmartIRC/SmartIRC/defines.php',
  100.         '/PEAR_Frontend_Gtk2/Gtk2/Checks.php',
  101.         '/PHP_Compat/Compat/',
  102.         '/PHP_CompatInfo/CompatInfo/',
  103.         */
  104.     );
  105.  
  106.     /**
  107.     * Returns a list of .php files in the given
  108.     * directory and its subdirectories.
  109.     * The files do not match self::$arBadFiles.
  110.     *
  111.     * @param string  $strPackageDir Directory to scan
  112.     * @param boolean $bAbsolute     Return absolute file paths
  113.     *                                 (or relative to package dir)
  114.     *
  115.     * @return array Array with absolute file paths
  116.     */
  117.     public static function getFileList($strPackageDir$bAbsolute = true)
  118.     {
  119.         if (!file_exists($strPackageDir|| !is_dir($strPackageDir)) {
  120.             throw new Exception(
  121.                 "Package directory does not exist: " $strPackageDir
  122.             );
  123.         }
  124.  
  125.         if (substr($strPackageDir-1!= '/'{
  126.             $strPackageDir .= '/';
  127.         }
  128.         $strPath getcwd();
  129.         chdir($strPackageDir);
  130.  
  131.         $arFiles preg_grep(
  132.             '!(' implode(self::$arBadFiles'|'')!',
  133.             glob('./' '{*,*/*,*/*/*,*/*/*/*}.php'GLOB_BRACE),
  134.             PREG_GREP_INVERT
  135.         );
  136.  
  137.         foreach ($arFiles as $id => $strFile{
  138.             if ($bAbsolute{
  139.                 $arFiles[$id$strPackageDir substr($strFile2);
  140.             else {
  141.                 $arFiles[$idsubstr($strFile2);
  142.             }
  143.         }
  144.  
  145.         chdir($strPath);
  146.  
  147.         return $arFiles;
  148.     }//public static function getFileList($strPackageDir, $bAbsolute = true)
  149.  
  150.  
  151.  
  152.     /**
  153.     * Tries to find classnames in a given file
  154.     *
  155.     * @param string $strClassFile .php filename
  156.     *
  157.     * @return array Array of classnames defined in the file
  158.     */
  159.     public static function getClassnamesFromFilename($strClassFile)
  160.     {
  161.         //simple: open file and search for "class classname"
  162.         $strContent file_get_contents($strClassFile);
  163.  
  164.         if (preg_match_all(
  165.                 '/' "(?:\r|\n)"
  166.                 . '\\s*(?:abstract\\s+)?(?:final\\s+)?'
  167.                 . '(?:[Cc]lass|interface)\\s+([A-Za-z0-9_]+)/',
  168.             $strContent,
  169.             $arMatches)
  170.         {
  171.             return $arMatches[1];
  172.         else {
  173.             return array();
  174.         }
  175.     }//public static function getClassnamesFromFilename($strClassFile)
  176.  
  177. }//class QA_Peardoc_Coverage_Classlist
  178. ?>

Documentation generated on Mon, 11 Mar 2019 15:10:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.