Skip to content

Commit 82f8ff7

Browse files
authored
Merge pull request #12 from moufmouf/protected_methods
Adding protectedGetter/Setter/OneToMany methods
2 parents eb658ce + 2028a51 commit 82f8ff7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ $posts = $db->table('posts')->customBeanName('Article');
3434
// This will generate a @UUID TDBM annotation that will help TDBM autogenerate the UUID
3535
$posts = $db->table('posts')->uuid('v4');
3636

37+
// Customize the visibility of a column
38+
$db->table('posts')
39+
->column('user_id')->references('users')
40+
->protectedGetter() // The Post.getUser() method is protected
41+
->protectedSetter() // The Post.setUser() method is protected
42+
->protectedOneToMany() // The User.getPosts() method is protected
43+
3744
// The "posts" table will generate a GraphQL type (i.e. the bean will be annotated with the GraphQLite @Type annotation).
3845
$posts = $db->table('posts')->graphqlType();
3946

src/TdbmFluidColumnOptions.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ public function graphqlField(): TdbmFluidColumnGraphqlOptions
108108
return new TdbmFluidColumnGraphqlOptions($this, $this->fluidColumn);
109109
}
110110

111+
public function protectedGetter(): self
112+
{
113+
$this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedGetter');
114+
return $this;
115+
}
116+
117+
public function protectedSetter(): self
118+
{
119+
$this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedSetter');
120+
return $this;
121+
}
122+
123+
public function protectedOneToMany(): self
124+
{
125+
$this->addAnnotation('TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedOneToMany');
126+
return $this;
127+
}
128+
111129
private function getComment(): Comment
112130
{
113131
$comment = $this->fluidColumn->getDbalColumn()->getComment();

tests/TdbmFluidColumnOptionsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ public function testOptions()
3838
$columnOptions->default(42);
3939
$this->assertSame(42, $dbalColumn->getDefault());
4040

41+
$columnOptions->protectedGetter();
42+
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedGetter', $dbalColumn->getComment());
43+
44+
$columnOptions->protectedSetter();
45+
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedSetter', $dbalColumn->getComment());
46+
47+
$columnOptions->protectedOneToMany();
48+
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedOneToMany', $dbalColumn->getComment());
49+
4150
$this->assertSame($posts, $columnOptions->then());
4251

4352
$columnOptions->column('bar');

0 commit comments

Comments
 (0)