Dennis
Dennis

Reputation: 8101

How to properly use 3rd party ZF2 modules when I want to make extensive changes to them

I want to use some 3rd party modules that serve my needs for the most part, but to use them for my specific application, I have to make some changes. More specifically I am using a module that provides ACL functionality, and in turn that module depends on a user&role-providing module. The modules themselves already have a database structure built-in, user object defined, role object defined, relationships between them defined, and so on. The modules also have a captcha, some HTML files with a specific layout in them, and some other stuff.

I have the need to use ACL but not all the other stuff. So I have the need to customize the stuff in the modules to suit my needs, namely:

I am under the impression that the proper ZF2 way is to extend the module to modify it to suit my needs. I do not see a way to easily extend these modules to make my changes, but maybe there is a way. I am concerned that if I do extend it, my extension will be trying to undo or redo a lot of what the base modules already had. It other words, it will become messy. I might as well create my own ACL module.

Another option is to edit the modules directly. I do not want to edit modules' code in the vendor folder, as doing so is not advisable, but I basically want to take the modules as-is and start hacking them up.

Question: How do I go about using the 3rd party modules ZF2 way, while allowing me to make extensive customizations to them?

Right now I am thinking of just taking the modules as-is, copying their content into my ZF2's module folder and using them as modules internal to my own ZF2 application. They will then be checked into the same version control as my main application code.

The only possible downside I see is that if the module is updated by the original author and I want their updates, I will need to either manually copy them over and incorporate them, or use something like git patches, or git cherry-pick.

Upvotes: 1

Views: 314

Answers (1)

edigu
edigu

Reputation: 10089

Editing any code which located under the vendor folder or incorporating them to your awesome application's module/library/whatever folder by copy & paste is not a good practice.

I think composer is what you're looking for. You can use any 3rd party library like a boss, really easily and when that library doesn't cover your requirements, extend classes which needs to provide more functionality in your own codebase using namespaces neatly.

For example, if none of the Zend's available pagination adapters are not enough for your requirements, extend/re-use/implement them with a similar scaffolding, using namespaces and existing interfaces. Example:

<?php
namespace YourModule\Paginator\Adapter;

use Zend\Paginator\Adapter\AdapterInterface;

class MyAwesomePaginatorAdapter implements AdapterInterface
{
   ...
}

You can do exactly same thing with every library which managed by composer in a typical ZF2 application. There are bunch of really good libraries on packagist.

I think another good approach is forking an existing 3rd party library which hosted in a popular service like github. Fork that library to your account, require in your project's composer.json by giving your own fork source (not original).

In other hand, create another project for your forked 3rd party library clone in your working environment. Clone it, edit, improve and manage that library under your own account, separated both from your project and original source.

When you think that improvement which you made are really rocks, contribute back to the original library by opening pull request for others.

Upvotes: 2

Related Questions