library/log4php/LoggerLocationInfo.php
changeset 46 f11c31f7fa3e
parent 45 a56e7f9a0463
child 47 03388ec805b4
equal deleted inserted replaced
45:a56e7f9a0463 46:f11c31f7fa3e
     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 caller location information.
       
    23  *
       
    24  * @version $Revision: 1379738 $
       
    25  * @package log4php
       
    26  * @since 0.3
       
    27  */
       
    28 class LoggerLocationInfo {
       
    29 
       
    30     /** The value to return when the location information is not available. */
       
    31     const LOCATION_INFO_NA = 'NA';
       
    32 
       
    33     /**
       
    34      * Caller line number.
       
    35      * @var integer
       
    36      */
       
    37     protected $lineNumber;
       
    38 
       
    39     /**
       
    40      * Caller file name.
       
    41      * @var string
       
    42      */
       
    43     protected $fileName;
       
    44 
       
    45     /**
       
    46      * Caller class name.
       
    47      * @var string
       
    48      */
       
    49     protected $className;
       
    50 
       
    51     /**
       
    52      * Caller method name.
       
    53      * @var string
       
    54      */
       
    55     protected $methodName;
       
    56 
       
    57     /**
       
    58      * All the information combined.
       
    59      * @var string
       
    60      */
       
    61     protected $fullInfo;
       
    62 
       
    63     /**
       
    64      * Instantiate location information based on a {@link PHP_MANUAL#debug_backtrace}.
       
    65      *
       
    66      * @param array $trace
       
    67      * @param mixed $caller
       
    68      */
       
    69     public function __construct($trace, $fqcn = null) {
       
    70         $this->lineNumber = isset($trace['line']) ? $trace['line'] : null;
       
    71         $this->fileName = isset($trace['file']) ? $trace['file'] : null;
       
    72         $this->className = isset($trace['class']) ? $trace['class'] : null;
       
    73         $this->methodName = isset($trace['function']) ? $trace['function'] : null;
       
    74         $this->fullInfo = $this->getClassName() . '.' . $this->getMethodName() .
       
    75             '(' . $this->getFileName() . ':' . $this->getLineNumber() . ')';
       
    76     }
       
    77 
       
    78     /** Returns the caller class name. */
       
    79     public function getClassName() {
       
    80         return ($this->className === null) ? self::LOCATION_INFO_NA : $this->className;
       
    81     }
       
    82 
       
    83     /** Returns the caller file name. */
       
    84     public function getFileName() {
       
    85         return ($this->fileName === null) ? self::LOCATION_INFO_NA : $this->fileName;
       
    86     }
       
    87 
       
    88     /** Returns the caller line number. */
       
    89     public function getLineNumber() {
       
    90         return ($this->lineNumber === null) ? self::LOCATION_INFO_NA : $this->lineNumber;
       
    91     }
       
    92 
       
    93     /** Returns the caller method name. */
       
    94     public function getMethodName() {
       
    95         return ($this->methodName === null) ? self::LOCATION_INFO_NA : $this->methodName;
       
    96     }
       
    97 
       
    98     /** Returns the full information of the caller. */
       
    99     public function getFullInfo() {
       
   100         return ($this->fullInfo === null) ? self::LOCATION_INFO_NA : $this->fullInfo;
       
   101     }
       
   102 
       
   103 }