开发者

PHP rename external libraries

开发者 https://www.devze.com 2023-01-07 16:02 出处:网络
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 p

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

T开发者_JS百科here must be a better way, right?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消