Files
zhamao-framework/src/ZM/Annotation/AnnotationBase.php
2022-04-03 02:17:58 +08:00

47 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace ZM\Annotation;
use ArrayIterator;
use Closure;
use IteratorAggregate;
use Traversable;
abstract class AnnotationBase implements IteratorAggregate
{
public $method = '';
public $class = '';
public function __toString()
{
$str = __CLASS__ . ': ';
foreach ($this as $k => $v) {
$str .= "\n\t" . $k . ' => ';
if (is_string($v)) {
$str .= "\"{$v}\"";
} elseif (is_numeric($v)) {
$str .= $v;
} elseif (is_bool($v)) {
$str .= ($v ? 'TRUE' : 'FALSE');
} elseif (is_array($v)) {
$str .= json_encode($v, JSON_UNESCAPED_UNICODE);
} elseif ($v instanceof Closure) {
$str .= '@AnonymousFunction';
} elseif (is_null($v)) {
$str .= 'NULL';
} else {
$str .= '@Unknown';
}
}
return $str;
}
public function getIterator(): Traversable
{
return new ArrayIterator($this);
}
}