views:

31

answers:

2

I have a library "Google" that I keep in a separate GIT repository.

This library is used in some projects. The problem is that I want to rename the library to match the naming convention of these projects, e.g. "Service_Google".

Since PHP doesn't allow for automagic refactoring, the best way I've come up with is to do the following.

  1. Clone the repo
  2. Use regex search and replace to change every class name and reference
  3. [use it until there's a new version]
  4. Revert
  5. Pull the latest version
  6. Step 2

There must be a better way, right?

+1  A: 

I would work very hard to avoid changing an external library in any way. Even apparently benign changes such as name changes can be fraught with danger. The sheer hassle of needing to make those changes every time you take a new version is to me unacceptable.

I would also say that the motivation of bending Google's stuff to conform to your naming convention is rather suspect. Should we take this further? Colour for Color? Oui for Yes if we're working in France? (I mean in variable names and function names not in presentation.)

I would even avoid using class_alias for this purpose. You give a new developer, who happens already to be familiar with the external library, a headache.

Bottom line: there are times to go with the flow, embrace the library that you are using, control the things you own.

djna
The problem is that, for autoloading to work, classes must be named in a specific way.
Znarkus
Speculation: Is it not possible to write your own auto-loader to accommodate both naming convetions?
djna
A: 

Well, if you use a reasonably modern IDE, it probably has tools for automatic re-factoring. In NetBeans, just right click on the class name and select "Rename". That's all there is to it.

ircmaxell