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
Slimをオススメしてみる ディレクトリ構造
Search
gallu
October 25, 2023
Technology
610
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
84
セッションで遊んでみた
gallu
0
79
Slimをオススメしてみる ControllerとContainer
gallu
0
400
20230315のPHP勉強会(Slimをオススメしてみる)
gallu
0
290
20230215PHP勉強会.pdf
gallu
0
71
PHP 来歴のトリヴィア
gallu
0
130
HTTPを振り返ってみる
gallu
0
67
Other Decks in Technology
See All in Technology
500名弱規模の組織のPythonプロジェクト(dbt) をどう管理するか?
hiracky16
0
180
巨大気象データと戦う ― サロゲートモデル学習を高速化する圧縮技術
gpuunite_official
0
280
国家プロジェクトを支える「さくらONE」 大規模LLM開発におけるGPU障害を乗り越えるクラスター運用戦略
gpuunite_official
0
290
Rust×eBPFでEDRっぽいものをつくる
sunlife3
2
970
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
ClaudeCodeでセキュリティ監視業務を半自動化_1年の運用でわかったAIに任せる設計の5つのポイント
kintotechdev
3
480
【書籍出版記念】 10周回って、エージェント開発は RAGがすべてだった。〜RAGの歴史と開発現場で見えた実践知〜
akiratameto
20
7.6k
Kiro5兄弟のいまどきのセキュリティ基礎知識
kentapapa
0
290
AI for Science時代を切り開く、政府の次世代HPC戦略の展望
gpuunite_official
0
260
Claude Teamプランの コスト最適化を考える
rfdnxbro
0
710
Oracle MCP Servers Explained
thatjeffsmith
1
510
暗号化?某ファイルストレージはどうなるの!? 3rd Partyとうまく付き合う秘密度ラベル設計
kasada
0
200
Featured
See All Featured
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
250
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
900
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
67
57k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Prompt Engineering for Job Search
mfonobong
0
420
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
490
HDC tutorial
michielstock
2
820
Skip the Path - Find Your Career Trail
mkilby
1
190
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を、是非!!!(笑