Gets an array of classes and their corresponding definition files, or examines a file and
returns the classes it defines.
public static classes ( array $options = [] ) : array | ||
$options | array | Option consists of: - `'group'`: Can be `classes` for grouping by class name or `files` for grouping by filename. - `'file': Valid file path for inspecting the containing classes. |
Résultat | array | Associative of classes and their corresponding definition files |
/** * Helper method for caching closure function references to help the process of building the * stack trace. * * @param array $frame Backtrace information. * @param callable|string $function The method related to $frame information. * @return string Returns either the cached or the fetched closure function reference while * writing its reference to the cache array `$_closureCache`. */ protected static function _closureDef($frame, $function) { $reference = '::'; $frame += array('file' => '??', 'line' => '??'); $cacheKey = "{$frame['file']}@{$frame['line']}"; if (isset(static::$_closureCache[$cacheKey])) { return static::$_closureCache[$cacheKey]; } if ($class = Inspector::classes(array('file' => $frame['file']))) { foreach (Inspector::methods(key($class), 'extents') as $method => $extents) { $line = $frame['line']; if (!($extents[0] <= $line && $line <= $extents[1])) { continue; } $class = key($class); $reference = "{$class}::{$method}"; $function = "{$reference}()::{closure}"; break; } } else { $reference = $frame['file']; $function = "{$reference}::{closure}"; } $line = static::_definition($reference, $frame['line']) ?: '?'; $function .= " @ {$line}"; return static::$_closureCache[$cacheKey] = $function; }
public function testClassFileIntrospection() { $result = Inspector::classes(array('file' => __FILE__)); $this->assertEqual(array(__CLASS__ => __FILE__), $result); $result = Inspector::classes(array('file' => __FILE__, 'group' => 'files')); $this->assertCount(1, $result); $this->assertEqual(__FILE__, key($result)); $result = Inspector::classes(array('file' => __FILE__, 'group' => 'foo')); $this->assertEqual(array(), $result); }