for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\component\debug\attach;
/**
* 多行附加属性
*/
trait AttachTrait
{
* 属性数组
*
* @var array
protected $attribute;
* 附加数组
protected $attach;
public function mergeAttribute(array $value)
$this->attribute = array_merge($this->attribute, $value);
}
protected function analyse(array $context)
$replace = [];
foreach ($context as $key => $val) {
if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
$replace['{' . $key . '}'] = $val;
} else {
$this->attach[$key] = $val;
return $replace;
public function interpolate(string $message, array $context)
$replace = $this->analyse($context);
foreach ($this->attribute as $key => $val) {
$replace['%' . $key . '%'] = $val;
$message = strtr($message, $replace);
foreach ($this->attach as $name => $value) {
$message.=PHP_EOL.$name.'<' . get_class($val).'>'.PHP_EOL;
$val
foreach
44
if ($value instanceof AttachValueInterface) {
$message.= $value->getLogAttach().PHP_EOL;
} elseif ($value instanceof \Exception) {
$message.= DumpTrait::dumpException($value).PHP_EOL;
$message.= DumpTrait::parameterToString($value).PHP_EOL;
return $message;