PHP開発支援(Slim/PDO/Composer)。 PSR-12、PHPStan、PDOでセキュアPHP開発をガイド。
/plugin marketplace add sk8metalme/ai-agent-setup/plugin install lang-php@ai-agent-setupThis skill is limited to using the following tools:
このファイルはPHP開発に特化した設定を定義します。
最新の安定版バージョンは以下の公式ドキュメントを参照してください:
| 技術 | 公式ドキュメント | 用途 |
|---|---|---|
| PHP | PHP Downloads | バージョン確認・ダウンロード |
| PHP Supported Versions | PHP Supported Versions | サポート状況確認 |
| Slim Framework | Slim Framework | 公式サイト |
| Slim (Packagist) | slim/slim | 最新版・リリース履歴 |
| PHPUnit | phpunit/phpunit | 最新版・リリース履歴 |
| PHPStan | phpstan/phpstan | 最新版・リリース履歴 |
| Monolog | monolog/monolog | 最新版・リリース履歴 |
最新の安定版バージョンは上記の公式ドキュメントリファレンスで確認してください。
src/
├── Controllers/ # コントローラー
├── Models/ # データモデル
├── Services/ # ビジネスロジック
├── Helpers/ # ヘルパー関数
└── Config/ # 設定
public/ # 公開ディレクトリ
├── index.php # エントリーポイント
├── css/
├── js/
└── images/
vendor/ # Composerパッケージ
tests/ # テストコード
composer.json # 依存関係定義
phpunit.xml # PHPUnit設定
{
"name": "company/project",
"description": "PHP Application",
"type": "project",
"require": {
"php": "^8.3",
"monolog/monolog": "^3.0",
"slim/slim": "^4.0",
"slim/psr7": "^1.0",
"ext-pdo": "*",
"ext-pdo_mysql": "*",
"ext-pdo_oci": "*"
},
"require-dev": {
"phpunit/phpunit": "^11.0",
"phake/phake": "^4.0",
"phpstan/phpstan": "^2.0",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.0"
},
"comment": "最新版は公式ドキュメントリファレンスのPackagistリンクで確認してください(参考値: 2025年12月時点)",
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
// config/database.php
return [
'mysql' => [
'dsn' => 'mysql:host=localhost;dbname=app;charset=utf8mb4',
'username' => 'root',
'password' => 'password',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
],
'oracle' => [
'dsn' => 'oci:dbname=//localhost:1521/ORCL;charset=AL32UTF8',
'username' => 'app_user',
'password' => 'password',
'options' => [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]
]
];
use Monolog\Logger;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Formatter\LineFormatter;
class LoggerFactory
{
public static function create(string $name = 'app'): Logger
{
$logger = new Logger($name);
// 日別ローテーション
$handler = new RotatingFileHandler(
__DIR__ . '/logs/app.log',
30, // 30日間保持
Logger::INFO
);
$formatter = new LineFormatter(
"[%datetime%] %channel%.%level_name%: %message% %context%\n",
'Y-m-d H:i:s'
);
$handler->setFormatter($formatter);
$logger->pushHandler($handler);
return $logger;
}
}
グローバルセキュリティポリシーを参照してください。
// セキュリティ例
// 入力検証
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
// CSRFトークン生成
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
// パスワードハッシュ化
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
use PHPUnit\Framework\TestCase;
use Phake;
class UserServiceTest extends TestCase
{
private $userRepository;
private $logger;
private $userService;
protected function setUp(): void
{
$this->userRepository = Phake::mock(UserRepository::class);
$this->logger = Phake::mock(\Monolog\Logger::class);
$this->userService = new UserService(
$this->userRepository,
$this->logger
);
}
public function testCreateUser(): void
{
// テスト実装
Phake::when($this->userRepository)->create($userData)
->thenReturn(['id' => 1] + $userData);
$user = $this->userService->create($userData);
Phake::verify($this->userRepository)->create($userData);
Phake::verify($this->logger)->info('User created', Phake::anyParameters());
}
}
# Composer
composer install
composer require phake/phake --dev
composer require monolog/monolog
# テスト
./vendor/bin/phpunit
./vendor/bin/phpunit --coverage-html coverage
./vendor/bin/phpstan analyse
# コード整形
./vendor/bin/php-cs-fixer fix
./vendor/bin/phpcs --standard=PSR12 src/
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.