Skip to content

Commit 6adcebc

Browse files
authored
Merge pull request #15 from moufmouf/implement_interface
Adding useTrait and useTraitOnDao methods
2 parents 567da73 + 5a63b4e commit 6adcebc

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/TdbmFluidTable.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,32 @@ public function implementsInterfaceOnDao(string $interfaceName): self
134134
return $this;
135135
}
136136

137+
/**
138+
* Makes the generated bean implement the trait $traitName
139+
*
140+
* @param string $traitName
141+
* @param string[] $modifiers An array of modifiers. For instance: ['A::foo insteadof B']
142+
* @return TdbmFluidTable
143+
*/
144+
public function useTrait(string $traitName, array $modifiers = []): self
145+
{
146+
$this->addAnnotation('AddTrait', ['name' => $traitName, 'modifiers' => $modifiers], false);
147+
return $this;
148+
}
149+
150+
/**
151+
* Makes the generated DAO implement the trait $traitName
152+
*
153+
* @param string $traitName
154+
* @param string[] $modifiers An array of modifiers. For instance: ['A::foo insteadof B']
155+
* @return TdbmFluidTable
156+
*/
157+
public function useTraitOnDao(string $traitName, array $modifiers = []): self
158+
{
159+
$this->addAnnotation('AddTraitOnDao', ['name' => $traitName, 'modifiers' => $modifiers], false);
160+
return $this;
161+
}
162+
137163
private function getComment(): Comment
138164
{
139165
$options = $this->fluidTable->getDbalTable()->getOptions();

tests/TdbmFluidTableTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ public function testImplementsInterfaceOnDao()
148148
$this->assertSame("\n@AddInterfaceOnDao(name = \"Foo\\Bar\")", $schema->getTable('posts')->getOptions()['comment']);
149149
}
150150

151+
public function testUseTrait()
152+
{
153+
$schema = new Schema();
154+
$fluid = new TdbmFluidSchema($schema);
155+
156+
$posts = $fluid->table('posts');
157+
158+
$posts->useTrait('Foo\\Bar');
159+
$posts->useTrait('Foo\\Bar2');
160+
161+
$this->assertSame("\n@AddTrait(name = \"Foo\\Bar\", modifiers = {})\n@AddTrait(name = \"Foo\\Bar2\", modifiers = {})", $schema->getTable('posts')->getOptions()['comment']);
162+
}
163+
164+
public function testUseTraitOnDao()
165+
{
166+
$schema = new Schema();
167+
$fluid = new TdbmFluidSchema($schema);
168+
169+
$posts = $fluid->table('posts');
170+
171+
$posts->useTraitOnDao('Foo\\Bar');
172+
173+
$this->assertSame("\n@AddTraitOnDao(name = \"Foo\\Bar\", modifiers = {})", $schema->getTable('posts')->getOptions()['comment']);
174+
}
175+
151176
public function testTimestamps()
152177
{
153178
if (defined('Doctrine\\DBAL\\Types\\Type::DATE_IMMUTABLE')) {

0 commit comments

Comments
 (0)