1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
7
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
8
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
9
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
10
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
11
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
12
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
13
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
14
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
15
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
16
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
17
|
|
|
* |
18
|
|
|
* This software consists of voluntary contributions made by many individuals |
19
|
|
|
* and is licensed under the MIT license. For more information, see |
20
|
|
|
* <https://github.com/digitalkaoz/php-ipfs> |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace IPFS\Container; |
24
|
|
|
|
25
|
|
|
use Http\Client\Common\PluginClient; |
26
|
|
|
use Http\Client\HttpAsyncClient; |
27
|
|
|
use Http\Discovery\HttpAsyncClientDiscovery; |
28
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
29
|
|
|
use Http\Discovery\UriFactoryDiscovery; |
30
|
|
|
use Http\Message\MessageFactory; |
31
|
|
|
use Http\Message\UriFactory; |
32
|
|
|
use IPFS\Api; |
33
|
|
|
use IPFS\Console\ApiBuildCommand; |
34
|
|
|
use IPFS\Console\CommandBuilder; |
35
|
|
|
use IPFS\Driver\Cli; |
36
|
|
|
use IPFS\Driver\Http; |
37
|
|
|
use IPFS\Utils\AnnotationReader; |
38
|
|
|
use phpDocumentor\Reflection\DocBlockFactory; |
39
|
|
|
use PhpParser\BuilderFactory; |
40
|
|
|
use Pimple\Container; |
41
|
|
|
use Pimple\ServiceProviderInterface; |
42
|
|
|
use Symfony\Component\Console\Application; |
43
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
44
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
45
|
|
|
|
46
|
|
|
class ServiceProvider implements ServiceProviderInterface |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
1 |
|
public function register(Container $pimple) |
52
|
|
|
{ |
53
|
1 |
|
$this->registerDriver($pimple); |
|
|
|
|
54
|
1 |
|
$this->registerHttp($pimple); |
|
|
|
|
55
|
1 |
|
$this->registerConsole($pimple); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$pimple[AnnotationReader::class] = function () { |
58
|
|
|
return new AnnotationReader( |
59
|
|
|
new \Doctrine\Common\Annotations\AnnotationReader(), |
60
|
|
|
DocBlockFactory::createInstance() |
61
|
|
|
); |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
$pimple[Api\ApiBuilder::class] = function (Container $pimple) { |
65
|
|
|
$parser = new Api\ApiParser($pimple[HttpAsyncClient::class], $pimple[MessageFactory::class], new Crawler()); |
66
|
|
|
$generator = new Api\ApiGenerator(new BuilderFactory()); |
67
|
|
|
|
68
|
|
|
return new Api\ApiBuilder($parser, $generator); |
69
|
|
|
}; |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
public function registerHttp(Container $pimple) |
73
|
|
|
{ |
74
|
|
|
$pimple[HttpAsyncClient::class] = function () { |
75
|
|
|
return new PluginClient( |
76
|
|
|
HttpAsyncClientDiscovery::find(), |
77
|
|
|
[] |
78
|
|
|
); |
79
|
|
|
}; |
80
|
|
|
|
81
|
|
|
$pimple[MessageFactory::class] = function () { |
82
|
|
|
return MessageFactoryDiscovery::find(); |
83
|
|
|
}; |
84
|
|
|
|
85
|
|
|
$pimple[UriFactory::class] = function () { |
86
|
|
|
return UriFactoryDiscovery::find(); |
87
|
|
|
}; |
88
|
1 |
|
} |
89
|
|
|
|
90
|
1 |
|
private function registerDriver(Container $pimple) |
91
|
|
|
{ |
92
|
|
|
$pimple[Http::class] = function (Container $pimple) { |
93
|
|
|
return new Http( |
94
|
|
|
$pimple[HttpAsyncClient::class], |
95
|
|
|
$pimple[MessageFactory::class], |
96
|
|
|
$pimple[UriFactory::class], |
97
|
|
|
$pimple[AnnotationReader::class], |
98
|
|
|
getenv('IPFS_API') ?: 'http://localhost:5001/api/v0' |
99
|
|
|
); |
100
|
|
|
}; |
101
|
|
|
|
102
|
|
|
$pimple[Cli::class] = function (Container $pimple) { |
103
|
|
|
return new Cli(new ProcessBuilder(), $pimple[AnnotationReader::class], getenv('IPFS_BINARY') ?: 'ipfs'); |
104
|
|
|
}; |
105
|
1 |
|
} |
106
|
|
|
|
107
|
|
|
private function registerConsole(Container $pimple) |
108
|
|
|
{ |
109
|
|
|
$pimple[CommandBuilder::class] = function (Container $pimple) { |
110
|
|
|
return new CommandBuilder([ |
111
|
|
|
new Api\Basics(), |
112
|
|
|
new Api\Bitswap(), |
113
|
|
|
new Api\Block(), |
114
|
|
|
new Api\Bootstrap(), |
115
|
|
|
new Api\Config(), |
116
|
|
|
new Api\Dht(), |
117
|
|
|
new Api\Diag(), |
118
|
|
|
new Api\File(), |
119
|
|
|
new Api\Files(), |
120
|
|
|
new Api\Log(), |
121
|
|
|
new Api\Name(), |
122
|
|
|
new Api\Object(), |
123
|
|
|
new Api\Pin(), |
124
|
|
|
new Api\Refs(), |
125
|
|
|
new Api\Repo(), |
126
|
|
|
new Api\Stats(), |
127
|
|
|
new Api\Swarm(), |
128
|
|
|
new Api\Tar(), |
129
|
|
|
new Api\Tour(), |
130
|
|
|
], $pimple); |
131
|
|
|
}; |
132
|
|
|
|
133
|
|
|
$pimple[Application::class] = function (Container $pimple) { |
134
|
|
|
$app = new Application('ipfs', '@git-version@'); |
135
|
|
|
$app->addCommands($pimple[CommandBuilder::class]->generateCommands()); |
136
|
|
|
$app->add(new ApiBuildCommand($pimple[Api\ApiBuilder::class])); |
137
|
|
|
|
138
|
|
|
return $app; |
139
|
|
|
}; |
140
|
1 |
|
} |
141
|
|
|
} |
142
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: