6.3. Profiler Traits

Profiler traits assists with troubleshooting code.

6.3.1. Caller

The caller trait profiles meta information about the current method and the method that called it. Mounting this trait can be done with the following example.

use Cradle\Profiler\CallerTrait

class MyClass
{
    use CallerTrait;
}

The caller trait adds on two method to your class called getCaller and getCallee. The following shows how these method can be used.

$this->getCaller(); //--> ['file', 'line', 'class', 'method' ...]
$this->getCallee(); //--> ['file', 'line', 'class', 'method' ...]

6.3.2. Inspector

The inspector trait profiles class properties in certain stages. Mounting this trait can be done with the following example.

use Cradle\Profiler\InspectorTrait

class MyClass
{
    use InspectorTrait;
}

The inspector trait adds on just one method to your class called inspect which can be used in various ways. The following shows how this method can be used.

//echo MyClass->protectedProperty
$this->inspect('protectedProperty');

//echo MyClass->protectedProperty after `someMethod` was called
$this->inspect('protectedProperty', true)->someMethod();

6.3.3. Logger

The logger trait enables a clean way to take notes. Mounting this trait can be done with the following example.

use Cradle\Profiler\LoggerTrait

class MyClass
{
    use LoggerTrait;
}

The logger trait adds on two method to your class called addLogger and log which can be used in various ways. The following shows how these method can be used.

$this->addLogger(function($message) {
    //Do something
});

$this->log('Something has happened');