Hi @stelin
How to scan annotations in custom path or file in application initialize process?
I need to create some service which they may register some routes to api
application and some routes to backend
application.
In case, imagine i have a directory named UserService
and have two directories like Http\Api\SomeController
and Http\Backend\SomeController
, when running an application with context api
then this directory Http\Api\SomeController
must be scanned and in backend
context this directory: Http\Backend\SomeController
.
i create an annotation named Service
and in ServiceParser
check for input values which may be api
, backend
or both, then must tell swoft to scan related directories.
is it can be done now with swoft? or sowft has any solution to achieve this idea?
ServiceParser:
public function parse(int $type, $annotation): array
{
// Check instance
if ($type !== self::TYPE_CLASS) {
throw new HttpServerException('`@AbstractService` must be defined by class!');
}
// Register service
ServiceFactory::Register($this->className, $annotation->getContexts());
// Returns singleton options
return [$this->className, $this->className, Bean::SINGLETON, ''];
}
ServiceFactory:
public static function Register(string $class, array $contexts)
In Register
method 'll create an instance of given class and get its path and Swoft
must be notified to scan extra path for annotations.
Thanks a lot*
难道 swoft/http-client 组件,只适用于 swoft 1.X版本吗?
"HTTP Client Compoment for Swoft 1.x" via githab repo.