1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright Humbly Arrogant Ltd 2020-2022. |
7
|
|
|
* |
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
9
|
|
|
* |
10
|
|
|
* Change Date: TBD ( 3 years after 2.0.0 release ) |
11
|
|
|
* |
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Parthenon\User\Team; |
16
|
|
|
|
17
|
|
|
use Parthenon\User\Entity\MemberInterface; |
18
|
|
|
use Parthenon\User\Entity\TeamInterface; |
19
|
|
|
use Parthenon\User\Repository\TeamRepositoryInterface; |
20
|
|
|
use Parthenon\User\Repository\UserRepositoryInterface; |
21
|
|
|
|
22
|
|
|
final class TeamCreator implements TeamCreatorInterface |
23
|
|
|
{ |
24
|
|
|
private TeamRepositoryInterface $teamRepository; |
25
|
|
|
private TeamInterface $teamClass; |
26
|
|
|
private UserRepositoryInterface $userRepository; |
27
|
|
|
|
28
|
|
|
public function __construct(TeamRepositoryInterface $teamRepository, UserRepositoryInterface $userRepository, TeamInterface $teamClass) |
29
|
|
|
{ |
30
|
|
|
$this->teamRepository = $teamRepository; |
31
|
|
|
$this->teamClass = $teamClass; |
32
|
|
|
$this->userRepository = $userRepository; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function createForUser(MemberInterface $user): void |
36
|
|
|
{ |
37
|
|
|
$className = get_class($this->teamClass); |
38
|
|
|
/** @var TeamInterface $team */ |
39
|
|
|
$team = new $className(); |
40
|
|
|
$team->setName(sprintf("%s's team", $user->getEmail())); |
41
|
|
|
$team->setCreatedAt(new \DateTime('now')); |
42
|
|
|
$team->addMember($user); |
43
|
|
|
|
44
|
|
|
$this->teamRepository->save($team); |
45
|
|
|
$user->setTeam($team); |
46
|
|
|
$this->userRepository->save($user); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|