Index: trunk/extensions/DonationInterface/paypal_gateway/IPN/PaypalIPNListener.php |
— | — | @@ -49,21 +49,36 @@ |
50 | 50 | |
51 | 51 | class PaypalIPNProcessor { |
52 | 52 | |
53 | | - // set the apropriate logging level |
54 | | - $log_level = LOG_LEVEL_INFO; |
| 53 | + /** |
| 54 | + * @var string set the apropriate logging level |
| 55 | + */ |
| 56 | + protected $log_level = LOG_LEVEL_INFO; |
55 | 57 | |
56 | | - // path to Stomp |
57 | | - $stomp_path = "../../activemq_stomp/Stomp.php"; |
| 58 | + /** |
| 59 | + * @var string path to Stomp |
| 60 | + */ |
| 61 | + protected $stomp_path = "../../activemq_stomp/Stomp.php"; |
58 | 62 | |
59 | | - // path to pending queue |
60 | | - $pending_queue = '/queue/pending_paypal'; |
| 63 | + /** |
| 64 | + * @var string path to pending queue |
| 65 | + */ |
| 66 | + protected $pending_queue = '/queue/pending_paypal'; |
61 | 67 | |
62 | | - // path to the verified queue |
63 | | - $verified_queue = '/queue/donations'; |
| 68 | + /** |
| 69 | + * @var string path to the verified queue |
| 70 | + */ |
| 71 | + protected $verified_queue = '/queue/donations'; |
64 | 72 | |
65 | | - // URI to activeMQ |
66 | | - $activemq_stomp_uri = 'tcp://localhost:61613'; |
| 73 | + /** |
| 74 | + * @var string URI to activeMQ |
| 75 | + */ |
| 76 | + protected $activemq_stomp_uri = 'tcp://localhost:61613'; |
67 | 77 | |
| 78 | + /** |
| 79 | + * @var resource a file system pointer resource (usually made with fopen()) |
| 80 | + */ |
| 81 | + protected $output_handle = NULL; |
| 82 | + |
68 | 83 | /** |
69 | 84 | * Class constructor, sets configurable parameters |
70 | 85 | * |
— | — | @@ -77,8 +92,14 @@ |
78 | 93 | unset( $opts[ 'log_level'] ); |
79 | 94 | } |
80 | 95 | |
81 | | - $this->out( "Loading Paypal IPN processor" ); |
| 96 | + // prepare the output log file if necessary |
| 97 | + if ( array_key_exists( 'output_handle', $opts )) { |
| 98 | + $this->output_handle = $opts[ 'output_handle' ]; |
| 99 | + unset( $opts[ 'output_handle' ] ); |
| 100 | + } |
82 | 101 | |
| 102 | + $this->out( "Loading Paypal IPN processor with log level: " . $this->log_level ); |
| 103 | + |
83 | 104 | // set parameters |
84 | 105 | foreach ( $opts as $key => $value ) { |
85 | 106 | $this->{$key} = $value; |
— | — | @@ -371,7 +392,17 @@ |
372 | 393 | * @param $level the Level at which the message should be output. |
373 | 394 | */ |
374 | 395 | protected function out( $msg, $level=LOG_LEVEL_INFO ) { |
375 | | - if ( $this->log_level >= $level ) echo date( 'c' ) . ": " . $msg . "\n"; |
| 396 | + $out = NULL; |
| 397 | + |
| 398 | + // format the output message if the apropriate log level is set |
| 399 | + if ( $this->log_level >= $level ) $out = date( 'c' ) . ": " . $msg . "\n"; |
| 400 | + |
| 401 | + // if we have an output resource handle, write to the resource. otherwise, echo |
| 402 | + if ( $this->output_handle ) { |
| 403 | + fwrite( $this->output_handle, $out ); |
| 404 | + } else { |
| 405 | + echo $out; |
| 406 | + } |
376 | 407 | } |
377 | 408 | |
378 | 409 | public function __destruct() { |
Index: trunk/extensions/DonationInterface/paypal_gateway/IPN/StandaloneListener.php.example |
— | — | @@ -11,9 +11,12 @@ |
12 | 12 | * @author Arthur Richards <arichards@wikimedia.org> |
13 | 13 | */ |
14 | 14 | |
15 | | -// turn on output buffering so we can capture the output |
16 | | -ob_start(); |
17 | 15 | |
| 16 | +// define a file where you can log the output from the listener |
| 17 | +$log_file = "out_" . date( 'Ymd' ) . '.log'; |
| 18 | +// create a file resource pointer |
| 19 | +$output_handle = fopen( $log_file, 'a' ); |
| 20 | + |
18 | 21 | // require the actual listener |
19 | 22 | require_once( '/path/to/PaypalIPNListener.php' ); |
20 | 23 | |
— | — | @@ -28,10 +31,9 @@ |
29 | 32 | 'contrib_db_username' => 'user', |
30 | 33 | 'contrib_db_password' => 'password', |
31 | 34 | 'contrib_db_name' => 'drupal', |
| 35 | + 'output_handle' => $output_handle, // filesystem pointer resource for logging output |
32 | 36 | ); |
33 | 37 | |
34 | | -// define a file where you can log the output from the listener |
35 | | -$log_file = "out_" . date( 'Ymd' ) . '.log'; //for logging the output |
36 | 38 | |
37 | 39 | // instantaite the listener with our config options |
38 | 40 | $listener = new PaypalIPNProcessor( $config ); |
— | — | @@ -42,13 +44,6 @@ |
43 | 45 | // shutdown the listener |
44 | 46 | unset( $listener ); |
45 | 47 | |
46 | | -// get the output from the buffer |
47 | | -$output = ob_get_clean(); |
48 | | -ob_flush(); |
49 | | - |
50 | | -// open our log file |
51 | | -$handle = fopen( $log_file, 'a' ); |
52 | | - |
53 | | -// write the output to the log file |
54 | | -fwrite( $handle, $output ); |
| 48 | +// cleanly close the file pointer for output |
| 49 | +fclose( $output_handle ); |
55 | 50 | ?> |