Skip to content

Commit aedb817

Browse files
authored
Merge pull request #114 from lucasnetau/cache_inflector
Cache the Doctrine\Inflector instance as a static property for reuse
2 parents 92a9783 + 854264a commit aedb817

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Messages/Factory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace WyriHaximus\React\ChildProcess\Messenger\Messages;
66

7+
use Doctrine\Inflector\Inflector;
78
use Doctrine\Inflector\InflectorFactory;
89
use Exception;
910
use Throwable;
@@ -12,13 +13,16 @@
1213

1314
final class Factory
1415
{
16+
private static ?Inflector $inflector = null;
17+
1518
/**
1619
* @param array<mixed> $lineOptions
1720
*/
1821
public static function fromLine(string $line, array $lineOptions): ActionableMessageInterface
1922
{
2023
$line = json_decode($line, true);
21-
$method = InflectorFactory::create()->build()->camelize($line['type']);
24+
self::$inflector ??= InflectorFactory::create()->build();
25+
$method = self::$inflector->camelize($line['type']);
2226
if ($method === 'secure') {
2327
return static::secureFromLine($line, $lineOptions);
2428
}

0 commit comments

Comments
 (0)