symfony-components
Symfony Components
Complete reference for all 38 Symfony components — patterns, APIs, configuration, and best practices for PHP 8.3+ and Symfony 7.x.
Component Index
HTTP & Runtime
- HttpFoundation — Object-oriented HTTP requests/responses replacing PHP globals → reference
- HttpKernel — Request handling, kernel events, controller resolution, middleware → reference
- PSR-7 Bridge — Bidirectional HttpFoundation ↔ PSR-7 conversion → reference
- Runtime — Decoupled bootstrapping for multiple runtime environments → reference
Messaging
- Messenger — Sync/async message buses, transports (AMQP, Redis, Doctrine), middleware, envelopes → reference
Console
- Console — CLI commands, input/output handling, helpers, formatters, progress bars → reference
Dependency Injection
- DependencyInjection — Service container, autowiring, compiler passes, tagged services → reference
- Contracts — Decoupled abstractions for interoperability (Cache, EventDispatcher, HttpClient, etc.) → reference
Forms & Validation
- Form — Form creation, field types, events, data transformers, collections, theming → reference
- Validator — JSR-303 constraints, custom validators, groups, severity levels → reference
- OptionsResolver — Option configuration with defaults, validation, normalization, nesting → reference
Cache, Lock & Semaphore
- Cache — PSR-6/PSR-16 adapters, tag-based invalidation, stampede prevention → reference
- Lock — Exclusive resource locking across processes/servers (Redis, PostgreSQL, file) → reference
- Semaphore — Concurrent access with configurable limits (Redis, DynamoDB) → reference
Events & Workflow
- EventDispatcher — Observer/Mediator patterns, listeners, subscribers, priorities → reference
- Workflow — State machines, workflow transitions, guards, metadata, events → reference
Configuration & Expressions
- Config — Configuration loading, validation, caching, tree building, bundle config → reference
- ExpressionLanguage — Safe expression sandbox for business rules, validation, security → reference
- Yaml — YAML parsing, dumping, linting with full data type support → reference
Filesystem, Finder & Process
- Filesystem — Platform-independent file/directory operations, atomic writes, path utils → reference
- Finder — File search with fluent criteria (name, size, date, depth, content) → reference
- Process — Secure system command execution, async processes, output streaming → reference
Serialization & Types
- PropertyAccess — Read/write objects and arrays via string paths (
foo.bar[baz]) → reference - PropertyInfo — Property metadata extraction (types, access, descriptions) → reference
- TypeInfo — PHP type extraction, resolution, and validation → reference
- VarDumper — Enhanced variable debugging with HTML/CLI formatters → reference
- VarExporter — Export PHP data to OPcache-optimized code, lazy ghost/proxy objects → reference
Testing
- BrowserKit — Simulated browser for programmatic HTTP, cookies, history → reference
- DomCrawler — HTML/XML traversal, CSS selectors, form automation → reference
- CssSelector — CSS-to-XPath conversion for DOM querying → reference
- PHPUnit Bridge — Deprecation reporting, time/DNS mocking, parallel tests → reference
Data & Text Utilities
- Uid — UUID (v1–v8) and ULID generation, conversion, Doctrine integration → reference
- Clock — Testable time abstraction with MockClock and DatePoint → reference
- Intl — Internationalization data (languages, countries, currencies, timezones) → reference
- JsonPath — RFC 9535 JSONPath queries on JSON structures → reference
- Mime — MIME message creation for emails and content types → reference
- Ldap — LDAP/Active Directory connections, queries, and management → reference
- Asset — URL generation and versioning for web assets → reference
Quick Patterns
Dependency Injection (Autowiring)
# services.yaml — most services are autowired automatically
services:
_defaults:
autowire: true
autoconfigure: true
App\:
resource: '../src/'
exclude: '../src/{DI,Entity,Kernel.php}'
Define a Route + Controller
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class ArticleController
{
#[Route('/articles/{id}', methods: ['GET'])]
public function show(int $id): Response
{
return new Response("Article $id");
}
}
Dispatch a Message (Async)
use Symfony\Component\Messenger\MessageBusInterface;
class OrderService
{
public function __construct(private MessageBusInterface $bus) {}
public function place(Order $order): void
{
$this->bus->dispatch(new OrderPlaced($order->getId()));
}
}
Create and Validate a Form
$form = $this->createForm(ArticleType::class, $article);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->persist($form->getData());
$em->flush();
return $this->redirectToRoute('article_list');
}
Cache with Tags
use Symfony\Contracts\Cache\ItemInterface;
$value = $cache->get('products_list', function (ItemInterface $item) {
$item->expiresAfter(3600);
$item->tag(['products']);
return $this->repository->findAll();
});
$cache->invalidateTags(['products']);
Console Command
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(name: 'app:process', description: 'Process items')]
class ProcessCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Processing...');
return Command::SUCCESS;
}
}
Event Subscriber
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OrderSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [OrderPlacedEvent::class => 'onOrderPlaced'];
}
public function onOrderPlaced(OrderPlacedEvent $event): void
{
// Handle event
}
}
Workflow Transition
if ($workflow->can($article, 'publish')) {
$workflow->apply($article, 'publish');
}
Lock a Resource
$lock = $factory->createLock('pdf-generation', ttl: 30);
if ($lock->acquire()) {
try {
generatePdf();
} finally {
$lock->release();
}
}
Best Practices
- Target PHP 8.3+ and Symfony 7.x with strict typing
- Use attributes over YAML/XML for routes, commands, message handlers, event listeners
- Prefer autowiring — only register services manually when configuration is needed
- Use Cache Contracts (
$cache->get()) over raw PSR-6 for stampede prevention - Apply validation groups to support multiple form contexts
- Use state machines by default; use workflows only when parallel states are needed
- Create custom constraints for business logic that can't be expressed with built-in ones
- Mock time and DNS in tests using PHPUnit Bridge for deterministic results
More from krzysztofsurdy/code-virtuoso
symfony-upgrade
Symfony framework version upgrade guide using the deprecation-first approach. Use when the user asks to upgrade Symfony to a new minor or major version, fix deprecation warnings, update Symfony recipes, check bundle compatibility, migrate between LTS versions, or plan a Symfony version migration strategy. Covers PHPUnit Bridge deprecation tracking, recipe updates, bundle compatibility checks, version-specific breaking changes, and the changelog-first upgrade workflow.
88solid
SOLID principles for object-oriented design with multi-language examples (PHP, Java, Python, TypeScript, C++). Use when the user asks to review SOLID compliance, fix a SOLID violation, evaluate class design, reduce coupling, improve extensibility, or apply Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, or Dependency Inversion principles. Covers motivation, violation detection, refactoring fixes, and real-world trade-offs for each principle.
47agentic-rules-writer
Interactive tool to generate tailored rules and instruction files for any AI coding agent. Use when the user asks to set up agent rules, configure Claude Code instructions, create Cursor rules, write Windsurf rules, generate Copilot instructions, or establish consistent AI coding standards for a team. Supports 13+ agents (Claude Code, Cursor, Windsurf, Copilot, Gemini, Codex, Cline, OpenCode, Continue, Trae, Roo Code, Amp) with global, team-shared, and dev-specific scopes. Defers to the `using-ecosystem` meta-skill for ecosystem discovery (skills, agents, recommendations) and runs an interactive questionnaire for workflow preferences.
47refactoring
Comprehensive skill for 89 refactoring techniques and 22 code smells with practical examples. Use when the user asks to refactor code, detect code smells, improve code quality, reduce complexity, or clean up technical debt. Covers composing methods, moving features between objects, organizing data, simplifying conditionals and method calls, dealing with generalization, and detecting smells across bloaters, OO abusers, change preventers, dispensables, and couplers with before/after comparisons and step-by-step mechanics.
42clean-architecture
Clean Architecture, Hexagonal Architecture (Ports and Adapters), and Domain-Driven Design fundamentals. Use when the user asks to design system architecture, define layer boundaries, apply DDD tactical patterns (entities, value objects, aggregates, repositories), structure a hexagonal application, enforce dependency rules, or evaluate whether a codebase needs architectural refactoring. Covers bounded contexts, use cases, domain services, and framework-independent design.
41security
Application security principles and OWASP Top 10 for building secure web applications. Use when the user asks to review code for security vulnerabilities, implement authentication or authorization, handle secrets or API keys, configure security headers, prevent injection attacks (SQL, XSS, CSRF), prepare for a security audit, or respond to a vulnerability report. Covers input validation, data protection, secrets management, session handling, and common security antipatterns.
40