Automattic\WooCommerce\Internal\Admin\Settings\PaymentsProviders
PaymentGateway::get_class_filename
Get the filename of the payment gateway class.
Method of the class: PaymentGateway{}
No Hooks.
Returns
String|null. The filename of the payment gateway class or null if it cannot be determined.
Usage
// private - for code of main (parent) class only $result = $this->get_class_filename( $payment_gateway ): ?string;
- $payment_gateway(WC_Payment_Gateway) (required)
- The payment gateway object.
PaymentGateway::get_class_filename() PaymentGateway::get class filename code WC 10.8.1
private function get_class_filename( WC_Payment_Gateway $payment_gateway ): ?string {
// If the payment gateway object has a `class_filename` property, use it.
// It is only used in development environments (including when running tests).
if ( isset( $payment_gateway->class_filename ) && in_array( wp_get_environment_type(), array( 'local', 'development' ), true ) ) {
$class_filename = $payment_gateway->class_filename;
} else {
try {
$reflector = new \ReflectionClass( get_class( $payment_gateway ) );
$class_filename = $reflector->getFileName();
} catch ( Throwable $e ) {
// Bail but log so we can investigate.
SafeGlobalFunctionProxy::wc_get_logger()->debug(
'Failed to get gateway class filename: ' . $e->getMessage(),
array(
'gateway' => $payment_gateway->id,
'source' => 'settings-payments',
'exception' => $e,
)
);
return null;
}
}
// Bail if we couldn't get the gateway class filename.
if ( ! is_string( $class_filename ) ) {
return null;
}
return $class_filename;
}