<?php
/**
 * PHP 7.4 compatibility polyfills.
 *
 * Provides str_contains(), str_starts_with(), and str_ends_with() for
 * environments running PHP < 8.0. Loaded unconditionally from the main
 * plugin file before any other code executes.
 */

// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
	 exit;
}

if ( ! function_exists( 'str_contains' ) ) {
	function str_contains( string $haystack, string $needle ): bool {
		return $needle === '' || strpos( $haystack, $needle ) !== false;
	}
}

if ( ! function_exists( 'str_starts_with' ) ) {
	function str_starts_with( string $haystack, string $needle ): bool {
		return $needle === '' || strncmp( $haystack, $needle, strlen( $needle ) ) === 0;
	}
}

if ( ! function_exists( 'str_ends_with' ) ) {
	function str_ends_with( string $haystack, string $needle ): bool {
		return $needle === '' || substr( $haystack, -strlen( $needle ) ) === $needle;
	}
}
