Skip to content

Commit b0ed9e1

Browse files
[10.x] Adds support for parse callbacks from anonymous classes (#49432)
* Adds support for anonymous classes callbacks * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent ee059bb commit b0ed9e1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Illuminate/Support/Str.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,17 @@ public static function padRight($value, $length, $pad = ' ')
810810
*/
811811
public static function parseCallback($callback, $default = null)
812812
{
813+
if (static::contains($callback, "@anonymous\0")) {
814+
if (static::substrCount($callback, '@') > 1) {
815+
return [
816+
static::beforeLast($callback, '@'),
817+
static::afterLast($callback, '@'),
818+
];
819+
}
820+
821+
return [$callback, $default];
822+
}
823+
813824
return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default];
814825
}
815826

tests/Support/SupportStrTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,15 @@ public function testConvertCase()
328328

329329
public function testParseCallback()
330330
{
331+
$this->assertEquals(['Class', 'method'], Str::parseCallback('Class@method'));
331332
$this->assertEquals(['Class', 'method'], Str::parseCallback('Class@method', 'foo'));
332333
$this->assertEquals(['Class', 'foo'], Str::parseCallback('Class', 'foo'));
333334
$this->assertEquals(['Class', null], Str::parseCallback('Class'));
335+
336+
$this->assertEquals(["Class@anonymous\0/laravel/382.php:8$2ec", 'method'], Str::parseCallback("Class@anonymous\0/laravel/382.php:8$2ec@method"));
337+
$this->assertEquals(["Class@anonymous\0/laravel/382.php:8$2ec", 'method'], Str::parseCallback("Class@anonymous\0/laravel/382.php:8$2ec@method", 'foo'));
338+
$this->assertEquals(["Class@anonymous\0/laravel/382.php:8$2ec", 'foo'], Str::parseCallback("Class@anonymous\0/laravel/382.php:8$2ec", 'foo'));
339+
$this->assertEquals(["Class@anonymous\0/laravel/382.php:8$2ec", null], Str::parseCallback("Class@anonymous\0/laravel/382.php:8$2ec"));
334340
}
335341

336342
public function testSlug()

0 commit comments

Comments
 (0)