• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / AbstractServiceProvider::reflect_class_or_callable() – Check if a combination of class name and concrete is valid for registration.

You appear to be a bot. Output may be restricted

Description

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).

Usage

$\ReflectionFunctionAbstract|null = AbstractServiceProvider::reflect_class_or_callable( $class_name, $concrete );

Parameters

$class_name
( string ) required – The class name to check.
$concrete
( mixed ) required – The concrete to check.

Returns

\ReflectionFunctionAbstract|null A reflection instance for the $class_name injection method or $concrete injection method or callable; null otherwise.

Source

File name: woocommerce/src/Internal/DependencyManagement/AbstractServiceProvider.php


Lines:

1 to 35 of 35
  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;
  }
 

 View on GitHub View on Trac

Published: 10th December 2020 | Last updated: 22nd February 2021

Primary Sidebar

Information

Function name: AbstractServiceProvider::reflect_class_or_callable
Class ref: AbstractServiceProvider
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: src/Internal/DependencyManagement/AbstractServiceProvider.php
File ref: src/Internal/DependencyManagement/AbstractServiceProvider.php
Deprecated?: No
API Letters: A,C,O,R

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites