-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.php
More file actions
77 lines (60 loc) · 2.3 KB
/
Copy pathbasic.php
File metadata and controls
77 lines (60 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
require_once __DIR__ . '../../vendor/autoload.php';
use Dotcms\PhpSdk\Config\Config;
use Dotcms\PhpSdk\DotCMSClient;
use Dotcms\PhpSdk\Config\LogLevel;
// Create a configuration for the client
// Replace with your actual dotCMS host and API key
$config = new Config(
host: 'https://demo.dotcms.com',
apiKey: 'API_KEY',
clientOptions: [
'timeout' => 30,
'verify' => true, // Set to false if using self-signed certificates
],
logConfig: [
'level' => LogLevel::DEBUG,
'console' => true, // Output logs to console
]
);
// Create the dotCMS client
$client = new DotCMSClient($config);
try {
// Example 1: Fetch a page synchronously
echo "Fetching page synchronously...\n";
// Create a page request for a specific page
$pageRequest = $client->createPageRequest('/', 'json');
// Get the page
$page = $client->getPage($pageRequest);
$test = $page->template->title;
$test1 = $page->layout['rows'][0];
$test2 = $page->layout->body->rows[0]->columns[0]->containers[0];
// Display some information about the page
echo "Page title: " . $page->page->title . "\n";
echo "Page URL: " . $page->page->pageUrl . "\n";
echo "Template name: " . $page->template->title . "\n";
echo "Number of containers: " . count($page->containers) . "\n\n";
// Example 2: Fetch a page asynchronously
echo "Fetching page asynchronously...\n";
// Create another page request
$asyncPageRequest = $client->createPageRequest('/', 'json');
// Get the page asynchronously
$promise = $client->getPageAsync($asyncPageRequest);
// Add callbacks for success and failure
$promise->then(
function ($asyncPage) {
echo "Async page title: " . $asyncPage->page->title . "\n";
echo "Async page URL: " . $asyncPage->page->pageUrl . "\n";
echo "Async template name: " . $asyncPage->template->title . "\n";
},
function (\Exception $e) {
echo "Error fetching page asynchronously: " . $e->getMessage() . "\n";
}
);
// Wait for the promise to complete
$promise->wait();
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "Stack trace: " . $e->getTraceAsString() . "\n";
}