1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the XabbuhPandaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\PandaBundle\Cloud; |
13
|
|
|
|
14
|
1 |
|
@trigger_error('The Xabbuh\PandaBundle\Cloud\CloudFactory class is deprecated since version 1.3 and will be removed in 2.0', E_USER_DEPRECATED); |
15
|
|
|
|
16
|
|
|
use Xabbuh\PandaClient\Api\AccountManagerInterface; |
17
|
|
|
use Xabbuh\PandaClient\Api\Cloud; |
18
|
|
|
use Xabbuh\PandaClient\Api\HttplugClient; |
19
|
|
|
use Xabbuh\PandaClient\Transformer\TransformerRegistryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Factory to create Cloud instances. |
23
|
|
|
* |
24
|
|
|
* @author Christian Flothmann <[email protected]> |
25
|
|
|
* |
26
|
|
|
* @deprecated since version 1.3, to be removed in 2.0 |
27
|
|
|
*/ |
28
|
|
|
class CloudFactory implements CloudFactoryInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* The account manager being used to manage all configured Accounts |
32
|
|
|
* @var AccountManagerInterface |
33
|
|
|
*/ |
34
|
|
|
private $accountManager; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Factory for creating model transformers |
38
|
|
|
* @var TransformerRegistryInterface |
39
|
|
|
*/ |
40
|
|
|
private $transformerRegistry; |
41
|
|
|
|
42
|
3 |
|
public function __construct( |
43
|
|
|
AccountManagerInterface $accountManager, |
44
|
|
|
TransformerRegistryInterface $transformerFactory |
45
|
|
|
) { |
46
|
3 |
|
$this->accountManager = $accountManager; |
47
|
3 |
|
$this->transformerRegistry = $transformerFactory; |
48
|
3 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
3 |
|
public function get($cloudId, $accountKey = null) |
54
|
|
|
{ |
55
|
3 |
|
$account = $this->accountManager->getAccount($accountKey); |
56
|
|
|
|
57
|
3 |
|
$httpClient = new HttplugClient(); |
58
|
|
|
$httpClient->setCloudId($cloudId); |
59
|
|
|
$httpClient->setAccount($account); |
60
|
|
|
|
61
|
|
|
$cloud = new Cloud(); |
62
|
|
|
$cloud->setHttpClient($httpClient); |
63
|
|
|
$cloud->setTransformers($this->transformerRegistry); |
64
|
|
|
|
65
|
|
|
return $cloud; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.