Answer the question
In order to leave comments, you need to log in
How to connect a third-party library to Symfony 2?
Hello, dear IT-specialists.
The project needs to include a third-party library, which is essentially just one file with a class. Not a bundle, just a library.
We have Symfony with composer .
After a long googling, I did the following:
1. I tried to fit the class to the PSR-0
standard
2. I added a file with composer.json
3. I uploaded it to github ( https://github.com/musaev-haybulla/FloydWarshall)
4. I uploaded it to packagist ( https://packagist.org/packages/musaevhs/floyd-warshall)
5. Attached it to the project with the composer require "musaevhs/floyd-warshall:dev-master" command .
6. I try to call in the service like this:
use Musaevhs;
class RoutePlanService
{
/**
* @param RoutePlan $routePlan
* @return array
*/
public function minRoute(RoutePlan $routePlan)
{
$fl = new \FloydWarshall([0 => [1], [1] => [0]]);
}
}
, but in my class this is set. Answer the question
In order to leave comments, you need to log in
The file should be /Musaevhs/FloydWarshall.php
In composer /src/Musaevhs/FloydWarshall.php is equivalent to Musaevhs\FloydWarshall
With your
"psr-0": { "FloydWarshall": "src/" }
would be
use FloydWarshall\Musaevhs \Floyd Warshall; (With folder added)
use FloydWarshall\FloydWarshall; (If you remove the namespace in the file)
use Musaevhs\FloydWarshall; (If you remove FloydWarshall in composer)
use FloydWarshall; (If namespace and FloydWarshall are in composer)
"psr-0": { "": "src/FloydWarshall" } - (In theory it won't work)
В общем измените структуру
src/
Musaevhs/ <-- добавив папку
FloydWarshall.php
composer
"psr-0": { "": "src/" }
И подключение либы
use Musaevhs\FloydWarshall;
And what for such complexities for the sake of one file with a class? I see no reason to upload someone else's library to packagist. Just put it in your bundle, assign namespaces to it, make a service if necessary, and that's it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question