How can I link a composer lib to a local source? - php

The case is that I have a main project using a composer lib made by someone on my team, and I don't have write access in this lib repository, so any change done in this lib needs to be commited, pull requested and published to be updated in the main project (by composer update).
Is there some way to link this lib folder on my main project, to my locally forked source, so I can use my own changes skiping this whole proccess?
P.S. I can't change the source on composer.json. It would be good if we can overwrite some items in composer using like as composer-custom.json as we can do in the Vagrant settings.

Related

intellij: how to deploy to two folders?

The general question is: how to work with many different git repos at the same time in one intellij project. Where the git repos need to be inside the main application (that is one git repo too). I cannot use symlinks because I cannot commit those
I have 2 git repos
one is for the main app, the other one is for a library I am using in several projects.
Here is how it goes: I have the main app. Via composer I add my library / package to the application.
The problem:
folder structure:
to develop
IdeaProjects/myappA
note: there is are as well IdeaProjects myappB etc
IdeaProjects/mylib
in myappA there is
IdeaProjects/myappA/vendor/mylib
server deploy folder:
/var/www/www.myappA.com/
I do a lot of changes to the library, I have it open as another module when I work on myappA so I do code changes to mylib in that folder / module that actually contains the original source code of mylib. Now i don't want to composer install or update each time I do a tiny change. So what I do is I deploy via intellij the files from the library mylib each time on save directly into the composer install folder of my main application e.g. to IdeaProjects/myappA/vendor/mylib. Now the problem is, I need to deploy it as well to the server deployment folder. But there seems no way to deploy files to two folders out of the box with intellij.
What else can I do?
currently I manually use a short key to trigger an ant build that then copies the folder IdeaProjects/myappA/vendor/mylib to the server deployment directory.
There are multiple solutions depending on your setup:
solution inside intellij: just import mylib as a module inside your myapp project
Go to File > Project Settings > Modules, click the + and choose import module
git native solution: Use submodules
Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.
Note that there are some quirks when working with submodules, especially the way to keep the referenced submodules up-to-date
For completeness: if you were using gradle or maven instead of ant, you could use their respective projects views and use the + to add multiple build.gradle or pom.xml files, which would automatically import those projects as modules into intellij.
I think the module approach does fit your case and yes you can have a different git repo per module. Right click on your project root new->module or file->new module from existing source
Intellij should also detect every git repository automatically in your project if you check Settings | Version Control you should see the list.
You can also speed up some operations such as git pull instead of having to pull from every repository (VCS -> Git -> Pull) you can do VCS -> Update Project or ctrl-t (cmd-t on mac)

Laravel 5 setup git repo for multiple developers

I've done lot of Google but still looking for solution, I'm working on Laravel5 project & wants to set it up with GitHub so multiple developer can work on it.
I've install Laravel & place in a repository on Git, Now I cloned it on my local machine & another developer also clone that repository in his machine and start working.
But issue is that, I have installed a package for HTML forms in my machine by composer & push my code to github. But when another developer pull the repository then his code is break because composer.js is updated for that package but actually that HTML package is not exists on his machine.
Can anyone help me to short out this, or is there any way so we ignore vendor folder, composer.js, app.php etc files during git Push?
To answer your question specifically, yes you could choose to ignore the vendor folder, composer.json and app.php files when you push to git. To do this, you would simply need to update your .gitignore file to reflect this. I.e, include these in your .gitignore:
/vendor
composer.json
/config/app.php
But then the next question is whether you really want to do this, as doing so would mean that changes you make - and any subsequent pushes - may not be compatible with work the other developer is doing down the track.
If you exclude the /vendor file and the /config/app.php file but leave the composer.json file in there now that the other developer already has a copy of the core files, the updated composer.json file they download would allow them to use composer install to update the project with the new package.
However all of this would be problematic for a developer who joins you down the track and doesn't have any of the current files.

How can I contribute to a third-party Symfony bundle?

I'm trying to add a missing feature to a bundle. Here is what I've done so far:
Spoke to the project owner and got their approval
Created a fork and cloned it locally into a directory outside of my project
Made a feature branch
Ran composer install
Now, the question is, how can I include this into my own Symfony project so that it would be autoloaded? I want to test my changes inside my own project before I send a pull request.
See How to require a fork with composer, to be specific, require a VCS repository as described in Composer docs
Or a bit faster way for improving developing process (which is independent on Github), try using local repositories.
You can archive in two manner:
You can hack the vendor folder replacing the folder of the bundle with a symlink of the third-party bundle
[RECOMENDED] Put in the composer.json file of your project the reference of your personal github project instead of the official version

Using Composer packages in a FuelPHP app managed with GitHub

I have a web application that I built using FuelPHP which is hosted on a private GitHub repo.
I recently added JAXL and APNS-PHP to the project using Composer. Specifically, I created a composer.json inside of the fuel/app directory with these contents:
{
"require": {
"varavan/apns-php": "dev-master",
"abhinavsingh/jaxl": "3.*#dev"
}
}
I ran composer update and everything works fine on my local development environment. I can push to GitHub just fine from the command line also.
However, when I pull on the public server, the newly installed composer packages are not included in the pull, although their directories are created. Specifically, these directories exist, but are empty:
fuel/app/vendor/abhinavsingh/jaxl/
fuel/app/vendor/varavan/apns-php/
If I look at those directories on GitHub, they don't look like directories. They've got an icon that I don't recognize:
Also, if I click on "Sync Branch" from the GitHub GUI app, it gives me this message This has been resolved, see update below.
The submodule at 'fuel/app/vendor/abhinavsingh/jaxl' was removed from
.gitmodules, but the folder still exists in the repositroy. Delete the
folder, commit the change, then try again.
WHAT!?
I used composer to install JAXL, not Git.
If I run composer install on the server, it says:
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
But the JAXL and APNS-PHP directories are still empty.
How do I get the composer packages onto my production server?
Update
I added this to my .gitmodules file:
[submodule "fuel/app/vendor/abhinavsingh/jaxl"]
path = fuel/app/vendor/abhinavsingh/jaxl
url = git://github.com/abhinavsingh/JAXL.git
[submodule "fuel/app/vendor/varavan/apns-php"]
path = fuel/app/vendor/varavan/apns-php
url = git://github.com/varavan/ApnsPHP.git
That fixed the error that the GitHub GUI app was giving me, but I still can't figure out how to get the composer packages installed on the production server.
I continued to try everything I could think of to get the composer packages loaded, but I couldn't figure it out.
After adding the submodule definitions to my .gitmodules file, I deleted the entire project from the production server and re-cloned the whole thing from GitHub. The submodules came along for the ride.
It's not the composer way of doing things...
Whatever. What a waste of time.
Composer uses git, especially if you specify you want a development version. It will get it directly from the source.
And if you create a second vendor folder inside app, and Composer has added a git repository there (because of what you specified), git will detect a repo-in-repo, and since submodules are active for Fuel, it will assume you're adding a new submodule.
Like Martin Bean said, make sure you exclude the vendor folder, to prevent this from happening.

Download a repository in Github along with composer packages

Without using Composer, is it possible to download a repository in Github along with it's defined composer packages?
For example: FluxBB 2 requires Laravel 4.
I was hoping to download FluxBB and at the same time the packages of Laravel 4 without using Composer.
Usually projects that use composer will ignore 3rd party components. In .gitignore you will see /vendor. This is the place where Composer downloads its dependencies.
This will find the latest version of monolog/monolog that matches the supplied version constraint and download it into the vendor directory. It's a convention to put third party code into a directory named vendor. In case of monolog it will put it into vendor/monolog/monolog.
Tip: If you are using git for your project, you probably want to add vendor into your .gitignore. You really don't want to add all of that code to your repository.
http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies
Doing it manually is a bit of a hassle. Composer uses packagist to get its files (if you look at a package it has a source added to it Laravel https://packagist.org/packages/laravel/framework).
Composer auto loads the needed files automatically so its a big time saver.
For libraries that specify autoload information, Composer generates a vendor/autoload.php file. You can simply include this file and you will get autoloading for free.
require 'vendor/autoload.php';
This makes it really easy to use third party code. For example: If
your project depends on monolog, you can just start using classes from
it, and they will be autoloaded.
http://getcomposer.org/doc/01-basic-usage.md#autoloading

Categories