Bandwidth PHP SDK
  • Namespace
  • Class

Namespaces

  • Catapult
  • None

Classes

  • Catapult\Account
  • Catapult\AnswerCallEvent
  • Catapult\Application
  • Catapult\ApplicationCollection
  • Catapult\AudioMixin
  • Catapult\BaML
  • Catapult\BaMLAssert
  • Catapult\BaMLAttribute
  • Catapult\BaMLContainer
  • Catapult\BaMLGather
  • Catapult\BaMLGeneric
  • Catapult\BaMLHangup
  • Catapult\BaMLPlayAudio
  • Catapult\BaMLRedirect
  • Catapult\BaMLResource
  • Catapult\BaMLSendMessage
  • Catapult\BaMLSpeakSentence
  • Catapult\BaMLText
  • Catapult\BaMLTransfer
  • Catapult\BaMLVerb
  • Catapult\BaMLVerbGather
  • Catapult\BaMLVerbHangup
  • Catapult\BaMLVerbPlayAudio
  • Catapult\BaMLVerbRecord
  • Catapult\BaMLVerbRedirect
  • Catapult\BaMLVerbSendMessage
  • Catapult\BaMLVerbSpeakSentence
  • Catapult\BaMLVerbTransfer
  • Catapult\BaseResource
  • Catapult\BaseUtilities
  • Catapult\Bridge
  • Catapult\BridgeCollection
  • Catapult\Call
  • Catapult\Callback
  • Catapult\CallCollection
  • Catapult\CallCombo
  • Catapult\CallEvent
  • Catapult\CallEvents
  • Catapult\CallEventsCollection
  • Catapult\Cleaner
  • Catapult\Client
  • Catapult\ClientResource
  • Catapult\CollectionIterator
  • Catapult\CollectionObject
  • Catapult\CollectionSequence
  • Catapult\Conference
  • Catapult\ConferenceEventMixin
  • Catapult\ConferenceMember
  • Catapult\ConferenceMemberEvent
  • Catapult\ConferencePlaybackEvent
  • Catapult\Constructor
  • Catapult\Converter
  • Catapult\Credentials
  • Catapult\CredentialsUser
  • Catapult\DataPacket
  • Catapult\DataPacketCollection
  • Catapult\Date
  • Catapult\DependsObject
  • Catapult\DependsResource
  • Catapult\Domains
  • Catapult\DomainsCollection
  • Catapult\DTMF
  • Catapult\DtmfCallEvent
  • Catapult\Endpoints
  • Catapult\EndpointsCollection
  • Catapult\EndpointsCredentials
  • Catapult\EndpointsMulti
  • Catapult\EndpointsToken
  • Catapult\Ensure
  • Catapult\EnsureResource
  • Catapult\ErrorCallEvent
  • Catapult\Event
  • Catapult\EventAssert
  • Catapult\EventCollection
  • Catapult\EventResource
  • Catapult\EventType
  • Catapult\FileHandler
  • Catapult\Gather
  • Catapult\GatherCallEvent
  • Catapult\GatherCollection
  • Catapult\GenericResource
  • Catapult\HangupCallEvent
  • Catapult\Id
  • Catapult\IncomingCallEvent
  • Catapult\LoadsResource
  • Catapult\Locator
  • Catapult\Log
  • Catapult\Media
  • Catapult\MediaCollection
  • Catapult\MediaURL
  • Catapult\Message
  • Catapult\MessageCollection
  • Catapult\MessageEvent
  • Catapult\MessageMulti
  • Catapult\MetaResource
  • Catapult\Multi
  • Catapult\NumberInfo
  • Catapult\Page
  • Catapult\Parameters
  • Catapult\PathResource
  • Catapult\PhoneCombo
  • Catapult\PhoneNumber
  • Catapult\PhoneNumbers
  • Catapult\PhoneNumbersCollection
  • Catapult\PlaybackCallEvent
  • Catapult\PrototypeUtility
  • Catapult\Recording
  • Catapult\RecordingCallEvent
  • Catapult\RecordingCollection
  • Catapult\RejectCallEvent
  • Catapult\RemoveResource
  • Catapult\Resolver
  • Catapult\ResolverResource
  • Catapult\RESTClient
  • Catapult\SchemaResource
  • Catapult\Sentence
  • Catapult\SIP
  • Catapult\SIPRealm
  • Catapult\Size
  • Catapult\SpeakCallEvent
  • Catapult\StringifyResource
  • Catapult\SubfunctionObject
  • Catapult\SubFunctionResource
  • Catapult\TextMessage
  • Catapult\Timeout
  • Catapult\TimeoutCallEvent
  • Catapult\TitleUtility
  • Catapult\Transaction
  • Catapult\TransactionCollection
  • Catapult\Transcription
  • Catapult\TranscriptionCallEvent
  • Catapult\TranscriptionCollection
  • Catapult\Types
  • Catapult\URIResource
  • Catapult\UserError
  • Catapult\UserErrorCollection
  • Catapult\VerifyResource
  • Catapult\Voice
  • Catapult\XMLUtility
  • CatapultApiWarning

Interfaces

  • Catapult\API
  • Catapult\API_MODE
  • Catapult\BAML_SETTINGS
  • Catapult\BAML_VERBS
  • Catapult\BAML_XML_HANDLERS
  • Catapult\BAML_XML_METHODS
  • Catapult\BAML_XML_OPTIONS
  • Catapult\CALL_ERROR
  • Catapult\CALL_STATES
  • Catapult\CONFERENCE_MEMBER_STATES
  • Catapult\CONFERENCE_SPEAK_STATES
  • Catapult\CONFERENCE_STATES
  • Catapult\DEFAULTS
  • Catapult\EXCEPTIONS
  • Catapult\GATHER_REASONS
  • Catapult\GATHER_STATES
  • Catapult\MESSAGE_DIRECTIONS
  • Catapult\MESSAGE_STATES
  • Catapult\NUMBER_STATES
  • Catapult\PATHS
  • Catapult\PLAYBACK_STATES
  • Catapult\RECORDING_STATES
  • Catapult\RECORDING_STATUSES
  • Catapult\SPEAK_STATES
  • Catapult\TRANSCRIPTION_STATES
  • Catapult\WARNINGS

Exceptions

  • CatapultApiException

Functions

  • includeDir
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 
<?php

/**
 * Base of Catapult events. 
 * All functionality here should reference 
 * catapult models. For more information on Catapult's
 * events, https://catapult.inetwork.com/docs/callback-events/
 */
namespace Catapult;

/**
 * Primary event object. All events
 * should provide its basic
 * methods. Moreover be initialized
 * by it.  
 */
class Event {
    public function __construct($data=null) 
    {
      if (!(in_array($_SERVER['HTTP_METHOD'], array("GET", "POST"))))
        throw new \CatapultApiException("Catapult events only accept GET and POST");


      if ($data!=null) {// mocking tests only
       $data = Ensure::Input($data);
      } else {
        $data = Ensure::Input(json_decode(file_get_contents("php://input")));
      }

      return new EventType(
      new EventResource($this, $data)
      );

    }
    public function __call($function, $args) {
      return $this->model->$function($args);
    }
    public function __get($key) {
      return $this->model->$key;
    }
}


class EventAssert extends Event {

  public static $events = array(
    "CallEvent" => array(
      "incomingcall", 
      "answer", 
      "reject", 
      "timeout", 
      "error", 
      "speak", 
      "dtmf", 
      "recording", 
      "playback", 
      "transcription", 
      "hangup"
    ), 
    "AnswerCallEvent" => array(
      "answer"
    ), 
    "IncomingCallEvent" => array(
      "incomingcall"
    ),
    "ErrorCallEvent" => array(
      "error"
    ), 
    "PlaybackCallEvent" => array(
      "playback"
    ), 
    "SpeakCallEvent" => array(
      "speak"
    ), 
    "HangupCallEvent" => array(
      "hangup"
    ), 
    "RejectCallEvent" => array(
      "reject"
    ), 
    "MessageEvent" => array(
      "sms"
    ), 
    "GatherCallEvent" => array(
      "gather"
    ), 
    "DtmfCallEvent" => array(
      "dtmf"
    ), 
    "RecordingCallEvent" => array(
      "recording"
    ), 
    "TranscriptionCallEvent" => array(
      "transcription"
    ), 
    "ConferenceEvent" => array(
      "conference", 
      "conference-member", 
      "confeence-playback"
    ), 
    "ConferenceMemberEvent" => array(
      "conference-member",
      "conference-speak",
      "conference-playback"
    ), 
    "ConferenceMemberSpeakEvent" => array(
      "conference-speak"
    ), 
    "ConferenceMemberPlaybackEvent" => array(
      "conference-playback"
    )
  );

  /**
   * check if the right event
   * has been called this
   * is done by looking at 
   * what the keywords  have 
   * for this eventType
   */
  public static function check($class, $eventType) 
  {
    $class = preg_replace("/Catapult\\\/", "", get_class($class));

    /** does the event exist ? **/
    if (array_key_exists($class, self::$events)) {

      if (in_array($eventType, self::$events[$class])) {
        return true;
      }
    }

    return false;
  }
}

/**
 * A generic to handle all event types. Afterwards
 * it should initiate the type specified in datapacket
 * 
 * EventType($data) where data
 *
 * i.e
 * data:
 * {
 *    "eventType": "sms"   
 * }
 * makes MessageEvent
 * 
 */
class EventType extends Event {
    public function __construct($resource=NULL)
    { 
      /**
      * when we're called directly as 
      * a sub class we figure out our input first.

      * i.e
      * event = new Event;
      *
      * this is only when the user doesn't knows which
      * event should be triggered in his program.
      * or when multiple events lead to the same script
      *
      */
    }

    /**
    * TODO:
    * models provide stringify functionality
    * which resembles:
    *
    * CLASS(op1, op2, op3)
    *
    * --- event information should be included 
    */
    public function __toString()
    {
      return (string) $this->model;
    }


   /**
    * _init will register things
    * used by this event object
    *
    * @param proto: EnsuredInput. needs to be two arity
    * @param class: Intiated model class
    */
    public function _init($proto, $class = null) 
    {
      $this->active = false;
      $this->model = $class;
      $cons = $proto[0]->get(); 
      $args = $proto[1]->get();
      /** make sure our constraints match **/

      foreach ($cons as $k => $v) {
        /** 
         * one constraint does not match
         * when this happens we need
         * to revoke the event
         *
         * i.e
         * MessageEvent(array("direction" => "incoming"))
         *
         * should not accept outgoing
         */
        if (isset($args[$k]) 
           && $args[$k] !== $v) {
          return;
        }
      }

      /**
       * now that our constraints match
       * make sure 'eventType' is this classes
       * type. 
       */

      if (!($this->isInvoked($args))) {
        return;
      }

      /** set the variables **/

      foreach ($args as $k => $v) {
        $this->$k = $v;
      }

      /**
       * TODO move
       *
       * as of now model will not autmatically
       * be made.
       */
      //$this->model->id = $args['id'];
      //$this->model->get();
    }


    public function isInvoked($args)
    {
      if (EventAssert::check($this, $args['eventType'])) {
        $this->active = true;
      }

      return $this->active;
    } 


    /**
     * isActive/1 tells us if the event
     * is being used or not. This
     * will make all other events 
     * non functional
     */
    public function isActive()
    {
      return $this->active;
    }

    /**
     * calling the event should be
     * the same as using isActive/0, 
     * as a result: 
     *
     * answerCallEvent->isActive() = answerCallEvent
     */
    public function __invoke() {
      return $this->isActive();
    }

   /**
    * Event calls should be forwaded
    * to their models
    *
    * This will be identical to 
    * Call->create
    * where create is any function of the public API
    *
    * @param function: model function
    * @param args: args for function
    */  
    public function __call($function, $args)
    {
      /**
      * Handling will be done
      * by GenericResource
      */
      return $this->model->$function($args);
    }
    /**
    * Same for properties all should
    * be identical
    *
    * @param prop: property for object
    */
    public function __get($prop)
    {
      if (isset($this->$prop)) {
        return $this->$prop;
      }
      return $this->model->$prop;
    }
}
Bandwidth PHP SDK API documentation generated by ApiGen