Symfony2: how to integrate php library that is not a package
I am trying to integrate Agile CRM into a Symfony2 application.
There is a PHP library provided by Agile: https://github.com/agilecrm/php-api
However, this is not a package.
How can I integrate it correctly into my application? Should I put the request once in my app.php or my core? Or is there a better way?
source to share
Composer has automatic file upload feature
https://getcomposer.org/doc/04-schema.md#files
{
"autoload": {
"files": ["src/MyLibrary/functions.php"]
}
}
Other methods?
Expose the functionality of the Service using the code provided in the library.
source to share
Composer (as mentioned in other answers) is only a dependency manager and therefore only part of the solution. If you're really interested in the cleanest way, it's pretty simple: write the kit itself.
In fact, there are many sample packages that act as integration layers for third party libraries. For example, take a look at https://github.com/nelmio/alice , a Symfony2 package designed to port Faker, an external data library lib.
A package can declare configuration options that are overridden by the application's main configuration files. It can call service definitions on library objects, so you can avoid manually creating them and injecting them as needed (regardless of whether the library is written with DI in mind). It can also be useful for twig extensions, event listeners, etc.
A good writing package promotes reuse, testability, and separation of concerns. Feel free to write your bundle from scratch, start here http://symfony.com/doc/current/cookbook/bundles/best_practices.html
source to share
You have to 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
source to share
Since agilecrm/php-api
not available in Packagist , the best approach would be to add the repository to your composer.json file, and then install the package just like 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"
}
//...
}
source to share