invalidate() public method

Invalidates object with passed key on CloudFront
public invalidate ( $keys ) : boolean | string
$keys
return boolean | string
示例#1
0
 public static function cdnPurge()
 {
     $file = JRequest::getVar('purge');
     $cdn = JRequest::getVar('cdn');
     $result = false;
     if ($cdn == 'cloudfront') {
         $keys = JRequest::getVar('keys', '');
         list($accessKeyId, $secretKey, $distributionId) = explode('::', $keys);
         if ($accessKeyId && $secretKey && $distributionId) {
             require_once self::pluginLocation(true) . 'jbetolo/CloudFront.php';
             $cf = new CloudFront($accessKeyId, $secretKey, $distributionId);
             $result = $cf->invalidate($file);
         }
     } else {
         if ($cdn == 'maxcdn') {
             require_once self::pluginLocation(true) . 'jbetolo/xmlrpc/xmlrpc.inc';
             date_default_timezone_set('America/Los_Angeles');
             $cur = date('c');
             $keys = JRequest::getVar('keys', '');
             list($apiKey, $apiId) = explode('::', $keys);
             $namespace = 'cache';
             $method = 'purge';
             $authString = hash('sha256', $cur . ':' . $apiKey . ':' . $method);
             $f = new xmlrpcmsg("{$namespace}.{$method}", array(php_xmlrpc_encode($apiUserId), php_xmlrpc_encode($authString), php_xmlrpc_encode($cur), php_xmlrpc_encode($file)));
             $c = new xmlrpc_client("/xmlrpc/cache", "api.netdna.com", 80, 'http11');
             $result =& $c->send($f);
         }
     }
     return JText::_($result ? 'PLG_SYSTEM_JBETOLO_CDN_PURGE_SUCCESS' : 'PLG_SYSTEM_JBETOLO_CDN_PURGE_FAILED');
 }
	
	// your AWS/CloudFront keys go here
	$keyId          = ""; 
	$secretKey      = "";
	$distributionId = "";
	
	$key = ""; // String representing the existing CloudFront object to invalidate
	
	$cf  = new CloudFront($keyId, $secretKey, $distributionId);
?>
<html>
<head>
<style> textarea {width:100%; height:600px; font:12px/16px consolas;} </style>
</head>
<body>
	Key: <?php 
echo $key;
?>
<br/>
	<hr/>
	CF call:<br/>
	<?/* 
	 	Passing "true" to enable debugging for the purpose of this example. 
		This will render the XML response.
	*/?>
	<textarea><?php 
echo $cf->invalidate($key, true);
?>
</textarea>
</body>
</html>
<?
require 'CloudFront.php';

// your AWS/CloudFront keys go here
$keyId = "";
$secretKey = "";
$distributionId = "";

$key = ""; // String representing the existing CloudFront object to invalidate

$cf = new CloudFront($keyId, $secretKey, $distributionId);
$cf->invalidate($key);

?>
<html>
<head>
    <style> textarea {
        width: 100%;
        height: 600px;
        font: 12px/16px consolas;
    } </style>
</head>
<body>
Key: <?php 
echo $key;
?>
<br/>
<hr/>
CF call:<br/>
<!--Passing "true" to enable debugging for the purpose of this example.
This will render the XML response.-->