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
440
5.5リリース直前 Laravel Container 使い方振り返り
yuuki takezawa
July 31, 2017
Tweet
Share
More Decks by yuuki takezawa
See All by yuuki takezawa
オブジェクトのおしゃべり大失敗 メッセージングアンチパターン集 / messaging anti-pattern collection
ytake
2
790
DRE/SREのプラクティス融合によるクラウドネイティブなデータ基盤作り / dre_sre
ytake
0
550
技術的負債と向き合う取り組みでよかったもの / positive_efforts_to_tackle_technical_debt
ytake
10
3.6k
アプリケーションエンジニアから強いデータエンジニアへの歩き方 / How to transition and become a Data Engineer from an Application Engineer
ytake
1
340
入門 境界づけられたコンテキスト
ytake
6
3.9k
時間軸とドメインイベントとデータ処理
ytake
1
2k
事業のスケールアウトを支える PHPで作る分散アーキテクチャ
ytake
4
4.5k
Hack HTTP Request and Response Interfaces
ytake
0
6.6k
Hackで作る堅実な アプリケーションアーキテクチャ / Hack-application-architecture
ytake
3
7.6k
Other Decks in Technology
See All in Technology
テストコードを書きながらCompose Multiplatformを乗りこなす
subroh0508
0
150
「できる!」を増やすGitHub Copilot活用法 / How to use GitHub Copilot to expand your possibilities
sansan_randd
1
240
LINEヤフーのウェブアクセシビリティ
lycorptech_jp
PRO
3
210
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
12
7.9k
TDD - Test Driven Drupal
opdavies
0
3k
社内での継続的な機械学習勉強会の開催のコツ
yudai00
2
390
AWS アーキテクチャ作図入門/aws-architecture-diagram-101
ma2shita
16
6.7k
.NET GraphQL Client のリアル
sansantech
PRO
1
450
能動学習のいろは:書籍「Human-in-the-Loop機械学習」3〜5章
hiroyoshiito
0
310
#phpconkagawa レガシーコードにもオブザーバビリティを 〜少しずつ始めるサービス監視〜
yamato_sorariku
0
570
TypeScript の抽象構文木を用いた、数百を超える API の大規模リファクタリング戦略
yanaemon
6
1.3k
PhpStorm超絶技巧40分集中講義 #phpconkagawa
yusuke
4
790
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Embracing the Ebb and Flow
colly
80
4.2k
Testing 201, or: Great Expectations
jmmastey
30
6.4k
How GitHub (no longer) Works
holman
305
140k
A Tale of Four Properties
chriscoyier
153
22k
5 minutes of I Can Smell Your CMS
philhawksworth
199
19k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Building an army of robots
kneath
300
42k
In The Pink: A Labor of Love
frogandcode
138
21k
Being A Developer After 40
akosma
67
580k
Art, The Web, and Tiny UX
lynnandtonic
290
19k
Raft: Consensus for Rubyists
vanstee
133
6.3k
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Λʂ