How can we easily update our own vendor in symfony? - php

I have a symfony project.
I have a bundle in my vendor directory. This bundle belongs to me. The bundle is hosted in our own server (git).
This bundle is constantly evolving.
My question is :
Is it possible to update this bundle inside my symfony project ?
I tried but I don't know how to push the updated code...
For the moment, I am obliged to import the bundle in a new project, do the update, commit and push, and finally do the "composer update" in symdony project.
It is a bit complicated.
Do you have another way to do that ?

I think you can do this with composer alone. You can specify your dependencies to come directly from a branch in your git repository. Example below uses github, but you should be able to use your git server instead:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/username/repository"
}
],
"require": {
"username/repository": "dev-branch_name"
}
}
Then you can just do your edits inside of the bundle's repository, commit, push, and just run composer update to pull your changes in to your current project.

Related

Is there a way to override the load method of a bundle in SF4?

I am trying to use Webonaute/DoctrineFixturesGeneratorBundle (a bundle for generating fixtures from database data via a symfony console command) on a Symfony 4.2 project. It is officially supported according to the README.md, but it doesn't work.
Command "doctrine:generate:fixture" is not defined.
After a search on Google, I discovered that I am not alone in having a problem with this bundle on SF 4.2 and I found a PR (opened for months) that solves the problem.
https://github.com/Webonaute/DoctrineFixturesGeneratorBundle/pull/57/files
I applied the patch directly into the vendor directory and it works. But, I would like to override the class without modify the vendor.
So, is there a way to do that?
Thank you!
I just had to add the repo in the composer.json file.
"repositories":
[
{
"type": "vcs",
"url": "https://github.com/PapyDanone/DoctrineFixturesGeneratorBundle.git"
}
],
Do not forget to authorize bundles in dev state.
"minimum-stability": "dev",
"prefer-stable": true
However, I had to fix other things on the project, to make the bundle compatible with Symfony 4. Then, I forked the repo of the person who submitted the pull request, corrected it and made a new pull request to the original repo.

Keep local and production composer.json files in sync?

I am working on a large project with a lot of git repositories. I can easily keep them in sync like this:
https://getcomposer.org/doc/05-repositories.md#path
"repositories": [
{ "type": "path", "url": "../another-component" },
{ "type": "path", "url": "../yet-another-component" }
]
If I run composer this will create a symbolic link inside my vendor folder for each repository provided. This way whenever I update one of the repositories outside my main app repository changes will be reflected immediately.
This is a perfect local development solution but on production I would just like to have a composer file that points to the online Github repositories and pull the repositories from Github.
Of course this composer file would look a bit different since the types would be set to vcs and the url's would point to Github instead of being relative paths.
How do people do this for local/production setups? Do you just maintain 2 separate composer files, one for local development and another for production?
This would mean whenever I add another repository to my codebase I have to remember to update it in 2 places or my entire codebase breaks down.
Since it seems your components are already hosted online, I would recommend to just let composer pull them down from Github and manage them like any other dependency, be it from development or production.

PHP Developing a composer package under vendor of the main project

I have a main php project that needs a php component developed by me, that i intend to reuse in other projects, the component is in the main project vendor directory.
However pushing to Github the component, go to the main project, running composer update is time consuming.
In order to speed up the development of the component, is there a way to include the local component project into the main project?
This is how I do local composer package development.
Create a vendor-repo folder next to the vendor folder.
Create a directory for the vendor and project name for example vendor-repo/vendorname/packagename
Create a git repo inside the packagename folder and build your composer package complete with composer.json etc.
Add your local repository to the main composer.json (the one that requires your package). You can also disable the packagist repo by adding the "packagist": false as per the example below. This will speed things up and is a good idea if you aren't using any packages from packagist.
"repositories": [
{
"type": "path",
"url": "vendor-repo/vendorname/packagename"
},
{
"packagist": false
}
]
Then when you run composer update it will get your package from your local repo rather than needing to get it from GitHub.
You can add the library directly inside your vendor folder, register the sources using the psr-0 or psr-4 autoload, dump the autoload classes and create a git repository inside the folder.
So you can use it as a library, and at the same time, you don't need to pull every update you do to test the library inside your project.
I don't know if it's a good approach, but symlinks didn't work for me and i still need to register the classes in the autoload.

Blocking a package install in PHP Composer to use a fork of the package

I am working with Behat and Composer for a project at work. I had to create a fork and patch for Mink and the Mink Selenium 2 driver to handle popup windows. Currently the patches are still being reviewed by those that manage the repos I forked. So in the mean time I would like to use my fork versions instead.
I have added my repositories to composer and they are being pulled in. However the "behat/mink" package is still being installed because the "behat/mink-extension" requires it. The thing is it can use my fork of it too. So I would like to have it pull in only mine and not the "behat/mink" package.
Can I do this? Can I block a package's required package in favor of my fork?
Thanks!
Yes, all you need to do is list your fork as a repository to use and Composer will automatically include the fork in preference to the original package. From the documentation
If you are using a certain library for your project and you decide to
change something in the library, you will want your project to use the
patched version. If the library is on GitHub (this is the case most of
the time), you can simply fork it there and push your changes to your
fork. After that you update the project's composer.json. All you have
to do is add your fork as a repository and update the version
constraint to point to your custom branch.
An example where someone has patched Monolog. They then tell Composer to use their repository.
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/igorw/monolog"
}
],
"require": {
"monolog/monolog": "dev-bugfix"
}
}
Composer will scan all the versions available in https://github.com/igorw/monolog and use them in preference to the version of Monolog available on Packagist.
You can also tell Composer to use local directories rather than an HTTP address.
"repositories": [
{
"type": "vcs",
"url": "/documents/project/igorw/monolog"
}
],
This allows you to develop library, use it in another project and test it without having to push to Github between each edit and test.
You cannot really block them. You might be able to disable the fetching of info from packagist.org, but this will affect all packages.
What you should do is add an alias for behat/mink. See the documentation of composer aliases.
Try to avoid branch aliases, use the inline alias.

Composer check local repository instead online repository like Maven

how to get composer http://getcomposer.org to work like maven in java. Instead of getting repository online, it can get from local repository. So, we don't have to download again.
I don't know Maven, but at least two options in composer's world come to my mind:
Access a local git repository
Let's say you want to use a local git repository of braincrafted's bootstrap bundle.
Add the following entry to your composer.json:
"repositories": [
{
"type": "vcs",
"url": "/home/user/braincrafted/bootstrap-bundle"
}
]
"require":{
"braincrafted/bootstrap-bundle":"dev-master"
}
Satis
Another alternative is Satis - makes you have your private packagist.com
It's explained in the documentation
This talk is worth watching to learn more about Composer, SAtis etc: https://www.youtube.com/watch?v=P3NwF8RV1lY

Categories