lithium\console\command\Help::_methods()

protected method

Get the methods for the class.

Parameters

  • string $class
  • array $options

Returns

array

Source

	protected function _methods($class, $options = []) {
		$defaults = ['name' => null];
		$options += $defaults;

		$map = function($item) {
			if ($item->name[0] === '_') {
				return;
			}
			if ($setAccess = !$item->isPublic()) {
				$item->setAccessible(true);
			}
			$args = [];

			foreach ($item->getParameters() as $arg) {
				$args[] = [
					'name' => $arg->getName(),
					'optional' => $arg->isOptional(),
					'description' => null
				];
			}
			$result = compact('args') + [
				'docComment' => $item->getDocComment(),
				'name' => $item->getName()
			];
			if ($setAccess) {
				$item->setAccessible(false);
			}
			return $result;
		};

		$methods = Inspector::methods($class)->map($map, ['collect' => false]);
		$results = [];

		foreach (array_filter($methods) as $method) {
			$comment = Docblock::comment($method['docComment']);

			$name = $method['name'];
			$description = trim($comment['description'] . PHP_EOL . $comment['text']);
			$args = $method['args'];
			$return = null;

			foreach ($args as &$arg) {
				if (isset($comment['tags']['params']['$' . $arg['name']])) {
					$arg['description'] = $comment['tags']['params']['$' . $arg['name']]['text'];
				}
				$arg['usage'] = $arg['optional'] ? "[<{$arg['name']}>]" : "<{$arg['name']}>";
			}
			if (isset($comment['tags']['return'])) {
				$return = trim(strtok($comment['tags']['return'], ' '));
			}
			$results[$name] = compact('name', 'description', 'return', 'args');

			if ($name && $name == $options['name']) {
				return [$name => $results[$name]];
			}
		}
		return $results;
	}