Skip to content

Commit d74a675

Browse files
committed
chore: Example implementation and test fixtures
1 parent 33b29e0 commit d74a675

File tree

10 files changed

+614
-2
lines changed

10 files changed

+614
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
![Unit Tests](https://github.com/articulate-laravel/concise/actions/workflows/tests.yml/badge.svg)
1111
![Static Analysis](https://github.com/articulate-laravel/concise/actions/workflows/static-analysis.yml/badge.svg)
1212

13-
# Articulate: Concise for Laravel
13+
# Articulate: Concise
1414
### A super lightweight data mapper ORM for Laravel
1515

1616
This package is currently under development.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Components;
5+
6+
use Carbon\CarbonInterface;
7+
8+
class AuthCredentials
9+
{
10+
protected string $email;
11+
12+
protected string $password;
13+
14+
protected ?string $rememberToken;
15+
16+
protected ?CarbonInterface $emailVerifiedAt;
17+
18+
public function __construct(
19+
string $email,
20+
string $password,
21+
?string $rememberToken = null,
22+
?CarbonInterface $emailVerifiedAt = null,
23+
)
24+
{
25+
$this->email = $email;
26+
$this->password = $password;
27+
$this->rememberToken = $rememberToken;
28+
$this->emailVerifiedAt = $emailVerifiedAt;
29+
}
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getEmail(): string
35+
{
36+
return $this->email;
37+
}
38+
39+
/**
40+
* @param string $email
41+
*
42+
* @return AuthCredentials
43+
*/
44+
public function setEmail(string $email): AuthCredentials
45+
{
46+
$this->email = $email;
47+
return $this;
48+
}
49+
50+
/**
51+
* @return \Carbon\CarbonInterface|null
52+
*/
53+
public function getEmailVerifiedAt(): ?CarbonInterface
54+
{
55+
return $this->emailVerifiedAt;
56+
}
57+
58+
/**
59+
* @param \Carbon\CarbonInterface|null $emailVerifiedAt
60+
*
61+
* @return AuthCredentials
62+
*/
63+
public function setEmailVerifiedAt(?CarbonInterface $emailVerifiedAt): AuthCredentials
64+
{
65+
$this->emailVerifiedAt = $emailVerifiedAt;
66+
return $this;
67+
}
68+
69+
/**
70+
* @return string
71+
*/
72+
public function getPassword(): string
73+
{
74+
return $this->password;
75+
}
76+
77+
/**
78+
* @param string $password
79+
*
80+
* @return AuthCredentials
81+
*/
82+
public function setPassword(string $password): AuthCredentials
83+
{
84+
$this->password = $password;
85+
return $this;
86+
}
87+
88+
/**
89+
* @return string|null
90+
*/
91+
public function getRememberToken(): ?string
92+
{
93+
return $this->rememberToken;
94+
}
95+
96+
/**
97+
* @param string|null $rememberToken
98+
*
99+
* @return AuthCredentials
100+
*/
101+
public function setRememberToken(?string $rememberToken): AuthCredentials
102+
{
103+
$this->rememberToken = $rememberToken;
104+
return $this;
105+
}
106+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Components;
5+
6+
use Carbon\CarbonInterface;
7+
8+
class Timestamps
9+
{
10+
protected CarbonInterface $createdAt;
11+
12+
protected CarbonInterface $updatedAt;
13+
14+
public function __construct(
15+
?CarbonInterface $createdAt = null,
16+
?CarbonInterface $updatedAt = null,
17+
)
18+
{
19+
if ($createdAt) {
20+
$this->createdAt = $createdAt;
21+
}
22+
23+
if ($updatedAt) {
24+
$this->updatedAt = $updatedAt;
25+
}
26+
}
27+
28+
/**
29+
* @return \Carbon\CarbonInterface
30+
*/
31+
public function getCreatedAt(): CarbonInterface
32+
{
33+
return $this->createdAt;
34+
}
35+
36+
/**
37+
* @param \Carbon\CarbonInterface $createdAt
38+
*
39+
* @return Timestamps
40+
*/
41+
public function setCreatedAt(CarbonInterface $createdAt): Timestamps
42+
{
43+
$this->createdAt = $createdAt;
44+
return $this;
45+
}
46+
47+
/**
48+
* @return \Carbon\CarbonInterface
49+
*/
50+
public function getUpdatedAt(): CarbonInterface
51+
{
52+
return $this->updatedAt;
53+
}
54+
55+
/**
56+
* @param \Carbon\CarbonInterface $updatedAt
57+
*
58+
* @return Timestamps
59+
*/
60+
public function setUpdatedAt(CarbonInterface $updatedAt): Timestamps
61+
{
62+
$this->updatedAt = $updatedAt;
63+
return $this;
64+
}
65+
}

workbench/app/Entities/User.php

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace App\Entities;
5+
6+
use App\Components\AuthCredentials;
7+
use App\Components\Timestamps;
8+
use Illuminate\Contracts\Auth\Authenticatable;
9+
10+
class User implements Authenticatable
11+
{
12+
protected int $id;
13+
14+
protected string $name;
15+
16+
protected AuthCredentials $auth;
17+
18+
protected Timestamps $timestamps;
19+
20+
/**
21+
* @return \App\Components\AuthCredentials
22+
*/
23+
public function getAuth(): AuthCredentials
24+
{
25+
return $this->auth;
26+
}
27+
28+
/**
29+
* @param \App\Components\AuthCredentials $auth
30+
*
31+
* @return User
32+
*/
33+
public function setAuth(AuthCredentials $auth): User
34+
{
35+
$this->auth = $auth;
36+
return $this;
37+
}
38+
39+
/**
40+
* @return int
41+
*/
42+
public function getId(): int
43+
{
44+
return $this->id;
45+
}
46+
47+
/**
48+
* @param int $id
49+
*
50+
* @return User
51+
*/
52+
public function setId(int $id): User
53+
{
54+
$this->id = $id;
55+
return $this;
56+
}
57+
58+
/**
59+
* @return bool
60+
*/
61+
public function hasId(): bool
62+
{
63+
return isset($this->id);
64+
}
65+
66+
/**
67+
* @return string
68+
*/
69+
public function getName(): string
70+
{
71+
return $this->name;
72+
}
73+
74+
/**
75+
* @param string $name
76+
*
77+
* @return User
78+
*/
79+
public function setName(string $name): User
80+
{
81+
$this->name = $name;
82+
return $this;
83+
}
84+
85+
/**
86+
* @return \App\Components\Timestamps
87+
*/
88+
public function getTimestamps(): Timestamps
89+
{
90+
return $this->timestamps;
91+
}
92+
93+
/**
94+
* @param \App\Components\Timestamps $timestamps
95+
*
96+
* @return User
97+
*/
98+
public function setTimestamps(Timestamps $timestamps): User
99+
{
100+
$this->timestamps = $timestamps;
101+
return $this;
102+
}
103+
104+
/**
105+
* Get the name of the unique identifier for the user.
106+
*
107+
* @return string
108+
*/
109+
public function getAuthIdentifierName(): string
110+
{
111+
return 'id';
112+
}
113+
114+
/**
115+
* Get the unique identifier for the user.
116+
*
117+
* @return int
118+
*/
119+
public function getAuthIdentifier(): int
120+
{
121+
return $this->getId();
122+
}
123+
124+
/**
125+
* Get the name of the password attribute for the user.
126+
*
127+
* @return string
128+
*/
129+
public function getAuthPasswordName(): string
130+
{
131+
return 'password';
132+
}
133+
134+
/**
135+
* Get the password for the user.
136+
*
137+
* @return string
138+
*/
139+
public function getAuthPassword(): string
140+
{
141+
return $this->getAuth()->getPassword();
142+
}
143+
144+
/**
145+
* Get the token value for the "remember me" session.
146+
*
147+
* @return string
148+
*/
149+
public function getRememberToken(): string
150+
{
151+
return $this->getAuth()->getRememberToken();
152+
}
153+
154+
/**
155+
* Set the token value for the "remember me" session.
156+
*
157+
* @param string $value
158+
*
159+
* @return void
160+
*/
161+
public function setRememberToken($value): void
162+
{
163+
$this->getAuth()->setRememberToken($value);
164+
}
165+
166+
/**
167+
* Get the column name for the "remember me" token.
168+
*
169+
* @return string
170+
*/
171+
public function getRememberTokenName(): string
172+
{
173+
return 'remember_token';
174+
}
175+
}

0 commit comments

Comments
 (0)