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 
<?php
namespace Catapult;

final class XMLUtility extends BaseUtilities {

    /**
     * Basic options for
     * XML utility. XML
     * document encoding 
     * and other options
     * should be set from setOption/1
     */
    public static $options = array(
        "header" => '<?xml version="1.0" encoding="UTF-8"?>',
        "encoding" => "UTF-8"
    );

    /**
     * Takes a struct of 
     * one dimensional XML
     * elements and makes
     * them a BaML tree
     *
     * Provided object must
     * have its validating method available
     * @param XML struct
     * @returns BaMLResource
     */
    public function Make(&$baml, $values=null) {
        $stack = array();
        $elements = array();

        if ($values)
            $baml->values = $values;
        foreach ($baml->values as $el) {
          $idx = count($elements);
           if ($el['type'] == "complete" || $el['type'] == "open") {
             $bobj = $baml->register($el);
             $elements[$idx] = $bobj;

             if ($el['type'] == "open") {
               $stack[count($stack)] = &$elements;
               $texts[$bobj->level] = &$elements[$idx]->text;
               $elements = &$elements[$idx]->verbs;
              }
            }
            if ($el['type'] == 'cdata') {
              $texts[$el['level']] .= trim($el['value']);
            }
            if ($el['type'] == "close") {
              $elements = &$stack[count($stack) - 1];
              unset($stack[count($stack) - 1]);
            }
        }

        unset($baml->values);

        $baml->data = $elements;

        return $elements;
    }

    /**
     * make without baML
     * schema. Really just used for tests
     *
     */
    public function MakePred($xml) {
      $baml = new BaML;
      $baml->values = $xml;

      self::make($baml);
    }

    /**
     * Default header for baML
     * will set encoding based
     * on XMLUtility static class
     *
     * render using the default encoding
     */
    public static function getHeader() {
      return self::$options['header']; 
    }

    /**
     * default open
     * for baML verb
     * 
     */
    public static function open($tag, $baml=false) {
      if ($baml && !in_array($tag, BaMLVerb::$valid)) {
        throw new \CatapultApiException("This is not a valid baML verb");
      }

      return "<$tag";
    }

    /**
     * a full open tag
     * for the BaML document
     * optionally checks if its valid
     */
    public static function fullOpen($tag, $baml=false) {
      if ($baml && !in_array($tag, BaMLVerb::$valid)) {
        throw new \CatapultApiException("This is not a valid baML verb");
      }

      return "<$tag>";
    }

    /**
     * a close tag
     * for the BaML document
     * optionally checks if its valid
     */
    public static function close($tag, $baml=false) {
      return "</$tag>";
    }

    /** 
     * a full close tag
     * for BaML
     * optionally checks if its valid
     */
    public static function fullClose($tag, $baml=false) {
      return "</$tag>";
    } 

    /**
     * gets the attribute collection as a
     * string
     * @param attributes: BaMLAttributes [array]
     */
    public static function getAttributesCollection($attributes, $padding=1) {
      /** one space to seperate namespace **/
      $attrs = str_repeat(" ", $padding);
      foreach ($attributes as $attr) {
        $attrs .= $attr->getKey() . "=" . '"' . $attr->getValue() . '" ';
      }

      return substr($attrs, 0, strlen($attrs) - 1);
    }

    /**
     * simple xml join tree
     * sax wrapper around PHP's XML parser does
     * not provide
     * @param verbs: BaMLVerbs [array]
     */
    public static function joinTree($verbs) {
      $str = '';

      if (sizeof($verbs) > 0) {

        foreach ($verbs as $v) {
          $str .= self::openTag($v->getName(), $v->getAttributes());

          if ($v->hasVerbs()) {
            $str .= self::joinTree($v->getVerbs());    
          }

          $str .= $v->getText();


          $str .= self::closeTag($v->getName());
        }
      }

      return $str;
    }

    /**
     * open tag for a BaML
     * document. will join
     * attributes if available
     *
     * @param name: valid BaML verb
     */
    public function openTag($name, $attributes=null) {
        if ($attributes) {
          $initial = $name;
          $name = self::open($initial);
          $name .= self::getAttributesCollection($attributes);
          $name .= ">";

          return $name;
        } 

      return self::fullOpen($name);
    }

    /**
     * close tag for
     * BaML document. Stub, see
     * full close
     */
    public function closeTag($name) {
      return self::fullClose("$name");
    }

    /**
     * Pretty print the XML 
     * document. Preserve spacing
     * tab at every newline
     * 
     * @param xml: xml document 
     */
    public static function indent($xml) {
      $cnt = 0;
      $d = 0;
      $t = 0;
      $c = 0;
      while ($cnt != strlen($xml)) {
        $ch = substr($xml, $cnt, 1);
        $ch2 = substr($xml, $cnt, 2);
        $lch = substr($xml, strlen($xml) - 1, 1);
        $f = strlen($xml);
        $a = strlen($xml);

          if ($ch == "<" && $ch2 != "</" && $cnt != "0") {
            $n = "\n";
              for($i = 0; $i <= ($t - $c); $i ++) {
                $n .= "\t";
              }

            $pre = substr($xml, 0, $cnt);
            $af = substr($xml, $cnt, (max(strlen($xml), $cnt) - min(strlen($xml), $cnt)));
            $xml = $pre . $n . $af;

            $a = strlen($xml);
            $d ++;
            $t ++;
          }

          if ($ch2 == "</") {
            $n = "\n";
            for($i = 0; $i <= ($t - $c) - 1; $i ++) {
              $n .= "\t";
            }

            $pre = substr($xml, 0, $cnt);
            $af = substr($xml, $cnt, (max(strlen($xml), $cnt) - min(strlen($xml), $cnt)));
            $xml = $pre . $n . $af;

            $a = strlen($xml);
            $c ++;
          }

          $cnt += ($a - $f) > 0 ? ($a-$f)+1:1;         
      }

      return $xml;
    }

    /**
     * parse a singular element
     * and return its pieces as either
     * an attribute, verb or text
     *
     * @param element: XML element
     */
    public static function parse($element) {
      $space = strpos(" ", $element);
      $tag = substr($element, 1, $space);
      $verb = "Catapult\\BaML" . $tag;

      return new $verb; 
    }
}
Bandwidth PHP SDK API documentation generated by ApiGen