Viszman
Viszman

Reputation: 1398

Symfony2.7, adding 3rd party lib to project

I'm stuck, i wanted to load external library to my symfony2 project but got error stating that class was not found my app/autoloader.php:

...
$loader->add('Tinify', __DIR__.'/../vendor/tinify/tinify/lib');
...

and my file where i want to use it looks like it:

<?php

namespace XYZ\NewsBundle\Controller;
...

use Tinify;

class NewsController extends Controller{
...
public function displayAction($slug)
{
    $em = $this->getDoctrine()->getManager();

    $external = new \Tinify();
}

error is as follow The autoloader expected class "Tinify" to be defined in file "xyz/app/../vendor/tinify/tinify/lib\Tinify.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

but file under vendor\tinify\tinify\lib\Tinify.php

namespace Tinify;

const VERSION = "1.3.0";

class Tinify {
...
}

i checked if it really has typo but don't see one

Upvotes: 0

Views: 64

Answers (2)

Jose M. Gonz&#225;lez
Jose M. Gonz&#225;lez

Reputation: 14990

Why don't install Tinyfy throught Composer?

composer require tinify/tinify

In this way composer handles de autoload of the library, you don't need to load manually nothing, you only must to make an instance of the class and run

$tinify = new Tinify();

Upvotes: 1

Jakub Matczak
Jakub Matczak

Reputation: 15656

Full qualified class name of Tinify is not Tinify but \Tinify\Tinify. Its namespace + classname.

In you NewsController class you should do:

use \Tinify\Tinify;

Also note the backslash at the beginning of the namespace.

Then in the code you should use just class name and not namespace so also change this:

$external = new \Tinify();

to this:

$external = new Tinify();

Upvotes: 2

Related Questions