PHP 8 ์„ฑ๋Šฅ ๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿš€

3826 ๋‹จ์–ด performancephpdiscusswebdev
๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด PHP 8์—์„œ ํฐ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ๋ณด๊ณ  ์žˆ์Šต๋‹ˆ๊นŒ?

๋‚ด ์ž‘์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ๋ฆฌํ”Œ๋ ‰์…˜๊ณผ ์•ฝ๊ฐ„์˜ ์ •๊ทœ ํ‘œํ˜„์‹์„ ๋‹ค๋ฃจ๋Š” ๋ช‡ ๊ฐ€์ง€ ํ…Œ์ŠคํŠธ๊ฐ€ 30-50% ๋” ๋น ๋ฅด๊ฒŒ ์‹คํ–‰๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค ๐Ÿ’ช!
ํ›Œ๋ฅญํ•˜์ง€๋งŒ ๊ฒฉ๋ฆฌ๋œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋Š” ๊ฒฐ์ฝ” ๋Œ€ํ‘œ์ ์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๋” ๋ณต์žกํ•œ ์†”๋ฃจ์…˜์„ ์ด๋ฏธ ์„ฑ๊ณต์ ์œผ๋กœ ๋ฒค์น˜๋งˆํ‚นํ•œ ์‚ฌ๋žŒ์ด ์žˆ์Šต๋‹ˆ๊นŒ?

์ƒˆ PHP ๋ฒ„์ „์— ๋Œ€ํ•œ ํƒ€์‚ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ง€์›์ด ์ถฉ๋ถ„ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์•„์ง ๋” ๋ณต์žกํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์—†์—ˆ์Šต๋‹ˆ๋‹ค.

์ด๊ฒƒ์€ ๋ถ€์ŠคํŠธ๋ฅผ ๋ณด๊ณ  ์žˆ๋Š” ์ทจ๋ฏธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.


๋‹ค์ฟ ์ ฌ / ์™€์ด์–ด ์ง€๋‹ˆ


Autowiring ๋„๊ตฌ ๋ฐ ์ข…์†์„ฑ ์ œ๊ณต์ž.





์™€์ด์–ด ์ง€๋‹ˆ ๐Ÿงž





PSR-11 ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ์šฉ Autowiring ๋„๊ตฌ ๋ฐ ์ข…์†์„ฑ ๊ณต๊ธ‰์ž
์ง€๋‹ˆ์˜ ํž˜์œผ๋กœ ์—ฐ๊ฒฐํ•˜์„ธ์š”.

๐Ÿ’ฟ composer require dakujem/wire-genie


๋ญ?


์ดˆ๋Šฅ๋ ฅ์žcall_user_func ? ์˜ˆ! ๊ทธ๋ฆฌ๊ณ  ๋”.
Wire Genie๋Š” PSR-11 ์„œ๋น„์Šค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์ˆ˜(์ข…์†์„ฑ)๋ฅผ "๋งˆ์ˆ ์ฒ˜๋Ÿผ"์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ชจ๋“  ์ฝœ๋Ÿฌ๋ธ” ํ˜ธ์ถœ
  • ๋ชจ๋“  ๊ฐ์ฒด ๊ตฌ์„ฑ

  • ... ์ธ์ˆ˜์— ๋Œ€ํ•œ ๋†’์€ ์ˆ˜์ค€์˜ ์ œ์–ด๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ’ช

    ์šฉ๋ฒ•


    $container = new Any\Psr11\Container([
        Thing::class => new Thing()
        MyService::class => new MyService()
    ])
    $callable = function (MyService $service, Thing $thing){ ... };
    
    class Something {
        public function __construct(MyService $service, Thing $thing) { ... }
    }
    
    $g = new Dakujem\Wire\Genie($container);
    
    // Magic! The dependencies are resolved from the container.
    $value  = $g->invoke
    โ€ฆ


    View on GitHub

    ๊ทธ๋ฆฌ๊ณ  ์ด์ œ ๋ฌธ์„œ-์ฃผ์„ ์ฃผ์„ ๊ตฌ๋ฌธ ๋ถ„์„(๋Œ€๋ถ€๋ถ„์˜ ์ •๊ทœ ํ‘œํ˜„์‹ ๊ตฌ๋ฌธ ๋ถ„์„์ด ํ•„์š”ํ•จ) ๋Œ€์‹  ์†์„ฑ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ํ–ฅํ›„ ๋ฒ„์ „์€ ์„ค๊ณ„์ƒ ํ›จ์”ฌ ๋น ๋ฅผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ