Skip to content

Commit eaab1e8

Browse files
authored
Merge pull request #27 from moufmouf/logged_method_on_field
Adding logged() method on Field
2 parents 476c5e1 + d588acc commit eaab1e8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Field.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
class Field implements SourceFieldInterface
1212
{
1313
private $hide = true;
14+
/**
15+
* @var bool
16+
*/
17+
private $logged = false;
18+
/**
19+
* @var string
20+
*/
1421
private $right;
1522
/**
1623
* @var string
@@ -60,6 +67,18 @@ public function isHidden(): bool
6067
return $this->hide;
6168
}
6269

70+
/**
71+
* The user must be logged to access this field.
72+
*/
73+
public function logged(): self
74+
{
75+
$this->logged = true;
76+
return $this;
77+
}
78+
79+
/**
80+
* The user must have right $right to access this field.
81+
*/
6382
public function requiresRight(string $right): self
6483
{
6584
$this->right = $right;
@@ -103,7 +122,7 @@ public function getName(): ?string
103122
*/
104123
public function isLogged(): bool
105124
{
106-
return false;
125+
return $this->logged;
107126
}
108127

109128
/**

tests/FieldTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public function testFailWith()
3232
$this->assertTrue($field->canFailWith());
3333
$this->assertSame('foo', $field->getFailWith());
3434
}
35+
36+
public function testLogged()
37+
{
38+
$field = new Field('test');
39+
$this->assertFalse($field->isLogged());
40+
$field->logged();
41+
$this->assertTrue($field->isLogged());
42+
}
3543
}

0 commit comments

Comments
 (0)