Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
5.5リリース直前 Laravel Container 使い方振り返り
Search
yuuki takezawa
July 31, 2017
Technology
1
460
5.5リリース直前 Laravel Container 使い方振り返り
yuuki takezawa
July 31, 2017
Tweet
Share
More Decks by yuuki takezawa
See All by yuuki takezawa
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
110
PHPでアクターモデルを理解・体験しよう / Understand and experience the actor model in PHP
ytake
2
250
再考 アクターモデル/ reconsider actor model
ytake
0
1k
GoとアクターモデルでES+CQRSを実践! / proto_actor_es_cqrs
ytake
1
420
Phluxorでアクターモデルを 理解・体験しよう / toolkit-for-flexible-actor-models-in-php-phluxor
ytake
1
260
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
2
1.1k
DRE/SREのプラクティス融合によるクラウドネイティブなデータ基盤作り / dre_sre
ytake
0
770
技術的負債と向き合う取り組みでよかったもの / positive_efforts_to_tackle_technical_debt
ytake
10
3.8k
アプリケーションエンジニアから強いデータエンジニアへの歩き方 / How to transition and become a Data Engineer from an Application Engineer
ytake
1
550
Other Decks in Technology
See All in Technology
Two Blades, One Journey: Engineering While Managing
ohbarye
4
1.9k
AIエージェント元年
shukob
0
160
遷移の高速化 ヤフートップの試行錯誤
narirou
6
1.1k
AWSアカウントのセキュリティ自動化、どこまで進める? 最適な設計と実践ポイント
yuobayashi
7
580
あなたが人生で成功するための5つの普遍的法則 #jawsug #jawsdays2025 / 20250301 HEROZ
yoshidashingo
2
290
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
Share my, our lessons from the road to re:Invent
naospon
0
140
AIエージェント入門
minorun365
PRO
31
17k
【詳説】コンテンツ配信 システムの複数機能 基盤への拡張
hatena
0
230
手を動かしてレベルアップしよう!
maruto
0
210
php-conference-nagoya-2025
fuwasegu
0
150
EDRの検知の仕組みと検知回避について
chayakonanaika
11
4.8k
Featured
See All Featured
Faster Mobile Websites
deanohume
306
31k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
10
1.3k
Embracing the Ebb and Flow
colly
84
4.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
Statistics for Hackers
jakevdp
797
220k
Raft: Consensus for Rubyists
vanstee
137
6.8k
A better future with KSS
kneath
238
17k
Six Lessons from altMBA
skipperchong
27
3.6k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Unsuck your backbone
ammeep
669
57k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
10
510
Transcript
5.5લʂ Container ৼΓฦΓ yuuki takezawa / ytake
Author • https://github.com/ytake/Laravel-Couchbase • https://github.com/ytake/Laravel-Aspect • https://github.com/ytake/Laravel.Smarty
Container!
class HogeFugaPiyo { public function nanika() { \App::make(‘aaa’); app(‘bbb’); }
}
݁߹ߴ͠ μϝઈର
class HogeFugaPiyo { public function __construct(Application $app) { $this->app =
$app; } }
Application ຊମඞཁͳ͍Ͱ͢ΑͶ
class Hoge { public $int = 1; }
class HogeFugaPiyo { public function __construct(Hoge $hoge) { $this->hoge =
$hoge; } }
Πϯελϯεͷੜํ๏Λࢦఆ
// Hogeͱॻ͍ͯ͋ͬͨΒHogeΛ͍ͩ͘͞ $this->app->bind(Hoge::class, function () { return new Hoge; });
$this->app->bind(Hoge::class); // singletonͰ͍ͩ͘͞ $this->app->singleton(Hoge::class);
Πϯελϯεͷੜํ๏Λࢦఆ Ҿ͕ඞཁͳ߹
class Fuga { private $arg; public function __construct($arg) { $this->arg
= $arg; } }
$this->app->bind(Fuga::class, function () { return new Fuga(1); });
Πϯελϯεͷੜํ๏Λࢦఆ ࠞ߹
class Piyo { private $hoge; private $fuga; public function __construct(Hoge
$hoge, Fuga $fuga) { $this->hoge = $hoge; $this->fuga = $fuga; } }
$this->app->bind(Hoge::class, function () { return new Hoge; }); $this->app->bind(Fuga::class, function
() { return new Fuga(1); });
// ߹ʹΑͬͯ͜Μͳͷ $this->app->bind( Fuga::class, function (Application $app) { return new
Fuga($app->make(‘nanika’)); });
Πϯελϯεੜ࣌ʹ ಛఆͷԿ͔Λ͍ͨ͠
class HogeFugaPiyo { private $name = ‘’; public function __construct(Hoge
$hoge) { $this->hoge = $hoge; } public function setName(string $name) { $this->name = $name; } }
$this->app->extend( HogeFugaPiyo::class, function (HogeFugaPiyo $hoge) { $hoge->setName(“hoge”); return $hoge; });
* ଞʹ͋Γ·͢
ಛఆͷΫϥεΛܧঝͨ͠Ϋϥεͷ Πϯελϯε͕ੜ͞Εͨ࣌ʹ ͳʹ͔͍ͨ͠
abstract class AbstractHoge { private $name = ‘abstract’; public function
setName(string $name) { $this->name = $name; } }
class Hoge extends AbstractHoge { }
$this->app->resolving( AbstractHoge::class, function (AbstractHoge $abstractHoge) { $abstractHoge->setName(‘aaaaa’); return $abstractHoge; });
ૄ݁߹ʹ͍ͨ͠
// constructorʹinterfaceΛॻ͖·͠ΐ͏ $this->app->bind(HogeInterface::class, Hoge::class);
Կ͔ͷ݅Ͱฦ٫͞ΕΔ ΠϯελϯεΛมߋ͍ͨ͠
use Illuminate\Support\Manager; class StringManager extends Manager { protected $driver =
‘hoge’; public function getDefaultDriver() { return $this->driver; } protected function createHogeDriver() { return ‘hoge dayo’; } protected function createFugaDriver() { return ‘fuga dayo’; } }
// constructorͰManagerΫϥε ܕએݴ $this->app->bind( StringManager::class, function(Application $app) { return new
StringManager($app); });
protected $manager; public function __construct(StringManager $manager) { $this->manager = $manager;
} public function __invoke($id) { $manager = $this->manager->driver(‘hoge’); if($id === 1) { $manager = $this->manager->driver(‘fuga’); } dd($manager); }
SOLIDͳAppΛʂ