lithium\analysis\Inspector::properties()

public static method

Returns various information on the properties of an object.

Parameters

  • mixed $class

    A string class name or an object instance, from which to get methods.

  • array $options

    Set of options applied directly (check _items() for more options):

    • 'properties': array of properties to gather information from.
    • 'self': If true (default), only returns properties defined in $class, excluding properties from inherited classes.

Returns

mixed

Returns an array with information about the properties from the class given in $class or null on error.

Source

	public static function properties($class, array $options = array()) {
		$defaults = array('properties' => array(), 'self' => true);
		$options += $defaults;

		if (!(is_object($class) && $class instanceof ReflectionClass)) {
			try {
				$class = new ReflectionClass($class);
			} catch (ReflectionException $e) {
				return null;
			}
		}
		$options += array('names' => $options['properties']);

		return static::_items($class, 'getProperties', $options)->map(function($item) {
			$class = __CLASS__;
			$modifiers = array_values($class::invokeMethod('_modifiers', array($item)));
			$setAccess = (
				array_intersect($modifiers, array('private', 'protected')) !== array()
			);
			if ($setAccess) {
				$item->setAccessible(true);
			}
			$result = compact('modifiers') + array(
				'docComment' => $item->getDocComment(),
				'name' => $item->getName(),
				'value' => $item->getValue($item->getDeclaringClass())
			);
			if ($setAccess) {
				$item->setAccessible(false);
			}
			return $result;
		}, array('collect' => false));
	}