Files
zhamao-framework/src/ZM/Annotation/AnnotationBase.php

47 lines
1.1 KiB
PHP
Raw Normal View History

2020-03-02 16:14:20 +08:00
<?php
declare(strict_types=1);
2020-03-02 16:14:20 +08:00
namespace ZM\Annotation;
2022-04-03 01:47:38 +08:00
use ArrayIterator;
2020-03-02 16:14:20 +08:00
use Closure;
2022-04-03 01:47:38 +08:00
use IteratorAggregate;
use Traversable;
2020-03-02 16:14:20 +08:00
2022-04-03 01:47:38 +08:00
abstract class AnnotationBase implements IteratorAggregate
2020-03-02 16:14:20 +08:00
{
public $method = '';
2020-03-02 16:14:20 +08:00
public $class = '';
2020-03-02 16:14:20 +08:00
public function __toString()
{
$str = __CLASS__ . ': ';
2020-03-02 16:14:20 +08:00
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';
}
2020-03-02 16:14:20 +08:00
}
return $str;
}
2022-04-03 01:47:38 +08:00
public function getIterator(): Traversable
{
return new ArrayIterator($this);
}
}