1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Marek\Toggable\Factory; |
4
|
|
|
|
5
|
|
|
use Marek\Toggable\Factory\Authentication\AuthenticationFactory; |
6
|
|
|
use Marek\Toggable\Factory\Http\HttpClientFactory; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Marek\Toggable\Factory\Hydrator\HydratorFactory; |
9
|
|
|
use Marek\Toggable\Http\Manager\NativeRequestManager; |
10
|
|
|
use Marek\Toggable\Service\Authentication\AuthenticationService; |
11
|
|
|
use Marek\Toggable\Service\Client\ClientService; |
12
|
|
|
use Marek\Toggable\Service\Dashboard\DashboardService; |
13
|
|
|
use Marek\Toggable\Service\Project\ProjectService; |
14
|
|
|
use Marek\Toggable\Service\ProjectUsers\ProjectUsersService; |
15
|
|
|
use Marek\Toggable\Service\Tag\TagService; |
16
|
|
|
use Marek\Toggable\Service\Task\TaskService; |
17
|
|
|
use Marek\Toggable\Service\TimeEntry\TimeEntryService; |
18
|
|
|
use Marek\Toggable\Service\User\UserService; |
19
|
|
|
use Marek\Toggable\Service\Workspace\WorkspaceService; |
20
|
|
|
use Marek\Toggable\Service\WorkspaceUsers\WorkspaceUsersService; |
21
|
|
|
use Marek\Toggable\Toggl; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class TogglFactory |
25
|
|
|
* @package Marek\Toggable\Factory |
26
|
|
|
*/ |
27
|
|
|
class TogglFactory implements FactoryInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var \Marek\Toggable\Factory\FactoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $authentication; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \Marek\Toggable\Factory\FactoryInterface |
36
|
|
|
*/ |
37
|
|
|
private $http; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var \Marek\Toggable\Factory\FactoryInterface |
41
|
17 |
|
*/ |
42
|
1 |
|
private $hydrator; |
43
|
17 |
|
|
44
|
1 |
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
16 |
|
private $config; |
48
|
|
|
|
49
|
14 |
|
/** |
50
|
|
|
* TogglFactory constructor. |
51
|
16 |
|
* |
52
|
|
|
* @param array $config |
53
|
1 |
|
* @param \Marek\Toggable\Factory\FactoryInterface $authentication |
54
|
1 |
|
* @param \Marek\Toggable\Factory\FactoryInterface $http |
55
|
1 |
|
* @param \Marek\Toggable\Factory\FactoryInterface $hydrator |
56
|
1 |
|
*/ |
57
|
|
|
public function __construct($config, FactoryInterface $authentication, FactoryInterface $http, FactoryInterface $hydrator) |
|
|
|
|
58
|
1 |
|
{ |
59
|
|
|
if (!is_array($config) || empty($config)) { |
60
|
1 |
|
throw new InvalidArgumentException('Please provide valid configuration.'); |
61
|
|
|
} |
62
|
|
|
$this->config = $config; |
63
|
|
|
|
64
|
15 |
|
$this->authentication = new AuthenticationFactory($config); |
65
|
15 |
|
$this->http = new HttpClientFactory($config, $this->authentication->build()); |
66
|
1 |
|
$this->hydrator = new HydratorFactory(); |
67
|
|
|
|
68
|
|
|
} |
69
|
14 |
|
|
70
|
14 |
|
/** |
71
|
14 |
|
* @inheritDoc |
72
|
14 |
|
*/ |
73
|
|
|
public function build() |
74
|
14 |
|
{ |
75
|
|
|
$nativeHttpClient = $this->http->build(); |
76
|
14 |
|
$requestManager = new NativeRequestManager($nativeHttpClient); |
77
|
14 |
|
|
78
|
14 |
|
$hydrator = $this->hydrator->build(); |
79
|
14 |
|
|
80
|
14 |
|
$authenticationService = new AuthenticationService($requestManager, $hydrator); |
81
|
14 |
|
$clientService = new ClientService($requestManager, $hydrator); |
82
|
14 |
|
$dashboardService = new DashboardService($requestManager, $hydrator); |
83
|
14 |
|
$projectService = new ProjectService($requestManager, $hydrator); |
84
|
|
|
$projectUsersService = new ProjectUsersService($requestManager, $hydrator); |
85
|
14 |
|
$tagService = new TagService($requestManager, $hydrator); |
86
|
14 |
|
$taskService = new TaskService($requestManager, $hydrator); |
87
|
14 |
|
$timeEntryService = new TimeEntryService($requestManager, $hydrator); |
88
|
|
|
|
89
|
14 |
|
$userService = new UserService($requestManager, $hydrator); |
90
|
14 |
|
$workspaceService = new WorkspaceService($requestManager, $hydrator); |
91
|
14 |
|
$workspaceUsersService = new WorkspaceUsersService($requestManager, $hydrator); |
92
|
14 |
|
|
93
|
14 |
|
return new Toggl( |
94
|
14 |
|
$authenticationService, |
95
|
14 |
|
$clientService, |
96
|
14 |
|
$dashboardService, |
97
|
14 |
|
$projectService, |
98
|
14 |
|
$projectUsersService, |
99
|
14 |
|
$tagService, |
100
|
|
|
$taskService, |
101
|
14 |
|
$timeEntryService, |
102
|
|
|
$userService, |
103
|
14 |
|
$workspaceService, |
104
|
|
|
$workspaceUsersService |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.