jardispsr / dbschema
This package provides dbSchema interfaces for a domain driven design approach
Installs: 61
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/jardispsr/dbschema
Requires
- php: >=8.2
Requires (Dev)
- phpstan/phpstan: ^2.0.4
- squizlabs/php_codesniffer: ^3.11.2
README
PHP library providing database schema interfaces for Domain Driven Design (DDD) approaches.
Installation
composer require jardispsr/dbschema
Requirements
- PHP >= 8.2
Interfaces
This package provides two complementary interfaces for database schema operations:
DbSchemaReaderInterface
Read and introspect database schema information:
use JardisPsr\DbSchema\DbSchemaReaderInterface; class YourSchemaReader implements DbSchemaReaderInterface { public function tables(): ?array { // Return list of all tables in the database } public function columns(string $container, ?array $fields = null): ?array { // Return columns for a table, optionally filtered by specified fields } public function indexes(string $container): ?array { // Return indexes for a table } public function foreignKeys(string $container): ?array { // Return foreign keys for a table } public function fieldType(string $fieldType): ?string { // Map database field types to PHP types (e.g., 'varchar' -> 'string') } public function getDriverName(): string { // Return the name of the database driver (e.g., 'mysql', 'pgsql', 'sqlite') } }
DbSchemaExporterInterface
Export database schema in various formats:
use JardisPsr\DbSchema\DbSchemaExporterInterface; class YourSchemaExporter implements DbSchemaExporterInterface { public function toSql(array $tables): string { // Export schema as SQL DDL script } public function toJson(array $tables, bool $prettyPrint = false): string { // Export schema as JSON } public function toArray(array $tables): array { // Export schema as PHP array } }
Terminology
- Container: Database-agnostic term for "table" (aligned with DDD principles)
- Fields: Specific column attributes to retrieve when querying columns
Development
This project uses Docker for all development operations. See CLAUDE.md for detailed instructions.
Quick Start
# Install dependencies make install # Run code quality checks make phpcs make phpstan # Access container shell make shell
Code Quality Standards
- PHP Version: 8.2+ (development: 8.3)
- Coding Standard: PSR-12
- Static Analysis: PHPStan Level 8
- Strict Types: Required in all files
Contributing
- Follow branch naming:
feature/[ticket]_descriptionorfix/[ticket]_description - Pre-commit hooks enforce code standards automatically
- All PRs must pass PHPCS and PHPStan checks
License
MIT