Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
5.5リリース直前 Laravel Container 使い方振り返り
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
yuuki takezawa
July 31, 2017
Technology
480
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
5.5リリース直前 Laravel Container 使い方振り返り
yuuki takezawa
July 31, 2017
Transcript
32 slides
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Λʂ
More Decks by yuuki takezawa
See All by yuuki takezawa
なぜAI時代に 「イベント」を中心に考えるのか? / Why focus on "events" in the age of AI?
ytake
4
2.3k
PHPでアクターモデルを活用したSagaパターンの実践法 / php-saga-pattern-with-actor-model
ytake
0
3.2k
PHP ステートレス VS ステートフル 状態管理と並行性 / php-stateless-stateful
ytake
0
410
PHPでアクターモデルを理解・体験しよう / Understand and experience the actor model in PHP
ytake
2
1k
再考 アクターモデル/ reconsider actor model
ytake
0
1.7k
GoとアクターモデルでES+CQRSを実践! / proto_actor_es_cqrs
ytake
1
750
Phluxorでアクターモデルを 理解・体験しよう / toolkit-for-flexible-actor-models-in-php-phluxor
ytake
1
410
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
2
1.4k
DRE/SREのプラクティス融合によるクラウドネイティブなデータ基盤作り / dre_sre
ytake
0
1.1k
Other Decks in Technology
See All in Technology
Kiro CLI 入門 (ターミナルと CI で使う) | 目指せ Kiro マスター 03
inariku
PRO
2
130
IBC 2026 動画技術関連レポート / IBC 2026 Report
cyberagentdevelopers
PRO
2
450
Kiro Crew の Bot (続く役目を任せる窓口) | 目指せ Kiro マスター 12
inariku
PRO
2
360
2026-11-11 Tamachi.sre#7 PaCにインフラリソースの命を救われました。 / PaC saves the infra resource life
masasuzu
0
110
Claude Codeで作ったアプリを安全に公開する/Built with Claude Japan 2026
yoshidashingo
0
230
Reticulum, le réseau cypherpunk dont vous avez besoin !
rlifchitz
0
130
セキュリティ専任チームなしで攻撃を先回りするSREが実践したSIEM on Amazon OpenSearch Service
cscengineer
PRO
1
760
GCASアップデート(202607-202610)
techniczna
1
250
AIエージェントの監視、思考を見るか行動を見るか / Monitoring AI Agents: Thoughts or Actions
yusukeshimizu
2
180
レガシーコードに対する loop engineering的なAI開発プロセス導入について
kubell_hr
0
330
業務でAWSをあまり使っていない私が、AWSへのモチベを保つ方法
smt7174
0
190
evcc & Home Assistant
naltatis
0
540
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
400
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
310
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Statistics for Hackers
jakevdp
799
230k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Design in an AI World
tapps
1
390
Abbi's Birthday
coloredviolet
5
11k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Optimising Largest Contentful Paint
csswizardry
37
4k