バージョン選択

フォーラム

メニュー

オンライン状況

79 人のユーザが現在オンラインです。 (68 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 79
もっと...

サイト内検索

質問 > その他 > 共通クラス内で「フロント機能」 or 「管理機能」の判定

その他

新規スレッドを追加する

フラット表示 前のトピック | 次のトピック
投稿者 スレッド
ramrun
投稿日時: 2009/5/7 0:54
対応状況: −−−
仙人
登録日: 2006/11/3
居住地:
投稿: 789
Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定
引用:
try/catch と異なり、特定のエラーが特定の Page クラスで発生した場合に、固有の処理を行いたいといったケースが少々難しそうですね。

require_base.phpあたりでset_error_handlerして、LC_Pageでそれまでに捕まえたエラーをウンヌンするという考えでした。

単にエラーになりそうな箇所をset_error_handlerとrestre_error_handlerでサンドイッチして、その間のエラーだけ収集したほうがいいかな。

<?php
/* ▼▼  ErrorHandler  ▼▼ */
class ErrorHandler {
  var $list = array();
  
  function ErrorHandler($name = '') {
    static $err_stock = array();
    
    $this->name = $name;
    $this->list =& $err_stock;
    $this->pos = count($this->list);
    
    if(version_compare(phpversion(), '5.0.0', '>=')) {
      set_error_handler(array(&$this, 'set'), E_ALL);
    } else {
      set_error_handler(array(&$this, 'set'));
    }
    echo "▼ $this->name エラーハンドラをセットしました\n";
    register_shutdown_function(array(&$this, 'destroy'));
  }
  
  function set($errno, $errstr, $errfile, $errline) {
    for($i = 0; $i < ($this->pos + 1); $i++) {
      $this->list[$i][] = "[$errno] $errstr $errfile $errline";
    }
  }
  
  function get() {
    $message = '';
    while(count($this->list[$this->pos])) {
      $message .= $this->name . array_pop($this->list[$this->pos]) . "\n";
    }
    return $message;
  }
  
  function isError() {
    return !empty($this->list[$this->pos]);
  }
  
  function reset() {
    restore_error_handler();
    unset($this->list[$this->pos]);
    echo "▲ $this->name エラーハンドラを破棄しました\n";
  }
  
  function destroy() {
    unset($this->list);
    restore_error_handler();
  }
}

/* ▼▼  Mail  ▼▼ */

class Helper_Mail {
  function sendOrder() {
    $objMail = new Send_Mail_Ex;
    
    $objErr = new ErrorHandler('['.get_class($this).']');  // ▼▼ set_error_handler    ▼▼
      $objMail->sendMail();
    if($objErr->isError()) {
      echo "エラー処理\n";
    }
    $objErr->reset();                                      // ▲▲ restre_error_handler ▲▲
  }
}

class Send_Mail_Ex extends Send_Mail{
  function Send_Mail_Ex() {
    parent::Send_Mail();
  }
}

class Send_Mail {
  function Send_Mail() {
    $buf = 1 / 0; // error
  }
  
  function sendMail() {
    trigger_error('Send_Mail の sendMail() でエラー'); // error
  }
}

/* ▼▼  LC_Page_hoge  ▼▼ */

trigger_error('set_error_handlerする前にtrigger_error');

echo "<pre>";

$obj = new ErrorHandler('[LC_Page_hoge1]');  // ▼▼ set_error_handler    ▼▼
  trigger_error('LC_Page_hoge の process() でエラー'); // error
  $c = new Helper_Mail;
  $c->sendOrder();
echo $obj->get();
$obj->reset();                               // ▲▲ restre_error_handler ▲▲

$obj = new ErrorHandler('[LC_Page_hoge2]');  // ▼▼ set_error_handler    ▼▼
  $objMail = new Send_Mail_Ex(); // error
echo $obj->get();
$obj->reset();                               // ▲▲ restre_error_handler ▲▲

echo "</pre>";

?>
追記:入れ子にしたときに使えなさそな動きをしていたので修正(汗)
フラット表示 前のトピック | 次のトピック


題名 投稿者 日時
   共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 13:15
     Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 kishik 2009/4/30 14:27
       Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 15:01
         Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 kishik 2009/4/30 15:24
           Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 15:36
             Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 tao_s 2009/4/30 23:19
               Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 23:22
                 Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 23:27
                 Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 tao_s 2009/4/30 23:32
                   Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/4/30 23:43
                     Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 tao_s 2009/5/1 1:24
                       Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/1 1:56
                         Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 tao_s 2009/5/1 2:26
                           Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 ramrun 2009/5/1 21:45
                             Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/1 21:54
                               Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 ramrun 2009/5/1 22:06
                                 Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/1 22:38
                                   Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 ramrun 2009/5/2 1:24
                                     Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 nanasess 2009/5/2 8:57
                                       Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/2 11:08
                                         Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 nanasess 2009/5/2 12:51
                                           Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/2 15:47
                                             Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 ramrun 2009/5/4 1:09
                                               Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/6 12:09
                                               » Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 ramrun 2009/5/7 0:54
                                                   Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 seasoft 2009/5/7 20:08
                                                     Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 nanasess 2009/5/8 22:47
                                                       Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 ramrun 2009/5/9 9:35
                                                         Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 nanasess 2009/5/9 10:02
                                                           Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 seasoft 2009/5/9 10:54
                                                             Re: 共通クラス内での「フロント機能」 or 「管理機能」判定 ramrun 2009/5/9 14:05
                                     Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/5/2 10:50
                                 Re: 共通クラス内で「フロント機能」 or 「管理機能」の判定 seasoft 2009/9/7 19:27

 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,973名です
総投稿数は110,019件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1296
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.