Skip to content

Commit f7eafda

Browse files
authored
Remove PHP 8+ polyfills and use native string functions (#656)
1 parent 53bce2e commit f7eafda

File tree

10 files changed

+22
-46
lines changed

10 files changed

+22
-46
lines changed

init/functions.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -563,19 +563,6 @@ function camel_case($value)
563563
}
564564
}
565565

566-
if (!function_exists('ends_with')) {
567-
/**
568-
* ends_with determines if a given string ends with a given substring
569-
* @param string $haystack
570-
* @param string|array $needles
571-
* @return bool
572-
*/
573-
function ends_with($haystack, $needles)
574-
{
575-
return Str::endsWith($haystack, $needles);
576-
}
577-
}
578-
579566
if (!function_exists('kebab_case')) {
580567
/**
581568
* kebab_case converts a string to kebab case
@@ -601,19 +588,6 @@ function snake_case($value, $delimiter = '_')
601588
}
602589
}
603590

604-
if (!function_exists('starts_with')) {
605-
/**
606-
* starts_with determines if a given string starts with a given substring
607-
* @param string $haystack
608-
* @param string|array $needles
609-
* @return bool
610-
*/
611-
function starts_with($haystack, $needles)
612-
{
613-
return Str::startsWith($haystack, $needles);
614-
}
615-
}
616-
617591
if (!function_exists('str_after')) {
618592
/**
619593
* str_after returns the remainder of a string after a given value

src/Auth/Models/Role.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function hasAccess($permissions, $all = true)
7777
// Now, let's check if the permission ends in a wildcard "*" symbol.
7878
// If it does, we'll check through all the merged permissions to see
7979
// if a permission exists which matches the wildcard.
80-
if ((strlen($permission) > 1) && ends_with($permission, '*')) {
80+
if ((strlen($permission) > 1) && str_ends_with($permission, '*')) {
8181
$matched = false;
8282

8383
foreach ($rolePermissions as $rolePermission => $value) {
@@ -88,7 +88,7 @@ public function hasAccess($permissions, $all = true)
8888
// exactly match our permission, but starts with it.
8989
if (
9090
$checkPermission !== $rolePermission &&
91-
starts_with($rolePermission, $checkPermission) &&
91+
str_starts_with($rolePermission, $checkPermission) &&
9292
(int) $value === 1
9393
) {
9494
$matched = true;
@@ -99,7 +99,7 @@ public function hasAccess($permissions, $all = true)
9999
// Now, let's check if the permission starts in a wildcard "*" symbol.
100100
// If it does, we'll check through all the merged permissions to see
101101
// if a permission exists which matches the wildcard.
102-
elseif ((strlen($permission) > 1) && starts_with($permission, '*')) {
102+
elseif ((strlen($permission) > 1) && str_starts_with($permission, '*')) {
103103
$matched = false;
104104

105105
foreach ($rolePermissions as $rolePermission => $value) {
@@ -110,7 +110,7 @@ public function hasAccess($permissions, $all = true)
110110
// exactly match our permission, but ends with it.
111111
if (
112112
$checkPermission !== $rolePermission &&
113-
ends_with($rolePermission, $checkPermission) &&
113+
str_ends_with($rolePermission, $checkPermission) &&
114114
(int) $value === 1
115115
) {
116116
$matched = true;
@@ -123,7 +123,7 @@ public function hasAccess($permissions, $all = true)
123123

124124
foreach ($rolePermissions as $rolePermission => $value) {
125125
// This time check if the rolePermission ends in wildcard "*" symbol.
126-
if ((strlen($rolePermission) > 1) && ends_with($rolePermission, '*')) {
126+
if ((strlen($rolePermission) > 1) && str_ends_with($rolePermission, '*')) {
127127
$matched = false;
128128

129129
// Strip the '*' off the end of the permission.
@@ -133,7 +133,7 @@ public function hasAccess($permissions, $all = true)
133133
// exactly match our permission, but starts with it.
134134
if (
135135
$checkGroupPermission !== $permission &&
136-
starts_with($permission, $checkGroupPermission) &&
136+
str_starts_with($permission, $checkGroupPermission) &&
137137
(int) $value === 1
138138
) {
139139
$matched = true;

src/Auth/Models/User.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ public function hasPermission($permissions, $all = true)
542542
// Now, let's check if the permission ends in a wildcard "*" symbol.
543543
// If it does, we'll check through all the merged permissions to see
544544
// if a permission exists which matches the wildcard.
545-
if ((strlen($permission) > 1) && ends_with($permission, '*')) {
545+
if ((strlen($permission) > 1) && str_ends_with($permission, '*')) {
546546
$matched = false;
547547

548548
foreach ($mergedPermissions as $mergedPermission => $value) {
@@ -553,15 +553,15 @@ public function hasPermission($permissions, $all = true)
553553
// exactly match our permission, but starts with it.
554554
if (
555555
$checkPermission !== $mergedPermission &&
556-
starts_with($mergedPermission, $checkPermission) &&
556+
str_starts_with($mergedPermission, $checkPermission) &&
557557
(int) $value === 1
558558
) {
559559
$matched = true;
560560
break;
561561
}
562562
}
563563
}
564-
elseif ((strlen($permission) > 1) && starts_with($permission, '*')) {
564+
elseif ((strlen($permission) > 1) && str_starts_with($permission, '*')) {
565565
$matched = false;
566566

567567
foreach ($mergedPermissions as $mergedPermission => $value) {
@@ -572,7 +572,7 @@ public function hasPermission($permissions, $all = true)
572572
// exactly match our permission, but ends with it.
573573
if (
574574
$checkPermission !== $mergedPermission &&
575-
ends_with($mergedPermission, $checkPermission) &&
575+
str_ends_with($mergedPermission, $checkPermission) &&
576576
(int) $value === 1
577577
) {
578578
$matched = true;
@@ -585,7 +585,7 @@ public function hasPermission($permissions, $all = true)
585585

586586
foreach ($mergedPermissions as $mergedPermission => $value) {
587587
// This time check if the mergedPermission ends in wildcard "*" symbol.
588-
if ((strlen($mergedPermission) > 1) && ends_with($mergedPermission, '*')) {
588+
if ((strlen($mergedPermission) > 1) && str_ends_with($mergedPermission, '*')) {
589589
$matched = false;
590590

591591
// Strip the '*' off the end of the permission.
@@ -595,7 +595,7 @@ public function hasPermission($permissions, $all = true)
595595
// exactly match our permission, but starts with it.
596596
if (
597597
$checkMergedPermission !== $permission &&
598-
starts_with($permission, $checkMergedPermission) &&
598+
str_starts_with($permission, $checkMergedPermission) &&
599599
(int) $value === 1
600600
) {
601601
$matched = true;

src/Database/Attach/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ public function deleteThumbs()
730730
$allFiles = $this->storageCmd('files', $directory);
731731
$collection = [];
732732
foreach ($allFiles as $file) {
733-
if (starts_with(basename($file), $pattern)) {
733+
if (str_starts_with(basename($file), $pattern)) {
734734
$collection[] = $file;
735735
}
736736
}

src/Foundation/Providers/ExecutionContextProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function determineContext($app): string
3939

4040
$backendUri = $this->normalizeUrl($app['config']->get('backend.uri', 'backend'));
4141

42-
if (starts_with($requestPath, $backendUri)) {
42+
if (str_starts_with($requestPath, $backendUri)) {
4343
return 'backend';
4444
}
4545

src/Halcyon/Traits/Validation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ protected function processValidationRules($rules)
235235
// Analyse each rule individually
236236
foreach ($ruleParts as $key => $rulePart) {
237237
// Look for required:create and required:update rules
238-
if (starts_with($rulePart, 'required:create') && $this->exists) {
238+
if (str_starts_with($rulePart, 'required:create') && $this->exists) {
239239
unset($ruleParts[$key]);
240240
}
241-
elseif (starts_with($rulePart, 'required:update') && !$this->exists) {
241+
elseif (str_starts_with($rulePart, 'required:update') && !$this->exists) {
242242
unset($ruleParts[$key]);
243243
}
244244
}

src/Html/HtmlBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace October\Rain\Html;
22

3+
use October\Rain\Support\Str;
34
use Illuminate\Routing\UrlGenerator;
45

56
/**
@@ -585,7 +586,7 @@ public static function cleanVector(string $html): string
585586
*/
586587
public function isValidColor(string $value): bool
587588
{
588-
return starts_with($value, [
589+
return Str::startsWith($value, [
589590
'#',
590591
'var(',
591592
'rgb(',

src/Parse/Syntax/SyntaxModelTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace October\Rain\Parse\Syntax;
22

3+
use October\Rain\Support\Str;
34
use Request;
45

56
/**
@@ -102,7 +103,7 @@ protected function getThumbForImage($image, $params = [])
102103
$path = $image->getPath();
103104
}
104105

105-
if (!starts_with($path, ['//', 'http://', 'https://'])) {
106+
if (!Str::startsWith($path, ['//', 'http://', 'https://'])) {
106107
$path = Request::getSchemeAndHttpHost() . $path;
107108
}
108109

src/Scaffold/Console/CreateFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateFactory extends GeneratorCommandBase
3030
*/
3131
public function handle()
3232
{
33-
if (!ends_with($this->argument('name'), 'Factory')) {
33+
if (!str_ends_with($this->argument('name'), 'Factory')) {
3434
$this->components->error('Factory classes names must end in "Factory"');
3535
return;
3636
}

src/Scaffold/Console/CreateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CreateTest extends GeneratorCommandBase
3030
*/
3131
public function handle()
3232
{
33-
if (!ends_with($this->argument('name'), 'Test')) {
33+
if (!str_ends_with($this->argument('name'), 'Test')) {
3434
$this->components->error('Test classes names must end in "Test"');
3535
return;
3636
}

0 commit comments

Comments
 (0)