2012-08-25 18:49:11 -04:00
|
|
|
<?php
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2021-06-13 04:44:26 -04:00
|
|
|
use Google\Cloud\Core\Exception\BadRequestException;
|
|
|
|
use Google\Cloud\Core\Exception\NotFoundException;
|
|
|
|
use Google\Cloud\Storage\Bucket;
|
|
|
|
use Google\Cloud\Storage\Connection\ConnectionInterface;
|
|
|
|
use Google\Cloud\Storage\StorageClient;
|
|
|
|
use Google\Cloud\Storage\StorageObject;
|
2016-08-09 05:54:42 -04:00
|
|
|
use PrivateBin\Persistence\ServerSalt;
|
2016-07-21 11:09:48 -04:00
|
|
|
|
2016-07-26 02:19:35 -04:00
|
|
|
error_reporting(E_ALL | E_STRICT);
|
2012-08-25 18:49:11 -04:00
|
|
|
|
|
|
|
// change this, if your php files and data is outside of your webservers document root
|
2016-07-26 02:19:35 -04:00
|
|
|
if (!defined('PUBLIC_PATH')) {
|
|
|
|
define('PUBLIC_PATH', '..');
|
|
|
|
}
|
|
|
|
if (!defined('PATH')) {
|
|
|
|
define('PATH', '..' . DIRECTORY_SEPARATOR);
|
|
|
|
}
|
|
|
|
if (!defined('CONF')) {
|
2017-10-03 13:45:47 -04:00
|
|
|
define('CONF', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.php');
|
2016-07-26 02:19:35 -04:00
|
|
|
}
|
2017-10-08 05:03:17 -04:00
|
|
|
if (!defined('CONF_SAMPLE')) {
|
|
|
|
define('CONF_SAMPLE', PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.sample.php');
|
2016-07-26 02:19:35 -04:00
|
|
|
}
|
2012-08-25 18:49:11 -04:00
|
|
|
|
2016-07-21 11:09:48 -04:00
|
|
|
require PATH . 'vendor/autoload.php';
|
2016-08-16 05:11:03 -04:00
|
|
|
Helper::updateSubresourceIntegrity();
|
2012-08-25 18:49:11 -04:00
|
|
|
|
2021-06-13 04:44:26 -04:00
|
|
|
/**
|
|
|
|
* Class StorageClientStub provides a limited stub for performing the unit test
|
|
|
|
*/
|
|
|
|
class StorageClientStub extends StorageClient
|
|
|
|
{
|
2022-11-04 16:27:27 -04:00
|
|
|
private $_config = null;
|
|
|
|
private $_connection = null;
|
|
|
|
private static $_buckets = array();
|
2021-06-13 04:44:26 -04:00
|
|
|
|
|
|
|
public function __construct(array $config = array())
|
|
|
|
{
|
|
|
|
$this->_config = $config;
|
|
|
|
$this->_connection = new ConnectionInterfaceStub();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function bucket($name, $userProject = false)
|
|
|
|
{
|
2022-11-04 16:04:18 -04:00
|
|
|
if (!key_exists($name, self::$_buckets)) {
|
2021-06-13 04:44:26 -04:00
|
|
|
$b = new BucketStub($this->_connection, $name, array(), $this);
|
2022-11-04 16:04:18 -04:00
|
|
|
self::$_buckets[$name] = $b;
|
2021-06-13 04:44:26 -04:00
|
|
|
}
|
2022-11-04 16:04:18 -04:00
|
|
|
return self::$_buckets[$name];
|
2021-06-13 04:44:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws \Google\Cloud\Core\Exception\NotFoundException
|
|
|
|
*/
|
|
|
|
public function deleteBucket($name)
|
|
|
|
{
|
2022-11-04 16:04:18 -04:00
|
|
|
if (key_exists($name, self::$_buckets)) {
|
|
|
|
unset(self::$_buckets[$name]);
|
2021-06-13 04:44:26 -04:00
|
|
|
} else {
|
|
|
|
throw new NotFoundException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buckets(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function registerStreamWrapper($protocol = null)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unregisterStreamWrapper($protocol = null)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signedUrlUploader($uri, $data, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function timestamp(\DateTimeInterface $timestamp, $nanoSeconds = null)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceAccount(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hmacKeys(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hmacKey($accessId, $projectId = null, array $metadata = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createHmacKey($serviceAccountEmail, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createBucket($name, array $options = array())
|
|
|
|
{
|
2022-11-04 16:04:18 -04:00
|
|
|
if (key_exists($name, self::$_buckets)) {
|
2021-06-13 04:44:26 -04:00
|
|
|
throw new BadRequestException('already exists');
|
|
|
|
}
|
|
|
|
$b = new BucketStub($this->_connection, $name, array(), $this);
|
2022-11-04 16:04:18 -04:00
|
|
|
self::$_buckets[$name] = $b;
|
2021-06-13 04:44:26 -04:00
|
|
|
return $b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BucketStub stubs a GCS bucket.
|
|
|
|
*/
|
|
|
|
class BucketStub extends Bucket
|
|
|
|
{
|
|
|
|
public $_objects;
|
|
|
|
private $_name;
|
|
|
|
private $_info;
|
|
|
|
private $_connection;
|
|
|
|
private $_client;
|
|
|
|
|
|
|
|
public function __construct(ConnectionInterface $connection, $name, array $info = array(), $client = null)
|
|
|
|
{
|
|
|
|
$this->_name = $name;
|
|
|
|
$this->_info = $info;
|
|
|
|
$this->_connection = $connection;
|
|
|
|
$this->_objects = array();
|
|
|
|
$this->_client = $client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function acl()
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defaultAcl()
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
2022-12-12 14:49:04 -05:00
|
|
|
public function exists(array $options = array())
|
2021-06-13 04:44:26 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function upload($data, array $options = array())
|
|
|
|
{
|
|
|
|
if (!is_string($data) || !key_exists('name', $options)) {
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $options['name'];
|
|
|
|
$generation = '1';
|
|
|
|
$o = new StorageObjectStub($this->_connection, $name, $this, $generation, $options);
|
|
|
|
$this->_objects[$options['name']] = $o;
|
|
|
|
$o->setData($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadAsync($data, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getResumableUploader($data, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getStreamableUploader($data, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function object($name, array $options = array())
|
|
|
|
{
|
|
|
|
if (key_exists($name, $this->_objects)) {
|
|
|
|
return $this->_objects[$name];
|
|
|
|
} else {
|
|
|
|
return new StorageObjectStub($this->_connection, $name, $this, null, $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function objects(array $options = array())
|
|
|
|
{
|
|
|
|
$prefix = key_exists('prefix', $options) ? $options['prefix'] : '';
|
|
|
|
|
|
|
|
return new CallbackFilterIterator(
|
2023-06-18 06:54:22 -04:00
|
|
|
new ArrayIterator($this->_objects),
|
|
|
|
function ($current, $key, $iterator) use ($prefix) {
|
|
|
|
return substr($key, 0, strlen($prefix)) == $prefix;
|
|
|
|
}
|
2021-06-13 04:44:26 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createNotification($topic, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notification($id)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notifications(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(array $options = array())
|
|
|
|
{
|
|
|
|
$this->_client->deleteBucket($this->_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function compose(array $sourceObjects, $name, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function info(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reload(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function lifecycle(array $lifecycle = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function currentLifecycle(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isWritable($file = null)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function iam()
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lockRetentionPolicy(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signedUrl($expires, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generateSignedPostPolicyV4($objectName, $expires, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class StorageObjectStub stubs a GCS storage object.
|
|
|
|
*/
|
|
|
|
class StorageObjectStub extends StorageObject
|
|
|
|
{
|
|
|
|
private $_name;
|
|
|
|
private $_data;
|
|
|
|
private $_info;
|
|
|
|
private $_bucket;
|
|
|
|
private $_generation;
|
|
|
|
private $_exists = false;
|
|
|
|
private $_connection;
|
|
|
|
|
|
|
|
public function __construct(ConnectionInterface $connection, $name, $bucket, $generation = null, array $info = array(), $encryptionKey = null, $encryptionKeySHA256 = null)
|
|
|
|
{
|
|
|
|
$this->_name = $name;
|
|
|
|
$this->_bucket = $bucket;
|
|
|
|
$this->_generation = $generation;
|
|
|
|
$this->_info = $info;
|
|
|
|
$this->_connection = $connection;
|
2022-02-12 10:41:09 -05:00
|
|
|
$timeCreated = new DateTime();
|
2021-06-14 00:44:30 -04:00
|
|
|
$this->_info['metadata']['timeCreated'] = $timeCreated->format('Y-m-d\TH:i:s.u\Z');
|
2021-06-13 04:44:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function acl()
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exists(array $options = array())
|
|
|
|
{
|
|
|
|
return key_exists($this->_name, $this->_bucket->_objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function delete(array $options = array())
|
|
|
|
{
|
|
|
|
if (key_exists($this->_name, $this->_bucket->_objects)) {
|
|
|
|
unset($this->_bucket->_objects[$this->_name]);
|
|
|
|
} else {
|
|
|
|
throw new NotFoundException('key ' . $this->_name . ' not found.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function update(array $metadata, array $options = array())
|
|
|
|
{
|
|
|
|
if (!$this->_exists) {
|
|
|
|
throw new NotFoundException('key ' . $this->_name . ' not found.');
|
|
|
|
}
|
|
|
|
$this->_info = $metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function copy($destination, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rewrite($destination, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rename($name, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function downloadAsString(array $options = array())
|
|
|
|
{
|
|
|
|
if (!$this->_exists) {
|
|
|
|
throw new NotFoundException('key ' . $this->_name . ' not found.');
|
|
|
|
}
|
|
|
|
return $this->_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function downloadToFile($path, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function downloadAsStream(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function downloadAsStreamAsync(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signedUrl($expires, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signedUploadUrl($expires, array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function beginSignedUploadSession(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function info(array $options = array())
|
|
|
|
{
|
|
|
|
return key_exists('metadata',$this->_info) ? $this->_info['metadata'] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function reload(array $options = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function identity()
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function gcsUri()
|
|
|
|
{
|
|
|
|
return sprintf(
|
|
|
|
'gs://%s/%s',
|
|
|
|
$this->_bucket->name(),
|
|
|
|
$this->_name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setData($data)
|
|
|
|
{
|
|
|
|
$this->_data = $data;
|
|
|
|
$this->_exists = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ConnectionInterfaceStub required for the stubs.
|
|
|
|
*/
|
|
|
|
class ConnectionInterfaceStub implements ConnectionInterface
|
|
|
|
{
|
|
|
|
public function deleteAcl(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAcl(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listAcl(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insertAcl(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function patchAcl(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteBucket(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBucket(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listBuckets(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insertBucket(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBucketIamPolicy(array $args)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setBucketIamPolicy(array $args)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBucketIamPermissions(array $args)
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function patchBucket(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
2024-05-01 14:16:03 -04:00
|
|
|
public function restoreObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
2021-06-13 04:44:26 -04:00
|
|
|
public function copyObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function rewriteObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function composeObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listObjects(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function patchObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function downloadObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insertObject(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNotification(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteNotification(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function insertNotification(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listNotifications(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceAccount(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function lockRetentionPolicy(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createHmacKey(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteHmacKey(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHmacKey(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateHmacKey(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function listHmacKeys(array $args = array())
|
|
|
|
{
|
|
|
|
throw new BadMethodCallException('not supported by this stub');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Helper provides unit tests pastes and comments of various formats
|
|
|
|
*/
|
2016-08-09 05:54:42 -04:00
|
|
|
class Helper
|
2012-08-25 18:49:11 -04:00
|
|
|
{
|
2015-09-21 16:32:52 -04:00
|
|
|
/**
|
|
|
|
* example ID of a paste
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2019-05-03 17:03:57 -04:00
|
|
|
private static $pasteid = '5b65a01b43987bc2';
|
2015-09-21 16:32:52 -04:00
|
|
|
|
|
|
|
/**
|
2019-04-16 01:45:04 -04:00
|
|
|
* example paste version 1
|
2015-09-21 16:32:52 -04:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-04-16 01:45:04 -04:00
|
|
|
private static $pasteV1 = array(
|
2016-10-29 04:24:08 -04:00
|
|
|
'data' => '{"iv":"EN39/wd5Nk8HAiSG2K5AsQ","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"QKN1DBXe5PI","ct":"8hA83xDdXjD7K2qfmw5NdA"}',
|
|
|
|
'attachment' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
2015-09-26 06:29:27 -04:00
|
|
|
'attachmentname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
2016-10-29 04:24:08 -04:00
|
|
|
'meta' => array(
|
|
|
|
'formatter' => 'plaintext',
|
|
|
|
'postdate' => 1344803344,
|
2015-09-21 16:32:52 -04:00
|
|
|
'opendiscussion' => true,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2019-04-16 01:45:04 -04:00
|
|
|
/**
|
|
|
|
* example paste version 2
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $pasteV2 = array(
|
|
|
|
'adata' => array(
|
|
|
|
array(
|
|
|
|
'gMSNoLOk4z0RnmsYwXZ8mw==',
|
|
|
|
'TZO+JWuIuxs=',
|
|
|
|
100000,
|
|
|
|
256,
|
|
|
|
128,
|
|
|
|
'aes',
|
|
|
|
'gcm',
|
2019-05-03 14:51:01 -04:00
|
|
|
'zlib',
|
2019-04-16 01:45:04 -04:00
|
|
|
),
|
|
|
|
'plaintext',
|
2019-05-05 08:36:47 -04:00
|
|
|
1,
|
2019-05-10 15:45:34 -04:00
|
|
|
0,
|
2019-04-16 01:45:04 -04:00
|
|
|
),
|
2019-05-03 14:51:01 -04:00
|
|
|
'meta' => array(
|
2019-05-05 08:36:47 -04:00
|
|
|
'expire' => '5min',
|
2019-05-03 14:51:01 -04:00
|
|
|
),
|
2019-05-10 15:45:34 -04:00
|
|
|
'v' => 2,
|
2019-05-03 14:51:01 -04:00
|
|
|
'ct' => 'ME5JF/YBEijp2uYMzLZozbKtWc5wfy6R59NBb7SmRig=',
|
2019-04-16 01:45:04 -04:00
|
|
|
);
|
|
|
|
|
2015-09-21 16:32:52 -04:00
|
|
|
/**
|
|
|
|
* example ID of a comment
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $commentid = '5a52eebf11c4c94b';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* example comment
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-05-03 14:51:01 -04:00
|
|
|
private static $commentV1 = array(
|
2015-09-21 16:32:52 -04:00
|
|
|
'data' => '{"iv":"Pd4pOKWkmDTT9uPwVwd5Ag","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"6nOCU3peNDclDDpFtJEBKA"}',
|
|
|
|
'meta' => array(
|
|
|
|
'nickname' => '{"iv":"76MkAtOGC4oFogX/aSMxRA","v":1,"iter":1000,"ks":128,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"ZIUhFTliVz4","ct":"b6Ae/U1xJdsX/+lATud4sQ"}',
|
2016-10-29 04:24:08 -04:00
|
|
|
'vizhash' => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGUlEQVQokWOsl5/94983CNKQMjnxaOePf98MeKwPfNjkLZ3AgARab6b9+PeNEVnDj3/ff/z7ZiHnzsDA8Pv7H2TVPJw8EAYLAwb48OaVgIgYKycLsrYv378wMDB8//qdCVMDRA9EKSsnCwRBxNsepaLboMFlyMDAICAi9uHNK24GITQ/MDAwoNhgIGMLtwGrzegaLjw5jMz9+vUdnN17uwDCQDhJgk0O07yvX9+teDX1x79v6DYIsIjgcgMaYGFgYOBg4kJx2JejkAiBxAw+PzAwMNz4dp6wDXDw4MdNNOl0rWYsNkD89OLXI/xmo9sgzatJjAYmBgYGDiauD3/ePP18nVgb4MF89+M5ZX6js293wUMpnr8KTQMAxsCJnJ30apMAAAAASUVORK5CYII=',
|
2015-09-21 16:32:52 -04:00
|
|
|
'postdate' => 1344803528,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2016-08-16 05:11:03 -04:00
|
|
|
/**
|
|
|
|
* JS files and their SRI hashes
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private static $hashes = array();
|
|
|
|
|
2015-09-21 16:32:52 -04:00
|
|
|
/**
|
|
|
|
* get example paste ID
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getPasteId()
|
|
|
|
{
|
2024-03-23 06:27:25 -04:00
|
|
|
return self::$pasteid;
|
2015-09-21 16:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example paste, as stored on server
|
2015-09-21 16:32:52 -04:00
|
|
|
*
|
2019-05-03 14:51:01 -04:00
|
|
|
* @param int $version
|
|
|
|
* @param array $meta
|
2015-09-21 16:32:52 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-10 15:35:36 -04:00
|
|
|
public static function getPaste($version = 2, array $meta = array())
|
2015-09-26 06:29:27 -04:00
|
|
|
{
|
2019-05-03 14:51:01 -04:00
|
|
|
$example = self::getPasteWithAttachment($version, $meta);
|
|
|
|
// v1 has the attachment stored in a separate property
|
|
|
|
if ($version === 1) {
|
|
|
|
unset($example['attachment'], $example['attachmentname']);
|
|
|
|
}
|
2015-09-26 06:29:27 -04:00
|
|
|
return $example;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example paste with attachment, as stored on server
|
2015-09-26 06:29:27 -04:00
|
|
|
*
|
2019-05-03 14:51:01 -04:00
|
|
|
* @param int $version
|
|
|
|
* @param array $meta
|
2015-09-26 06:29:27 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-10 15:35:36 -04:00
|
|
|
public static function getPasteWithAttachment($version = 2, array $meta = array())
|
2015-09-21 16:32:52 -04:00
|
|
|
{
|
2019-05-05 08:36:47 -04:00
|
|
|
$example = $version === 1 ? self::$pasteV1 : self::$pasteV2;
|
2016-08-22 10:20:14 -04:00
|
|
|
$example['meta']['salt'] = ServerSalt::generate();
|
2016-10-29 04:24:08 -04:00
|
|
|
$example['meta'] = array_merge($example['meta'], $meta);
|
2015-09-21 16:32:52 -04:00
|
|
|
return $example;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:08:28 -04:00
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example paste, as decoded from POST by the request object
|
2015-10-18 05:08:28 -04:00
|
|
|
*
|
2019-05-03 14:51:01 -04:00
|
|
|
* @param int $version
|
|
|
|
* @param array $meta
|
2015-10-18 05:08:28 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-10 15:35:36 -04:00
|
|
|
public static function getPastePost($version = 2, array $meta = array())
|
2015-10-18 05:08:28 -04:00
|
|
|
{
|
2019-05-10 15:45:34 -04:00
|
|
|
$example = self::getPaste($version, $meta);
|
2021-06-13 04:44:26 -04:00
|
|
|
if ($version == 2) {
|
|
|
|
$example['meta'] = array('expire' => $example['meta']['expire']);
|
|
|
|
} else {
|
|
|
|
unset($example['meta']['postdate']);
|
|
|
|
}
|
2019-05-10 01:55:39 -04:00
|
|
|
return $example;
|
2015-10-18 05:08:28 -04:00
|
|
|
}
|
2019-05-10 15:45:34 -04:00
|
|
|
|
2019-05-06 16:15:21 -04:00
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example paste, as received via POST by the user
|
2019-05-06 16:15:21 -04:00
|
|
|
*
|
|
|
|
* @param int $version
|
2019-05-10 01:55:39 -04:00
|
|
|
* @param array $meta
|
2019-05-06 16:15:21 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-13 16:31:52 -04:00
|
|
|
public static function getPasteJson($version = 2, array $meta = array())
|
2019-05-06 16:15:21 -04:00
|
|
|
{
|
2019-05-13 16:31:52 -04:00
|
|
|
return json_encode(self::getPastePost($version, $meta));
|
2019-05-06 16:15:21 -04:00
|
|
|
}
|
|
|
|
|
2015-09-21 16:32:52 -04:00
|
|
|
/**
|
|
|
|
* get example paste ID
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getCommentId()
|
|
|
|
{
|
|
|
|
return self::$commentid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example comment, as stored on server
|
2015-09-21 16:32:52 -04:00
|
|
|
*
|
2019-05-03 14:51:01 -04:00
|
|
|
* @param int $version
|
|
|
|
* @param array $meta
|
2015-09-21 16:32:52 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-10 15:35:36 -04:00
|
|
|
public static function getComment($version = 2, array $meta = array())
|
2015-09-21 16:32:52 -04:00
|
|
|
{
|
2019-05-05 08:36:47 -04:00
|
|
|
$example = $version === 1 ? self::$commentV1 : self::$pasteV2;
|
2019-05-03 14:51:01 -04:00
|
|
|
if ($version === 2) {
|
2019-05-15 01:44:03 -04:00
|
|
|
$example['adata'] = $example['adata'][0];
|
2019-05-10 15:45:34 -04:00
|
|
|
$example['pasteid'] = $example['parentid'] = self::getPasteId();
|
2019-05-03 14:51:01 -04:00
|
|
|
$example['meta']['created'] = self::$commentV1['meta']['postdate'];
|
2019-05-10 15:45:34 -04:00
|
|
|
$example['meta']['icon'] = self::$commentV1['meta']['vizhash'];
|
2019-05-03 14:51:01 -04:00
|
|
|
unset($example['meta']['expire']);
|
|
|
|
}
|
2015-09-21 16:32:52 -04:00
|
|
|
$example['meta'] = array_merge($example['meta'], $meta);
|
|
|
|
return $example;
|
|
|
|
}
|
|
|
|
|
2015-10-03 09:52:37 -04:00
|
|
|
/**
|
2019-05-10 01:55:39 -04:00
|
|
|
* get example comment, as decoded from POST by the request object
|
2015-10-03 09:52:37 -04:00
|
|
|
*
|
2019-05-03 14:51:01 -04:00
|
|
|
* @param int $version
|
2015-10-03 09:52:37 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-06 16:15:21 -04:00
|
|
|
public static function getCommentPost()
|
2015-10-03 09:52:37 -04:00
|
|
|
{
|
2019-05-06 16:15:21 -04:00
|
|
|
$example = self::getComment();
|
|
|
|
unset($example['meta']);
|
2015-10-03 09:52:37 -04:00
|
|
|
return $example;
|
|
|
|
}
|
|
|
|
|
2019-05-10 01:55:39 -04:00
|
|
|
/**
|
|
|
|
* get example comment, as received via POST by user
|
|
|
|
*
|
|
|
|
* @param int $version
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-05-13 16:31:52 -04:00
|
|
|
public static function getCommentJson()
|
2019-05-10 01:55:39 -04:00
|
|
|
{
|
2019-05-13 16:31:52 -04:00
|
|
|
return json_encode(self::getCommentPost());
|
2019-05-10 01:55:39 -04:00
|
|
|
}
|
|
|
|
|
2015-08-29 04:41:10 -04:00
|
|
|
/**
|
|
|
|
* delete directory and all its contents recursively
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-05-10 16:00:34 -04:00
|
|
|
public static function rmDir($path)
|
2015-08-27 15:41:21 -04:00
|
|
|
{
|
2017-03-24 18:42:11 -04:00
|
|
|
if (is_dir($path)) {
|
|
|
|
$path .= DIRECTORY_SEPARATOR;
|
|
|
|
$dir = dir($path);
|
|
|
|
while (false !== ($file = $dir->read())) {
|
|
|
|
if ($file != '.' && $file != '..') {
|
|
|
|
if (is_dir($path . $file)) {
|
|
|
|
self::rmDir($path . $file);
|
|
|
|
} elseif (is_file($path . $file)) {
|
|
|
|
if (!unlink($path . $file)) {
|
|
|
|
throw new Exception('Error deleting file "' . $path . $file . '".');
|
|
|
|
}
|
2015-08-27 15:41:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-24 18:42:11 -04:00
|
|
|
$dir->close();
|
|
|
|
if (!rmdir($path)) {
|
|
|
|
throw new Exception('Error deleting directory "' . $path . '".');
|
|
|
|
}
|
2015-08-27 15:41:21 -04:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 04:41:10 -04:00
|
|
|
|
2015-09-22 17:21:31 -04:00
|
|
|
/**
|
|
|
|
* create a backup of the config file
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function confBackup()
|
|
|
|
{
|
2016-07-26 02:19:35 -04:00
|
|
|
if (!is_file(CONF . '.bak') && is_file(CONF)) {
|
2015-09-22 17:21:31 -04:00
|
|
|
rename(CONF, CONF . '.bak');
|
2016-07-26 02:19:35 -04:00
|
|
|
}
|
2017-10-08 05:03:17 -04:00
|
|
|
if (!is_file(CONF_SAMPLE . '.bak') && is_file(CONF_SAMPLE)) {
|
|
|
|
copy(CONF_SAMPLE, CONF_SAMPLE . '.bak');
|
|
|
|
}
|
2015-09-22 17:21:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* restor backup of the config file
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function confRestore()
|
|
|
|
{
|
2016-07-26 02:19:35 -04:00
|
|
|
if (is_file(CONF . '.bak')) {
|
2015-09-22 17:21:31 -04:00
|
|
|
rename(CONF . '.bak', CONF);
|
2016-07-26 02:19:35 -04:00
|
|
|
}
|
2017-10-08 05:03:17 -04:00
|
|
|
if (is_file(CONF_SAMPLE . '.bak')) {
|
|
|
|
rename(CONF_SAMPLE . '.bak', CONF_SAMPLE);
|
|
|
|
}
|
2015-09-22 17:21:31 -04:00
|
|
|
}
|
|
|
|
|
2015-08-29 04:41:10 -04:00
|
|
|
/**
|
|
|
|
* create ini file
|
|
|
|
*
|
|
|
|
* @param string $pathToFile
|
|
|
|
* @param array $values
|
|
|
|
*/
|
2019-05-10 16:00:34 -04:00
|
|
|
public static function createIniFile($pathToFile, array $values)
|
2015-08-29 04:41:10 -04:00
|
|
|
{
|
|
|
|
if (count($values)) {
|
|
|
|
@unlink($pathToFile);
|
|
|
|
$ini = fopen($pathToFile, 'a');
|
|
|
|
foreach ($values as $section => $options) {
|
|
|
|
fwrite($ini, "[$section]" . PHP_EOL);
|
2016-07-26 02:19:35 -04:00
|
|
|
foreach ($options as $option => $setting) {
|
2015-08-29 04:41:10 -04:00
|
|
|
if (is_null($setting)) {
|
|
|
|
continue;
|
|
|
|
} elseif (is_string($setting)) {
|
|
|
|
$setting = '"' . $setting . '"';
|
2015-09-26 21:03:55 -04:00
|
|
|
} elseif (is_array($setting)) {
|
|
|
|
foreach ($setting as $key => $value) {
|
|
|
|
if (is_null($value)) {
|
|
|
|
$value = 'null';
|
|
|
|
} elseif (is_string($value)) {
|
|
|
|
$value = '"' . $value . '"';
|
|
|
|
} else {
|
|
|
|
$value = var_export($value, true);
|
|
|
|
}
|
|
|
|
fwrite($ini, $option . "[$key] = $value" . PHP_EOL);
|
|
|
|
}
|
|
|
|
continue;
|
2015-08-29 04:41:10 -04:00
|
|
|
} else {
|
|
|
|
$setting = var_export($setting, true);
|
|
|
|
}
|
|
|
|
fwrite($ini, "$option = $setting" . PHP_EOL);
|
|
|
|
}
|
|
|
|
fwrite($ini, PHP_EOL);
|
|
|
|
}
|
|
|
|
fclose($ini);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a var_export that returns arrays without line breaks
|
|
|
|
* by linus@flowingcreativity.net via php.net
|
|
|
|
*
|
|
|
|
* @param mixed $var
|
|
|
|
* @param bool $return
|
|
|
|
* @return void|string
|
|
|
|
*/
|
2019-05-10 16:00:34 -04:00
|
|
|
public static function varExportMin($var, $return = false)
|
2015-08-29 04:41:10 -04:00
|
|
|
{
|
|
|
|
if (is_array($var)) {
|
|
|
|
$toImplode = array();
|
|
|
|
foreach ($var as $key => $value) {
|
2016-08-09 05:54:42 -04:00
|
|
|
$toImplode[] = var_export($key, true) . ' => ' . self::varExportMin($value, true);
|
2015-08-29 04:41:10 -04:00
|
|
|
}
|
|
|
|
$code = 'array(' . implode(', ', $toImplode) . ')';
|
|
|
|
if ($return) {
|
|
|
|
return $code;
|
|
|
|
} else {
|
|
|
|
echo $code;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return var_export($var, $return);
|
|
|
|
}
|
|
|
|
}
|
2016-08-16 05:11:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* update all templates with the latest SRI hashes for all JS files
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function updateSubresourceIntegrity()
|
|
|
|
{
|
|
|
|
$dir = dir(PATH . 'js');
|
|
|
|
while (false !== ($file = $dir->read())) {
|
|
|
|
if (substr($file, -3) === '.js') {
|
|
|
|
self::$hashes[$file] = base64_encode(
|
|
|
|
hash('sha512', file_get_contents(
|
|
|
|
PATH . 'js' . DIRECTORY_SEPARATOR . $file
|
|
|
|
), true)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$dir = dir(PATH . 'tpl');
|
|
|
|
while (false !== ($file = $dir->read())) {
|
|
|
|
if (substr($file, -4) === '.php') {
|
|
|
|
$content = file_get_contents(
|
|
|
|
PATH . 'tpl' . DIRECTORY_SEPARATOR . $file
|
|
|
|
);
|
|
|
|
$content = preg_replace_callback(
|
2018-07-01 01:51:05 -04:00
|
|
|
'#<script ([^>]+) src="js/([a-z0-9.-]+.js)([^"]*)"( integrity="[^"]+" crossorigin="[^"]+")?></script>#',
|
2016-08-16 05:11:03 -04:00
|
|
|
function ($matches) {
|
2018-07-01 01:51:05 -04:00
|
|
|
if (array_key_exists($matches[2], Helper::$hashes)) {
|
|
|
|
return '<script ' . $matches[1] . ' src="js/' .
|
|
|
|
$matches[2] . $matches[3] .
|
|
|
|
'" integrity="sha512-' . Helper::$hashes[$matches[2]] .
|
2016-08-16 05:11:03 -04:00
|
|
|
'" crossorigin="anonymous"></script>';
|
|
|
|
} else {
|
|
|
|
return $matches[0];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
$content
|
|
|
|
);
|
|
|
|
file_put_contents(
|
|
|
|
PATH . 'tpl' . DIRECTORY_SEPARATOR . $file,
|
|
|
|
$content
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-06 03:01:10 -04:00
|
|
|
}
|