Files
kiri-core/kiri-note/Note.php
T

87 lines
1.3 KiB
PHP
Raw Normal View History

2020-12-14 19:03:05 +08:00
<?php
2021-11-30 15:10:01 +08:00
namespace Note;
2020-12-14 19:03:05 +08:00
2021-03-03 18:35:04 +08:00
use DirectoryIterator;
2021-03-23 16:14:05 +08:00
use Exception;
2021-07-27 16:15:28 +08:00
use ReflectionException;
2021-08-11 01:04:57 +08:00
use Kiri\Abstracts\Component;
2020-12-14 19:03:05 +08:00
/**
2021-11-30 15:10:01 +08:00
* Class Note
* @package Note
2020-12-14 19:03:05 +08:00
*/
2021-11-30 15:10:01 +08:00
class Note extends Component
2020-12-14 19:03:05 +08:00
{
2021-02-23 14:16:08 +08:00
2021-04-25 17:01:57 +08:00
private Loader $_loader;
2021-08-29 04:06:49 +08:00
/**
*
*/
2021-04-25 17:01:57 +08:00
public function init(): void
{
$this->_loader = new Loader();
}
/**
* @return Loader
*/
public function getLoader(): Loader
{
return $this->_loader;
}
/**
* @param Loader $loader
* @return Loader
*/
public function setLoader(Loader $loader): Loader
{
return $this->_loader = $loader;
}
2021-08-29 04:06:49 +08:00
2021-04-25 17:01:57 +08:00
/**
* @param object $class
2021-07-27 16:15:28 +08:00
* @throws ReflectionException
2021-04-25 17:01:57 +08:00
*/
public function injectProperty(object $class)
{
$this->_loader->injectProperty($class::class, $class);
}
/**
* @param string $path
* @param string $namespace
2021-08-05 16:30:45 +08:00
* @param array $exclude
2021-09-06 14:30:20 +08:00
* @return static
2021-04-25 17:01:57 +08:00
* @throws Exception
*/
2021-09-06 14:30:20 +08:00
public function read(string $path, string $namespace = 'App', array $exclude = []): static
2021-04-25 17:01:57 +08:00
{
2021-08-05 16:30:45 +08:00
$this->_loader->_scanDir(new DirectoryIterator($path), $namespace, $exclude);
2021-09-06 14:30:20 +08:00
return $this;
2021-04-25 17:01:57 +08:00
}
/**
* @param string $dir
2021-08-05 15:55:27 +08:00
* @param array $exclude
2021-07-27 16:15:28 +08:00
* @return array
2021-04-25 17:01:57 +08:00
* @throws Exception
*/
2021-08-05 15:55:27 +08:00
public function runtime(string $dir, array $exclude = []): array
2021-04-25 17:01:57 +08:00
{
2021-08-05 15:55:27 +08:00
return $this->_loader->loadByDirectory($dir, $exclude);
2021-04-25 17:01:57 +08:00
}
2020-12-14 19:03:05 +08:00
}