1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Pickle |
7
|
|
|
* |
8
|
|
|
* |
9
|
|
|
* @license |
10
|
|
|
* |
11
|
|
|
* New BSD License |
12
|
|
|
* |
13
|
|
|
* Copyright © 2015-2015, Pickle community. All rights reserved. |
14
|
|
|
* |
15
|
|
|
* Redistribution and use in source and binary forms, with or without |
16
|
|
|
* modification, are permitted provided that the following conditions are met: |
17
|
|
|
* * Redistributions of source code must retain the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer. |
19
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
20
|
|
|
* notice, this list of conditions and the following disclaimer in the |
21
|
|
|
* documentation and/or other materials provided with the distribution. |
22
|
|
|
* * Neither the name of the Hoa nor the names of its contributors may be |
23
|
|
|
* used to endorse or promote products derived from this software without |
24
|
|
|
* specific prior written permission. |
25
|
|
|
* |
26
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
27
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
28
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
29
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
30
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
31
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
32
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
33
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
34
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
35
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
36
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
37
|
|
|
*/ |
38
|
|
|
|
39
|
|
|
namespace Pickle\Base\Pecl; |
40
|
|
|
|
41
|
|
|
class WebsiteFactory |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @var Website|null |
45
|
|
|
*/ |
46
|
|
|
private static $website = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the PECL website configuration. |
50
|
|
|
*/ |
51
|
|
|
public static function getWebsite(): Website |
52
|
|
|
{ |
53
|
|
|
if (self::$website === null) { |
54
|
|
|
if (static::isTestServer()) { |
55
|
|
|
self::$website = new Website('http://127.0.0.1:' . Website::TEST_PORT . '/index.php', true); |
56
|
|
|
} else { |
57
|
|
|
$unsafe = static::allowUnsafeConnections(); |
58
|
|
|
self::$website = new Website($unsafe ? 'http://pecl.php.net' : 'https://pecl.php.net', $unsafe); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return self::$website; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function isTestServer(): bool |
66
|
|
|
{ |
67
|
|
|
$v = strtolower(getenv('PICKLE_PECL_TESTSERVER') ?: ''); |
68
|
|
|
|
69
|
|
|
return in_array($v, ['1', 'true', 'yes'], true); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected static function allowUnsafeConnections(): bool |
73
|
|
|
{ |
74
|
|
|
if (static::isTestServer()) { |
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
$v = strtolower(getenv('PICKLE_PECL_UNSAFE') ?: ''); |
78
|
|
|
|
79
|
|
|
return in_array($v, ['1', 'true', 'yes', 'y', 'ok'], true); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
84
|
|
|
|