Skip to content

Commit

Permalink
Added coverage of old frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Dec 22, 2020
1 parent 416b271 commit 7168fd8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"minimum-stability": "stable",
"prefer-stable": true,
"extra": {
"laravel": {
"providers": [
"Helldar\\LaravelRoutesCore\\ServiceProvider"
]
},
"thanks": [
{
"name": "andrey-helldar/support",
Expand Down
38 changes: 38 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Helldar\LaravelRoutesCore;

use Illuminate\Support\Str;

final class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->registerStrBefore();
$this->registerStrAfter();
}

protected function registerStrBefore(): void
{
if (! method_exists(Str::class, 'before')) {
Str::macro('before', static function ($subject, $search) {
if ($search === '') {
return $subject;
}

$result = strstr($subject, (string) $search, true);

return $result === false ? $subject : $result;
});
}
}

protected function registerStrAfter()
{
if (! method_exists(Str::class, 'after')) {
Str::macro('after', static function ($subject, $search) {
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
});
}
}
}

0 comments on commit 7168fd8

Please sign in to comment.