lithium\analysis\Inspector::dependencies()

public static method

Gets the static and dynamic dependencies for a class or group of classes.

Parameters

  • mixed $classes

    Either a string specifying a class, or a numerically indexed array of classes

  • array $options

    Option consists of:

    • 'type': The type of dependency to check: static for static dependencies, dynamicfor dynamic dependencies or null for both merged in the same array. Defaults to null.

Returns

array

An array of the static and dynamic class dependencies or each if type is defined in $options.

Source

	public static function dependencies($classes, array $options = []) {
		$defaults = ['type' => null];
		$options += $defaults;
		$static = $dynamic = [];
		$trim = function($c) { return trim(trim($c, '\\')); };
		$join = function($i) { return join('', $i); };

		foreach ((array) $classes as $class) {
			$data = explode("\n", file_get_contents(Libraries::path($class)));
			$data = "<?php \n" . join("\n", preg_grep('/^\s*use /', $data)) . "\n ?>";

			$classes = array_map($join, Parser::find($data, 'use *;', [
				'return'      => 'content',
				'lineBreaks'  => true,
				'startOfLine' => true,
				'capture'     => ['T_STRING', 'T_NAME_QUALIFIED', 'T_NAME_FULLY_QUALIFIED']
			]));

			if ($classes) {
				$static = array_unique(array_merge($static, array_map($trim, $classes)));
			}
			$classes = static::info($class . '::$_classes', ['value']);

			if (isset($classes['value'])) {
				$dynamic = array_merge($dynamic, array_map($trim, array_values($classes['value'])));
			}
		}

		if (empty($options['type'])) {
			return array_unique(array_merge($static, $dynamic));
		}
		$type = $options['type'];
		return isset(${$type}) ? ${$type} : null;
	}