How to use Call class

Best Prophecy code snippet using Call

handler.php

Source:handler.php Github

copy

Full Screen

2if(!defined('DOKU_INC')) die('meh.');3if (!defined('DOKU_PARSER_EOL')) define('DOKU_PARSER_EOL',"\n"); // add this to make handling test cases simpler4class Doku_Handler {5 var $Renderer = NULL;6 var $CallWriter = NULL;7 var $calls = array();8 var $status = array(9 'section' => false,10 );11 var $rewriteBlocks = true;12 function Doku_Handler() {13 $this->CallWriter = new Doku_Handler_CallWriter($this);14 }15 function _addCall($handler, $args, $pos) {16 $call = array($handler,$args, $pos);17 $this->CallWriter->writeCall($call);18 }19 function addPluginCall($plugin, $args, $state, $pos, $match) {20 $call = array('plugin',array($plugin, $args, $state, $match), $pos);21 $this->CallWriter->writeCall($call);22 }23 function _finalize(){24 $this->CallWriter->finalise();25 if ( $this->status['section'] ) {26 $last_call = end($this->calls);27 array_push($this->calls,array('section_close',array(), $last_call[2]));28 }29 if ( $this->rewriteBlocks ) {30 $B = new Doku_Handler_Block();31 $this->calls = $B->process($this->calls);32 }33 trigger_event('PARSER_HANDLER_DONE',$this);34 array_unshift($this->calls,array('document_start',array(),0));35 $last_call = end($this->calls);36 array_push($this->calls,array('document_end',array(),$last_call[2]));37 }38 function fetch() {39 $call = each($this->calls);40 if ( $call ) {41 return $call['value'];42 }43 return false;44 }45 /**46 * Special plugin handler47 *48 * This handler is called for all modes starting with 'plugin_'.49 * An additional parameter with the plugin name is passed50 *51 * @author Andreas Gohr <andi@splitbrain.org>52 */53 function plugin($match, $state, $pos, $pluginname){54 $data = array($match);55 $plugin =& plugin_load('syntax',$pluginname);56 if($plugin != null){57 $data = $plugin->handle($match, $state, $pos, $this);58 }59 if ($data !== false) {60 $this->addPluginCall($pluginname,$data,$state,$pos,$match);61 }62 return true;63 }64 function base($match, $state, $pos) {65 switch ( $state ) {66 case DOKU_LEXER_UNMATCHED:67 $this->_addCall('cdata',array($match), $pos);68 return true;69 break;70 }71 }72 function header($match, $state, $pos) {73 // get level and title74 $title = trim($match);75 $level = 7 - strspn($title,'=');76 if($level < 1) $level = 1;77 $title = trim($title,'=');78 $title = trim($title);79 if ($this->status['section']) $this->_addCall('section_close',array(),$pos);80 $this->_addCall('header',array($title,$level,$pos), $pos);81 $this->_addCall('section_open',array($level),$pos);82 $this->status['section'] = true;83 return true;84 }85 function notoc($match, $state, $pos) {86 $this->_addCall('notoc',array(),$pos);87 return true;88 }89 function nocache($match, $state, $pos) {90 $this->_addCall('nocache',array(),$pos);91 return true;92 }93 function linebreak($match, $state, $pos) {94 $this->_addCall('linebreak',array(),$pos);95 return true;96 }97 function eol($match, $state, $pos) {98 $this->_addCall('eol',array(),$pos);99 return true;100 }101 function hr($match, $state, $pos) {102 $this->_addCall('hr',array(),$pos);103 return true;104 }105 function _nestingTag($match, $state, $pos, $name) {106 switch ( $state ) {107 case DOKU_LEXER_ENTER:108 $this->_addCall($name.'_open', array(), $pos);109 break;110 case DOKU_LEXER_EXIT:111 $this->_addCall($name.'_close', array(), $pos);112 break;113 case DOKU_LEXER_UNMATCHED:114 $this->_addCall('cdata',array($match), $pos);115 break;116 }117 }118 function strong($match, $state, $pos) {119 $this->_nestingTag($match, $state, $pos, 'strong');120 return true;121 }122 function emphasis($match, $state, $pos) {123 $this->_nestingTag($match, $state, $pos, 'emphasis');124 return true;125 }126 function underline($match, $state, $pos) {127 $this->_nestingTag($match, $state, $pos, 'underline');128 return true;129 }130 function monospace($match, $state, $pos) {131 $this->_nestingTag($match, $state, $pos, 'monospace');132 return true;133 }134 function subscript($match, $state, $pos) {135 $this->_nestingTag($match, $state, $pos, 'subscript');136 return true;137 }138 function superscript($match, $state, $pos) {139 $this->_nestingTag($match, $state, $pos, 'superscript');140 return true;141 }142 function deleted($match, $state, $pos) {143 $this->_nestingTag($match, $state, $pos, 'deleted');144 return true;145 }146 function footnote($match, $state, $pos) {147// $this->_nestingTag($match, $state, $pos, 'footnote');148 if (!isset($this->_footnote)) $this->_footnote = false;149 switch ( $state ) {150 case DOKU_LEXER_ENTER:151 // footnotes can not be nested - however due to limitations in lexer it can't be prevented152 // we will still enter a new footnote mode, we just do nothing153 if ($this->_footnote) {154 $this->_addCall('cdata',array($match), $pos);155 break;156 }157 $this->_footnote = true;158 $ReWriter = new Doku_Handler_Nest($this->CallWriter,'footnote_close');159 $this->CallWriter = & $ReWriter;160 $this->_addCall('footnote_open', array(), $pos);161 break;162 case DOKU_LEXER_EXIT:163 // check whether we have already exitted the footnote mode, can happen if the modes were nested164 if (!$this->_footnote) {165 $this->_addCall('cdata',array($match), $pos);166 break;167 }168 $this->_footnote = false;169 $this->_addCall('footnote_close', array(), $pos);170 $this->CallWriter->process();171 $ReWriter = & $this->CallWriter;172 $this->CallWriter = & $ReWriter->CallWriter;173 break;174 case DOKU_LEXER_UNMATCHED:175 $this->_addCall('cdata', array($match), $pos);176 break;177 }178 return true;179 }180 function listblock($match, $state, $pos) {181 switch ( $state ) {182 case DOKU_LEXER_ENTER:183 $ReWriter = new Doku_Handler_List($this->CallWriter);184 $this->CallWriter = & $ReWriter;185 $this->_addCall('list_open', array($match), $pos);186 break;187 case DOKU_LEXER_EXIT:188 $this->_addCall('list_close', array(), $pos);189 $this->CallWriter->process();190 $ReWriter = & $this->CallWriter;191 $this->CallWriter = & $ReWriter->CallWriter;192 break;193 case DOKU_LEXER_MATCHED:194 $this->_addCall('list_item', array($match), $pos);195 break;196 case DOKU_LEXER_UNMATCHED:197 $this->_addCall('cdata', array($match), $pos);198 break;199 }200 return true;201 }202 function unformatted($match, $state, $pos) {203 if ( $state == DOKU_LEXER_UNMATCHED ) {204 $this->_addCall('unformatted',array($match), $pos);205 }206 return true;207 }208 function php($match, $state, $pos) {209 global $conf;210 if ( $state == DOKU_LEXER_UNMATCHED ) {211 $this->_addCall('php',array($match), $pos);212 }213 return true;214 }215 function phpblock($match, $state, $pos) {216 global $conf;217 if ( $state == DOKU_LEXER_UNMATCHED ) {218 $this->_addCall('phpblock',array($match), $pos);219 }220 return true;221 }222 function html($match, $state, $pos) {223 global $conf;224 if ( $state == DOKU_LEXER_UNMATCHED ) {225 $this->_addCall('html',array($match), $pos);226 }227 return true;228 }229 function htmlblock($match, $state, $pos) {230 global $conf;231 if ( $state == DOKU_LEXER_UNMATCHED ) {232 $this->_addCall('htmlblock',array($match), $pos);233 }234 return true;235 }236 function preformatted($match, $state, $pos) {237 switch ( $state ) {238 case DOKU_LEXER_ENTER:239 $ReWriter = new Doku_Handler_Preformatted($this->CallWriter);240 $this->CallWriter = & $ReWriter;241 $this->_addCall('preformatted_start',array(), $pos);242 break;243 case DOKU_LEXER_EXIT:244 $this->_addCall('preformatted_end',array(), $pos);245 $this->CallWriter->process();246 $ReWriter = & $this->CallWriter;247 $this->CallWriter = & $ReWriter->CallWriter;248 break;249 case DOKU_LEXER_MATCHED:250 $this->_addCall('preformatted_newline',array(), $pos);251 break;252 case DOKU_LEXER_UNMATCHED:253 $this->_addCall('preformatted_content',array($match), $pos);254 break;255 }256 return true;257 }258 function quote($match, $state, $pos) {259 switch ( $state ) {260 case DOKU_LEXER_ENTER:261 $ReWriter = new Doku_Handler_Quote($this->CallWriter);262 $this->CallWriter = & $ReWriter;263 $this->_addCall('quote_start',array($match), $pos);264 break;265 case DOKU_LEXER_EXIT:266 $this->_addCall('quote_end',array(), $pos);267 $this->CallWriter->process();268 $ReWriter = & $this->CallWriter;269 $this->CallWriter = & $ReWriter->CallWriter;270 break;271 case DOKU_LEXER_MATCHED:272 $this->_addCall('quote_newline',array($match), $pos);273 break;274 case DOKU_LEXER_UNMATCHED:275 $this->_addCall('cdata',array($match), $pos);276 break;277 }278 return true;279 }280 function file($match, $state, $pos) {281 return $this->code($match, $state, $pos, 'file');282 }283 function code($match, $state, $pos, $type='code') {284 if ( $state == DOKU_LEXER_UNMATCHED ) {285 $matches = explode('>',$match,2);286 $param = preg_split('/\s+/', $matches[0], 2, PREG_SPLIT_NO_EMPTY);287 while(count($param) < 2) array_push($param, null);288 // We shortcut html here.289 if ($param[0] == 'html') $param[0] = 'html4strict';290 if ($param[0] == '-') $param[0] = null;291 array_unshift($param, $matches[1]);292 $this->_addCall($type, $param, $pos);293 }294 return true;295 }296 function acronym($match, $state, $pos) {297 $this->_addCall('acronym',array($match), $pos);298 return true;299 }300 function smiley($match, $state, $pos) {301 $this->_addCall('smiley',array($match), $pos);302 return true;303 }304 function wordblock($match, $state, $pos) {305 $this->_addCall('wordblock',array($match), $pos);306 return true;307 }308 function entity($match, $state, $pos) {309 $this->_addCall('entity',array($match), $pos);310 return true;311 }312 function multiplyentity($match, $state, $pos) {313 preg_match_all('/\d+/',$match,$matches);314 $this->_addCall('multiplyentity',array($matches[0][0],$matches[0][1]), $pos);315 return true;316 }317 function singlequoteopening($match, $state, $pos) {318 $this->_addCall('singlequoteopening',array(), $pos);319 return true;320 }321 function singlequoteclosing($match, $state, $pos) {322 $this->_addCall('singlequoteclosing',array(), $pos);323 return true;324 }325 function apostrophe($match, $state, $pos) {326 $this->_addCall('apostrophe',array(), $pos);327 return true;328 }329 function doublequoteopening($match, $state, $pos) {330 $this->_addCall('doublequoteopening',array(), $pos);331 return true;332 }333 function doublequoteclosing($match, $state, $pos) {334 $this->_addCall('doublequoteclosing',array(), $pos);335 return true;336 }337 function camelcaselink($match, $state, $pos) {338 $this->_addCall('camelcaselink',array($match), $pos);339 return true;340 }341 /*342 */343 function internallink($match, $state, $pos) {344 // Strip the opening and closing markup345 $link = preg_replace(array('/^\[\[/','/\]\]$/u'),'',$match);346 // Split title from URL347 $link = explode('|',$link,2);348 if ( !isset($link[1]) ) {349 $link[1] = NULL;350 } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) {351 // If the title is an image, convert it to an array containing the image details352 $link[1] = Doku_Handler_Parse_Media($link[1]);353 }354 $link[0] = trim($link[0]);355 //decide which kind of link it is356 if ( preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link[0]) ) {357 // Interwiki358 $interwiki = explode('>',$link[0],2);359 $this->_addCall(360 'interwikilink',361 array($link[0],$link[1],strtolower($interwiki[0]),$interwiki[1]),362 $pos363 );364 }elseif ( preg_match('/^\\\\\\\\[^\\\\]+?\\\\/u',$link[0]) ) {365 // Windows Share366 $this->_addCall(367 'windowssharelink',368 array($link[0],$link[1]),369 $pos370 );371 }elseif ( preg_match('#^([a-z0-9\-\.+]+?)://#i',$link[0]) ) {372 // external link (accepts all protocols)373 $this->_addCall(374 'externallink',375 array($link[0],$link[1]),376 $pos377 );378 }elseif ( preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link[0]) ) {379 // E-Mail (pattern above is defined in inc/mail.php)380 $this->_addCall(381 'emaillink',382 array($link[0],$link[1]),383 $pos384 );385 }elseif ( preg_match('!^#.+!',$link[0]) ){386 // local link387 $this->_addCall(388 'locallink',389 array(substr($link[0],1),$link[1]),390 $pos391 );392 }else{393 // internal link394 $this->_addCall(395 'internallink',396 array($link[0],$link[1]),397 $pos398 );399 }400 return true;401 }402 function filelink($match, $state, $pos) {403 $this->_addCall('filelink',array($match, NULL), $pos);404 return true;405 }406 function windowssharelink($match, $state, $pos) {407 $this->_addCall('windowssharelink',array($match, NULL), $pos);408 return true;409 }410 function media($match, $state, $pos) {411 $p = Doku_Handler_Parse_Media($match);412 $this->_addCall(413 $p['type'],414 array($p['src'], $p['title'], $p['align'], $p['width'],415 $p['height'], $p['cache'], $p['linking']),416 $pos417 );418 return true;419 }420 function rss($match, $state, $pos) {421 $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match);422 // get params423 list($link,$params) = explode(' ',$link,2);424 $p = array();425 if(preg_match('/\b(\d+)\b/',$params,$match)){426 $p['max'] = $match[1];427 }else{428 $p['max'] = 8;429 }430 $p['reverse'] = (preg_match('/rev/',$params));431 $p['author'] = (preg_match('/\b(by|author)/',$params));432 $p['date'] = (preg_match('/\b(date)/',$params));433 $p['details'] = (preg_match('/\b(desc|detail)/',$params));434 if (preg_match('/\b(\d+)([dhm])\b/',$params,$match)) {435 $period = array('d' => 86400, 'h' => 3600, 'm' => 60);436 $p['refresh'] = max(600,$match[1]*$period[$match[2]]); // n * period in seconds, minimum 10 minutes437 } else {438 $p['refresh'] = 14400; // default to 4 hours439 }440 $this->_addCall('rss',array($link,$p),$pos);441 return true;442 }443 function externallink($match, $state, $pos) {444 $url = $match;445 $title = null;446 // add protocol on simple short URLs447 if(substr($url,0,3) == 'ftp' && (substr($url,0,6) != 'ftp://')){448 $title = $url;449 $url = 'ftp://'.$url;450 }451 if(substr($url,0,3) == 'www' && (substr($url,0,7) != 'http://')){452 $title = $url;453 $url = 'http://'.$url;454 }455 $this->_addCall('externallink',array($url, $title), $pos);456 return true;457 }458 function emaillink($match, $state, $pos) {459 $email = preg_replace(array('/^</','/>$/'),'',$match);460 $this->_addCall('emaillink',array($email, NULL), $pos);461 return true;462 }463 function table($match, $state, $pos) {464 switch ( $state ) {465 case DOKU_LEXER_ENTER:466 $ReWriter = new Doku_Handler_Table($this->CallWriter);467 $this->CallWriter = & $ReWriter;468 $this->_addCall('table_start', array($pos + 1), $pos);469 if ( trim($match) == '^' ) {470 $this->_addCall('tableheader', array(), $pos);471 } else {472 $this->_addCall('tablecell', array(), $pos);473 }474 break;475 case DOKU_LEXER_EXIT:476 $this->_addCall('table_end', array($pos), $pos);477 $this->CallWriter->process();478 $ReWriter = & $this->CallWriter;479 $this->CallWriter = & $ReWriter->CallWriter;480 break;481 case DOKU_LEXER_UNMATCHED:482 if ( trim($match) != '' ) {483 $this->_addCall('cdata',array($match), $pos);484 }485 break;486 case DOKU_LEXER_MATCHED:487 if ( $match == ' ' ){488 $this->_addCall('cdata', array($match), $pos);489 } else if ( preg_match('/:::/',$match) ) {490 $this->_addCall('rowspan', array($match), $pos);491 } else if ( preg_match('/\t+/',$match) ) {492 $this->_addCall('table_align', array($match), $pos);493 } else if ( preg_match('/ {2,}/',$match) ) {494 $this->_addCall('table_align', array($match), $pos);495 } else if ( $match == "\n|" ) {496 $this->_addCall('table_row', array(), $pos);497 $this->_addCall('tablecell', array(), $pos);498 } else if ( $match == "\n^" ) {499 $this->_addCall('table_row', array(), $pos);500 $this->_addCall('tableheader', array(), $pos);501 } else if ( $match == '|' ) {502 $this->_addCall('tablecell', array(), $pos);503 } else if ( $match == '^' ) {504 $this->_addCall('tableheader', array(), $pos);505 }506 break;507 }508 return true;509 }510}511//------------------------------------------------------------------------512function Doku_Handler_Parse_Media($match) {513 // Strip the opening and closing markup514 $link = preg_replace(array('/^\{\{/','/\}\}$/u'),'',$match);515 // Split title from URL516 $link = explode('|',$link,2);517 // Check alignment518 $ralign = (bool)preg_match('/^ /',$link[0]);519 $lalign = (bool)preg_match('/ $/',$link[0]);520 // Logic = what's that ;)...521 if ( $lalign & $ralign ) {522 $align = 'center';523 } else if ( $ralign ) {524 $align = 'right';525 } else if ( $lalign ) {526 $align = 'left';527 } else {528 $align = NULL;529 }530 // The title...531 if ( !isset($link[1]) ) {532 $link[1] = NULL;533 }534 //remove aligning spaces535 $link[0] = trim($link[0]);536 //split into src and parameters (using the very last questionmark)537 $pos = strrpos($link[0], '?');538 if($pos !== false){539 $src = substr($link[0],0,$pos);540 $param = substr($link[0],$pos+1);541 }else{542 $src = $link[0];543 $param = '';544 }545 //parse width and height546 if(preg_match('#(\d+)(x(\d+))?#i',$param,$size)){547 ($size[1]) ? $w = $size[1] : $w = NULL;548 ($size[3]) ? $h = $size[3] : $h = NULL;549 } else {550 $w = NULL;551 $h = NULL;552 }553 //get linking command554 if(preg_match('/nolink/i',$param)){555 $linking = 'nolink';556 }else if(preg_match('/direct/i',$param)){557 $linking = 'direct';558 }else if(preg_match('/linkonly/i',$param)){559 $linking = 'linkonly';560 }else{561 $linking = 'details';562 }563 //get caching command564 if (preg_match('/(nocache|recache)/i',$param,$cachemode)){565 $cache = $cachemode[1];566 }else{567 $cache = 'cache';568 }569 // Check whether this is a local or remote image570 if ( preg_match('#^(https?|ftp)#i',$src) ) {571 $call = 'externalmedia';572 } else {573 $call = 'internalmedia';574 }575 $params = array(576 'type'=>$call,577 'src'=>$src,578 'title'=>$link[1],579 'align'=>$align,580 'width'=>$w,581 'height'=>$h,582 'cache'=>$cache,583 'linking'=>$linking,584 );585 return $params;586}587//------------------------------------------------------------------------588class Doku_Handler_CallWriter {589 var $Handler;590 function Doku_Handler_CallWriter(& $Handler) {591 $this->Handler = & $Handler;592 }593 function writeCall($call) {594 $this->Handler->calls[] = $call;595 }596 function writeCalls($calls) {597 $this->Handler->calls = array_merge($this->Handler->calls, $calls);598 }599 // function is required, but since this call writer is first/highest in600 // the chain it is not required to do anything601 function finalise() {602 unset($this->Handler);603 }604}605//------------------------------------------------------------------------606/**607 * Generic call writer class to handle nesting of rendering instructions608 * within a render instruction. Also see nest() method of renderer base class609 *610 * @author Chris Smith <chris@jalakai.co.uk>611 */612class Doku_Handler_Nest {613 var $CallWriter;614 var $calls = array();615 var $closingInstruction;616 /**617 * constructor618 *619 * @param object $CallWriter the renderers current call writer620 * @param string $close closing instruction name, this is required to properly terminate the621 * syntax mode if the document ends without a closing pattern622 */623 function Doku_Handler_Nest(& $CallWriter, $close="nest_close") {624 $this->CallWriter = & $CallWriter;625 $this->closingInstruction = $close;626 }627 function writeCall($call) {628 $this->calls[] = $call;629 }630 function writeCalls($calls) {631 $this->calls = array_merge($this->calls, $calls);632 }633 function finalise() {634 $last_call = end($this->calls);635 $this->writeCall(array($this->closingInstruction,array(), $last_call[2]));636 $this->process();637 $this->CallWriter->finalise();638 unset($this->CallWriter);639 }640 function process() {641 // merge consecutive cdata642 $unmerged_calls = $this->calls;643 $this->calls = array();644 foreach ($unmerged_calls as $call) $this->addCall($call);645 $first_call = reset($this->calls);646 $this->CallWriter->writeCall(array("nest", array($this->calls), $first_call[2]));647 }648 function addCall($call) {649 $key = count($this->calls);650 if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {651 $this->calls[$key-1][1][0] .= $call[1][0];652 } else if ($call[0] == 'eol') {653 // do nothing (eol shouldn't be allowed, to counter preformatted fix in #1652 & #1699)654 } else {655 $this->calls[] = $call;656 }657 }658}659class Doku_Handler_List {660 var $CallWriter;661 var $calls = array();662 var $listCalls = array();663 var $listStack = array();664 function Doku_Handler_List(& $CallWriter) {665 $this->CallWriter = & $CallWriter;666 }667 function writeCall($call) {668 $this->calls[] = $call;669 }670 // Probably not needed but just in case...671 function writeCalls($calls) {672 $this->calls = array_merge($this->calls, $calls);673# $this->CallWriter->writeCalls($this->calls);674 }675 function finalise() {676 $last_call = end($this->calls);677 $this->writeCall(array('list_close',array(), $last_call[2]));678 $this->process();679 $this->CallWriter->finalise();680 unset($this->CallWriter);681 }682 //------------------------------------------------------------------------683 function process() {684 foreach ( $this->calls as $call ) {685 switch ($call[0]) {686 case 'list_item':687 $this->listOpen($call);688 break;689 case 'list_open':690 $this->listStart($call);691 break;692 case 'list_close':693 $this->listEnd($call);694 break;695 default:696 $this->listContent($call);697 break;698 }699 }700 $this->CallWriter->writeCalls($this->listCalls);701 }702 //------------------------------------------------------------------------703 function listStart($call) {704 $depth = $this->interpretSyntax($call[1][0], $listType);705 $this->initialDepth = $depth;706 $this->listStack[] = array($listType, $depth);707 $this->listCalls[] = array('list'.$listType.'_open',array(),$call[2]);708 $this->listCalls[] = array('listitem_open',array(1),$call[2]);709 $this->listCalls[] = array('listcontent_open',array(),$call[2]);710 }711 //------------------------------------------------------------------------712 function listEnd($call) {713 $closeContent = true;714 while ( $list = array_pop($this->listStack) ) {715 if ( $closeContent ) {716 $this->listCalls[] = array('listcontent_close',array(),$call[2]);717 $closeContent = false;718 }719 $this->listCalls[] = array('listitem_close',array(),$call[2]);720 $this->listCalls[] = array('list'.$list[0].'_close', array(), $call[2]);721 }722 }723 //------------------------------------------------------------------------724 function listOpen($call) {725 $depth = $this->interpretSyntax($call[1][0], $listType);726 $end = end($this->listStack);727 // Not allowed to be shallower than initialDepth728 if ( $depth < $this->initialDepth ) {729 $depth = $this->initialDepth;730 }731 //------------------------------------------------------------------------732 if ( $depth == $end[1] ) {733 // Just another item in the list...734 if ( $listType == $end[0] ) {735 $this->listCalls[] = array('listcontent_close',array(),$call[2]);736 $this->listCalls[] = array('listitem_close',array(),$call[2]);737 $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);738 $this->listCalls[] = array('listcontent_open',array(),$call[2]);739 // Switched list type...740 } else {741 $this->listCalls[] = array('listcontent_close',array(),$call[2]);742 $this->listCalls[] = array('listitem_close',array(),$call[2]);743 $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);744 $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);745 $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);746 $this->listCalls[] = array('listcontent_open',array(),$call[2]);747 array_pop($this->listStack);748 $this->listStack[] = array($listType, $depth);749 }750 //------------------------------------------------------------------------751 // Getting deeper...752 } else if ( $depth > $end[1] ) {753 $this->listCalls[] = array('listcontent_close',array(),$call[2]);754 $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);755 $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);756 $this->listCalls[] = array('listcontent_open',array(),$call[2]);757 $this->listStack[] = array($listType, $depth);758 //------------------------------------------------------------------------759 // Getting shallower ( $depth < $end[1] )760 } else {761 $this->listCalls[] = array('listcontent_close',array(),$call[2]);762 $this->listCalls[] = array('listitem_close',array(),$call[2]);763 $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);764 // Throw away the end - done765 array_pop($this->listStack);766 while (1) {767 $end = end($this->listStack);768 if ( $end[1] <= $depth ) {769 // Normalize depths770 $depth = $end[1];771 $this->listCalls[] = array('listitem_close',array(),$call[2]);772 if ( $end[0] == $listType ) {773 $this->listCalls[] = array('listitem_open',array($depth-1),$call[2]);774 $this->listCalls[] = array('listcontent_open',array(),$call[2]);775 } else {776 // Switching list type...777 $this->listCalls[] = array('list'.$end[0].'_close', array(), $call[2]);778 $this->listCalls[] = array('list'.$listType.'_open', array(), $call[2]);779 $this->listCalls[] = array('listitem_open', array($depth-1), $call[2]);780 $this->listCalls[] = array('listcontent_open',array(),$call[2]);781 array_pop($this->listStack);782 $this->listStack[] = array($listType, $depth);783 }784 break;785 // Haven't dropped down far enough yet.... ( $end[1] > $depth )786 } else {787 $this->listCalls[] = array('listitem_close',array(),$call[2]);788 $this->listCalls[] = array('list'.$end[0].'_close',array(),$call[2]);789 array_pop($this->listStack);790 }791 }792 }793 }794 //------------------------------------------------------------------------795 function listContent($call) {796 $this->listCalls[] = $call;797 }798 //------------------------------------------------------------------------799 function interpretSyntax($match, & $type) {800 if ( substr($match,-1) == '*' ) {801 $type = 'u';802 } else {803 $type = 'o';804 }805 // Is the +1 needed? It used to be count(explode(...))806 // but I don't think the number is seen outside this handler807 return substr_count(str_replace("\t",' ',$match), ' ') + 1;808 }809}810//------------------------------------------------------------------------811class Doku_Handler_Preformatted {812 var $CallWriter;813 var $calls = array();814 var $pos;815 var $text ='';816 function Doku_Handler_Preformatted(& $CallWriter) {817 $this->CallWriter = & $CallWriter;818 }819 function writeCall($call) {820 $this->calls[] = $call;821 }822 // Probably not needed but just in case...823 function writeCalls($calls) {824 $this->calls = array_merge($this->calls, $calls);825# $this->CallWriter->writeCalls($this->calls);826 }827 function finalise() {828 $last_call = end($this->calls);829 $this->writeCall(array('preformatted_end',array(), $last_call[2]));830 $this->process();831 $this->CallWriter->finalise();832 unset($this->CallWriter);833 }834 function process() {835 foreach ( $this->calls as $call ) {836 switch ($call[0]) {837 case 'preformatted_start':838 $this->pos = $call[2];839 break;840 case 'preformatted_newline':841 $this->text .= "\n";842 break;843 case 'preformatted_content':844 $this->text .= $call[1][0];845 break;846 case 'preformatted_end':847 if (trim($this->text)) {848 $this->CallWriter->writeCall(array('preformatted',array($this->text),$this->pos));849 }850 // see FS#1699 & FS#1652, add 'eol' instructions to ensure proper triggering of following p_open851 $this->CallWriter->writeCall(array('eol',array(),$this->pos));852 $this->CallWriter->writeCall(array('eol',array(),$this->pos));853 break;854 }855 }856 }857}858//------------------------------------------------------------------------859class Doku_Handler_Quote {860 var $CallWriter;861 var $calls = array();862 var $quoteCalls = array();863 function Doku_Handler_Quote(& $CallWriter) {864 $this->CallWriter = & $CallWriter;865 }866 function writeCall($call) {867 $this->calls[] = $call;868 }869 // Probably not needed but just in case...870 function writeCalls($calls) {871 $this->calls = array_merge($this->calls, $calls);872 }873 function finalise() {874 $last_call = end($this->calls);875 $this->writeCall(array('quote_end',array(), $last_call[2]));876 $this->process();877 $this->CallWriter->finalise();878 unset($this->CallWriter);879 }880 function process() {881 $quoteDepth = 1;882 foreach ( $this->calls as $call ) {883 switch ($call[0]) {884 case 'quote_start':885 $this->quoteCalls[] = array('quote_open',array(),$call[2]);886 case 'quote_newline':887 $quoteLength = $this->getDepth($call[1][0]);888 if ( $quoteLength > $quoteDepth ) {889 $quoteDiff = $quoteLength - $quoteDepth;890 for ( $i = 1; $i <= $quoteDiff; $i++ ) {891 $this->quoteCalls[] = array('quote_open',array(),$call[2]);892 }893 } else if ( $quoteLength < $quoteDepth ) {894 $quoteDiff = $quoteDepth - $quoteLength;895 for ( $i = 1; $i <= $quoteDiff; $i++ ) {896 $this->quoteCalls[] = array('quote_close',array(),$call[2]);897 }898 } else {899 if ($call[0] != 'quote_start') $this->quoteCalls[] = array('linebreak',array(),$call[2]);900 }901 $quoteDepth = $quoteLength;902 break;903 case 'quote_end':904 if ( $quoteDepth > 1 ) {905 $quoteDiff = $quoteDepth - 1;906 for ( $i = 1; $i <= $quoteDiff; $i++ ) {907 $this->quoteCalls[] = array('quote_close',array(),$call[2]);908 }909 }910 $this->quoteCalls[] = array('quote_close',array(),$call[2]);911 $this->CallWriter->writeCalls($this->quoteCalls);912 break;913 default:914 $this->quoteCalls[] = $call;915 break;916 }917 }918 }919 function getDepth($marker) {920 preg_match('/>{1,}/', $marker, $matches);921 $quoteLength = strlen($matches[0]);922 return $quoteLength;923 }924}925//------------------------------------------------------------------------926class Doku_Handler_Table {927 var $CallWriter;928 var $calls = array();929 var $tableCalls = array();930 var $maxCols = 0;931 var $maxRows = 1;932 var $currentCols = 0;933 var $firstCell = false;934 var $lastCellType = 'tablecell';935 function Doku_Handler_Table(& $CallWriter) {936 $this->CallWriter = & $CallWriter;937 }938 function writeCall($call) {939 $this->calls[] = $call;940 }941 // Probably not needed but just in case...942 function writeCalls($calls) {943 $this->calls = array_merge($this->calls, $calls);944 }945 function finalise() {946 $last_call = end($this->calls);947 $this->writeCall(array('table_end',array(), $last_call[2]));948 $this->process();949 $this->CallWriter->finalise();950 unset($this->CallWriter);951 }952 //------------------------------------------------------------------------953 function process() {954 foreach ( $this->calls as $call ) {955 switch ( $call[0] ) {956 case 'table_start':957 $this->tableStart($call);958 break;959 case 'table_row':960 $this->tableRowClose($call);961 $this->tableRowOpen(array('tablerow_open',$call[1],$call[2]));962 break;963 case 'tableheader':964 case 'tablecell':965 $this->tableCell($call);966 break;967 case 'table_end':968 $this->tableRowClose($call);969 $this->tableEnd($call);970 break;971 default:972 $this->tableDefault($call);973 break;974 }975 }976 $this->CallWriter->writeCalls($this->tableCalls);977 }978 function tableStart($call) {979 $this->tableCalls[] = array('table_open',$call[1],$call[2]);980 $this->tableCalls[] = array('tablerow_open',array(),$call[2]);981 $this->firstCell = true;982 }983 function tableEnd($call) {984 $this->tableCalls[] = array('table_close',$call[1],$call[2]);985 $this->finalizeTable();986 }987 function tableRowOpen($call) {988 $this->tableCalls[] = $call;989 $this->currentCols = 0;990 $this->firstCell = true;991 $this->lastCellType = 'tablecell';992 $this->maxRows++;993 }994 function tableRowClose($call) {995 // Strip off final cell opening and anything after it996 while ( $discard = array_pop($this->tableCalls ) ) {997 if ( $discard[0] == 'tablecell_open' || $discard[0] == 'tableheader_open') {998 break;999 }1000 }1001 $this->tableCalls[] = array('tablerow_close', array(), $call[2]);1002 if ( $this->currentCols > $this->maxCols ) {1003 $this->maxCols = $this->currentCols;1004 }1005 }1006 function tableCell($call) {1007 if ( !$this->firstCell ) {1008 // Increase the span1009 $lastCall = end($this->tableCalls);1010 // A cell call which follows an open cell means an empty cell so span1011 if ( $lastCall[0] == 'tablecell_open' || $lastCall[0] == 'tableheader_open' ) {1012 $this->tableCalls[] = array('colspan',array(),$call[2]);1013 }1014 $this->tableCalls[] = array($this->lastCellType.'_close',array(),$call[2]);1015 $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]);1016 $this->lastCellType = $call[0];1017 } else {1018 $this->tableCalls[] = array($call[0].'_open',array(1,NULL,1),$call[2]);1019 $this->lastCellType = $call[0];1020 $this->firstCell = false;1021 }1022 $this->currentCols++;1023 }1024 function tableDefault($call) {1025 $this->tableCalls[] = $call;1026 }1027 function finalizeTable() {1028 // Add the max cols and rows to the table opening1029 if ( $this->tableCalls[0][0] == 'table_open' ) {1030 // Adjust to num cols not num col delimeters1031 $this->tableCalls[0][1][] = $this->maxCols - 1;1032 $this->tableCalls[0][1][] = $this->maxRows;1033 $this->tableCalls[0][1][] = array_shift($this->tableCalls[0][1]);1034 } else {1035 trigger_error('First element in table call list is not table_open');1036 }1037 $lastRow = 0;1038 $lastCell = 0;1039 $cellKey = array();1040 $toDelete = array();1041 // Look for the colspan elements and increment the colspan on the1042 // previous non-empty opening cell. Once done, delete all the cells1043 // that contain colspans1044 for ($key = 0 ; $key < count($this->tableCalls) ; ++$key) {1045 $call = $this->tableCalls[$key];1046 switch ($call[0]) {1047 case 'tablerow_open':1048 $lastRow++;1049 $lastCell = 0;1050 break;1051 case 'tablecell_open':1052 case 'tableheader_open':1053 $lastCell++;1054 $cellKey[$lastRow][$lastCell] = $key;1055 break;1056 case 'table_align':1057 $prev = in_array($this->tableCalls[$key-1][0], array('tablecell_open', 'tableheader_open'));1058 $next = in_array($this->tableCalls[$key+1][0], array('tablecell_close', 'tableheader_close'));1059 // If the cell is empty, align left1060 if ($prev && $next) {1061 $this->tableCalls[$key-1][1][1] = 'left';1062 // If the previous element was a cell open, align right1063 } elseif ($prev) {1064 $this->tableCalls[$key-1][1][1] = 'right';1065 // If the next element is the close of an element, align either center or left1066 } elseif ( $next) {1067 if ( $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] == 'right' ) {1068 $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'center';1069 } else {1070 $this->tableCalls[$cellKey[$lastRow][$lastCell]][1][1] = 'left';1071 }1072 }1073 // Now convert the whitespace back to cdata1074 $this->tableCalls[$key][0] = 'cdata';1075 break;1076 case 'colspan':1077 $this->tableCalls[$key-1][1][0] = false;1078 for($i = $key-2; $i >= $cellKey[$lastRow][1]; $i--) {1079 if ( $this->tableCalls[$i][0] == 'tablecell_open' || $this->tableCalls[$i][0] == 'tableheader_open' ) {1080 if ( false !== $this->tableCalls[$i][1][0] ) {1081 $this->tableCalls[$i][1][0]++;1082 break;1083 }1084 }1085 }1086 $toDelete[] = $key-1;1087 $toDelete[] = $key;1088 $toDelete[] = $key+1;1089 break;1090 case 'rowspan':1091 if ( $this->tableCalls[$key-1][0] == 'cdata' ) {1092 // ignore rowspan if previous call was cdata (text mixed with :::) we don't have to check next call as that wont match regex1093 $this->tableCalls[$key][0] = 'cdata';1094 } else {1095 $spanning_cell = null;1096 for($i = $lastRow-1; $i > 0; $i--) {1097 if ( $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tablecell_open' || $this->tableCalls[$cellKey[$i][$lastCell]][0] == 'tableheader_open' ) {1098 if ($this->tableCalls[$cellKey[$i][$lastCell]][1][2] >= $lastRow - $i) {1099 $spanning_cell = $i;1100 break;1101 }1102 }1103 }1104 if (is_null($spanning_cell)) {1105 // No spanning cell found, so convert this cell to1106 // an empty one to avoid broken tables1107 $this->tableCells[$key][1][1] = '';1108 continue;1109 }1110 $this->tableCalls[$cellKey[$spanning_cell][$lastCell]][1][2]++;1111 $this->tableCalls[$key-1][1][2] = false;1112 $toDelete[] = $key-1;1113 $toDelete[] = $key;1114 $toDelete[] = $key+1;1115 }1116 break;1117 case 'tablerow_close':1118 // Fix broken tables by adding missing cells1119 while (++$lastCell < $this->maxCols) {1120 array_splice($this->tableCalls, $key, 0, array(1121 array('tablecell_open', array(1, null, 1), $call[2]),1122 array('cdata', array(''), $call[2]),1123 array('tablecell_close', array(), $call[2])));1124 $key += 3;1125 }1126 break;1127 }1128 }1129 // condense cdata1130 $cnt = count($this->tableCalls);1131 for( $key = 0; $key < $cnt; $key++){1132 if($this->tableCalls[$key][0] == 'cdata'){1133 $ckey = $key;1134 $key++;1135 while($this->tableCalls[$key][0] == 'cdata'){1136 $this->tableCalls[$ckey][1][0] .= $this->tableCalls[$key][1][0];1137 $toDelete[] = $key;1138 $key++;1139 }1140 continue;1141 }1142 }1143 foreach ( $toDelete as $delete ) {1144 unset($this->tableCalls[$delete]);1145 }1146 $this->tableCalls = array_values($this->tableCalls);1147 }1148}1149/**1150 * Handler for paragraphs1151 *1152 * @author Harry Fuecks <hfuecks@gmail.com>1153 */1154class Doku_Handler_Block {1155 var $calls = array();1156 var $skipEol = false;1157 // Blocks these should not be inside paragraphs1158 var $blockOpen = array(1159 'header',1160 'listu_open','listo_open','listitem_open','listcontent_open',1161 'table_open','tablerow_open','tablecell_open','tableheader_open',1162 'quote_open',1163 'code','file','hr','preformatted','rss',1164 'htmlblock','phpblock',1165 'footnote_open',1166 );1167 var $blockClose = array(1168 'header',1169 'listu_close','listo_close','listitem_close','listcontent_close',1170 'table_close','tablerow_close','tablecell_close','tableheader_close',1171 'quote_close',1172 'code','file','hr','preformatted','rss',1173 'htmlblock','phpblock',1174 'footnote_close',1175 );1176 // Stacks can contain paragraphs1177 var $stackOpen = array(1178 'section_open',1179 );1180 var $stackClose = array(1181 'section_close',1182 );1183 /**1184 * Constructor. Adds loaded syntax plugins to the block and stack1185 * arrays1186 *1187 * @author Andreas Gohr <andi@splitbrain.org>1188 */1189 function Doku_Handler_Block(){1190 global $DOKU_PLUGINS;1191 //check if syntax plugins were loaded1192 if(empty($DOKU_PLUGINS['syntax'])) return;1193 foreach($DOKU_PLUGINS['syntax'] as $n => $p){1194 $ptype = $p->getPType();1195 if($ptype == 'block'){1196 $this->blockOpen[] = 'plugin_'.$n;1197 $this->blockClose[] = 'plugin_'.$n;1198 }elseif($ptype == 'stack'){1199 $this->stackOpen[] = 'plugin_'.$n;1200 $this->stackClose[] = 'plugin_'.$n;1201 }1202 }1203 }1204 function openParagraph($pos){1205 if ($this->inParagraph) return;1206 $this->calls[] = array('p_open',array(), $pos);1207 $this->inParagraph = true;1208 $this->skipEol = true;1209 }1210 /**1211 * Close a paragraph if needed1212 *1213 * This function makes sure there are no empty paragraphs on the stack1214 *1215 * @author Andreas Gohr <andi@splitbrain.org>1216 */1217 function closeParagraph($pos){1218 if (!$this->inParagraph) return;1219 // look back if there was any content - we don't want empty paragraphs1220 $content = '';1221 $ccount = count($this->calls);1222 for($i=$ccount-1; $i>=0; $i--){1223 if($this->calls[$i][0] == 'p_open'){1224 break;1225 }elseif($this->calls[$i][0] == 'cdata'){1226 $content .= $this->calls[$i][1][0];1227 }else{1228 $content = 'found markup';1229 break;1230 }1231 }1232 if(trim($content)==''){1233 //remove the whole paragraph1234 //array_splice($this->calls,$i); // <- this is much slower than the loop below1235 for($x=$ccount; $x>$i; $x--) array_pop($this->calls);1236 }else{1237 // remove ending linebreaks in the paragraph1238 $i=count($this->calls)-1;1239 if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL);1240 $this->calls[] = array('p_close',array(), $pos);1241 }1242 $this->inParagraph = false;1243 $this->skipEol = true;1244 }1245 function addCall($call) {1246 $key = count($this->calls);1247 if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {1248 $this->calls[$key-1][1][0] .= $call[1][0];1249 } else {1250 $this->calls[] = $call;1251 }1252 }1253 // simple version of addCall, without checking cdata1254 function storeCall($call) {1255 $this->calls[] = $call;1256 }1257 /**1258 * Processes the whole instruction stack to open and close paragraphs1259 *1260 * @author Harry Fuecks <hfuecks@gmail.com>1261 * @author Andreas Gohr <andi@splitbrain.org>1262 */1263 function process($calls) {1264 // open first paragraph1265 $this->openParagraph(0);1266 foreach ( $calls as $key => $call ) {1267 $cname = $call[0];1268 if ($cname == 'plugin') {1269 $cname='plugin_'.$call[1][0];1270 $plugin = true;1271 $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));1272 $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));1273 } else {1274 $plugin = false;1275 }1276 /* stack */1277 if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) {1278 $this->closeParagraph($call[2]);1279 $this->storeCall($call);1280 $this->openParagraph($call[2]);1281 continue;1282 }1283 if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) {1284 $this->closeParagraph($call[2]);1285 $this->storeCall($call);1286 $this->openParagraph($call[2]);1287 continue;1288 }1289 /* block */1290 // If it's a substition it opens and closes at the same call.1291 // To make sure next paragraph is correctly started, let close go first.1292 if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {1293 $this->closeParagraph($call[2]);1294 $this->storeCall($call);1295 $this->openParagraph($call[2]);1296 continue;1297 }1298 if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) {1299 $this->closeParagraph($call[2]);1300 $this->storeCall($call);1301 continue;1302 }1303 /* eol */1304 if ( $cname == 'eol' ) {1305 // Check this isn't an eol instruction to skip...1306 if ( !$this->skipEol ) {1307 // Next is EOL => double eol => mark as paragraph1308 if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) {1309 $this->closeParagraph($call[2]);1310 $this->openParagraph($call[2]);1311 } else {1312 //if this is just a single eol make a space from it1313 $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2]));1314 }1315 }1316 continue;1317 }1318 /* normal */1319 $this->addCall($call);1320 $this->skipEol = false;1321 }1322 // close last paragraph1323 $call = end($this->calls);1324 $this->closeParagraph($call[2]);1325 return $this->calls;1326 }1327}1328//Setup VIM: ex: et ts=4 :...

Full Screen

Full Screen

Collection.php

Source:Collection.php Github

copy

Full Screen

...4 *5 * @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)6 * @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License7 */8namespace Nexmo\Call;9use Nexmo\Client\ClientAwareInterface;10use Nexmo\Client\ClientAwareTrait;11use Nexmo\Conversations\Conversation;12use Nexmo\Entity\CollectionInterface;13use Nexmo\Entity\CollectionTrait;14use Psr\Http\Message\ResponseInterface;15use Zend\Diactoros\Request;16use Nexmo\Client\Exception;17class Collection implements ClientAwareInterface, CollectionInterface, \ArrayAccess18{19 use ClientAwareTrait;20 use CollectionTrait;21 public static function getCollectionName()22 {23 return 'calls';24 }25 public static function getCollectionPath()26 {27 return '/v1/' . self::getCollectionName();28 }29 public function hydrateEntity($data, $idOrCall)30 {31 if(!($idOrCall instanceof Call)){32 $idOrCall = new Call($idOrCall);33 }34 $idOrCall->setClient($this->getClient());35 $idOrCall->jsonUnserialize($data);36 return $idOrCall;37 }38 /**39 * @param null $callOrFilter40 * @return $this|Call41 */42 public function __invoke(Filter $filter = null)43 {44 if(!is_null($filter)){45 $this->setFilter($filter);46 }47 return $this;48 }49 public function create($call)50 {51 return $this->post($call);52 }53 public function put($payload, $idOrCall)54 {55 if(!($idOrCall instanceof Call)){56 $idOrCall = new Call($idOrCall);57 }58 $idOrCall->setClient($this->getClient());59 $idOrCall->put($payload);60 return $idOrCall;61 }62 public function delete($call = null, $type)63 {64 if(is_object($call) AND is_callable([$call, 'getId'])){65 $call = $call->getId();66 }67 if(!($call instanceof Call)){68 $call = new Call($call);69 }70 $request = new Request(71 $this->getClient()->getApiUrl() . $this->getCollectionPath() . '/' . $call->getId() . '/' . $type72 ,'DELETE'73 );74 $response = $this->client->send($request);75 if($response->getStatusCode() != '204'){76 throw $this->getException($response);77 }78 return $call;79 }80 public function post($call)81 {82 if($call instanceof Call){83 $body = $call->getRequestData();84 } else {85 $body = $call;86 }87 $request = new Request(88 $this->getClient()->getApiUrl() . $this->getCollectionPath()89 ,'POST',90 'php://temp',91 ['content-type' => 'application/json']92 );93 $request->getBody()->write(json_encode($body));94 $response = $this->client->send($request);95 if($response->getStatusCode() != '201'){96 throw $this->getException($response);97 }98 $body = json_decode($response->getBody()->getContents(), true);99 $call = new Call($body['uuid']);100 $call->jsonUnserialize($body);101 $call->setClient($this->getClient());102 return $call;103 }104 public function get($call)105 {106 if(!($call instanceof Call)){107 $call = new Call($call);108 }109 $call->setClient($this->getClient());110 $call->get();111 return $call;112 }113 protected function getException(ResponseInterface $response)114 {115 $body = json_decode($response->getBody()->getContents(), true);116 $status = $response->getStatusCode();117 // Error responses aren't consistent. Some are generated within the118 // proxy and some are generated within voice itself. This handles119 // both cases120 // This message isn't very useful, but we shouldn't ever see it121 $errorTitle = 'Unexpected error';122 if (isset($body['title'])) {123 $errorTitle = $body['title'];124 }125 if (isset($body['error_title'])) {126 $errorTitle = $body['error_title'];127 }128 if($status >= 400 AND $status < 500) {129 $e = new Exception\Request($errorTitle, $status);130 } elseif($status >= 500 AND $status < 600) {131 $e = new Exception\Server($errorTitle, $status);132 } else {133 $e = new Exception\Exception('Unexpected HTTP Status Code');134 throw $e;135 }136 return $e;137 }138 public function offsetExists($offset)139 {140 //todo: validate form of id141 return true;142 }143 /**144 * @param mixed $call145 * @return Call146 */147 public function offsetGet($call)148 {149 if(!($call instanceof Call)){150 $call = new Call($call);151 }152 $call->setClient($this->getClient());153 return $call;154 }155 public function offsetSet($offset, $value)156 {157 throw new \RuntimeException('can not set collection properties');158 }159 public function offsetUnset($offset)160 {161 throw new \RuntimeException('can not unset collection properties');162 }163}...

Full Screen

Full Screen

Call

Using AI Code Generation

copy

Full Screen

1require_once('Call.php');2$call = new Call();3$call->callMethod();4Call::callStaticMethod();5callFunction();6Call::callStaticFunction();7echo Call::CONSTANT;8echo Call::$staticProperty;9$call->property;10$call->callMethod();11Call::callStaticMethod();12callFunction();13Call::callStaticFunction();14echo Call::CONSTANT;15echo Call::$staticProperty;16$call->property;17$call->callMethod();18Call::callStaticMethod();19callFunction();20Call::callStaticFunction();21echo Call::CONSTANT;22echo Call::$staticProperty;23$call->property;24$call->callMethod();25Call::callStaticMethod();26callFunction();27Call::callStaticFunction();28echo Call::CONSTANT;29echo Call::$staticProperty;30$call->property;31$call->callMethod();32Call::callStaticMethod();33callFunction();34Call::callStaticFunction();35echo Call::CONSTANT;36echo Call::$staticProperty;37$call->property;38$call->callMethod();39Call::callStaticMethod();

Full Screen

Full Screen

Call

Using AI Code Generation

copy

Full Screen

1$call = new Call();2$call->setCallName('test');3$call->setCallDescription('test');4$call->setCallStatus('test');5$call->setCallDate('test');6$call->setCallTime('test');7$call->setCallDuration('test');8$call->setCallPhoneNumber('test');9$call->setCallCost('test');10$call->setCallType('test');11$call->setCallDirection('test');12$call->setCallSource('test');13$call->setCallDestination('test');14$call->setCallIsArchived('test');15$call->setCallIsDeleted('test');16$call->setCallIsSpam('test');17$call->setCallIsRead('test');18$call->setCallIsUnread('test');19$call->setCallIsImportant('test');20$call->setCallIsReplied('test');21$call->setCallIsForwarded('test');22$call->setCallIsSent('test');23$call->setCallIsReceived('test');24$call->setCallIsDraft('test');25$call->setCallIsTrashed('test');26$call->setCallIsStarred('test');27$call->setCallIsUnstarred('test');28$call->setCallIsShared('test');29$call->setCallIsUnshared('test');30$call->setCallIsSharedToMe('test');31$call->setCallIsUnsharedToMe('test');32$call->setCallIsSharedToOthers('test');33$call->setCallIsUnsharedToOthers('test');34$call->setCallIsSharedToAll('test');35$call->setCallIsUnsharedToAll('test');36$call->setCallIsSharedToEveryone('test');37$call->setCallIsUnsharedToEveryone('test');38$call->setCallIsSharedToFriends('test');39$call->setCallIsUnsharedToFriends('test');40$call->setCallIsSharedToFamily('test');41$call->setCallIsUnsharedToFamily('test');42$call->setCallIsSharedToColleagues('test');43$call->setCallIsUnsharedToColleagues('test');44$call->setCallIsSharedToOthers('test');45$call->setCallIsUnsharedToOthers('test');46$call->setCallIsSharedToEveryoneElse('

Full Screen

Full Screen

Call

Using AI Code Generation

copy

Full Screen

1require_once('Call.php');2$call = new Call();3$call->setCallId(123);4$call->setCallStatus('connected');5$call->setCallFrom('9999999999');6$call->setCallTo('9999999999');7$call->setCallDirection('inbound');8$call->setCallDuration(10);9echo $call->getCallId();10echo $call->getCallStatus();11echo $call->getCallFrom();12echo $call->getCallTo();13echo $call->getCallDirection();14echo $call->getCallDuration();15echo $call->getCallRecordUrl();16{"call_id":123,"call_status":"connected","call_from":"9999999999","call_to":"9999999999","call_direction":"inbound","call_duration":10,"call_record_url":"http:\/\/localhost\/record.mp3"}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful