Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop PHP packages in a team using composer?

Introduction

This is quite a lengthy question, the question I asked in the title is probably ambiguous and I may change this to something more suitable.

A similar question has already been asked and answered here although I do not think this entirely answers the question.

Synopsis

I am working with a team of developers on a project. We are using a framework (for argument sake - the framework is irrelevant) except one of the requirements is that we use composer.

These packages are essentially de-coupled from the application and each other, however one package may depend on another package.

These packages have their own git repository, and during development of the application have branch aliases set to dev-master.

Problem #1

In order for the application to work with my packages I need to register them with composer.json, which is fine until I have to commit the existing work of my package development to their repository before I can run composer update.

Problem #2

I have committed the initial package architecture and the composer.json. I run composer update which completes and my package is available to the application. Yet, I continue to develop this package at the same time another developer has already committed a different change to this package - i.e. a bug fix.

I need to update another package in order for my work to continue, yet I can't because doing so would throw a warning similar to:

Loading composer repositories with package information
Updating dependencies (including require-dev)         
  - Removing hu/admin (dev-master)
  The package has modified files:
  M composer.json
  M src/...
  Discard changes [y,n,v,?]?

If I respond with y my changes are blown away and lost forever. If I choose n composer is aborted and my project is broken due to a package not being updated parallel to my changes.

Problem #3

Another problem with this way of developing is that if I am working on my package outside of vendor and I commit my changes I can run composer update but my application is broken due to a fatal error. I fix the missing ; or other small syntax error. I commit this change and run composer update - yet I don't want my git history full of little typo fixes and parse error fixes just because I can't work on my package within the application parallel to other development/developers on the application and other packages or this package.

Problem #4

I discovered a package on GuitHub called franzliedke/studio which seems to part-solve my problem. Once a package has been published due to being complete/functional, this then cannot remain inside the vendor/bin directory alas causing the initial problems to rise once more.

Conclusion

I am wondering the best way to work around this or any best practices in order to work on packages with teams of developers without having to commit everything every time before I run composer update.

laravel did have a workbench feature which was pretty cool. But was removed from version 5.0 and so was that bad practice?

like image 977
Ash Avatar asked May 18 '15 00:05

Ash


1 Answers

That's what we do in huge projects consisting of several little composer components which are developed at the same time:

Develop your application 'in one piece' like described in the other answer your mentioned by just keeping all components separate inside their own namespaces and directory structure.

/Application
-composer.json (Application json)
-/src
--/Component1
----composer.json (Component json)
--/Component2
----composer.json (Component json)
--/ApplicationFeature
----Class1.php
----Class2.php

The whole application is developed in a single git repository which would eliminate most of your aforementioned problems. Then occasionally split the application repo into single component repositories using git subtree. I wrote a little php cli script which splits the project into smaller components and pushes them to the according component repositories. There are a lot of advantages compared to git submodules. The whole commit history of a component is kept and pushed to the component repository. More information on subtrees here In case you are interested please let me know, I am happy to share the script which splits/tags and finally pushes the single components by just defining a directory <-> componentName mapping as a json.

like image 145
tworabbits Avatar answered Oct 19 '22 03:10

tworabbits