PHP Composer mixed with Git Submodules and Symfony2 - php

I have a project here that's a large Symfony2 app, I'm looking to introduce git submodules to components we're building here in-house. The issue here is that each component also requires composer packages for itself to function properly and now I have composer packages for the symfony2 app and composer packages needed for the component and I'm unsure how to handle/setup these dependencies here.
At the moment I'm manually running 'composer install' for each component (git submodule) we add, implying that each component has its own 'vendor' folder, this is far from ideal so I'm coming to Stack to get come good advice on how to keep these 'symfony composer dependencies' and 'component composer dependencies' easily maintainable.
I don't need to make sure the version of the symfony2 app's deps are synchronised with the components deps, i just need to make it simple and maintainable without having to run 'composer update' with each git submodule we setup.
Thanks!
EDIT
I'm now using composer's repositories key to define URL's to my companies private github repos. I'm able to pull in a singular private repo, lets call it Repo A. However when I add Repo B and make Repo A require Repo B it doesn't resolve properly.
composer.json for Repo A (user-reporting-component): https://gist.github.com/dragoonis/6ea92e062762c516baea
Composer.json for Repo B (database-component): https://gist.github.com/dragoonis/e54b47b75a79b82ebaea
The following error message occurs: https://gist.github.com/dragoonis/d79cd2c2dd5cc50bcd2a
The package of opinurate/database-component does exist as it's one of the repos defined in the respositories key.
Conclusion
The end solution here was to use Satis to setup what is your own private version of 'packagist' what will work alongside packagist.
I setup Satis at 'http://packages.mydomain.com' and added a 'repositories' key in my main apps composer.json file to that URL. Now when evaluating package names it will use your own custom satis server to give you git URL's too.

I would say your best bet is to add those components via composer as opposed to git submodules. It makes coding and maintenance a bit more complex, but it ensures that your application is aware for all the actual dependencies.
If you don't want them to be public and want an easier way to handle them, then i would roll out a Satis deploy locally and register them all there, adding that satis repo to your composer.json.
Satis is a simpler version of Packagist, as long as the server with it, and the machines that run composer install have access to your private repositories, nothing else will see them. There is documentation on the Composer website at: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
You will then setup packages.yourcompany.com and add it to your composer.json as an alternate source of packages. Everything stays private.
Reply to Edit:
This is happening because composer compartimentalizes, which means the "repository" is only known to your project's composer.json, the one in Repo A does not know, so it cannot find it. You must re-define the repository in that one. Even using Satis the "satis" address must be added to all composer.json files involved.
Add the "repository" stuff you added in your app to the composer.json in Repo A and B, it should work it all out.

I think this maybe sounds a bit similar to what you want to do, so I thought I'd post the link in case was helpful and you hadn't already seen it How do I use a Git submodule with a Composer loaded library?

You should use a .gitignore file containing something like that:
web/bundles/
app/cache/*
app/logs/*
app/sessions/*
build/
vendor
When developing you should launch php composer.phar update from time to time. When your work is validated, you should commit the composer.lock file with your development.
When deploying, you can then just launch php composer.phar install.

Related

How to manage github repository dependencies while and after contributing to them?

I'm using Symfony2 and for my projects I normally do composer require name/repository which will install the repository in the vendor folder and add a line in the composer.json including the package and the installed version.
Supposing that I fork a project because I want to add something to it or fix a bug and use it in my Symfony app, I'd have to run composer require myname/repository, modify it, test it and then submit a pull request. Afterwards, after the pull has been commit to the original repository, I'll have to delete my own and remove it from composer.json and reinstall the original repository.
Is there a better workflow to this that doesn't have to change the json file that much?

Suggestions on how to use version control and composer with symfony2

I'm already half way done with a project in Symfony2.
I need to install a couple of new vendor bundles using composer.
I already have everything (minus logs, cache and parameters.yml) in version control (including the vendor folder).
Problem is when using composer update, it deletes the .svn folders in the vendor folders that where updated. So it's basically impossible to commit now (gives me not a working copy error).
Additional information: I'm working locally and committing to a dev server and then once approved an application server. Therefore it has to be perfect (cannot just run php composer install or php composer update on the dev/application server after commit).
I also tried exporting everything and copying and pasting them back into the repo but that also didn't work (index page broke locally).
Regarding to vendor versioning the best way is not version vendors at all.
The only things you need to version are composer.json and composer.lock. This may cause a problem with vendors which doesn't have stable versions or with that for which you need not stable one (eg. master with particular commit).
As a solution you should create your own (private) vendor repository (let's say your own packagist). Composer has a tool for that, which is called Satis.
https://github.com/composer/satis
So my suggestion would be:
Create a private repository with Satis. You place every package you need in satis.json and whenever you need to update a version of vendor, or add new one, you only modify satis.json and rebuild repository.
In your project's composer.json you set your new private repository as the only repository and set option: packagist to false.
Now, every time you run composer install it will use only your private repository, so it's fast and you always sure that every environemnt has the same versions
-
I was in similar situation two years ago.
The hard lesson I learned was never to edit files within vendor. At first I totally rejected using composer and manually cloned everything I needed. Later on, I decided to fork projects I needed to edit and referenced my forks instead.
Composer supports private GitHub repos - you don't need to register it to Packagist in order to work.
You should not keep your vendor directory in your version control. This is how it is done in Symfony Standard Edition and you should follow this. Running composer install command should be a part of your deployment process
Including vendor packages in your codebase is not recommended, so if you need to maintain the same version of the packages you use on your local machine, the best way is to keep composer.lock in the VCS and running only composer install on other environments.
Additionally, if you want the prod deployment to be instant, without depending on the composer process, you could run composer install on the dev server, and once it's validated you can make your prod deployment script copy the vendor folder from the dev env.

Git Module Subtree Composer Best Pratice in Yii2

If I want to create a module inside the vendor folder, what are the git commands to create a subtree (or somehting else)?
Scenario:
I update the module
Push it to github
My colleague wants the update too, should he pull from github, or just update composer?
Then he has to make his own changes and push them too github
I tried some solutions but I felt like they where not the best, how does everybody else do this?
Scenario:
I want to override some view files from an existing module and create my own module for this (yes it has to be a module), extending from the original module
Do I need extra steps for this? And a separate composer package?
How can my colleague install this module and make some changes?
If you want the module to be accessible to everybody the easiest way to do this is to create a composer package for it. Then you just add it to the composer.json file and you can both use the package just by doing a composer update.
Remember to tie the git repository to packagist (through webhooks, when you create the packagist package you will see instructions), so each time you update git, an update to packagist will be available.
To push an update the module just browse to that particular path and do a commit / push to git like any other package.
If you do not want to create a packagist package, then you can always create a repository like this in composer.json Use PHP composer to clone git repo.

CakePHP and Composer installs -- how to use it for Plugin and Vendor dependencies for a CakePHP 2.x application

I am having some weird issues with git submodule update for a Plugin dependency with Jenkins # CloudBees.
So I am switching some, if not, all my dependencies from git submodule to Composer.
I came across this repo called composer installers. https://github.com/composer/installers
I was wondering how to use this for both Plugin and Vendor dependencies.
I am not familiar with Composer and even after reading the docs, I am uncertain how to say, place this dependency specifically to Plugin/xxx
I know how to do this with git submodule add.
So anyone knows how I should use Composer or better yet, Composer installers, please advise me.
To make things easier, I want to use 2 actual examples.
https://github.com/milesj/Utility is to be placed inside my app/Plugin/Utility
https://github.com/simkimsia/php-gd-simpleimage is to be placed inside my app/Vendor/SimpleImage
There is a Composer plugin for CakePHP that has a Backery article about it. The code is available on Github:
https://github.com/uzyn/cakephp-composer
It's actively being developed (last commit was yesterday), but in my early use of it (today), it seems to be working as expected.
Packagist has loads of Compose-ready libraries. Some of them are CakePHP related. Some are not.
The two examples you listed aren't in Packagist (yet?). Thankfully, Composer makes it possible to work directly with Git (and other VCS) repos. For the milesj/Utility plugin (which has a composer.json file), you'll need to follow the Repositories guide in the Composer docs to set things up properly.
For the php-gd-simpleimage repo, you'll need to write a composer.json file, then follow the Repositories steps.
One of the most confusing things about Composer is that composer.json is the same system/file-format for both libraries and "projects." Really, they're all the same to Composer. In your "project" repo, though, you're only outlining requirements (usually), not making your application installable via Composer. Regardless of their locations, both composer.json files are for the same thing: tracking and installing dependencies. You can imagine it as a tree with your project (and it's composer.json) at the top, and then a branching dependency tree all the way down.
Happy Composing!

What's the correct way for reusing bundles across different projects with Composer and git in Symfony 2?

I want to reuse a bundle, eg: Company/CommonBundle
So what I need to know is how to turn a bundle created with 'php app/console generate:bundle', into a vendor bundle, installable through Composer, and versioned with git.
There seems to be a convention for vendors names, eg: 'monolog/monolog/src/Monolog'. Is there a guide for that?
You can use satis for that. I have never used it myself but I have been told by Stof (himself!) that it is the way to go if you want to have some sort of private composer repository.
All right I figured this out
1) uninstall the newly created bundle and move it somewhere else
2) create a git or hg repository for it, commit and push
3) add the dependency to your project, in composer.json
4) run 'composer update nothing'
That's it. Composer downloaded the repository, so you can modify it as needed, commit/push and make it available to all your other projects by following 3) and 4). If the bundle is already installed, you update it like this: 'composer update mybundle'. Enjoy.
Now all I need to figure out is how to have the bundle auto-added to AppKernel.php, etc. If you find how to do this, please share it.

Categories