Commit 174d5cbc authored by Thorsten Buss's avatar Thorsten Buss

add local-url-aware adapter/repository for locale repository with possible...

add local-url-aware adapter/repository for locale repository with possible download link (file://) for local development systems (no need to generate a downloadURL for every getUrl())
FIX: S3 overwrite option wor downlod_url with %s replacement for key
parent 167bee06
......@@ -3,6 +3,11 @@ bnrepo-test-local:
dir: /tmp/bnrepo-test
create: true
bnrepo-test-local-url-aware:
type: localUrlAware
dir: /tmp/bnrepo-test
create: true
bnrepo-test-s3-DISABLED:
type: s3
aws_key: AWS_KEY
......
......@@ -108,7 +108,7 @@ class AdapterAmazonS3Ver2 extends AmazonS3 implements GaufretteAdapter, UrlAware
public function getUrl($key, $validTime = 0, $options = array()) {
// for CloudFront or static Domain, set download_url in Repositories.yml
if (array_key_exists('download_url', $options)) {
return $options['download_url'];
return sprintf($options['download_url'], $key);
}
$url = "https://{$this->bucket}.s3.amazonaws.com/{$this->computePath($key)}";
......
<?php
/**
* User: thorsten
* Date: 28.02.14
* Time: 14:45
*/
namespace BNRepo\Repository\Adapter;
class AdapterLocalUrlAware extends AdapterLocal implements Adapter, UrlAware {
/**
* Generates a URL to the File to Download/View
*
* @param string $key
* @param string $downloadUrl URL where the File could download (Controller with Repository::download())
* @param array $options
*
* @return string Generated URL
* @throws \Gaufrette\Exception\FileNotFound when key does not exist
* @throws \RuntimeException Url cannot generated
*/
public function getUrl($key, $downloadUrl = null, $options = array()) {
// genereic downloadmanager for whole repository, set download_url in Repositories.yml
if (array_key_exists('download_url', $options)) {
return sprintf($options['download_url'], $key);
}
return 'file://'.$this->computePath($key);
}
}
\ No newline at end of file
<?php
/**
* User: thorsten
* Date: 28.02.14
* Time: 14:49
*/
namespace BNRepo\Repository;
use BNRepo\Repository\Adapter\AdapterLocalUrlAware;
class RepositoryLocalUrlAware extends RepositoryLocal {
protected function createAdapter($cfg) {
if (!isset($cfg['dir']) || empty($cfg['dir']))
$cfg['dir'] = '/';
return new AdapterLocalUrlAware($cfg['dir'], isset($cfg['create']) ? $cfg['create'] : false);
}
}
<?php
/**
* User: thorsten
* Date: 28.02.14
* Time: 14:49
*/
namespace BNRepo\Tests\Repository;
class RepositoryLocalUrlAwareTest extends RepositoryLocalTest {
protected $cfg_id = 'bnrepo-test-local-url-aware';
public function testGetUrl() {
$this->_testGetUrl($this->repo());
}
public function testGetPublicUrl() {
/** @var $repo \BNRepo\Repository\RepositoryLocalUrlAware */
$repo = $this->repo();
$repo->write('public.txt', $this->test_content, true);
$url = $repo->getUrl('public.txt');
$this->assertEquals($this->test_content, file_get_contents($url), 'check Equal Content');
$repo->delete('public.txt');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment