Maslosoft Signals API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
<?php
/**
* This software package is licensed under `AGPL, Commercial` license[s].
*
* @package maslosoft/signals
* @license AGPL, Commercial
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
* @link https://maslosoft.com/signals/
*/
namespace Maslosoft\Signals\Helpers;
use Maslosoft\Signals\Meta\SignalsAnnotation;
use ReflectionClass;
/**
* ExceptionFormatter
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class ExceptionFormatter
{
public static function formatForAnnotation(SignalsAnnotation $annotation, $class)
{
$shortName = (new ReflectionClass($annotation))->getShortName();
$type = preg_replace('~Annotation$~', '', $shortName);
$typeName = $annotation->getMeta()->type()->name;
$name = $annotation->name;
// Always available params
$params = [
$type,
$typeName,
];
// Prepare first part of message
if (empty($class))
{
$msg = 'Could not resolve class name';
}
else
{
array_unshift($params, $class);
$msg = 'Class `%s` not found';
}
// Prepare location of bogus annotation
if ($name === $typeName)
{
$msgOn = 'for `@%s` annotation on `%s`';
}
else
{
$params[] = $name;
$msgOn = 'for `@%s` annotation on `%s::%s`';
}
$msg = implode(' ', [$msg, $msgOn]);
return vsprintf($msg, $params);
}
}
API documentation generated by ApiGen