定制 holyshared/attribute 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

holyshared/attribute

最新稳定版本:0.1.1

Composer 安装命令:

composer require holyshared/attribute

包简介

Attribute for Hack

README 文档

README

Attribute for Hack

Latest Stable Version Build Status Dependency Status License

ClassAttribute

<?hh //strict

namespace example;

use attribute\ClassAttribute;

final class Tag extends ClassAttribute
{

    public function __construct(
        private string $name
    )
    {
    }

    public function value() : string
    {
        return $this->name;
    }

}
<?hh //strict

namespace example;

<<Tag('important')>>
class TaggedTarget
{
}
<?hh //strict

namespace example;

$attribute = Tag::findByClassName(TaggedTarget::class);
var_dump($attribute->value()); // Tag attribute instance

$attribute = Tag::findByClass(new ReflectionClass(TaggedTarget::class));
var_dump($attribute->value()); // Tag attribute instance

MethodAttribute

<?hh //strict

namespace example;

use attribute\MethodAttribute;

final class Tag extends MethodAttribute
{

    public function __construct(
        private string $name
    )
    {
    }

    public function value() : string
    {
        return $this->name;
    }

}
<?hh //strict

namespace example;

class TaggedTarget
{

    public function __construct(
        private string $name
    )
    {
    }

    <<Tag('important')>>
    public function getName() : string
    {
        return $this->name;
    }

}
<?hh //strict

namespace example;

$attributes = Tag::findByClassName(TaggedTarget::class);
var_dump($attributes->at('getName')->value()); // important

$attributes = Tag::findByClass(new ReflectionClass(TaggedTarget::class));
var_dump($attributes->at('getName')->value()); // important

$attribute = Tag::findByMethod(new ReflectionMethod(TaggedTarget::class, 'getName'));
var_dump($attribute->value()); // important

Run the test

composer install
composer test

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Hack

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-03