library/log4php/LoggerThrowableInformation.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     4  * contributor license agreements. See the NOTICE file distributed with
       
     5  * this work for additional information regarding copyright ownership.
       
     6  * The ASF licenses this file to You under the Apache License, Version 2.0
       
     7  * (the "License"); you may not use this file except in compliance with
       
     8  * the License. You may obtain a copy of the License at
       
     9  *
       
    10  *       http://www.apache.org/licenses/LICENSE-2.0
       
    11  *
       
    12  * Unless required by applicable law or agreed to in writing, software
       
    13  * distributed under the License is distributed on an "AS IS" BASIS,
       
    14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    15  * See the License for the specific language governing permissions and
       
    16  * limitations under the License.
       
    17  *
       
    18  * @package log4php
       
    19  */
       
    20 
       
    21 /**
       
    22  * The internal representation of throwables.
       
    23  *
       
    24  * @package log4php
       
    25  * @since 2.1
       
    26  */
       
    27 class LoggerThrowableInformation {
       
    28 
       
    29     /** @var Exception Throwable to log */
       
    30     private $throwable;
       
    31 
       
    32     /** @var array Array of throwable messages */
       
    33     private $throwableArray;
       
    34 
       
    35     /**
       
    36      * Create a new instance
       
    37      *
       
    38      * @param $throwable - a throwable as a exception
       
    39      * @param $logger - Logger reference
       
    40      */
       
    41     public function __construct(Exception $throwable) {
       
    42         $this->throwable = $throwable;
       
    43     }
       
    44 
       
    45     /**
       
    46      * Return source exception
       
    47      *
       
    48      * @return Exception
       
    49      */
       
    50     public function getThrowable() {
       
    51         return $this->throwable;
       
    52     }
       
    53 
       
    54     /**
       
    55      * @desc Returns string representation of throwable
       
    56      *
       
    57      * @return array
       
    58      */
       
    59     public function getStringRepresentation() {
       
    60         if (!is_array($this->throwableArray)) {
       
    61             $renderer = new LoggerRendererException();
       
    62 
       
    63             $this->throwableArray = explode("\n", $renderer->render($this->throwable));
       
    64         }
       
    65 
       
    66         return $this->throwableArray;
       
    67     }
       
    68 }