Example #1
0
 public function send()
 {
     /** @var \Rj\SmsGate\Herald $mailer */
     $gate = $this->getDI()->getShared('SmsGate');
     try {
         if ($num = Helper::sanitizePhone($this->phone)) {
             $result = $gate->send($num, $this->text, ['uid' => $this->sms_queue_id]);
         } else {
             trigger_error('Invalid phone number ' . $this->phone);
             $result = false;
         }
         if ($result) {
             $this->sent_at = date('Y-m-d H:i:s');
             $this->err = null;
             $this->status = static::STATUS_OK;
         } else {
             if ($error = error_get_last()) {
                 $this->err = $error['message'];
                 $this->status = static::STATUS_ERR;
             } else {
                 $this->status = static::STATUS_ERR;
             }
         }
     } catch (Exception $e) {
         $this->err = $e->getMessage();
         $this->status = static::STATUS_ERR;
     }
     $this->save();
     Assert::noMessages($this);
 }
Example #2
0
 public function indexAction()
 {
     $this->view->noRender();
     Assert::found($query = $this->dispatcher->getParam('query'));
     Assert::found($pkg = $this->getPackage($query));
     $dst = DOCROOT . '/../public/media/';
     @Helper::mkdir($dst . dirname($query), 0777);
     Assert::found($f = fopen('zip://' . $pkg . '#' . $query, 'r'));
     Assert::true($d = fopen($dst . $query, 'w'));
     $content = '';
     while (!feof($f)) {
         $content .= $data = fread($f, 8 * 1024);
         fwrite($d, $data);
     }
     fclose($f);
     $mime = null;
     if ($ext = strtolower(pathinfo($query, PATHINFO_EXTENSION))) {
         $mime = empty(FileInfo::$types[$ext]) ? null : FileInfo::$types[$ext];
     }
     if ($mime) {
         $this->response->setHeader('Content-Type', $mime);
     }
     return $this->response->setContent($content);
 }