php-oop
/php-oop
Pokazuje w PHP zasady projektowania klas i obiektów wartości, np. Tell Don't Ask, readonly properties i IteratorAggregate.
- Autor
- fabiensalles ↗
- Repozytorium
- claude-marketplace ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 12.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pokazuje w PHP zasady projektowania klas i obiektów wartości, np. Tell Don't Ask, readonly properties i IteratorAggregate.
Wyzwalacze z opisu
Oryginalny opis (EN)
ACTIVATE when designing PHP classes, value objects, collections, or when the user asks about object design, encapsulation, or 'Tell Don't Ask' in PHP. Provides PHP-specific examples for the cross-language OOP rules defined in craft:oop-principles, plus PHP-specific patterns (readonly properties, IteratorAggregate). DO NOT use for: refactoring methodology (see php-refactoring), DDD domain modeling (see php-ddd-conventions).
Jak działa
- Example — Rule 1: Tell Don't Ask
- Example — Rule 2: Collection Over Named Properties
- Example — Rule 3: Whole Object
- Example — Rule 4: Iterable Collections via IteratorAggregate
- Example — Rule 5: Self-Describing Value Object
Podgląd SKILL.md
---
name: php-oop
description: "ACTIVATE when designing PHP classes, value objects, collections, or when the user asks about object design, encapsulation, or 'Tell Don't Ask' in PHP. Provides PHP-specific examples for the cross-language OOP rules defined in craft:oop-principles, plus PHP-specific patterns (readonly properties, IteratorAggregate). DO NOT use for: refactoring methodology (see php-refactoring), DDD domain modeling (see php-ddd-conventions)."
---
# OOP — PHP Examples
> The **rules** are defined in `craft:oop-principles`. This skill provides PHP / Symfony examples plus PHP-specific patterns.
## Example — Rule 1: Tell Don't Ask
```php
// ❌ AVOID — caller queries and decides
foreach ($identityDocument->getRequiredFieldNames() as $fieldName) {
$file = $identityDocument->getFileByFieldName($fieldName);
if ($file !== null) { continue; }
// ... re-download logic
}
// ✅ CORRECT — object exposes behavior
foreach ($identityDocument->getMissingExistingFiles() as $fieldName => $existingFile) {
// Object already determined which files are missing
}
```
## Example — Rule 2: Collection Over Named Properties
```php
// ❌ AVOID — N separate properties = N identical code paths
final class FormData {
private ?File $frontFile = null;
private ?File $backFile = null;
private ?File $passportFile = null;
}
// ✅ CORRECT — one keyed collection
final class FormData {
/** @param array<string, File> $files */
private array $files = [];
public function addFile(string $fieldName, File $file): void { /* ... */ }
}
```
## Example — Rule 3: Whole Object
```php
// ❌ AVOID — caller destructures
$collection->add(
documentType: $document->type,
documentName: $document->originalFileName,
downloadUrl: $url,
);
// ✅ CORRECT — pass the whole object
$collection->addFromDocument($document, $url);
```
## Example — Rule 4: Iterable Collections via `IteratorAggregate`
PHP-specific: implement `IteratorAggregate` to allow `foreach` while keeping internals private.
```php
/** @implements \IteratorAggregate<string, FileInfo> */
final class FilesCollection implements \IteratorAggregate
{
public function __construct(private array $files = []) {}
public function add(string $name, FileInfo $file): void
{
$this->files[$name] = $file;
}
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->files);
}
}
// Usage: foreach ($collection as $name => $file) { ... }
```
## Example — Rule 5: Self-Describing Value Object
```php
// ❌ AVOID — consumer needs external fieldName → fileType mapping
final class UploadFile {
public function __construct(
public string $content,
public string $originalFileName,
) {}
}
// ✅ CORRECT — object carries its own type
final readonly class UploadFile {
public function __construct(
public FileTypeEnum $type,
public string $content,
public string $originalFileName,
) {}
}
```
Readonly placement (per-property vs class-level) is `php-8-2`'s call, not this skill's.
Wersje
W bazie nie ma innych skilli o nazwie php-oop.
Migawka bazy z 28.10.2026 · wersja paczki 4641b63fe786 (skrót SHA-256 całej paczki)
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 95oop-principles
Wyjaśnia zasady OOP, np. Tell Don't Ask i obiekty wartości, i pokazuje, jak projektować klasy w różnych językach. - 95ts-oop
Projektuje klasy w TypeScript: enkapsulację, obiekty wartości, kolekcje, zasadę Tell Don't Ask i Symbol.iterator. - 90oop-guide
Podpowiada projekt hierarchii klas i zasady OOP: dziedziczenie, polimorfizm, SOLID, wzorce projektowe i interfejsy. - 100php-idioms
Pokazuje nowoczesne idiomy PHP 8.x: typy ścisłe, enumy, klasy readonly i wyrażenia match przy refaktoryzacji kodu. - 100php-language
Stosuje podstawowe standardy języka PHP i nowoczesne funkcje 8.x, takie jak enumy, fibers, właściwości readonly i argumenty nazwane. - 95oop-encapsulation
Pomaga stosować zasady enkapsulacji i ukrywania informacji w projektowaniu obiektowym oraz kontrolować dostęp do stanu i zachowania obiektów.