I'm working with a CakePHP 3.0 project that needs to talk to a very old version of SQL Server, and I've found it necessary to extend the Sqlserver database driver class, as well as the SqlserverDialectTrait trait, in order to override a couple of functions therein.
That part, I've got working well enough. Where I'm stuck is this: where do I actually place the new class files within my project so that I can use them in the "driver" param of my database configuration?
(All of the documentation I've been able to find on doing this sort of thing seems to refer to CakePHP 2.0, rather than 3.0, though I'd be grateful if someone could point out anything I've overlooked.)
Theoretically you can place them anywhere where composer can load them when you reference it via a fully qualified name, which you can set in the driver
option of your datasource configuration.
In order to keep things Cake-ish, and to have the driver loadable even without specifying the fully qualified name, but just a classname (this works similar in various other places like components, helpers, tables, etc), you should follow the CakePHP core naming/folder schema, ie drivers go to into src/Database/Driver
with a matching namespace, ie App\Database\Driver
, and the dialect trait (while not affected by the CakePHP classname-only loadability thingy) would go into src/Database/Dialect
.
Then it would not only work with the fully qualified name like
'driver' => '\App\Database\Driver\MyCustomDriver'
but also with only the classname, like
'driver' => 'MyCustomDriver'
See also