Giter VIP home page Giter VIP logo

annotation's Introduction

BaseAnnotation

php注解实现

基础使用

$directory = new \Tool\Annotation\AnnotationService();
// 设置遍历目录
$scanDir = realpath(__DIR__);
$directory->setScanDirectory($scanDir,"");
// 设置注解标签,绑定注解tag到类
$directory->setAnnotation('TestBase',TestBase::class);
$directory->setAnnotation('TestBase2',TestBase2::class);

foreach ($directory->eachAnnotation() as $annotation){
    if( $annotation instanceof TestBase){
        // 是TestBase注解
    }
}

定义TestBase注解

class TestBase extends \Tool\Annotation\AnnotationAbstract
{
    public $one;

    function init(...$params)
    {
        // @TestBase("参数1","参数2") 注解的参数将会传入这里
        $this->one = $params[0];
    }
}

逻辑中使用注解

class TestClass
{
    /**
     * @TestBase(1)
     * @param null $time
     */
    public function testFunc($time=null)
    {
        var_dump($time);
    }

    /**
     * @TestMapping($route="/user","/test")
     * @param string $route
     * @param string $middleware
     */
    public static function testStatic($route='',$middleware)
    {
        var_dump($route,$middleware);
    }

    /**
     * @TestMapping($route="/user","/test")
     * @isBase
     * @param string $route
     * @param string $middleware
     */
    public static function testBase($route='',$middleware)
    {
        var_dump($route,$middleware);
    }
}

annotation's People

Contributors

ctfang avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.