filipajdacic / yii2-twilio

This component is YII2 wrapper for Twilio PHP SDK.
1 stars 5 forks source link

Problems to find the class #2

Open eduardo-g-silva opened 7 years ago

eduardo-g-silva commented 7 years ago

Hi there,

I found some problems when you try to instanciate the twillio classs

Error

Class 'Twilio\Rest\Client' not found

here is how i fix it:

<?php

namespace filipajdacic\yiitwilio;

use yii\base\Component;
use \Services_Twilio;

/**
 * YiiTwilio class
 * @author Filip Ajdacic <ajdasoft@gmail.com>
 * @license MIT
 * @version 1.0
 * @copyright (C) 2016 Filip Ajdacic <ajdasoft@gmail.com>
 * @see http://github.com/filipajdacic
 * */

class YiiTwilio extends Component
{

    /**
     * The internal Twilio object.
     *
     * @var object Twilio
     */
    private $twilioClass;

    /**
     ** @var string $account_sid -> Twilio Account ID
     */
    public $account_sid;

    /**
     ** @var string $auth_key -> Twilio Authorization Key
     */

    public $auth_key;

    /**
     * init() called by yii.
     */

    public function init()
    {   
          try {
                $this->twilioClass = new Services_Twilio($this->account_sid, $this->auth_key);
          } catch (Exception $e) {
                throw $e;
          }  
    }

    public function initTwilio() {
        return $this->twilioClass;
    }

    /**
     * Use magic PHP function __call to route function calls to the Twilio class.
     * Look into the Twilio class for possible functions.
     *
     * @param string $methodName Method name from Twilio class
     * @param array $methodParams Parameters pass to method
     * @return mixed
     */

    public function __call($methodName, $methodParams)
    {
        if (method_exists($this->twilioClass, $methodName)) {
            return call_user_func_array(array($this->twilioClass, $methodName), $methodParams);
        } else {
            return parent::__call($methodName, $methodParams);
        }
    }

}
arturodr commented 7 years ago

I fixed the same problem installing the twillio SDK: composer require twilio/sdk

paramessanjay commented 6 years ago

Class filipajdacic\yiitwilio\YiiTwilio does not exist

error occurs any one have solution for it?

rossaddison commented 6 years ago

I experienced the same error. Reflection exception. I am using the yii2 advanced template and had to restructure directories to work online. Worked fine on my wampserver but not online.

Solution: File: vendor\filipajdacic\YiiTwilio.php

Add vendor to namespace:

was: namespace filipajdacic\yiitwilio; now: namespace vendor\filipajdacic\yiitwilio;

File: frontend\config\main.php

Include vendor in class.

was:

'Yii2Twilio' => [ 'class' => 'filipajdacic\yiitwilio\YiiTwilio', 'account_sid' => '***', 'auth_key' => '**',
],

now:

'Yii2Twilio' => [ 'class' => 'vendor\filipajdacic\yiitwilio\YiiTwilio', 'account_sid' => '***', 'auth_key' => '**',

I did not have to change my bootstrap.php under common/config directory nor alter my autoload namespaces.

Receiving trial texts via Twilio at last!

To avoid SSL problems on my wampserver and apache setup: I had to add: CURLOPT_SSL_VERIFYPEER => false,

to the ....\vendor\twilio\sdk\Twilio\Http\Curlclient.php

Solution:

        CURLOPT_URL => $url,
        CURLOPT_HEADER => true,
        CURLOPT_RETURNTRANSFER => true,

         //added here
        CURLOPT_SSL_VERIFYPEER => false,

        CURLOPT_INFILESIZE => Null,
        CURLOPT_HTTPHEADER => array(),
        CURLOPT_TIMEOUT => $timeout,

Don't forget to take this line out once you are up and running.