Question

I want to implement yelp API in my new project.Downloaded their library and sample code.But this library is very old, uploaded 3 year back.I don't know how to include it in symfony2.3.Can anyone tell me that how to include this type of files in symfony2.3 projects.

Was it helpful?

Solution

I think you can define it as services like this:

First of all include the Api inside your bundle, for example in:

Acme/YourBundle/Yelp/

But you will have to seperate the classes in individual files:

Acme/YourBundle/Yelp/OAuthToken.php
Acme/YourBundle/Yelp/OAuthConsumer.php
Acme/YourBundle/Yelp/OAuthSignatureMethod_HMAC_SHA1.php
Acme/YourBundle/Yelp/OAuthRequest.php

And add a namespace to each:

namespace Acme\YourBundle\Yelp;

class OAuthToken {
    ...

Then define the keys in your app/config/parameter.yml:

parameters:
    yelp_token: "..."
    yelp_token_secret: "..."
    consumer_key: "..."
    consumer_secret: "..."

Now the services in app/config/config.yml

services:
    yelp_token:
        class: Acme\YourBundle\Yelp\OAuthToken
        arguments: [%yelp_token%, %yelp_token_secret%]
    yelp_consumer:
        class: Acme\YourBundle\Yelp\OAuthConsumer
        arguments: [%consumer_key%, %consumer_secret%]
    yelp_signature_method:
        class: Acme\YourBundle\Yelp\OAuthSignatureMethod_HMAC_SHA1
    yelp_oauthrequest:
        class: Acme\YourBundle\Yelp\OAuthRequest

And in your controllers you can access the classes like this:

$yelp_token = $this->container->get('yelp_token');

I don't think this is a copy/paste solution but it might guide you in the right direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top