Глава 49: класс атрибута

This commit is contained in:
Igor Simdyanov
2022-06-25 13:26:08 +03:00
parent f75a094250
commit ef19283c2c
3 changed files with 47 additions and 0 deletions

11
attributes/model.php Normal file
View File

@ -0,0 +1,11 @@
<?php
spl_autoload_register();
$reflect = new ReflectionClass(Model\User::class);
echo '<pre>';
foreach ($reflect->getAttributes() as $attribute) {
echo $attribute->getName() . PHP_EOL;
echo $attribute->newInstance()->info() . PHP_EOL;;
}
echo '</pre>';

23
attributes/model/user.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace Model;
use Attribute;
#[Model]
class User
{
}
#[Attribute]
class Model
{
private const INFO = <<<TEXT
Классы моделей предназначены для представления содержимого базы данных
TEXT;
public function __construct() {}
public function info()
{
return self::INFO;
}
}

View File

@ -0,0 +1,13 @@
<?php
spl_autoload_register();
use Model\User as User;
use Model\Model as Model;
$reflect = new ReflectionClass(User::class);
echo '<pre>';
foreach ($reflect->getAttributes(Model::class) as $attribute) {
echo $attribute->getName() . PHP_EOL;
echo $attribute->newInstance()->info() . PHP_EOL;;
}
echo '</pre>';