Automattic\WooCommerce\Internal\BatchProcessing

BatchProcessingController::get_processor_instance()privateWC 1.0

Get an instance of a processor given its class name.

Method of the class: BatchProcessingController{}

Hooks from the method

Return

BatchProcessorInterface. Instance of batch processor for the given class.

Usage

// private - for code of main (parent) class only
$result = $this->get_processor_instance( $processor_class_name ): BatchProcessorInterface;
$processor_class_name(string) (required)
Full class name of the batch processor.

BatchProcessingController::get_processor_instance() code WC 9.3.3

private function get_processor_instance( string $processor_class_name ): BatchProcessorInterface {

	$container = wc_get_container();
	$processor = $container->has( $processor_class_name ) ? $container->get( $processor_class_name ) : null;

	/**
	 * Filters the instance of a processor for a given class name.
	 *
	 * @param object|null $processor The processor instance given by the dependency injection container, or null if none was obtained.
	 * @param string $processor_class_name The full class name of the processor.
	 * @return BatchProcessorInterface|null The actual processor instance to use, or null if none could be retrieved.
	 *
	 * @since 6.8.0.
	 */
	$processor = apply_filters( 'woocommerce_get_batch_processor', $processor, $processor_class_name );
	if ( ! isset( $processor ) && class_exists( $processor_class_name ) ) {
		// This is a fallback for when the batch processor is not registered in the container.
		$processor = new $processor_class_name();
	}
	if ( ! is_a( $processor, BatchProcessorInterface::class ) ) {
		throw new \Exception( "Unable to initialize batch processor instance for $processor_class_name" );
	}
	return $processor;
}