Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR-4 approach acceptable? #317

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

gohanman
Copy link
Contributor

Checking in if this is a reasonable approach to chipping away at #192 - take a file containing multiple classes, lift one out into its own file, and namespace it.

@dregad
Copy link
Member

dregad commented Mar 21, 2017

@gohanman thanks for your contribution. Yes, that is the general idea.

However, before you spend too much time converting the files, please note that I have a work in progress (currently not in a publicly available branch), to add and standardize PHPDoc blocks that would likely cause a large number of merge conflicts.

I would also like to have a discussion regarding the namespaces before moving forward. If you have already given this some thought, please share your conclusions.

@gohanman
Copy link
Contributor Author

RE: namespaces:

I can see at least two options: dividing by base class e.g. ADOdb\Connections or ADOdb\RecordSets or dividing by driver e.g. ADOdb\Drivers\MySQL, ADOdb\Drivers\Postgres, etc. Going by base class is probably more common in most big PHP projects I've seen. It's less clear to me where something like ADOFieldObject should land. A catch-all like ADOdb\Lib or ADOdb\Util isn't that much tidier than leaving things in the root namespace.

For backward compatibility it's probably worth allowing exceptions to PSR-1 naming conventions. Having some lowercase class names like ADOdb\Connections\postgres9 ought to make it easier to keep ADONewConnection('postgres9') working as expected. Maybe that's another upside to grouping things by base class.

@dregad
Copy link
Member

dregad commented Mar 21, 2017

I haven't thought this all the way through, but it seems to me that dividing by driver offers the advantage of regrouping all code for that driver in a single directory, i.e. under ADOdb\Drivers\MySQL we would find classes Connection, RecordSet, DataDict, etc, so maybe easier for development and maintenance.

I am fine with keeping "global" classes in the root namespace for now, I agree that there is not much added value to use ADOdb\lib (unless there are a lot of classes).

With regards to BC and making exceptions to the PSR standard, I wouldn't worry about it too much considering that it should be fairly simple to provide compatibility within the ADONewConnection function.

Speaking of that, I was thinking of moving some of the functionality currently provided via standalone functions into a generic ADOdb class, so instead of $db = ADONewConnection('mysql'); we would do `$db = new ADOdb('mysql'); or something similar.

@gohanman
Copy link
Contributor Author

OK. With the driver route, what's your opinion on closely related drivers - i.e., does ADOdb\Drivers\Postgres9\Connection extends ADOdb\Drivers\Postgres8\Connection, or is there a single ADOdb\Drivers\Postgres namespace containing classes for the different versions?

@dregad
Copy link
Member

dregad commented Mar 21, 2017

A lot of these "related drivers" are legacy things that should be refactored.

In the case of PostgreSQL, since the earliest supported version as of this writing is 9.2 (EOL in Sept 2017), the plan was to merge all the drivers into a single class.

And if we do end up needing a specialized class for version-specific functionality, I think it would make sense to have it in the ADOdb\Drivers\Postgres namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants