Files
kiri-core/Annotation/Annotation.php
T

104 lines
1.8 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;
2021-03-23 16:14:05 +08:00
use Exception;
2020-12-14 19:03:05 +08:00
use Snowflake\Abstracts\Component;
/**
* Class Annotation
* @package Annotation
*/
class Annotation extends Component
{
2021-02-23 14:16:08 +08:00
2021-04-07 02:21:29 +08:00
private Loader $_loader;
public function init(): void
{
$this->_loader = new Loader();
}
/**
* @return Loader
*/
public function getLoader(): Loader
{
return $this->_loader;
}
2021-04-08 00:09:04 +08:00
/**
* @param Loader $loader
* @return Loader
*/
public function setLoader(Loader $loader): Loader
{
return $this->_loader = $loader;
}
2021-04-07 02:21:29 +08:00
/**
* @param string $className
* @param string $method
* @return array 根据类名获取注解
* 根据类名获取注解
*/
public function getMethods(string $className, string $method = ''): mixed
{
return $this->_loader->getMethod($className, $method);
}
/**
* @param object $class
*/
public function injectProperty(object $class)
{
$this->_loader->injectProperty(get_class($class), $class);
}
/**
* @param string $path
* @param string $namespace
* @param string $alias
* @return void
* @throws Exception
*/
public function read(string $path, string $namespace, string $alias = 'root'): void
{
$this->_loader->_scanDir(new DirectoryIterator($path), $namespace);
}
/**
* @param string $dir
2021-04-08 01:54:16 +08:00
* @param string|null $outPath
2021-04-07 02:21:29 +08:00
* @throws Exception
*/
2021-04-08 00:38:29 +08:00
public function instanceDirectoryFiles(string $dir, ?string $outPath = null)
2021-04-07 02:21:29 +08:00
{
2021-04-08 00:38:29 +08:00
$this->_loader->loadByDirectory($dir, $outPath);
}
2021-04-07 02:21:29 +08:00
/**
* @param string $filename
* @return mixed
*/
public function getFilename(string $filename): mixed
{
return $this->_loader->getClassByFilepath($filename);
}
2021-03-03 19:02:27 +08:00
2020-12-14 19:03:05 +08:00
}