This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
show-supported-formats-cached.php
executable file
·73 lines (48 loc) · 1.92 KB
/
show-supported-formats-cached.php
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
<?php
require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Zend\Cache\Cache;
use Zend\Service\LiveDocx\Helper;
use Zend\Service\LiveDocx\MailMerge;
Helper::printLine(
PHP_EOL . 'Template, Document and Image Formats' .
PHP_EOL .
PHP_EOL . 'The following formats are supported by LiveDocx:' .
PHP_EOL .
PHP_EOL . '(Note these method calls are cached for maximum performance. The supported formats change very infrequently, hence, they are good candidates to be cached.)' .
PHP_EOL .
PHP_EOL
);
$cacheId = md5(__FILE__);
$cacheFrontendOptions = array(
'lifetime' => 2592000, // 30 days
'automatic_serialization' => true
);
$cacheBackendOptions = array(
'cache_dir' => __DIR__ . '/cache'
);
if (!is_dir($cacheBackendOptions['cache_dir'])) {
mkdir($cacheBackendOptions['cache_dir']);
}
$cache = Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions);
if (! $formats = $cache->load($cacheId)) {
// Cache miss. Connect to backend service (expensive).
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$formats = new \StdClass();
$formats->template = $mailMerge->getTemplateFormats();
$formats->document = $mailMerge->getDocumentFormats();
$formats->image = $mailMerge->getImageExportFormats();
$cache->save($formats, $cacheId);
unset($mailMerge);
} else {
// Cache hit. Continue.
}
unset($cache);
printf("Supported TEMPLATE file formats (input) : %s%s",
Helper::arrayDecorator($formats->template), PHP_EOL);
printf("Supported DOCUMENT file formats (output) : %s%s",
Helper::arrayDecorator($formats->document), PHP_EOL);
printf("Supported IMAGE file formats (output) : %s%s",
Helper::arrayDecorator($formats->image), PHP_EOL);
print(PHP_EOL);