| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Attributes; |
| 4: | |
| 5: | use Attribute; |
| 6: | |
| 7: | /** |
| 8: | * Declares a semantic link between two {@see SemanticObject}s. |
| 9: | * |
| 10: | * Applied to a property of a model that itself represents a SemanticObject, |
| 11: | * this attribute marks a *reference* (arc) to another semantic object. |
| 12: | * |
| 13: | * The link enables the SDK and UI to automatically: |
| 14: | * - resolve cross-module navigation intents |
| 15: | * - display related-object menus and context actions |
| 16: | * - construct semantic relationship graphs |
| 17: | * |
| 18: | * ### Example |
| 19: | * ```php |
| 20: | * use LaravelUi5\Core\Attributes\SemanticLink; |
| 21: | * |
| 22: | * class Project extends Model |
| 23: | * { |
| 24: | * #[SemanticLink(model: \Ui5\Partners\Models\Partner::class)] |
| 25: | * public string $partner_id; |
| 26: | * } |
| 27: | * ``` |
| 28: | * |
| 29: | * ### Parameters |
| 30: | * @param string $model Fully qualified Eloquent model class of the |
| 31: | * *target* semantic object. |
| 32: | * |
| 33: | * ### Validation rules |
| 34: | * - May only be placed on models that are declared as a SemanticObject. |
| 35: | * - `$model` must reference another registered SemanticObject model. |
| 36: | * - Links to unknown models cause a LogicException during pass 2. |
| 37: | * |
| 38: | * ### Design rationale |
| 39: | * The link does *not* contain a title or icon. Those are resolved automatically |
| 40: | * from the target semantic object, ensuring a single source of truth and |
| 41: | * a consistent naming graph across the system. |
| 42: | */ |
| 43: | #[Attribute(Attribute::TARGET_METHOD)] |
| 44: | class SemanticLink |
| 45: | { |
| 46: | /** |
| 47: | * @param string|null $model Fully qualified model class of the target |
| 48: | * SemanticObject. Must exist and be discoverable. |
| 49: | */ |
| 50: | public function __construct( |
| 51: | public ?string $model = null, |
| 52: | ) {} |
| 53: | } |
| 54: |