Posted over 4 years ago. Visible to the public.

Get Methods of Class

Yes, very dirty, but it works a treat! Save this file in your Magento root directory, then fire up a command line and run whatever.php Mage_Core_Model_App (or some other class) and you should see the output.

Output looks like below:

Copy
$ ./classmethods.php Varien_Db_Adapter_Pdo_Mysql __construct Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 __destruct Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 __sleep Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 __wakeup Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 _beginTransaction Zend_Db_Adapter_Pdo_Abstract lib/Zend/Db/Adapter/Pdo/Abstract.php:45 _checkDdlTransaction Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _checkRequiredOptions Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 _commit Zend_Db_Adapter_Pdo_Abstract lib/Zend/Db/Adapter/Pdo/Abstract.php:45 _connect Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _convertMixedBind Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _debugException Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _debugStat Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _debugTimer Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _debugWriteToFile Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _dsn Zend_Db_Adapter_Pdo_Mysql lib/Zend/Db/Adapter/Pdo/Mysql.php:39 _getCacheId Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getColumnDefinition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getColumnTypeByDdl Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getColumnsDefinition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getDdlAction Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getDdlType Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getForeignKeyName Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getForeignKeysDefinition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getIndexesDefinition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getInsertSqlQuery Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getIntervalUnitSql Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getOptionsDefinition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _getTableName Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _minusSuperfluous Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _parseTextSize Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _prepareInsertData Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _prepareQuery Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _prepareQuotedSqlCondition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _prepareSqlDateCondition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _quote Zend_Db_Adapter_Pdo_Abstract lib/Zend/Db/Adapter/Pdo/Abstract.php:45 _quoteIdentifier Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 _quoteIdentifierAs Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 _removeDuplicateEntry Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _rollBack Zend_Db_Adapter_Pdo_Abstract lib/Zend/Db/Adapter/Pdo/Abstract.php:45 _splitMultiQuery Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _transformStringSqlCondition Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _unQuote Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 _whereExpr Zend_Db_Adapter_Abstract lib/Zend/Db/Adapter/Abstract.php:43 addColumn Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 addConstraint Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 addForeignKey Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 addIndex Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 addKey Varien_Db_Adapter_Pdo_Mysql lib/Varien/Db/Adapter/Pdo/Mysql.php:30 ...

Here is the script:

Copy
#!/usr/bin/env php <?php /** * Quick and dirty script to enumerate the methods of a class, giving you the * declaring class and path with line number for each */ if ($_SERVER['argc'] != 2) { die('Usage: ' . __FILE__ . " class_name\n"); } $class = $_SERVER['argv'][1]; // bootstrap magento, get base dir length require 'app/Mage.php'; Mage::app(); $baseDirLength = strlen(Mage::getBaseDir()) +1; // get methods try { $reflectionClass = new ReflectionClass($class); } catch (ReflectionException $e) { die("Could not load class $class\n"); } $methods = array(); foreach ($reflectionClass->getMethods() as $method) { $methods[] = array( 'name' => $method->getName(), 'class' => $method->getDeclaringClass()->getName(), 'file' => substr($method->getDeclaringClass()->getFileName(), $baseDirLength), 'line' => $method->getDeclaringClass()->getStartLine(), ); } // find longest method name for printf output $longestMethodName = 0; foreach ($methods as $method) { $methodNameLength = strlen($method['name']); $longestMethodName = ($methodNameLength > $longestMethodName) ? $methodNameLength : $longestMethodName; } $longestMethodName += 1; // find longest class name for printf output $longestClassName = 0; foreach ($methods as $method) { $classNameLength = strlen($method['class']); $longestClassName = ($classNameLength > $longestClassName) ? $classNameLength : $longestClassName; } $longestClassName += 1; // order alphabetically usort($methods, function($l, $r) { return strcmp($l['name'], $r['name']); }); // output foreach ($methods as $method) { printf("%-${longestMethodName}s %-${longestClassName}s %s:%s\n", $method['name'], $method['class'], $method['file'], $method['line']); }

Owner of this card:

Avatar
Mike Whitby
Last edit:
over 4 years ago
by Mike Whitby
Posted by Mike Whitby to Magento
This website uses cookies to improve usability and analyze traffic.
Accept or learn more