I am trying to integrate Agile CRM in my Symfony2 application.
There is a PHP library provided by Agile :
https://github.com/agilecrm/php-api
However it's not a bundle.
How can I integrate it correctly in my application? Should I put a require once in my app.php or my kernel? Or is there a better way?
Composer has a feature to auto load files
https://getcomposer.org/doc/04-schema.md#files
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
Other ways ?
Expose the functionality as a Service using the code provided in the library.
I think the best way to do this is to:
contribute to the project to add a composer.json
contribute to allow the configuration to be loaded from elsewhere instead of being hardcoded
Then you'll be abled to simply use composer to load that package. :)
Composer (as mentioned in other answers) is only a dependency manager and therefore only part of the solution. If you are really interested in the cleanest way, it is quite simple: write the bundle yourself.
In fact, there are many examples of bundles that work as integration layers for 3rd party libraries. For example, look at https://github.com/nelmio/alice, a Symfony2 bundle meant to wrap Faker, an external data fixture lib.
A bundle may declare configuration options overridable by the app main config files. It may expose service definitions for the library objects so that you can avoid to create them manually and inject them when needed (whether or not the library is written with DI in mind). It may be also useful for twig extensions, event listeners and so on.
A good written bundle promotes reuse, testability and separation of concern. Don't be scared from writing your bundle from scratch, start here http://symfony.com/doc/current/cookbook/bundles/best_practices.html
As agilecrm/php-api is not available on Packagist the best approach would be to add the repository to your composer.json file and then install the package the same way you would with everything else.
{
//...
"repositories": [
{
"type": "package",
"package": {
"name": "agilecrm/php-api",
"version": "2.1.0",
"source": {
"url": "https://github.com/agilecrm/php-api",
"type": "git",
"reference": "2.1.0"
}
}
}
],
"require": {
//...
"agilecrm/php-api": "2.1.0"
}
//...
}
You should add it to your composer.json
{
"require": {
"agilecrm/php-api": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#github.com:agilecrm/php-api.git"
}
]
}
or you can add it to composer autoloader https://getcomposer.org/doc/01-basic-usage.md#autoloading
Related
First of all, I know this setup is stupid but this is what we're stuck with 🤷♂️
We build websites with our company framework. The website contains some classes that the framework directly accesses. This means we have a circular dependency. This was not a problem until now.
These are slimmer versions of our composer.jsons:
Framework:
The framework just defines some other
{
"name": "company/framework",
"type": "library",
"require": {
...
}
}
Website:
{
"name": "company/website",
"require": {
"company/framework": "^4.3",
...
}
}
Very simple, framework is a dependency of website.
Now, I'm trying to setup a CI server with static analysis for the framework. As mentioned, the framework requires some files in the website for static analysis to succeed.
The new company/framework/composer.json file looks like this:
{
"name": "company/framework",
"type": "library",
"require": {
"company/website": "^4.3",
...
}
}
This works fine when testing a tagged framework version. Whenever we're in a develop branch Composer will fail since website requires a stable ^4.3 version of the framework but this is a develop branch.
Is there any way I can work around this?
Extract the classes that are needed to test the framework into a separate package.
Framework requires that package.
Website requires that package. And requires Framework (which also requires that package).
Voila, you transformed a circular dependency into a linear graph.
Add semantic versioning to this approach, and you will never have serious problems - or spot them pretty soon.
When I worked with Spring MVC in Java , it manage all dependency by Maven and I think with Laravel , all library are managed by Composer. (I'm not sure, cause I'm a newbie in Laravel ^^ )
Now, I have 2 laravel project, one common project and one sub project , in sub project how can I use common project through Composer management ?
As mentioned by Pitchinnate, you can include a local repository via Composer.
You'll want to reference the second repository that the first is dependant upon in the "repositories" section of your composer.json, and then require it.
Ex:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*#dev"
}
}
This should allow you to link your project and sub-project, if we've understood your question correctly.
Cheers!
I am working on several projects but each one connects to a REST web service.
I've developed the first one using Laravel, and developed a few classes really useful to communicate with the web services.
I would like to start the second one, and of course, reuse the classes developed for the REST connection.
My problem is, my company wants me to use several git directories for the projects, and each one should be uploaded to a different springloops project.
Springloops is a bit like github, you can upload your code using git.
How would you proceed to avoid copy/paste and use the same laravel code but in different projects (and I guess, in different locations)?
I'm not sure I'm really clear, but don't hesitate to ask me for more information if you need to.
Thanks.
How about creating your own Composer package and store it in a separate (private) Git repo? As far as Composer is concerned it's just like any other package, you may want to check out this section of the docs:
Using private repositories
Exactly the same solution allows you to work with your private
repositories at GitHub and BitBucket:
{
"require": {
"vendor/my-private-repo": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:vendor/my-private-repo.git"
}
]
}
The only requirement is the installation of SSH keys for a git client.
I've developed my own PHP framework which is used to power many different apps. At the moment, it uses Twig, Symfony YAML, Monolog and Facebook SDK as components. Now I need to create an admin section so those who update the content can login to a secure area, and very likely a user section, so their would be different roles too.
I like the look of Zend and Symfony's components and I have found many Stack Overflow questions related to it, but I was wondering:
If I use Symfony2's Security Component, how do I use it outside of the Symfony2 framework? This is very frustratingly missing from the Components Handbook, seeing as they've documented every other of their components.
If I use Zend_Auth and Zend_Acl, can I load them with Composer, without downloading the full stack? Or would I have to download it manually and extract the classes?
Do you recommend another package?
Found the solution. http://packages.zendframework.com/
Reason I didn't find this out earlier, Zend 2 uses it's own repository instead of Packagist.
Composer.json:
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
and
"require": {
"zendframework/zend-authentication": "2.0.*",
"zendframework/zend-permissions-acl": "2.0.*"
},
"minimum-stability": "beta"
Though I'm using "minimum-stability": "dev" for my project
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.