protected static _items ( ReflectionClass $class, string $method, array $options ) : object | ||
$class | ReflectionClass | A reflection class instance from which to fetch. |
$method | string | A getter method to call on the `ReflectionClass` instance, which will return an array of items, i.e. `'getProperties'` or `'getMethods'`. |
$options | array | 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. |
return | 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`. |
protected static function _items($class, $method, $options)
{
$defaults = array('names' => array(), 'self' => true, 'public' => true);
$options += $defaults;
$params = array('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'));
}