0

Bundle Name : Open tok ( i downloaded it from github )

i put that folder in Vendor Folder of Symfony( project name\vendor\OpenTok\OpenTok\and all files and folders here )

in AppKernel.php

<?php

 use Symfony\Component\HttpKernel\Kernel;
 use Symfony\Component\Config\Loader\LoaderInterface;

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
        $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new OpenTokBundle\OpenTokBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AdminBundle\AdminBundle(),
        new SiteBundle\SiteBundle(),
        new WSBundle\WSBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
   }

  public function registerContainerConfiguration(LoaderInterface $loader)
  {
      $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
   }
}

in app\autoload.php

 <?php

  use Doctrine\Common\Annotations\AnnotationRegistry;
  use Composer\Autoload\ClassLoader;
  /**
  * @var ClassLoader $loader
  */
  $loader = require __DIR__.'/../vendor/autoload.php';
  AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
  $loader->add('OpenTok' , __DIR__.'/..vendor/OpenTok');
  return $loader;

 ?>

Composer.json

  "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0", 
       "opentok/opentok": "dev-master"
   },

This above code gives me error :

Fatal error: Class 'OpenTokBundle\OpenTokBundle' not found

now how can i use opentok Bundle in my all other files ? Please help me. I am new to symfony

Lucas Huang
  • 3,998
  • 3
  • 20
  • 29
Aaska Patel
  • 460
  • 6
  • 21

2 Answers2

1

Your issue is due to the slash.
It should be $loader->add('OpenTok' => __DIR__.'/../vendor/OpenTok'); as in the other line (although I'm not sure the actual path would be correct).

That being said you should actually download and manage the package using composer as it has dependencies that won't be included by just downloading the repository.

To do this:

  1. Delete the $loader->add('OpenTok' => __DIR__.'/..vendor/OpenTok'); line from your autoload
  2. Add "opentok/opentok": "^2.3.2" or the version you want to download to your "require" key in your composer.json
  3. Run composer update opentok/opentok.

The package and classes should now be available in your application and, when you require a newer version, you can manage it all through composer rather than needing to download the package by hand (along with all dependencies).

qooplmao
  • 17,622
  • 2
  • 44
  • 69
  • Sorry sir, but i m new to symfony , i can't get understand 2nd and 3rd points – Aaska Patel Jul 06 '16 at 11:16
  • Pls see my Edits in question – Aaska Patel Jul 06 '16 at 11:18
  • You already have `opentok/opentok` in your composer.json. Do you have composer on your machine? If not, open terminal, go to the root directory of your Symfony application and install it (see https://getcomposer.org/download/). Then in terminal run `php composer.phar update opentok/opentok`. For more info on composer see https://getcomposer.org/doc/01-basic-usage.md – qooplmao Jul 06 '16 at 11:24
  • Update through **composer update opentok/opentok** but still getting error `Fatal error: Class 'OpenTokBundle\OpenTokBundle' not found in C:\wamp\www\lemon_garden_opentok\app\AppKernel.php on line 16` – Aaska Patel Jul 06 '16 at 12:01
  • Oh god. I just saw that. `opentok` isn't a bundle so it has no `OpenTokBundle` class. You can just use the classes in your app like normal, as stated here - https://github.com/opentok/OpenTok-PHP-SDK#initializing – qooplmao Jul 06 '16 at 12:48
  • to use this "OpenTok-PHP-SDK" i have to install it ? how can i install it and use – Aaska Patel Jul 07 '16 at 04:41
  • Delete the `project name\vendor\OpenTok` directory as it's not managed by composer so it will confuse things. Install it using the instruction on that page. Once that is done composer will create the autoloader so that you can use the class anywhere like `$openTok = new \OpenTok\OpenTok($apiKey, $apiSecret); ... etc`. Essentially just follow the instructions here - https://github.com/opentok/OpenTok-PHP-SDK#composer-recommended . – qooplmao Jul 07 '16 at 07:14
  • Thank You So much **#qooplmao sir** . it works now . i created Session . Thanks , Thank You so much....!!! :-) – Aaska Patel Jul 07 '16 at 10:22
1

I think you should manage all using composer, and you need to install the library opentok/opentok and the bundle for symfony joos/open-tok-bundle so in your composer.json...

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.8.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "joos/open-tok-bundle": "2.3.x-dev", 
    "opentok/opentok": "dev-master"
   },

Run composer install

And in your AppKernel.php

<?php

 use Symfony\Component\HttpKernel\Kernel;
 use Symfony\Component\Config\Loader\LoaderInterface;

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
        $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Joos\OpenTokBundle\JoosOpenTokBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AdminBundle\AdminBundle(),
        new SiteBundle\SiteBundle(),
        new WSBundle\WSBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
   }

  public function registerContainerConfiguration(LoaderInterface $loader)
  {
      $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
   }
}

From this url https://github.com/djoos/JoosOpenTokBundle

Edu
  • 2,520
  • 1
  • 15
  • 15
  • You mean to say that , i install opentok through composer and then i have to create bundle for joosopentok? can you explain me all steps please . – Aaska Patel Jul 07 '16 at 04:40
  • hey i changed as per your feedback , composer.json ,appkernel.php and Config.yml `joos_open_tok: class: OpenTok key: "4578792" secret: "0ec08800000001f4711011db0e9e72f9ac93"` i use it, `public function indexAction() { $open_tok = $this->get('joos_open_tok'); var_dump($open_tok); return array("response"=>"W"); }` give me error : `Fatal error: Class 'OpenTok' not found` ,`Attempted to load class "OpenTok" from the global namespace. Did you forget a "use" statement for "OpenTok\OpenTok"?` – Aaska Patel Jul 07 '16 at 05:30
  • What is the result of executing this command from your symfony installation: **php app/console container:debug** ? Is the service joos_open_tok in the list? – Edu Jul 07 '16 at 09:21
  • Can you Mark the answer as accepted so other People getting here get the solution, Thanks you – Edu Jul 07 '16 at 16:47