Automattic\WooCommerce\Internal\DependencyManagement

ExtendedContainer::replace()publicWC 1.0

Replace an existing registration with a different concrete. See also 'reset_replacement' and 'reset_all_replacements'.

Метод класса: ExtendedContainer{}

Хуков нет.

Возвращает

DefinitionInterface. The modified definition.

Использование

$ExtendedContainer = new ExtendedContainer();
$ExtendedContainer->replace( $class_name, $concrete ) : DefinitionInterface;
$class_name(строка) (обязательный)
The class name whose definition will be replaced.
$concrete(разное) (обязательный)
The new concrete (same as "add").

Код ExtendedContainer::replace() WC 9.3.3

public function replace( string $class_name, $concrete ) : DefinitionInterface {
	if ( ! $this->has( $class_name ) ) {
		throw new ContainerException( "The container doesn't have '$class_name' registered, please use 'add' instead of 'replace'." );
	}

	$concrete_class = $this->get_class_from_concrete( $concrete );
	if ( isset( $concrete_class ) && ! $this->is_class_allowed( $concrete_class ) && ! $this->is_anonymous_class( $concrete_class ) ) {
		throw new ContainerException( "You cannot use concrete '$concrete_class', only classes in the {$this->woocommerce_namespace} namespace are allowed." );
	}

	if ( ! array_key_exists( $class_name, $this->original_concretes ) ) {
		// LegacyProxy is a special case: we replace it with MockableLegacyProxy at unit testing bootstrap time.
		$original_concrete                       = LegacyProxy::class === $class_name ? MockableLegacyProxy::class : $this->extend( $class_name )->getConcrete( $concrete );
		$this->original_concretes[ $class_name ] = $original_concrete;
	}

	return $this->extend( $class_name )->setConcrete( $concrete );
}