Files
kiri-core/Annotation/Annotation.php
T

82 lines
1.3 KiB
PHP
Raw Normal View History

2020-12-14 19:03:05 +08:00
<?php
namespace Annotation;
2021-03-03 18:35:04 +08:00
use DirectoryIterator;
2020-12-14 19:03:05 +08:00
use Snowflake\Abstracts\Component;
2021-03-04 10:19:56 +08:00
use Snowflake\Exception\ComponentException;
2020-12-14 19:03:05 +08:00
/**
* Class Annotation
* @package Annotation
*/
class Annotation extends Component
{
2021-02-23 14:16:08 +08:00
2021-03-03 18:35:04 +08:00
private Loader $_loader;
2021-02-23 14:16:08 +08:00
2021-03-03 18:35:04 +08:00
public function init(): void
2021-02-23 14:16:08 +08:00
{
2021-03-03 18:35:04 +08:00
$this->_loader = new Loader();
2021-02-23 14:16:08 +08:00
}
/**
* @param string $className
2021-03-03 20:06:32 +08:00
* @param string $method
2021-02-23 14:16:08 +08:00
* @return array 根据类名获取注解
* 根据类名获取注解
*/
2021-03-03 23:47:19 +08:00
public function getMethods(string $className, string $method = ''): mixed
2021-02-23 14:16:08 +08:00
{
2021-03-03 20:06:32 +08:00
return $this->_loader->getMethod($className, $method);
2021-02-23 14:16:08 +08:00
}
/**
2021-03-03 18:35:04 +08:00
* @param object $class
2021-02-23 14:16:08 +08:00
*/
2021-03-03 18:35:04 +08:00
public function injectProperty(object $class)
2021-02-23 14:16:08 +08:00
{
2021-03-03 18:35:04 +08:00
$this->_loader->injectProperty(get_class($class), $class);
2021-02-23 14:16:08 +08:00
}
/**
2021-03-03 18:35:04 +08:00
* @param string $path
2021-02-23 14:16:08 +08:00
* @param string $namespace
* @param string $alias
2021-02-26 10:37:12 +08:00
* @return void
2021-03-04 10:19:56 +08:00
* @throws ComponentException
2021-02-26 10:37:12 +08:00
*/
2021-03-03 18:35:04 +08:00
public function read(string $path, string $namespace, string $alias = 'root'): void
2021-02-23 14:16:08 +08:00
{
2021-03-03 18:35:04 +08:00
$this->_loader->_scanDir(new DirectoryIterator($path), $namespace);
2021-02-23 14:16:08 +08:00
}
2021-03-03 19:02:27 +08:00
2021-03-04 10:19:56 +08:00
/**
* @param string $dir
*/
public function instanceDirectoryFiles(string $dir)
{
$this->_loader->loadByDirectory($dir);
}
2021-03-03 19:02:27 +08:00
/**
* @param string $filename
* @return mixed
*/
public function getFilename(string $filename): mixed
{
return $this->_loader->getClassByFilepath($filename);
}
2020-12-14 19:03:05 +08:00
}