php / php/php-src

Connect attributes to their targets

Đang mở
#18,553 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Extension: reflection Feature Status: Needs Triage
Ngôn ngữ chính
C
Star
40.4k
Fork
8.1k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

There currently seems to be no way to get the actual target of the attribute. The getTarget method returns the bitmask of the constants. Example usage:

class X {

#[Tag]
private string $property;

#[Tag]
private string $otherProperty;

private string $extraProperty;
}

...
$attributeReflections = $propertyReflection->getAttributes(Tag::class);
// now I want to pass the reflections somewhere else and do

$property = $attributeReflection->getPropertyReflection();
$property->getValue();

Obviously there is a workaround to build some datastructure to pass the reference in along with the reflection. But it seems like it should be part of the API. Given I can limit to what type of object I can attach it to, I should be able to get the actual "instance" of the object somehow IMHO. But maybe I'm missing some important context why this doesn't make sense, sorry if that's the case :)

Essentially it's the same as when ReflectionProperty has $class even though one could argue that you always get the property from class, so you should be able to maintain the relation yourself. I believe that property attribute should at least have $class and $property, if the above proposed API is too heavy.

Does it make sense?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng việc xem xét hành vi phản xạ thuộc tính xung quanh getTarget() và API getPropertyReflection() được đề xuất, cùng với mối quan hệ lớp và thuộc tính hiện có của ReflectionProperty. Xác định xem các thuộc tính của property nên cung cấp class và property khai báo chúng hay một đối tượng đích rộng hơn. Công việc được xem là hoàn tất khi có một thiết kế API đã được thống nhất, cùng với hành vi tương ứng và các bài kiểm thử cho ví dụ liên quan đến nhiều property.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
php
Lĩnh vực
backend
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.