- Can I use this bundle directly in Laravel, or is it only for Symfony?
- This bundle is designed for Symfony and assumes its Bundle architecture. For Laravel, you’d need to manually adapt it—likely by extracting the type converters (e.g., `StringType`, `DateTimeType`) and registering them via Laravel’s `DatabaseServiceProvider` or a custom connection resolver. The `SQLServerDriver` would also need Laravel-compatible integration.
- Does this bundle support `pdo_sqlsrv` instead of `pdo_dblib`?
- No, the bundle explicitly relies on `pdo_dblib` and its Composer script patches Doctrine’s `DriverManager` for this driver. Switching to `pdo_sqlsrv` would require modifying the bundle’s core logic or creating a separate driver class. Check if alternatives like `vlucas/phpdotenv` or Laravel’s native `sqlsrv` driver handle your use case.
- How do I handle type mismatches in Laravel Eloquent without global Doctrine overrides?
- Since Laravel’s Eloquent doesn’t use Doctrine’s type system directly, you can manually cast attributes in your models (e.g., `$casts = ['datetime_column' => 'datetime:Y-m-d H:i:s']`) or use accessors/mutators. For DBAL-level fixes (e.g., `NVARCHAR(MAX)`), you’d need to extend Laravel’s `Connection` class or use a custom `DBAL` event listener to intercept queries/responses.
- What SQL Server data types does this bundle *not* handle, and how can I extend it?
- The bundle currently focuses on `string`, `text`, and `datetime` types. For other types (e.g., `UNIQUEIDENTIFIER`, `GEOGRAPHY`, `XML`), you’d need to create custom Doctrine types and register them in `config.yml` under the `types` key. The bundle’s architecture is designed to be extended, but test edge cases like collations or large objects thoroughly.
- Will this bundle break if I update Laravel or Doctrine DBAL?
- Yes—this bundle is unmaintained and targets Symfony 2/3. Laravel’s Doctrine integration (via `illuminate/database`) may diverge from Symfony’s `DoctrineBundle`. Extract the core type converters into a standalone package and mock dependencies in tests to future-proof your integration. Avoid relying on the Composer `post-install-cmd` hook, as it’s invasive.
- How do I test this bundle in a Laravel project?
- Since the bundle lacks tests, mock its behavior by creating a Laravel-compatible wrapper. Use PHPUnit to test type conversions in isolation (e.g., `StringType::convertToDatabaseValue()`) and verify interactions with Laravel’s `Connection` or `QueryBuilder`. Test edge cases like timezone-aware datetimes, UTF-8 encoding, and large text fields with SQL Server’s `NVARCHAR(MAX)`.
- Are there Laravel-native alternatives to this bundle?
- Yes. For `pdo_sqlsrv` users, Laravel’s built-in Eloquent casting or packages like `laravel-mssql` (if available) may suffice. For DBAL-level fixes, consider creating a custom `Connection` resolver or using Doctrine event listeners (e.g., `SchemaEventArgs`). Check Packagist for Laravel-specific forks of this bundle or similar projects targeting SQL Server.
- How do I configure this bundle for partial type overrides (e.g., only for specific models)?
- The bundle overrides Doctrine types globally, which isn’t ideal for partial use. In Laravel, you’d need to dynamically swap type handlers per connection or model. One approach is to extend Laravel’s `Connection` class and override the `getDoctrineType()` method to conditionally apply the bundle’s types. Alternatively, use a trait in models to apply custom casting logic.
- What are the performance implications of using custom type handlers?
- Custom type handlers (e.g., converting `DATETIME2` to Carbon) introduce serialization/deserialization overhead. Benchmark your app with and without the bundle, especially for high-traffic APIs. Optimize by caching converted values or using Laravel’s built-in casting where possible. Avoid unnecessary conversions for simple `VARCHAR` fields.
- How do I handle timezone issues with SQL Server datetime conversions?
- SQL Server’s `DATETIME`/`DATETIME2` types may not preserve timezone info by default. Configure your Laravel app to use UTC consistently (e.g., `config/app.php` `timezone = 'UTC'`). In the bundle’s `DateTimeType`, explicitly handle timezone conversion using Carbon’s `createFromFormat()` or `setTimezone()`. Test with `DATETIMEOFFSET` types if your schema uses them.