Symfony - requiring dependencies in use by another dependency - php

So, i am using the aws symfony bundle (which uses guzzle. I see it in the sdk's composer.json and also files under the "vendor" directory). I want to use Guzzle directly in one of my services in my bundle. What is the best way that i should go about it?
(How does composer really work with regards to this?)

Composer Packages Custom Installer plugin will help you to achieve your target. You will need to fork Guzzle package and edit composer.json and add simple type attribute and CPCInstaller dependency.
...
"type": "vendor-package",
"require": {"Yourname/cpcinstaller" : "1.*"}
CPC Installer plugin is very easy to customize as you need. Best of luck

Related

composer inside other composer project

I have a composer project for which I need to create a custom plugin that will also use composer. Both the main project and the plugin use the same dependencies but in different versions. How should I resolve these dependencies between each other? So that the plugin uses a dependency from its composer vendor and not from the vendor of the main project?
I found for example this solution: https://github.com/TypistTech/imposter-plugin but it doesn't seem very elegant to me.
Compare as well with another recent Q&A Dependency Conflict between Plugin and Theme which should add more general clarification.
As you normally use Composer to resolve dependencies you could also use it here. However there seems to be a little misconception or at least some lack of clarity in your question:
So that the plugin uses a dependency from its composer vendor and not from the vendor of the main project?
In a compoer project, there is only one vendor folder, the one of the root project, the one you likely meant by "main project".
This paired with the description of only a "Project" and a "Plugin" there might be a slight chance that it is either one project which has its dependencies managed by Composer ("Project") of which one dependency is the "Plugin".
Or you have just two independent projects ("Project" and "Plugin") that can work independent to each other (normally not the case for "Plugin" material).
At the end of the day it is less a question of Composer, but just whether your software projects dependencies can resolve or not in a compatible manner.
As PHP has a global namespace and it is static, if you really have incompatible dependencies across the same software packages, you need to fork these and rename the namespace so that you can have one dependency for your module A and one for module B. So next to your a "Project" and a "Plugin" you also have projects you manage the dependency packages in, e.g. rewriting Namespaces and then offering to composer via a repository.

Installing Intervention Image without composer

I would like to test Intervention Image. It looks like a nice package. The installation instructions say:
The best way to install Intervention Image is quickly and easily with
Composer.
The sentence above implies there's also a inferior, slower and difficult, way to install it. I assume the author is referring to an installation without Composer? That is exactly what I am looking for!
However, I am unable to find a way to do that. I have looked for an autoloader file, or even any autoload call in the code. There's none. No documentation either. It seems that only an installation with Composer is supported in a meaningful way.
Has anybody of you tried to use Intervention Image without resorting to Composer?
The way without composer is simply to fetch the source from github, move it in one off your vendor directories and load all needed files.
As there's no autoload file provided inside the package, you have to extend your own autoload script or register a new autoload handler, as including each required file is a really annyoing task.
If you take a deeper look inside the composer.json file, you may notice inside the require section, that this package also need Guzzle. If you want to install Guzzle, you will again read the sentence "The recommended way to install Guzzle is through Composer". So you have to do the same thing again for Guzzle. This time you need the other two Guzzle dependencies psr7 and promises....
At this point, I hope you build your autoloader robust enough to simply add only a new mapping from namespace prefix to path, as their might be many other required packages.
If you don't want to include composer directly inside your project, for what reasons ever, you could also create a empty composer project, just for managing the dependencies and the autoloader. That might be easier to do everything by hand.
Note: If you are lucky, you could use the Intervention/Image package
without the guzzle dependency.

Project using git put the library/framework in the repository or not?

I'd like to know what's the best practice
using git for a project using external
library/modules/framework.
Put the case I deploy a project with zend 2
and some modules for instance ZfcUser and BjyAuthorize
should I put it in the repository or not ?
When a developer clone the project get the framework
and modules or not ?
Thanks in advance.
In the case you're using composer to manage your project dependencies, no need to push ZF2, ZfcUser and BjyAuthorize. Just add your composer.json package descriptor and ignore your vendor folder to push your project.
If you're managing dependencies by yourself, i think it can be useful to push all your libraries. (that's how i did for many ZF1 projects where i had embedded some libraries).
I strongly urge you to use composer or any tool like it as you don't have to worry anymore about framework / libraries updates.
If the framework exists as a git repository I would consider using git submodule add yourFramework which will put a reference to the framework in your repository that others can download.
The overhead associated with adding some frameworks to a repository is probably trivial seeing as that code shouldn't get touched. It might just be easier for you to add the framework into the repository to reduce the work that other developers would have to do in order to start working.

Using Composer when multiple components are in the same vcs repo

I have a git repo that contains a few small and related libraries. Since the platform I am working with lacks proper dependency management, dealing with many git repos is a hassle, hence my team decided to put these into one git repo. I'm now working on having our software being installable via Composer. It is however not clear to me how to register each component in this git repo, as I'm not even sure it is possible to have more then one composer.json file per repo. Is this possible? And if so, how?
"is it possible to have more then one composer.json file per repo."
No.
You can't register the components separately, they will be registered as one big dependency and you will have to import them all into other projects, rather than being able to pull them individually.
However you can register where each component lives in the directory structure so that the autoloader is able to load them correctly.
"autoload": {
"psr-0": {
"Intahwebz\\Component1": "src/Component1",
"Intahwebz\\Component2": "src/Intahwebz/Component2",
"Intahwebz": "src/"
}
}
After including the Composer generated autoloader, creating a new class of type Intahwebz\Component1\TestClass will find it in the correct directory.

How to give third party libraries in composer.json in Symfony 2.1 and access library in our bundle?

I need to integrate TCPDF as third party library in Symfony 2.1.
I tried in composer.json like
"repositories": [
{
"type": "vcs",
"url": "git://tcpdf.git.sourceforge.net/gitroot/tcpdf/tcpdf"
}
],
"require": {
"tcpdf/tcpdf":"*"
},
But it gives an error The requested package tcpdf * could not be found.
How to give third party libraries correct in composer.json file?
TCPDF library don't follow namespaces, so how we can access this library in our bundle?
The reason it's not found is that the package name in the tcpdf repo is tecnick.com/tcpdf, so that's what you should require.
That said, since it's available on packagist you don't need to add the vcs repository at all in your composer.json.
There are several packages related to TCPDF on Packagist — some of them are bundles to integrate it with Symfony.
Since tcpdf does not support composer you need to use the package repository. The docs for this is available at:
http://getcomposer.org/doc/05-repositories.md#package-2
Do note that their example configuration has both dist and source where source is what you need. You will probably also need to configure the autoloading to match that of tcpdf. You can find documentation on that on the composer website as well.
A good thing would also be to send the tcpdf authors an email and ask them if they don't mind adding a composer.json.

Categories