예제 #1
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|ModelInterface $nameOrModel The script/resource process, or a view model
  * @param  null|array|\ArrayAccess $values Values to use during rendering
  * @return string The script output.
  */
 public function render($nameOrModel, $values = null)
 {
     if ($values === null) {
         $values = array();
     }
     if (is_string($nameOrModel)) {
         $values['payload'] = $nameOrModel;
         $nameOrModel = new TwilioModel($values);
     }
     if ($nameOrModel instanceof ViewModel) {
         if (!$nameOrModel instanceof TwilioModel) {
             $vars = $nameOrModel->getVariables();
             $options = $nameOrModel->getOptions();
             $nameOrModel = new TwilioModel($vars, $options);
         }
     }
     if (!$nameOrModel instanceof TwilioModel) {
         throw new \InvalidArgumentException(sprintf('%s expects a ViewModel or a string feed type as the first argument; received "%s"', __METHOD__, is_object($nameOrModel) ? get_class($nameOrModel) : gettype($nameOrModel)));
     }
     // Get feed and type
     $response = $nameOrModel->getResponse();
     if ($response instanceof Services_Twilio_Twiml) {
         $response = $response->__toString();
     }
     return $response;
 }
예제 #2
0
 public function processTwilio()
 {
     $responder = $this->getResponder();
     $response = $responder->getTwilioResponse();
     $viewModel = new TwilioModel();
     $viewModel->setResponse($response);
     return $viewModel;
 }
 public function testCanRenderStringPayload()
 {
     $twiml = '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Hello</Say></Response>';
     $model = new TwilioModel(array('payload' => $twiml));
     $model->setContentType('application/xml');
     $test = $this->renderer->render($model);
     $this->assertEquals('<?xml version="1.0" encoding="UTF-8"?><Response><Say>Hello</Say></Response>', str_replace("\n", "", $test));
 }
예제 #4
0
 public function testTextContentTypeIsCalculatedForStringResponse()
 {
     $this->model->setResponse('String Response');
     $this->assertEquals('text/plain', $this->model->getContentType());
 }