gollumsf/entity-relation-setter
Composer 安装命令:
composer require gollumsf/entity-relation-setter
包简介
Trait for add method cross setter
README 文档
README
Trait for add method cross setter
Installation:
composer require gollumsf/entity-relation-setter
Exemple
OneToOne
use GollumSF\EntityRelationSetter\OneToOneSetter; class User { use OneToOneSetter; /** * @ORM\OneToOne(targetEntity=Address::class, inversedBy="tiers") * @var Address */ private $address; //////////// // Setter // //////////// public function setAddress(?Address $address): self { return $this->oneToOneSet($address/*, 'address', 'user'*/); } } class Address { use OneToOneSetter; /** * @ORM\OneToOne(targetEntity=Tiers::User, mappedBy="address") * @var Address */ private $address; //////////// // Setter // //////////// public function setUser(?User $user): self { return $this->oneToOneSet($user/*, 'user', 'address'*/); } }
OneToManySetter and ManyToOneSetter
use GollumSF\EntityRelationSetter\ManyToOneSetter; use GollumSF\EntityRelationSetter\OneToManySetter; class Address { use ManyToOneSetter; /** * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="addresses") * @var Country */ private $country; //////////// // Setter // //////////// public function setCountry(?Country $country): self { return $this->manyToOneSet($country/*, 'country', 'address'*/); } } class Country { use OneToManySetter; /** * @ORM\OneToMany(targetEntity=Address::class, mappedBy="country") * @var Address[]|ArrayCollection */ private $addresses; public function __construct() { $this->addresses = new ArrayCollection(); } ///////// // Add // ///////// public function addAddress(Address $address): self { return $this->oneToManyAdd($address/*, 'addresses', 'country'*/); } //////////// // Remove // //////////// public function removeAddress(Address $address): self { return $this->oneToManyRemove($address/*, 'addresses', 'country'*/); } }
ManyToManySetter
use GollumSF\EntityRelationSetter\ManyToManySetter; class Post { use ManyToManySetter; /** * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="posts") * @var Tag[]|ArrayCollection */ private $tags; public function __construct() { $this->tags = new ArrayCollection(); } ///////// // Add // ///////// public function addTag(Tag $tag): self { return $this->manyToManyAdd($tag/*, 'tags', 'post'*/); } //////////// // Remove // //////////// public function removeTag(Tag $tag): self { return $this->manyToManyRemove($tag/*, 'tags', 'post'*/); } } class Tag { use ManyToManySetter; /** * @ORM\ManyToMany(targetEntity=Post:class, inversedBy="tags")²& * @var Post[]|ArrayCollection */ private $posts; public function __construct() { $this->posts = new ArrayCollection(); } ///////// // Add // ///////// public function addPost(Post $post): self { return $this->manyToManyAdd($post/*, 'posts', 'tag'*/); } //////////// // Remove // //////////// public function removePost(Post $post): self { return $this->manyToManyRemove($post/*, 'posts', 'tag'*/); } }
统计信息
- 总下载量: 1.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-12-06