Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Last active October 3, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treetop1500/047819afd8b2732e3cecab36578f5a26 to your computer and use it in GitHub Desktop.
Save treetop1500/047819afd8b2732e3cecab36578f5a26 to your computer and use it in GitHub Desktop.
A helper service for uploading to S3 via Froala
<?php
/**
* Created by PhpStorm.
* User: rwade@grayloon.com
* Date: 10/2/17
* Time: 12:18 PM
*/
namespace Hoyt\UtilBundle;
use S3;
class FroalaS3Service
{
private $timezone;
const keyStart = "uploads/froala/";
const acl = 'public-read';
private $bucket;
private $region;
private $accessKey;
private $secretKey;
/**
* @param string $key
* @param string $secret
* @param string $bucket
* @param string $region
*/
public function __construct($key, $secret, $bucket, $region)
{
$this->setAccessKey($key);
$this->setSecretKey($secret);
$this->setRegion($region);
$this->setBucket($bucket);
$this->setTimezone(date_default_timezone_get());
}
/**
* @return mixed
*/
public function getBucket()
{
return $this->bucket;
}
/**
* @param mixed $bucket
*/
public function setBucket($bucket)
{
$this->bucket = $bucket;
}
/**
* @return mixed
*/
public function getRegion()
{
return $this->region;
}
/**
* @param mixed $region
*/
public function setRegion($region)
{
$this->region = $region;
}
/**
* @return mixed
*/
public function getAccessKey()
{
return $this->accessKey;
}
/**
* @param mixed $accessKey
*/
public function setAccessKey($accessKey)
{
$this->accessKey = $accessKey;
}
/**
* @return mixed
*/
public function getSecretKey()
{
return $this->secretKey;
}
/**
* @param mixed $secretKey
*/
public function setSecretKey($secretKey)
{
$this->secretKey = $secretKey;
}
/**
* @return mixed
*/
public function getTimezone()
{
return $this->timezone;
}
/**
* @param mixed $timezone
*/
public function setTimezone($timezone)
{
$this->timezone = $timezone;
}
public function getS3Hash() {
$config = array(
'timezone' => $this->getTimezone(),
'bucket' => $this->getBucket(),
'region' => $this->getRegion(),
'keyStart' => self::keyStart,
'acl' => self::acl,
'accessKey' => $this->getAccessKey(),
'secretKey' => $this->getSecretKey(),
);
$hashed = json_encode(S3::getHash($config));
// Compute the signature.
return $hashed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment