wayhood/hyperf-service

dev-main 2023-04-14 10:58 UTC

This package is auto-updated.

Last update: 2024-10-31 00:21:36 UTC


README

A Service Annotation for Hyperf

Example

auto set dependencies

TestSerivce -> TestServiceImpl

<?php

namespace App\Service;

interface TestService
{
    public function getTest(): string;
}
<?php

namespace App\Service\Impl;

use App\Service\TestService;
use Wayhood\Service\Annotation\Service;

#[Service]
class TestServiceImpl implements TestService
{
    public function getTest(): string {
        return "abc";
    }
}
namespace App\Controller;

use App\Service\TestService;
use Hyperf\Di\Annotation\Inject;

class IndexController extends AbstractController
{
    #[Inject]
    protected TestService $testService;

    public function index()
    {
        return $this->testService->getTest();
    }
}