commit_id
string | repo
string | commit_message
string | diff
string | label
int64 |
---|---|---|---|---|
b1543bdbbc86fe874421e09b98c3310312eb17ba
|
1up-lab/OneupUploaderBundle
|
Fixed typo in orphanage.md
|
commit b1543bdbbc86fe874421e09b98c3310312eb17ba
Author: FunkeMT <[email protected]>
Date: Mon Feb 17 16:40:50 2014 +0100
Fixed typo in orphanage.md
diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index b4051a2..b489535 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -76,7 +76,7 @@ and default to ```orphanage```.
## Clean up
The `OrphanageManager` can be forced to clean up orphans by using the command provided by the OneupUploaderBundle.
- $> php app/console oneup:uploader:clean-orphans
+ $> php app/console oneup:uploader:clear-orphans
This parameter will clean all orphaned files older than the `maxage` value in your configuration.
| 0 |
70b5f5e04f1834e547fafdebb5ce35dba2c796d7
|
1up-lab/OneupUploaderBundle
|
process max size when string
|
commit 70b5f5e04f1834e547fafdebb5ce35dba2c796d7
Author: jbouzekri <[email protected]>
Date: Fri Jan 30 21:49:37 2015 +0100
process max size when string
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 34e707d..aec580d 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -69,7 +69,7 @@ class OneupUploaderExtension extends Extension
protected function processMapping($key, &$mapping)
{
- $mapping['max_size'] = $mapping['max_size'] < 0 ?
+ $mapping['max_size'] = $mapping['max_size'] < 0 || is_string($mapping['max_size']) ?
$this->getMaxUploadSize($mapping['max_size']) :
$mapping['max_size']
;
| 0 |
75df20dfc9f2aa035368a876678349b21649a198
|
1up-lab/OneupUploaderBundle
|
Composer: Added require_dev phpunit/phpunit 3.7.*
Just for avoid old and ugly pear
|
commit 75df20dfc9f2aa035368a876678349b21649a198
Author: Veniamin Albaev <[email protected]>
Date: Tue Jul 16 13:27:57 2013 +0400
Composer: Added require_dev phpunit/phpunit 3.7.*
Just for avoid old and ugly pear
diff --git a/composer.json b/composer.json
index 221dcaa..cd3bbd5 100644
--- a/composer.json
+++ b/composer.json
@@ -30,7 +30,8 @@
"symfony/yaml": "2.*",
"symfony/form": "2.*",
"symfony/twig-bundle": "2.*",
- "symfony/browser-kit": "2.*"
+ "symfony/browser-kit": "2.*",
+ "phpunit/phpunit": "3.7.*"
},
"suggest": {
| 0 |
e7cb8dcf98d16af8310bb56750d576247c7becdf
|
1up-lab/OneupUploaderBundle
|
Fixed some typos in documentation.
|
commit e7cb8dcf98d16af8310bb56750d576247c7becdf
Author: Jim Schmid <[email protected]>
Date: Fri Oct 11 19:19:02 2013 +0200
Fixed some typos in documentation.
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index b6c560d..7eefd95 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -38,7 +38,7 @@ oneup_uploader:
You can choose a custom directory to save the chunks temporarily while uploading by changing the parameter `directory`.
Since version 1.0 you can also use a Gaufrette filesystem as the chunk storage. To do this you must first
-set up [Gaufrette](gaufrette_storage.md).There are however some additional things to keep in mind.
+set up [Gaufrette](gaufrette_storage.md). There are however some additional things to keep in mind.
The configuration for the Gaufrette chunk storage should look as the following:
```
oneup_uploader:
@@ -46,14 +46,14 @@ oneup_uploader:
maxage: 86400
storage:
type: gaufrette
- filesystem: gaufrette.gallery_filesystem
+ filesystem: gaufrette.gallery_filesystem
prefix: 'chunks'
stream_wrapper: 'gaufrette://gallery/'
```
-> Setting the stream_wrapper is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings)
+> Setting the `stream_wrapper` is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings)
-As you can see there are is a new option, ```prefix```. It represents the directory
+As you can see there are is a new option, `prefix`. It represents the directory
*relative* to the filesystem's directory which the chunks are stored in.
Gaufrette won't allow it to be outside of the filesystem.
@@ -61,16 +61,16 @@ Gaufrette won't allow it to be outside of the filesystem.
only the Local filesystem is capable of streaming directly.
This will give you a better structured directory,
-as the chunk's folders and the uploaded files won't mix with each other.
-> You can set it to an empty string (```''```), if you don't need it. Otherwise it defaults to ```chunks```.
+as the chunk's folders and the uploaded files won't mix with each other.
+> You can set it to an empty string (`''`), if you don't need it. Otherwise it defaults to `chunks`.
-The chunks will be read directly from the tmp and appended to the already existing part on the given filesystem,
+The chunks will be read directly from the temporary directory and appended to the already existing part on the given filesystem,
resulting in only 1 read and 1 write operation.
-You can achieve the biggest improvement if you use the same filesystem as your storage, as if you do so, the assembled
-file only has to be moved out of the chunk directory, which on the same filesystem takes almost not time.
+You can achieve the biggest improvement if you use the same filesystem as your storage. If you do so, the assembled
+file only has to be moved out of the chunk directory, which takes no time on a local filesystem.
-> The ```load distribution``` is forcefully turned on, if you use gaufrette as the chunk storage.
+> The load distribution is forcefully turned on, if you use Gaufrette as the chunk storage.
## Clean up
diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md
index c03ba84..2e74a3c 100644
--- a/Resources/doc/gaufrette_storage.md
+++ b/Resources/doc/gaufrette_storage.md
@@ -53,7 +53,7 @@ knp_gaufrette:
local:
directory: %kernel.root_dir%/../web/uploads
create: true
-
+
filesystems:
gallery:
adapter: gallery
@@ -71,7 +71,7 @@ oneup_uploader:
gallery:
storage:
type: gaufrette
- filesystem: gaufrette.gallery_filesystem
+ filesystem: gaufrette.gallery_filesystem
```
You can specify the buffer size used for syncing files from your filesystem to the gaufrette storage by changing the property `sync_buffer_size`.
@@ -84,7 +84,7 @@ oneup_uploader:
gallery:
storage:
type: gaufrette
- filesystem: gaufrette.gallery_filesystem
+ filesystem: gaufrette.gallery_filesystem
sync_buffer_size: 1M
```
@@ -97,18 +97,18 @@ oneup_uploader:
gallery:
storage:
type: gaufrette
- filesystem: gaufrette.gallery_filesystem
+ filesystem: gaufrette.gallery_filesystem
stream_wrapper: gaufrette://gallery/
```
-> This is only useful if you are using a stream capable adapter, at the time of this writing only
+> This is only useful if you are using a stream-capable adapter. At the time of this writing, only
the local adapter is capable of streaming directly.
-The first part (```gaufrette```) in the example above ```MUST``` be the same as ```knp_gaufrette.stream_wrapper.protocol```,
-the second part (```gallery```) in the example, ```MUST``` be the key of the filesytem (```knp_gaufette.filesystems.key```).
-It also must end with a slash (```/```).
+The first part (`gaufrette`) in the example above `MUST` be the same as `knp_gaufrette.stream_wrapper.protocol`,
+the second part (`gallery`) in the example, `MUST` be the key of the filesytem (`knp_gaufette.filesystems.key`).
+It also must end with a slash (`/`).
This is particularly useful if you want to get exact informations about your files. Gaufrette offers you every functionality
to do this without relying on the stream wrapper, however it will have to download the file and load it into memory
-to operate on it. If ```stream_wrapper``` is specified the bundle will try to open the file as streams when such operation
-is requested.(e.g. getting the size of the file, the mime-type based on content)
+to operate on it. If `stream_wrapper` is specified, the bundle will try to open the file as streams when such operation
+is requested. (e.g. getting the size of the file, the mime-type based on content)
| 0 |
a1b15da3b36f478e66463c498382793dfc8c9b82
|
1up-lab/OneupUploaderBundle
|
Fixed a typo.
|
commit a1b15da3b36f478e66463c498382793dfc8c9b82
Author: Jim Schmid <[email protected]>
Date: Thu Apr 11 21:48:50 2013 +0200
Fixed a typo.
diff --git a/Resources/doc/frontend_uploadify.md b/Resources/doc/frontend_uploadify.md
index 78a3dbe..e84c7d5 100644
--- a/Resources/doc/frontend_uploadify.md
+++ b/Resources/doc/frontend_uploadify.md
@@ -3,7 +3,7 @@ Use Uploadify
Download [Uploadify](http://www.uploadify.com/download/) and include it in your template. Connect the `uploader` property to the dynamic route `_uploader_{mapping_name}` and include the FlashUploader file.
-> If you are using UploadiFive, please drop me a note. I'd like to know if this bundle also works works for the HTML5-Version of this frontend library.
+> If you are using UploadiFive, please drop me a note. I'd like to know if this bundle also works for the HTML5-Version of this frontend library.
```html
| 0 |
1c5b6cdfdd1a003c8ac7c30dee113dda4b8899ab
|
1up-lab/OneupUploaderBundle
|
Fix broken link (#358)
|
commit 1c5b6cdfdd1a003c8ac7c30dee113dda4b8899ab
Author: Sela <[email protected]>
Date: Tue Feb 19 14:13:20 2019 +0000
Fix broken link (#358)
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index bc3858f..50b7929 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -169,7 +169,7 @@ This is absolutely no problem, just follow the instructions given in the corresp
> Why didn't you implement the _delete_ feature provided by Fine Uploader?
-FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](http://docs.fineuploader.com/features/delete.html) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader.
+FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](http://docs.fineuploader.com/features/delete.html) and on [the blog](https://blog.fineuploader.com/delete-an-uploaded-file-in-3-3-3623bf6ec9c) of Fine Uploader.
> Why didn't you implement the _delete_ feature provided by another library?
| 0 |
75a380fa651ca456726fba944fd60ff5d20b7edb
|
1up-lab/OneupUploaderBundle
|
Merge pull request #18 from UseAllFive/GaufretteStorageWriteNotAppend
Fix RuntimeException: Could not read key content bug
|
commit 75a380fa651ca456726fba944fd60ff5d20b7edb (from 09141db3d858b433677c6275e6759abaa34bf1a9)
Merge: 09141db bf58310
Author: Jim Schmid <[email protected]>
Date: Tue Jun 11 23:54:30 2013 -0700
Merge pull request #18 from UseAllFive/GaufretteStorageWriteNotAppend
Fix RuntimeException: Could not read key content bug
diff --git a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
new file mode 100644
index 0000000..cfcf85d
--- /dev/null
+++ b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use \AmazonS3 as AmazonClient;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Gaufrette\Filesystem as GaufretteFilesystem;
+use Gaufrette\Adapter\AmazonS3 as S3Adapter;
+use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage;
+
+class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase
+{
+ protected $directory;
+ protected $storage;
+
+ public function setUp()
+ {
+ if(
+ "" == getenv('AWS_ACCESS_KEY_ID') ||
+ "" == getenv('AWS_SECRET_ACCESS_KEY') ||
+ "" == getenv('AWS_BUCKET')
+ ) {
+ $this->markTestSkipped('Missing AWS_* ENV variables.');
+ }
+
+ $this->prefix = 'someObscureStorage';
+ $this->directory = sys_get_temp_dir() .'/'. $this->prefix;
+ if(!file_exists($this->directory)) {
+ mkdir($this->directory);
+ }
+
+ // create temporary file
+ $this->file = tempnam($this->directory, 'uploader');
+
+ $pointer = fopen($this->file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ $service = new AmazonClient(array(
+ 'key' => getenv('AWS_ACCESS_KEY_ID'),
+ 'secret' => getenv('AWS_SECRET_ACCESS_KEY'),
+ ));
+ $adapter = new S3Adapter($service, getenv('AWS_BUCKET'));
+ $this->filesystem = new GaufretteFilesystem($adapter);
+
+ $this->storage = new GaufretteStorage($this->filesystem);
+ }
+
+ public function testUpload()
+ {
+ $payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true);
+ $this->storage->upload($payload, $this->prefix .'/notsogrumpyanymore.jpeg');
+
+ $files = $this->filesystem->listKeys($this->prefix);
+
+ // on Amazon S3, if it exists, it is considered a directory
+ $this->assertCount(2, $files['keys']);
+
+ foreach($files['keys'] as $filename)
+ {
+ if($filename === $this->prefix) {
+ // ignore the prefix directory
+ continue;
+ }
+ $this->assertEquals($this->prefix. '/notsogrumpyanymore.jpeg', $filename);
+ $this->assertEquals(1024, strlen($this->filesystem->read($filename)));
+ }
+ }
+
+ public function tearDown()
+ {
+ $files = $this->filesystem->listKeys($this->prefix);
+ foreach($files['keys'] as $filename)
+ {
+ if($this->filesystem->has($filename)) {
+ $this->filesystem->delete($filename);
+ }
+ }
+ }
+}
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 5823d50..47306ab 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -38,7 +38,7 @@ class GaufretteStorage implements StorageInterface
$this->filesystem->write($path, '', true);
$src->open(new StreamMode('rb+'));
- $dst->open(new StreamMode('ab+'));
+ $dst->open(new StreamMode('wb+'));
while(!$src->eof())
{
diff --git a/composer.json b/composer.json
index ac41496..e3ca30d 100644
--- a/composer.json
+++ b/composer.json
@@ -18,6 +18,7 @@
},
"require-dev": {
+ "amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
"symfony/class-loader": "2.*",
"symfony/security-bundle": "2.*",
| 0 |
fa48674308ca34c2c035d165ea113a3a8f1f9f7b
|
1up-lab/OneupUploaderBundle
|
Improved documentation.
|
commit fa48674308ca34c2c035d165ea113a3a8f1f9f7b
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 14:58:10 2013 +0200
Improved documentation.
diff --git a/README.md b/README.md
index 558ff06..48eb51b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
OneupUploaderBundle
===================
-The OneupUploaderBundle adds support for handling file uploads using one of the following Javascript libraries:
+The OneupUploaderBundle adds support for handling file uploads using one of the following Javascript libraries to your Symfony2 application:
* [FineUploader](http://fineuploader.com/)
* [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/)
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 357df8f..0aae9be 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -1,6 +1,8 @@
Getting started
===============
+The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.1+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself.
+
## Prerequisites
This bundle is tested using Symfony2 versions 2.1+.
@@ -117,4 +119,8 @@ some more advanced features.
> Why didn't you implement the _delete_ feature provided by Fine Uploader?
-Fine Uploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](https://github.com/Widen/fine-uploader/blob/master/docs/options-fineuploaderbasic.md#deletefile-option-properties) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader.
\ No newline at end of file
+FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](https://github.com/Widen/fine-uploader/blob/master/docs/options-fineuploaderbasic.md#deletefile-option-properties) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader.
+
+> Why didn't you implement the _delete_ feature provided by another library?
+
+See the answer to the previous question and replace _FineUploader_ by the library you have chosen.
\ No newline at end of file
| 0 |
ede6f6c407a75f8318e4bf77169a5567b1347313
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit ede6f6c407a75f8318e4bf77169a5567b1347313 (from 3a88954c9b402cc39c776008b96f34bb7225258a)
Merge: 3a88954 ee4f159
Author: Jim Schmid <[email protected]>
Date: Mon Aug 12 12:05:07 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 6472e05..1c8ec39 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -72,7 +72,7 @@ class Configuration implements ConfigurationInterface
->arrayNode('disallowed_mimetypes')
->prototype('scalar')->end()
->end()
- ->scalarNode('error_handler')->defaultValue('oneup_uploader.error_handler.noop')->end()
+ ->scalarNode('error_handler')->defaultNull()->end()
->scalarNode('max_size')
->defaultValue(\PHP_INT_MAX)
->info('Set max_size to -1 for gracefully downgrade this number to the systems max upload size.')
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index fa4cb90..fae9056 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -121,7 +121,9 @@ class OneupUploaderExtension extends Extension
throw new ServiceNotFoundException('Empty controller class or name. If you really want to use a custom frontend implementation, be sure to provide a class and a name.');
}
- $errorHandler = new Reference($mapping['error_handler']);
+ $errorHandler = is_null($mapping['error_handler']) ?
+ new Reference('oneup_uploader.error_handler.'.$mapping['frontend']) :
+ new Reference($mapping['error_handler']);
// create controllers based on mapping
$container
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index 025e38a..7bfb131 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -10,7 +10,14 @@
<services>
<service id="oneup_uploader.error_handler.noop" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.fineuploader" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false" />
+ <service id="oneup_uploader.error_handler.uploadify" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.yui3" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" />
</services>
</container>
commit ede6f6c407a75f8318e4bf77169a5567b1347313 (from ee4f159a981762183fa5193ff2eb060ab2e83852)
Merge: 3a88954 ee4f159
Author: Jim Schmid <[email protected]>
Date: Mon Aug 12 12:05:07 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/composer.json b/composer.json
index cd3bbd5..df76f99 100644
--- a/composer.json
+++ b/composer.json
@@ -13,12 +13,12 @@
"role": "Developer"
}
],
-
+
"require": {
"symfony/framework-bundle": "2.*",
- "symfony/finder": ">=2.0.16,<2.4-dev"
+ "symfony/finder": ">=2.2.0,<2.4-dev"
},
-
+
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
@@ -33,11 +33,11 @@
"symfony/browser-kit": "2.*",
"phpunit/phpunit": "3.7.*"
},
-
+
"suggest": {
"knplabs/knp-gaufrette-bundle": "0.1.*"
},
-
+
"autoload": {
"psr-0": { "Oneup\\UploaderBundle": "" }
},
| 0 |
1b544a0d5e188540d578eb783584ecc8bcdda9b7
|
1up-lab/OneupUploaderBundle
|
Added Validation test for FancyUpload.
|
commit 1b544a0d5e188540d578eb783584ecc8bcdda9b7
Author: Jim Schmid <[email protected]>
Date: Sat May 18 16:56:04 2013 +0200
Added Validation test for FancyUpload.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index a7d02f4..fcb884e 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -33,6 +33,15 @@ oneup_uploader:
frontend: fancyupload
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
+ fancyupload_validation:
+ frontend: fancyupload
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+ allowed_extensions: [ "ok" ]
+ disallowed_extensions: [ "fail" ]
+ allowed_mimetypes: [ "image/jpg", "text/plain" ]
+ disallowed_mimetypes: [ "image/gif" ]
yui3:
frontend: yui3
diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php
new file mode 100644
index 0000000..1ca342d
--- /dev/null
+++ b/Tests/Controller/FancyUploadValidationTest.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
+
+class FancyUploadValidationTest extends AbstractValidationTest
+{
+ protected function getConfigKey()
+ {
+ return 'fancyupload_validation';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getFileWithCorrectExtension()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'text/plain',
+ 128
+ );
+ }
+
+ protected function getFileWithIncorrectExtension()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.fail',
+ 'text/plain',
+ 128
+ );
+ }
+
+ protected function getFileWithCorrectMimeType()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'image/jpg',
+ 128
+ );
+ }
+
+ protected function getFileWithIncorrectMimeType()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'image/gif',
+ 128
+ );
+ }
+}
| 0 |
c4b736752cbc14c6c909df51b8136973698f081c
|
1up-lab/OneupUploaderBundle
|
Update README.md
Corrected backlink to packagist.
|
commit c4b736752cbc14c6c909df51b8136973698f081c
Author: Jim Schmid <[email protected]>
Date: Wed Jul 24 10:42:32 2013 +0200
Update README.md
Corrected backlink to packagist.
diff --git a/README.md b/README.md
index 07e647c..17de8d8 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Features included:
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
[](http://depending.in/1up-lab/OneupUploaderBundle)
-[](https://packagist.org/packages/symfony/symfony)
+[](https://packagist.org/packages/oneup/uploader-bundle)
Documentation
-------------
| 0 |
a4d2762d7c4cce87e6fc2b0914c7f046297ca417
|
1up-lab/OneupUploaderBundle
|
Fix doc (see #320)
|
commit a4d2762d7c4cce87e6fc2b0914c7f046297ca417
Author: Akash Gosai <[email protected]>
Date: Tue Jun 5 13:58:01 2018 +0530
Fix doc (see #320)
diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md
index c4fd761..5e267f5 100644
--- a/Resources/doc/custom_uploader.md
+++ b/Resources/doc/custom_uploader.md
@@ -14,7 +14,7 @@ oneup_uploader:
frontend: custom
custom_frontend:
class: Acme\DemoBundle\Controller\CustomController
- name: MyFancyCustomUploader
+ name: gallery
```
This will automatically create everything you need later.
| 0 |
66e395c1eebcc93b3cf2ac70d2cba22c096e4e3f
|
1up-lab/OneupUploaderBundle
|
Mocking madness.. Tested Controller, the first part.
|
commit 66e395c1eebcc93b3cf2ac70d2cba22c096e4e3f
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 15:56:13 2013 +0200
Mocking madness.. Tested Controller, the first part.
diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php
new file mode 100644
index 0000000..567d066
--- /dev/null
+++ b/Tests/Controller/ControllerTest.php
@@ -0,0 +1,101 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
+use Oneup\UploaderBundle\Controller\UploaderController;
+
+class ControllerTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tempFile;
+
+ public function setUp()
+ {
+ // create temporary file
+ $this->tempFile = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($this->tempFile, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+ }
+
+ public function testUpload()
+ {
+ $container = $this->getContainerMock();
+ $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
+ $config = array(
+ 'use_orphanage' => false,
+ 'namer' => 'namer',
+ 'max_size' => 2048,
+ 'allowed_extensions' => array(),
+ 'disallowed_extensions' => array()
+ );
+
+ $controller = new UploaderController($container, $storage, $config, 'cat');
+ $controller->upload();
+
+ // check if original file has been moved
+ $this->assertFalse(file_exists($this->tempFile));
+ }
+
+ protected function getContainerMock()
+ {
+ $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'containerGetCb')))
+ ;
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'request')
+ return $this->getRequestMock();
+
+ if($inp == 'event_dispatcher')
+ return $this->getEventDispatcherMock();
+
+ if($inp == 'namer')
+ return new UniqidNamer();
+ }
+
+ protected function getEventDispatcherMock()
+ {
+ $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $mock
+ ->expects($this->any())
+ ->method('dispatch')
+ ->will($this->returnValue(true))
+ ;
+
+ return $mock;
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->with('qqtotalparts')
+ ->will($this->returnValue(1))
+ ;
+
+ $mock->files = array(
+ $this->getUploadedFile()
+ );
+
+ return $mock;
+ }
+
+ protected function getUploadedFile()
+ {
+ return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
+ }
+}
\ No newline at end of file
| 0 |
c70ac38252200356540ec27b67853b2eb1106c53
|
1up-lab/OneupUploaderBundle
|
Add support for Gaufrette's FilesystemInterface (#284)
|
commit c70ac38252200356540ec27b67853b2eb1106c53
Author: Lctrs <[email protected]>
Date: Tue Nov 21 16:52:27 2017 +0100
Add support for Gaufrette's FilesystemInterface (#284)
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 9d22fd6..d7f581b 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -3,10 +3,10 @@
namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
use Gaufrette\Adapter\StreamFactory;
+use Gaufrette\Filesystem;
+use Gaufrette\FilesystemInterface;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
-use Gaufrette\Filesystem;
-
use Oneup\UploaderBundle\Uploader\Gaufrette\StreamManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -16,13 +16,27 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
protected $prefix;
protected $streamWrapperPrefix;
- public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
+ /**
+ * @param FilesystemInterface|Filesystem $filesystem
+ * @param int $bufferSize
+ * @param string $streamWrapperPrefix
+ * @param string $prefix
+ */
+ public function __construct($filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
{
+ $base = interface_exists('Gaufrette\FilesystemInterface')
+ ? 'Gaufrette\FilesystemInterface'
+ : 'Gaufrette\Filesystem';
+
+ if (!$filesystem instanceof $base) {
+ throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, is_object($filesystem) ? get_class($filesystem) : gettype($filesystem)));
+ }
+
if (!($filesystem->getAdapter() instanceof StreamFactory)) {
throw new \InvalidArgumentException('The filesystem used as chunk storage must implement StreamFactory');
}
$this->filesystem = $filesystem;
- $this->bufferSize = $bufferSize;
+ $this->buffersize = $bufferSize;
$this->prefix = $prefix;
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 39c9234..1d38ab8 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -4,16 +4,30 @@ namespace Oneup\UploaderBundle\Uploader\File;
use Gaufrette\Adapter\StreamFactory;
use Gaufrette\File;
-use Gaufrette\Filesystem;
use Gaufrette\Adapter\AwsS3;
+use Gaufrette\Filesystem;
+use Gaufrette\FilesystemInterface;
class GaufretteFile extends File implements FileInterface
{
protected $streamWrapperPrefix;
protected $mimeType;
- public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
+ /**
+ * @param File $file
+ * @param FilesystemInterface|Filesystem $filesystem
+ * @param string|null $streamWrapperPrefix
+ */
+ public function __construct(File $file, $filesystem, $streamWrapperPrefix = null)
{
+ $base = interface_exists('Gaufrette\FilesystemInterface')
+ ? 'Gaufrette\FilesystemInterface'
+ : 'Gaufrette\Filesystem';
+
+ if (!$filesystem instanceof $base) {
+ throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, is_object($filesystem) ? get_class($filesystem) : gettype($filesystem)));
+ }
+
parent::__construct($file->getKey(), $filesystem);
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php
index 7fcc83a..e745eef 100644
--- a/Uploader/Gaufrette/StreamManager.php
+++ b/Uploader/Gaufrette/StreamManager.php
@@ -46,7 +46,7 @@ class StreamManager
$this->openStream($src, 'r');
while (!$src->eof()) {
- $data = $src->read($this->bufferSize);
+ $data = $src->read($this->buffersize);
$dst->write($data);
}
diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php
index 4be4daa..b003236 100644
--- a/Uploader/Storage/GaufretteOrphanageStorage.php
+++ b/Uploader/Storage/GaufretteOrphanageStorage.php
@@ -4,7 +4,6 @@ namespace Oneup\UploaderBundle\Uploader\Storage;
use Gaufrette\File;
use Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage as GaufretteChunkStorage;
-use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -30,7 +29,7 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto
* initiate the storage on the chunk storage's filesystem
* the stream wrapper is useful for metadata.
*/
- parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, $chunkStorage->getStreamWrapperPrefix());
+ parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->buffersize, $chunkStorage->getStreamWrapperPrefix());
$this->storage = $storage;
$this->chunkStorage = $chunkStorage;
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 7b9bc7e..d83687e 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
+use Gaufrette\FilesystemInterface;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
use Gaufrette\Filesystem;
@@ -13,10 +14,23 @@ class GaufretteStorage extends StreamManager implements StorageInterface
{
protected $streamWrapperPrefix;
- public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix = null)
+ /**
+ * @param FilesystemInterface|Filesystem $filesystem
+ * @param int $bufferSize
+ * @param string|null $streamWrapperPrefix
+ */
+ public function __construct($filesystem, $bufferSize, $streamWrapperPrefix = null)
{
+ $base = interface_exists('Gaufrette\FilesystemInterface')
+ ? 'Gaufrette\FilesystemInterface'
+ : 'Gaufrette\Filesystem';
+
+ if (!$filesystem instanceof $base) {
+ throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, is_object($filesystem) ? get_class($filesystem) : gettype($filesystem)));
+ }
+
$this->filesystem = $filesystem;
- $this->bufferSize = $bufferSize;
+ $this->buffersize = $bufferSize;
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
| 0 |
05823b4693d9b9d2aae630a2b01f3cc6806e231a
|
1up-lab/OneupUploaderBundle
|
Added first chunked upload test for Plupload.
|
commit 05823b4693d9b9d2aae630a2b01f3cc6806e231a
Author: Jim Schmid <[email protected]>
Date: Mon May 6 23:20:01 2013 +0200
Added first chunked upload test for Plupload.
diff --git a/Tests/Controller/AbstractChunkedControllerTest.php b/Tests/Controller/AbstractChunkedControllerTest.php
new file mode 100644
index 0000000..61ea9c8
--- /dev/null
+++ b/Tests/Controller/AbstractChunkedControllerTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+abstract class AbstractChunkedControllerTest extends AbstractControllerTest
+{
+ protected $total = 6;
+
+ abstract protected function getNextRequestParameters($i);
+ abstract protected function getNextFile($i);
+
+ public function testChunkedUpload()
+ {
+ // assemble a request
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+
+ for($i = 0; $i < $this->total; $i ++) {
+ $client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($this->getNextFile($i)));
+ $response = $client->getResponse();
+
+ $this->assertTrue($response->isSuccessful());
+ $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
+ }
+
+ foreach($this->getUploadedFiles() as $file) {
+ $this->assertTrue($file->isFile());
+ $this->assertTrue($file->isReadable());
+ $this->assertEquals(120, $file->getSize());
+ }
+ }
+}
diff --git a/Tests/Controller/PluploadTest.php b/Tests/Controller/PluploadTest.php
index 216886f..1cb80a8 100644
--- a/Tests/Controller/PluploadTest.php
+++ b/Tests/Controller/PluploadTest.php
@@ -39,10 +39,10 @@ class PluploadTest extends AbstractChunkedControllerTest
protected function getNextFile($i)
{
return new UploadedFile(
- $this->createTempFile(21),
+ $this->createTempFile(20),
'cat.txt',
'text/plain',
- 21
+ 20
);
}
}
| 0 |
1ffd96c74e3d456a241138e4d80d1f99e5216f0c
|
1up-lab/OneupUploaderBundle
|
fix iterator access. fixes #190.
|
commit 1ffd96c74e3d456a241138e4d80d1f99e5216f0c
Author: Ulrich Völkel <[email protected]>
Date: Sat Sep 26 20:10:05 2015 +0200
fix iterator access. fixes #190.
diff --git a/Uploader/Chunk/Storage/FilesystemStorage.php b/Uploader/Chunk/Storage/FilesystemStorage.php
index 8855188..acc98d7 100644
--- a/Uploader/Chunk/Storage/FilesystemStorage.php
+++ b/Uploader/Chunk/Storage/FilesystemStorage.php
@@ -56,7 +56,7 @@ class FilesystemStorage implements ChunkStorageInterface
throw new \InvalidArgumentException('The first argument must implement \IteratorAggregate interface.');
}
- $iterator = $chunks->getIterator()->getInnerIterator();
+ $iterator = $chunks->getIterator();
$base = $iterator->current();
$iterator->next();
| 0 |
d7350835783f6ff5cd52c491c3a75cf38253e44b
|
1up-lab/OneupUploaderBundle
|
Merge pull request #1 from ThomasLandauer/ThomasLandauer-patch-1
Ordered JavaScript libraries by today's relevance
|
commit d7350835783f6ff5cd52c491c3a75cf38253e44b (from 18507cfb909f0d0a37b8a49cd0b06c6caa8fe1e6)
Merge: 18507cf 4cf7350
Author: Thomas Landauer <[email protected]>
Date: Tue Feb 16 21:03:05 2016 +0100
Merge pull request #1 from ThomasLandauer/ThomasLandauer-patch-1
Ordered JavaScript libraries by today's relevance
diff --git a/README.md b/README.md
index daa5eac..b6b3992 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,17 @@
OneupUploaderBundle
===================
-The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
+The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
-* [FineUploader](http://fineuploader.com/)
-* [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/)
-* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/)
-* [Uploadify](http://www.uploadify.com/)
-* [FancyUpload](http://digitarald.de/project/fancyupload/)
-* [MooUpload](https://github.com/juanparati/MooUpload)
-* [Plupload](http://www.plupload.com/)
+* [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/)
* [Dropzone](http://www.dropzonejs.com/)
+* [Plupload](http://www.plupload.com/)
+* [FineUploader](http://fineuploader.com/)
+* [FancyUpload](http://digitarald.de/project/fancyupload/) (based on MooTools)
+* [MooUpload](https://github.com/juanparati/MooUpload) (based on MooTools)
+* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) (the YUI library is no longer maintained)
+* [UploadiFive](http://www.uploadify.com/) ($ 5.00)
+
Features included:
diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md
index 66fc318..875fb3d 100644
--- a/Resources/doc/frontend_dropzone.md
+++ b/Resources/doc/frontend_dropzone.md
@@ -4,9 +4,9 @@ Use Dropzone in your Symfony2 application
Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`.
```html
-<script type="text/javascript" src="https://rawgithub.com/enyo/dropzone/master/downloads/dropzone.js"></script>
+<script type="text/javascript" src="https://raw.github.com/enyo/dropzone/master/dist/dropzone.js"></script>
-<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone">
+<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black">
</form>
```
commit d7350835783f6ff5cd52c491c3a75cf38253e44b (from 4cf73508bf6676454fcaed4b1d63f59817317153)
Merge: 18507cf 4cf7350
Author: Thomas Landauer <[email protected]>
Date: Tue Feb 16 21:03:05 2016 +0100
Merge pull request #1 from ThomasLandauer/ThomasLandauer-patch-1
Ordered JavaScript libraries by today's relevance
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 2e90a51..ac381bc 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -72,7 +72,7 @@ This bundle was designed to just work out of the box. The only thing you have to
oneup_uploader:
mappings:
gallery:
- frontend: blueimp # or any uploader you use in the frontend
+ frontend: dropzone # or any uploader you use in the frontend
```
To enable the dynamic routes, add the following to your routing configuration file.
@@ -85,13 +85,19 @@ oneup_uploader:
type: uploader
```
-The default directory that is used to upload files to is `web/uploads/{mapping_name}`.
+The default directory that is used to upload files to is `web/uploads/{mapping_name}`, where `{mapping_name}` is the value for `mappings` in your `config.yml` (namely `gallery` in the above example).
-> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you.
+### Step 4: Check if the bundle is working correctly
-### Step 4: Prepare your frontend
+No matter which JavaScript library you are going to use ultimately, we recommend to test the bundle with Dropzone first, since this one features the easiest setup process:
-No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
+1. [Install Dropzone](frontend_dropzone.md)
+1. Drag a file onto the dashed rectangle. The upload should start immediately. However, you won't get any visual feedback yet.
+1. Check your `web/uploads/gallery` directory: If you see the file there, the OneupUploaderBundle is working correctly. If you don't have that folder, create it manually and try again.
+
+### Step 5: Prepare your real frontend
+
+Now it's up to you to decide for a JavaScript library or write your own. Be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
```php
$helper = $this->container->get('oneup_uploader.templating.uploader_helper');
| 0 |
34d22041d40ff45f87de56cd617a580d48cbdd8c
|
1up-lab/OneupUploaderBundle
|
Fix #422 PHP 8.1 compatibility / deprecation warnings (#427)
|
commit 34d22041d40ff45f87de56cd617a580d48cbdd8c
Author: Martin Mandl <[email protected]>
Date: Mon Jul 25 09:48:07 2022 +0200
Fix #422 PHP 8.1 compatibility / deprecation warnings (#427)
diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php
index 8223619..e2507e0 100644
--- a/src/Uploader/Response/AbstractResponse.php
+++ b/src/Uploader/Response/AbstractResponse.php
@@ -46,6 +46,7 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
*
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->data[$offset] ?? null;
| 0 |
abb29a42947ea431d0c9b5f3c9092dbe334bd594
|
1up-lab/OneupUploaderBundle
|
Added new config option to the configuration reference.
|
commit abb29a42947ea431d0c9b5f3c9092dbe334bd594
Author: Jim Schmid <[email protected]>
Date: Wed Mar 5 07:27:06 2014 +0100
Added new config option to the configuration reference.
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index dcc5a20..6b0d248 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -34,6 +34,7 @@ oneup_uploader:
directory: ~
stream_wrapper: ~
sync_buffer_size: 100K
+ route_prefix:
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
| 0 |
e8133f933fa84ca26ea9dc7e6a358872e1292556
|
1up-lab/OneupUploaderBundle
|
Added support for Dropzone uploader.
Controller and Configuration part.
More information at http://www.dropzonejs.com/
|
commit e8133f933fa84ca26ea9dc7e6a358872e1292556
Author: Jim Schmid <[email protected]>
Date: Wed Sep 18 12:09:57 2013 +0200
Added support for Dropzone uploader.
Controller and Configuration part.
More information at http://www.dropzonejs.com/
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
new file mode 100644
index 0000000..17d6ba9
--- /dev/null
+++ b/Controller/DropzoneController.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+use Oneup\UploaderBundle\Controller\AbstractController;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class DropzoneController extends AbstractController
+{
+ public function upload()
+ {
+ $request = $this->container->get('request');
+ $response = new EmptyResponse();
+ $files = $this->getFiles($request->files);
+
+ foreach ($files as $file) {
+ try {
+ $uploaded = $this->handleUpload($file, $response, $request);
+ } catch (UploadException $e) {
+ $this->errorHandler->addException($response, $e);
+ }
+ }
+
+ return new JsonResponse($response->assemble());
+ }
+}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 1c8ec39..e18268a 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -37,7 +37,7 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->enumNode('frontend')
- ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'custom'))
+ ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom'))
->defaultValue('fineuploader')
->end()
->arrayNode('custom_frontend')
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index 7bfb131..e684668 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -17,6 +17,7 @@
<service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" />
</services>
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index f6c93af..39502ab 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -18,6 +18,7 @@
<parameter key="oneup_uploader.controller.fancyupload.class">Oneup\UploaderBundle\Controller\FancyUploadController</parameter>
<parameter key="oneup_uploader.controller.mooupload.class">Oneup\UploaderBundle\Controller\MooUploadController</parameter>
<parameter key="oneup_uploader.controller.plupload.class">Oneup\UploaderBundle\Controller\PluploadController</parameter>
+ <parameter key="oneup_uploader.controller.dropzone.class">Oneup\UploaderBundle\Controller\DropzoneController</parameter>
</parameters>
<services>
| 0 |
c753f9955148683c2e703d1251e8c1a12280ea60
|
1up-lab/OneupUploaderBundle
|
Added twig helper to get max_size configuration value in a template.
This reads and parses the configured value mapping.max_size and adds a
template helper to retrieve this value in a template.
Refs: #77
|
commit c753f9955148683c2e703d1251e8c1a12280ea60
Author: Jim Schmid <[email protected]>
Date: Sun Dec 15 09:52:21 2013 +0100
Added twig helper to get max_size configuration value in a template.
This reads and parses the configured value mapping.max_size and adds a
template helper to retrieve this value in a template.
Refs: #77
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index f6720a6..1d52140 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -39,13 +39,16 @@ class OneupUploaderExtension extends Extension
$container->setParameter('oneup_uploader.orphanage', $this->config['orphanage']);
$controllers = array();
+ $maxsize = array();
// handle mappings
foreach ($this->config['mappings'] as $key => $mapping) {
$controllers[$key] = $this->processMapping($key, $mapping);
+ $maxsize[$key] = $this->getMaxUploadSize($mapping['max_size']);
}
$container->setParameter('oneup_uploader.controllers', $controllers);
+ $container->setParameter('oneup_uploader.maxsize', $maxsize);
}
protected function processOrphanageConfig()
diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml
index a964783..a53e1f8 100644
--- a/Resources/config/templating.xml
+++ b/Resources/config/templating.xml
@@ -8,6 +8,7 @@
<service id="oneup_uploader.templating.uploader_helper" class="Oneup\UploaderBundle\Templating\Helper\UploaderHelper">
<argument type="service" id="router" />
+ <argument>%oneup_uploader.maxsize%</argument>
<tag name="templating.helper" alias="oneup_uploader" />
</service>
diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php
index c433675..1705356 100644
--- a/Templating/Helper/UploaderHelper.php
+++ b/Templating/Helper/UploaderHelper.php
@@ -8,10 +8,12 @@ use Symfony\Component\Templating\Helper\Helper;
class UploaderHelper extends Helper
{
protected $router;
+ protected $maxsize;
- public function __construct(RouterInterface $router)
+ public function __construct(RouterInterface $router, array $maxsize)
{
- $this->router = $router;
+ $this->router = $router;
+ $this->maxsize = $maxsize;
}
public function getName()
@@ -38,4 +40,13 @@ class UploaderHelper extends Helper
{
return ini_get('session.upload_progress.name');
}
+
+ public function maxSize($key)
+ {
+ if (!array_key_exists($key, $this->maxsize)) {
+ throw new \InvalidArgumentException('No such mapping found to get maxsize for.');
+ }
+
+ return $this->maxsize[$key];
+ }
}
diff --git a/Tests/Templating/TemplateHelperTest.php b/Tests/Templating/TemplateHelperTest.php
index a3cafbf..eda82e9 100644
--- a/Tests/Templating/TemplateHelperTest.php
+++ b/Tests/Templating/TemplateHelperTest.php
@@ -16,4 +16,17 @@ class TemplateHelperTest extends WebTestCase
// this is for code coverage
$this->assertEquals($helper->getName(), 'oneup_uploader');
}
+
+ public function testNonExistentMappingForMaxSize()
+ {
+ $this->setExpectedException('\InvalidArgumentException');
+
+ $client = static::createClient();
+ $container = $client->getContainer();
+
+ $helper = $container->get('oneup_uploader.templating.uploader_helper');
+ $helper->maxSize(uniqid());
+
+ $this->fail('No exception has been raised');
+ }
}
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index 2665a89..c042e56 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -21,10 +21,11 @@ class UploaderExtension extends \Twig_Extension
public function getFunctions()
{
return array(
- 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'),
- 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'),
- 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'),
- 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey')
+ 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'),
+ 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'),
+ 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'),
+ 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey'),
+ 'oneup_uploader_maxsize' => new \Twig_Function_Method($this, 'maxSize'),
);
}
@@ -47,4 +48,9 @@ class UploaderExtension extends \Twig_Extension
{
return $this->helper->uploadKey();
}
+
+ public function maxSize($key)
+ {
+ return $this->helper->maxSize($key);
+ }
}
| 0 |
68023c5268696390c86aa2c172497606c03d79e1
|
1up-lab/OneupUploaderBundle
|
Remove cache before executing tests
|
commit 68023c5268696390c86aa2c172497606c03d79e1
Author: Jim Schmid <[email protected]>
Date: Thu Jul 18 10:10:41 2013 +0200
Remove cache before executing tests
diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php
index f04fc53..a1756af 100644
--- a/Tests/bootstrap.php
+++ b/Tests/bootstrap.php
@@ -10,6 +10,7 @@ EOT
);
}
+passthru(sprintf('rm -rf %s/App/cache', __DIR__));
spl_autoload_register(function($class) {
if (0 === strpos($class, 'Oneup\\UploaderBundle\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
| 0 |
3afa894a70d3c7586141f0ddfff9a40a5435fdac
|
1up-lab/OneupUploaderBundle
|
Remove wrong comment.
|
commit 3afa894a70d3c7586141f0ddfff9a40a5435fdac
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 21:55:52 2013 +0200
Remove wrong comment.
diff --git a/Uploader/Response/BlueimpResponse.php b/Uploader/Response/BlueimpResponse.php
index a7e6c26..60be67b 100644
--- a/Uploader/Response/BlueimpResponse.php
+++ b/Uploader/Response/BlueimpResponse.php
@@ -21,9 +21,6 @@ class BlueimpResponse extends AbstractResponse
public function assemble()
{
- // explicitly overwrite success and error key
- // as these keys are used internaly by the
- // frontend uploader
$data = $this->data;
$data['files'] = $this->files;
| 0 |
c7c92b186d091523734db5585c15f73bbb820603
|
1up-lab/OneupUploaderBundle
|
Added Tests for UniqidNamer
|
commit c7c92b186d091523734db5585c15f73bbb820603
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 10:30:00 2013 +0200
Added Tests for UniqidNamer
diff --git a/Tests/Uploader/Naming/UniqidNamerTest.php b/Tests/Uploader/Naming/UniqidNamerTest.php
new file mode 100644
index 0000000..63567f7
--- /dev/null
+++ b/Tests/Uploader/Naming/UniqidNamerTest.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Naming;
+
+use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
+
+class UniqidNamerTest extends \PHPUnit_Framework_TestCase
+{
+ public function testNamerReturnsName()
+ {
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+
+ $file
+ ->expects($this->any())
+ ->method('guessExtension')
+ ->will($this->returnValue('jpeg'))
+ ;
+
+ $namer = new UniqidNamer();
+ $this->assertRegExp('/[a-z0-9]{13}.jpeg/', $namer->name($file));
+ }
+
+ public function testNamerReturnsUniqueName()
+ {
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+
+ $file
+ ->expects($this->any())
+ ->method('guessExtension')
+ ->will($this->returnValue('jpeg'))
+ ;
+
+ $namer = new UniqidNamer();
+
+ // get two different names
+ $name1 = $namer->name($file);
+ $name2 = $namer->name($file);
+
+ $this->assertNotEquals($name1, $name2);
+ }
+}
\ No newline at end of file
| 0 |
efaaa65412838f5b7cc1d8d4aaf2eb03c1746bd2
|
1up-lab/OneupUploaderBundle
|
Fixes BC for #294 (see #298)
|
commit efaaa65412838f5b7cc1d8d4aaf2eb03c1746bd2
Author: David Greminger <[email protected]>
Date: Thu Nov 23 10:02:01 2017 +0100
Fixes BC for #294 (see #298)
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index fac6246..487a972 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -113,7 +113,7 @@ abstract class AbstractController
if (!($file instanceof FileInterface)) {
$file = new FilesystemFile($file);
}
- $this->validate($file, $response, $request);
+ $this->validate($file, $request, $response);
$this->dispatchPreUploadEvent($file, $response, $request);
@@ -169,10 +169,10 @@ abstract class AbstractController
}
}
- protected function validate(FileInterface $file,ResponseInterface $response, Request $request)
+ protected function validate(FileInterface $file, Request $request, ResponseInterface $response = null)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $response, $request, $this->config, $this->type);
+ $event = new ValidationEvent($file, $request, $this->config, $this->type, $response);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index 4240059..cff3c99 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -15,7 +15,7 @@ class ValidationEvent extends Event
protected $request;
protected $response;
- public function __construct(FileInterface $file, ResponseInterface $response, Request $request, array $config, $type)
+ public function __construct(FileInterface $file, Request $request, array $config, $type, ResponseInterface $response = null)
{
$this->file = $file;
$this->config = $config;
| 0 |
59acfbb39d6a13161be95b46cd84454bdb094fc1
|
1up-lab/OneupUploaderBundle
|
Add correct array annotation (#420)
|
commit 59acfbb39d6a13161be95b46cd84454bdb094fc1
Author: David Greminger <[email protected]>
Date: Wed Jan 12 08:28:27 2022 +0100
Add correct array annotation (#420)
diff --git a/src/Uploader/Orphanage/OrphanageManager.php b/src/Uploader/Orphanage/OrphanageManager.php
index a2109b8..8a15620 100644
--- a/src/Uploader/Orphanage/OrphanageManager.php
+++ b/src/Uploader/Orphanage/OrphanageManager.php
@@ -75,6 +75,7 @@ class OrphanageManager
$finder = new Finder();
$finder->in($this->config['directory'])->directories();
+ /** @var array<int, \Symfony\Component\Finder\SplFileInfo> $dirArray */
$dirArray = iterator_to_array($finder, false);
$size = \count($dirArray);
| 0 |
92cb3219998b1b708c3028009b7439949211564e
|
1up-lab/OneupUploaderBundle
|
Add the correct Reference instead of the name of the reference to GaufretteStorage.
|
commit 92cb3219998b1b708c3028009b7439949211564e
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 18:06:14 2013 +0200
Add the correct Reference instead of the name of the reference to GaufretteStorage.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index c90c5cd..11e76ac 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -69,7 +69,7 @@ class OneupUploaderExtension extends Extension
{
$container
->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type'])))
- ->addArgument($mapping['storage']['filesystem'])
+ ->addArgument(new Reference($mapping['storage']['filesystem']))
;
}
| 0 |
1eb0446c70fea348102255d9afebacb9cc1e7308
|
1up-lab/OneupUploaderBundle
|
Made the cleanup command for orphans working again. We still need a solution to clear empty directories.
|
commit 1eb0446c70fea348102255d9afebacb9cc1e7308
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 16:52:26 2013 +0100
Made the cleanup command for orphans working again. We still need a solution to clear empty directories.
diff --git a/Command/ClearOrphansCommand.php b/Command/ClearOrphansCommand.php
index ae80570..46dcfdc 100644
--- a/Command/ClearOrphansCommand.php
+++ b/Command/ClearOrphansCommand.php
@@ -18,7 +18,7 @@ class ClearOrphansCommand extends ContainerAwareCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
- $manager = $this->getContainer()->get('oneup_uploader.orphanage');
+ $manager = $this->getContainer()->get('oneup_uploader.orphanage_manager');
$manager->clear();
}
}
\ No newline at end of file
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index e993938..9593d07 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -31,7 +31,7 @@ class OrphanageManager implements OrphanageManagerInterface
try
{
- $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
+ $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds')->files();
}
catch(\InvalidArgumentException $e)
{
| 0 |
d2652914296766d29f7ecff02058f4777a708b74
|
1up-lab/OneupUploaderBundle
|
Use 1.0 version of this bundle.
|
commit d2652914296766d29f7ecff02058f4777a708b74
Author: Jim Schmid <[email protected]>
Date: Wed Oct 23 15:17:17 2013 +0200
Use 1.0 version of this bundle.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 430fc08..bf97ce0 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -34,7 +34,7 @@ Add OneupUploaderBundle to your composer.json using the following construct:
```js
{
"require": {
- "oneup/uploader-bundle": "0.9.*@dev"
+ "oneup/uploader-bundle": "1.0.*@dev"
}
}
```
@@ -71,7 +71,8 @@ This bundle was designed to just work out of the box. The only thing you have to
oneup_uploader:
mappings:
- gallery: ~
+ gallery:
+ frontend: blueimp # or any uploader you use in the frontend
```
To enable the dynamic routes, add the following to your routing configuration file.
| 0 |
1e91e1e47f1a5e591e0adff95751df44843f9f85
|
1up-lab/OneupUploaderBundle
|
Moved the check for a custom error message entirely to the ValidationException.
|
commit 1e91e1e47f1a5e591e0adff95751df44843f9f85
Author: Jim Schmid <[email protected]>
Date: Mon Jul 15 12:00:02 2013 +0200
Moved the check for a custom error message entirely to the ValidationException.
diff --git a/Resources/doc/response.md b/Resources/doc/response.md
index 60807e6..bfef2ca 100644
--- a/Resources/doc/response.md
+++ b/Resources/doc/response.md
@@ -32,3 +32,5 @@ $response->setError($msg);
```
> Do not use the keys `success` and `error` if you provide custom data, they will be overwritten by the internal properties of `UploaderResponse`.
+
+Due to limitations of the `\ArrayAccess` regarding multi-dimensional array access, there is a method `addToOffset` which can be used to attach values to specific pathes in the array.
\ No newline at end of file
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index d9adf89..600d933 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -10,12 +10,7 @@ class BlueimpErrorHandler implements ErrorHandlerInterface
{
public function addException(ResponseInterface $response, UploadException $exception)
{
- if ($exception instanceof ValidationException) {
- $message = $exception->getErrorMessage();
- } else {
- $message = $exception->getMessage();
- }
-
+ $message = $exception->getErrorMessage();
$response->addToOffset(array('error' => $message), array('files'));
}
}
| 0 |
ec662ba25f61230854d6fbbd4706e503a1674c9e
|
1up-lab/OneupUploaderBundle
|
Added Upgrade Note for 1.0
|
commit ec662ba25f61230854d6fbbd4706e503a1674c9e
Author: Jim Schmid <[email protected]>
Date: Wed Oct 23 15:24:27 2013 +0200
Added Upgrade Note for 1.0
diff --git a/README.md b/README.md
index a8b708b..0abe5c1 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
+* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
* If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320).
* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads).
| 0 |
8389a0a5d0b06c084ebbad7b35f9afc10d122a7b
|
1up-lab/OneupUploaderBundle
|
Merge pull request #266 from mablae/patch-1
Add flysystem to Readme
|
commit 8389a0a5d0b06c084ebbad7b35f9afc10d122a7b (from 7920b4393d57e76038fbdb0e7152552ac52fd715)
Merge: 7920b43 2e926bd
Author: David Greminger <[email protected]>
Date: Tue Oct 4 15:26:27 2016 +0200
Merge pull request #266 from mablae/patch-1
Add flysystem to Readme
diff --git a/README.md b/README.md
index d0f6ed6..7f18c9a 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Features included:
* Multiple file uploads handled by your chosen frontend library
* Chunked uploads
-* Supports [Gaufrette](https://github.com/KnpLabs/Gaufrette) and/or local filesystem
+* Support for: [Gaufrette](https://github.com/KnpLabs/Gaufrette) / [Flysystem](https://github.com/thephpleague/flysystem) / local filesystem
* Provides an orphanage for cleaning up orphaned files
* Supports [Session upload progress & cancelation of uploads](http://php.net/manual/en/session.upload-progress.php) as of PHP 5.4
* Fully unit tested
| 0 |
5f8d0514844fa2ec4d8059236263d1057a2b9db9
|
1up-lab/OneupUploaderBundle
|
Forgot to commit composer.json with new tags.
|
commit 5f8d0514844fa2ec4d8059236263d1057a2b9db9
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 16:02:34 2013 +0200
Forgot to commit composer.json with new tags.
diff --git a/composer.json b/composer.json
index 99e963e..8124134 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
"description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support.",
- "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"],
+ "keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"],
"homepage": "http://1up.io",
"license": "MIT",
"authors": [
| 0 |
a453078f0ffc3496f482e39149768fbd1de63823
|
1up-lab/OneupUploaderBundle
|
Merge branch 'brandon1499-patch-1'
|
commit a453078f0ffc3496f482e39149768fbd1de63823 (from 5b1b2076daab43b3e8aaed9e0b43cb537142c456)
Merge: 5b1b207 d6e903c
Author: David Greminger <[email protected]>
Date: Fri Sep 15 16:32:50 2017 +0200
Merge branch 'brandon1499-patch-1'
diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php
index 9a98720..aa2fa61 100644
--- a/Uploader/Storage/FlysystemStorage.php
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -45,7 +45,9 @@ class FlysystemStorage implements StorageInterface
}
$stream = fopen($file->getPathname(), 'r+');
- $this->filesystem->putStream($name, $stream);
+ $this->filesystem->putStream($name, $stream, array(
+ 'mimetype' => $file->getMimeType()
+ ));
if (is_resource($stream)) {
fclose($stream);
}
| 0 |
39d0c0a3b8eb12ceb4d71586e95619810e03f0b1
|
1up-lab/OneupUploaderBundle
|
removed line
thanks!
|
commit 39d0c0a3b8eb12ceb4d71586e95619810e03f0b1
Author: MEDIA.figaro <[email protected]>
Date: Thu Jun 23 12:20:42 2016 +0200
removed line
thanks!
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 5af1774..7b6601e 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -100,7 +100,6 @@ If you want to use your own path, for example /data/uploads :
oneup_uploader:
mappings:
gallery:
- frontend: dropzone
storage:
directory: "%kernel.root_dir%/../data/uploads/"
```
| 0 |
275872e80c57a32d7e6461abed1d328f38aea6a8
|
1up-lab/OneupUploaderBundle
|
Documentation: Return custom data to the frontend.
|
commit 275872e80c57a32d7e6461abed1d328f38aea6a8
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 10:13:20 2013 +0200
Documentation: Return custom data to the frontend.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 63eb4ac..1d44c18 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -113,6 +113,7 @@ This is of course a very minimal setup. Be sure to include stylesheets for Fine
After installing and setting up the basic functionality of this bundle you can move on and integrate
some more advanced features.
+* [Return custom data to frontend](response.md)
* [Enable chunked uploads](chunked_uploads.md)
* [Using the Orphanage](orphanage.md)
* [Use Gaufrette as storage layer](gaufrette_storage.md)
diff --git a/Resources/doc/response.md b/Resources/doc/response.md
new file mode 100644
index 0000000..a438956
--- /dev/null
+++ b/Resources/doc/response.md
@@ -0,0 +1,6 @@
+Return custom data to the Frontend
+==================================
+
+There are some use cases where you need custom data to be returned to the frontend. For example the id of a generated Doctrine Entity or the like. To cover this, you can use `UploaderResponse` passed through all `Events`.
+
+```php
| 0 |
5baa9266d9e063bc2ee2b92d3d7ab5761559f188
|
1up-lab/OneupUploaderBundle
|
Added validator to validate disallowed extensions.
|
commit 5baa9266d9e063bc2ee2b92d3d7ab5761559f188
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 19:36:05 2013 +0200
Added validator to validate disallowed extensions.
diff --git a/EventListener/DisallowedExtensionValidationListener.php b/EventListener/DisallowedExtensionValidationListener.php
new file mode 100644
index 0000000..26a5f3a
--- /dev/null
+++ b/EventListener/DisallowedExtensionValidationListener.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class DisallowedExtensionValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+
+ if(count($config['disallowed_extensions']) > 0 && in_array($extension, $config['disallowed_extensions'])) {
+ throw new ValidationException('error.blacklist');
+ }
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml
index a272a48..3daeb90 100644
--- a/Resources/config/validation.xml
+++ b/Resources/config/validation.xml
@@ -6,11 +6,24 @@
<services>
- <service id="oneup_uploader.validation_listener.max_size" class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener">
+ <service
+ id="oneup_uploader.validation_listener.max_size"
+ class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener"
+ >
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
- <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener">
+ <service
+ id="oneup_uploader.validation_listener.allowed_extension"
+ class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener"
+ >
+ <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
+ </service>
+
+ <service
+ id="oneup_uploader.validation_listener.disallowed_extension"
+ class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener"
+ >
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
| 0 |
38cf65177d5d36cdfbd0f0ec6ecfa437b8335ae6
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit 38cf65177d5d36cdfbd0f0ec6ecfa437b8335ae6 (from cf5b24b8c21b8fe1301d546b24c247cdea2e2f88)
Merge: cf5b24b a2b58ac
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:46:13 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/README.md b/README.md
index 17de8d8..cfdfbdb 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,16 @@
+***
+
+**Warning**: There is currently a pretty serious issue reported. Until further notice,
+consider chunked uploads as *not-working*. It is highly recommended to switch from chunked
+uploads to non-chunked uploads until this issue is fixed again. You can find more
+information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21).
+
+***
+
+
OneupUploaderBundle
===================
+
The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
* [FineUploader](http://fineuploader.com/)
commit 38cf65177d5d36cdfbd0f0ec6ecfa437b8335ae6 (from a2b58acd47ee19bed944e45cb4488e338c97b3fe)
Merge: cf5b24b a2b58ac
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:46:13 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index d7d00ba..c197ec1 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -60,17 +60,12 @@ abstract class AbstractChunkedController extends AbstractController
if ($chunkManager->getLoadDistribution()) {
$chunks = $chunkManager->getChunks($uuid);
- $assembled = $chunkManager->assembleChunks($chunks);
+ $assembled = $chunkManager->assembleChunks($chunks, true, $last);
}
// if all chunks collected and stored, proceed
// with reassembling the parts
if ($last) {
- if (!$chunkManager->getLoadDistribution()) {
- $chunks = $chunkManager->getChunks($uuid);
- $assembled = $chunkManager->assembleChunks($chunks);
- }
-
$path = $assembled->getPath();
// create a temporary uploaded file to meet the interface restrictions
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 310cd0b..4e3e284 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -48,7 +48,7 @@ class ChunkManager implements ChunkManagerInterface
return $chunk->move($path, $name);
}
- public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true)
+ public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false)
{
$iterator = $chunks->getIterator()->getInnerIterator();
@@ -71,9 +71,15 @@ class ChunkManager implements ChunkManagerInterface
$iterator->next();
}
+ $name = $base->getBasename();
+
+ if ($renameChunk) {
+ $name = preg_replace('/^(\d+)_/', '', $base->getBasename());
+ }
+
// remove the prefix added by self::addChunk
$assembled = new File($base->getRealPath());
- $assembled = $assembled->move($base->getPath(), preg_replace('/^(.+?)_/', '', $base->getBasename()));
+ $assembled = $assembled->move($base->getPath(), $name);
return $assembled;
}
| 0 |
f26a7bbc5cd5995ab2f29b1103ffc9cbc778a968
|
1up-lab/OneupUploaderBundle
|
Merge pull request #215 from JHGitty/patch-1
Improve example on custom logic
|
commit f26a7bbc5cd5995ab2f29b1103ffc9cbc778a968 (from 550578a4b03a3fb819633a039b78d2c20eb2287f)
Merge: 550578a 5d61e56
Author: Jim Schmid <[email protected]>
Date: Mon Feb 8 08:38:00 2016 +0100
Merge pull request #215 from JHGitty/patch-1
Improve example on custom logic
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index ccb915e..6fea373 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -11,15 +11,21 @@ In almost every use case you need to further process uploaded files. For example
To listen to one of these events you need to create an `EventListener`.
```php
-namespace Acme\HelloBundle\EventListener;
+namespace AppBundle\EventListener;
+use Doctrine\Common\Persistence\ObjectManager;
use Oneup\UploaderBundle\Event\PostPersistEvent;
class UploadListener
{
- public function __construct($doctrine)
+ /**
+ * @var ObjectManager
+ */
+ private $om;
+
+ public function __construct(ObjectManager $om)
{
- $this->doctrine = $doctrine;
+ $this->om = $om;
}
public function onUpload(PostPersistEvent $event)
@@ -33,7 +39,7 @@ And register it in your `services.xml`.
```xml
<services>
- <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener\UploadListener">
+ <service id="app.upload_listener" class="AppBundle\EventListener\UploadListener">
<argument type="service" id="doctrine" />
<tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" />
</service>
@@ -43,8 +49,8 @@ And register it in your `services.xml`.
```yml
services:
acme_hello.upload_listener:
- class: Acme\HelloBundle\EventListener\UploadListener
- argument: ["@doctrine"]
+ class: AppBundle\EventListener\UploadListener
+ argument: ["@doctrine.orm.entity_manager"]
tags:
- { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload }
```
@@ -114,6 +120,6 @@ use Symfony\Component\HttpFoundation\File\Exception\UploadException;
public function onUpload(PostPersistEvent $event)
{
// Remember to remove the already uploaded file
- throw new UploadException('Nope, I dont do files');
+ throw new UploadException('Nope, I don\'t do files.');
}
```
commit f26a7bbc5cd5995ab2f29b1103ffc9cbc778a968 (from 5d61e56cdf0132ea1d39e6304f9a4f45d84372cf)
Merge: 550578a 5d61e56
Author: Jim Schmid <[email protected]>
Date: Mon Feb 8 08:38:00 2016 +0100
Merge pull request #215 from JHGitty/patch-1
Improve example on custom logic
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index fd6d87a..c577309 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -1,7 +1,7 @@
Using Chunked Uploads
=====================
-Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend.
+Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabled, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend.
```js
$(document).ready(function()
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index c83002d..256d2c6 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -10,7 +10,7 @@ First, create a custom namer which implements ```Oneup\UploaderBundle\Uploader\N
```php
<?php
-namespace Acme\DemoBundle;
+namespace AppBundle\Uploader\Naming;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
@@ -24,7 +24,7 @@ class CatNamer implements NamerInterface
}
```
-To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful.
+To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists.
Next, register your created namer as a service in your `services.xml`
@@ -36,8 +36,8 @@ Next, register your created namer as a service in your `services.xml`
```yml
services:
- acme_demo.custom_namer:
- class: Acme\DemoBundle\CatNamer
+ app.cat_namer:
+ class: AppBundle\Uploader\Naming\CatNamer
```
Now you can use your custom service by adding it to your configuration:
@@ -46,7 +46,7 @@ Now you can use your custom service by adding it to your configuration:
oneup_uploader:
mappings:
gallery:
- namer: acme_demo.custom_namer
+ namer: app.cat_namer
```
Every file uploaded through the `Controller` of this mapping will be named with your custom namer.
diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md
index cd8a019..22fbb16 100644
--- a/Resources/doc/frontend_fineuploader.md
+++ b/Resources/doc/frontend_fineuploader.md
@@ -1,26 +1,27 @@
Use FineUploader
================
-Download [FineUploader](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`.
+Download [FineUploader 5](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. This example is based on the [UI Mode](http://docs.fineuploader.com/branch/master/quickstart/01-getting-started.html) of FineUploader.
```html
-<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
-<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script>
+<link href="fine-uploader/fine-uploader-new.min.css" rel="stylesheet">
+<script type="text/javascript" src="fine-uploader/fine-uploader.min.js"></script>
<script type="text/javascript">
-$(document).ready(function()
-{
var uploader = new qq.FineUploader({
- element: $('#uploader')[0],
+ element: document.getElementById('fine-uploader'),
request: {
endpoint: "{{ oneup_uploader_endpoint('gallery') }}"
}
});
-});
</script>
-<div id="uploader"></div>
+<div id="fine-uploader"></div>
```
+You can find a fully example of all available settings on the [official documentation](http://docs.fineuploader.com/branch/master/quickstart/02-setting_options.html).
+
+If you are using Fine Uploader UI, as described in this example, you **MUST** include a template in your document/markup. You can use the ``default.html`` file in the templates directory bundled with the FineUploader library and customize it as desired. You even can use an inline template. See the official [styling documentation page](http://docs.fineuploader.com/branch/master/features/styling.html) for more details.
+
Configure the OneupUploaderBundle to use the correct controller:
```yaml
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 4178e9e..39ab715 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -34,19 +34,9 @@ Perform the following steps to install and use the basic functionality of the On
Add OneupUploaderBundle to your composer.json using the following construct:
-```js
-{
- "require": {
- "oneup/uploader-bundle": "~1.4"
- }
-}
-```
-
-Now tell composer to download the bundle by running the following command:
-
- $> php composer.phar update oneup/uploader-bundle
+ $ composer require oneup/uploader-bundle "~1.4"
-Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup```
+Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory.
### Step 2: Enable the bundle
| 0 |
3353b55aafd45f8874f91646b74d48fc3b296e04
|
1up-lab/OneupUploaderBundle
|
Started commenting AbstractController.
|
commit 3353b55aafd45f8874f91646b74d48fc3b296e04
Author: Jim Schmid <[email protected]>
Date: Tue Jun 4 10:01:47 2013 +0200
Started commenting AbstractController.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 06ba7d7..47e07a4 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -34,6 +34,16 @@ abstract class AbstractController
abstract public function upload();
+ /**
+ * This internal function handles the actual upload process
+ * and will most likely be called from the upload()
+ * function in the implemented Controller.
+ *
+ * Note: The return value differs when
+ *
+ * @param UploadedFile The file to upload
+ * @return File the actual file
+ */
protected function handleUpload(UploadedFile $file)
{
$this->validate($file);
@@ -48,6 +58,10 @@ abstract class AbstractController
return $uploaded;
}
+ /**
+ * This function is a helper function which dispatches post upload
+ * and post persist events.
+ */
protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
| 0 |
192cccbe3106aad04d2369feca0f6bfda092e01f
|
1up-lab/OneupUploaderBundle
|
Added documentation section to readme.
|
commit 192cccbe3106aad04d2369feca0f6bfda092e01f
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 12:14:30 2013 +0200
Added documentation section to readme.
diff --git a/README.md b/README.md
index 9e0e312..d674be8 100644
--- a/README.md
+++ b/README.md
@@ -13,6 +13,13 @@ Features included:
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
+Documentation
+-------------
+
+The entry point of the documentation can be found in the file `Resources/docs/index.md`
+
+[Read the documentation for master](...)
+
License
-------
| 0 |
c0c044660aef7a57f6b63885ac367786bc9251e8
|
1up-lab/OneupUploaderBundle
|
Merge branch 'request-masterrequest' of https://github.com/lsv/OneupUploaderBundle into lsv-request-masterrequest
|
commit c0c044660aef7a57f6b63885ac367786bc9251e8 (from 5f132712944010de0c2b119f708e9eee96d6c5ec)
Merge: 5f13271 12c37c7
Author: David Greminger <[email protected]>
Date: Thu Dec 10 10:56:22 2015 +0100
Merge branch 'request-masterrequest' of https://github.com/lsv/OneupUploaderBundle into lsv-request-masterrequest
diff --git a/.travis.yml b/.travis.yml
index 1b0403c..26b3eb4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -42,5 +42,6 @@ matrix:
before_script:
- composer selfupdate
+ - composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
- composer install --dev --prefer-source
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 62f9df1..691a44f 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -7,7 +7,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
abstract class AbstractChunkedController extends AbstractController
@@ -45,7 +44,6 @@ abstract class AbstractChunkedController extends AbstractController
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
// get basic container stuff
- $request = $this->container->get('request');
$chunkManager = $this->container->get('oneup_uploader.chunk_manager');
// get information about this chunked request
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index b150214..01ae713 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -17,6 +17,7 @@ use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Symfony\Component\HttpKernel\Kernel;
abstract class AbstractController
{
@@ -38,7 +39,7 @@ abstract class AbstractController
public function progress()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
@@ -54,7 +55,7 @@ abstract class AbstractController
public function cancel()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
@@ -73,8 +74,8 @@ abstract class AbstractController
/**
* Flattens a given filebag to extract all files.
*
- * @param bag The filebag to use
- * @return array An array of files
+ * @param FileBag $bag The filebag to use
+ * @return array An array of files
*/
protected function getFiles(FileBag $bag)
{
@@ -100,9 +101,9 @@ abstract class AbstractController
*
* Note: The return value differs when
*
- * @param The file to upload
- * @param response A response object.
- * @param request The request object.
+ * @param mixed $file The file to upload
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function handleUpload($file, ResponseInterface $response, Request $request)
{
@@ -129,9 +130,9 @@ abstract class AbstractController
/**
* This function is a helper function which dispatches pre upload event
*
- * @param uploaded The uploaded file.
- * @param response A response object.
- * @param request The request object.
+ * @param FileInterface $uploaded The uploaded file.
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request)
{
@@ -147,9 +148,9 @@ abstract class AbstractController
* This function is a helper function which dispatches post upload
* and post persist events.
*
- * @param uploaded The uploaded file.
- * @param response A response object.
- * @param request The request object.
+ * @param mixed $uploaded The uploaded file.
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request)
{
@@ -171,7 +172,7 @@ abstract class AbstractController
protected function validate(FileInterface $file)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->container->get('request'), $this->config, $this->type);
+ $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
}
@@ -189,7 +190,7 @@ abstract class AbstractController
*/
protected function createSupportedJsonResponse($data, $statusCode = 200)
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new JsonResponse($data, $statusCode);
$response->headers->set('Vary', 'Accept');
@@ -199,4 +200,20 @@ abstract class AbstractController
return $response;
}
+
+ /**
+ * Get the master request
+ *
+ * @return Request
+ */
+ protected function getRequest()
+ {
+
+ if (version_compare(Kernel::VERSION, '2.4', '<=')) {
+ return $this->container->get('request');
+ }
+
+ return $this->container->get('request_stack')->getMasterRequest();
+ }
+
}
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index f9186c7..f12329e 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class BlueimpController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
@@ -34,7 +33,7 @@ class BlueimpController extends AbstractChunkedController
public function progress()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index fd11420..b4fdc99 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class DropzoneController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
$statusCode = 200;
diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php
index bc21006..2aae793 100644
--- a/Controller/FancyUploadController.php
+++ b/Controller/FancyUploadController.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class FancyUploadController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 246b7f6..79cab8c 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
class FineUploaderController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$translator = $this->container->get('translator');
$response = new FineUploaderResponse();
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index e4f055b..95babd4 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -6,7 +6,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\MooUploadResponse;
class MooUploadController extends AbstractChunkedController
@@ -15,7 +14,7 @@ class MooUploadController extends AbstractChunkedController
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new MooUploadResponse();
$headers = $request->headers;
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index 56cb151..ee0ceb4 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class PluploadController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index ea68396..b93c725 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class UploadifyController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index c79e72b..043cacc 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class YUI3Controller extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md
index 20de413..c4fd761 100644
--- a/Resources/doc/custom_uploader.md
+++ b/Resources/doc/custom_uploader.md
@@ -40,7 +40,7 @@ class CustomUploader extends UploaderController
public function upload()
{
// get some basic stuff together
- $request = $this->container->get('request');
+ $request = $this->container->get('request_stack')->getMasterRequest();
$response = new EmptyResponse();
// get file from request (your own logic)
diff --git a/composer.json b/composer.json
index aa66e5d..3d9a755 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,8 @@
],
"require": {
- "symfony/framework-bundle": ">=2.2",
+ "symfony/framework-bundle": "^2.3.0",
+ "symfony/http-kernel": "^2.3.0",
"symfony/finder": ">=2.2.0"
},
commit c0c044660aef7a57f6b63885ac367786bc9251e8 (from 12c37c7407cfc8d34e93ca3243f9e9f786180756)
Merge: 5f13271 12c37c7
Author: David Greminger <[email protected]>
Date: Thu Dec 10 10:56:22 2015 +0100
Merge branch 'request-masterrequest' of https://github.com/lsv/OneupUploaderBundle into lsv-request-masterrequest
diff --git a/.travis.yml b/.travis.yml
index f9fa7be..26b3eb4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,21 +5,39 @@ php:
- 5.4
- 5.5
- 5.6
+ - 7.0
- hhvm
env:
- SYMFONY_VERSION=2.3.*
+ - SYMFONY_VERSION=2.7.*
+ - SYMFONY_VERSION=2.8.*
+
+cache:
+ directories:
+ - $COMPOSER_CACHE_DIR
matrix:
allow_failures:
- - env: SYMFONY_VERSION=dev-master
- php: hhvm
+ - env: SYMFONY_VERSION=dev-master
+
include:
- - php: 5.5
+ - php: 5.6
+ env: SYMFONY_VERSION=2.3.*
+ - php: 5.6
env: SYMFONY_VERSION=2.4.*
- - php: 5.5
+ - php: 5.6
env: SYMFONY_VERSION=2.5.*
- - php: 5.5
+ - php: 5.6
+ env: SYMFONY_VERSION=2.6.*
+ - php: 5.6
+ env: SYMFONY_VERSION=2.7.*
+ - php: 5.6
+ env: SYMFONY_VERSION=2.8.*
+ - php: 5.6
+ env: SYMFONY_VERSION=3.0.*
+ - php: 5.6
env: SYMFONY_VERSION=dev-master
before_script:
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 8b1dfc5..01ae713 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -184,13 +184,14 @@ abstract class AbstractController
* then the content type of the response will be set to text/plain instead.
*
* @param mixed $data
+ * @param int $statusCode
*
* @return JsonResponse
*/
- protected function createSupportedJsonResponse($data)
+ protected function createSupportedJsonResponse($data, $statusCode = 200)
{
$request = $this->getRequest();
- $response = new JsonResponse($data);
+ $response = new JsonResponse($data, $statusCode);
$response->headers->set('Vary', 'Accept');
if (!in_array('application/json', $request->getAcceptableContentTypes())) {
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index 11b5339..b4fdc99 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -13,11 +13,12 @@ class DropzoneController extends AbstractController
$request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
-
+ $statusCode = 200;
foreach ($files as $file) {
try {
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
+ $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x
$this->errorHandler->addException($response, $e);
$translator = $this->container->get('translator');
$message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle');
@@ -27,6 +28,6 @@ class DropzoneController extends AbstractController
}
}
- return $this->createSupportedJsonResponse($response->assemble());
+ return $this->createSupportedJsonResponse($response->assemble(), $statusCode);
}
}
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index e684668..bf580bf 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -6,6 +6,7 @@
<parameters>
<parameter key="oneup_uploader.error_handler.noop.class">Oneup\UploaderBundle\Uploader\ErrorHandler\NoopErrorHandler</parameter>
<parameter key="oneup_uploader.error_handler.blueimp.class">Oneup\UploaderBundle\Uploader\ErrorHandler\BlueimpErrorHandler</parameter>
+ <parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter>
</parameters>
<services>
@@ -17,7 +18,7 @@
<service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
- <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" />
<service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" />
</services>
diff --git a/Uploader/ErrorHandler/DropzoneErrorHandler.php b/Uploader/ErrorHandler/DropzoneErrorHandler.php
new file mode 100755
index 0000000..5b0ad44
--- /dev/null
+++ b/Uploader/ErrorHandler/DropzoneErrorHandler.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Exception;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class DropzoneErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(AbstractResponse $response, Exception $exception)
+ {
+ $errors[] = $exception;
+ $message = $exception->getMessage();
+ // Dropzone wants JSON with error message put into 'error' field.
+ // This overwrites the previous error message, so we're only displaying the last one.
+ $response['error'] = $message;
+ }
+}
| 0 |
c4a5f7a9150448ca03442531d07d171baaf2b501
|
1up-lab/OneupUploaderBundle
|
Remove error key if success is true.
|
commit c4a5f7a9150448ca03442531d07d171baaf2b501
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 11:16:06 2013 +0200
Remove error key if success is true.
diff --git a/Uploader/Response/UploaderResponse.php b/Uploader/Response/UploaderResponse.php
index d7ae71a..090df34 100644
--- a/Uploader/Response/UploaderResponse.php
+++ b/Uploader/Response/UploaderResponse.php
@@ -23,6 +23,9 @@ class UploaderResponse implements \ArrayAccess
$data = $this->data;
$data['success'] = $this->success;
+ if($this->success)
+ unset($data['error']);
+
if(!$this->success)
$data['error'] = $this->error;
| 0 |
b1f8be5addc22bd7541db29a3ac44d25e6bb7f65
|
1up-lab/OneupUploaderBundle
|
Moved Controller to the request Scope.
|
commit b1f8be5addc22bd7541db29a3ac44d25e6bb7f65
Author: Jim Schmid <[email protected]>
Date: Tue Mar 12 17:36:05 2013 +0100
Moved Controller to the request Scope.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index f5e0b84..3a5a4e9 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -9,37 +9,37 @@ class UploaderController implements UploadControllerInterface
protected $namer;
protected $storage;
- public function __construct($namer, $storage)
+ public function __construct($request, $namer, $storage, $config)
{
+ $this->request = $request;
$this->namer = $namer;
$this->storage = $storage;
+ $this->config = $config;
}
public function upload()
{
- /*
- $container = $this->container;
- $config = $this->mappings[$mapping];
- $request = $container->get('request');
- $files = $request->files;
+ $totalParts = $this->request->get('qqtotalparts', 1);
- if(!$container->has($config['storage']))
- throw new \InvalidArgumentException(sprintf('The storage service "%s" must be defined.'));
-
- if(!$container->has($config['namer']))
- throw new \InvalidArgumentException(sprintf('The namer service "%s" must be defined.'));
-
- $storage = $container->get($config['storage']);
- $namer = $container->get($config['namer']);
+ return $totalParts > 1 ? $this->handleChunkedUpload() : $this->handleUpload();
+ }
+
+ protected function handleUpload()
+ {
+ // get filebag from request
+ $files = $this->request->files;
- var_dump($request);
+ var_dump(get_class($this->storage)); die();
- die();
foreach($files as $file)
{
- var_dump($namer->name($file, $config));
}
- */
+
die();
}
+
+ protected function handleChunkedUpload()
+ {
+
+ }
}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index f5ece9d..171d66e 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -35,6 +35,7 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->scalarNode('storage')->isRequired()->end()
+ ->scalarNode('directory_prefix')->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->scalarNode('action')->defaultNull()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 8f8011b..7dc1244 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -37,6 +37,11 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach($config['mappings'] as $key => $mapping)
{
+ if(!array_key_exists($mapping['directory_prefix']))
+ {
+ $mapping['directory_prefix'] = $key;
+ }
+
$this->registerServicesPerMap($container, $key, $mapping);
}
}
@@ -47,13 +52,19 @@ class OneupUploaderExtension extends Extension
$container
->register(sprintf('oneup_uploader.controller.%s', $type), $container->getParameter('oneup_uploader.controller.class'))
+ ->addArgument(new Reference('request'))
+
// add the correct namer as argument
->addArgument(new Reference($mapping['namer']))
// add the correspoding storage service as argument
->addArgument(new Reference($mapping['storage']))
+ // after all, add the config as argument
+ ->addArgument($mapping)
+
->addTag('oneup_uploader.routable', array('type' => $type))
+ ->setScope('request')
;
}
}
\ No newline at end of file
| 0 |
dccc51343fc61b69112e5451ad857e5331db91be
|
1up-lab/OneupUploaderBundle
|
Fixed test suite.
|
commit dccc51343fc61b69112e5451ad857e5331db91be
Author: Jim Schmid <[email protected]>
Date: Wed Apr 10 01:01:08 2013 +0200
Fixed test suite.
diff --git a/Tests/Controller/AbstractControllerChunkedTest.php b/Tests/Controller/AbstractControllerChunkedTest.php
new file mode 100644
index 0000000..771282f
--- /dev/null
+++ b/Tests/Controller/AbstractControllerChunkedTest.php
@@ -0,0 +1,147 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
+use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
+
+abstract class AbstractControllerChunkedTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tempChunks;
+ protected $currentChunk;
+ protected $chunkUuid;
+ protected $numberOfChunks;
+
+ abstract public function getControllerString();
+ abstract protected function getRequestMock();
+
+ public function setUp()
+ {
+ $this->numberOfChunks = 10;
+
+ // create 10 chunks
+ for($i = 0; $i < $this->numberOfChunks; $i++)
+ {
+ // create temporary file
+ $chunk = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($chunk, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ $this->tempChunks[] = $chunk;
+ }
+
+ $this->currentChunk = 0;
+ $this->chunkUuid = uniqid();
+ }
+
+ public function testUpload()
+ {
+ $container = $this->getContainerMock();
+ $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
+ $config = array(
+ 'use_orphanage' => false,
+ 'namer' => 'namer',
+ 'max_size' => 2048,
+ 'allowed_extensions' => array(),
+ 'disallowed_extensions' => array()
+ );
+
+ $responses = array();
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
+
+ // mock as much requests as there are parts to assemble
+ for($i = 0; $i < $this->numberOfChunks; $i ++)
+ {
+ $responses[] = $controller->upload();
+
+ // will be used internaly
+ $this->currentChunk++;
+ }
+
+ for($i = 0; $i < $this->numberOfChunks; $i ++)
+ {
+ // check if original file has been moved
+ $this->assertFalse(file_exists($this->tempChunks[$i]));
+
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $responses[$i]);
+ $this->assertEquals(200, $responses[$i]->getStatusCode());
+ }
+
+ // check if assembled file is here
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/uploader')->files();
+ $this->assertCount(1, $finder);
+
+ // and check if chunks are gone
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/chunks')->files();
+ $this->assertCount(0, $finder);
+ }
+
+ protected function getContainerMock()
+ {
+ $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'containerGetCb')))
+ ;
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'request')
+ return $this->getRequestMock();
+
+ if($inp == 'event_dispatcher')
+ return $this->getEventDispatcherMock();
+
+ if($inp == 'namer')
+ return new UniqidNamer();
+
+ if($inp == 'oneup_uploader.chunk_manager')
+ return $this->getChunkManager();
+ }
+
+ protected function getEventDispatcherMock()
+ {
+ $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $mock
+ ->expects($this->any())
+ ->method('dispatch')
+ ->will($this->returnValue(true))
+ ;
+
+ return $mock;
+ }
+
+ protected function getUploadedFile()
+ {
+ return new UploadedFile($this->tempChunks[$this->currentChunk], 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
+ }
+
+ protected function getChunkManager()
+ {
+ return new ChunkManager(array(
+ 'directory' => sys_get_temp_dir() . '/chunks'
+ ));
+ }
+
+ public function tearDown()
+ {
+ // remove all files in tmp folder
+ $filesystem = new Filesystem();
+ $filesystem->remove(sys_get_temp_dir() . '/uploader');
+ $filesystem->remove(sys_get_temp_dir() . '/chunks');
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
new file mode 100644
index 0000000..80176e9
--- /dev/null
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -0,0 +1,144 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
+
+abstract class AbstractControllerTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tempFile;
+
+ abstract public function getControllerString();
+ abstract protected function getRequestMock();
+
+ public function setUp()
+ {
+ // create temporary file
+ $this->tempFile = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($this->tempFile, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+ }
+
+ public function testUpload()
+ {
+ $container = $this->getContainerMock();
+ $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
+ $config = array(
+ 'use_orphanage' => false,
+ 'namer' => 'namer',
+ 'max_size' => 2048,
+ 'allowed_extensions' => array(),
+ 'disallowed_extensions' => array()
+ );
+
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
+ $response = $controller->upload();
+
+ // check if original file has been moved
+ $this->assertFalse(file_exists($this->tempFile));
+
+ // testing response
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
+ $this->assertEquals(200, $response->getStatusCode());
+
+ // check if file is present
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/uploader')->files();
+
+ $this->assertCount(1, $finder);
+ }
+
+ public function testUploadWhichFails()
+ {
+ $container = $this->getContainerMock();
+ $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
+ $config = array(
+ 'use_orphanage' => false,
+ 'namer' => 'namer',
+ 'max_size' => 1,
+ 'allowed_extensions' => array(),
+ 'disallowed_extensions' => array()
+ );
+
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
+ $response = $controller->upload();
+
+ $json = json_decode($response->getContent());
+
+ // testing response
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
+ $this->assertEquals(200, $response->getStatusCode());
+ }
+
+ protected function getContainerMock()
+ {
+ $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'containerGetCb')))
+ ;
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'request')
+ return $this->getRequestMock();
+
+ if($inp == 'event_dispatcher')
+ return $this->getEventDispatcherMock();
+
+ if($inp == 'namer')
+ return new UniqidNamer();
+
+ if($inp == 'translator')
+ return $this->getTranslatorMock();
+ }
+
+ protected function getEventDispatcherMock()
+ {
+ $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $mock
+ ->expects($this->any())
+ ->method('dispatch')
+ ->will($this->returnValue(true))
+ ;
+
+ return $mock;
+ }
+
+ protected function getTranslatorMock()
+ {
+ $mock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
+ $mock
+ ->expects($this->any())
+ ->method('trans')
+ ->will($this->returnValue('A translated error.'))
+ ;
+
+ return $mock;
+ }
+
+ protected function getUploadedFile()
+ {
+ return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
+ }
+
+ public function tearDown()
+ {
+ // remove all files in tmp folder
+ $filesystem = new Filesystem();
+ $filesystem->remove(sys_get_temp_dir() . '/uploader');
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/AbstractControllerValidationTest.php b/Tests/Controller/AbstractControllerValidationTest.php
new file mode 100644
index 0000000..b066e3b
--- /dev/null
+++ b/Tests/Controller/AbstractControllerValidationTest.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+abstract class AbstractControllerValidationTest extends \PHPUnit_Framework_TestCase
+{
+ abstract public function getControllerString();
+
+ /**
+ * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
+ */
+ public function testMaxSizeValidationFails()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 10;
+ $config['allowed_extensions'] = array();
+ $config['disallowed_extensions'] = array();
+
+ $this->performConfigTest($config);
+ }
+
+ public function testMaxSizeValidationPasses()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 20;
+ $config['allowed_extensions'] = array();
+ $config['disallowed_extensions'] = array();
+
+ $this->performConfigTest($config);
+ }
+
+ /**
+ * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
+ */
+ public function testAllowedExtensionValidationFails()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 20;
+ $config['allowed_extensions'] = array('txt', 'pdf');
+ $config['disallowed_extensions'] = array();
+
+ $this->performConfigTest($config);
+ }
+
+ public function testAllowedExtensionValidationPasses()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 20;
+ $config['allowed_extensions'] = array('png', 'jpg', 'jpeg', 'gif');
+ $config['disallowed_extensions'] = array();
+
+ $this->performConfigTest($config);
+ }
+
+ /**
+ * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
+ */
+ public function testDisallowedExtensionValidationFails()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 20;
+ $config['allowed_extensions'] = array();
+ $config['disallowed_extensions'] = array('jpeg');
+
+ $this->performConfigTest($config);
+ }
+
+ public function testDisallowedExtensionValidationPasses()
+ {
+ // create a config
+ $config = array();
+ $config['max_size'] = 20;
+ $config['allowed_extensions'] = array();
+ $config['disallowed_extensions'] = array('exe', 'bat');
+
+ $this->performConfigTest($config);
+ }
+
+ protected function performConfigTest($config)
+ {
+ // prepare mock
+ $file = $this->getUploadedFileMock();
+ $method = $this->getValidationMethod();
+
+ $container = $this->getContainerMock();
+ $storage = $this->getStorageMock();
+
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
+ $method->invoke($controller, $file);
+
+ // yey, no exception thrown
+ $this->assertTrue(true);
+ }
+
+ protected function getUploadedFileMock()
+ {
+ $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+
+ $file
+ ->expects($this->any())
+ ->method('getClientSize')
+ ->will($this->returnValue(15))
+ ;
+
+ $file
+ ->expects($this->any())
+ ->method('getClientOriginalName')
+ ->will($this->returnValue('grumpycat.jpeg'))
+ ;
+
+ return $file;
+ }
+
+ protected function getContainerMock()
+ {
+ return $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ }
+
+ protected function getStorageMock()
+ {
+ return $this->getMock('Oneup\UploaderBundle\Uploader\Storage\StorageInterface');
+ }
+
+ protected function getValidationMethod()
+ {
+ // create a public version of the validate method
+ $class = new \ReflectionClass($this->getControllerString());
+ $method = $class->getMethod('validate');
+ $method->setAccessible(true);
+
+ return $method;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/BlueimpControllerChunkedTest.php b/Tests/Controller/BlueimpControllerChunkedTest.php
new file mode 100644
index 0000000..9b95ca5
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerChunkedTest.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
+
+class BlueimpControllerChunkedTest extends AbstractControllerChunkedTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+
+ $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
+ $headers
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'headersGetCb')))
+ ;
+
+ $mock->headers = $headers;
+
+ $mock->files = array(
+ array($this->getUploadedFile())
+ );
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'session')
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Session\Session');
+ $mock
+ ->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue('fixed-id'))
+ ;
+
+ return $mock;
+ }
+
+ return parent::containerGetCb($inp);
+ }
+
+ public function headersGetCb($inp)
+ {
+ if($inp == 'content-disposition')
+ return 'grumpy-cat.jpeg';
+
+ if($inp == 'content-range')
+ {
+ if($this->currentChunk == ($this->numberOfChunks - 1))
+ {
+ return sprintf('- 9218, 10240/10241');
+ }
+ else
+ {
+ $size = 1024;
+ $ret = sprintf('- %d, %d/%d', $this->currentChunk * $size, $this->currentChunk * $size + $size, 10240);
+
+ return $ret;
+ }
+ }
+ }
+}
diff --git a/Tests/Controller/BlueimpControllerTest.php b/Tests/Controller/BlueimpControllerTest.php
new file mode 100644
index 0000000..19ffefa
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class BlueimpControllerTest extends AbstractControllerTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
+ $headers
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnValue(null))
+ ;
+
+ $mock->headers = $headers;
+
+ $mock->files = array(
+ array($this->getUploadedFile())
+ );
+
+ return $mock;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/BlueimpControllerValidationTest.php b/Tests/Controller/BlueimpControllerValidationTest.php
new file mode 100644
index 0000000..40a32eb
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerValidationTest.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerValidationTest;
+
+class BlueimpControllerValidationTest extends AbstractControllerValidationTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerChunkedTest.php b/Tests/Controller/FineUploaderControllerChunkedTest.php
index f82f41b..9d9adb1 100644
--- a/Tests/Controller/FineUploaderControllerChunkedTest.php
+++ b/Tests/Controller/FineUploaderControllerChunkedTest.php
@@ -2,126 +2,15 @@
namespace Oneup\UploaderBundle\Tests\Controller;
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
-use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
-use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
-use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-use Oneup\UploaderBundle\Controller\FineUploaderController;
-
-class FineUploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase
+class FineUploaderControllerChunkedTest extends AbstractControllerChunkedTest
{
- protected $tempChunks;
- protected $currentChunk;
- protected $chunkUuid;
- protected $numberOfChunks;
-
- public function setUp()
+ public function getControllerString()
{
- $this->numberOfChunks = 10;
-
- // create 10 chunks
- for($i = 0; $i < $this->numberOfChunks; $i++)
- {
- // create temporary file
- $chunk = tempnam(sys_get_temp_dir(), 'uploader');
-
- $pointer = fopen($chunk, 'w+');
- fwrite($pointer, str_repeat('A', 1024), 1024);
- fclose($pointer);
-
- $this->tempChunks[] = $chunk;
- }
-
- $this->currentChunk = 0;
- $this->chunkUuid = uniqid();
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
}
-
- public function testUpload()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 2048,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
- $responses = array();
- $controller = new FineUploaderController($container, $storage, $config, 'cat');
-
- // mock as much requests as there are parts to assemble
- for($i = 0; $i < $this->numberOfChunks; $i ++)
- {
- $responses[] = $controller->upload();
-
- // will be used internaly
- $this->currentChunk++;
- }
-
- for($i = 0; $i < $this->numberOfChunks; $i ++)
- {
- // check if original file has been moved
- $this->assertFalse(file_exists($this->tempChunks[$i]));
-
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $responses[$i]);
- $this->assertEquals(200, $responses[$i]->getStatusCode());
- }
-
- // check if assembled file is here
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/uploader')->files();
- $this->assertCount(1, $finder);
-
- // and check if chunks are gone
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/chunks')->files();
- $this->assertCount(0, $finder);
- }
-
- protected function getContainerMock()
- {
- $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'containerGetCb')))
- ;
-
- return $mock;
- }
-
- public function containerGetCb($inp)
- {
- if($inp == 'request')
- return $this->getRequestMock();
-
- if($inp == 'event_dispatcher')
- return $this->getEventDispatcherMock();
-
- if($inp == 'namer')
- return new UniqidNamer();
-
- if($inp == 'oneup_uploader.chunk_manager')
- return $this->getChunkManager();
- }
-
- protected function getEventDispatcherMock()
- {
- $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $mock
- ->expects($this->any())
- ->method('dispatch')
- ->will($this->returnValue(true))
- ;
-
- return $mock;
- }
-
protected function getRequestMock()
{
$mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -152,24 +41,4 @@ class FineUploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase
if($inp == 'qqfilename')
return 'grumpy-cat.jpeg';
}
-
- protected function getUploadedFile()
- {
- return new UploadedFile($this->tempChunks[$this->currentChunk], 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
- }
-
- protected function getChunkManager()
- {
- return new ChunkManager(array(
- 'directory' => sys_get_temp_dir() . '/chunks'
- ));
- }
-
- public function tearDown()
- {
- // remove all files in tmp folder
- $filesystem = new Filesystem();
- $filesystem->remove(sys_get_temp_dir() . '/uploader');
- $filesystem->remove(sys_get_temp_dir() . '/chunks');
- }
}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerTest.php b/Tests/Controller/FineUploaderControllerTest.php
index 84f0db4..5fafc14 100644
--- a/Tests/Controller/FineUploaderControllerTest.php
+++ b/Tests/Controller/FineUploaderControllerTest.php
@@ -2,119 +2,15 @@
namespace Oneup\UploaderBundle\Tests\Controller;
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
-use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
-use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-use Oneup\UploaderBundle\Controller\FineUploaderController;
-
-class FineUploaderControllerTest extends \PHPUnit_Framework_TestCase
+class FineUploaderControllerTest extends AbstractControllerTest
{
- protected $tempFile;
-
- public function setUp()
- {
- // create temporary file
- $this->tempFile = tempnam(sys_get_temp_dir(), 'uploader');
-
- $pointer = fopen($this->tempFile, 'w+');
- fwrite($pointer, str_repeat('A', 1024), 1024);
- fclose($pointer);
- }
-
- public function testUpload()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 2048,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
-
- $controller = new FineUploaderController($container, $storage, $config, 'cat');
- $response = $controller->upload();
-
- // check if original file has been moved
- $this->assertFalse(file_exists($this->tempFile));
-
- // testing response
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
- $this->assertEquals(200, $response->getStatusCode());
-
- // check if file is present
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/uploader')->files();
-
- $this->assertCount(1, $finder);
- }
-
- public function testUploadWhichFails()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 1,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
-
- $controller = new FineUploaderController($container, $storage, $config, 'cat');
- $response = $controller->upload();
-
- $json = json_decode($response->getContent());
-
- // testing response
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
- $this->assertEquals(200, $response->getStatusCode());
- $this->assertFalse($json->success);
- }
-
- protected function getContainerMock()
- {
- $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'containerGetCb')))
- ;
-
- return $mock;
- }
-
- public function containerGetCb($inp)
- {
- if($inp == 'request')
- return $this->getRequestMock();
-
- if($inp == 'event_dispatcher')
- return $this->getEventDispatcherMock();
-
- if($inp == 'namer')
- return new UniqidNamer();
-
- if($inp == 'translator')
- return $this->getTranslatorMock();
- }
-
- protected function getEventDispatcherMock()
+ public function getControllerString()
{
- $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $mock
- ->expects($this->any())
- ->method('dispatch')
- ->will($this->returnValue(true))
- ;
-
- return $mock;
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
}
-
+
protected function getRequestMock()
{
$mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
@@ -131,28 +27,4 @@ class FineUploaderControllerTest extends \PHPUnit_Framework_TestCase
return $mock;
}
-
- protected function getTranslatorMock()
- {
- $mock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
- $mock
- ->expects($this->any())
- ->method('trans')
- ->will($this->returnValue('A translated error.'))
- ;
-
- return $mock;
- }
-
- protected function getUploadedFile()
- {
- return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
- }
-
- public function tearDown()
- {
- // remove all files in tmp folder
- $filesystem = new Filesystem();
- $filesystem->remove(sys_get_temp_dir() . '/uploader');
- }
}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerValidationTest.php b/Tests/Controller/FineUploaderControllerValidationTest.php
index f38e951..3c1f2c9 100644
--- a/Tests/Controller/FineUploaderControllerValidationTest.php
+++ b/Tests/Controller/FineUploaderControllerValidationTest.php
@@ -2,140 +2,12 @@
namespace Oneup\UploaderBundle\Tests\Controller;
-use Oneup\UploaderBundle\Controller\FineUploaderController;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerValidationTest;
-class FineUploaderControllerValidationTest extends \PHPUnit_Framework_TestCase
+class FineUploaderControllerValidationTest extends AbstractControllerValidationTest
{
- /**
- * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
- */
- public function testMaxSizeValidationFails()
+ public function getControllerString()
{
- // create a config
- $config = array();
- $config['max_size'] = 10;
- $config['allowed_extensions'] = array();
- $config['disallowed_extensions'] = array();
-
- $this->performConfigTest($config);
- }
-
- public function testMaxSizeValidationPasses()
- {
- // create a config
- $config = array();
- $config['max_size'] = 20;
- $config['allowed_extensions'] = array();
- $config['disallowed_extensions'] = array();
-
- $this->performConfigTest($config);
- }
-
- /**
- * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
- */
- public function testAllowedExtensionValidationFails()
- {
- // create a config
- $config = array();
- $config['max_size'] = 20;
- $config['allowed_extensions'] = array('txt', 'pdf');
- $config['disallowed_extensions'] = array();
-
- $this->performConfigTest($config);
- }
-
- public function testAllowedExtensionValidationPasses()
- {
- // create a config
- $config = array();
- $config['max_size'] = 20;
- $config['allowed_extensions'] = array('png', 'jpg', 'jpeg', 'gif');
- $config['disallowed_extensions'] = array();
-
- $this->performConfigTest($config);
- }
-
- /**
- * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
- */
- public function testDisallowedExtensionValidationFails()
- {
- // create a config
- $config = array();
- $config['max_size'] = 20;
- $config['allowed_extensions'] = array();
- $config['disallowed_extensions'] = array('jpeg');
-
- $this->performConfigTest($config);
- }
-
- public function testDisallowedExtensionValidationPasses()
- {
- // create a config
- $config = array();
- $config['max_size'] = 20;
- $config['allowed_extensions'] = array();
- $config['disallowed_extensions'] = array('exe', 'bat');
-
- $this->performConfigTest($config);
- }
-
- protected function performConfigTest($config)
- {
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new FineUploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
-
- // yey, no exception thrown
- $this->assertTrue(true);
- }
-
- protected function getUploadedFileMock()
- {
- $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
- ->disableOriginalConstructor()
- ->getMock()
- ;
-
- $file
- ->expects($this->any())
- ->method('getClientSize')
- ->will($this->returnValue(15))
- ;
-
- $file
- ->expects($this->any())
- ->method('getClientOriginalName')
- ->will($this->returnValue('grumpycat.jpeg'))
- ;
-
- return $file;
- }
-
- protected function getContainerMock()
- {
- return $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- }
-
- protected function getStorageMock()
- {
- return $this->getMock('Oneup\UploaderBundle\Uploader\Storage\StorageInterface');
- }
-
- protected function getValidationMethod()
- {
- // create a public version of the validate method
- $class = new \ReflectionClass('Oneup\\UploaderBundle\\Controller\\FineUploaderController');
- $method = $class->getMethod('validate');
- $method->setAccessible(true);
-
- return $method;
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
}
}
\ No newline at end of file
diff --git a/Tests/Uploader/Response/EmptyResponseTest.php b/Tests/Uploader/Response/EmptyResponseTest.php
new file mode 100644
index 0000000..82b4f63
--- /dev/null
+++ b/Tests/Uploader/Response/EmptyResponseTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class TestEmptyResponse extends \PHPUnit_Framework_TestCase
+{
+ public function testEmpty()
+ {
+ $response = new EmptyResponse();
+ $assembled = $response->assemble();
+
+ $this->assertTrue(is_array($assembled));
+ $this->assertCount(0, $assembled);
+ }
+
+ public function testWithItems()
+ {
+ $response = new EmptyResponse();
+
+ // fill in some data
+ $response['cat'] = 'grumpy';
+ $response['dog'] = 'has no idea';
+
+ $assembled = $response->assemble();
+
+ $this->assertTrue(is_array($assembled));
+ $this->assertCount(2, $assembled);
+ }
+}
\ No newline at end of file
| 0 |
d2d4d765fff945b454487b4eceec5e8d6e239c9a
|
1up-lab/OneupUploaderBundle
|
Added a test to check wheter the Validation event is triggered during upload.
|
commit d2d4d765fff945b454487b4eceec5e8d6e239c9a
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 22:00:16 2013 +0200
Added a test to check wheter the Validation event is triggered during upload.
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index 5b5861e..73d66f9 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -2,6 +2,9 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\UploadEvents;
+
abstract class AbstractValidationTest extends AbstractControllerTest
{
abstract protected function getFileWithCorrectExtension();
@@ -29,6 +32,24 @@ abstract class AbstractValidationTest extends AbstractControllerTest
}
}
+ public function testEvents()
+ {
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+ $dispatcher = $client->getContainer()->get('event_dispatcher');
+
+ // event data
+ $validationCount = 0;
+
+ $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) {
+ ++ $validationCount;
+ });
+
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
+
+ $this->assertEquals(1, $validationCount);
+ }
+
public function testAgainstIncorrectExtension()
{
// assemble a request
| 0 |
0cad0804ebe1ee5377450aaaa747751de46314ca
|
1up-lab/OneupUploaderBundle
|
Update PR to master
|
commit 0cad0804ebe1ee5377450aaaa747751de46314ca
Author: David Greminger <[email protected]>
Date: Mon Jun 20 09:54:16 2016 +0200
Update PR to master
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 276ddf3..75d64b4 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -90,6 +90,7 @@ class Configuration implements ConfigurationInterface
->booleanNode('enable_progress')->defaultFalse()->end()
->booleanNode('enable_cancelation')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
+ ->booleanNode('root_folder')->defaultFalse()->end()
->end()
->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 4a471c5..5ffbe09 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -200,8 +200,11 @@ class OneupUploaderExtension extends Extension
switch ($config['type']) {
case 'filesystem':
+ // root_folder is true, remove the mapping name folder from path
+ $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key;
+
$config['directory'] = is_null($config['directory']) ?
- sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
+ sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) :
$this->normalizePath($config['directory'])
;
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index 6b0d248..a7cee8a 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -38,6 +38,7 @@ oneup_uploader:
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
+ root_folder: false
# Set max_size to -1 for gracefully downgrade this number to the systems max upload size.
max_size: 9223372036854775807
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index 256d2c6..257451d 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -50,3 +50,57 @@ oneup_uploader:
```
Every file uploaded through the `Controller` of this mapping will be named with your custom namer.
+
+## Change the directory structure
+
+With the `NameInterface` you can change the directory structure to provide a better files organization or to use your own existing structure. For example, you need to separate the uploaded files by users with a `user_id` folder.
+
+You need to inject the `security.token_storage` service to your namer.
+
+```xml
+<services>
+ <service id="acme_demo.custom_namer" class="Acme\DemoBundle\CatNamer">
+ <argument type="service" id="security.token_storage"/>
+ </service>
+</services>
+```
+
+Now you can use the service to get the logged user id and return the custom directory like below:
+
+```php
+<?php
+
+namespace Acme\DemoBundle;
+
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+
+class CatNamer implements NamerInterface
+{
+ private $tokenStorage;
+
+ public function __construct(TokenStorage $tokenStorage){
+ $this->tokenStorage = $tokenStorage;
+ }
+
+ /**
+ * Creates a user directory name for the file being uploaded.
+ *
+ * @param FileInterface $file
+ * @return string The directory name.
+ */
+ public function name(FileInterface $file)
+ {
+ $userId = $tokenStorage->getToken()->getUser()->getId();
+
+ return sprintf('%s/%s.%s',
+ $userId,
+ uniqid(),
+ $file->getExtension()
+ );
+ }
+}
+```
+
+Every file uploaded through the `Controller` of this mapping will be named with your new directory structure.
\ No newline at end of file
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 5fd3425..0c18f92 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -78,9 +78,19 @@ oneup_uploader:
type: uploader
```
-The default directory that is used to upload files to is `web/uploads/{mapping_name}`.
+The default directory that is used to upload files to is `web/uploads/{mapping_name}`. In case you want to avoid a separated mapping folder, you can set `root_folder: true` and the default directory will be `web/uploads`.
+
+```yaml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ root_folder: true
+```
> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you.
+> You can improve the directory structure checking the "[Change the directory structure](custom_namer.md#change-the-directory-structure)".
### Step 4: Prepare your frontend
| 0 |
efaa424cd58b6b2b391b93316e7e69fb264e309e
|
1up-lab/OneupUploaderBundle
|
Merge pull request #3 from sheeep/release-1.0
Documentation / Test / Little Improvement
|
commit efaa424cd58b6b2b391b93316e7e69fb264e309e (from 01e33479db3496aee484fdae9823d4bbddeac930)
Merge: 01e3347 988082e
Author: mitom <[email protected]>
Date: Mon Oct 14 11:48:55 2013 -0700
Merge pull request #3 from sheeep/release-1.0
Documentation / Test / Little Improvement
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index b25c844..c017bdc 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -229,6 +229,8 @@ class OneupUploaderExtension extends Extension
if(strlen($filesystem) <= 0)
throw new ServiceNotFoundException('Empty service name');
+ $streamWrapper = $this->normalizeStreamWrapper($streamWrapper);
+
$this->container
->register($key, $class)
->addArgument(new Reference($filesystem))
@@ -266,4 +268,13 @@ class OneupUploaderExtension extends Extension
{
return rtrim($input, '/');
}
+
+ protected function normalizeStreamWrapper($input)
+ {
+ if (is_null($input)) {
+ return null;
+ }
+
+ return rtrim($input, '/') . '/';
+ }
}
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index 7eefd95..fd6d87a 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -37,10 +37,13 @@ oneup_uploader:
You can choose a custom directory to save the chunks temporarily while uploading by changing the parameter `directory`.
-Since version 1.0 you can also use a Gaufrette filesystem as the chunk storage. To do this you must first
-set up [Gaufrette](gaufrette_storage.md). There are however some additional things to keep in mind.
+## Use Gaufrette to store chunk files
+
+You can also use a Gaufrette filesystem as the chunk storage. A possible use case is to use chunked uploads behind non-session sticky load balancers.
+To do this you must first set up [Gaufrette](gaufrette_storage.md). There are however some additional things to keep in mind.
The configuration for the Gaufrette chunk storage should look as the following:
-```
+
+```yaml
oneup_uploader:
chunks:
maxage: 86400
@@ -51,27 +54,29 @@ oneup_uploader:
stream_wrapper: 'gaufrette://gallery/'
```
-> Setting the `stream_wrapper` is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings)
+> :exclamation: Setting the `stream_wrapper` is heavily recommended for better performance, see the reasons in the [gaufrette configuration](gaufrette_storage.md#configure-your-mappings)
-As you can see there are is a new option, `prefix`. It represents the directory
+As you can see there are is an option, `prefix`. It represents the directory
*relative* to the filesystem's directory which the chunks are stored in.
Gaufrette won't allow it to be outside of the filesystem.
-
-> You can only use stream capable filesystems for the chunk storage, at the time of this writing
-only the Local filesystem is capable of streaming directly.
-
This will give you a better structured directory,
as the chunk's folders and the uploaded files won't mix with each other.
-> You can set it to an empty string (`''`), if you don't need it. Otherwise it defaults to `chunks`.
+You can set it to an empty string (`''`), if you don't need it. Otherwise it defaults to `chunks`.
+
+> :exclamation: You can only use stream capable filesystems for the chunk storage, at the time of this writing
+only the Local filesystem is capable of streaming directly.
The chunks will be read directly from the temporary directory and appended to the already existing part on the given filesystem,
-resulting in only 1 read and 1 write operation.
+resulting in only one single read and one single write operation.
+
+> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem for the mapping. This is not possible to check during container setup and will throw unexpected errors at runtime!
You can achieve the biggest improvement if you use the same filesystem as your storage. If you do so, the assembled
file only has to be moved out of the chunk directory, which takes no time on a local filesystem.
> The load distribution is forcefully turned on, if you use Gaufrette as the chunk storage.
+See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section in the documentation for a full configuration example.
## Clean up
diff --git a/Resources/doc/load_balancers.md b/Resources/doc/load_balancers.md
index 0667b94..c178600 100644
--- a/Resources/doc/load_balancers.md
+++ b/Resources/doc/load_balancers.md
@@ -3,4 +3,39 @@ Use Chunked Uploads behind Load Balancers
If you want to use Chunked Uploads behind load balancers that is not configured to use sticky sessions you'll eventually end up with a bunch of chunks on every instance and the bundle is not able to reassemble the file on the server.
-You can avoid this problem by using Gaufrette as an abstract filesystem.
\ No newline at end of file
+You can avoid this problem by using Gaufrette as an abstract filesystem. Check the following configuration as an example.
+
+```yaml
+knp_gaufrette:
+ adapters:
+ gallery:
+ local:
+ directory: %kernel.root_dir%/../web/uploads
+ create: true
+
+ filesystems:
+ gallery:
+ adapter: gallery
+
+ stream_wrapper: ~
+
+oneup_uploader:
+ chunks:
+ storage:
+ type: gaufrette
+ filesystem: gaufrette.gallery_filesystem
+ stream_wrapper: gaufrette://gallery/
+
+ mappings:
+ gallery:
+ frontend: fineuploader
+ storage:
+ type: gaufrette
+ filesystem: gaufrette.gallery_filesystem
+```
+
+> :exclamation: Event though it is possible to use two different Gaufrette filesystems - one for the the chunk storage - and one for the mapping, it is not recommended.
+
+> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem one for the mapping. This is not possible to check during configuration and will throw unexpected errors!
+
+Using Gaufrette filesystems for chunked upload directories has some limitations. It is highly recommended to use a `Local` Gaufrette adapter as it is the only one that is able to `rename` a file but `move` it. Especially when working with bigger files this can have serious perfomance advantages as this way the file doesn't have to be moved entirely to memory!
\ No newline at end of file
diff --git a/Tests/DependencyInjection/OneupUploaderExtensionTest.php b/Tests/DependencyInjection/OneupUploaderExtensionTest.php
index 1b09fbf..85ac094 100644
--- a/Tests/DependencyInjection/OneupUploaderExtensionTest.php
+++ b/Tests/DependencyInjection/OneupUploaderExtensionTest.php
@@ -28,6 +28,28 @@ class OneupUploaderExtensionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(2147483648, $method->invoke($mock, '2G'));
}
+ public function testNormalizationOfStreamWrapper()
+ {
+ $mock = $this->getMockBuilder('Oneup\UploaderBundle\DependencyInjection\OneupUploaderExtension')
+ ->disableOriginalConstructor()
+ ->getMock()
+ ;
+
+ $method = new \ReflectionMethod(
+ 'Oneup\UploaderBundle\DependencyInjection\OneupUploaderExtension',
+ 'normalizeStreamWrapper'
+ );
+ $method->setAccessible(true);
+
+ $output1 = $method->invoke($mock, 'gaufrette://gallery');
+ $output2 = $method->invoke($mock, 'gaufrette://gallery/');
+ $output3 = $method->invoke($mock, null);
+
+ $this->assertEquals('gaufrette://gallery/', $output1);
+ $this->assertEquals('gaufrette://gallery/', $output2);
+ $this->assertNull($output3);
+ }
+
public function testGetMaxUploadSize()
{
$mock = $this->getMockBuilder('Oneup\UploaderBundle\DependencyInjection\OneupUploaderExtension')
diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
index bc3a671..418298c 100644
--- a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -28,6 +28,10 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
$this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
$this->payloads = array();
+ if (!$this->checkIfTempnameMatchesAfterCreation()) {
+ $this->markTestSkipped('Temporary directories do not match');
+ }
+
$filesystem = new \Symfony\Component\Filesystem\Filesystem();
$filesystem->mkdir($this->realDirectory);
$filesystem->mkdir($this->chunkDirectory);
@@ -107,4 +111,8 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
$this->assertCount($this->numberOfPayloads, $finder);
}
+ public function checkIfTempnameMatchesAfterCreation()
+ {
+ return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ }
}
commit efaa424cd58b6b2b391b93316e7e69fb264e309e (from 988082eb6eda9f1f69182ed478a04f333c5766f5)
Merge: 01e3347 988082e
Author: mitom <[email protected]>
Date: Mon Oct 14 11:48:55 2013 -0700
Merge pull request #3 from sheeep/release-1.0
Documentation / Test / Little Improvement
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index e9e05a8..2e803bb 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -53,11 +53,16 @@ abstract class AbstractChunkedController extends AbstractController
$chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
- $this->dispatchChunkEvents($chunk, $response, $request, $last);
+ if ($chunk) {
+ $this->dispatchChunkEvents($chunk, $response, $request, $last);
+ }
if ($chunkManager->getLoadDistribution()) {
$chunks = $chunkManager->getChunks($uuid);
$assembled = $chunkManager->assembleChunks($chunks, true, $last);
+ if (!$chunk) {
+ $this->dispatchChunkEvents($assembled, $response, $request, $last);
+ }
}
// if all chunks collected and stored, proceed
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index f1ae5bd..7b9bc7e 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -5,6 +5,7 @@ namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
use Gaufrette\Filesystem;
+use Symfony\Component\Filesystem\Filesystem as LocalFilesystem;
use Gaufrette\Adapter\MetadataSupporter;
use Oneup\UploaderBundle\Uploader\Gaufrette\StreamManager;
@@ -39,9 +40,15 @@ class GaufretteStorage extends StreamManager implements StorageInterface
$dst = $this->filesystem->createStream($path);
$this->openStream($dst, 'w');
-
$this->stream($file, $dst);
+ if ($file instanceof GaufretteFile) {
+ $file->delete();
+ } else {
+ $filesystem = new LocalFilesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
| 0 |
2fa822b7b9c097d26317ffc163fd9d0d584ca6a1
|
1up-lab/OneupUploaderBundle
|
Fix tests
|
commit 2fa822b7b9c097d26317ffc163fd9d0d584ca6a1
Author: David Greminger <[email protected]>
Date: Tue Feb 4 14:03:24 2020 +0100
Fix tests
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index e72f144..81772b6 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -27,6 +27,8 @@ abstract class AbstractControllerTest extends WebTestCase
public function setUp()
{
$this->client = static::createClient();
+ $this->client->catchExceptions(false);
+
self::$container = $this->client->getContainer();
$this->helper = self::$container->get('oneup_uploader.templating.uploader_helper');
$this->createdFiles = [];
diff --git a/composer.json b/composer.json
index 9405e60..c0c4941 100644
--- a/composer.json
+++ b/composer.json
@@ -34,10 +34,11 @@
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
"oneup/flysystem-bundle": "^1.2|^2.0|^3.0",
- "phpunit/phpunit": "^6.5",
+ "phpunit/phpunit": "^7.5",
"sensio/framework-extra-bundle": "^5.0",
"symfony/browser-kit": "^3.0|^4.0",
"symfony/class-loader": "^3.0|^4.0",
+ "symfony/phpunit-bridge": "^5.0",
"symfony/security-bundle": "^3.0|^4.0",
"symfony/var-dumper": "^3.0|^4.0",
"twistor/flysystem-stream-wrapper": "^1.0"
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6f2e1c0..2e0c235 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -5,6 +5,10 @@
<server name="KERNEL_DIR" value="Tests/App" />
<server name="KERNEL_CLASS" value="AppKernel" />
</php>
+
+ <listeners>
+ <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
+ </listeners>
<testsuites>
<testsuite name="OneupUploaderBundle test suite">
| 0 |
2a7fda616e23e50d1fc35385a36d2199b5acf925
|
1up-lab/OneupUploaderBundle
|
Added Validation test for YUI3 Uploader.
|
commit 2a7fda616e23e50d1fc35385a36d2199b5acf925
Author: Jim Schmid <[email protected]>
Date: Sat May 18 16:50:53 2013 +0200
Added Validation test for YUI3 Uploader.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index a286251..1e0ae87 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -38,6 +38,15 @@ oneup_uploader:
frontend: yui3
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
+ yui3_validation:
+ frontend: yui3
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+ allowed_extensions: [ "ok" ]
+ disallowed_extensions: [ "fail" ]
+ allowed_mimetypes: [ "image/jpg", "text/plain" ]
+ disallowed_mimetypes: [ "image/gif" ]
plupload:
frontend: plupload
diff --git a/Tests/Controller/UploadifyValidationTest.php b/Tests/Controller/UploadifyValidationTest.php
index 5b29e39..7d22c95 100644
--- a/Tests/Controller/UploadifyValidationTest.php
+++ b/Tests/Controller/UploadifyValidationTest.php
@@ -7,7 +7,6 @@ use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
class UploadifyValidationTest extends AbstractValidationTest
{
-
protected function getConfigKey()
{
return 'uploadify_validation';
diff --git a/Tests/Controller/YUI3ValidationTest.php b/Tests/Controller/YUI3ValidationTest.php
new file mode 100644
index 0000000..c3781cb
--- /dev/null
+++ b/Tests/Controller/YUI3ValidationTest.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest;
+
+class YUI3ValidationTest extends AbstractValidationTest
+{
+ protected function getConfigKey()
+ {
+ return 'yui3_validation';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getFileWithCorrectExtension()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'text/plain',
+ 128
+ );
+ }
+
+ protected function getFileWithIncorrectExtension()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.fail',
+ 'text/plain',
+ 128
+ );
+ }
+
+ protected function getFileWithCorrectMimeType()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'image/jpg',
+ 128
+ );
+ }
+
+ protected function getFileWithIncorrectMimeType()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.ok',
+ 'image/gif',
+ 128
+ );
+ }
+}
| 0 |
712bff50293aabc60d2c9f34c02abc5dcb977e29
|
1up-lab/OneupUploaderBundle
|
Registered a new EventListener on POST_UPLOAD. This one is for the session storage after upload.
|
commit 712bff50293aabc60d2c9f34c02abc5dcb977e29
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 10:11:27 2013 +0100
Registered a new EventListener on POST_UPLOAD. This one is for the session storage after upload.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 6d29961..0d18043 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -4,7 +4,8 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
-use Oneup\UploaderBundle\StoreEvents;
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
@@ -38,9 +39,9 @@ class UploaderController implements UploadControllerInterface
$name = $this->namer->name($file, $this->config['directory_prefix']);
$uploaded = $this->storage->upload($file, $name);
- // dispatch POST_UPLOAD event
- $event = new PostUploadEvent($uploaded, $request);
- $this->dispatcher->dispatch(StoreEvents::POST_UPLOAD, $event);
+ // dispatch post upload event
+ $event = new PostUploadEvent($uploaded, $this->request);
+ $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $event);
}
return new JsonResponse(array('success' => true));
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 8d26404..5f8cd6d 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -94,7 +94,7 @@ class OneupUploaderExtension extends Extension
->addArgument($mapping)
// we need the EventDispatcher for post upload events
- ->addArgument(new Reference('event.dispatcher'))
+ ->addArgument(new Reference('event_dispatcher'))
->addTag('oneup_uploader.routable', array('type' => $type))
->setScope('request')
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index a24af56..132e71e 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -2,7 +2,6 @@
namespace Oneup\UploaderBundle\Event;
-use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
diff --git a/EventListener/SessionStoreListener.php b/EventListener/SessionStoreListener.php
new file mode 100644
index 0000000..a8f25c5
--- /dev/null
+++ b/EventListener/SessionStoreListener.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\UploadEvents;
+
+class SessionStoreListener implements EventSubscriberInterface
+{
+ public function __construct(SessionInterface $session)
+ {
+ $this->session = $session;
+ }
+
+ public function addToSession(PostUploadEvent $event)
+ {
+ $request = $event->getRequest();
+ $file = $event->getFile();
+ }
+
+ public static function getSubscribedEvents()
+ {
+ return array(
+ UploadEvents::POST_UPLOAD => 'addToSession',
+ );
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index b0e8de6..d22de7e 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -10,6 +10,7 @@
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
<parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.listener.session.class">Oneup\UploaderBundle\EventListener\SessionStoreListener</parameter>
</parameters>
<services>
@@ -29,6 +30,13 @@
<tag name="routing.loader" />
</service>
+ <!-- events -->
+ <service id="oneup_uploader.listener.session" class="%oneup_uploader.listener.session.class%">
+ <argument type="service" id="session" />
+
+ <tag name="kernel.event_subscriber" />
+ </service>
+
</services>
</container>
\ No newline at end of file
| 0 |
8e21e8100a4dba50a1f2175e822d9e77e73cb918
|
1up-lab/OneupUploaderBundle
|
Added Upgrade Note about version 1.0.
|
commit 8e21e8100a4dba50a1f2175e822d9e77e73cb918
Author: Jim Schmid <[email protected]>
Date: Wed Oct 23 15:27:21 2013 +0200
Added Upgrade Note about version 1.0.
diff --git a/README.md b/README.md
index a8b708b..0abe5c1 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
+* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
* If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320).
* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads).
| 0 |
c71ac47cdd4ab545444c4735e0f6c41dd5d2f977
|
1up-lab/OneupUploaderBundle
|
Merge branch 'tompiard-dropzone-chunk'
|
commit c71ac47cdd4ab545444c4735e0f6c41dd5d2f977 (from e1e139af3c63d0a19f6f8b06591987fb4ca0d6bb)
Merge: e1e139a 69d0819
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:19:47 2017 +0100
Merge branch 'tompiard-dropzone-chunk'
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index b4fdc99..feab508 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -2,11 +2,12 @@
namespace Oneup\UploaderBundle\Controller;
-use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-class DropzoneController extends AbstractController
+class DropzoneController extends AbstractChunkedController
{
public function upload()
{
@@ -14,9 +15,15 @@ class DropzoneController extends AbstractController
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
$statusCode = 200;
+
+ $chunked = !is_null($request->request->get('dzchunkindex'));
+
foreach ($files as $file) {
try {
- $this->handleUpload($file, $response, $request);
+ $chunked ?
+ $this->handleChunkedUpload($file, $response, $request) :
+ $this->handleUpload($file, $response, $request)
+ ;
} catch (UploadException $e) {
$statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x
$this->errorHandler->addException($response, $e);
@@ -24,10 +31,26 @@ class DropzoneController extends AbstractController
$message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle');
$response = $this->createSupportedJsonResponse(array('error'=>$message ));
$response->setStatusCode(400);
- return $response;
+ return $response;
}
}
return $this->createSupportedJsonResponse($response->assemble(), $statusCode);
}
+
+ protected function parseChunkedRequest(Request $request)
+ {
+ $totalChunkCount = $request->get('dztotalchunkcount');
+ $index = $request->get('dzchunkindex');
+ $last = ($index + 1) === (int) $totalChunkCount;
+ $uuid = $request->get('dzuuid');
+
+ /**
+ * @var UploadedFile $file
+ */
+ $file = $request->files->get('file')->getClientOriginalName();
+ $orig = $file;
+
+ return [$last, $uuid, $index, $orig];
+ }
}
| 0 |
54a1ea0d8754bf6fe3532528aadd729b4352dca9
|
1up-lab/OneupUploaderBundle
|
Changed function names for upload progress helpers.
|
commit 54a1ea0d8754bf6fe3532528aadd729b4352dca9
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 11:16:37 2013 +0200
Changed function names for upload progress helpers.
diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php
index a61efa5..f4a3490 100644
--- a/Templating/Helper/UploaderHelper.php
+++ b/Templating/Helper/UploaderHelper.php
@@ -24,12 +24,12 @@ class UploaderHelper extends Helper
return $this->router->generate(sprintf('_uploader_upload_%s', $key));
}
- public function progressRoute($key)
+ public function progress($key)
{
return $this->router->generate(sprintf('_uploader_progress_%s', $key));
}
- public function progressKey()
+ public function uploadKey()
{
return ini_get('session.upload_progress.name');
}
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index 4b23e2f..e33b9b4 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -22,8 +22,8 @@ class UploaderExtension extends \Twig_Extension
{
return array(
'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'),
- 'oneup_uploader_progress_route' => new \Twig_Function_Method($this, 'progressRoute'),
- 'oneup_uploader_progress_key' => new \Twig_Function_Method($this, 'progressKey')
+ 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'),
+ 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey')
);
}
@@ -32,13 +32,13 @@ class UploaderExtension extends \Twig_Extension
return $this->helper->endpoint($key);
}
- public function progressRoute($key)
+ public function progress($key)
{
- return $this->helper->progressRoute($key);
+ return $this->helper->progress($key);
}
- public function progressKey()
+ public function uploadKey()
{
- return $this->helper->progressKey();
+ return $this->helper->uploadKey();
}
}
| 0 |
625ff285d43eeaf3ccac45dc4fae1bf7587b17f9
|
1up-lab/OneupUploaderBundle
|
Added missing methods to ChunkManager.
|
commit 625ff285d43eeaf3ccac45dc4fae1bf7587b17f9
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 17:17:34 2013 +0100
Added missing methods to ChunkManager.
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 3e58f00..6d4b489 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -58,7 +58,7 @@ class ChunkManager implements ChunkManagerInterface
$chunk->move($path, $name);
}
- public function assembleChunks($chunks)
+ public function assembleChunks(array $chunks)
{
// I don't really get it why getIterator()->current() always
// gives me a null-value, due to that I've to implement this
diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php
index 12574c9..4d0068d 100644
--- a/Uploader/Chunk/ChunkManagerInterface.php
+++ b/Uploader/Chunk/ChunkManagerInterface.php
@@ -2,8 +2,14 @@
namespace Oneup\UploaderBundle\Uploader\Chunk;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
interface ChunkManagerInterface
{
public function warmup();
public function clear();
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original);
+ public function assembleChunks(array $chunks);
+ public function cleanup($path);
+ public function getChunks($uuid);
}
\ No newline at end of file
| 0 |
c1e9a148b7b159e76f4b59a3437c0006babd90db
|
1up-lab/OneupUploaderBundle
|
Fixed ErrorHandlerInterface implementation documentation (issue #68)
|
commit c1e9a148b7b159e76f4b59a3437c0006babd90db
Author: USvER <[email protected]>
Date: Wed Nov 6 19:04:52 2013 +0200
Fixed ErrorHandlerInterface implementation documentation (issue #68)
diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md
index b6cd21c..4110836 100644
--- a/Resources/doc/custom_error_handler.md
+++ b/Resources/doc/custom_error_handler.md
@@ -10,13 +10,13 @@ To create your own error handler, implement the `ErrorHandlerInterface` and add
namespace Acme\DemoBundle\ErrorHandler;
-use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
-use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
class CustomErrorHandler implements ErrorHandlerInterface
{
- public function addException(ResponseInterface $response, UploadException $exception)
+ public function addException(AbstractResponse $response, Exception $exception)
{
$message = $exception->getMessage();
$response['error'] = $message;
| 0 |
209b593525545ca8e792529a49aa92809f362391
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit 209b593525545ca8e792529a49aa92809f362391 (from 5e82365a40d187de263c9588693ecf853aa3f32c)
Merge: 5e82365 dad8de6
Author: Jim Schmid <[email protected]>
Date: Wed Dec 4 11:16:19 2013 +0100
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/README.md b/README.md
index 0abe5c1..7ddeab2 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ Features included:
* Fully unit tested
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
-[](http://depending.in/1up-lab/OneupUploaderBundle)
+[](http://depending.in/1up-lab/OneupUploaderBundle)
[](https://packagist.org/packages/oneup/uploader-bundle)
Documentation
commit 209b593525545ca8e792529a49aa92809f362391 (from dad8de6070dd9d4fb54e00da12aa23d2e38c613b)
Merge: 5e82365 dad8de6
Author: Jim Schmid <[email protected]>
Date: Wed Dec 4 11:16:19 2013 +0100
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/.travis.yml b/.travis.yml
index fc9e984..3381bd6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,6 +7,7 @@ php:
env:
- SYMFONY_VERSION=2.2.*
- SYMFONY_VERSION=2.3.*
+ - SYMFONY_VERSION=2.4.*
before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
| 0 |
93e68ffa9858d8a451938a66c594bde0e30147a6
|
1up-lab/OneupUploaderBundle
|
Included a feature list and some standard stuff to Readme
|
commit 93e68ffa9858d8a451938a66c594bde0e30147a6
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 11:14:32 2013 +0300
Included a feature list and some standard stuff to Readme
diff --git a/README.md b/README.md
index 0961964..9e0e312 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,31 @@
OneupUploaderBundle
===================
+The OneupUploaderBundle adds support for handling file uploads using the popular
+Javascript library [Fine Uploader](http://fineuploader.com/).
-[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
\ No newline at end of file
+Features included:
+
+* Multiple file uploads handled by Fine Uploader
+* Chunked uploads
+* Supports [Gaufrette](https://github.com/KnpLabs/Gaufrette) and/or local filesystem
+* Provides an orphanage for cleaning up orphaned files
+* Fully unit tested
+
+[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
+
+License
+-------
+
+This bundle is under the MIT license. See the complete license in the bundle:
+
+ Resources/meta/LICENSE
+
+Reporting an issue or a feature request
+---------------------------------------
+
+Issues and feature requests are tracked in the [Github issue tracker](https://github.com/Spea/SpBowerBundle/issues).
+
+When reporting a bug, it may be a good idea to reproduce it in a basic project
+built using the [Symfony Standard Edition](https://github.com/symfony/symfony-standard)
+to allow developers of the bundle to reproduce the issue by simply cloning it
+and following some steps.
| 0 |
65d73e73037256d59ffe56ad6cb86ca499db7c8f
|
1up-lab/OneupUploaderBundle
|
Fixes test suite by adding missing deps and psr-0 settings in composer and adding a bootstrap files for the tests.
|
commit 65d73e73037256d59ffe56ad6cb86ca499db7c8f
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 12:30:10 2013 +0100
Fixes test suite by adding missing deps and psr-0 settings in composer and adding a bootstrap files for the tests.
diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php
new file mode 100644
index 0000000..1f4f67c
--- /dev/null
+++ b/Tests/bootstrap.php
@@ -0,0 +1,8 @@
+<?php
+
+$file = __DIR__.'/../vendor/autoload.php';
+if (!file_exists($file)) {
+ throw new RuntimeException('Install dependencies to run test suite.');
+}
+
+$autoload = require_once $file;
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 2728f5d..51ece7f 100644
--- a/composer.json
+++ b/composer.json
@@ -28,6 +28,14 @@
},
"require": {
- "valums/file-uploader": "3.3.*"
- }
+ "symfony/finder": ">=2.0.16,<2.3-dev",
+ "symfony/filesystem": ">=2.0.16,<2.3-dev",
+ "valums/file-uploader": "3.3.*"
+ },
+
+ "autoload": {
+ "psr-0": { "Oneup\\UploaderBundle": "" }
+ },
+
+ "target-dir": "Oneup/UploaderBundle"
}
\ No newline at end of file
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index b34158b..f3c7e3e 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<phpunit colors="true">
+<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="OneupUploaderBundle test suite">
@@ -14,6 +14,7 @@
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
+ <directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
| 0 |
beb16992f788f9fecfd1e6be214f0a51e3a420ea
|
1up-lab/OneupUploaderBundle
|
Test the filesystem storage.
|
commit beb16992f788f9fecfd1e6be214f0a51e3a420ea
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 20:36:52 2013 +0200
Test the filesystem storage.
diff --git a/Tests/Uploader/Storage/FilesystemStorageTest.php b/Tests/Uploader/Storage/FilesystemStorageTest.php
new file mode 100644
index 0000000..7560a79
--- /dev/null
+++ b/Tests/Uploader/Storage/FilesystemStorageTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
+
+class FilesystemStorageTest extends \PHPUnit_Framework_TestCase
+{
+ protected $directory;
+ protected $file;
+
+ public function setUp()
+ {
+ $this->directory = sys_get_temp_dir() . '/storage';
+
+ // create temporary file
+ $this->file = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($this->file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+ }
+
+ public function testUpload()
+ {
+ $payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true);
+ $storage = new FilesystemStorage($this->directory);
+ $storage->upload($payload, 'notsogrumpyanymore.jpeg');
+
+ $finder = new Finder();
+ $finder->in($this->directory)->files();
+
+ $this->assertCount(1, $finder);
+
+ foreach($finder as $file)
+ {
+ $this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg');
+ $this->assertEquals($file->getSize(), 1024);
+ }
+ }
+
+ public function tearDown()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->directory);
+ }
+}
\ No newline at end of file
| 0 |
9ea61f30b4b634ef5bc27e44bb69954524915bd9
|
1up-lab/OneupUploaderBundle
|
Fix issue #340 for Symfony < 4.1
|
commit 9ea61f30b4b634ef5bc27e44bb69954524915bd9
Author: David Greminger <[email protected]>
Date: Wed Jul 18 12:25:15 2018 +0200
Fix issue #340 for Symfony < 4.1
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index dda6d65..c242fc2 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
+use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@@ -23,6 +24,12 @@ class RouteLoader extends Loader
public function load($resource, $type = null)
{
$routes = new RouteCollection();
+ $separator = ':';
+
+ // Double colon separators are used in Symfony >= 4.1 (see #340)
+ if (version_compare(Kernel::VERSION, '4.1', '>=')) {
+ $separator .= ':';
+ }
foreach ($this->controllers as $type => $controllerArray) {
$service = $controllerArray[0];
@@ -30,7 +37,7 @@ class RouteLoader extends Loader
$upload = new Route(
$options['endpoints']['upload'] ?: sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type),
- ['_controller' => $service.'::upload', '_format' => 'json'],
+ ['_controller' => $service.$separator.'upload', '_format' => 'json'],
[],
[],
'',
@@ -41,7 +48,7 @@ class RouteLoader extends Loader
if (true === $options['enable_progress']) {
$progress = new Route(
$options['endpoints']['progress'] ?: sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type),
- ['_controller' => $service.'::progress', '_format' => 'json'],
+ ['_controller' => $service.$separator.'progress', '_format' => 'json'],
[],
[],
'',
@@ -55,7 +62,7 @@ class RouteLoader extends Loader
if (true === $options['enable_cancelation']) {
$progress = new Route(
$options['endpoints']['cancel'] ?: sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type),
- ['_controller' => $service.'::cancel', '_format' => 'json'],
+ ['_controller' => $service.$separator.'cancel', '_format' => 'json'],
[],
[],
'',
| 0 |
48b19bc18fb944fe8b05a70173bff94074b8f83b
|
1up-lab/OneupUploaderBundle
|
Removed extension validators.
|
commit 48b19bc18fb944fe8b05a70173bff94074b8f83b
Author: Jim Schmid <[email protected]>
Date: Fri Oct 11 18:15:47 2013 +0200
Removed extension validators.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 97b1eef..3ebfbec 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -59,12 +59,6 @@ class Configuration implements ConfigurationInterface
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->end()
->end()
- ->arrayNode('allowed_extensions')
- ->prototype('scalar')->end()
- ->end()
- ->arrayNode('disallowed_extensions')
- ->prototype('scalar')->end()
- ->end()
->arrayNode('allowed_mimetypes')
->prototype('scalar')->end()
->end()
diff --git a/EventListener/AllowedExtensionValidationListener.php b/EventListener/AllowedExtensionValidationListener.php
deleted file mode 100644
index 68c26e8..0000000
--- a/EventListener/AllowedExtensionValidationListener.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\EventListener;
-
-use Oneup\UploaderBundle\Event\ValidationEvent;
-use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
-
-class AllowedExtensionValidationListener
-{
- public function onValidate(ValidationEvent $event)
- {
- $config = $event->getConfig();
- $file = $event->getFile();
-
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
-
- if (count($config['allowed_extensions']) > 0 && !in_array($extension, $config['allowed_extensions'])) {
- throw new ValidationException('error.whitelist');
- }
- }
-}
diff --git a/EventListener/DisallowedExtensionValidationListener.php b/EventListener/DisallowedExtensionValidationListener.php
deleted file mode 100644
index 9cdac58..0000000
--- a/EventListener/DisallowedExtensionValidationListener.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\EventListener;
-
-use Oneup\UploaderBundle\Event\ValidationEvent;
-use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
-
-class DisallowedExtensionValidationListener
-{
- public function onValidate(ValidationEvent $event)
- {
- $config = $event->getConfig();
- $file = $event->getFile();
-
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
-
- if (count($config['disallowed_extensions']) > 0 && in_array($extension, $config['disallowed_extensions'])) {
- throw new ValidationException('error.blacklist');
- }
- }
-}
diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml
index 5b2ffe0..4c3fc73 100644
--- a/Resources/config/validators.xml
+++ b/Resources/config/validators.xml
@@ -8,14 +8,6 @@
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
- <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener">
- <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
- </service>
-
- <service id="oneup_uploader.validation_listener.disallowed_extension" class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener">
- <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
- </service>
-
<service id="oneup_uploader.validation_listener.allowed_mimetype" class="Oneup\UploaderBundle\EventListener\AllowedMimetypeValidationListener">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index b75fee4..07c420b 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -27,8 +27,6 @@ oneup_uploader:
filesystem: ~
directory: ~
sync_buffer_size: 100K
- allowed_extensions: []
- disallowed_extensions: []
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 619cebc..a350ddb 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -23,8 +23,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -38,8 +37,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -53,8 +51,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -68,8 +65,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -83,8 +79,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -98,8 +93,7 @@ oneup_uploader:
max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
@@ -115,8 +109,7 @@ oneup_uploader:
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
error_handler: oneup_uploader.error_handler.blueimp
- allowed_extensions: [ "ok" ]
- disallowed_extensions: [ "fail" ]
+
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index 01b0a6d..8b56bfb 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -7,8 +7,6 @@ use Oneup\UploaderBundle\UploadEvents;
abstract class AbstractValidationTest extends AbstractControllerTest
{
- abstract protected function getFileWithCorrectExtension();
- abstract protected function getFileWithIncorrectExtension();
abstract protected function getFileWithCorrectMimeType();
abstract protected function getFileWithIncorrectMimeType();
abstract protected function getOversizedFile();
@@ -27,26 +25,6 @@ abstract class AbstractValidationTest extends AbstractControllerTest
$this->assertCount(0, $this->getUploadedFiles());
}
- public function testAgainstCorrectExtension()
- {
- // assemble a request
- $client = $this->client;
- $endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
- $response = $client->getResponse();
-
- $this->assertTrue($response->isSuccessful());
- $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
- $this->assertCount(1, $this->getUploadedFiles());
-
- foreach ($this->getUploadedFiles() as $file) {
- $this->assertTrue($file->isFile());
- $this->assertTrue($file->isReadable());
- $this->assertEquals(128, $file->getSize());
- }
- }
-
public function testEvents()
{
$client = $this->client;
@@ -60,7 +38,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest
++ $validationCount;
});
- $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectMimeType()));
$this->assertEquals(1, $validationCount);
}
@@ -82,25 +60,11 @@ abstract class AbstractValidationTest extends AbstractControllerTest
++ $validationCount;
});
- $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectMimeType()));
$this->assertEquals(1, $validationCount);
}
- public function testAgainstIncorrectExtension()
- {
- // assemble a request
- $client = $this->client;
- $endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithIncorrectExtension()));
- $response = $client->getResponse();
-
- //$this->assertTrue($response->isNotSuccessful());
- $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
- $this->assertCount(0, $this->getUploadedFiles());
- }
-
public function testAgainstCorrectMimeType()
{
// assemble a request
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 4bbfa1c..c5b8af6 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -23,26 +23,6 @@ class BlueimpValidationTest extends AbstractValidationTest
$this->assertCount(0, $this->getUploadedFiles());
}
- public function testAgainstCorrectExtension()
- {
- // assemble a request
- $client = $this->client;
- $endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension(), array('HTTP_ACCEPT' => 'application/json'));
- $response = $client->getResponse();
-
- $this->assertTrue($response->isSuccessful());
- $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
- $this->assertCount(1, $this->getUploadedFiles());
-
- foreach ($this->getUploadedFiles() as $file) {
- $this->assertTrue($file->isFile());
- $this->assertTrue($file->isReadable());
- $this->assertEquals(128, $file->getSize());
- }
- }
-
public function testEvents()
{
$client = $this->client;
@@ -56,25 +36,11 @@ class BlueimpValidationTest extends AbstractValidationTest
++ $validationCount;
});
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension());
+ $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType());
$this->assertEquals(1, $validationCount);
}
- public function testAgainstIncorrectExtension()
- {
- // assemble a request
- $client = $this->client;
- $endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectExtension(), array('HTTP_ACCEPT' => 'application/json'));
- $response = $client->getResponse();
-
- //$this->assertTrue($response->isNotSuccessful());
- $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
- $this->assertCount(0, $this->getUploadedFiles());
- }
-
public function testAgainstCorrectMimeType()
{
// assemble a request
@@ -131,26 +97,6 @@ class BlueimpValidationTest extends AbstractValidationTest
)));
}
- protected function getFileWithCorrectExtension()
- {
- return array('files' => array(new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- )));
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return array('files' => array(new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- )));
- }
-
protected function getFileWithCorrectMimeType()
{
return array('files' => array(new UploadedFile(
diff --git a/Tests/Controller/DropzoneValidationTest.php b/Tests/Controller/DropzoneValidationTest.php
index 73cb5ff..abe7f06 100644
--- a/Tests/Controller/DropzoneValidationTest.php
+++ b/Tests/Controller/DropzoneValidationTest.php
@@ -27,26 +27,6 @@ class DropzoneValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php
index 7e48964..1f78228 100644
--- a/Tests/Controller/FancyUploadValidationTest.php
+++ b/Tests/Controller/FancyUploadValidationTest.php
@@ -27,26 +27,6 @@ class FancyUploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/FineUploaderValidationTest.php b/Tests/Controller/FineUploaderValidationTest.php
index d1961e4..a3b1a7e 100644
--- a/Tests/Controller/FineUploaderValidationTest.php
+++ b/Tests/Controller/FineUploaderValidationTest.php
@@ -27,26 +27,6 @@ class FineUploaderValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/PluploadValidationTest.php b/Tests/Controller/PluploadValidationTest.php
index 61ffc55..c9e9be9 100644
--- a/Tests/Controller/PluploadValidationTest.php
+++ b/Tests/Controller/PluploadValidationTest.php
@@ -27,26 +27,6 @@ class PluploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/UploadifyValidationTest.php b/Tests/Controller/UploadifyValidationTest.php
index 0f10650..086267f 100644
--- a/Tests/Controller/UploadifyValidationTest.php
+++ b/Tests/Controller/UploadifyValidationTest.php
@@ -27,26 +27,6 @@ class UploadifyValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/YUI3ValidationTest.php b/Tests/Controller/YUI3ValidationTest.php
index ca4919c..2325c61 100644
--- a/Tests/Controller/YUI3ValidationTest.php
+++ b/Tests/Controller/YUI3ValidationTest.php
@@ -27,26 +27,6 @@ class YUI3ValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.ok',
- 'text/plain',
- 128
- );
- }
-
- protected function getFileWithIncorrectExtension()
- {
- return new UploadedFile(
- $this->createTempFile(128),
- 'cat.fail',
- 'text/plain',
- 128
- );
- }
-
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
| 0 |
e6b23d64bde9126393bec2a7f79d9ef25deca284
|
1up-lab/OneupUploaderBundle
|
Merge pull request #45 from cioddi/patch-1
fineuploader 3.7.1 wants a DOM object as element param
|
commit e6b23d64bde9126393bec2a7f79d9ef25deca284 (from 7fd33d564b32740712fdad082a02a282dcabf3f2)
Merge: 7fd33d5 8072203
Author: Jim Schmid <[email protected]>
Date: Wed Aug 14 03:14:32 2013 -0700
Merge pull request #45 from cioddi/patch-1
fineuploader 3.7.1 wants a DOM object as element param
diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md
index 91a0f77..b024857 100644
--- a/Resources/doc/frontend_fineuploader.md
+++ b/Resources/doc/frontend_fineuploader.md
@@ -10,7 +10,7 @@ Download [FineUploader](http://fineuploader.com/) and include it in your templat
$(document).ready(function()
{
var uploader = new qq.FineUploader({
- element: $('#uploader'),
+ element: $('#uploader')[0],
request: {
endpoint: "{{ oneup_uploader_endpoint('gallery') }}"
}
@@ -34,4 +34,4 @@ oneup_uploader:
> Actually, `fineuploader` is the default value, so you don't have to provide it manually.
-Be sure to check out the [official manual](https://github.com/Widen/fine-uploader/blob/master/readme.md) for details on the configuration.
\ No newline at end of file
+Be sure to check out the [official manual](https://github.com/Widen/fine-uploader/blob/master/readme.md) for details on the configuration.
| 0 |
f5ce6e41df95b28d827c51fc69de071349dd7d53
|
1up-lab/OneupUploaderBundle
|
Introducing an orphanage for uploads.
|
commit f5ce6e41df95b28d827c51fc69de071349dd7d53
Author: Jim Schmid <[email protected]>
Date: Tue Mar 12 11:17:03 2013 +0100
Introducing an orphanage for uploads.
diff --git a/Uploader/Orphanage/Orphanage.php b/Uploader/Orphanage/Orphanage.php
new file mode 100644
index 0000000..7239042
--- /dev/null
+++ b/Uploader/Orphanage/Orphanage.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Orphanage;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+
+use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface;
+
+class Orphanage implements OrphanageInterface
+{
+ public function __construct($configuration)
+ {
+ $this->configuration = $configuration;
+ }
+
+ public function warmup()
+ {
+ $fileSystem = new FileSystem();
+ $fileSystem->mkdir($this->configuration['directory']);
+ }
+
+ public function clear()
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ try
+ {
+ $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
+ }
+ catch(\InvalidArgumentException $e)
+ {
+ // the finder will throw an exception of type InvalidArgumentException
+ // if the directory he should search in does not exist
+ // in that case we don't have anything to clean
+ return;
+ }
+
+ foreach($finder as $file)
+ {
+ $system->remove($file);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Uploader/Orphanage/OrphanageInterface.php b/Uploader/Orphanage/OrphanageInterface.php
new file mode 100644
index 0000000..6d66c0f
--- /dev/null
+++ b/Uploader/Orphanage/OrphanageInterface.php
@@ -0,0 +1,9 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Orphanage;
+
+interface OrphanageInterface
+{
+ public function warmup();
+ public function clear();
+}
\ No newline at end of file
| 0 |
93a42fe2bca31e7c5feaa936d0df0cbfd7752ac9
|
1up-lab/OneupUploaderBundle
|
Merge pull request #17 from 1up-lab/comments
Comments
|
commit 93a42fe2bca31e7c5feaa936d0df0cbfd7752ac9 (from 164034b17415acda36711a47c334a03232dab9ec)
Merge: 164034b 3353b55
Author: Jim Schmid <[email protected]>
Date: Tue Jun 4 01:07:23 2013 -0700
Merge pull request #17 from 1up-lab/comments
Comments
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index f32cc56..de094cb 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -8,8 +8,33 @@ use Oneup\UploaderBundle\Controller\AbstractController;
abstract class AbstractChunkedController extends AbstractController
{
+ /**
+ * Parses a chunked request and return relevant information.
+ *
+ * This function must return an array containing the following
+ * keys and their corresponding values:
+ * - last: Wheter this is the last chunk of the uploaded file
+ * - uuid: A unique id which distinguishes two uploaded files
+ * This uuid must stay the same among the task of
+ * uploading a chunked file.
+ * - index: A numerical representation of the currently uploaded
+ * chunk. Must be higher that in the previous request.
+ * - orig: The original file name.
+ *
+ * @param request The request object
+ */
abstract protected function parseChunkedRequest(Request $request);
+ /**
+ * This function will be called in order to upload and save an
+ * uploaded chunk.
+ *
+ * This function also calls the chunk manager if the function
+ * parseChunkedRequest has set true for the "last" key of the
+ * returned array to reassemble the uploaded chunks.
+ *
+ * @param file The uploaded chunk.
+ */
protected function handleChunkedUpload(UploadedFile $file)
{
// get basic container stuff
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 06ba7d7..47e07a4 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -34,6 +34,16 @@ abstract class AbstractController
abstract public function upload();
+ /**
+ * This internal function handles the actual upload process
+ * and will most likely be called from the upload()
+ * function in the implemented Controller.
+ *
+ * Note: The return value differs when
+ *
+ * @param UploadedFile The file to upload
+ * @return File the actual file
+ */
protected function handleUpload(UploadedFile $file)
{
$this->validate($file);
@@ -48,6 +58,10 @@ abstract class AbstractController
return $uploaded;
}
+ /**
+ * This function is a helper function which dispatches post upload
+ * and post persist events.
+ */
protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 949663d..1b06878 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -21,24 +21,13 @@ class MooUploadController extends AbstractChunkedController
$translator = $this->container->get('translator');
$response = new MooUploadResponse();
- $files = $request->files;
$headers = $request->headers;
+ list($file, $uploadFileName) = $this->getUploadedFile($request);
+
// we have to get access to this object in another method
$this->response = $response;
- // create temporary file in systems temp dir
- $tempFile = tempnam(sys_get_temp_dir(), 'uploader');
- $contents = file_get_contents('php://input');
-
- // put data from php://input to temp file
- file_put_contents($tempFile, $contents);
-
- $uploadFileName = sprintf('%s_%s', $headers->get('x-file-id'), $headers->get('x-file-name'));
-
- // create an uploaded file to upload
- $file = new UploadedFile($tempFile, $uploadFileName, null, null, null, true);
-
// check if uploaded by chunks
$chunked = $headers->get('content-length') < $headers->get('x-file-size');
@@ -119,4 +108,23 @@ class MooUploadController extends AbstractChunkedController
return $ints;
}
+
+ protected function getUploadedFile(Request $request)
+ {
+ $headers = $request->headers;
+
+ // create temporary file in systems temp dir
+ $tempFile = tempnam(sys_get_temp_dir(), 'uploader');
+ $contents = file_get_contents('php://input');
+
+ // put data from php://input to temp file
+ file_put_contents($tempFile, $contents);
+
+ $uploadFileName = sprintf('%s_%s', $headers->get('x-file-id'), $headers->get('x-file-name'));
+
+ // create an uploaded file to upload
+ $file = new UploadedFile($tempFile, $uploadFileName, null, null, null, true);
+
+ return array($file, $uploadFileName);
+ }
}
\ No newline at end of file
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 2c577af..f17c2f8 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -106,4 +106,9 @@ oneup_uploader:
allowed_extensions: [ "ok" ]
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
- disallowed_mimetypes: [ "image/gif" ]
\ No newline at end of file
+ disallowed_mimetypes: [ "image/gif" ]
+
+ mooupload:
+ frontend: mooupload
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
\ No newline at end of file
diff --git a/Tests/Controller/MooUploadTest.php b/Tests/Controller/MooUploadTest.php
new file mode 100644
index 0000000..a1aaf7b
--- /dev/null
+++ b/Tests/Controller/MooUploadTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class MooUploadTest extends AbstractControllerTest
+{
+ protected function getConfigKey()
+ {
+ return 'mooupload';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getRequestFile()
+ {
+ return array(new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.txt',
+ 'text/plain',
+ 128
+ ));
+ }
+}
diff --git a/composer.json b/composer.json
index 5a86478..ac41496 100644
--- a/composer.json
+++ b/composer.json
@@ -14,7 +14,7 @@
"require": {
"symfony/framework-bundle": "2.*",
- "symfony/finder": ">=2.0.16,<2.3-dev"
+ "symfony/finder": ">=2.0.16,<2.4-dev"
},
"require-dev": {
commit 93a42fe2bca31e7c5feaa936d0df0cbfd7752ac9 (from 3353b55aafd45f8874f91646b74d48fc3b296e04)
Merge: 164034b 3353b55
Author: Jim Schmid <[email protected]>
Date: Tue Jun 4 01:07:23 2013 -0700
Merge pull request #17 from 1up-lab/comments
Comments
diff --git a/README.md b/README.md
index 1e702c7..d828af8 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ Features included:
* Fully unit tested
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
+[](http://depending.in/1up-lab/OneupUploaderBundle)
Documentation
-------------
| 0 |
b1973d8e3dac0f12b6e48ef71cd0843f0ff93fe5
|
1up-lab/OneupUploaderBundle
|
Added App directory to testing documentation.
|
commit b1973d8e3dac0f12b6e48ef71cd0843f0ff93fe5
Author: Jim Schmid <[email protected]>
Date: Mon Aug 12 13:24:26 2013 +0200
Added App directory to testing documentation.
diff --git a/Resources/doc/testing.md b/Resources/doc/testing.md
index 91a37a6..4fd96cb 100644
--- a/Resources/doc/testing.md
+++ b/Resources/doc/testing.md
@@ -34,6 +34,9 @@ Copy the `phpunit.xml.dist` to `phpunit.xml` and use this configuration.
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
+ <php>
+ <server name="KERNEL_DIR" value="Tests/App" />
+ </php>
<testsuites>
<testsuite name="OneupUploaderBundle test suite">
| 0 |
01e33479db3496aee484fdae9823d4bbddeac930
|
1up-lab/OneupUploaderBundle
|
avoid post-chunk upload events to fire with empty files
|
commit 01e33479db3496aee484fdae9823d4bbddeac930
Author: mitom <[email protected]>
Date: Mon Oct 14 12:28:36 2013 +0200
avoid post-chunk upload events to fire with empty files
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index e9e05a8..2e803bb 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -53,11 +53,16 @@ abstract class AbstractChunkedController extends AbstractController
$chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
- $this->dispatchChunkEvents($chunk, $response, $request, $last);
+ if ($chunk) {
+ $this->dispatchChunkEvents($chunk, $response, $request, $last);
+ }
if ($chunkManager->getLoadDistribution()) {
$chunks = $chunkManager->getChunks($uuid);
$assembled = $chunkManager->assembleChunks($chunks, true, $last);
+ if (!$chunk) {
+ $this->dispatchChunkEvents($assembled, $response, $request, $last);
+ }
}
// if all chunks collected and stored, proceed
| 0 |
6b6587eb5f3394950be6dded2a696aad7fc4508c
|
1up-lab/OneupUploaderBundle
|
getFiles will return an array of SplFileInfo instead of File.
Mentioned in - and fixes #90.
|
commit 6b6587eb5f3394950be6dded2a696aad7fc4508c
Author: Jim Schmid <[email protected]>
Date: Fri Jun 20 10:59:02 2014 +0200
getFiles will return an array of SplFileInfo instead of File.
Mentioned in - and fixes #90.
diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index b489535..6848615 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -53,7 +53,7 @@ class AcmeController extends Controller
You will get an array containing the moved files.
-> If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `Symfony\Component\HttpFoundation\File\File`.
+> If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `SplFileInfo`.
## Configure the Orphanage
You can configure the `Orphanage` by using the following configuration parameters.
| 0 |
b06cf28f671cdb33c3ffdddd3a0df9884d1a5449
|
1up-lab/OneupUploaderBundle
|
Fixed a bug where not the correct request value was taken to access the session.
|
commit b06cf28f671cdb33c3ffdddd3a0df9884d1a5449
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 11:06:10 2013 +0200
Fixed a bug where not the correct request value was taken to access the session.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 68fa7b4..4b8bf48 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -44,7 +44,7 @@ abstract class AbstractController
// assemble session key
// ref: http://php.net/manual/en/session.upload-progress.php
- $key = sprintf('%s.%s', $prefix, $name);
+ $key = sprintf('%s.%s', $prefix, $request->get($name));
$value = $session->get($key);
return new JsonResponse($value);
| 0 |
3b3460caefaf03e46cf8c6c17ddc46ed7474088f
|
1up-lab/OneupUploaderBundle
|
Added missing instance variables.
|
commit 3b3460caefaf03e46cf8c6c17ddc46ed7474088f
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 17:06:38 2013 +0100
Added missing instance variables.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index a7566f4..09f386a 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -14,8 +14,13 @@ use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
{
+ protected $request;
protected $namer;
protected $storage;
+ protected $config;
+ protected $dispatcher;
+ protected $type;
+ protected $chunkManager;
public function __construct($request, $namer, $storage, $dispatcher, $type, $config, $chunkManager)
{
| 0 |
c7d022d74a1de408dd8ad06d5083ac11a7a547df
|
1up-lab/OneupUploaderBundle
|
Removed unused variables on UploadifyController.
|
commit c7d022d74a1de408dd8ad06d5083ac11a7a547df
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 11:25:18 2013 +0200
Removed unused variables on UploadifyController.
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index 7c94966..ea18f52 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -13,9 +13,6 @@ class UploadifyController extends AbstractController
public function upload()
{
$request = $this->container->get('request');
- $dispatcher = $this->container->get('event_dispatcher');
- $translator = $this->container->get('translator');
-
$response = new EmptyResponse();
$files = $request->files;
| 0 |
cb7399c80b62123b43d30ff894dca5fea1611c7f
|
1up-lab/OneupUploaderBundle
|
Add documentation for using Flysystem
|
commit cb7399c80b62123b43d30ff894dca5fea1611c7f
Author: Shank <[email protected]>
Date: Mon Sep 5 13:19:53 2016 -0700
Add documentation for using Flysystem
diff --git a/Resources/doc/flysystem_storage.md b/Resources/doc/flysystem_storage.md
new file mode 100644
index 0000000..76aa1ea
--- /dev/null
+++ b/Resources/doc/flysystem_storage.md
@@ -0,0 +1,75 @@
+Use Flysystem as Storage layer
+==============================
+
+Flysystem is an abstract storage layer you can use to store your uploaded files. An explanation why you should use an abstraction storage layer comes from the _Why use Gaufrette_ section on [the Gaufrette Repo](https://github.com/KnpLabs/Gaufrette):
+
+> The filesystem abstraction layer permits you to develop your application without the need to know were all those medias will be stored and how.
+>
+> Another advantage of this is the possibility to update the files location without any impact on the code apart from the definition of your filesystem. In example, if your project grows up very fast and if your server reaches its limits, you can easily move your medias in an Amazon S3 server or any other solution.
+
+In order to use Flysystem with OneupUploaderBundle, be sure to follow these steps:
+
+## Install OneupFlysystemBundle
+
+Add the OneupFlysystemBundle to your composer.json file.
+
+```js
+{
+ "require": {
+ "oneup/flysystem-bundle": "1.4.*"
+ }
+}
+```
+
+And update your dependencies through composer.
+
+ $> php composer.phar update oneup/flysystem-bundle
+
+After installing, enable the bundle in your AppKernel:
+
+``` php
+<?php
+// app/AppKernel.php
+
+public function registerBundles()
+{
+ $bundles = array(
+ // ...
+ new Oneup\FlysystemBundle\OneupFlysystemBundle(),
+ );
+}
+```
+
+## Configure your Filesystems
+
+The following is a sample configuration for the OneupFlysystemBundle. It will create a flysystem service called `oneup_flysystem.gallery_filesystem` which can be used in the OneupUploaderBundle. For a complete list of features refer to the [official documentation](https://github.com/1up-lab/OneupFlysystemBundle).
+
+```yml
+# app/config/config.yml
+
+oneup_flysystem:
+ adapters:
+ acme.flysystem_adapter:
+ awss3v3:
+ client: acme.s3_client
+ bucket: ~
+ prefix: ~
+ filesystems:
+ gallery:
+ adapter: acme.flysystem_adapter
+```
+
+## Configure your mappings
+
+Activate Flysystem by switching the `type` property to `flysystem` and pass the Flysystem filesystem configured in the previous step.
+
+```yml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ type: flysystem
+ filesystem: oneup_flysystem.gallery_filesystem
+```
| 0 |
b6d5a570ab63fc78ae09314bc62a5bf4172144b6
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of https://github.com/ThomasLandauer/OneupUploaderBundle into ThomasLandauer-master
|
commit b6d5a570ab63fc78ae09314bc62a5bf4172144b6 (from 15f3614144d72b166d82a3e1586c2e66a357c0d1)
Merge: 15f3614 8af488c
Author: David Greminger <[email protected]>
Date: Fri Dec 23 15:04:38 2016 +0100
Merge branch 'master' of https://github.com/ThomasLandauer/OneupUploaderBundle into ThomasLandauer-master
diff --git a/README.md b/README.md
index 7f18c9a..1daa930 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,17 @@
OneupUploaderBundle
===================
-The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
+The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
-* [FineUploader](http://fineuploader.com/)
-* [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/)
-* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/)
-* [Uploadify](http://www.uploadify.com/)
-* [FancyUpload](http://digitarald.de/project/fancyupload/)
-* [MooUpload](https://github.com/juanparati/MooUpload)
-* [Plupload](http://www.plupload.com/)
* [Dropzone](http://www.dropzonejs.com/)
+* [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/)
+* [Plupload](http://www.plupload.com/)
+* [FineUploader](http://fineuploader.com/)
+* [FancyUpload](http://digitarald.de/project/fancyupload/) (based on MooTools)
+* [MooUpload](https://github.com/juanparati/MooUpload) (based on MooTools)
+* [YUI3 Uploader](http://yuilibrary.com/yui/docs/uploader/) (the YUI library is no longer maintained)
+* [UploadiFive](http://www.uploadify.com/) ($ 5.00)
+
Features included:
diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md
index b0fd9b1..875fb3d 100644
--- a/Resources/doc/frontend_dropzone.md
+++ b/Resources/doc/frontend_dropzone.md
@@ -4,9 +4,9 @@ Use Dropzone in your Symfony2 application
Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`.
```html
-<script type="text/javascript" src="https://raw.githubusercontent.com/enyo/dropzone/master/dist/dropzone.js"></script>
+<script type="text/javascript" src="https://raw.github.com/enyo/dropzone/master/dist/dropzone.js"></script>
-<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone">
+<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black">
</form>
```
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 1b07234..3942d44 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -65,7 +65,7 @@ This bundle was designed to just work out of the box. The only thing you have to
oneup_uploader:
mappings:
gallery:
- frontend: blueimp # or any uploader you use in the frontend
+ frontend: dropzone # or any uploader you use in the frontend
```
To enable the dynamic routes, add the following to your routing configuration file.
@@ -104,9 +104,17 @@ oneup_uploader:
directory: "%kernel.root_dir%/../data/uploads/"
```
-### Step 4: Prepare your frontend
+### Step 4: Check if the bundle is working correctly
-No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
+No matter which JavaScript library you are going to use ultimately, we recommend to test the bundle with Dropzone first, since this one features the easiest setup process:
+
+1. [Install Dropzone](frontend_dropzone.md)
+1. Drag a file onto the dashed rectangle. The upload should start immediately. However, you won't get any visual feedback yet.
+1. Check your `web/uploads/gallery` directory: If you see the file there, the OneupUploaderBundle is working correctly. If you don't have that folder, create it manually and try again.
+
+### Step 5: Prepare your real frontend
+
+Now it's up to you to decide for a JavaScript library or write your own. Be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
```php
$helper = $this->container->get('oneup_uploader.templating.uploader_helper');
@@ -119,14 +127,14 @@ or in a Twig template you can use the `oneup_uploader_endpoint` function:
So if you take the mapping described before, the generated route name would be `_uploader_gallery`. Follow one of the listed guides to include your frontend:
-* [Use FineUploader](frontend_fineuploader.md)
+* [Use Dropzone](frontend_dropzone.md)
* [Use jQuery File Upload](frontend_blueimp.md)
-* [Use YUI3 Uploader](frontend_yui3.md)
-* [Use Uploadify](frontend_uploadify.md)
+* [Use Plupload](frontend_plupload.md)
+* [Use FineUploader](frontend_fineuploader.md)
* [Use FancyUpload](frontend_fancyupload.md)
* [Use MooUpload](frontend_mooupload.md)
-* [Use Plupload](frontend_plupload.md)
-* [Use Dropzone](frontend_dropzone.md)
+* [Use YUI3 Uploader](frontend_yui3.md)
+* [Use Uploadify](frontend_uploadify.md)
## Next steps
commit b6d5a570ab63fc78ae09314bc62a5bf4172144b6 (from 8af488c0f35a8e08da2a409bfc9be595e915531b)
Merge: 15f3614 8af488c
Author: David Greminger <[email protected]>
Date: Fri Dec 23 15:04:38 2016 +0100
Merge branch 'master' of https://github.com/ThomasLandauer/OneupUploaderBundle into ThomasLandauer-master
diff --git a/.travis.yml b/.travis.yml
index 5a3affa..0e69924 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,28 +1,48 @@
language: php
php:
- - 5.3
- 5.4
- 5.5
- 5.6
+ - 7.0
+ - 7.1
- hhvm
env:
- - SYMFONY_VERSION=2.3.*
+ - SYMFONY_VERSION=2.4.*
+ - SYMFONY_VERSION=2.7.*
+ - SYMFONY_VERSION=2.8.*
+
+cache:
+ directories:
+ - $COMPOSER_CACHE_DIR
matrix:
allow_failures:
- - env: SYMFONY_VERSION=dev-master
- php: hhvm
+ - php: 7.0
+ - php: 7.1
+ - env: SYMFONY_VERSION=dev-master
+
include:
- - php: 5.5
+ - php: 5.6
env: SYMFONY_VERSION=2.4.*
- - php: 5.5
+ - php: 5.6
env: SYMFONY_VERSION=2.5.*
- - php: 5.5
+ - php: 5.6
+ env: SYMFONY_VERSION=2.6.*
+ - php: 5.6
+ env: SYMFONY_VERSION=2.7.*
+ - php: 5.6
+ env: SYMFONY_VERSION=2.8.*
+ - php: 5.6
+ env: SYMFONY_VERSION=3.0.*
+ - php: 5.6
env: SYMFONY_VERSION=dev-master
before_script:
- composer selfupdate
- - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
+ - composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source
- composer install --dev --prefer-source
+
+script: ./vendor/bin/phpunit
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 62f9df1..691a44f 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -7,7 +7,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
abstract class AbstractChunkedController extends AbstractController
@@ -45,7 +44,6 @@ abstract class AbstractChunkedController extends AbstractController
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
// get basic container stuff
- $request = $this->container->get('request');
$chunkManager = $this->container->get('oneup_uploader.chunk_manager');
// get information about this chunked request
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index a551ba8..75d3518 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -17,6 +17,7 @@ use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Symfony\Component\HttpKernel\Kernel;
abstract class AbstractController
{
@@ -38,7 +39,7 @@ abstract class AbstractController
public function progress()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
@@ -54,7 +55,7 @@ abstract class AbstractController
public function cancel()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
@@ -73,8 +74,8 @@ abstract class AbstractController
/**
* Flattens a given filebag to extract all files.
*
- * @param bag The filebag to use
- * @return array An array of files
+ * @param FileBag $bag The filebag to use
+ * @return array An array of files
*/
protected function getFiles(FileBag $bag)
{
@@ -100,9 +101,9 @@ abstract class AbstractController
*
* Note: The return value differs when
*
- * @param The file to upload
- * @param response A response object.
- * @param request The request object.
+ * @param mixed $file The file to upload
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function handleUpload($file, ResponseInterface $response, Request $request)
{
@@ -129,9 +130,9 @@ abstract class AbstractController
/**
* This function is a helper function which dispatches pre upload event
*
- * @param uploaded The uploaded file.
- * @param response A response object.
- * @param request The request object.
+ * @param FileInterface $uploaded The uploaded file.
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request)
{
@@ -147,9 +148,9 @@ abstract class AbstractController
* This function is a helper function which dispatches post upload
* and post persist events.
*
- * @param uploaded The uploaded file.
- * @param response A response object.
- * @param request The request object.
+ * @param mixed $uploaded The uploaded file.
+ * @param ResponseInterface $response A response object.
+ * @param Request $request The request object.
*/
protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request)
{
@@ -171,9 +172,10 @@ abstract class AbstractController
protected function validate(FileInterface $file)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->container->get('request'), $this->config, $this->type);
+ $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
+ $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
}
/**
@@ -183,13 +185,14 @@ abstract class AbstractController
* then the content type of the response will be set to text/plain instead.
*
* @param mixed $data
+ * @param int $statusCode
*
* @return JsonResponse
*/
- protected function createSupportedJsonResponse($data)
+ protected function createSupportedJsonResponse($data, $statusCode = 200)
{
- $request = $this->container->get('request');
- $response = new JsonResponse($data);
+ $request = $this->getRequest();
+ $response = new JsonResponse($data, $statusCode);
$response->headers->set('Vary', 'Accept');
if (!in_array('application/json', $request->getAcceptableContentTypes())) {
@@ -198,4 +201,20 @@ abstract class AbstractController
return $response;
}
+
+ /**
+ * Get the master request
+ *
+ * @return Request
+ */
+ protected function getRequest()
+ {
+
+ if (version_compare(Kernel::VERSION, '2.4', '<=')) {
+ return $this->container->get('request');
+ }
+
+ return $this->container->get('request_stack')->getMasterRequest();
+ }
+
}
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index f9186c7..f12329e 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class BlueimpController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
@@ -34,7 +33,7 @@ class BlueimpController extends AbstractChunkedController
public function progress()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$session = $this->container->get('session');
$prefix = ini_get('session.upload_progress.prefix');
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index 2121f32..b4fdc99 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -4,21 +4,21 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class DropzoneController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
-
+ $statusCode = 200;
foreach ($files as $file) {
try {
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
+ $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x
$this->errorHandler->addException($response, $e);
$translator = $this->container->get('translator');
$message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle');
@@ -28,6 +28,6 @@ class DropzoneController extends AbstractController
}
}
- return $this->createSupportedJsonResponse($response->assemble());
+ return $this->createSupportedJsonResponse($response->assemble(), $statusCode);
}
}
diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php
index bc21006..2aae793 100644
--- a/Controller/FancyUploadController.php
+++ b/Controller/FancyUploadController.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class FancyUploadController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 246b7f6..79cab8c 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
class FineUploaderController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$translator = $this->container->get('translator');
$response = new FineUploaderResponse();
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index e4f055b..95babd4 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -6,7 +6,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\MooUploadResponse;
class MooUploadController extends AbstractChunkedController
@@ -15,7 +14,7 @@ class MooUploadController extends AbstractChunkedController
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new MooUploadResponse();
$headers = $request->headers;
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index 56cb151..ee0ceb4 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -5,14 +5,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class PluploadController extends AbstractChunkedController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index ea68396..b93c725 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class UploadifyController extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index c79e72b..043cacc 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -4,14 +4,13 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Oneup\UploaderBundle\Controller\AbstractController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class YUI3Controller extends AbstractController
{
public function upload()
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new EmptyResponse();
$files = $this->getFiles($request->files);
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 3374889..75d64b4 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -22,7 +22,7 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->enumNode('type')
- ->values(array('filesystem', 'gaufrette'))
+ ->values(array('filesystem', 'gaufrette', 'flysystem'))
->defaultValue('filesystem')
->end()
->scalarNode('filesystem')->defaultNull()->end()
@@ -65,7 +65,7 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('service')->defaultNull()->end()
->enumNode('type')
- ->values(array('filesystem', 'gaufrette'))
+ ->values(array('filesystem', 'gaufrette', 'flysystem'))
->defaultValue('filesystem')
->end()
->scalarNode('filesystem')->defaultNull()->end()
@@ -90,6 +90,7 @@ class Configuration implements ConfigurationInterface
->booleanNode('enable_progress')->defaultFalse()->end()
->booleanNode('enable_cancelation')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
+ ->booleanNode('root_folder')->defaultFalse()->end()
->end()
->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index aec580d..0d472ff 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -13,6 +13,10 @@ use Symfony\Component\DependencyInjection\Loader;
class OneupUploaderExtension extends Extension
{
protected $storageServices = array();
+
+ /**
+ * @var ContainerBuilder
+ */
protected $container;
protected $config;
@@ -115,7 +119,6 @@ class OneupUploaderExtension extends Extension
->addArgument($key)
->addTag('oneup_uploader.routable', array('type' => $key))
- ->setScope('request')
;
return $controllerName;
@@ -142,31 +145,44 @@ class OneupUploaderExtension extends Extension
$config = &$this->config['chunks']['storage'];
$storageClass = sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']);
- if ($config['type'] === 'filesystem') {
- $config['directory'] = is_null($config['directory']) ?
- sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) :
- $this->normalizePath($config['directory'])
- ;
-
- $this->container
- ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']))
- ->addArgument($config['directory'])
- ;
- } else {
- $this->registerGaufretteStorage(
- 'oneup_uploader.chunks_storage',
- $storageClass, $config['filesystem'],
- $config['sync_buffer_size'],
- $config['stream_wrapper'],
- $config['prefix']
- );
-
- $this->container->setParameter('oneup_uploader.orphanage.class', 'Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage');
-
- // enforce load distribution when using gaufrette as chunk
- // torage to avoid moving files forth-and-back
- $this->config['chunks']['load_distribution'] = true;
+
+ switch($config['type']) {
+ case 'filesystem':
+ $config['directory'] = is_null($config['directory']) ?
+ sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) :
+ $this->normalizePath($config['directory'])
+ ;
+
+ $this->container
+ ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']))
+ ->addArgument($config['directory'])
+ ;
+ break;
+ case 'gaufrette':
+ case 'flysystem':
+ $this->registerFilesystem(
+ $config['type'],
+ 'oneup_uploader.chunks_storage',
+ $storageClass, $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper'],
+ $config['prefix']
+ );
+
+ $this->container->setParameter(
+ 'oneup_uploader.orphanage.class',
+ sprintf('Oneup\UploaderBundle\Uploader\Storage\%sOrphanageStorage', ucfirst($config['type']))
+ );
+
+ // enforce load distribution when using gaufrette as chunk
+ // torage to avoid moving files forth-and-back
+ $this->config['chunks']['load_distribution'] = true;
+ break;
+ default:
+ throw new \InvalidArgumentException(sprintf('Filesystem "%s" is invalid', $config['type']));
+ break;
}
+
}
protected function createStorageService(&$config, $key, $orphanage = false)
@@ -182,26 +198,34 @@ class OneupUploaderExtension extends Extension
$storageName = sprintf('oneup_uploader.storage.%s', $key);
$storageClass = sprintf('%%oneup_uploader.storage.%s.class%%', $config['type']);
- if ($config['type'] == 'filesystem') {
- $config['directory'] = is_null($config['directory']) ?
- sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
- $this->normalizePath($config['directory'])
- ;
-
- $this->container
- ->register($storageName, $storageClass)
- ->addArgument($config['directory'])
- ;
- }
-
- if ($config['type'] == 'gaufrette') {
- $this->registerGaufretteStorage(
- $storageName,
- $storageClass,
- $config['filesystem'],
- $config['sync_buffer_size'],
- $config['stream_wrapper']
- );
+ switch ($config['type']) {
+ case 'filesystem':
+ // root_folder is true, remove the mapping name folder from path
+ $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key;
+
+ $config['directory'] = is_null($config['directory']) ?
+ sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) :
+ $this->normalizePath($config['directory'])
+ ;
+
+ $this->container
+ ->register($storageName, $storageClass)
+ ->addArgument($config['directory'])
+ ;
+ break;
+ case 'gaufrette':
+ case 'flysystem':
+ $this->registerFilesystem(
+ $config['type'],
+ $storageName,
+ $storageClass,
+ $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper']
+ );
+ break;
+ default:
+ break;
}
$storageService = new Reference($storageName);
@@ -228,12 +252,22 @@ class OneupUploaderExtension extends Extension
return $storageService;
}
- protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '')
+ protected function registerFilesystem($type, $key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '')
{
- if(!class_exists('Gaufrette\\Filesystem'))
- throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a chunk storage service.');
+ switch ($type) {
+ case 'gaufrette':
+ if (!class_exists('Gaufrette\\Filesystem')) {
+ throw new InvalidArgumentException('You have to install knplabs/knp-gaufrette-bundle in order to use it as a chunk storage service.');
+ }
+ break;
+ case 'flysystem':
+ if (!class_exists('League\\Flysystem\\Filesystem')) {
+ throw new InvalidArgumentException('You have to install oneup/flysystem-bundle in order to use it as a chunk storage service.');
+ }
+ break;
+ }
- if(strlen($filesystem) <= 0)
+ if (strlen($filesystem) <= 0)
throw new ServiceNotFoundException('Empty service name');
$streamWrapper = $this->normalizeStreamWrapper($streamWrapper);
@@ -243,8 +277,7 @@ class OneupUploaderExtension extends Extension
->addArgument(new Reference($filesystem))
->addArgument($this->getValueInBytes($buffer))
->addArgument($streamWrapper)
- ->addArgument($prefix)
- ;
+ ->addArgument($prefix);
}
protected function getMaxUploadSize($input)
@@ -261,11 +294,14 @@ class OneupUploaderExtension extends Extension
// see: http://www.php.net/manual/en/function.ini-get.php
$input = trim($input);
$last = strtolower($input[strlen($input) - 1]);
+ $numericInput = substr($input, 0, -1);
switch ($last) {
- case 'g': $input *= 1024;
- case 'm': $input *= 1024;
- case 'k': $input *= 1024;
+ case 'g': $numericInput *= 1024;
+ case 'm': $numericInput *= 1024;
+ case 'k': $numericInput *= 1024;
+
+ return $numericInput;
}
return $input;
diff --git a/README.md b/README.md
index 7f5b15e..1daa930 100644
--- a/README.md
+++ b/README.md
@@ -17,7 +17,7 @@ Features included:
* Multiple file uploads handled by your chosen frontend library
* Chunked uploads
-* Supports [Gaufrette](https://github.com/KnpLabs/Gaufrette) and/or local filesystem
+* Support for: [Gaufrette](https://github.com/KnpLabs/Gaufrette) / [Flysystem](https://github.com/thephpleague/flysystem) / local filesystem
* Provides an orphanage for cleaning up orphaned files
* Supports [Session upload progress & cancelation of uploads](http://php.net/manual/en/session.upload-progress.php) as of PHP 5.4
* Fully unit tested
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
+* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway).
* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
* If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320).
* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index e684668..bf580bf 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -6,6 +6,7 @@
<parameters>
<parameter key="oneup_uploader.error_handler.noop.class">Oneup\UploaderBundle\Uploader\ErrorHandler\NoopErrorHandler</parameter>
<parameter key="oneup_uploader.error_handler.blueimp.class">Oneup\UploaderBundle\Uploader\ErrorHandler\BlueimpErrorHandler</parameter>
+ <parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter>
</parameters>
<services>
@@ -17,7 +18,7 @@
<service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.mooupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
- <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.noop.class%" public="false" />
+ <service id="oneup_uploader.error_handler.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" />
<service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" />
</services>
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index c970994..13d8f30 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -6,10 +6,12 @@
<parameters>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.chunks_storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.chunks_storage.flysystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage</parameter>
<parameter key="oneup_uploader.chunks_storage.filesystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.storage.flysystem.class">Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage</parameter>
<parameter key="oneup_uploader.storage.filesystem.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemOrphanageStorage</parameter>
<parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter>
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index fd6d87a..2aa007b 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -1,7 +1,7 @@
Using Chunked Uploads
=====================
-Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend.
+Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabled, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend.
```js
$(document).ready(function()
@@ -82,6 +82,6 @@ See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section i
The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle.
- $> php app/console oneup:uploader:clean-chunks
+ $> php app/console oneup:uploader:clear-chunks
This parameter will clean all chunk files older than the `maxage` value in your configuration.
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index 6b0d248..a7cee8a 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -38,6 +38,7 @@ oneup_uploader:
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
+ root_folder: false
# Set max_size to -1 for gracefully downgrade this number to the systems max upload size.
max_size: 9223372036854775807
diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md
index 4110836..8c1e248 100644
--- a/Resources/doc/custom_error_handler.md
+++ b/Resources/doc/custom_error_handler.md
@@ -33,6 +33,12 @@ Define a service for your class.
</services>
```
+```yml
+services:
+ acme_demo.custom_error_handler:
+ class: Acme\DemoBundle\ErrorHandler\CustomErrorHandler
+```
+
And configure the mapping to use your shiny new service.
```yml
@@ -42,4 +48,9 @@ oneup_uploader:
error_handler: acme_demo.custom_error_handler
```
-**Note**: As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) only the `BlueimpErrorHandler` is implemented. If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note.
+**Note**:
+
+* As of [9dbd905](https://github.com/1up-lab/OneupUploaderBundle/commit/9dbd9056dfe403ce6f1273d2d75fe814d517731a) `BlueimpErrorHandler` is implemented.
+* As of [f420fff](https://github.com/1up-lab/OneupUploaderBundle/commit/f420fff5bc3ec910e925ceae15bc513b419693f2) `DropZoneErrorHandler` is implemented.
+
+If you know how to implement the error handlers for the other supported frontends, please create a pull request or drop me a note.
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 88c6d71..1aa1cfd 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -11,15 +11,21 @@ In almost every use case you need to further process uploaded files. For example
To listen to one of these events you need to create an `EventListener`.
```php
-namespace Acme\HelloBundle\EventListener;
+namespace AppBundle\EventListener;
+use Doctrine\Common\Persistence\ObjectManager;
use Oneup\UploaderBundle\Event\PostPersistEvent;
class UploadListener
{
- public function __construct($doctrine)
+ /**
+ * @var ObjectManager
+ */
+ private $om;
+
+ public function __construct(ObjectManager $om)
{
- $this->doctrine = $doctrine;
+ $this->om = $om;
}
public function onUpload(PostPersistEvent $event)
@@ -33,13 +39,22 @@ And register it in your `services.xml`.
```xml
<services>
- <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener\UploadListener">
+ <service id="app.upload_listener" class="AppBundle\EventListener\UploadListener">
<argument type="service" id="doctrine" />
<tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" />
</service>
</services>
```
+```yml
+services:
+ acme_hello.upload_listener:
+ class: AppBundle\EventListener\UploadListener
+ arguments: ["@doctrine.orm.entity_manager"]
+ tags:
+ - { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload }
+```
+
You can now implement you custom logic in the `onUpload` method of your EventListener.
## Use custom input data
@@ -90,3 +105,21 @@ If you are using chunked uploads and hook into the `oneup_uploader.post_chunk_up
* `getType`: Get the name of the mapping of the current upload. Useful if you have multiple mappings and EventListeners.
* `getConfig`: Get the config of the mapping.
* `isLast`: Returns `true` if this is the last chunk to be uploaded, `false` otherwise.
+
+## Returning a error
+You can return a upload error by throwing a ```Symfony\Component\HttpFoundation\File\Exception\UploadException``` exception
+
+But remember in the PostPersistEvent the file is already uploaded, so its up to you to remove the file before throwing the exception.
+
+You should use the [validation event](custom_validator.md) if possible, so the file does not touch your system.
+
+```php
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+
+public function onUpload(PostPersistEvent $event)
+{
+ // Remember to remove the already uploaded file
+ throw new UploadException('Nope, I don\'t do files.');
+}
+```
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index 9b59e58..fea6ee0 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -10,7 +10,7 @@ First, create a custom namer which implements ```Oneup\UploaderBundle\Uploader\N
```php
<?php
-namespace Acme\DemoBundle;
+namespace AppBundle\Uploader\Naming;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
@@ -24,7 +24,7 @@ class CatNamer implements NamerInterface
}
```
-To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful.
+To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists.
Next, register your created namer as a service in your `services.xml`
@@ -34,13 +34,80 @@ Next, register your created namer as a service in your `services.xml`
</services>
```
+```yml
+services:
+ app.cat_namer:
+ class: AppBundle\Uploader\Naming\CatNamer
+```
+
Now you can use your custom service by adding it to your configuration:
```yml
oneup_uploader:
mappings:
gallery:
- namer: acme_demo.custom_namer
+ namer: app.cat_namer
```
Every file uploaded through the `Controller` of this mapping will be named with your custom namer.
+
+## Change the directory structure
+
+With the `NameInterface` you can change the directory structure to provide a better files organization or to use your own existing structure. For example, you need to separate the uploaded files by users with a `user_id` folder.
+
+You need to inject the `security.token_storage` service to your namer.
+
+```xml
+<services>
+ <service id="acme_demo.custom_namer" class="Acme\DemoBundle\CatNamer">
+ <argument type="service" id="security.token_storage"/>
+ </service>
+</services>
+```
+
+```yml
+services:
+ acme_demo.custom_namer:
+ class: Acme\DemoBundle\CatNamer
+ arguments: ["@security.token_storage"]
+```
+
+Now you can use the service to get the logged user id and return the custom directory like below:
+
+```php
+<?php
+
+namespace Acme\DemoBundle;
+
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
+use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
+
+class CatNamer implements NamerInterface
+{
+ private $tokenStorage;
+
+ public function __construct(TokenStorage $tokenStorage){
+ $this->tokenStorage = $tokenStorage;
+ }
+
+ /**
+ * Creates a user directory name for the file being uploaded.
+ *
+ * @param FileInterface $file
+ * @return string The directory name.
+ */
+ public function name(FileInterface $file)
+ {
+ $userId = $this->tokenStorage->getToken()->getUser()->getId();
+
+ return sprintf('%s/%s.%s',
+ $userId,
+ uniqid(),
+ $file->getExtension()
+ );
+ }
+}
+```
+
+Every file uploaded through the `Controller` of this mapping will be named with your new directory structure.
diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md
index 20de413..c4fd761 100644
--- a/Resources/doc/custom_uploader.md
+++ b/Resources/doc/custom_uploader.md
@@ -40,7 +40,7 @@ class CustomUploader extends UploaderController
public function upload()
{
// get some basic stuff together
- $request = $this->container->get('request');
+ $request = $this->container->get('request_stack')->getMasterRequest();
$response = new EmptyResponse();
// get file from request (your own logic)
diff --git a/Resources/doc/custom_validator.md b/Resources/doc/custom_validator.md
index 1f0ef03..1a4d77d 100644
--- a/Resources/doc/custom_validator.md
+++ b/Resources/doc/custom_validator.md
@@ -45,3 +45,13 @@ After that register your new `EventListener` in the `services.xml` of your appli
</services>
</container>
```
+
+```yml
+services:
+ acme_demo.always_false_listener:
+ class: Acme\DemoBundle\EventListener\AlwaysFalseValidationListener
+ tags:
+ - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate }
+```
+
+Since version 1.6 you can listen to an event thrown for every uploader specifically. The name for the event is `oneup_uploader.validation.{type}` where `{type}` represents the config key of the uploader you want to target.
diff --git a/Resources/doc/flysystem_storage.md b/Resources/doc/flysystem_storage.md
new file mode 100644
index 0000000..76aa1ea
--- /dev/null
+++ b/Resources/doc/flysystem_storage.md
@@ -0,0 +1,75 @@
+Use Flysystem as Storage layer
+==============================
+
+Flysystem is an abstract storage layer you can use to store your uploaded files. An explanation why you should use an abstraction storage layer comes from the _Why use Gaufrette_ section on [the Gaufrette Repo](https://github.com/KnpLabs/Gaufrette):
+
+> The filesystem abstraction layer permits you to develop your application without the need to know were all those medias will be stored and how.
+>
+> Another advantage of this is the possibility to update the files location without any impact on the code apart from the definition of your filesystem. In example, if your project grows up very fast and if your server reaches its limits, you can easily move your medias in an Amazon S3 server or any other solution.
+
+In order to use Flysystem with OneupUploaderBundle, be sure to follow these steps:
+
+## Install OneupFlysystemBundle
+
+Add the OneupFlysystemBundle to your composer.json file.
+
+```js
+{
+ "require": {
+ "oneup/flysystem-bundle": "1.4.*"
+ }
+}
+```
+
+And update your dependencies through composer.
+
+ $> php composer.phar update oneup/flysystem-bundle
+
+After installing, enable the bundle in your AppKernel:
+
+``` php
+<?php
+// app/AppKernel.php
+
+public function registerBundles()
+{
+ $bundles = array(
+ // ...
+ new Oneup\FlysystemBundle\OneupFlysystemBundle(),
+ );
+}
+```
+
+## Configure your Filesystems
+
+The following is a sample configuration for the OneupFlysystemBundle. It will create a flysystem service called `oneup_flysystem.gallery_filesystem` which can be used in the OneupUploaderBundle. For a complete list of features refer to the [official documentation](https://github.com/1up-lab/OneupFlysystemBundle).
+
+```yml
+# app/config/config.yml
+
+oneup_flysystem:
+ adapters:
+ acme.flysystem_adapter:
+ awss3v3:
+ client: acme.s3_client
+ bucket: ~
+ prefix: ~
+ filesystems:
+ gallery:
+ adapter: acme.flysystem_adapter
+```
+
+## Configure your mappings
+
+Activate Flysystem by switching the `type` property to `flysystem` and pass the Flysystem filesystem configured in the previous step.
+
+```yml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ type: flysystem
+ filesystem: oneup_flysystem.gallery_filesystem
+```
diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md
index cd8a019..22fbb16 100644
--- a/Resources/doc/frontend_fineuploader.md
+++ b/Resources/doc/frontend_fineuploader.md
@@ -1,26 +1,27 @@
Use FineUploader
================
-Download [FineUploader](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`.
+Download [FineUploader 5](http://fineuploader.com/) and include it in your template. Connect the `endpoint` property to the dynamic route `_uploader_{mapping_name}`. This example is based on the [UI Mode](http://docs.fineuploader.com/branch/master/quickstart/01-getting-started.html) of FineUploader.
```html
-<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
-<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script>
+<link href="fine-uploader/fine-uploader-new.min.css" rel="stylesheet">
+<script type="text/javascript" src="fine-uploader/fine-uploader.min.js"></script>
<script type="text/javascript">
-$(document).ready(function()
-{
var uploader = new qq.FineUploader({
- element: $('#uploader')[0],
+ element: document.getElementById('fine-uploader'),
request: {
endpoint: "{{ oneup_uploader_endpoint('gallery') }}"
}
});
-});
</script>
-<div id="uploader"></div>
+<div id="fine-uploader"></div>
```
+You can find a fully example of all available settings on the [official documentation](http://docs.fineuploader.com/branch/master/quickstart/02-setting_options.html).
+
+If you are using Fine Uploader UI, as described in this example, you **MUST** include a template in your document/markup. You can use the ``default.html`` file in the templates directory bundled with the FineUploader library and customize it as desired. You even can use an inline template. See the official [styling documentation page](http://docs.fineuploader.com/branch/master/features/styling.html) for more details.
+
Configure the OneupUploaderBundle to use the correct controller:
```yaml
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index ac381bc..3942d44 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -1,11 +1,14 @@
Getting started
===============
-The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.1+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself.
+The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.4+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself.
## Prerequisites
-This bundle is tested using Symfony2 versions 2.1+.
+This bundle is tested using Symfony 2.4+.
+
+**With Symfony 2.3**
+If you want to use the bundle with Symfony 2.3, head over to the documentation for [1.3.x](https://github.com/1up-lab/OneupUploaderBundle/blob/release-1.3.x/Resources/doc/index.md).
### Translations
If you wish to use the default texts provided with this bundle, you have to make sure that you have translator
@@ -22,7 +25,7 @@ framework:
Perform the following steps to install and use the basic functionality of the OneupUploaderBundle:
-* Download OnueupUploaderBundle using Composer
+* Download OneupUploaderBundle using Composer
* Enable the bundle
* Configure the bundle
* Prepare your frontend
@@ -31,19 +34,9 @@ Perform the following steps to install and use the basic functionality of the On
Add OneupUploaderBundle to your composer.json using the following construct:
-```js
-{
- "require": {
- "oneup/uploader-bundle": "~1.3"
- }
-}
-```
-
-Now tell composer to download the bundle by running the following command:
+ $ composer require oneup/uploader-bundle "~1.4"
- $> php composer.phar update oneup/uploader-bundle
-
-Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup```
+Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory.
### Step 2: Enable the bundle
@@ -85,7 +78,31 @@ oneup_uploader:
type: uploader
```
-The default directory that is used to upload files to is `web/uploads/{mapping_name}`, where `{mapping_name}` is the value for `mappings` in your `config.yml` (namely `gallery` in the above example).
+The default directory that is used to upload files to is `web/uploads/{mapping_name}`. In case you want to avoid a separated mapping folder, you can set `root_folder: true` and the default directory will be `web/uploads`.
+
+```yaml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ root_folder: true
+```
+
+> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you.
+> You can improve the directory structure checking the "[Change the directory structure](custom_namer.md#change-the-directory-structure)".
+
+If you want to use your own path, for example /data/uploads :
+
+```yaml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ directory: "%kernel.root_dir%/../data/uploads/"
+```
### Step 4: Check if the bundle is working correctly
@@ -110,14 +127,14 @@ or in a Twig template you can use the `oneup_uploader_endpoint` function:
So if you take the mapping described before, the generated route name would be `_uploader_gallery`. Follow one of the listed guides to include your frontend:
-* [Use FineUploader](frontend_fineuploader.md)
+* [Use Dropzone](frontend_dropzone.md)
* [Use jQuery File Upload](frontend_blueimp.md)
-* [Use YUI3 Uploader](frontend_yui3.md)
-* [Use Uploadify](frontend_uploadify.md)
+* [Use Plupload](frontend_plupload.md)
+* [Use FineUploader](frontend_fineuploader.md)
* [Use FancyUpload](frontend_fancyupload.md)
* [Use MooUpload](frontend_mooupload.md)
-* [Use Plupload](frontend_plupload.md)
-* [Use Dropzone](frontend_dropzone.md)
+* [Use YUI3 Uploader](frontend_yui3.md)
+* [Use Uploadify](frontend_uploadify.md)
## Next steps
@@ -128,6 +145,7 @@ some more advanced features.
* [Return custom data to frontend](response.md)
* [Enable chunked uploads](chunked_uploads.md)
* [Using the Orphanage](orphanage.md)
+* [Use Flysystem as storage layer](flysystem_storage.md)
* [Use Gaufrette as storage layer](gaufrette_storage.md)
* [Include your own Namer](custom_namer.md)
* [Use custom error handlers](custom_error_handler.md)
diff --git a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
new file mode 100644
index 0000000..f78b1fc
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use League\Flysystem\File;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
+
+use League\Flysystem\Adapter\Local as Adapter;
+use League\Flysystem\Filesystem as FSAdapter;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage;
+
+class FlysystemOrphanageStorageTest extends OrphanageTest
+{
+ protected $chunkDirectory;
+ protected $chunksKey = 'chunks';
+ protected $orphanageKey = 'orphanage';
+
+ public function setUp()
+ {
+ $this->numberOfPayloads = 5;
+ $this->realDirectory = sys_get_temp_dir() . '/storage';
+ $this->chunkDirectory = $this->realDirectory .'/' . $this->chunksKey;
+ $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
+ $this->payloads = array();
+
+ if (!$this->checkIfTempnameMatchesAfterCreation()) {
+ $this->markTestSkipped('Temporary directories do not match');
+ }
+
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->realDirectory);
+ $filesystem->mkdir($this->chunkDirectory);
+ $filesystem->mkdir($this->tempDirectory);
+
+ $adapter = new Adapter($this->realDirectory, true);
+ $filesystem = new FSAdapter($adapter);
+
+ $this->storage = new Storage($filesystem, 100000);
+
+ $chunkStorage = new ChunkStorage($filesystem, 100000, null, 'chunks');
+
+ // create orphanage
+ $session = new Session(new MockArraySessionStorage());
+ $session->start();
+
+ $config = array('directory' => 'orphanage');
+
+ $this->orphanage = new FlysystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
+
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ // create temporary file as if it was reassembled by the chunk manager
+ $file = tempnam($this->chunkDirectory, 'uploader');
+
+ $pointer = fopen($file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ //gaufrette needs the key relative to it's root
+ $fileKey = str_replace($this->realDirectory, '', $file);
+
+ $this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem);
+ }
+ }
+
+ public function testUpload()
+ {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
+ }
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+
+ $finder = new Finder();
+ // exclude the orphanage and the chunks
+ $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files();
+ $this->assertCount(0, $finder);
+ }
+
+ public function testUploadAndFetching()
+ {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
+ }
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+
+ $finder = new Finder();
+ $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files();
+ $this->assertCount(0, $finder);
+
+ $files = $this->orphanage->uploadFiles();
+
+ $this->assertTrue(is_array($files));
+ $this->assertCount($this->numberOfPayloads, $files);
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount(0, $finder);
+
+ $finder = new Finder();
+ $finder->in($this->realDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+ }
+
+ public function checkIfTempnameMatchesAfterCreation()
+ {
+ return strpos(@tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ }
+}
diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php
new file mode 100644
index 0000000..bdd43e9
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemStorageTest.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use League\Flysystem\Adapter\Local as Adapter;
+use League\Flysystem\Filesystem as FSAdapter;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FlysystemStorageTest extends \PHPUnit_Framework_TestCase
+{
+ protected $directory;
+
+ /**
+ * @var Storage
+ */
+ protected $storage;
+ protected $file;
+
+ public function setUp()
+ {
+ $this->directory = sys_get_temp_dir() . '/storage';
+
+ // create temporary file
+ $this->file = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($this->file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ $adapter = new Adapter($this->directory, true);
+ $filesystem = new FSAdapter($adapter);
+
+ $this->storage = new Storage($filesystem, 100000);
+ }
+
+ public function testUpload()
+ {
+ $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true));
+ $this->storage->upload($payload, 'notsogrumpyanymore.jpeg');
+
+ $finder = new Finder();
+ $finder->in($this->directory)->files();
+
+ $this->assertCount(1, $finder);
+
+ foreach ($finder as $file) {
+ $this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg');
+ $this->assertEquals($file->getSize(), 1024);
+ }
+ }
+
+ public function tearDown()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->directory);
+ }
+}
diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
index 418298c..a9e55cb 100644
--- a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -113,6 +113,6 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
public function checkIfTempnameMatchesAfterCreation()
{
- return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ return strpos(@tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
}
}
diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php
index 836ab86..c539e7f 100644
--- a/Tests/Uploader/Storage/OrphanageTest.php
+++ b/Tests/Uploader/Storage/OrphanageTest.php
@@ -2,13 +2,18 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
-abstract class OrphanageTest extends \PHPUnit_Framework_Testcase
+abstract class OrphanageTest extends \PHPUnit_Framework_TestCase
{
protected $tempDirectory;
protected $realDirectory;
+
+ /**
+ * @var \Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface
+ */
protected $orphanage;
protected $storage;
protected $payloads;
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index c042e56..3cac14d 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -21,11 +21,11 @@ class UploaderExtension extends \Twig_Extension
public function getFunctions()
{
return array(
- 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'),
- 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'),
- 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'),
- 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey'),
- 'oneup_uploader_maxsize' => new \Twig_Function_Method($this, 'maxSize'),
+ new \Twig_SimpleFunction('oneup_uploader_endpoint', array($this, 'endpoint')),
+ new \Twig_SimpleFunction('oneup_uploader_progress', array($this, 'progress')),
+ new \Twig_SimpleFunction('oneup_uploader_cancel', array($this, 'cancel')),
+ new \Twig_SimpleFunction('oneup_uploader_upload_key', array($this, 'uploadKey')),
+ new \Twig_SimpleFunction('oneup_uploader_maxsize', array($this, 'maxSize')),
);
}
diff --git a/Uploader/Chunk/Storage/FlysystemStorage.php b/Uploader/Chunk/Storage/FlysystemStorage.php
new file mode 100644
index 0000000..19e7a44
--- /dev/null
+++ b/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -0,0 +1,152 @@
+<?php
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
+
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use League\Flysystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FlysystemStorage implements ChunkStorageInterface
+{
+
+ protected $unhandledChunk;
+ protected $prefix;
+ protected $streamWrapperPrefix;
+
+ /**
+ * @var Filesystem
+ */
+ private $filesystem;
+
+ public $bufferSize;
+
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
+ {
+ if (
+ ! method_exists($filesystem, 'readStream')
+ ||
+ ! method_exists($filesystem, 'putStream')
+ ) {
+ throw new \InvalidArgumentException('The filesystem used as chunk storage must streamable');
+ }
+
+ $this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
+ $this->prefix = $prefix;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ public function clear($maxAge, $prefix = null)
+ {
+ $prefix = $prefix ? :$this->prefix;
+ $matches = $this->filesystem->listFiles($prefix);
+
+ $now = time();
+ $toDelete = array();
+
+ // Collect the directories that are old,
+ // this also means the files inside are old
+ // but after the files are deleted the dirs
+ // would remain
+ foreach ($matches['dirs'] as $key) {
+ if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) {
+ $toDelete[] = $key;
+ }
+ }
+ // The same directory is returned for every file it contains
+ array_unique($toDelete);
+ foreach ($matches['keys'] as $key) {
+ if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) {
+ $this->filesystem->delete($key);
+ }
+ }
+
+ foreach ($toDelete as $key) {
+ // The filesystem will throw exceptions if
+ // a directory is not empty
+ try {
+ $this->filesystem->delete($key);
+ } catch (\Exception $e) {
+ continue;
+ }
+ }
+ }
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $this->unhandledChunk = array(
+ 'uuid' => $uuid,
+ 'index' => $index,
+ 'chunk' => $chunk,
+ 'original' => $original
+ );
+ }
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk)
+ {
+ // the index is only added to be in sync with the filesystem storage
+ $path = $this->prefix.'/'.$this->unhandledChunk['uuid'].'/';
+ $filename = $this->unhandledChunk['index'].'_'.$this->unhandledChunk['original'];
+
+ if (empty($chunks)) {
+ $target = $filename;
+ } else {
+ sort($chunks, SORT_STRING | SORT_FLAG_CASE);
+ $target = pathinfo($chunks[0], PATHINFO_BASENAME);
+ }
+
+
+ if ($this->unhandledChunk['index'] === 0) {
+ // if it's the first chunk overwrite the already existing part
+ // to avoid appending to earlier failed uploads
+ $handle = fopen($path . '/' . $target, 'w');
+ } else {
+ $handle = fopen($path . '/' . $target, 'a');
+ }
+
+ $this->filesystem->putStream($path . $target, $handle);
+ if ($renameChunk) {
+ $name = preg_replace('/^(\d+)_/', '', $target);
+ /* The name can only match if the same user in the same session is
+ * trying to upload a file under the same name AND the previous upload failed,
+ * somewhere between this function, and the cleanup call. If that happened
+ * the previous file is unaccessible by the user, but if it is not removed
+ * it will block the user from trying to re-upload it.
+ */
+ if ($this->filesystem->has($path.$name)) {
+ $this->filesystem->delete($path.$name);
+ }
+
+ $this->filesystem->rename($path.$target, $path.$name);
+ $target = $name;
+ }
+ $uploaded = $this->filesystem->get($path.$target);
+
+ if (!$renameChunk) {
+ return $uploaded;
+ }
+
+ return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+ public function cleanup($path)
+ {
+ $this->filesystem->delete($path);
+ }
+
+ public function getChunks($uuid)
+ {
+ $results = $this->filesystem->listFiles($this->prefix.'/'.$uuid);
+ return preg_grep('/^.+\/(\d+)_/', $results['keys']);
+ }
+
+ public function getFilesystem()
+ {
+ return $this->filesystem;
+ }
+
+ public function getStreamWrapperPrefix()
+ {
+ return $this->streamWrapperPrefix;
+ }
+
+}
diff --git a/Uploader/ErrorHandler/DropzoneErrorHandler.php b/Uploader/ErrorHandler/DropzoneErrorHandler.php
new file mode 100755
index 0000000..5b0ad44
--- /dev/null
+++ b/Uploader/ErrorHandler/DropzoneErrorHandler.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Exception;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class DropzoneErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(AbstractResponse $response, Exception $exception)
+ {
+ $errors[] = $exception;
+ $message = $exception->getMessage();
+ // Dropzone wants JSON with error message put into 'error' field.
+ // This overwrites the previous error message, so we're only displaying the last one.
+ $response['error'] = $message;
+ }
+}
diff --git a/Uploader/File/FlysystemFile.php b/Uploader/File/FlysystemFile.php
new file mode 100644
index 0000000..dc36e69
--- /dev/null
+++ b/Uploader/File/FlysystemFile.php
@@ -0,0 +1,48 @@
+<?php
+namespace Oneup\UploaderBundle\Uploader\File;
+
+use League\Flysystem\File;
+use League\Flysystem\Filesystem;
+
+class FlysystemFile extends File implements FileInterface
+{
+
+ protected $streamWrapperPrefix;
+ protected $mimeType;
+
+ public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
+ {
+ parent::__construct($filesystem, $file->getPath());
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ /**
+ * Returns the path of the file
+ *
+ * @return string
+ */
+ public function getPathname()
+ {
+ return $this->getPath();
+ }
+
+ /**
+ * Returns the basename of the file
+ *
+ * @return string
+ */
+ public function getBasename()
+ {
+ return pathinfo($this->getPath(), PATHINFO_BASENAME);
+ }
+
+ /**
+ * Returns the guessed extension of the file
+ *
+ * @return mixed
+ */
+ public function getExtension()
+ {
+ return pathinfo($this->getPath(), PATHINFO_EXTENSION);
+ }
+}
diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php
index 58868b8..7fcc83a 100644
--- a/Uploader/Gaufrette/StreamManager.php
+++ b/Uploader/Gaufrette/StreamManager.php
@@ -25,11 +25,9 @@ class StreamManager
protected function ensureRemotePathExists($path)
{
- // this is a somehow ugly workaround introduced
- // because the stream-mode is not able to create
- // subdirectories.
- if(!$this->filesystem->has($path))
+ if(!$this->filesystem->has($path)) {
$this->filesystem->write($path, '', true);
+ }
}
protected function openStream(Stream $stream, $mode)
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index 9352b4e..9442712 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -32,7 +32,7 @@ class OrphanageManager
// Really ugly solution to clearing the orphanage on gaufrette
$class = $this->container->getParameter('oneup_uploader.orphanage.class');
if ($class === 'Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage') {
- $chunkStorage = $this->container->get('oneup_uploader.chunks_storage ');
+ $chunkStorage = $this->container->get('oneup_uploader.chunks_storage');
$chunkStorage->clear($this->config['maxage'], $this->config['directory']);
return;
diff --git a/Uploader/Storage/FilesystemOrphanageStorage.php b/Uploader/Storage/FilesystemOrphanageStorage.php
index ed6e4f6..8888e16 100644
--- a/Uploader/Storage/FilesystemOrphanageStorage.php
+++ b/Uploader/Storage/FilesystemOrphanageStorage.php
@@ -48,7 +48,7 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS
$return = array();
foreach ($files as $file) {
- $return[] = $this->storage->upload(new FilesystemFile(new File($file->getPathname())), str_replace($this->getFindPath(), '', $file));
+ $return[] = $this->storage->upload(new FilesystemFile(new File($file->getPathname())), ltrim(str_replace($this->getFindPath(), '', $file), "/"));
}
return $return;
diff --git a/Uploader/Storage/FlysystemOrphanageStorage.php b/Uploader/Storage/FlysystemOrphanageStorage.php
new file mode 100644
index 0000000..d9947c3
--- /dev/null
+++ b/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use League\Flysystem\File;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+
+class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageStorageInterface
+{
+ protected $storage;
+ protected $session;
+ protected $chunkStorage;
+ protected $config;
+ protected $type;
+
+ /**
+ * @param StorageInterface $storage
+ * @param SessionInterface $session
+ * @param ChunkStorage $chunkStorage This class is only used if the gaufrette chunk storage is used.
+ * @param $config
+ * @param $type
+ */
+ public function __construct(StorageInterface $storage, SessionInterface $session, ChunkStorage $chunkStorage, $config, $type)
+ {
+ /*
+ * initiate the storage on the chunk storage's filesystem
+ * the stream wrapper is useful for metadata.
+ */
+ parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, $chunkStorage->getStreamWrapperPrefix());
+
+ $this->storage = $storage;
+ $this->chunkStorage = $chunkStorage;
+ $this->session = $session;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ public function upload(FileInterface $file, $name, $path = null)
+ {
+ if(!$this->session->isStarted())
+ throw new \RuntimeException('You need a running session in order to run the Orphanage.');
+
+ return parent::upload($file, $name, $this->getPath());
+ }
+
+ public function uploadFiles(array $files = null)
+ {
+ try {
+ if (null === $files) {
+ $files = $this->getFiles();
+ }
+ $return = array();
+
+ foreach ($files as $key => $file) {
+ try {
+ $return[] = $this->storage->upload($file, str_replace($this->getPath(), '', $key));
+ } catch (\Exception $e) {
+ // well, we tried.
+ continue;
+ }
+ }
+
+ return $return;
+ } catch (\Exception $e) {
+ return array();
+ }
+ }
+
+ public function getFiles()
+ {
+ $keys = $this->chunkStorage->getFilesystem()->listFiles($this->getPath());
+ $keys = $keys['keys'];
+ $files = array();
+
+ foreach ($keys as $key) {
+ // gotta pass the filesystem to both as you can't get it out from one..
+ $files[$key] = new FlysystemFile(new File($this->chunkStorage->getFilesystem(), $key), $this->chunkStorage->getFilesystem());
+ }
+
+ return $files;
+ }
+
+ protected function getPath()
+ {
+ // the storage is initiated in the root of the filesystem, from where the orphanage directory
+ // should be relative.
+ return sprintf('%s/%s/%s', $this->config['directory'], $this->session->getId(), $this->type);
+ }
+
+}
diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php
new file mode 100644
index 0000000..9a98720
--- /dev/null
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use League\Flysystem\Filesystem;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Symfony\Component\Filesystem\Filesystem as LocalFilesystem;
+
+class FlysystemStorage implements StorageInterface
+{
+
+ /**
+ * @var null|string
+ */
+ protected $streamWrapperPrefix;
+
+ /**
+ * @var float
+ */
+ protected $bufferSize;
+
+ /**
+ * @var Filesystem
+ */
+ private $filesystem;
+
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix = null)
+ {
+ $this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ public function upload(FileInterface $file, $name, $path = null)
+ {
+ $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
+
+ if ($file instanceof FlysystemFile) {
+ if ($file->getFilesystem() == $this->filesystem) {
+ $file->getFilesystem()->rename($file->getPath(), $path);
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+ }
+
+ $stream = fopen($file->getPathname(), 'r+');
+ $this->filesystem->putStream($name, $stream);
+ if (is_resource($stream)) {
+ fclose($stream);
+ }
+
+ if ($file instanceof FlysystemFile) {
+ $file->delete();
+ } else {
+ $filesystem = new LocalFilesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+}
diff --git a/composer.json b/composer.json
index aa66e5d..b0ef8ce 100644
--- a/composer.json
+++ b/composer.json
@@ -15,22 +15,25 @@
],
"require": {
- "symfony/framework-bundle": ">=2.2",
- "symfony/finder": ">=2.2.0"
+ "php":">=5.4",
+ "symfony/framework-bundle": "^2.4.0|~3.0",
+ "symfony/finder": "^2.4.0|~3.0"
},
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
- "symfony/class-loader": "2.*",
- "symfony/security-bundle": "2.*",
- "sensio/framework-extra-bundle": "2.*",
- "symfony/browser-kit": "2.*",
- "phpunit/phpunit": "~4.1"
+ "symfony/class-loader": "2.*|~3.0",
+ "symfony/security-bundle": "2.*|~3.0",
+ "sensio/framework-extra-bundle": "2.*|~3.0",
+ "symfony/browser-kit": "2.*|~3.0",
+ "phpunit/phpunit": "~4.4",
+ "oneup/flysystem-bundle": "^1.2"
},
"suggest": {
- "knplabs/knp-gaufrette-bundle": "0.1.*"
+ "knplabs/knp-gaufrette-bundle": "0.1.*",
+ "oneup/flysystem-bundle": "^1.2"
},
"autoload": {
| 0 |
0609aa6c8dcdbdd50a6c308828cc40d06a7d513a
|
1up-lab/OneupUploaderBundle
|
CS fixes for Tests
|
commit 0609aa6c8dcdbdd50a6c308828cc40d06a7d513a
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 21:24:45 2013 +0200
CS fixes for Tests
diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php
index 2e39ab8..7a15fe8 100644
--- a/Tests/App/AppKernel.php
+++ b/Tests/App/AppKernel.php
@@ -13,7 +13,7 @@ class AppKernel extends Kernel
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
-
+
// bundle to test
new Oneup\UploaderBundle\OneupUploaderBundle(),
);
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index f17c2f8..96b50d3 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -23,12 +23,12 @@ monolog:
oneup_uploader:
mappings:
-
+
fineuploader:
frontend: fineuploader
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
fineuploader_validation:
frontend: fineuploader
storage:
@@ -37,12 +37,12 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
fancyupload:
frontend: fancyupload
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
fancyupload_validation:
frontend: fancyupload
storage:
@@ -51,12 +51,12 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
yui3:
frontend: yui3
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
yui3_validation:
frontend: yui3
storage:
@@ -65,12 +65,12 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
plupload:
frontend: plupload
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
plupload_validation:
frontend: plupload
storage:
@@ -79,12 +79,12 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
uploadify:
frontend: uploadify
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
uploadify_validation:
frontend: uploadify
storage:
@@ -93,12 +93,12 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
blueimp:
frontend: blueimp
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
-
+
blueimp_validation:
frontend: blueimp
storage:
@@ -107,8 +107,8 @@ oneup_uploader:
disallowed_extensions: [ "fail" ]
allowed_mimetypes: [ "image/jpg", "text/plain" ]
disallowed_mimetypes: [ "image/gif" ]
-
+
mooupload:
frontend: mooupload
storage:
- directory: %kernel.root_dir%/cache/%kernel.environment%/upload
\ No newline at end of file
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
diff --git a/Tests/App/config/routing.yml b/Tests/App/config/routing.yml
index 71cd825..ad9f64f 100644
--- a/Tests/App/config/routing.yml
+++ b/Tests/App/config/routing.yml
@@ -1,3 +1,3 @@
oneup_uploader:
resource: .
- type: uploader
\ No newline at end of file
+ type: uploader
diff --git a/Tests/Controller/AbstractChunkedUploadTest.php b/Tests/Controller/AbstractChunkedUploadTest.php
index dd434c6..29c8a90 100644
--- a/Tests/Controller/AbstractChunkedUploadTest.php
+++ b/Tests/Controller/AbstractChunkedUploadTest.php
@@ -10,58 +10,58 @@ use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
abstract class AbstractChunkedUploadTest extends AbstractUploadTest
{
protected $total = 6;
-
+
abstract protected function getNextRequestParameters($i);
abstract protected function getNextFile($i);
-
+
public function testChunkedUpload()
{
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
- for($i = 0; $i < $this->total; $i ++) {
+
+ for ($i = 0; $i < $this->total; $i ++) {
$client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($this->getNextFile($i)));
$response = $client->getResponse();
-
+
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
}
-
- foreach($this->getUploadedFiles() as $file) {
+
+ foreach ($this->getUploadedFiles() as $file) {
$this->assertTrue($file->isFile());
$this->assertTrue($file->isReadable());
$this->assertEquals(120, $file->getSize());
}
}
-
+
public function testEvents()
{
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
// prepare listener data
$me = $this;
$chunkCount = 0;
$uploadCount = 0;
$chunkSize = $this->getNextFile(0)->getSize();
-
- for($i = 0; $i < $this->total; $i ++) {
+
+ for ($i = 0; $i < $this->total; $i ++) {
// each time create a new client otherwise the events won't get dispatched
$client = static::createClient();
$dispatcher = $client->getContainer()->get('event_dispatcher');
-
+
$dispatcher->addListener(UploadEvents::POST_CHUNK_UPLOAD, function(PostChunkUploadEvent $event) use (&$chunkCount, $chunkSize, &$me) {
++ $chunkCount;
-
+
$chunk = $event->getChunk();
-
+
$me->assertEquals($chunkSize, $chunk->getSize());
});
-
+
$dispatcher->addListener(UploadEvents::POST_UPLOAD, function(Event $event) use (&$uploadCount) {
++ $uploadCount;
});
-
+
$client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($this->getNextFile($i)));
}
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index 9ad0e1d..351f173 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -10,27 +10,27 @@ abstract class AbstractControllerTest extends WebTestCase
protected $createdFiles;
protected $client;
protected $container;
-
+
public function setUp()
{
$this->client = static::createClient();
$this->container = $this->client->getContainer();
$this->helper = $this->container->get('oneup_uploader.templating.uploader_helper');
$this->createdFiles = array();
-
+
$routes = $this->container->get('router')->getRouteCollection()->all();
}
-
+
abstract protected function getConfigKey();
-
+
public function testRoute()
{
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$this->assertNotNull($endpoint);
$this->assertEquals(0, strpos('_uploader', $endpoint));
}
-
+
/**
* @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
@@ -39,7 +39,7 @@ abstract class AbstractControllerTest extends WebTestCase
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('GET', $endpoint);
}
-
+
/**
* @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
@@ -48,7 +48,7 @@ abstract class AbstractControllerTest extends WebTestCase
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('DELETE', $endpoint);
}
-
+
/**
* @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
@@ -57,15 +57,15 @@ abstract class AbstractControllerTest extends WebTestCase
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('PUT', $endpoint);
}
-
+
public function testCallByPost()
{
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint);
$response = $client->getResponse();
-
+
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
}
@@ -74,33 +74,33 @@ abstract class AbstractControllerTest extends WebTestCase
{
$file = tempnam(sys_get_temp_dir(), 'uploader_');
file_put_contents($file, str_repeat('A', $size));
-
+
$this->createdFiles[] = $file;
-
+
return $file;
}
-
+
protected function getUploadedFiles()
{
$env = $this->container->getParameter('kernel.environment');
$root = $this->container->getParameter('kernel.root_dir');
-
+
// assemble path
$path = sprintf('%s/cache/%s/upload', $root, $env);
-
+
$finder = new Finder();
$files = $finder->in($path);
-
+
return $files;
}
-
+
public function tearDown()
{
- foreach($this->createdFiles as $file) {
+ foreach ($this->createdFiles as $file) {
@unlink($file);
}
-
- foreach($this->getUploadedFiles() as $file) {
+
+ foreach ($this->getUploadedFiles() as $file) {
@unlink($file);
}
diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php
index 754bb8d..37c2b67 100644
--- a/Tests/Controller/AbstractUploadTest.php
+++ b/Tests/Controller/AbstractUploadTest.php
@@ -10,55 +10,55 @@ abstract class AbstractUploadTest extends AbstractControllerTest
{
abstract protected function getRequestParameters();
abstract protected function getRequestFile();
-
+
public function setUp()
{
parent::setUp();
$this->createdFiles = array();
}
-
+
public function testSingleUpload()
{
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getRequestFile()));
$response = $client->getResponse();
-
+
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(1, $this->getUploadedFiles());
-
- foreach($this->getUploadedFiles() as $file) {
+
+ foreach ($this->getUploadedFiles() as $file) {
$this->assertTrue($file->isFile());
$this->assertTrue($file->isReadable());
$this->assertEquals(128, $file->getSize());
}
}
-
+
public function testEvents()
{
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
$dispatcher = $client->getContainer()->get('event_dispatcher');
-
+
// event data
$me = $this;
$uploadCount = 0;
-
+
$dispatcher->addListener(UploadEvents::POST_UPLOAD, function(PostUploadEvent $event) use (&$uploadCount, &$me) {
++ $uploadCount;
-
+
$file = $event->getFile();
-
+
$me->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $file);
$me->assertEquals(128, $file->getSize());
});
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getRequestFile()));
-
+
$this->assertCount(1, $this->getUploadedFiles());
$this->assertEquals($uploadCount, count($this->getUploadedFiles()));
}
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index 7f00774..5b5861e 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -8,72 +8,72 @@ abstract class AbstractValidationTest extends AbstractControllerTest
abstract protected function getFileWithIncorrectExtension();
abstract protected function getFileWithCorrectMimeType();
abstract protected function getFileWithIncorrectMimeType();
-
+
public function testAgainstCorrectExtension()
{
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
$response = $client->getResponse();
-
+
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(1, $this->getUploadedFiles());
-
- foreach($this->getUploadedFiles() as $file) {
+
+ foreach ($this->getUploadedFiles() as $file) {
$this->assertTrue($file->isFile());
$this->assertTrue($file->isReadable());
$this->assertEquals(128, $file->getSize());
}
}
-
+
public function testAgainstIncorrectExtension()
{
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithIncorrectExtension()));
$response = $client->getResponse();
-
+
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
}
-
+
public function testAgainstCorrectMimeType()
{
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectMimeType()));
$response = $client->getResponse();
-
+
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(1, $this->getUploadedFiles());
-
- foreach($this->getUploadedFiles() as $file) {
+
+ foreach ($this->getUploadedFiles() as $file) {
$this->assertTrue($file->isFile());
$this->assertTrue($file->isReadable());
$this->assertEquals(128, $file->getSize());
}
}
-
+
public function testAgainstIncorrectMimeType()
{
$this->markTestSkipped('Mock mime type getter.');
-
+
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
+
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithIncorrectMimeType()));
$response = $client->getResponse();
-
+
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
diff --git a/Tests/Controller/BlueimpTest.php b/Tests/Controller/BlueimpTest.php
index 7814f66..0d515b5 100644
--- a/Tests/Controller/BlueimpTest.php
+++ b/Tests/Controller/BlueimpTest.php
@@ -11,12 +11,12 @@ class BlueimpTest extends AbstractUploadTest
{
return 'blueimp';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return array(new UploadedFile(
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 8484951..bdc9493 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -11,12 +11,12 @@ class BlueimpValidationTest extends AbstractValidationTest
{
return 'blueimp_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return array(new UploadedFile(
@@ -26,7 +26,7 @@ class BlueimpValidationTest extends AbstractValidationTest
128
));
}
-
+
protected function getFileWithIncorrectExtension()
{
return array(new UploadedFile(
@@ -36,7 +36,7 @@ class BlueimpValidationTest extends AbstractValidationTest
128
));
}
-
+
protected function getFileWithCorrectMimeType()
{
return array(new UploadedFile(
@@ -46,7 +46,7 @@ class BlueimpValidationTest extends AbstractValidationTest
128
));
}
-
+
protected function getFileWithIncorrectMimeType()
{
return array(new UploadedFile(
diff --git a/Tests/Controller/FancyUploadTest.php b/Tests/Controller/FancyUploadTest.php
index 7a014dd..708d5f6 100644
--- a/Tests/Controller/FancyUploadTest.php
+++ b/Tests/Controller/FancyUploadTest.php
@@ -11,12 +11,12 @@ class FancyUploadTest extends AbstractUploadTest
{
return 'fancyupload';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return new UploadedFile(
diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php
index 1ca342d..11ef999 100644
--- a/Tests/Controller/FancyUploadValidationTest.php
+++ b/Tests/Controller/FancyUploadValidationTest.php
@@ -11,12 +11,12 @@ class FancyUploadValidationTest extends AbstractValidationTest
{
return 'fancyupload_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectExtension()
{
return new UploadedFile(
@@ -36,7 +36,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
@@ -46,7 +46,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/FineUploaderTest.php b/Tests/Controller/FineUploaderTest.php
index 8bce50c..8d96928 100644
--- a/Tests/Controller/FineUploaderTest.php
+++ b/Tests/Controller/FineUploaderTest.php
@@ -11,12 +11,12 @@ class FineUploaderTest extends AbstractChunkedUploadTest
{
return 'fineuploader';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class FineUploaderTest extends AbstractChunkedUploadTest
128
);
}
-
+
protected function getNextRequestParameters($i)
{
return array(
@@ -36,7 +36,7 @@ class FineUploaderTest extends AbstractChunkedUploadTest
'qqfilename' => 'cat.txt'
);
}
-
+
protected function getNextFile($i)
{
return new UploadedFile(
diff --git a/Tests/Controller/FineUploaderValidationTest.php b/Tests/Controller/FineUploaderValidationTest.php
index 32586b3..9d5f31c 100644
--- a/Tests/Controller/FineUploaderValidationTest.php
+++ b/Tests/Controller/FineUploaderValidationTest.php
@@ -11,12 +11,12 @@ class FineUploaderValidationTest extends AbstractValidationTest
{
return 'fineuploader_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectExtension()
{
return new UploadedFile(
@@ -36,7 +36,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
@@ -46,7 +46,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/MooUploadTest.php b/Tests/Controller/MooUploadTest.php
index a1aaf7b..83b8745 100644
--- a/Tests/Controller/MooUploadTest.php
+++ b/Tests/Controller/MooUploadTest.php
@@ -10,12 +10,12 @@ class MooUploadTest extends AbstractControllerTest
{
return 'mooupload';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return array(new UploadedFile(
diff --git a/Tests/Controller/PluploadTest.php b/Tests/Controller/PluploadTest.php
index d1ab541..7ecdf70 100644
--- a/Tests/Controller/PluploadTest.php
+++ b/Tests/Controller/PluploadTest.php
@@ -11,12 +11,12 @@ class PluploadTest extends AbstractChunkedUploadTest
{
return 'plupload';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class PluploadTest extends AbstractChunkedUploadTest
128
);
}
-
+
protected function getNextRequestParameters($i)
{
return array(
@@ -35,7 +35,7 @@ class PluploadTest extends AbstractChunkedUploadTest
'name' => 'cat.txt'
);
}
-
+
protected function getNextFile($i)
{
return new UploadedFile(
diff --git a/Tests/Controller/PluploadValidationTest.php b/Tests/Controller/PluploadValidationTest.php
index 0bdbd03..ccd9848 100644
--- a/Tests/Controller/PluploadValidationTest.php
+++ b/Tests/Controller/PluploadValidationTest.php
@@ -11,12 +11,12 @@ class PluploadValidationTest extends AbstractValidationTest
{
return 'plupload_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class PluploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectExtension()
{
return new UploadedFile(
@@ -36,7 +36,7 @@ class PluploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
@@ -46,7 +46,7 @@ class PluploadValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/UploadifyTest.php b/Tests/Controller/UploadifyTest.php
index 32c4576..2267763 100644
--- a/Tests/Controller/UploadifyTest.php
+++ b/Tests/Controller/UploadifyTest.php
@@ -11,12 +11,12 @@ class UploadifyTest extends AbstractUploadTest
{
return 'uploadify';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return new UploadedFile(
diff --git a/Tests/Controller/UploadifyValidationTest.php b/Tests/Controller/UploadifyValidationTest.php
index 7d22c95..b5851b2 100644
--- a/Tests/Controller/UploadifyValidationTest.php
+++ b/Tests/Controller/UploadifyValidationTest.php
@@ -11,12 +11,12 @@ class UploadifyValidationTest extends AbstractValidationTest
{
return 'uploadify_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class UploadifyValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectExtension()
{
return new UploadedFile(
@@ -36,7 +36,7 @@ class UploadifyValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
@@ -46,7 +46,7 @@ class UploadifyValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/Controller/YUI3Test.php b/Tests/Controller/YUI3Test.php
index 00b9ebf..37f2f41 100644
--- a/Tests/Controller/YUI3Test.php
+++ b/Tests/Controller/YUI3Test.php
@@ -11,12 +11,12 @@ class YUI3Test extends AbstractUploadTest
{
return 'yui3';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getRequestFile()
{
return new UploadedFile(
diff --git a/Tests/Controller/YUI3ValidationTest.php b/Tests/Controller/YUI3ValidationTest.php
index bd09245..3d839f3 100644
--- a/Tests/Controller/YUI3ValidationTest.php
+++ b/Tests/Controller/YUI3ValidationTest.php
@@ -11,12 +11,12 @@ class YUI3ValidationTest extends AbstractValidationTest
{
return 'yui3_validation';
}
-
+
protected function getRequestParameters()
{
return array();
}
-
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
@@ -26,7 +26,7 @@ class YUI3ValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectExtension()
{
return new UploadedFile(
@@ -36,7 +36,7 @@ class YUI3ValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithCorrectMimeType()
{
return new UploadedFile(
@@ -46,7 +46,7 @@ class YUI3ValidationTest extends AbstractValidationTest
128
);
}
-
+
protected function getFileWithIncorrectMimeType()
{
return new UploadedFile(
diff --git a/Tests/DependencyInjection/OneupUploaderExtensionTest.php b/Tests/DependencyInjection/OneupUploaderExtensionTest.php
index b713e61..f68e764 100644
--- a/Tests/DependencyInjection/OneupUploaderExtensionTest.php
+++ b/Tests/DependencyInjection/OneupUploaderExtensionTest.php
@@ -8,4 +8,4 @@ class OneupUploaderExtensionTest extends \PHPUnit_Framework_TestCase
{
$this->assertTrue(true);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 4145b86..017a94e 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -15,19 +15,18 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
'cat' => $cat,
'dog' => $dog
));
-
+
$routes = $routeLoader->load(null);
-
+
// for code coverage
$this->assertTrue($routeLoader->supports('grumpy', 'uploader'));
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertCount(2, $routes);
-
- foreach($routes as $route)
- {
+
+ foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertEquals($route->getDefault('_format'), 'json');
$this->assertEquals($route->getRequirement('_method'), 'POST');
}
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Templating/TemplateHelperTest.php b/Tests/Templating/TemplateHelperTest.php
index 7dc17eb..a3cafbf 100644
--- a/Tests/Templating/TemplateHelperTest.php
+++ b/Tests/Templating/TemplateHelperTest.php
@@ -10,9 +10,9 @@ class TemplateHelperTest extends WebTestCase
{
$client = static::createClient();
$container = $client->getContainer();
-
+
$helper = $container->get('oneup_uploader.templating.uploader_helper');
-
+
// this is for code coverage
$this->assertEquals($helper->getName(), 'oneup_uploader');
}
diff --git a/Tests/Uploader/Chunk/ChunkManagerTest.php b/Tests/Uploader/Chunk/ChunkManagerTest.php
index 995b9c2..4ce9c4a 100644
--- a/Tests/Uploader/Chunk/ChunkManagerTest.php
+++ b/Tests/Uploader/Chunk/ChunkManagerTest.php
@@ -10,79 +10,78 @@ use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
class ChunkManagerTest extends \PHPUnit_Framework_TestCase
{
protected $tmpDir;
-
+
public function setUp()
{
// create a cache dir
$tmpDir = sprintf('/tmp/%s', uniqid());
-
+
$system = new Filesystem();
$system->mkdir($tmpDir);
-
+
$this->tmpDir = $tmpDir;
}
-
+
public function tearDown()
{
$system = new Filesystem();
$system->remove($this->tmpDir);
}
-
+
public function testExistanceOfTmpDir()
{
$this->assertTrue(is_dir($this->tmpDir));
$this->assertTrue(is_writeable($this->tmpDir));
}
-
+
public function testFillOfTmpDir()
{
$finder = new Finder();
$finder->in($this->tmpDir);
-
+
$numberOfFiles = 10;
-
+
$this->fillDirectory($numberOfFiles);
$this->assertCount($numberOfFiles, $finder);
}
-
+
public function testChunkCleanup()
{
// get a manager configured with a max-age of 5 minutes
$maxage = 5 * 60;
$manager = $this->getManager($maxage);
$numberOfFiles = 10;
-
+
$finder = new Finder();
$finder->in($this->tmpDir);
-
+
$this->fillDirectory($numberOfFiles);
$this->assertCount(10, $finder);
-
+
$manager->clear();
-
+
$this->assertTrue(is_dir($this->tmpDir));
$this->assertTrue(is_writeable($this->tmpDir));
$this->assertCount(5, $finder);
-
- foreach($finder as $file)
- {
+
+ foreach ($finder as $file) {
$this->assertGreaterThanOrEqual(time() - $maxage, filemtime($file));
}
}
-
+
public function testClearIfDirectoryDoesNotExist()
{
$filesystem = new Filesystem();
$filesystem->remove($this->tmpDir);
-
+
$manager = $this->getManager(10);
$manager->clear();
-
+
// yey, no exception
$this->assertTrue(true);
}
-
+
protected function getManager($maxage)
{
return new ChunkManager(array(
@@ -90,14 +89,13 @@ class ChunkManagerTest extends \PHPUnit_Framework_TestCase
'maxage' => $maxage
));
}
-
+
protected function fillDirectory($number)
{
$system = new Filesystem();
-
- for($i = 0; $i < $number; $i ++)
- {
+
+ for ($i = 0; $i < $number; $i ++) {
$system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
}
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Naming/UniqidNamerTest.php b/Tests/Uploader/Naming/UniqidNamerTest.php
index 63567f7..2ff1631 100644
--- a/Tests/Uploader/Naming/UniqidNamerTest.php
+++ b/Tests/Uploader/Naming/UniqidNamerTest.php
@@ -12,36 +12,36 @@ class UniqidNamerTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock()
;
-
+
$file
->expects($this->any())
->method('guessExtension')
->will($this->returnValue('jpeg'))
;
-
+
$namer = new UniqidNamer();
$this->assertRegExp('/[a-z0-9]{13}.jpeg/', $namer->name($file));
}
-
+
public function testNamerReturnsUniqueName()
{
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
->disableOriginalConstructor()
->getMock()
;
-
+
$file
->expects($this->any())
->method('guessExtension')
->will($this->returnValue('jpeg'))
;
-
+
$namer = new UniqidNamer();
-
+
// get two different names
$name1 = $namer->name($file);
$name2 = $namer->name($file);
-
+
$this->assertNotEquals($name1, $name2);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Orphanage/OrphanageManagerTest.php b/Tests/Uploader/Orphanage/OrphanageManagerTest.php
index 2404d37..c81cb88 100644
--- a/Tests/Uploader/Orphanage/OrphanageManagerTest.php
+++ b/Tests/Uploader/Orphanage/OrphanageManagerTest.php
@@ -12,84 +12,81 @@ class OrphanageManagerTest extends \PHPUnit_Framework_TestCase
protected $orphanagePath;
protected $mockContainer;
protected $mockConfig;
-
+
public function setUp()
{
$this->numberOfOrphans = 10;
$this->orphanagePath = sys_get_temp_dir() . '/orphanage';
-
+
$filesystem = new Filesystem();
$filesystem->mkdir($this->orphanagePath);
-
+
// create n orphans with a filemtime in the past
- for($i = 0; $i < $this->numberOfOrphans; $i ++)
- {
+ for ($i = 0; $i < $this->numberOfOrphans; $i ++) {
touch($this->orphanagePath . '/' . uniqid(), time() - 1000);
}
-
+
$this->mockConfig = array(
'maxage' => 100,
'directory' => $this->orphanagePath
);
-
+
$this->mockContainer = $this->getContainerMock();
}
-
+
public function testGetSpecificService()
{
$manager = new OrphanageManager($this->mockContainer, $this->mockConfig);
$service = $manager->get('grumpycat');
-
+
$this->assertTrue($service);
}
-
+
public function testClearAllInPast()
{
// create n orphans with a filemtime in the past
- for($i = 0; $i < $this->numberOfOrphans; $i ++)
- {
+ for ($i = 0; $i < $this->numberOfOrphans; $i ++) {
touch($this->orphanagePath . '/' . uniqid(), time() - 1000);
}
-
+
$manager = new OrphanageManager($this->mockContainer, $this->mockConfig);
$manager->clear();
-
+
$finder = new Finder();
$finder->in($this->orphanagePath)->files();
-
+
$this->assertCount(0, $finder);
}
-
+
public function testClearSomeInPast()
{
// create n orphans with half filetimes in the past and half in the future
// relative to the given threshold
- for($i = 0; $i < $this->numberOfOrphans; $i ++)
- {
+ for ($i = 0; $i < $this->numberOfOrphans; $i ++) {
touch($this->orphanagePath . '/' . uniqid(), time() - $i * 20);
}
-
+
$manager = new OrphanageManager($this->mockContainer, $this->mockConfig);
$manager->clear();
-
+
$finder = new Finder();
$finder->in($this->orphanagePath)->files();
-
+
$this->assertCount($this->numberOfOrphans / 2, $finder);
}
-
+
public function testClearIfDirectoryDoesNotExist()
{
$filesystem = new Filesystem();
$filesystem->remove($this->mockConfig['directory']);
-
+
$manager = new OrphanageManager($this->mockContainer, $this->mockConfig);
$manager->clear();
-
+
// yey, no exception
$this->assertTrue(true);
}
-
+
protected function getContainerMock()
{
$mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
@@ -99,13 +96,13 @@ class OrphanageManagerTest extends \PHPUnit_Framework_TestCase
->with('oneup_uploader.orphanage.grumpycat')
->will($this->returnValue(true))
;
-
+
return $mock;
}
-
+
public function tearDown()
{
$filesystem = new Filesystem();
$filesystem->remove($this->orphanagePath);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Response/EmptyResponseTest.php b/Tests/Uploader/Response/EmptyResponseTest.php
index 82b4f63..6bbef6f 100644
--- a/Tests/Uploader/Response/EmptyResponseTest.php
+++ b/Tests/Uploader/Response/EmptyResponseTest.php
@@ -10,22 +10,22 @@ class TestEmptyResponse extends \PHPUnit_Framework_TestCase
{
$response = new EmptyResponse();
$assembled = $response->assemble();
-
+
$this->assertTrue(is_array($assembled));
$this->assertCount(0, $assembled);
}
-
+
public function testWithItems()
{
$response = new EmptyResponse();
-
+
// fill in some data
$response['cat'] = 'grumpy';
$response['dog'] = 'has no idea';
-
+
$assembled = $response->assemble();
-
+
$this->assertTrue(is_array($assembled));
$this->assertCount(2, $assembled);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Response/FineUploaderResponseTest.php b/Tests/Uploader/Response/FineUploaderResponseTest.php
index 05f3d0a..1190669 100644
--- a/Tests/Uploader/Response/FineUploaderResponseTest.php
+++ b/Tests/Uploader/Response/FineUploaderResponseTest.php
@@ -9,19 +9,19 @@ class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase
public function testCreationOfResponse()
{
$response = new FineUploaderResponse();
-
+
$this->assertTrue($response->getSuccess());
$this->assertNull($response->getError());
}
-
+
public function testFillOfResponse()
{
$response = new FineUploaderResponse();
-
+
$cat = 'is grumpy';
$dog = 'has no idea';
$del = 'nothing here';
-
+
$response['cat'] = $cat;
$response['dog'] = $dog;
$response['del'] = $del;
@@ -30,11 +30,11 @@ class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase
// the next three lines are from code coverage
$this->assertTrue(isset($response['cat']));
$this->assertEquals($response['cat'], $cat);
-
+
unset($response['del']);
-
+
$assembled = $response->assemble();
-
+
$this->assertTrue(is_array($assembled));
$this->assertArrayHasKey('cat', $assembled);
$this->assertArrayHasKey('dog', $assembled);
@@ -43,27 +43,27 @@ class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase
$this->assertFalse($response->getSuccess());
$this->assertNull($response->getError());
}
-
+
public function testError()
{
$response = new FineUploaderResponse();
$response->setError('This response is grumpy');
-
+
$this->assertEquals($response->getError(), 'This response is grumpy');
}
-
+
public function testOverwriteOfInternals()
{
$response = new FineUploaderResponse();
$response['success'] = false;
$response['error'] = 42;
-
+
$this->assertTrue($response->getSuccess());
$this->assertNull($response->getError());
-
+
$assembled = $response->assemble();
-
+
$this->assertTrue($assembled['success']);
$this->assertArrayNotHasKey('error', $assembled);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Response/MooUploadResponseTest.php b/Tests/Uploader/Response/MooUploadResponseTest.php
index ba28199..41295bb 100644
--- a/Tests/Uploader/Response/MooUploadResponseTest.php
+++ b/Tests/Uploader/Response/MooUploadResponseTest.php
@@ -9,11 +9,11 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
public function testCreationOfResponse()
{
$response = new MooUploadResponse();
-
+
$this->assertTrue($response->getFinish());
$this->assertEquals(0, $response->getError());
}
-
+
public function testFunctionsOfResponse()
{
$response = new MooUploadResponse();
@@ -23,7 +23,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$response->setError(-1);
$response->setFinish(true);
$response->setUploadedName('b1/2d/b12d23.jpg');
-
+
$this->assertEquals(3, $response->getId());
$this->assertEquals('grumpy_cat.jpg', $response->getName());
$this->assertEquals(15093, $response->getSize());
@@ -31,7 +31,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(true, $response->getFinish());
$this->assertEquals('b1/2d/b12d23.jpg', $response->getUploadedName());
}
-
+
public function testFunctionsAfterOverwrite()
{
$response = new MooUploadResponse();
@@ -41,7 +41,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$response->setError(-1);
$response->setFinish(true);
$response->setUploadedName('b1/2d/b12d23.jpg');
-
+
$response['id'] = null;
$response['name'] = null;
$response['size'] = null;
@@ -49,7 +49,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$response['finish'] = null;
$response['uploadedName'] = null;
$response['princess'] = !null;
-
+
$this->assertEquals(3, $response->getId());
$this->assertEquals('grumpy_cat.jpg', $response->getName());
$this->assertEquals(15093, $response->getSize());
@@ -58,7 +58,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('b1/2d/b12d23.jpg', $response->getUploadedName());
$this->assertEquals(!null, $response['princess']);
}
-
+
public function testAssemble()
{
@@ -69,7 +69,7 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$response->setError(-1);
$response->setFinish(true);
$response->setUploadedName('b1/2d/b12d23.jpg');
-
+
$response['id'] = null;
$response['name'] = null;
$response['size'] = null;
@@ -78,9 +78,9 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase
$response['uploadedName'] = null;
$response['upload_name'] = null;
$response['princess'] = !null;
-
+
$data = $response->assemble();
-
+
$this->assertEquals(3, $data['id']);
$this->assertEquals('grumpy_cat.jpg', $data['name']);
$this->assertEquals(15093, $data['size']);
diff --git a/Tests/Uploader/Storage/FilesystemStorageTest.php b/Tests/Uploader/Storage/FilesystemStorageTest.php
index 7560a79..6f3e011 100644
--- a/Tests/Uploader/Storage/FilesystemStorageTest.php
+++ b/Tests/Uploader/Storage/FilesystemStorageTest.php
@@ -11,40 +11,39 @@ class FilesystemStorageTest extends \PHPUnit_Framework_TestCase
{
protected $directory;
protected $file;
-
+
public function setUp()
{
$this->directory = sys_get_temp_dir() . '/storage';
// create temporary file
$this->file = tempnam(sys_get_temp_dir(), 'uploader');
-
+
$pointer = fopen($this->file, 'w+');
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
}
-
+
public function testUpload()
{
$payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true);
$storage = new FilesystemStorage($this->directory);
$storage->upload($payload, 'notsogrumpyanymore.jpeg');
-
+
$finder = new Finder();
$finder->in($this->directory)->files();
-
+
$this->assertCount(1, $finder);
-
- foreach($finder as $file)
- {
+
+ foreach ($finder as $file) {
$this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg');
$this->assertEquals($file->getSize(), 1024);
}
}
-
+
public function tearDown()
{
$filesystem = new Filesystem();
$filesystem->remove($this->directory);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
index cfcf85d..e915501 100644
--- a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
@@ -13,7 +13,7 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase
{
protected $directory;
protected $storage;
-
+
public function setUp()
{
if(
@@ -26,24 +26,24 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase
$this->prefix = 'someObscureStorage';
$this->directory = sys_get_temp_dir() .'/'. $this->prefix;
- if(!file_exists($this->directory)) {
+ if (!file_exists($this->directory)) {
mkdir($this->directory);
}
// create temporary file
$this->file = tempnam($this->directory, 'uploader');
-
+
$pointer = fopen($this->file, 'w+');
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
-
+
$service = new AmazonClient(array(
'key' => getenv('AWS_ACCESS_KEY_ID'),
'secret' => getenv('AWS_SECRET_ACCESS_KEY'),
));
$adapter = new S3Adapter($service, getenv('AWS_BUCKET'));
$this->filesystem = new GaufretteFilesystem($adapter);
-
+
$this->storage = new GaufretteStorage($this->filesystem);
}
@@ -51,15 +51,14 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase
{
$payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true);
$this->storage->upload($payload, $this->prefix .'/notsogrumpyanymore.jpeg');
-
+
$files = $this->filesystem->listKeys($this->prefix);
-
+
// on Amazon S3, if it exists, it is considered a directory
$this->assertCount(2, $files['keys']);
-
- foreach($files['keys'] as $filename)
- {
- if($filename === $this->prefix) {
+
+ foreach ($files['keys'] as $filename) {
+ if ($filename === $this->prefix) {
// ignore the prefix directory
continue;
}
@@ -67,13 +66,12 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(1024, strlen($this->filesystem->read($filename)));
}
}
-
+
public function tearDown()
{
$files = $this->filesystem->listKeys($this->prefix);
- foreach($files['keys'] as $filename)
- {
- if($this->filesystem->has($filename)) {
+ foreach ($files['keys'] as $filename) {
+ if ($this->filesystem->has($filename)) {
$this->filesystem->delete($filename);
}
}
diff --git a/Tests/Uploader/Storage/GaufretteStorageTest.php b/Tests/Uploader/Storage/GaufretteStorageTest.php
index 054d71c..d2656ee 100644
--- a/Tests/Uploader/Storage/GaufretteStorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteStorageTest.php
@@ -13,21 +13,21 @@ class GaufretteStorageTest extends \PHPUnit_Framework_TestCase
{
protected $directory;
protected $storage;
-
+
public function setUp()
{
$this->directory = sys_get_temp_dir() . '/storage';
// create temporary file
$this->file = tempnam(sys_get_temp_dir(), 'uploader');
-
+
$pointer = fopen($this->file, 'w+');
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
-
+
$adapter = new Adapter($this->directory, true);
$filesystem = new GaufretteFilesystem($adapter);
-
+
$this->storage = new GaufretteStorage($filesystem);
}
@@ -35,22 +35,21 @@ class GaufretteStorageTest extends \PHPUnit_Framework_TestCase
{
$payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true);
$this->storage->upload($payload, 'notsogrumpyanymore.jpeg');
-
+
$finder = new Finder();
$finder->in($this->directory)->files();
-
+
$this->assertCount(1, $finder);
-
- foreach($finder as $file)
- {
+
+ foreach ($finder as $file) {
$this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg');
$this->assertEquals($file->getSize(), 1024);
}
}
-
+
public function tearDown()
{
$filesystem = new Filesystem();
$filesystem->remove($this->directory);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Uploader/Storage/OrphanageStorageTest.php b/Tests/Uploader/Storage/OrphanageStorageTest.php
index 070c677..3ca429a 100644
--- a/Tests/Uploader/Storage/OrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/OrphanageStorageTest.php
@@ -19,102 +19,99 @@ class OrphanageStorageTest extends \PHPUnit_Framework_TestCase
protected $storage;
protected $payloads;
protected $numberOfPayloads;
-
+
public function setUp()
{
$this->numberOfPayloads = 5;
$this->tempDirectory = sys_get_temp_dir() . '/orphanage';
$this->realDirectory = sys_get_temp_dir() . '/storage';
$this->payloads = array();
-
+
$filesystem = new Filesystem();
$filesystem->mkdir($this->tempDirectory);
$filesystem->mkdir($this->realDirectory);
-
- for($i = 0; $i < $this->numberOfPayloads; $i ++)
- {
+
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
// create temporary file
$file = tempnam(sys_get_temp_dir(), 'uploader');
-
+
$pointer = fopen($file, 'w+');
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
-
+
$this->payloads[] = new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true);
}
-
+
// create underlying storage
$this->storage = new FilesystemStorage($this->realDirectory);
-
+
// create orphanage
$session = new Session(new MockArraySessionStorage());
$session->start();
-
+
$config = array('directory' => $this->tempDirectory);
-
+
$this->orphanage = new OrphanageStorage($this->storage, $session, $config, 'cat');
}
-
+
public function testUpload()
{
- for($i = 0; $i < $this->numberOfPayloads; $i ++)
- {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
$this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
}
-
+
$finder = new Finder();
$finder->in($this->tempDirectory)->files();
$this->assertCount($this->numberOfPayloads, $finder);
-
+
$finder = new Finder();
$finder->in($this->realDirectory)->files();
$this->assertCount(0, $finder);
}
-
+
public function testUploadAndFetching()
{
- for($i = 0; $i < $this->numberOfPayloads; $i ++)
- {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
$this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
}
-
+
$finder = new Finder();
$finder->in($this->tempDirectory)->files();
$this->assertCount($this->numberOfPayloads, $finder);
-
+
$finder = new Finder();
$finder->in($this->realDirectory)->files();
$this->assertCount(0, $finder);
-
+
$files = $this->orphanage->uploadFiles();
-
+
$this->assertTrue(is_array($files));
$this->assertCount($this->numberOfPayloads, $files);
-
+
$finder = new Finder();
$finder->in($this->tempDirectory)->files();
$this->assertCount(0, $finder);
-
+
$finder = new Finder();
$finder->in($this->realDirectory)->files();
$this->assertCount($this->numberOfPayloads, $finder);
}
-
+
public function testUploadAndFetchingIfDirectoryDoesNotExist()
{
$filesystem = new Filesystem();
$filesystem->remove($this->tempDirectory);
-
+
$files = $this->orphanage->uploadFiles();
-
+
$this->assertTrue(is_array($files));
$this->assertCount(0, $files);
}
-
+
public function tearDown()
{
$filesystem = new Filesystem();
$filesystem->remove($this->tempDirectory);
$filesystem->remove($this->realDirectory);
}
-}
\ No newline at end of file
+}
diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php
index 5b67409..f04fc53 100644
--- a/Tests/bootstrap.php
+++ b/Tests/bootstrap.php
@@ -17,6 +17,7 @@ spl_autoload_register(function($class) {
return false;
}
require_once $path;
+
return true;
}
});
| 0 |
5904a41f3ff36e5c31753413da7dac507e236439
|
1up-lab/OneupUploaderBundle
|
- added USE statement;
|
commit 5904a41f3ff36e5c31753413da7dac507e236439
Author: Paulo Ribeiro <[email protected]>
Date: Wed Mar 26 11:45:29 2014 -0300
- added USE statement;
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 68c51b6..73fc147 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -5,6 +5,7 @@ namespace Oneup\UploaderBundle\Uploader\File;
use Gaufrette\Adapter\StreamFactory;
use Gaufrette\File;
use Gaufrette\Filesystem;
+use \Gaufrette\Adapter\AwsS3;
class GaufretteFile extends File implements FileInterface
{
@@ -79,7 +80,7 @@ class GaufretteFile extends File implements FileInterface
$this->mimeType = finfo_file($finfo, $this->streamWrapperPrefix.$this->getKey());
finfo_close($finfo);
}
- } elseif ($this->filesystem->getAdapter() instanceof \Gaufrette\Adapter\AwsS3 && !$this->mimeType) {
+ } elseif ($this->filesystem->getAdapter() instanceof AwsS3 && !$this->mimeType) {
$metadata = $this->filesystem->getAdapter()->getMetadata($this->getBasename());
if (isset($metadata['ContentType'])) {
$this->mimeType = $metadata['ContentType'];
| 0 |
0ccb23e3049c161b01fcc4c9c02939e4c8b011e4
|
1up-lab/OneupUploaderBundle
|
Fixed a markdown bug.
|
commit 0ccb23e3049c161b01fcc4c9c02939e4c8b011e4
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 17:18:28 2013 +0200
Fixed a markdown bug.
diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md
index 786e7a6..6c4a845 100644
--- a/Resources/doc/custom_uploader.md
+++ b/Resources/doc/custom_uploader.md
@@ -122,6 +122,7 @@ class FineUploaderResponse extends AbstractResponse
// ... snip, setters/getters
}
+```
## Notes
| 0 |
9c0a05d595aa5675e75b58972891d35b542ad9cb
|
1up-lab/OneupUploaderBundle
|
Documented the Session upload progress feature.
|
commit 9c0a05d595aa5675e75b58972891d35b542ad9cb
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 17:12:58 2013 +0200
Documented the Session upload progress feature.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 7e5a2ce..d5b5721 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -122,6 +122,7 @@ some more advanced features.
* [Support a custom uploader](custom_uploader.md)
* [Validate your uploads](custom_validator.md)
* [General/Generic Events](events.md)
+* [Enable Session upload progress / upload cancelation](progress.md)
* [Configuration Reference](configuration_reference.md)
## FAQ
diff --git a/Resources/doc/progress.md b/Resources/doc/progress.md
new file mode 100644
index 0000000..f3a6833
--- /dev/null
+++ b/Resources/doc/progress.md
@@ -0,0 +1,88 @@
+Enable Session Upload Progress
+==============================
+
+As of PHP 5.4, there is the possibility to track the upload progress of individual files being uploaded.
+To enable this feature be sure you enable it in your configuration.
+
+```yaml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ enable_progress: true
+```
+
+The OneupUploaderBundle generates a new route for you to probe the status of a file currently being uploaded.
+Once again, there are frontend helpers to simplify this process:
+
+* `{{ oneup_uploader_progress('gallery') }}` This helper will return the path where you can send your progress request to.
+* `{{ oneup_uploader_upload_key() }}` This helper will return the ini option `session.upload_progress.name`.
+
+An example of this feature using the jQuery File Upload plugin can be found in the [corresponding wiki article](https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-Session-Upload-Progress):
+
+```js
+$('#fileupload').bind('fileuploadsend', function (e, data) {
+ if (data.dataType.substr(0, 6) === 'iframe') {
+ var progressObj = {
+ name: '{{ oneup_uploader_upload_key() }}',
+ value: (new Date()).getTime() // pseudo unique ID
+ };
+
+ data.formData.push(progressObj);
+ data.context.data('interval', setInterval(function () {
+ $.get('{{ oneup_uploader_progress("gallery") }}', $.param([progressObj]), function (result) {
+ e = $.Event( 'progress', {bubbles: false, cancelable: true});
+ $.extend(e, result);
+ ($('#fileupload').data('blueimp-fileupload') ||
+ $('#fileupload').data('fileupload'))._onProgress(e, data);
+ }, 'json');
+ }, 1000));
+ }
+}).bind('fileuploadalways', function (e, data) {
+ clearInterval(data.context.data('interval'));
+});
+```
+
+Be sure to initially send the key/value in your upload request for this to work. Or to quote the [PHP-Manual](http://php.net/manual/en/session.upload-progress.php):
+
+> The upload progress will be available in the $_SESSION superglobal when an upload is in progress, and when POSTing a variable of the same name as the session.upload_progress.name INI setting is set to.
+
+
+Enable Cancelation Route
+------------------------
+
+The new API also comes with a handy new feature to cancel uploads currently in process.
+To activate the corresponding route, simply enable it in your configuration file.
+
+```yaml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ enable_cancelation: true
+```
+
+If enabled, you can use the frontend helper function to get the correct route:
+
+```twig
+{{ oneup_uploader_cancel('gallery') }}
+```
+
+You still need to send the correct value for the `oneup_uploader_upload_key`.
+
+Caveats
+-------
+
+You'll need an activated session for this feature to work correctly. Be sure to enable the session for anonymous users, if you provide anonymous uploads:
+
+```yml
+# app/config/security.yml
+
+security:
+ firewalls:
+ main:
+ pattern: ^/
+ anonymous: true
+```
| 0 |
4aa51a6cdff71d609eeba27c163183abf3b4a0e3
|
1up-lab/OneupUploaderBundle
|
Add security configuration for tests
|
commit 4aa51a6cdff71d609eeba27c163183abf3b4a0e3
Author: David Greminger <[email protected]>
Date: Tue Jun 5 10:46:38 2018 +0200
Add security configuration for tests
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 1db4696..dd084cd 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -10,6 +10,16 @@ framework:
session: ~
test: ~
+security:
+ providers:
+ in_memory: { memory: ~ }
+ firewalls:
+ dev:
+ pattern: ^/(_(profiler|wdt)|css|images|js)/
+ security: false
+ main:
+ anonymous: ~
+
oneup_uploader:
mappings:
| 0 |
434a8ed071188a115f79f65031e0a9cfed02e751
|
1up-lab/OneupUploaderBundle
|
Refreshed the configuration reference in documentation.
|
commit 434a8ed071188a115f79f65031e0a9cfed02e751
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 17:43:36 2013 +0200
Refreshed the configuration reference in documentation.
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index bea28a9..144c091 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -31,5 +31,7 @@ oneup_uploader:
disallowed_mimetypes: []
max_size: 9223372036854775807
use_orphanage: false
+ enable_progress: false
+ enable_cancelation: false
namer: oneup_uploader.namer.uniqid
```
| 0 |
0142800a2198d1e762ed2947975be2f16eb5c2e1
|
1up-lab/OneupUploaderBundle
|
Fix for #237
|
commit 0142800a2198d1e762ed2947975be2f16eb5c2e1
Author: Devi Prasad <[email protected]>
Date: Wed May 4 15:10:25 2016 +0530
Fix for #237
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index c577309..2aa007b 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -82,6 +82,6 @@ See the [Use Chunked Uploads behind Load Balancers](load_balancers.md) section i
The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle.
- $> php app/console oneup:uploader:clean-chunks
+ $> php app/console oneup:uploader:clear-chunks
This parameter will clean all chunk files older than the `maxage` value in your configuration.
| 0 |
60dde96237e7be4481eec44f1230c0a245914748
|
1up-lab/OneupUploaderBundle
|
forgot the config parameters
|
commit 60dde96237e7be4481eec44f1230c0a245914748
Author: Martin Aarhof <[email protected]>
Date: Tue Jan 19 15:09:09 2016 +0100
forgot the config parameters
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index c970994..13d8f30 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -6,10 +6,12 @@
<parameters>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.chunks_storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.chunks_storage.flysystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage</parameter>
<parameter key="oneup_uploader.chunks_storage.filesystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.storage.flysystem.class">Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage</parameter>
<parameter key="oneup_uploader.storage.filesystem.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemOrphanageStorage</parameter>
<parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter>
| 0 |
f3871241d648434f39310e95fcf1e442b28280a7
|
1up-lab/OneupUploaderBundle
|
Fixed the two bundled commands for clearing chunks and orphans.
|
commit f3871241d648434f39310e95fcf1e442b28280a7
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:26:06 2013 +0200
Fixed the two bundled commands for clearing chunks and orphans.
diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php
index 50bca9f..f1df091 100644
--- a/Command/ClearChunkCommand.php
+++ b/Command/ClearChunkCommand.php
@@ -18,7 +18,7 @@ class ClearChunkCommand extends ContainerAwareCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
- $manager = $this->getContainer()->get('oneup_uploader.chunks.manager');
+ $manager = $this->getContainer()->get('oneup_uploader.chunk_manager');
$manager->clear();
}
}
\ No newline at end of file
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 50b11cf..dc1e83c 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -102,7 +102,7 @@ class UploaderController implements UploadControllerInterface
// we'll take the first chunk and append the others to it
// this way we don't need another file in temporary space for assembling
$chunks = $chunkManager->getChunks($uuid);
-
+ die();
// assemble parts
$assembled = $chunkManager->assembleChunks($chunks);
$path = $assembled->getPath();
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index c252a84..0f9d511 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -23,6 +23,7 @@
<service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%">
<argument type="service" id="service_container" />
+ <argument>%oneup_uploader.orphanage%</argument>
</service>
<!-- namer -->
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 90c48ef..b35f5f9 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -29,7 +29,7 @@ class ChunkManager implements ChunkManagerInterface
try
{
- $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
+ $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds')->files();
}
catch(\InvalidArgumentException $e)
{
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index 9381aa6..053200f 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -2,17 +2,46 @@
namespace Oneup\UploaderBundle\Uploader\Orphanage;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrphanageManager
{
- public function __construct(ContainerInterface $container)
+ protected $config;
+ protected $container;
+
+ public function __construct(ContainerInterface $container, array $config)
{
$this->container = $container;
+ $this->config = $config;
}
public function get($key)
{
return $this->container->get(sprintf('oneup_uploader.orphanage.%s', $key));
}
+
+ public function clear()
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ try
+ {
+ $finder->in($this->config['directory'])->date('<=' . -1 * (int) $this->config['maxage'] . 'seconds')->files();
+ }
+ catch(\InvalidArgumentException $e)
+ {
+ // the finder will throw an exception of type InvalidArgumentException
+ // if the directory he should search in does not exist
+ // in that case we don't have anything to clean
+ return;
+ }
+
+ foreach($finder as $file)
+ {
+ $system->remove($file);
+ }
+ }
}
\ No newline at end of file
| 0 |
76bfb5d660c7c2c2162afa877c1c8993319bb7b5
|
1up-lab/OneupUploaderBundle
|
Integrated the correct link to the index.md of documentation in readme.
|
commit 76bfb5d660c7c2c2162afa877c1c8993319bb7b5
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 13:05:49 2013 +0200
Integrated the correct link to the index.md of documentation in readme.
diff --git a/README.md b/README.md
index d674be8..79d7905 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Documentation
The entry point of the documentation can be found in the file `Resources/docs/index.md`
-[Read the documentation for master](...)
+[Read the documentation for master](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md)
License
-------
diff --git a/Resources/docs/index.md b/Resources/doc/index.md
similarity index 100%
rename from Resources/docs/index.md
rename to Resources/doc/index.md
| 0 |
eac95c5cce541aa95cf549ea8d8e3be0009a9e58
|
1up-lab/OneupUploaderBundle
|
Update configuration_reference.md
|
commit eac95c5cce541aa95cf549ea8d8e3be0009a9e58
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 09:42:14 2013 +0300
Update configuration_reference.md
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index 18a156e..65cf43c 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -1,7 +1,7 @@
Configuration Reference
=======================
-All available configuration options are listed below with their default values.
+All available configuration options along with their default values are listed below.
``` yaml
oneup_uploader:
@@ -25,4 +25,4 @@ oneup_uploader:
max_size: 9223372036854775807
use_orphanage: false
namer: oneup_uploader.namer.uniqid
-```
\ No newline at end of file
+```
| 0 |
1a071d8ce8a04d8b9f2adfb0cf2b0dab4a979a24
|
1up-lab/OneupUploaderBundle
|
Added a progress method to AbstractController.
|
commit 1a071d8ce8a04d8b9f2adfb0cf2b0dab4a979a24
Author: Jim Schmid <[email protected]>
Date: Mon Jun 24 20:47:41 2013 +0200
Added a progress method to AbstractController.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index ab4db65..68fa7b4 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Controller;
+use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -33,6 +34,22 @@ abstract class AbstractController
abstract public function upload();
+ public function progress()
+ {
+ $request = $this->container->get('request');
+ $session = $this->container->get('session');
+
+ $prefix = ini_get('session.upload_progress.prefix');
+ $name = ini_get('session.upload_progress.name');
+
+ // assemble session key
+ // ref: http://php.net/manual/en/session.upload-progress.php
+ $key = sprintf('%s.%s', $prefix, $name);
+ $value = $session->get($key);
+
+ return new JsonResponse($value);
+ }
+
/**
* This internal function handles the actual upload process
* and will most likely be called from the upload()
| 0 |
324d398a3eafa4f9cbeacc187a0a86d7bd18ca4a
|
1up-lab/OneupUploaderBundle
|
Added flysystem to also be a possible filesystem
|
commit 324d398a3eafa4f9cbeacc187a0a86d7bd18ca4a
Author: Martin Aarhof <[email protected]>
Date: Tue Jan 19 14:27:42 2016 +0100
Added flysystem to also be a possible filesystem
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 3374889..276ddf3 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -22,7 +22,7 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->enumNode('type')
- ->values(array('filesystem', 'gaufrette'))
+ ->values(array('filesystem', 'gaufrette', 'flysystem'))
->defaultValue('filesystem')
->end()
->scalarNode('filesystem')->defaultNull()->end()
@@ -65,7 +65,7 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('service')->defaultNull()->end()
->enumNode('type')
- ->values(array('filesystem', 'gaufrette'))
+ ->values(array('filesystem', 'gaufrette', 'flysystem'))
->defaultValue('filesystem')
->end()
->scalarNode('filesystem')->defaultNull()->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 7f35224..4a471c5 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -13,6 +13,10 @@ use Symfony\Component\DependencyInjection\Loader;
class OneupUploaderExtension extends Extension
{
protected $storageServices = array();
+
+ /**
+ * @var ContainerBuilder
+ */
protected $container;
protected $config;
@@ -141,31 +145,44 @@ class OneupUploaderExtension extends Extension
$config = &$this->config['chunks']['storage'];
$storageClass = sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']);
- if ($config['type'] === 'filesystem') {
- $config['directory'] = is_null($config['directory']) ?
- sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) :
- $this->normalizePath($config['directory'])
- ;
-
- $this->container
- ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']))
- ->addArgument($config['directory'])
- ;
- } else {
- $this->registerGaufretteStorage(
- 'oneup_uploader.chunks_storage',
- $storageClass, $config['filesystem'],
- $config['sync_buffer_size'],
- $config['stream_wrapper'],
- $config['prefix']
- );
-
- $this->container->setParameter('oneup_uploader.orphanage.class', 'Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage');
-
- // enforce load distribution when using gaufrette as chunk
- // torage to avoid moving files forth-and-back
- $this->config['chunks']['load_distribution'] = true;
+
+ switch($config['type']) {
+ case 'filesystem':
+ $config['directory'] = is_null($config['directory']) ?
+ sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) :
+ $this->normalizePath($config['directory'])
+ ;
+
+ $this->container
+ ->register('oneup_uploader.chunks_storage', sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']))
+ ->addArgument($config['directory'])
+ ;
+ break;
+ case 'gaufrette':
+ case 'flysystem':
+ $this->registerFilesystem(
+ $config['type'],
+ 'oneup_uploader.chunks_storage',
+ $storageClass, $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper'],
+ $config['prefix']
+ );
+
+ $this->container->setParameter(
+ 'oneup_uploader.orphanage.class',
+ sprintf('Oneup\UploaderBundle\Uploader\Storage\%sOrphanageStorage', ucfirst($config['type']))
+ );
+
+ // enforce load distribution when using gaufrette as chunk
+ // torage to avoid moving files forth-and-back
+ $this->config['chunks']['load_distribution'] = true;
+ break;
+ default:
+ throw new \InvalidArgumentException(sprintf('Filesystem "%s" is invalid', $config['type']));
+ break;
}
+
}
protected function createStorageService(&$config, $key, $orphanage = false)
@@ -181,26 +198,31 @@ class OneupUploaderExtension extends Extension
$storageName = sprintf('oneup_uploader.storage.%s', $key);
$storageClass = sprintf('%%oneup_uploader.storage.%s.class%%', $config['type']);
- if ($config['type'] == 'filesystem') {
- $config['directory'] = is_null($config['directory']) ?
- sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
- $this->normalizePath($config['directory'])
- ;
-
- $this->container
- ->register($storageName, $storageClass)
- ->addArgument($config['directory'])
- ;
- }
-
- if ($config['type'] == 'gaufrette') {
- $this->registerGaufretteStorage(
- $storageName,
- $storageClass,
- $config['filesystem'],
- $config['sync_buffer_size'],
- $config['stream_wrapper']
- );
+ switch ($config['type']) {
+ case 'filesystem':
+ $config['directory'] = is_null($config['directory']) ?
+ sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
+ $this->normalizePath($config['directory'])
+ ;
+
+ $this->container
+ ->register($storageName, $storageClass)
+ ->addArgument($config['directory'])
+ ;
+ break;
+ case 'gaufrette':
+ case 'flysystem':
+ $this->registerFilesystem(
+ $config['type'],
+ $storageName,
+ $storageClass,
+ $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper']
+ );
+ break;
+ default:
+ break;
}
$storageService = new Reference($storageName);
@@ -227,12 +249,22 @@ class OneupUploaderExtension extends Extension
return $storageService;
}
- protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '')
+ protected function registerFilesystem($type, $key, $class, $filesystem, $buffer, $streamWrapper = null, $prefix = '')
{
- if(!class_exists('Gaufrette\\Filesystem'))
- throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a chunk storage service.');
+ switch ($type) {
+ case 'gaufrette':
+ if (!class_exists('Gaufrette\\Filesystem')) {
+ throw new InvalidArgumentException('You have to install knplabs/knp-gaufrette-bundle in order to use it as a chunk storage service.');
+ }
+ break;
+ case 'flysystem':
+ if (!class_exists('League\\Flysystem\\Filesystem')) {
+ throw new InvalidArgumentException('You have to install oneup/flysystem-bundle in order to use it as a chunk storage service.');
+ }
+ break;
+ }
- if(strlen($filesystem) <= 0)
+ if (strlen($filesystem) <= 0)
throw new ServiceNotFoundException('Empty service name');
$streamWrapper = $this->normalizeStreamWrapper($streamWrapper);
@@ -242,8 +274,7 @@ class OneupUploaderExtension extends Extension
->addArgument(new Reference($filesystem))
->addArgument($this->getValueInBytes($buffer))
->addArgument($streamWrapper)
- ->addArgument($prefix)
- ;
+ ->addArgument($prefix);
}
protected function getMaxUploadSize($input)
diff --git a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
new file mode 100644
index 0000000..a277d7e
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use League\Flysystem\File;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
+
+use League\Flysystem\Adapter\Local as Adapter;
+use League\Flysystem\Filesystem as FSAdapter;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage;
+
+class FlysystemOrphanageStorageTest extends OrphanageTest
+{
+ protected $chunkDirectory;
+ protected $chunksKey = 'chunks';
+ protected $orphanageKey = 'orphanage';
+
+ public function setUp()
+ {
+ $this->numberOfPayloads = 5;
+ $this->realDirectory = sys_get_temp_dir() . '/storage';
+ $this->chunkDirectory = $this->realDirectory .'/' . $this->chunksKey;
+ $this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
+ $this->payloads = array();
+
+ if (!$this->checkIfTempnameMatchesAfterCreation()) {
+ $this->markTestSkipped('Temporary directories do not match');
+ }
+
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->realDirectory);
+ $filesystem->mkdir($this->chunkDirectory);
+ $filesystem->mkdir($this->tempDirectory);
+
+ $adapter = new Adapter($this->realDirectory, true);
+ $filesystem = new FSAdapter($adapter);
+
+ $this->storage = new Storage($filesystem, 100000);
+
+ $chunkStorage = new ChunkStorage($filesystem, 100000, null, 'chunks');
+
+ // create orphanage
+ $session = new Session(new MockArraySessionStorage());
+ $session->start();
+
+ $config = array('directory' => 'orphanage');
+
+ $this->orphanage = new FlysystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
+
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ // create temporary file as if it was reassembled by the chunk manager
+ $file = tempnam($this->chunkDirectory, 'uploader');
+
+ $pointer = fopen($file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ //gaufrette needs the key relative to it's root
+ $fileKey = str_replace($this->realDirectory, '', $file);
+
+ $this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem);
+ }
+ }
+
+ public function testUpload()
+ {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
+ }
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+
+ $finder = new Finder();
+ // exclude the orphanage and the chunks
+ $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files();
+ $this->assertCount(0, $finder);
+ }
+
+ public function testUploadAndFetching()
+ {
+ for ($i = 0; $i < $this->numberOfPayloads; $i ++) {
+ $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
+ }
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+
+ $finder = new Finder();
+ $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files();
+ $this->assertCount(0, $finder);
+
+ $files = $this->orphanage->uploadFiles();
+
+ $this->assertTrue(is_array($files));
+ $this->assertCount($this->numberOfPayloads, $files);
+
+ $finder = new Finder();
+ $finder->in($this->tempDirectory)->files();
+ $this->assertCount(0, $finder);
+
+ $finder = new Finder();
+ $finder->in($this->realDirectory)->files();
+ $this->assertCount($this->numberOfPayloads, $finder);
+ }
+
+ public function checkIfTempnameMatchesAfterCreation()
+ {
+ return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ }
+}
diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php
new file mode 100644
index 0000000..bdd43e9
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemStorageTest.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use League\Flysystem\Adapter\Local as Adapter;
+use League\Flysystem\Filesystem as FSAdapter;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FlysystemStorageTest extends \PHPUnit_Framework_TestCase
+{
+ protected $directory;
+
+ /**
+ * @var Storage
+ */
+ protected $storage;
+ protected $file;
+
+ public function setUp()
+ {
+ $this->directory = sys_get_temp_dir() . '/storage';
+
+ // create temporary file
+ $this->file = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($this->file, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ $adapter = new Adapter($this->directory, true);
+ $filesystem = new FSAdapter($adapter);
+
+ $this->storage = new Storage($filesystem, 100000);
+ }
+
+ public function testUpload()
+ {
+ $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true));
+ $this->storage->upload($payload, 'notsogrumpyanymore.jpeg');
+
+ $finder = new Finder();
+ $finder->in($this->directory)->files();
+
+ $this->assertCount(1, $finder);
+
+ foreach ($finder as $file) {
+ $this->assertEquals($file->getFilename(), 'notsogrumpyanymore.jpeg');
+ $this->assertEquals($file->getSize(), 1024);
+ }
+ }
+
+ public function tearDown()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->directory);
+ }
+}
diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php
index 836ab86..ce3f6cd 100644
--- a/Tests/Uploader/Storage/OrphanageTest.php
+++ b/Tests/Uploader/Storage/OrphanageTest.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
@@ -9,6 +10,10 @@ abstract class OrphanageTest extends \PHPUnit_Framework_Testcase
{
protected $tempDirectory;
protected $realDirectory;
+
+ /**
+ * @var \Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface
+ */
protected $orphanage;
protected $storage;
protected $payloads;
diff --git a/Uploader/Chunk/Storage/FlysystemStorage.php b/Uploader/Chunk/Storage/FlysystemStorage.php
new file mode 100644
index 0000000..19e7a44
--- /dev/null
+++ b/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -0,0 +1,152 @@
+<?php
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
+
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use League\Flysystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FlysystemStorage implements ChunkStorageInterface
+{
+
+ protected $unhandledChunk;
+ protected $prefix;
+ protected $streamWrapperPrefix;
+
+ /**
+ * @var Filesystem
+ */
+ private $filesystem;
+
+ public $bufferSize;
+
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
+ {
+ if (
+ ! method_exists($filesystem, 'readStream')
+ ||
+ ! method_exists($filesystem, 'putStream')
+ ) {
+ throw new \InvalidArgumentException('The filesystem used as chunk storage must streamable');
+ }
+
+ $this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
+ $this->prefix = $prefix;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ public function clear($maxAge, $prefix = null)
+ {
+ $prefix = $prefix ? :$this->prefix;
+ $matches = $this->filesystem->listFiles($prefix);
+
+ $now = time();
+ $toDelete = array();
+
+ // Collect the directories that are old,
+ // this also means the files inside are old
+ // but after the files are deleted the dirs
+ // would remain
+ foreach ($matches['dirs'] as $key) {
+ if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) {
+ $toDelete[] = $key;
+ }
+ }
+ // The same directory is returned for every file it contains
+ array_unique($toDelete);
+ foreach ($matches['keys'] as $key) {
+ if ($maxAge <= $now-$this->filesystem->getTimestamp($key)) {
+ $this->filesystem->delete($key);
+ }
+ }
+
+ foreach ($toDelete as $key) {
+ // The filesystem will throw exceptions if
+ // a directory is not empty
+ try {
+ $this->filesystem->delete($key);
+ } catch (\Exception $e) {
+ continue;
+ }
+ }
+ }
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $this->unhandledChunk = array(
+ 'uuid' => $uuid,
+ 'index' => $index,
+ 'chunk' => $chunk,
+ 'original' => $original
+ );
+ }
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk)
+ {
+ // the index is only added to be in sync with the filesystem storage
+ $path = $this->prefix.'/'.$this->unhandledChunk['uuid'].'/';
+ $filename = $this->unhandledChunk['index'].'_'.$this->unhandledChunk['original'];
+
+ if (empty($chunks)) {
+ $target = $filename;
+ } else {
+ sort($chunks, SORT_STRING | SORT_FLAG_CASE);
+ $target = pathinfo($chunks[0], PATHINFO_BASENAME);
+ }
+
+
+ if ($this->unhandledChunk['index'] === 0) {
+ // if it's the first chunk overwrite the already existing part
+ // to avoid appending to earlier failed uploads
+ $handle = fopen($path . '/' . $target, 'w');
+ } else {
+ $handle = fopen($path . '/' . $target, 'a');
+ }
+
+ $this->filesystem->putStream($path . $target, $handle);
+ if ($renameChunk) {
+ $name = preg_replace('/^(\d+)_/', '', $target);
+ /* The name can only match if the same user in the same session is
+ * trying to upload a file under the same name AND the previous upload failed,
+ * somewhere between this function, and the cleanup call. If that happened
+ * the previous file is unaccessible by the user, but if it is not removed
+ * it will block the user from trying to re-upload it.
+ */
+ if ($this->filesystem->has($path.$name)) {
+ $this->filesystem->delete($path.$name);
+ }
+
+ $this->filesystem->rename($path.$target, $path.$name);
+ $target = $name;
+ }
+ $uploaded = $this->filesystem->get($path.$target);
+
+ if (!$renameChunk) {
+ return $uploaded;
+ }
+
+ return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+ public function cleanup($path)
+ {
+ $this->filesystem->delete($path);
+ }
+
+ public function getChunks($uuid)
+ {
+ $results = $this->filesystem->listFiles($this->prefix.'/'.$uuid);
+ return preg_grep('/^.+\/(\d+)_/', $results['keys']);
+ }
+
+ public function getFilesystem()
+ {
+ return $this->filesystem;
+ }
+
+ public function getStreamWrapperPrefix()
+ {
+ return $this->streamWrapperPrefix;
+ }
+
+}
diff --git a/Uploader/File/FlysystemFile.php b/Uploader/File/FlysystemFile.php
new file mode 100644
index 0000000..dc36e69
--- /dev/null
+++ b/Uploader/File/FlysystemFile.php
@@ -0,0 +1,48 @@
+<?php
+namespace Oneup\UploaderBundle\Uploader\File;
+
+use League\Flysystem\File;
+use League\Flysystem\Filesystem;
+
+class FlysystemFile extends File implements FileInterface
+{
+
+ protected $streamWrapperPrefix;
+ protected $mimeType;
+
+ public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
+ {
+ parent::__construct($filesystem, $file->getPath());
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ /**
+ * Returns the path of the file
+ *
+ * @return string
+ */
+ public function getPathname()
+ {
+ return $this->getPath();
+ }
+
+ /**
+ * Returns the basename of the file
+ *
+ * @return string
+ */
+ public function getBasename()
+ {
+ return pathinfo($this->getPath(), PATHINFO_BASENAME);
+ }
+
+ /**
+ * Returns the guessed extension of the file
+ *
+ * @return mixed
+ */
+ public function getExtension()
+ {
+ return pathinfo($this->getPath(), PATHINFO_EXTENSION);
+ }
+}
diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php
index 58868b8..7fcc83a 100644
--- a/Uploader/Gaufrette/StreamManager.php
+++ b/Uploader/Gaufrette/StreamManager.php
@@ -25,11 +25,9 @@ class StreamManager
protected function ensureRemotePathExists($path)
{
- // this is a somehow ugly workaround introduced
- // because the stream-mode is not able to create
- // subdirectories.
- if(!$this->filesystem->has($path))
+ if(!$this->filesystem->has($path)) {
$this->filesystem->write($path, '', true);
+ }
}
protected function openStream(Stream $stream, $mode)
diff --git a/Uploader/Storage/FlysystemOrphanageStorage.php b/Uploader/Storage/FlysystemOrphanageStorage.php
new file mode 100644
index 0000000..d9947c3
--- /dev/null
+++ b/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use League\Flysystem\File;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+
+class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageStorageInterface
+{
+ protected $storage;
+ protected $session;
+ protected $chunkStorage;
+ protected $config;
+ protected $type;
+
+ /**
+ * @param StorageInterface $storage
+ * @param SessionInterface $session
+ * @param ChunkStorage $chunkStorage This class is only used if the gaufrette chunk storage is used.
+ * @param $config
+ * @param $type
+ */
+ public function __construct(StorageInterface $storage, SessionInterface $session, ChunkStorage $chunkStorage, $config, $type)
+ {
+ /*
+ * initiate the storage on the chunk storage's filesystem
+ * the stream wrapper is useful for metadata.
+ */
+ parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, $chunkStorage->getStreamWrapperPrefix());
+
+ $this->storage = $storage;
+ $this->chunkStorage = $chunkStorage;
+ $this->session = $session;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ public function upload(FileInterface $file, $name, $path = null)
+ {
+ if(!$this->session->isStarted())
+ throw new \RuntimeException('You need a running session in order to run the Orphanage.');
+
+ return parent::upload($file, $name, $this->getPath());
+ }
+
+ public function uploadFiles(array $files = null)
+ {
+ try {
+ if (null === $files) {
+ $files = $this->getFiles();
+ }
+ $return = array();
+
+ foreach ($files as $key => $file) {
+ try {
+ $return[] = $this->storage->upload($file, str_replace($this->getPath(), '', $key));
+ } catch (\Exception $e) {
+ // well, we tried.
+ continue;
+ }
+ }
+
+ return $return;
+ } catch (\Exception $e) {
+ return array();
+ }
+ }
+
+ public function getFiles()
+ {
+ $keys = $this->chunkStorage->getFilesystem()->listFiles($this->getPath());
+ $keys = $keys['keys'];
+ $files = array();
+
+ foreach ($keys as $key) {
+ // gotta pass the filesystem to both as you can't get it out from one..
+ $files[$key] = new FlysystemFile(new File($this->chunkStorage->getFilesystem(), $key), $this->chunkStorage->getFilesystem());
+ }
+
+ return $files;
+ }
+
+ protected function getPath()
+ {
+ // the storage is initiated in the root of the filesystem, from where the orphanage directory
+ // should be relative.
+ return sprintf('%s/%s/%s', $this->config['directory'], $this->session->getId(), $this->type);
+ }
+
+}
diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php
new file mode 100644
index 0000000..4d0212d
--- /dev/null
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use League\Flysystem\Filesystem;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+use Symfony\Component\Filesystem\Filesystem as LocalFilesystem;
+
+class FlysystemStorage implements StorageInterface
+{
+
+ /**
+ * @var null|string
+ */
+ protected $streamWrapperPrefix;
+
+ /**
+ * @var float
+ */
+ protected $bufferSize;
+
+ /**
+ * @var Filesystem
+ */
+ private $filesystem;
+
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix = null)
+ {
+ $this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
+ }
+
+ public function upload(FileInterface $file, $name, $path = null)
+ {
+ $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
+
+ if ($file instanceof FlysystemFile) {
+ if ($file->getFilesystem() == $this->filesystem) {
+ $file->getFilesystem()->rename($file->getPath(), $path);
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+ }
+
+ $this->filesystem->put($name, file_get_contents($file));
+
+ if ($file instanceof FlysystemFile) {
+ $file->delete();
+ } else {
+ $filesystem = new LocalFilesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+}
diff --git a/composer.json b/composer.json
index b2f32a3..69253bb 100644
--- a/composer.json
+++ b/composer.json
@@ -26,11 +26,13 @@
"symfony/security-bundle": "2.*|~3.0",
"sensio/framework-extra-bundle": "2.*|~3.0",
"symfony/browser-kit": "2.*|~3.0",
- "phpunit/phpunit": "~4.4"
+ "phpunit/phpunit": "~4.4",
+ "oneup/flysystem-bundle": "^1.2"
},
"suggest": {
- "knplabs/knp-gaufrette-bundle": "0.1.*"
+ "knplabs/knp-gaufrette-bundle": "0.1.*",
+ "oneup/flysystem-bundle": "^1.2"
},
"autoload": {
| 0 |
1508dfbe4ae522014b68e0b62850acced526c2eb
|
1up-lab/OneupUploaderBundle
|
Merge pull request #80 from mitom/master
[Critical] fixed uploads not being retryable if there was an error
|
commit 1508dfbe4ae522014b68e0b62850acced526c2eb (from 46ed8f73d1e8fd5f82695e09f476fb93ae15206a)
Merge: 46ed8f7 b915fe5
Author: Jim Schmid <[email protected]>
Date: Mon Dec 16 06:45:03 2013 -0800
Merge pull request #80 from mitom/master
[Critical] fixed uploads not being retryable if there was an error
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 5c641d0..dec76ce 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -120,7 +120,6 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
$this->openStream($dst, 'a');
}
-
// Meet the interface requirements
$uploadedFile = new FilesystemFile($this->unhandledChunk['chunk']);
@@ -128,6 +127,16 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
if ($renameChunk) {
$name = preg_replace('/^(\d+)_/', '', $target);
+ /* The name can only match if the same user in the same session is
+ * trying to upload a file under the same name AND the previous upload failed,
+ * somewhere between this function, and the cleanup call. If that happened
+ * the previous file is unaccessible by the user, but if it is not removed
+ * it will block the user from trying to re-upload it.
+ */
+ if ($this->filesystem->has($path.$name)) {
+ $this->filesystem->delete($path.$name);
+ }
+
$this->filesystem->rename($path.$target, $path.$name);
$target = $name;
}
@@ -149,7 +158,11 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
{
$results = $this->filesystem->listKeys($this->prefix.'/'.$uuid);
- return $results['keys'];
+ /* exclude files without an index, so if there is a completed file which
+ * failed to upload it will not get mixed together with new one's chunks.
+ */
+
+ return preg_grep('/^.+\/(\d+)_/', $results['keys']);
}
public function getFilesystem()
| 0 |
8b6c03eb4d81ed75a4c72445c1f3b6d43af85099
|
1up-lab/OneupUploaderBundle
|
Some odd thing was going on to get the mock of a file, so changed it
|
commit 8b6c03eb4d81ed75a4c72445c1f3b6d43af85099
Author: Martin Aarhof <[email protected]>
Date: Sat Jan 23 16:19:29 2016 +0100
Some odd thing was going on to get the mock of a file, so changed it
diff --git a/Tests/Uploader/Naming/UrlSafeNamerTest.php b/Tests/Uploader/Naming/UrlSafeNamerTest.php
index 8673c91..1707940 100644
--- a/Tests/Uploader/Naming/UrlSafeNamerTest.php
+++ b/Tests/Uploader/Naming/UrlSafeNamerTest.php
@@ -34,23 +34,11 @@ class UrlSafeNamerTest extends FileTest
public function test_two_file_names_not_equal()
{
- $file = $this->getMockBuilder('Oneup\UploaderBundle\Uploader\File\FilesystemFile')
- ->disableOriginalConstructor()
- ->getMock()
- ;
-
- $file
- ->expects($this->any())
- ->method('getExtension')
- ->will($this->returnValue('jpeg'))
- ;
-
- /** @var \Oneup\UploaderBundle\Uploader\File\FileInterface $file */
$namer = new UrlSafeNamer();
// Trying 200 times just to be sure
for($i = 0; $i < 200; $i++) {
- $name1 = $namer->name($file);
- $name2 = $namer->name($file);
+ $name1 = $namer->name($this->file);
+ $name2 = $namer->name($this->file);
$this->assertNotEquals($name1, $name2);
}
| 0 |
72671ee9b9ca21bfe16741048caf5155ba16084f
|
1up-lab/OneupUploaderBundle
|
Merge pull request #8 from 1up-lab/frontend_agnostic
Make the Bundle frontend agnostic
|
commit 72671ee9b9ca21bfe16741048caf5155ba16084f (from baede5317fe99025e74a944aaeec833d84dc4a04)
Merge: baede53 dccc513
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 16:09:39 2013 -0700
Merge pull request #8 from 1up-lab/frontend_agnostic
Make the Bundle frontend agnostic
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
new file mode 100644
index 0000000..d659cf6
--- /dev/null
+++ b/Controller/AbstractChunkedController.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Controller\AbstractController;
+
+abstract class AbstractChunkedController extends AbstractController
+{
+ abstract protected function parseChunkedRequest(Request $request);
+
+ protected function handleChunkedUpload(UploadedFile $file)
+ {
+ // get basic container stuff
+ $request = $this->container->get('request');
+ $chunkManager = $this->container->get('oneup_uploader.chunk_manager');
+
+ // reset uploaded to always have a return value
+ $uploaded = null;
+
+ // get information about this chunked request
+ list($last, $uuid, $index, $orig) = $this->parseChunkedRequest($request);
+
+ $chunkManager->addChunk($uuid, $index, $file, $orig);
+
+ // if all chunks collected and stored, proceed
+ // with reassembling the parts
+ if($last)
+ {
+ // we'll take the first chunk and append the others to it
+ // this way we don't need another file in temporary space for assembling
+ $chunks = $chunkManager->getChunks($uuid);
+
+ // assemble parts
+ $assembled = $chunkManager->assembleChunks($chunks);
+ $path = $assembled->getPath();
+
+ // create a temporary uploaded file to meet the interface restrictions
+ $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true);
+
+ // validate this entity and upload on success
+ $this->validate($uploadedFile);
+ $uploaded = $this->handleUpload($uploadedFile);
+
+ $chunkManager->cleanup($path);
+ }
+
+ return $uploaded;
+ }
+}
\ No newline at end of file
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
new file mode 100644
index 0000000..c53e574
--- /dev/null
+++ b/Controller/AbstractController.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostPersistEvent;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+abstract class AbstractController
+{
+ protected $container;
+ protected $storage;
+ protected $config;
+ protected $type;
+
+ public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
+ {
+ $this->container = $container;
+ $this->storage = $storage;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ abstract public function upload();
+
+ protected function handleUpload(UploadedFile $file)
+ {
+ $this->validate($file);
+
+ // no error happend, proceed
+ $namer = $this->container->get($this->config['namer']);
+ $name = $namer->name($file);
+
+ // perform the real upload
+ $uploaded = $this->storage->upload($file, $name);
+
+ return $uploaded;
+ }
+
+ protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
+ {
+ $dispatcher = $this->container->get('event_dispatcher');
+
+ $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
+ $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
+
+ if(!$this->config['use_orphanage'])
+ {
+ // dispatch post upload event
+ $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config);
+ $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
+ }
+ }
+
+ protected function validate(UploadedFile $file)
+ {
+ // check if the file size submited by the client is over the max size in our config
+ if($file->getClientSize() > $this->config['max_size'])
+ throw new UploadException('error.maxsize');
+
+ $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+
+ // if this mapping defines at least one type of an allowed extension,
+ // test if the current is in this array
+ if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions']))
+ throw new UploadException('error.whitelist');
+
+ // check if the current extension is mentioned in the disallowed types
+ // and if so, throw an exception
+ if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions']))
+ throw new UploadException('error.blacklist');
+
+ }
+}
\ No newline at end of file
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
new file mode 100644
index 0000000..e2c6026
--- /dev/null
+++ b/Controller/BlueimpController.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostPersistEvent;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Controller\AbstractController;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class BlueimpController extends AbstractChunkedController
+{
+ public function upload()
+ {
+ $request = $this->container->get('request');
+ $dispatcher = $this->container->get('event_dispatcher');
+ $translator = $this->container->get('translator');
+
+ $response = new EmptyResponse();
+ $files = $request->files;
+
+ $chunked = !is_null($request->headers->get('content-range'));
+
+ foreach($files as $file)
+ {
+ $file = $file[0];
+
+ try
+ {
+ $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+
+ // dispatch POST_PERSIST AND POST_UPLOAD events
+ $this->dispatchEvents($uploaded, $response, $request);
+ }
+ catch(UploadException $e)
+ {
+ // return nothing
+ return new JsonResponse(array());
+ }
+ }
+
+ return new JsonResponse($response->assemble());
+ }
+
+ protected function parseChunkedRequest(Request $request)
+ {
+ $session = $this->container->get('session');
+ $headerRange = $request->headers->get('content-range');
+ $attachmentName = rawurldecode(preg_replace('/(^[^"]+")|("$)/', '', $request->headers->get('content-disposition')));
+
+ // split the header string to the appropriate parts
+ list($tmp, $startByte, $endByte, $totalBytes) = preg_split('/[^0-9]+/', $headerRange);
+
+ // getting information about chunks
+ // note: We don't have a chance to get the last $total
+ // correct. This is due to the fact that the $size variable
+ // is incorrect. As it will always be a higher number than
+ // the one before, we just let that happen, if you have
+ // any idea to fix this without fetching information about
+ // previously saved files, let me know.
+ $size = ($endByte + 1 - $startByte);
+ $last = ($endByte + 1) == $totalBytes;
+ $index = $last ? \PHP_INT_MAX : floor($startByte / $size);
+ $total = ceil($totalBytes / $size);
+
+ // it is possible, that two clients send a file with the
+ // exact same filename, therefore we have to add the session
+ // to the uuid otherwise we will get a mess
+ $uuid = md5(sprintf('%s.%s', $attachmentName, $session->getId()));
+ $orig = $attachmentName;
+
+ return array($last, $uuid, $index, $orig);
+ }
+}
\ No newline at end of file
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
new file mode 100644
index 0000000..7fcbace
--- /dev/null
+++ b/Controller/FineUploaderController.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostPersistEvent;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Controller\AbstractChunkedController;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
+
+class FineUploaderController extends AbstractChunkedController
+{
+ public function upload()
+ {
+ $request = $this->container->get('request');
+ $translator = $this->container->get('translator');
+
+ $response = new FineUploaderResponse();
+ $totalParts = $request->get('qqtotalparts', 1);
+ $files = $request->files;
+ $chunked = $totalParts > 1;
+
+ foreach($files as $file)
+ {
+ try
+ {
+ $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+
+ // dispatch POST_PERSIST AND POST_UPLOAD events
+ $this->dispatchEvents($uploaded, $response, $request);
+ }
+ catch(UploadException $e)
+ {
+ $response->setSuccess(false);
+ $response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'));
+
+ // an error happended, return this error message.
+ return new JsonResponse($response->assemble());
+ }
+ }
+
+ return new JsonResponse($response->assemble());
+ }
+
+ protected function parseChunkedRequest(Request $request)
+ {
+ $index = $request->get('qqpartindex');
+ $total = $request->get('qqtotalparts');
+ $uuid = $request->get('qquuid');
+ $orig = $request->get('qqfilename');
+ $last = ($total - 1) == $index;
+
+ return array($last, $uuid, $index, $orig);
+ }
+}
\ No newline at end of file
diff --git a/Controller/UploadControllerInterface.php b/Controller/UploadControllerInterface.php
deleted file mode 100644
index 977375e..0000000
--- a/Controller/UploadControllerInterface.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Controller;
-
-interface UploadControllerInterface
-{
- public function upload();
-}
\ No newline at end of file
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
deleted file mode 100644
index 3bf61a5..0000000
--- a/Controller/UploaderController.php
+++ /dev/null
@@ -1,144 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Controller;
-
-use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-use Symfony\Component\HttpFoundation\JsonResponse;
-
-use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Event\PostPersistEvent;
-use Oneup\UploaderBundle\Event\PostUploadEvent;
-use Oneup\UploaderBundle\Controller\UploadControllerInterface;
-use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
-use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
-
-class UploaderController implements UploadControllerInterface
-{
- protected $container;
- protected $storage;
- protected $config;
- protected $type;
-
- public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
- {
- $this->container = $container;
- $this->storage = $storage;
- $this->config = $config;
- $this->type = $type;
- }
-
- public function upload()
- {
- $request = $this->container->get('request');
- $dispatcher = $this->container->get('event_dispatcher');
- $translator = $this->container->get('translator');
-
- $response = new UploaderResponse();
- $totalParts = $request->get('qqtotalparts', 1);
- $files = $request->files;
- $chunked = $totalParts > 1;
-
- foreach($files as $file)
- {
- try
- {
- $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
- $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
- $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
-
- if(!$this->config['use_orphanage'])
- {
- // dispatch post upload event
- $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config);
- $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
- }
- }
- catch(UploadException $e)
- {
- $response->setSuccess(false);
- $response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'));
-
- // an error happended, return this error message.
- return new JsonResponse($response->assemble());
- }
- }
-
- return new JsonResponse($response->assemble());
- }
-
- protected function handleUpload(UploadedFile $file)
- {
- $this->validate($file);
-
- // no error happend, proceed
- $namer = $this->container->get($this->config['namer']);
- $name = $namer->name($file);
-
- // perform the real upload
- $uploaded = $this->storage->upload($file, $name);
-
- return $uploaded;
- }
-
- protected function handleChunkedUpload(UploadedFile $file)
- {
- $request = $this->container->get('request');
- $chunkManager = $this->container->get('oneup_uploader.chunk_manager');
- $uploaded = null;
-
- // getting information about chunks
- $index = $request->get('qqpartindex');
- $total = $request->get('qqtotalparts');
- $uuid = $request->get('qquuid');
- $orig = $request->get('qqfilename');
-
- $chunkManager->addChunk($uuid, $index, $file, $orig);
-
- // if all chunks collected and stored, proceed
- // with reassembling the parts
- if(($total - 1) == $index)
- {
- // we'll take the first chunk and append the others to it
- // this way we don't need another file in temporary space for assembling
- $chunks = $chunkManager->getChunks($uuid);
-
- // assemble parts
- $assembled = $chunkManager->assembleChunks($chunks);
- $path = $assembled->getPath();
-
- // create a temporary uploaded file to meet the interface restrictions
- $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true);
-
- // validate this entity and upload on success
- $this->validate($uploadedFile);
- $uploaded = $this->handleUpload($uploadedFile);
-
- $chunkManager->cleanup($path);
- }
-
- return $uploaded;
- }
-
- protected function validate(UploadedFile $file)
- {
- // check if the file size submited by the client is over the max size in our config
- if($file->getClientSize() > $this->config['max_size'])
- throw new UploadException('error.maxsize');
-
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
-
- // if this mapping defines at least one type of an allowed extension,
- // test if the current is in this array
- if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions']))
- throw new UploadException('error.whitelist');
-
- // check if the current extension is mentioned in the disallowed types
- // and if so, throw an exception
- if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions']))
- throw new UploadException('error.blacklist');
-
- }
-}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 5f061b0..8848e0d 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -34,6 +34,10 @@ class Configuration implements ConfigurationInterface
->requiresAtLeastOneElement()
->prototype('array')
->children()
+ ->enumNode('frontend')
+ ->values(array('fineuploader', 'blueimp'))
+ ->defaultValue('fineuploader')
+ ->end()
->arrayNode('storage')
->addDefaultsIfNotSet()
->children()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 04eb240..a9747a1 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -105,10 +105,11 @@ class OneupUploaderExtension extends Extension
}
$controllerName = sprintf('oneup_uploader.controller.%s', $key);
+ $controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $mapping['frontend']);
// create controllers based on mapping
$container
- ->register($controllerName, $container->getParameter('oneup_uploader.controller.class'))
+ ->register($controllerName, $controllerType)
->addArgument(new Reference('service_container'))
->addArgument($storageService)
diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php
index 6fed87f..a25dc19 100644
--- a/Event/PostPersistEvent.php
+++ b/Event/PostPersistEvent.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
class PostPersistEvent extends Event
{
@@ -14,7 +14,7 @@ class PostPersistEvent extends Event
protected $response;
protected $config;
- public function __construct($file, UploaderResponse $response, Request $request, $type, array $config)
+ public function __construct($file, ResponseInterface $response, Request $request, $type, array $config)
{
$this->file = $file;
$this->request = $request;
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index 9dfd6ce..872a131 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
class PostUploadEvent extends Event
{
@@ -14,7 +14,7 @@ class PostUploadEvent extends Event
protected $response;
protected $config;
- public function __construct($file, UploaderResponse $response, Request $request, $type, array $config)
+ public function __construct($file, ResponseInterface $response, Request $request, $type, array $config)
{
$this->file = $file;
$this->request = $request;
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 13baac6..7083edf 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -7,11 +7,12 @@
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
- <parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
<parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
<parameter key="oneup_uploader.storage.filesystem.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Storage\OrphanageStorage</parameter>
<parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter>
+ <parameter key="oneup_uploader.controller.fineuploader.class">Oneup\UploaderBundle\Controller\FineUploaderController</parameter>
+ <parameter key="oneup_uploader.controller.blueimp.class">Oneup\UploaderBundle\Controller\BlueimpController</parameter>
</parameters>
<services>
diff --git a/Tests/Controller/UploaderControllerChunkedTest.php b/Tests/Controller/AbstractControllerChunkedTest.php
similarity index 81%
rename from Tests/Controller/UploaderControllerChunkedTest.php
rename to Tests/Controller/AbstractControllerChunkedTest.php
index 1291823..771282f 100644
--- a/Tests/Controller/UploaderControllerChunkedTest.php
+++ b/Tests/Controller/AbstractControllerChunkedTest.php
@@ -9,15 +9,17 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-use Oneup\UploaderBundle\Controller\UploaderController;
-class UploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase
+abstract class AbstractControllerChunkedTest extends \PHPUnit_Framework_TestCase
{
protected $tempChunks;
protected $currentChunk;
protected $chunkUuid;
protected $numberOfChunks;
+ abstract public function getControllerString();
+ abstract protected function getRequestMock();
+
public function setUp()
{
$this->numberOfChunks = 10;
@@ -52,7 +54,8 @@ class UploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase
);
$responses = array();
- $controller = new UploaderController($container, $storage, $config, 'cat');
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
// mock as much requests as there are parts to assemble
for($i = 0; $i < $this->numberOfChunks; $i ++)
@@ -122,37 +125,6 @@ class UploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase
return $mock;
}
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'requestGetCb')))
- ;
-
- $mock->files = array(
- $this->getUploadedFile()
- );
-
- return $mock;
- }
-
- public function requestGetCb($inp)
- {
- if($inp == 'qqtotalparts')
- return $this->numberOfChunks;
-
- if($inp == 'qqpartindex')
- return $this->currentChunk;
-
- if($inp == 'qquuid')
- return $this->chunkUuid;
-
- if($inp == 'qqfilename')
- return 'grumpy-cat.jpeg';
- }
-
protected function getUploadedFile()
{
return new UploadedFile($this->tempChunks[$this->currentChunk], 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
diff --git a/Tests/Controller/UploaderControllerTest.php b/Tests/Controller/AbstractControllerTest.php
similarity index 84%
rename from Tests/Controller/UploaderControllerTest.php
rename to Tests/Controller/AbstractControllerTest.php
index e9bd236..80176e9 100644
--- a/Tests/Controller/UploaderControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -8,12 +8,14 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-use Oneup\UploaderBundle\Controller\UploaderController;
-class UploaderControllerTest extends \PHPUnit_Framework_TestCase
+abstract class AbstractControllerTest extends \PHPUnit_Framework_TestCase
{
protected $tempFile;
+ abstract public function getControllerString();
+ abstract protected function getRequestMock();
+
public function setUp()
{
// create temporary file
@@ -36,7 +38,8 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
'disallowed_extensions' => array()
);
- $controller = new UploaderController($container, $storage, $config, 'cat');
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
$response = $controller->upload();
// check if original file has been moved
@@ -65,7 +68,8 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
'disallowed_extensions' => array()
);
- $controller = new UploaderController($container, $storage, $config, 'cat');
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
$response = $controller->upload();
$json = json_decode($response->getContent());
@@ -73,7 +77,6 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
// testing response
$this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
$this->assertEquals(200, $response->getStatusCode());
- $this->assertFalse($json->success);
}
protected function getContainerMock()
@@ -115,23 +118,6 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
return $mock;
}
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $mock
- ->expects($this->any())
- ->method('get')
- ->with('qqtotalparts')
- ->will($this->returnValue(1))
- ;
-
- $mock->files = array(
- $this->getUploadedFile()
- );
-
- return $mock;
- }
-
protected function getTranslatorMock()
{
$mock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
diff --git a/Tests/Controller/UploaderControllerValidationTest.php b/Tests/Controller/AbstractControllerValidationTest.php
similarity index 92%
rename from Tests/Controller/UploaderControllerValidationTest.php
rename to Tests/Controller/AbstractControllerValidationTest.php
index 2e06720..b066e3b 100644
--- a/Tests/Controller/UploaderControllerValidationTest.php
+++ b/Tests/Controller/AbstractControllerValidationTest.php
@@ -2,10 +2,10 @@
namespace Oneup\UploaderBundle\Tests\Controller;
-use Oneup\UploaderBundle\Controller\UploaderController;
-
-class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase
+abstract class AbstractControllerValidationTest extends \PHPUnit_Framework_TestCase
{
+ abstract public function getControllerString();
+
/**
* @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException
*/
@@ -90,7 +90,8 @@ class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase
$container = $this->getContainerMock();
$storage = $this->getStorageMock();
- $controller = new UploaderController($container, $storage, $config, 'cat');
+ $str = $this->getControllerString();
+ $controller = new $str($container, $storage, $config, 'cat');
$method->invoke($controller, $file);
// yey, no exception thrown
@@ -132,7 +133,7 @@ class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase
protected function getValidationMethod()
{
// create a public version of the validate method
- $class = new \ReflectionClass('Oneup\\UploaderBundle\\Controller\\UploaderController');
+ $class = new \ReflectionClass($this->getControllerString());
$method = $class->getMethod('validate');
$method->setAccessible(true);
diff --git a/Tests/Controller/BlueimpControllerChunkedTest.php b/Tests/Controller/BlueimpControllerChunkedTest.php
new file mode 100644
index 0000000..9b95ca5
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerChunkedTest.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
+
+class BlueimpControllerChunkedTest extends AbstractControllerChunkedTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+
+ $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
+ $headers
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'headersGetCb')))
+ ;
+
+ $mock->headers = $headers;
+
+ $mock->files = array(
+ array($this->getUploadedFile())
+ );
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'session')
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Session\Session');
+ $mock
+ ->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue('fixed-id'))
+ ;
+
+ return $mock;
+ }
+
+ return parent::containerGetCb($inp);
+ }
+
+ public function headersGetCb($inp)
+ {
+ if($inp == 'content-disposition')
+ return 'grumpy-cat.jpeg';
+
+ if($inp == 'content-range')
+ {
+ if($this->currentChunk == ($this->numberOfChunks - 1))
+ {
+ return sprintf('- 9218, 10240/10241');
+ }
+ else
+ {
+ $size = 1024;
+ $ret = sprintf('- %d, %d/%d', $this->currentChunk * $size, $this->currentChunk * $size + $size, 10240);
+
+ return $ret;
+ }
+ }
+ }
+}
diff --git a/Tests/Controller/BlueimpControllerTest.php b/Tests/Controller/BlueimpControllerTest.php
new file mode 100644
index 0000000..19ffefa
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class BlueimpControllerTest extends AbstractControllerTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
+ $headers
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnValue(null))
+ ;
+
+ $mock->headers = $headers;
+
+ $mock->files = array(
+ array($this->getUploadedFile())
+ );
+
+ return $mock;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/BlueimpControllerValidationTest.php b/Tests/Controller/BlueimpControllerValidationTest.php
new file mode 100644
index 0000000..40a32eb
--- /dev/null
+++ b/Tests/Controller/BlueimpControllerValidationTest.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerValidationTest;
+
+class BlueimpControllerValidationTest extends AbstractControllerValidationTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\BlueimpController';
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerChunkedTest.php b/Tests/Controller/FineUploaderControllerChunkedTest.php
new file mode 100644
index 0000000..9d9adb1
--- /dev/null
+++ b/Tests/Controller/FineUploaderControllerChunkedTest.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
+
+class FineUploaderControllerChunkedTest extends AbstractControllerChunkedTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'requestGetCb')))
+ ;
+
+ $mock->files = array(
+ $this->getUploadedFile()
+ );
+
+ return $mock;
+ }
+
+ public function requestGetCb($inp)
+ {
+ if($inp == 'qqtotalparts')
+ return $this->numberOfChunks;
+
+ if($inp == 'qqpartindex')
+ return $this->currentChunk;
+
+ if($inp == 'qquuid')
+ return $this->chunkUuid;
+
+ if($inp == 'qqfilename')
+ return 'grumpy-cat.jpeg';
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerTest.php b/Tests/Controller/FineUploaderControllerTest.php
new file mode 100644
index 0000000..5fafc14
--- /dev/null
+++ b/Tests/Controller/FineUploaderControllerTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class FineUploaderControllerTest extends AbstractControllerTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->with('qqtotalparts')
+ ->will($this->returnValue(1))
+ ;
+
+ $mock->files = array(
+ $this->getUploadedFile()
+ );
+
+ return $mock;
+ }
+}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerValidationTest.php b/Tests/Controller/FineUploaderControllerValidationTest.php
new file mode 100644
index 0000000..3c1f2c9
--- /dev/null
+++ b/Tests/Controller/FineUploaderControllerValidationTest.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerValidationTest;
+
+class FineUploaderControllerValidationTest extends AbstractControllerValidationTest
+{
+ public function getControllerString()
+ {
+ return 'Oneup\UploaderBundle\Controller\FineUploaderController';
+ }
+}
\ No newline at end of file
diff --git a/Tests/Uploader/Response/EmptyResponseTest.php b/Tests/Uploader/Response/EmptyResponseTest.php
new file mode 100644
index 0000000..82b4f63
--- /dev/null
+++ b/Tests/Uploader/Response/EmptyResponseTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class TestEmptyResponse extends \PHPUnit_Framework_TestCase
+{
+ public function testEmpty()
+ {
+ $response = new EmptyResponse();
+ $assembled = $response->assemble();
+
+ $this->assertTrue(is_array($assembled));
+ $this->assertCount(0, $assembled);
+ }
+
+ public function testWithItems()
+ {
+ $response = new EmptyResponse();
+
+ // fill in some data
+ $response['cat'] = 'grumpy';
+ $response['dog'] = 'has no idea';
+
+ $assembled = $response->assemble();
+
+ $this->assertTrue(is_array($assembled));
+ $this->assertCount(2, $assembled);
+ }
+}
\ No newline at end of file
diff --git a/Tests/Uploader/Response/UploaderResponseTest.php b/Tests/Uploader/Response/FineUploaderResponseTest.php
similarity index 84%
rename from Tests/Uploader/Response/UploaderResponseTest.php
rename to Tests/Uploader/Response/FineUploaderResponseTest.php
index 37728a0..05f3d0a 100644
--- a/Tests/Uploader/Response/UploaderResponseTest.php
+++ b/Tests/Uploader/Response/FineUploaderResponseTest.php
@@ -2,13 +2,13 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Response;
-use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
+use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
-class TestUploaderResponse extends \PHPUnit_Framework_TestCase
+class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase
{
public function testCreationOfResponse()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$this->assertTrue($response->getSuccess());
$this->assertNull($response->getError());
@@ -16,7 +16,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testFillOfResponse()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$cat = 'is grumpy';
$dog = 'has no idea';
@@ -46,7 +46,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testError()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$response->setError('This response is grumpy');
$this->assertEquals($response->getError(), 'This response is grumpy');
@@ -54,7 +54,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testOverwriteOfInternals()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$response['success'] = false;
$response['error'] = 42;
diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php
new file mode 100644
index 0000000..1e97d50
--- /dev/null
+++ b/Uploader/Response/AbstractResponse.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+abstract class AbstractResponse implements ResponseInterface
+{
+ protected $data;
+
+ public function __construct()
+ {
+ $this->data = array();
+ }
+
+ abstract public function assemble();
+
+ public function offsetSet($offset, $value)
+ {
+ is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value;
+ }
+ public function offsetExists($offset)
+ {
+ return isset($this->data[$offset]);
+ }
+ public function offsetUnset($offset)
+ {
+ unset($this->data[$offset]);
+ }
+
+ public function offsetGet($offset)
+ {
+ return isset($this->data[$offset]) ? $this->data[$offset] : null;
+ }
+}
\ No newline at end of file
diff --git a/Uploader/Response/EmptyResponse.php b/Uploader/Response/EmptyResponse.php
new file mode 100644
index 0000000..3fa6f6c
--- /dev/null
+++ b/Uploader/Response/EmptyResponse.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class EmptyResponse extends AbstractResponse
+{
+ public function assemble()
+ {
+ return $this->data;
+ }
+
+}
\ No newline at end of file
diff --git a/Uploader/Response/UploaderResponse.php b/Uploader/Response/FineUploaderResponse.php
similarity index 65%
rename from Uploader/Response/UploaderResponse.php
rename to Uploader/Response/FineUploaderResponse.php
index 090df34..4b47e3c 100644
--- a/Uploader/Response/UploaderResponse.php
+++ b/Uploader/Response/FineUploaderResponse.php
@@ -2,17 +2,19 @@
namespace Oneup\UploaderBundle\Uploader\Response;
-class UploaderResponse implements \ArrayAccess
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class FineUploaderResponse extends AbstractResponse
{
protected $success;
protected $error;
- protected $data;
public function __construct()
{
$this->success = true;
$this->error = null;
- $this->data = array();
+
+ parent::__construct();
}
public function assemble()
@@ -31,24 +33,6 @@ class UploaderResponse implements \ArrayAccess
return $data;
}
-
- public function offsetSet($offset, $value)
- {
- is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value;
- }
- public function offsetExists($offset)
- {
- return isset($this->data[$offset]);
- }
- public function offsetUnset($offset)
- {
- unset($this->data[$offset]);
- }
-
- public function offsetGet($offset)
- {
- return isset($this->data[$offset]) ? $this->data[$offset] : null;
- }
public function setSuccess($success)
{
diff --git a/Uploader/Response/ResponseInterface.php b/Uploader/Response/ResponseInterface.php
new file mode 100644
index 0000000..b1e835e
--- /dev/null
+++ b/Uploader/Response/ResponseInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Response;
+
+interface ResponseInterface extends \ArrayAccess
+{
+ public function assemble();
+}
\ No newline at end of file
| 0 |
a4eca39e7ea9af1950855c031887d6df96f34906
|
1up-lab/OneupUploaderBundle
|
Add Response Object to ValidationEvent to be able to send error messages back to client
|
commit a4eca39e7ea9af1950855c031887d6df96f34906
Author: derpue <[email protected]>
Date: Wed Nov 8 09:58:47 2017 +0100
Add Response Object to ValidationEvent to be able to send error messages back to client
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 75d3518..fac6246 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -113,7 +113,7 @@ abstract class AbstractController
if (!($file instanceof FileInterface)) {
$file = new FilesystemFile($file);
}
- $this->validate($file);
+ $this->validate($file, $response, $request);
$this->dispatchPreUploadEvent($file, $response, $request);
@@ -169,10 +169,10 @@ abstract class AbstractController
}
}
- protected function validate(FileInterface $file)
+ protected function validate(FileInterface $file,ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
+ $event = new ValidationEvent($file, $response, $request, $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index 15e1c18..4240059 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Event;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
@@ -12,13 +13,15 @@ class ValidationEvent extends Event
protected $config;
protected $type;
protected $request;
+ protected $response;
- public function __construct(FileInterface $file, Request $request, array $config, $type)
+ public function __construct(FileInterface $file, ResponseInterface $response, Request $request, array $config, $type)
{
$this->file = $file;
$this->config = $config;
$this->type = $type;
$this->request = $request;
+ $this->response = $response;
}
public function getFile()
@@ -40,4 +43,10 @@ class ValidationEvent extends Event
{
return $this->request;
}
+
+ public function getResponse()
+ {
+ return $this->response;
+ }
+
}
| 0 |
009586389c5345fc96de2e59f598016de23f11a0
|
1up-lab/OneupUploaderBundle
|
fixed event firing check
|
commit 009586389c5345fc96de2e59f598016de23f11a0
Author: mitom <[email protected]>
Date: Mon Oct 14 21:33:49 2013 +0200
fixed event firing check
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 2e803bb..4116b4c 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -53,14 +53,14 @@ abstract class AbstractChunkedController extends AbstractController
$chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
- if ($chunk) {
+ if (null !== $chunk) {
$this->dispatchChunkEvents($chunk, $response, $request, $last);
}
if ($chunkManager->getLoadDistribution()) {
$chunks = $chunkManager->getChunks($uuid);
$assembled = $chunkManager->assembleChunks($chunks, true, $last);
- if (!$chunk) {
+ if (null === $chunk) {
$this->dispatchChunkEvents($assembled, $response, $request, $last);
}
}
| 0 |
32a4efa1a87d5c7caa65d7d2a1a28d533fbc2738
|
1up-lab/OneupUploaderBundle
|
Update GaufretteFile.php
|
commit 32a4efa1a87d5c7caa65d7d2a1a28d533fbc2738
Author: Saša Stamenković <[email protected]>
Date: Wed Jul 16 14:41:34 2014 +0200
Update GaufretteFile.php
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 446ae14..39c9234 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -9,14 +9,12 @@ use Gaufrette\Adapter\AwsS3;
class GaufretteFile extends File implements FileInterface
{
- protected $filesystem;
protected $streamWrapperPrefix;
protected $mimeType;
public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
{
parent::__construct($file->getKey(), $filesystem);
- $this->filesystem = $filesystem;
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
| 0 |
59659bda1dbd944cf18d140417ff5f29c8622644
|
1up-lab/OneupUploaderBundle
|
Removed a paragraph which pointed out that this bundle only supports FineUploader.
|
commit 59659bda1dbd944cf18d140417ff5f29c8622644
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 15:11:11 2013 +0200
Removed a paragraph which pointed out that this bundle only supports FineUploader.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 0aae9be..9b6afe0 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -99,8 +99,6 @@ So if you take the mapping described before, the generated route name would be `
* [Use FancyUpload](frontend_fancyupload.md)
* [Use MooUpload](frontend_mooupload.md)
-This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them.
-
## Next steps
After installing and setting up the basic functionality of this bundle you can move on and integrate
| 0 |
a1833b4864ab5545b67324eb4252e6e89a8695ff
|
1up-lab/OneupUploaderBundle
|
Fix .gitignore
|
commit a1833b4864ab5545b67324eb4252e6e89a8695ff
Author: David Greminger <[email protected]>
Date: Fri Oct 23 11:37:15 2020 +0200
Fix .gitignore
diff --git a/.gitignore b/.gitignore
index 68a1a75..1eeb0a2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,3 @@ vendor
tests/App/cache
tests/App/logs
tests/App/var
-tests/var
| 0 |
e1e139af3c63d0a19f6f8b06591987fb4ca0d6bb
|
1up-lab/OneupUploaderBundle
|
Merge branch 'derpue-validationEventWithResponse'
|
commit e1e139af3c63d0a19f6f8b06591987fb4ca0d6bb (from c70ac38252200356540ec27b67853b2eb1106c53)
Merge: c70ac38 c7c1d00
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:16:34 2017 +0100
Merge branch 'derpue-validationEventWithResponse'
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 75d3518..fac6246 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -113,7 +113,7 @@ abstract class AbstractController
if (!($file instanceof FileInterface)) {
$file = new FilesystemFile($file);
}
- $this->validate($file);
+ $this->validate($file, $response, $request);
$this->dispatchPreUploadEvent($file, $response, $request);
@@ -169,10 +169,10 @@ abstract class AbstractController
}
}
- protected function validate(FileInterface $file)
+ protected function validate(FileInterface $file,ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
+ $event = new ValidationEvent($file, $response, $request, $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index 15e1c18..4240059 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Event;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
@@ -12,13 +13,15 @@ class ValidationEvent extends Event
protected $config;
protected $type;
protected $request;
+ protected $response;
- public function __construct(FileInterface $file, Request $request, array $config, $type)
+ public function __construct(FileInterface $file, ResponseInterface $response, Request $request, array $config, $type)
{
$this->file = $file;
$this->config = $config;
$this->type = $type;
$this->request = $request;
+ $this->response = $response;
}
public function getFile()
@@ -40,4 +43,10 @@ class ValidationEvent extends Event
{
return $this->request;
}
+
+ public function getResponse()
+ {
+ return $this->response;
+ }
+
}
| 0 |
e9aab5fbfffbf91569b3aef3bd76a278af076fc7
|
1up-lab/OneupUploaderBundle
|
Initial RouteLoader, which should create dynamic, mapping-bound routes.
|
commit e9aab5fbfffbf91569b3aef3bd76a278af076fc7
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 17:37:26 2013 +0100
Initial RouteLoader, which should create dynamic, mapping-bound routes.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 0c09a89..9cbdc10 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -14,6 +14,13 @@ class Configuration implements ConfigurationInterface
$rootNode
->children()
+ ->arrayNode('routing')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('prefix')->defaultValue('/oneup/uploader')->end()
+ ->scalarNode('action')->defaultValue('OneupUploaderBundle:Uploader:upload')->end()
+ ->end()
+ ->end()
->arrayNode('chunks')
->addDefaultsIfNotSet()
->children()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 29cd7e9..0762b91 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -17,6 +17,12 @@ class OneupUploaderExtension extends Extension
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
+ // handle routing configuration
+ foreach($config['routing'] as $key => $value)
+ {
+ $container->setParameter(sprintf('oneup_uploader.routing.%s', $key), $value);
+ }
+
// handling chunk configuration
if(!array_key_exists('directory', $config['chunks']))
{
@@ -24,5 +30,13 @@ class OneupUploaderExtension extends Extension
}
$container->setParameter('oneup_uploader.chunks', $config['chunks']);
+
+ // handle mappings
+ foreach($config['mappings'] as $key => $mapping)
+ {
+ $container->setParameter(sprintf('oneup_uploader.mapping.%s', $key), $value);
+ }
+
+ $container->setParameter('oneup_uploader.mappings', $config['mappings']);
}
}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 72d08e6..727e452 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -5,12 +5,22 @@
<parameters>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
+ <parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
</parameters>
<services>
<service id="oneup_uploader.chunks.manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
</service>
+
+ <service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
+ <argument>%oneup_uploader.routing.action%</argument>
+ <argument>%oneup_uploader.routing.prefix%</argument>
+ <argument>%oneup_uploader.mappings%</argument>
+
+ <tag name="routing.loader" />
+ </service>
+
</services>
</container>
\ No newline at end of file
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
new file mode 100644
index 0000000..7c6ef11
--- /dev/null
+++ b/Routing/RouteLoader.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Oneup\UploaderBundle\Routing;
+
+use Symfony\Component\Config\Loader\Loader;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\RouteCollection;
+
+class RouteLoader extends Loader
+{
+ protected $action;
+ protected $prefix;
+ protected $mappings;
+
+ public function __construct($action, $prefix, array $mappings)
+ {
+ $this->action = $action;
+ $this->prefix = $prefix;
+ $this->mappings = $mappings;
+ }
+
+ public function supports($resource, $type = null)
+ {
+ return $type === 'uploader';
+ }
+
+ public function load($resource, $type = null)
+ {
+ $requirements = array('_method' => 'POST', 'mapping' => '[A-z0-9_\-]*');
+ $defaults = array('_controller' => $this->action);
+
+ $routes = new RouteCollection();
+
+ foreach($this->mappings as $key => $mapping)
+ {
+ $defaults += array('mapping' => $key);
+
+ $routes->add(sprintf('_uploader_%s', $key), new Route(
+ sprintf('%s/{mapping}', $this->prefix),
+ $defaults,
+ $requirements,
+ array()
+ ));
+ }
+
+ return $routes;
+ }
+}
\ No newline at end of file
| 0 |
ea2df2fe99f75014aa716b2cf3fb1b66b059e2f1
|
1up-lab/OneupUploaderBundle
|
Refactored POST_UPLOAD event.
|
commit ea2df2fe99f75014aa716b2cf3fb1b66b059e2f1
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 11:35:34 2013 +0100
Refactored POST_UPLOAD event.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 0d18043..afa18b3 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -5,7 +5,7 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Event\PostPersistEvent;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
@@ -37,11 +37,17 @@ class UploaderController implements UploadControllerInterface
foreach($files as $file)
{
$name = $this->namer->name($file, $this->config['directory_prefix']);
- $uploaded = $this->storage->upload($file, $name);
- // dispatch post upload event
- $event = new PostUploadEvent($uploaded, $this->request);
- $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $event);
+ if(!$this->config['use_orphanage'])
+ {
+ $uploaded = $this->storage->upload($file, $name);
+
+ // dispatch post upload event
+ $event = new PostPersistEvent($uploaded, $this->request);
+ $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $event);
+ }
+
+
}
return new JsonResponse(array('success' => true));
diff --git a/Event/PostUploadEvent.php b/Event/PostPersistEvent.php
similarity index 93%
rename from Event/PostUploadEvent.php
rename to Event/PostPersistEvent.php
index 132e71e..e4716c2 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostPersistEvent.php
@@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\Request;
use Gaufrette\File;
-class PostUploadEvent extends Event
+class PostPersistEvent extends Event
{
protected $file;
protected $request;
diff --git a/EventListener/SessionStoreListener.php b/EventListener/OrphanageListener.php
similarity index 65%
rename from EventListener/SessionStoreListener.php
rename to EventListener/OrphanageListener.php
index a8f25c5..ec40914 100644
--- a/EventListener/SessionStoreListener.php
+++ b/EventListener/OrphanageListener.php
@@ -7,18 +7,23 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface;
-class SessionStoreListener implements EventSubscriberInterface
+class OrphanageListener implements EventSubscriberInterface
{
- public function __construct(SessionInterface $session)
+ protected $orphanage;
+
+ public function __construct(OrphanageInterface $orphanage)
{
- $this->session = $session;
+ $this->orphanage = $orphanage;
}
public function addToSession(PostUploadEvent $event)
{
$request = $event->getRequest();
$file = $event->getFile();
+
+ $this->orphanage->addFile($file);
}
public static function getSubscribedEvents()
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index d22de7e..f7efd15 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -6,22 +6,29 @@
<parameters>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter>
+ <parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Orphanage\Orphanage</parameter>
<parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
<parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
- <parameter key="oneup_uploader.listener.session.class">Oneup\UploaderBundle\EventListener\SessionStoreListener</parameter>
+ <parameter key="oneup_uploader.listener.session.class">Oneup\UploaderBundle\EventListener\OrphanageListener</parameter>
</parameters>
<services>
<service id="oneup_uploader.chunks.manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
</service>
-
+
+ <!-- orphanage -->
<service id="oneup_uploader.orphanage.manager" class="%oneup_uploader.orphanage.manager.class%">
<argument>%oneup_uploader.orphanage%</argument>
</service>
+ <service id="oneup_uploader.orphanage" class="%oneup_uploader.orphanage.class%">
+ <argument type="service" id="session" />
+ <argument>%oneup_uploader.orphanage%</argument>
+ </service>
+
<!-- namer -->
<service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" />
@@ -31,8 +38,8 @@
</service>
<!-- events -->
- <service id="oneup_uploader.listener.session" class="%oneup_uploader.listener.session.class%">
- <argument type="service" id="session" />
+ <service id="oneup_uploader.listener.orphanage" class="%oneup_uploader.listener.session.class%">
+ <argument type="service" id="oneup_uploader.orphanage" />
<tag name="kernel.event_subscriber" />
</service>
diff --git a/UploadEvents.php b/UploadEvents.php
index 39adf0b..c319ce9 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -4,5 +4,5 @@ namespace Oneup\UploaderBundle;
final class UploadEvents
{
- const POST_UPLOAD = 'oneup.uploader.post.upload';
+ const POST_PERSIST = 'oneup.uploader.post.perist';
}
\ No newline at end of file
| 0 |
b41e553fc30a31ed62eb15830da2115db42d711f
|
1up-lab/OneupUploaderBundle
|
Fixed dependency version and hopefully also the travis builds
|
commit b41e553fc30a31ed62eb15830da2115db42d711f
Author: Jim Schmid <[email protected]>
Date: Sat May 4 13:46:43 2013 +0200
Fixed dependency version and hopefully also the travis builds
diff --git a/composer.json b/composer.json
index 6142788..5a86478 100644
--- a/composer.json
+++ b/composer.json
@@ -19,15 +19,15 @@
"require-dev": {
"knplabs/gaufrette": "0.2.*@dev",
- "symfony/class-loader": "dev-master",
- "symfony/security-bundle": "dev-master",
- "symfony/monolog-bundle": "dev-master",
- "sensio/framework-extra-bundle": "dev-master",
+ "symfony/class-loader": "2.*",
+ "symfony/security-bundle": "2.*",
+ "symfony/monolog-bundle": "2.*",
+ "sensio/framework-extra-bundle": "2.*",
"jms/serializer-bundle": "dev-master",
- "symfony/yaml": "dev-master",
+ "symfony/yaml": "2.*",
"symfony/form": "2.*",
- "symfony/twig-bundle": "dev-master",
- "symfony/browser-kit": "dev-master"
+ "symfony/twig-bundle": "2.*",
+ "symfony/browser-kit": "2.*"
},
"suggest": {
| 0 |
efdaa42ba08f672ceb101a6bdf8e8fef61904a01
|
1up-lab/OneupUploaderBundle
|
Added Orphanage-Storage.
|
commit efdaa42ba08f672ceb101a6bdf8e8fef61904a01
Author: Jim Schmid <[email protected]>
Date: Wed Mar 27 19:04:21 2013 +0100
Added Orphanage-Storage.
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
new file mode 100644
index 0000000..a463039
--- /dev/null
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Oneup\UploaderBundle\Storage;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Gaufrette\Filesystem;
+
+use Oneup\UploaderBundle\Storage\GaufretteStorage;
+
+class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface
+{
+ protected $masked;
+ protected $session;
+ protected $config;
+ protected $type;
+
+ public function __construct(Gaufrette $orphanage, Gaufrette $filesystem, SessionInterface $session, $config, $type)
+ {
+ parent::__construct($orphanage);
+
+ $this->masked = $filesystem;
+ $this->session = $session;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ public function upload(File $file, $name = null)
+ {
+ if(!$this->session->isStarted())
+ throw new \RuntimeException('You need a running session in order to run the Orphanage.');
+
+ parent::upload($file, $name);
+ }
+
+ public function uploadFiles($keep = false)
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ // switch orphanage with masked filesystem
+ $this->filesystem = $this->masked;
+
+ if(!$system->exists($this->getPath()))
+ return array();
+
+ $finder->in($this->getPathRelativeToSession())->files();
+
+ $uploaded = array();
+ foreach($finder as $file)
+ {
+ $uploaded[] = $this->upload(new UploadedFile($file->getPathname(), $file->getBasename(), null, null, null, true));
+
+ if(!$keep)
+ {
+ $system->remove($file);
+ }
+ }
+
+ return $uploaded;
+ }
+
+ protected function getPath()
+ {
+ $id = $this->session->getId();
+ $path = sprintf('%s/%s/%s', $this->config['directory'], $id, $this->type);
+
+ return $path;
+ }
+
+ protected function getPathRelativeToSession()
+ {
+ $id = $this->session->getId();
+ $path = sprintf('%s/%s', $this->config['directory'], $id);
+
+ return $path;
+ }
+}
\ No newline at end of file
diff --git a/Uploader/Storage/OrphanageStorageInterface.php b/Uploader/Storage/OrphanageStorageInterface.php
new file mode 100644
index 0000000..de0eb47
--- /dev/null
+++ b/Uploader/Storage/OrphanageStorageInterface.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use Symfony\Component\HttpFoundation\File\File;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+
+interface OrphanageStorageInterface extends StorageInterface
+{
+ public function uploadFiles($keep = false);
+}
| 0 |
564839351006a86888743e49cd984c8abd985138
|
1up-lab/OneupUploaderBundle
|
Changed generated route name as we now only have one method per mapping.
|
commit 564839351006a86888743e49cd984c8abd985138
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:29:59 2013 +0200
Changed generated route name as we now only have one method per mapping.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 3ccc0a0..016fb2b 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -38,7 +38,7 @@ class RouteLoader extends Loader
array('_method' => 'POST')
);
- $routes->add(sprintf('_uploader_%s_upload', $type), $upload);
+ $routes->add(sprintf('_uploader_%s', $type), $upload);
}
return $routes;
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.