forked from sonata-project/SonataMediaBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PantherPortal.php
146 lines (128 loc) · 3.39 KB
/
PantherPortal.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\MediaBundle\CDN;
/**
* From https://pantherportal.cdnetworks.com/wsdl/flush.wsdl.
*
* flushRequest:
* username, password: credentials of a user that has web service access.
* siteId: the numeric id of the site to flush from.
* flushtype: the type of flush: "all" or "paths".
* paths: a newline-separated list of paths to flush. empty if flushtype is "all".
* wildcard: a boolean to activate wildcard mode. may be true only when flushtype is "paths".
* use_ims: a boolean to activate fetching with If-Modified-Since. may be true only when flushtype is "all" or wildcard is true.
*
* Please see the documentation available on the Panther Customer Portal
* for more detail about the effects of these parameters.
*
* Please note that an error with response "Over the limit of flush requests per hour" means that the flush is rate limited.
* Any requests until the rate limit is no longer exceeded will receive this response.
*/
class PantherPortal implements CDNInterface
{
/**
* @var string
*/
protected $path;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $siteId;
/**
* @var \SoapClient
*/
protected $client;
/**
* @var string
*/
protected $wsdl;
/**
* @param string $path
* @param string $username
* @param string $password
* @param string $siteId
* @param string $wsdl
*/
public function __construct($path, $username, $password, $siteId, $wsdl = 'https://pantherportal.cdnetworks.com/wsdl/flush.wsdl')
{
$this->path = $path;
$this->username = $username;
$this->password = $password;
$this->siteId = $siteId;
$this->wsdl = $wsdl;
}
/**
* {@inheritdoc}
*/
public function getPath($relativePath, $isFlushable)
{
return sprintf('%s/%s', $this->path, $relativePath);
}
/**
* {@inheritdoc}
*/
public function flushByString($string)
{
$this->flushPaths(array($string));
}
/**
* {@inheritdoc}
*/
public function flush($string)
{
$this->flushPaths(array($string));
}
/**
* {@inheritdoc}
*/
public function flushPaths(array $paths)
{
$result = $this->getClient()->flush($this->username, $this->password, 'paths', $this->siteId, implode("\n", $paths), true, false);
if ($result != 'Flush successfully submitted.') {
throw new \RuntimeException('Unable to flush : '.$result);
}
}
/**
* For testing only.
*
* @param $client
*/
public function setClient($client)
{
$this->client = $client;
}
/**
* {@inheritdoc}
*/
public function getFlushStatus($identifier)
{
// nothing to do
}
/**
* Return a SoapClient.
*
* @return \SoapClient
*/
private function getClient()
{
if (!$this->client) {
$this->client = new \SoapClient($this->wsdl);
}
return $this->client;
}
}