Skip to main content

소스 정보

저장소
miles990/claude-software-skills
최근 소스 활동
2026년 1월 8일 02:34
감지된 SKILL.md 언어
영어
스타
25
포크
6

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
4 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
php
description
Modern PHP programming patterns
domain
programming-languages
version
1.0.0
tags
["php","laravel","composer","oop","traits"]
triggers
{"keywords":{"primary":["php","laravel","composer","symfony","wordpress"],"secondary":["eloquent","blade","artisan","phpunit","trait","doctrine"]},"context_boost":["web","backend","cms","api","legacy"],"context_penalty":["python","javascript","java","go"],"priority":"medium"}
# PHP ## Overview Modern PHP (7.4+/8.x) patterns including typed properties, attributes, and modern OOP features. --- ## Modern PHP Features ### Type System ```php <?php declare(strict_types=1); // Typed properties (PHP 7.4+) class User { public string $id; public string $email; public ?string $name = null; public bool $active = true; public array $roles = []; public DateTimeImmutable $createdAt; // Constructor promotion (PHP 8.0+) public function __construct( public readonly string $email, public readonly string $name, private string $password ) { $this->id = uniqid(); $this->createdAt = new DateTimeImmutable(); } } // Union types (PHP 8.0+) function process(string|int $value): string|int { return is_string($value) ? strtoupper($value) : $value * 2; } // Intersection types (PHP 8.1+) function processIterable(Countable&Iterator $items): int { return count($items); } // Return types function findUser(string $id): ?User { return $this->repository->find($id); } function getUsers(): array { return $this->repository->findAll(); } // Never return type (PHP 8.1+) function fail(string $message): never { throw new RuntimeException($message); } // Nullable types function setName(?string $name): void { $this->name = $name; } ``` ### Attributes (PHP 8.0+) ```php <?php use Attribute; // Define attribute #[Attribute(Attribute::TARGET_PROPERTY)] class Column { public function __construct( public string $name, public string $type = 'string', public bool $nullable = false ) {} } #[Attribute(Attribute::TARGET_METHOD)] class Route { public function __construct( public string $path, public string $method = 'GET' ) {} } #[Attribute(Attribute::TARGET_CLASS)] class Entity { public function __construct( public string $table ) {} } // Using attributes #[Entity(table: 'users')] class User { #[Column(name: 'id', type: 'uuid')] public string $id; #[Column(name: 'email', type: 'string')] public string $email; #[Column(name: 'name', nullable: true)] public ?string $name; } class UserController { #[Route(path: '/users', method: 'GET')] public function index(): array { return $this->userService->getAll(); } #[Route(path: '/users/{id}', method: 'GET')] public function show(string $id): User { return $this->userService->find($id); } } // Reading attributes $reflection = new ReflectionClass(User::class); $attributes = $reflection->getAttributes(Entity::class); foreach ($attributes as $attribute) { $instance = $attribute->newInstance(); echo $instance->table; // 'users' } ``` ### Enums (PHP 8.1+) ```php <?php // Basic enum enum Status { case Pending; case Active; case Inactive; public function label(): string { return match ($this) { self::Pending => 'Pending Review', self::Active => 'Active', self::Inactive => 'Inactive', }; } } // Backed enum (with values) enum Role: string { case Admin = 'admin'; case Moderator = 'moderator'; case User = 'user'; public function permissions(): array { return match ($this) { self::Admin => ['read', 'write', 'delete', 'admin'], self::Moderator => ['read', 'write', 'delete'], self::User => ['read', 'write'], }; } public static function fromString(string $value): self { return self::from($value); } public static function tryFromString(string $value): ?self { return self::tryFrom($value); } } // Usage $status = Status::Active; echo $status->label(); // "Active" $role = Role::Admin; echo $role->value; // "admin" $userRole = Role::from('user'); $permissions = $userRole->permissions(); ``` --- ## Object-Oriented Patterns ### Traits ```php <?php // Trait definition trait Timestampable { protected ?DateTimeImmutable $createdAt = null; protected ?DateTimeImmutable $updatedAt = null; public function getCreatedAt(): ?DateTimeImmutable { return $this->createdAt; } public function getUpdatedAt(): ?DateTimeImmutable { return $this->updatedAt; } public function touch(): void { $now = new DateTimeImmutable(); $this->createdAt ??= $now; $this->updatedAt = $now; } } trait SoftDeletable { protected ?DateTimeImmutable $deletedAt = null; public function delete(): void { $this->deletedAt = new DateTimeImmutable(); } public function restore(): void { $this->deletedAt = null; } public function isDeleted(): bool { return $this->deletedAt !== null; } } // Using traits class Document { use Timestampable; use SoftDeletable; public function __construct( public string $title, public string $content ) { $this->touch(); } } // Trait conflict resolution trait A { public function hello(): string { return 'Hello from A'; } } trait B { public function hello(): string { return 'Hello from B'; } } class MyClass { use A, B { A::hello insteadof B; B::hello as helloFromB; } } ``` ### Interfaces and Abstract Classes ```php <?php // Interface interface Repository { public function find(string $id): ?object; public function findAll(): array; public function save(object $entity): void; public function delete(string $id): void; } // Generic-style interface interface Collection { public function add(mixed $item): void; public function remove(mixed $item): bool; public function contains(mixed $item): bool; public function count(): int; public function toArray(): array; } // Abstract class abstract class BaseRepository implements Repository { public function __construct( protected PDO $pdo, protected string $table ) {} abstract protected function hydrate(array $row): object; public function find(string $id): ?object { $stmt = $this->pdo->prepare( "SELECT * FROM {$this->table} WHERE id = :id" ); $stmt->execute(['id' => $id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); return $row ? $this->hydrate($row) : null; } public function findAll(): array { $stmt = $this->pdo->query("SELECT * FROM {$this->table}"); return array_map( fn(array $row) => $this->hydrate($row), $stmt->fetchAll(PDO::FETCH_ASSOC) ); } } // Concrete implementation class UserRepository extends BaseRepository { public function __construct(PDO $pdo) { parent::__construct($pdo, 'users'); } protected function hydrate(array $row): User { return new User( id: $row['id'], email: $row['email'], name: $row['name'] ); } public function findByEmail(string $email): ?User { // Custom method } } ``` --- ## Error Handling ```php <?php // Custom exceptions class AppException extends Exception { public function __construct( string $message, public readonly string $code, public readonly array $context = [], ?Throwable $previous = null ) { parent::__construct($message, 0, $previous); } } class ValidationException extends AppException { public function __construct( public readonly array $errors, ?Throwable $previous = null ) { parent::__construct( 'Validation failed', 'VALIDATION_ERROR', ['errors' => $errors], $previous ); } } class NotFoundException extends AppException { public function __construct( string $resource, string $id, ?Throwable $previous = null ) { parent::__construct( "{$resource} not found: {$id}", 'NOT_FOUND', ['resource' => $resource, 'id' => $id], $previous ); } } // Result pattern readonly class Result { private function __construct( public mixed $value, public ?string $error, public bool $success ) {} public static function success(mixed $value): self { return new self($value, null, true); } public static function failure(string $error): self { return new self(null, $error, false); } public function map(callable $fn): self { if (!$this->success) { return $this; } return self::success($fn($this->value)); } public function flatMap(callable $fn): self { if (!$this->success) { return $this; } return $fn($this->value); } } // Usage function createUser(array $data): Result { if (empty($data['email'])) { return Result::failure('Email is required'); } try { $user = new User($data['email'], $data['name'] ?? ''); $this->repository->save($user); return Result::success($user); } catch (Exception $e) { return Result::failure($e->getMessage()); } } ``` --- ## Collections and Arrays ```php <?php // Array functions $users = [ ['name' => 'Alice', 'age' => 30], ['name' => 'Bob', 'age' => 25], ['name' => 'Charlie', 'age' => 35], ]; // Filter $adults = array_filter($users, fn($u) => $u['age'] >= 30); // Map $names = array_map(fn($u) => $u['name'], $users); // Reduce $totalAge = array_reduce($users, fn($sum, $u) => $sum + $u['age'], 0); // Find
GitHub에서 보기
이 SKILL.md는 매우 커서 SkillsMP가 여기에는 첫 섹션만 미리 보여줍니다. GitHub에서 보기