2014-04-07 5 views
0

PHP 응용 프로그램에서 여러 개의 전자 메일을 보내고 있는데 보내지 못한 전자 메일을 사용자에게 알리고 싶습니다.PHP : 예외를 throw하지 않고 오류 처리

몇 가지 방법은를 호출을 통해

  • 내가
  • 통화가가는 나머지 이메일의 전송을 종료 예외를 throw하지 않으려는 경우 오류 처리를 할 수있는 가장 우아한 방법은 무엇입니까

내가 원하는 것은 Suggestion :: notifyDeletionToAll()에서 $ notificationSucceeded를 SuggestionController에 어떻게 든 알맞게 모든 알림에서 가져 오는 것입니다.

모든 메서드를 통해 반환하는 것이 가장 좋은 방법 인 경우 호출 스택의 깊이가 의심 스럽습니다. 특히 Suggestion :: cancel()의 반환 값이 이미있는 경우에는 특히 그렇습니다.

더 좋은 방법이 있습니까?

컨트롤러 :

class SuggestionController { 
    function cancelSuggestion($suggestionId) 
    { 
     $suggestion = new Suggestion(); 
     $suggestion->fetch($suggestionId); 

     $suggestionDeleted = $suggestion->cancel(); 

     print json_encode(array(
      'status' => 'ok', 
      'suggestionDeleted' => $suggestionDeleted, 
     )); 
    } 
} 

제안 클래스 :

class Suggestion { 

    /** 
    * Cancels membership of current user in the suggestion 
    */ 
    public function cancel() 
    { 
     $this->cancelMembership(); 

     if (!$this->hasAcceptedMembers()) { 
      $this->deleteAndNotify(); 
      return true; 
     } 

     return false; 
    } 

    /** 
    * Deletes the suggestion and notifies all the users in it 
    */ 
    private function deleteAndNotify() 
    { 
     $this->notifyDeletionToAll(); 
     DB::inst()->query("DELETE FROM suggestions WHERE id = {$this->id}"); 
    } 

    /** 
    * Notifies about the deletion of the suggestion to all members (users in the suggestion) 
    */ 
    private function notifyDeletionToAll() 
    { 
     $result = DB::inst()->query("SELECT user_id FROM suggestions_users 
      WHERE suggestion_id = {$this->id}"); 
     while ($member_id = DB::inst()->fetchFirstField($result)) { 
      $member = new User(); 
      $member->fetch($member_id); 
      $notificationSucceeded = $member->notifySuggestionDeleted($this); 
     } 
    } 
} 
+0

당신의 질문은 명확하지 않다. 세부 정보 추가 : 중요한 코드 조각, 원하는 동작 설명 e t.c –

+0

"호출이 여러 메소드 호출을 거쳤다"고 했으므로 메소드의 반환 값을 사용하고 "false"가 반환 될 때마다 "이메일 # 1이 (를) 보낼 수 없습니다"라는 줄을 변수에 추가 하시겠습니까? – FanaticD

+0

빠른 응답을 보내 주셔서 감사합니다. – Ipa

답변

1

나는 명확하게 질문을 이해할 수 없습니다. 그러나 이것이 당신을 도울 것이라고 희망한다.

$successfully_sent_arr = array(); 
$failure_notsent_arr = array(); 
if($mail->Send()) 
{ 
    $successfully_sent_arr[] = $to_email; 
    //Once the last loop occurs, update this array in database 
} 
else 
{ 
    $failure_notsent_arr[] = $to_email; 
    //Once the last loop occurs, update this array in database 
} 
+0

나는 그 질문을 명확히했다. – Ipa

+0

@Ipa Ok가 확인하고 다시 돌아옵니다. –

관련 문제