Issues (18)

examples/exampleHTTP.php (2 issues)

1
<?php
2
namespace Elphin\LEClient;
3
4
require_once(__DIR__.'/../vendor/autoload.php');
5
6
//Sets the maximum execution time to two minutes, to be sure.
7
ini_set('max_execution_time', 120);
8
9
// Listing the contact information in case a new account has to be created.
10
$email = array('[email protected]');
11
// Defining the base name for this order
12
$basename = 'example.org';
13
// Listing the domains to be included on the certificate
14
$domains = array('example.org', 'test.example.org');
15
16
$logger = new DiagnosticLogger;
0 ignored issues
show
The type Elphin\LEClient\DiagnosticLogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
// Initiating the client instance. In this case using the staging server (argument 2) and outputting all status and
19
// debug information (argument 3).
20
$client = new LEClient($email, true, $logger);
0 ignored issues
show
The type Elphin\LEClient\LEClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
// Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the
22
// domains in the array (argument 2) will be on the certificate.
23
$order = $client->getOrCreateOrder($basename, $domains);
24
// Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
25
if(!$order->allAuthorizationsValid())
26
{
27
	// Get the HTTP challenges from the pending authorizations.
28
	$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_HTTP);
29
	// Walk the list of pending authorization HTTP challenges.
30
	if(!empty($pending))
31
	{
32
		foreach($pending as $challenge)
33
		{
34
			// Define the folder in which to store the challenge. For the purpose of this example, a fictitious path is
35
            // set.
36
			$folder = '/path/to/' . $challenge['identifier'] . '/.well-known/acme-challenge/';
37
			// Check if that directory yet exists. If not, create it.
38
			if(!file_exists($folder)) mkdir($folder, 0777, true);
39
			// Store the challenge file for this domain.
40
			file_put_contents($folder . $challenge['filename'], $challenge['content']);
41
			// Let LetsEncrypt verify this challenge.
42
			$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_HTTP);
43
		}
44
	}
45
}
46
// Check once more whether all authorizations are valid before we can finalize the order.
47
if($order->allAuthorizationsValid())
48
{
49
	// Finalize the order first, if that is not yet done.
50
	if(!$order->isFinalized()) $order->finalizeOrder();
51
	// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
52
	if($order->isFinalized()) $order->getCertificate();
53
}
54
55
echo "\nDiagnostic logs\n";
56
$logger->dumpConsole();