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でアクターモデルを活用したSagaパターンの実践法 / php-saga-pattern-with-actor-model
ytake
0
1.7k
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
170
PHPでアクターモデルを理解・体験しよう / Understand and experience the actor model in PHP
ytake
2
590
再考 アクターモデル/ reconsider actor model
ytake
0
1.3k
GoとアクターモデルでES+CQRSを実践! / proto_actor_es_cqrs
ytake
1
490
Phluxorでアクターモデルを 理解・体験しよう / toolkit-for-flexible-actor-models-in-php-phluxor
ytake
1
310
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
2
1.2k
DRE/SREのプラクティス融合によるクラウドネイティブなデータ基盤作り / dre_sre
ytake
0
850
技術的負債と向き合う取り組みでよかったもの / positive_efforts_to_tackle_technical_debt
ytake
10
3.9k
Other Decks in Technology
See All in Technology
rubygem開発で鍛える設計力
joker1007
1
170
Claude Code Actionを使ったコード品質改善の取り組み
potix2
PRO
6
2k
標準技術と独自システムで作る「つらくない」SaaS アカウント管理 / Effortless SaaS Account Management with Standard Technologies & Custom Systems
yuyatakeyama
3
1.2k
VISITS_AIIoTビジネス共創ラボ登壇資料.pdf
iotcomjpadmin
0
150
UIテスト自動化サポート- Testbed for XCUIAutomation practice
notoroid
0
120
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1.5k
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
130
変化する開発、進化する体系時代に適応するソフトウェアエンジニアの知識と考え方(JaSST'25 Kansai)
mizunori
0
170
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
1
430
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
29
9.6k
Oracle Audit Vault and Database Firewall 20 概要
oracle4engineer
PRO
3
1.7k
Definition of Done
kawaguti
PRO
6
470
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Gamification - CAS2011
davidbonilla
81
5.3k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Faster Mobile Websites
deanohume
307
31k
A better future with KSS
kneath
239
17k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
4
200
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Building Adaptive Systems
keathley
43
2.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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Λʂ