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でアクターモデルを理解・体験しよう / Understand and experience the actor model in PHP
ytake
2
200
再考 アクターモデル/ reconsider actor model
ytake
0
620
GoとアクターモデルでES+CQRSを実践! / proto_actor_es_cqrs
ytake
1
320
Phluxorでアクターモデルを 理解・体験しよう / toolkit-for-flexible-actor-models-in-php-phluxor
ytake
1
230
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
2
1k
DRE/SREのプラクティス融合によるクラウドネイティブなデータ基盤作り / dre_sre
ytake
0
720
技術的負債と向き合う取り組みでよかったもの / positive_efforts_to_tackle_technical_debt
ytake
10
3.8k
アプリケーションエンジニアから強いデータエンジニアへの歩き方 / How to transition and become a Data Engineer from an Application Engineer
ytake
1
510
入門 境界づけられたコンテキスト
ytake
6
4.1k
Other Decks in Technology
See All in Technology
目玉アップデート!のSageMaker LakehouseとUnified Studioは何たるかを見てみよう!
nayuts
0
250
Classmethod_regrowth_2024_tokyo_security_identity_governance_summary
hiashisan
0
980
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
250
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
320
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
350
Kubeshark で Kubernetes の Traffic を眺めてみよう/Let's Look at k8s Traffic with Kubeshark
kota2and3kan
3
370
コンテナセキュリティのためのLandlock入門
nullpo_head
2
310
Turing × atmaCup #18 - 1st Place Solution
hakubishin3
0
420
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
150
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
190
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
110
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
270
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Navigating Team Friction
lara
183
15k
Being A Developer After 40
akosma
87
590k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Building Applications with DynamoDB
mza
91
6.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
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Λʂ