Beispiel #1
0
 public static function detectAttachmentType($url)
 {
     if (giga_match('%(.jpg|.png|.bmp|.gif|.jpeg|.tiff|.gif)%', $url)) {
         return 'image';
     }
     if (giga_match('%(.avi|.flv|.mp4|.mkv|.3gp|.webm|.vob|.mov|.rm|.rmvb)%', $url)) {
         return 'video';
     }
     if (giga_match('%(.mp3|.wma|.midi|.au)%', $url)) {
         return 'audio';
     }
     return null;
 }
Beispiel #2
0
 public function testPipelines()
 {
     $pattern = '(foo|bar)';
     $this->assertEquals(1, giga_match($pattern, 'foo'));
     $this->assertEquals(0, giga_match($pattern, 'baz'));
 }
Beispiel #3
0
 /**
  * Response sender message
  *
  * @param $nodes
  * @param null $lead_id
  */
 public function response($nodes, $lead_id = null)
 {
     if (is_null($lead_id)) {
         $lead_id = $this->conversation->get('lead_id');
     }
     foreach ($nodes as $node) {
         /** New wait */
         if (!empty($node->wait)) {
             $this->storage->set($lead_id, '_wait', $node->wait);
         }
         // Backward compatibility
         if (array_key_exists('type', $node->answers)) {
             $node->answers = [$node->answers];
         }
         foreach ($node->answers as $answer) {
             /** Process dynamic content */
             if (isset($answer['type'])) {
                 // Backward compatibility
                 if (isset($answer['callback'])) {
                     $answer['content'] = $answer['callback'];
                 }
                 if (giga_match('%SerializableClosure%', $answer['content'])) {
                     $answer['content'] = $this->serializer->unserialize($answer['content']);
                 }
                 $return = DynamicParser::parse($answer);
                 // If the callback return, we'll send that message to user.
                 if ($return != null || !empty($return)) {
                     $answer = $this->model->parseWithoutSave($return);
                     // Answer == 0 means that answers is already parsed and it's a single message.
                     if ($answer != false) {
                         $this->request->sendMessages($answer);
                     } else {
                         $this->request->sendMessage($return);
                     }
                     continue;
                 }
             }
             $this->request->sendMessage($answer);
         }
     }
 }