From 820f2b7469b43d465683c9555447de57d3f57521 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Fri, 28 Aug 2020 16:37:25 -0500 Subject: [PATCH] fix: add new endsWith() from core. bump version. build: [skip-ci] --- composer.json | 2 +- src/Utils.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bfde626..807596e 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Utilities that make reading and writing PHP code more convenient and enjoyable", "type": "library", "license": "GPL-v2-or-later", - "version": "1.1.0", + "version": "1.1.1", "authors": [ { "name": "Elegant Themes", diff --git a/src/Utils.php b/src/Utils.php index 3947ebf..ef3e3ff 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -300,6 +300,26 @@ public function arrayUpdate( &$array, $path, $value ): void { $this->arraySet( $array, $path, array_merge( $current_value, $value ) ); } + /** + * Whether or not a string ends with a substring. + * + * @since 1.1.1 + * + * @param string $haystack The string to look in. + * @param string $needle The string to look for. + * + * @return bool + */ + public function endsWith( string $haystack, string $needle ): bool { + $length = strlen( $needle ); + + if ( 0 === $length ) { + return true; + } + + return ( substr( $haystack, -$length ) === $needle ); + } + public function ensureDirectoryExists( $path ): bool { if ( file_exists( $path ) ) { return is_dir( $path );