2

I am working on a Symfony 2.2 Project in which I need to upload video to Vimeo. I am using advanced Vimeo API via the Vimeo.php (official library of Vimeo)

I managed to add a namespace to the library and added it to the entity folder in my bundle because that is the only way the project was detecting the library.

<?php
**namespace MediaBundle\Entity;**

use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException as Exception;

class Vimeo
{
    .... Vimeo.php Code ....
}
?>

I am trying to find a better way to integrate this library in my code. I have tried to place in the vendor/vimeo folder and autoload it from app/autoload.php

Without Namespace:

$loader->registerPrefixes(array(
    'Vimeo_' => __DIR__.'/../vendor/vimeo/lib',
));

With Namespace:

$loader->registerNamespaces(array(
    'Vimeo' => __DIR__.'/../vendor/vimeo/lib',
));

The class is still not recognized in the controller.

To automate the process I tried using a composer package dukt/vimeo, it is basically the same library just wrapper into composer. It places it in the autoload_namespaces.php, but I am still unable to use it in any controller. It is always not found.

Perhaps I am not putting the correct use statement. The autoload_namespaces.php code is:

'Dukt\\Vimeo' => $vendorDir . '/dukt/vimeo/src/',

There is a Vimeo.php class in /dukt/vimeo/src with namespace Dukt;. What should be my use statement in the controller?

Please let me know what is the best way to integrate a 3rd party library into my Symfony2 projects. I would continue using it via entity, but I am getting some errors, I think the API is not working properly from entity due to come callback path errors. I could be wrong though. None the less I'd like to properly include it.

Ajeet Varma
  • 726
  • 4
  • 20

1 Answers1

2

Install the wrapper package via Composer. It will handle all the autoloading stuff.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • Thanks for your reply. I have already tried to install the package. It even installs fine, adds to the autoload_namespaces.php file, but the use statement still cannot find the class I need. Please read the second half of the question for details on this. Thanks again. – Ajeet Varma Mar 26 '13 at 11:52
  • Since the library is not namespaced then a 'use' statement won't be much, well, use. Instead, prefix the class name with a back slash. Something like: $vimeo = new \phpVimeo(); – Cerad Mar 26 '13 at 14:29
  • The class name in the package has been changed from phpVimeo to Vimeo and it seems to be namespaced with Dukt; So I have tried \Dukt(), \Dukt\Vimeo(), \Vimeo() and nothing seems to work. I don't know why including a simple library is causing so much trouble. Please let me know if you have any other ideas. Thanks! – Ajeet Varma Mar 28 '13 at 06:09