Automattic\WooCommerce\Internal\DependencyManagement
AbstractServiceProvider::reflect_class_or_callable() private WC 1.0
Check if a combination of class name and concrete is valid for registration. Also return the class injection method if the concrete is either a class name or null (then use the supplied class name).
{} Это метод класса: AbstractServiceProvider{}
Хуков нет.
Возвращает
\ReflectionFunctionAbstract/null. A reflection instance for the $class_name injection method or $concrete injection method or callable; null otherwise.
Использование
// private - только в коде основоного (родительского) класса $result = $this->reflect_class_or_callable( $class_name, $concrete );
- $class_name(строка) (обязательный)
- The class name to check.
- $concrete(смешанный) (обязательный)
- The concrete to check.
Код AbstractServiceProvider::reflect_class_or_callable() AbstractServiceProvider::reflect class or callable WC 4.9.1
private function reflect_class_or_callable( string $class_name, $concrete ) {
if ( ! isset( $concrete ) || is_string( $concrete ) && class_exists( $concrete ) ) {
try {
$class = $concrete ?? $class_name;
$method = new \ReflectionMethod( $class, Definition::INJECTION_METHOD );
if ( ! isset( $method ) ) {
return null;
}
$missing_modifiers = array();
if ( ! $method->isFinal() ) {
$missing_modifiers[] = 'final';
}
if ( ! $method->isPublic() ) {
$missing_modifiers[] = 'public';
}
if ( ! empty( $missing_modifiers ) ) {
throw new ContainerException( "Method '" . Definition::INJECTION_METHOD . "' of class '$class' isn't '" . implode( ' ', $missing_modifiers ) . "', instances can't be created." );
}
return $method;
} catch ( \ReflectionException $ex ) {
return null;
}
} elseif ( is_callable( $concrete ) ) {
try {
return new \ReflectionFunction( $concrete );
} catch ( \ReflectionException $ex ) {
throw new ContainerException( "Error when reflecting callable: {$ex->getMessage()}" );
}
}
return null;
}