lithium\analysis\Inspector::_items()

protected static method

Helper method to get an array of ReflectionMethod or ReflectionProperty objects, wrapped in a Collection object, and filtered based on a set of options.

Parameters

  • ReflectionClass $class

    A reflection class instance from which to fetch.

  • string $method

    A getter method to call on the ReflectionClass instance, which will return an array of items, i.e. 'getProperties' or 'getMethods'.

  • array $options

    The options used to filter the resulting method list.

    • 'names': array of properties for filtering the result.
    • 'self': If true (default), only returns properties defined in $class, excluding properties from inherited classes.
    • 'public': If true (default) forces the property to be recognized as public.

Returns

object

Returns a Collection object instance containing the results of the items returned from the call to the method specified in $method, after being passed through the filters specified in $options.

Source

	protected static function _items($class, $method, $options) {
		$defaults = ['names' => [], 'self' => true, 'public' => true];
		$options += $defaults;

		$params = [
			'getProperties' => ReflectionProperty::IS_PUBLIC | (
				$options['public'] ? 0 : ReflectionProperty::IS_PROTECTED
			)
		];
		$data = isset($params[$method]) ? $class->{$method}($params[$method]) : $class->{$method}();

		if (!empty($options['names'])) {
			$data = array_filter($data, function($item) use ($options) {
				return in_array($item->getName(), (array) $options['names']);
			});
		}

		if ($options['self']) {
			$data = array_filter($data, function($item) use ($class) {
				return ($item->getDeclaringClass()->getName() === $class->getName());
			});
		}

		if ($options['public']) {
			$data = array_filter($data, function($item) { return $item->isPublic(); });
		}
		return static::_instance('collection', compact('data'));
	}