0

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

2
  • 1
    Shouldn't $external = new \Tinify(); be $external = new Tinify();? AFAIK the `` will only be used, if you're using native PHP classes. Commented May 19, 2016 at 7:15
  • Thanks, this pointed me to right direction Commented May 19, 2016 at 7:41

2 Answers 2

2

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();
Sign up to request clarification or add additional context in comments.

Comments

1

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();

1 Comment

when i only installed it via composer i got error stating that i don't have service named Tinify

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.