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
Slimをオススメしてみる ディレクトリ構造
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
gallu
October 25, 2023
Technology
640
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Slimをオススメしてみる ディレクトリ構造
gallu
October 25, 2023
More Decks by gallu
See All by gallu
日付四方山話
gallu
0
94
セッションで遊んでみた
gallu
0
80
Slimをオススメしてみる ControllerとContainer
gallu
0
430
20230315のPHP勉強会(Slimをオススメしてみる)
gallu
0
300
20230215PHP勉強会.pdf
gallu
0
78
PHP 来歴のトリヴィア
gallu
0
130
HTTPを振り返ってみる
gallu
0
70
Other Decks in Technology
See All in Technology
パッチ更新でterraform initが落ちた日
grimoh
1
140
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
130
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
140
Refining Active Record
shugo
0
160
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
200
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
200
Getting Started with Google Antigravity
glaforge
0
320
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.4k
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
950
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
180
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Faster Mobile Websites
deanohume
310
32k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
780
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
Abbi's Birthday
coloredviolet
4
10k
The untapped power of vector embeddings
frankvandijk
2
1.9k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
HDC tutorial
michielstock
2
960
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Transcript
Slimをオススメしてみる ディレクトリ構造 by がる
自己紹介 古庄と申します 「がる(gallu)」というハンドルでふらついております 本職は技術者です。現役プログラマーやってます バックエンド系なので、インフラとかDBとかも一通り
最近はPM業も多いですねぇ あわせて、教育とか色々
Slimいいよ!! https://www.slimframework.com/ Slim is a PHP micro framework
that helps you quickly write simple yet powerful web applications and APIs. Slim は、シンプルかつ強力な Web アプリケーションと API をすばやく作 成するのに役立つ PHP マイクロ フレームワークです。(Google) Slimは、シンプルかつパワフルなWebアプリケーションやAPIを素早く作 成できるPHPマイクロフレームワークです。(DeepL) Slimいいです!! micro framework いいです!! シンプルでいいです!! っていう個人の感想と妄想を垂れ流してみます(笑
連載記録 Slimをオススメしてみる https://speakerdeck.com/gallu/20230315nophpmian-qiang- hui-slimwoosusumesitemiru Slimをオススメしてみる ControllerとContainer
https://speakerdeck.com/gallu/slimwoosusumesitemiru- controllertocontainer
今回のお題 ちょっと方向性を変えて「ディレクトリ構成」を、各有名フ レームワークと比較していきたいと思います 結果として「Slimがスバラシイ」事をまた一つ、宣伝でき ればと思います(笑 ※ 主観です
Laravelのディレクトリ構成 いわゆる「MVC」ベースのディレク トリ構成ですね ぱっと見で大体分かる……ような 気がするんですがどうなんですか ねぇ? 実際「わかりやすい」んじゃない、
かなぁ? と。多分 昔は Modelsが無かった記憶がご ざいます(うろ覚え app/ Console/ Exceptions/ Http/ Controllers/ Middleware/ Jobs/ Models/ Providers/ Rules/ bootstrap/ config/ database/ public/ resources/ routes/ storage/ logs/ tests/
CakePHPのディレクトリ構成 こちらも「MVC」ベースです うっすらとLaravelとの違いはあるものの、 やっぱり大体「見ればあらかた分かる」 感じですね Laravelの app/
に対して、CakePHPの ほうは src/ って感じが興味深いです bin/ config/ plugins/ resources/ src/ Console/ Controller/ Model/ View/ templates/ tests/ tmp/ webroot/
Slim……はまず素のinstallをおさらい # まずは必要なものをinstall composer require slim/slim composer require slim/http composer
require slim/psr7 # こんな感じになります [gallu@鯖 slim_plain]$ ls composer.json composer.lock vendor # いわゆる「DocumentRoot」を作成します mkdir public vi public/index.php (コードは後述) # 簡易サーバ起動して動く事を確認 php -S 0.0.0.0:8080 -t public/
設置したindex.php <?php use Psr¥Http¥Message¥ResponseInterface as Response; use Psr¥Http¥Message¥ServerRequestInterface as Request;
use Slim¥Factory¥AppFactory; require __DIR__ . '/../vendor/autoload.php'; // Instantiate App $app = AppFactory::create(); // Add error middleware $app->addErrorMiddleware(true, true, true); // Add routes $app->get('/', function (Request $request, Response $response) { $response->getBody()->write("Hello"); return $response; }); $app->run();
(結果)素のSlimのディレクトリ構成 シンプル! 侘び寂び!! 後はどうとでも如何様にでも!!! あなたの設計とコードに合わせて自由に!!!!
真っ白なカンバスに好きな絵を描くことができます!!!!! 無限の荒野が広がってます!!!!!! スバラシイと思いませんか? とはいえまぁ流石にこれは「荒野に過ぎる」ので…… public/
Slim-Skeleton というものがございます いわゆる「こんな風にディレクトリ切ったらどうかね?」と いった感じのサンプルですね 数種類あるっぽいのですが(色々な人が作成しているみ たいです)、公式 https://github.com/slimphp を見ます
バージョン3の頃 https://github.com/slimphp/Slim-Skeleton/tree/3.1.8 注目は「srcに設定ファイル」? あとはまぁわかりやすく プログラムは別途 app/
を切る事が多いかと思います autoloaderの設定を忘れずに その辺はあくまでも「自由に」 src/ 設定ファイル routes.php settings.php middleware.php dependencies.php public/ templates/ logs/ tests/Functional/
バージョン4の頃 https://github.com/slimphp/Slim-Skeleton/tree/4.5.0 少しクリーンアークテクチャぽいのを意識してる? DomainとかInfrastructureとか 突っ込みどころはまぁ……
リポジトリだけ、なぜ app/ ? srcの名前空間名…… app/ 設定ファイル routes.php settings.php middleware.php dependencies.php repositories.php src/ (namespace App¥...) Application/ Domain/ Infrastructure/Persistence/User/ public/ templates/ logs/ tests/
個人的な好みと見解 まぁぶっちゃけ「Slim3ベースのスケルトン」のほうが好み でございます慣れてるし(笑 なので「Slim3のディレクトリ構成のままの、Slim4- Skeletonを作成公開しております(笑 コレデマタヒトツフエタ……
とはいえやっぱり「MVCだったころ」の作成物なので、そ ろそろクリーンアーキテクチャベースのも作っていきたい ような気はしております
まとめ もちろん他のフレームワークでも「ディレクトリ構成をごっ そりと入れ替える」事は大体可能だと思います 知ってる限りでは「出来ない事」はそれほど無かった記憶 ただ「それほど」なので、シンドイ箇所が無いわけでもなく 一方でSlimは「そもそもディレクトリ構成とか存在しなかっ
た」ベースなので、思うがままに自由に設計できます(笑 まぁ結果「大体Laravelに酷似」とかよくありますが(爆 とはいえ案件によっては「妙な縛りがあってそれがフレー ムワークの縛りと相性が悪い」なんてことも そんな時「にこそ」、選択肢としてSlimを、是非!!!(笑