Vinit Dave
Vinit Dave

Reputation: 21

TaskRouter in twilio-php library for Symfony3

I am using Symfony3 for building a Twilio TaskRouter based application which is using the twilio-php library.

All the other components in Symfony use the PS-0 or PS-4 naming convention while the standard twilio-php library does not use the same, thus I am not directly able to use certain classes(in my case taskrouter) .

The class in question is Services_Twilio_TaskRouter_Worker_Capability which resides in twilio-php/sdk/Services/CapabilityTaskRouter.php.

Symfony expects the class to be in the directory vendor/twilio/sdk/Services/Twilio/TaskRouter/Worker/Capability directory, which it fails to find.

Is there a way to include vendor/twilio/sdk/Services/CapabilityTaskRouter.php in a symfony class and extend the Services_Twilio_TaskRouter_Worker_Capability class?

Upvotes: 1

Views: 176

Answers (3)

Justin Witz
Justin Witz

Reputation: 76

Twilio employee here.

I went down the route of implementing a helper extension to https://github.com/fridolin-koch/VreshTwilioBundle and in that process discovered this was really a twilio-php helper library problem due to the naming conventions and the autoloading of these particular classes.

I intend to finish up the helper extension to VreshTwilioBundle, however, this is the PR that I have submitted that should keep you moving forward:

https://github.com/twilio/twilio-php/pull/288

Upvotes: 0

Sofien Benrhouma
Sofien Benrhouma

Reputation: 406

You can install the lib in the vendor by running:

composer require twilio/sdk

and composer will add the lib to the vendor folder and in you controller you will be able to call it like :

$sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account
$token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account

$client = new Services_Twilio($sid, $token);
$message = $client->account->messages->sendMessage(
  '9991231234', // From a valid Twilio number
  '8881231234', // Text this number
  "Hello monkey!"
);

print_r($message->sid);

Upvotes: 1

Bonscho
Bonscho

Reputation: 133

In my opinion it is possible. To keep the include logic separated from your project code, you should create a wrapper class that follows PSR-4 naming conventions, that simply extends the Twilio class.

<?php

    namespace MyProject\Service;

    require_once('path/to/twilio-php/sdk/Services/CapabilityTaskRouter.php');

    class CapabilityTaskRouter extends \Services_Twilio_TaskRouter_Worker_Capability
    {
    }

This is the way, we did a lot of times to integrate libraries not following PSR auloading concepts into our projects.

Upvotes: 0

Related Questions