commit_id
string | repo
string | commit_message
string | diff
string | label
int64 |
|---|---|---|---|---|
8cf97432722c844e3247c4e4a4bd7cdbdf3efb07
|
1up-lab/OneupUploaderBundle
|
This bundle does now depend on the framework-bundle.
|
commit 8cf97432722c844e3247c4e4a4bd7cdbdf3efb07
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:43:35 2013 +0200
This bundle does now depend on the framework-bundle.
diff --git a/composer.json b/composer.json
index ac64ad5..27a5d81 100644
--- a/composer.json
+++ b/composer.json
@@ -13,9 +13,7 @@
],
"require": {
- "symfony/finder": ">=2.0.16,<2.3-dev",
- "symfony/filesystem": ">=2.0.16,<2.3-dev",
- "symfony/event-dispatcher": ">=2.0.16,<2.3-dev"
+ "symfony/framework-bundle": "2.*"
},
"suggest": {
| 0
|
d6a88f980a1d49832e58cd876c8907f860d5e76a
|
1up-lab/OneupUploaderBundle
|
Update FineUploader doc to version 5
|
commit d6a88f980a1d49832e58cd876c8907f860d5e76a
Author: JHGitty <[email protected]>
Date: Sat Jan 30 16:12:36 2016 +0100
Update FineUploader doc to version 5
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
| 0
|
7943c98ea43578ddeb9492a60d292aae9bc5a0eb
|
1up-lab/OneupUploaderBundle
|
Added PHPDoc block for NamerInterface.
|
commit 7943c98ea43578ddeb9492a60d292aae9bc5a0eb
Author: Jim Schmid <[email protected]>
Date: Tue Aug 13 15:42:44 2013 +0200
Added PHPDoc block for NamerInterface.
diff --git a/Uploader/Naming/NamerInterface.php b/Uploader/Naming/NamerInterface.php
index 40ba4cd..d44b817 100644
--- a/Uploader/Naming/NamerInterface.php
+++ b/Uploader/Naming/NamerInterface.php
@@ -6,5 +6,11 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
interface NamerInterface
{
+ /**
+ * Name a given file and return the name
+ *
+ * @param UploadedFile $file
+ * @return string
+ */
public function name(UploadedFile $file);
}
| 0
|
4c954cd2baf5531b91317bbe72f00f904d47e51d
|
1up-lab/OneupUploaderBundle
|
Fix links
|
commit 4c954cd2baf5531b91317bbe72f00f904d47e51d
Author: David Greminger <[email protected]>
Date: Fri Mar 27 16:56:10 2020 +0100
Fix links
diff --git a/README.md b/README.md
index f9b252e..c404bb7 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
-* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter], @[gubler], @[patrickbussmann], @[ErnadoO] and @[enumag]), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
+* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter](https://github.com/steveWinter), @[gubler](https://github.com/gubler), @[patrickbussmann](https://github.com/patrickbussmann), @[ErnadoO](https://github.com/ErnadoO) and @[enumag](https://github.com/enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
* 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).
| 0
|
3a88954c9b402cc39c776008b96f34bb7225258a
|
1up-lab/OneupUploaderBundle
|
Increased minimum symfony/finder version to 2.2.0
This will fix #41.
|
commit 3a88954c9b402cc39c776008b96f34bb7225258a
Author: Jim Schmid <[email protected]>
Date: Mon Aug 12 11:57:30 2013 +0200
Increased minimum symfony/finder version to 2.2.0
This will fix #41.
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
|
b68f4fc37b2f5430460acc5caf7ddd8ccd549e5e
|
1up-lab/OneupUploaderBundle
|
More text on Gaufrette documentation.
|
commit b68f4fc37b2f5430460acc5caf7ddd8ccd549e5e
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 20:50:30 2013 +0200
More text on Gaufrette documentation.
diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md
index 4205957..74ec3fe 100644
--- a/Resources/doc/gaufrette_storage.md
+++ b/Resources/doc/gaufrette_storage.md
@@ -42,6 +42,8 @@ public function registerBundles()
## Configure your Filesystems
+The following is a sample configuration for the KnpGaufretteBundle. It will create a filystem service called `gaufrette.gallery_filesystem` which can be used in the OneupUploaderBundle. For a complete list of features refer to the [official documentation](https://github.com/KnpLabs/KnpGaufretteBundle).
+
```yml
knp_gaufrette:
adapters:
@@ -59,6 +61,8 @@ knp_gaufrette:
## Configure your mappings
+Activate Gaufrette by switching the `type` property to `gaufrette` and pass the Gaufrette filesystem configured in the previous step.
+
```yml
oneup_uploader:
mappings:
| 0
|
56bc64a5db84379ef6cc42c471595a3e5d0182df
|
1up-lab/OneupUploaderBundle
|
[DOC] How to move specific files out of the orphanage
This is related to the PR #115, but there was no documentation associated with it.
I never used the Finder object before so I hope my example is relevant. In any case, this is definitely something to document.
|
commit 56bc64a5db84379ef6cc42c471595a3e5d0182df
Author: Schyzophrenic <[email protected]>
Date: Fri Nov 28 18:14:34 2014 +0100
[DOC] How to move specific files out of the orphanage
This is related to the PR #115, but there was no documentation associated with it.
I never used the Finder object before so I hope my example is relevant. In any case, this is definitely something to document.
diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index 6848615..9e4db06 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -53,6 +53,18 @@ class AcmeController extends Controller
You will get an array containing the moved files.
+Note that you can move only one or a set of defined files out of the orphanage by passing an array to $manager->getFiles().
+For instance, you can use this to move a specific file:
+```php
+ // get files
+ $files = $manager->getFiles();
+
+ // reduce the scope of the Finder object to what you want
+ $files->files()->name($filename);
+ $manager->uploadFiles(iterator_to_array($files));
+```
+In this example, $filename is the name of the file you want to move out of the orphanage.
+
> If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `SplFileInfo`.
## Configure the Orphanage
| 0
|
1b0bc70271660f126481d8cbe2f41423ad002704
|
1up-lab/OneupUploaderBundle
|
Require symfony/http-foundation in compatible version
|
commit 1b0bc70271660f126481d8cbe2f41423ad002704
Author: David Greminger <[email protected]>
Date: Tue Feb 4 14:27:44 2020 +0100
Require symfony/http-foundation in compatible version
diff --git a/.travis.yml b/.travis.yml
index 0cc8236..f5b74fe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,7 +26,7 @@ before_install:
- travis_retry composer selfupdate
before_script:
- - travis_wait composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
+ - travis_wait composer require symfony/framework-bundle:${SYMFONY_VERSION} symfony/http-foundation:${SYMFONY_VERSION} --prefer-source
- travis_wait composer install --dev --prefer-source
script: ./vendor/bin/phpunit
diff --git a/composer.json b/composer.json
index c0c4941..fe94046 100644
--- a/composer.json
+++ b/composer.json
@@ -25,6 +25,7 @@
"symfony/asset": "^3.0|^4.0",
"symfony/finder": "^3.0|^4.0",
"symfony/framework-bundle": "^3.0|^4.0",
+ "symfony/http-foundation": "^3.0|^4.0",
"symfony/templating": "^3.0|^4.0",
"symfony/translation": "^3.0|^4.0",
"symfony/yaml": "^3.0|^4.0"
| 0
|
7fd33d564b32740712fdad082a02a282dcabf3f2
|
1up-lab/OneupUploaderBundle
|
Readded symfony/class-loader for Symfony2.1 tests.
|
commit 7fd33d564b32740712fdad082a02a282dcabf3f2
Author: Jim Schmid <[email protected]>
Date: Tue Aug 13 16:52:35 2013 +0200
Readded symfony/class-loader for Symfony2.1 tests.
diff --git a/composer.json b/composer.json
index f2b846a..2dfd657 100644
--- a/composer.json
+++ b/composer.json
@@ -22,6 +22,7 @@
"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.*",
| 0
|
fc1bd5ead3c90b3bcf62dda3e1f7929e42782e00
|
1up-lab/OneupUploaderBundle
|
made scrutiziner happier
|
commit fc1bd5ead3c90b3bcf62dda3e1f7929e42782e00
Author: mitom <[email protected]>
Date: Thu Oct 10 15:11:29 2013 +0200
made scrutiziner happier
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 0b92d58..e9e05a8 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -48,9 +48,6 @@ abstract class AbstractChunkedController extends AbstractController
$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);
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 5f5ece9..b5e2ab5 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -33,11 +33,7 @@ class OneupUploaderExtension extends Extension
}
$this->createChunkStorageService();
-
- $this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ?
- sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir')) :
- $this->normalizePath($this->config['orphanage']['directory'])
- ;
+ $this->processOrphanageConfig();
$container->setParameter('oneup_uploader.chunks', $this->config['chunks']);
$container->setParameter('oneup_uploader.orphanage', $this->config['orphanage']);
@@ -46,58 +42,71 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach ($this->config['mappings'] as $key => $mapping) {
- $mapping['max_size'] = $mapping['max_size'] < 0 ?
- $this->getMaxUploadSize($mapping['max_size']) :
- $mapping['max_size']
- ;
+ $this->processMapping($key, $mapping);
+ }
+
+ $container->setParameter('oneup_uploader.controllers', $controllers);
+ }
+
+ protected function processOrphanageConfig()
+ {
+ $this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ?
+ sprintf('%s/uploader/orphanage', $this->container->getParameter('kernel.cache_dir')) :
+ $this->normalizePath($this->config['orphanage']['directory'])
+ ;
+ }
- // create the storage service according to the configuration
- $storageService = $this->createStorageService($mapping['storage'], $key, isset($mapping['orphanage']) ? :null);
+ protected function processMapping($key, &$mapping)
+ {
+ $mapping['max_size'] = $mapping['max_size'] < 0 ?
+ $this->getMaxUploadSize($mapping['max_size']) :
+ $mapping['max_size']
+ ;
- if ($mapping['frontend'] != 'custom') {
- $controllerName = sprintf('oneup_uploader.controller.%s', $key);
- $controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $mapping['frontend']);
- } else {
- $customFrontend = $mapping['custom_frontend'];
+ // create the storage service according to the configuration
+ $storageService = $this->createStorageService($mapping['storage'], $key, isset($mapping['orphanage']) ? :null);
- $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
- $controllerType = $customFrontend['class'];
+ if ($mapping['frontend'] != 'custom') {
+ $controllerName = sprintf('oneup_uploader.controller.%s', $key);
+ $controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $mapping['frontend']);
+ } else {
+ $customFrontend = $mapping['custom_frontend'];
- if(empty($controllerName) || empty($controllerType))
- 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.');
- }
+ $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
+ $controllerType = $customFrontend['class'];
- $errorHandler = is_null($mapping['error_handler']) ?
- new Reference('oneup_uploader.error_handler.'.$mapping['frontend']) :
- new Reference($mapping['error_handler']);
+ if(empty($controllerName) || empty($controllerType))
+ 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.');
+ }
- // create controllers based on mapping
- $container
- ->register($controllerName, $controllerType)
+ $errorHandler = is_null($mapping['error_handler']) ?
+ new Reference('oneup_uploader.error_handler.'.$mapping['frontend']) :
+ new Reference($mapping['error_handler']);
- ->addArgument(new Reference('service_container'))
- ->addArgument($storageService)
- ->addArgument($errorHandler)
- ->addArgument($mapping)
- ->addArgument($key)
+ // create controllers based on mapping
+ $this->container
+ ->register($controllerName, $controllerType)
- ->addTag('oneup_uploader.routable', array('type' => $key))
- ->setScope('request')
- ;
+ ->addArgument(new Reference('service_container'))
+ ->addArgument($storageService)
+ ->addArgument($errorHandler)
+ ->addArgument($mapping)
+ ->addArgument($key)
- if ($mapping['enable_progress'] || $mapping['enable_cancelation']) {
- if (strnatcmp(phpversion(), '5.4.0') < 0) {
- throw new InvalidArgumentException('You need to run PHP version 5.4.0 or above to use the progress/cancelation feature.');
- }
- }
+ ->addTag('oneup_uploader.routable', array('type' => $key))
+ ->setScope('request')
+ ;
- $controllers[$key] = array($controllerName, array(
- 'enable_progress' => $mapping['enable_progress'],
- 'enable_cancelation' => $mapping['enable_cancelation']
- ));
+ if ($mapping['enable_progress'] || $mapping['enable_cancelation']) {
+ if (strnatcmp(phpversion(), '5.4.0') < 0) {
+ throw new InvalidArgumentException('You need to run PHP version 5.4.0 or above to use the progress/cancelation feature.');
+ }
}
- $container->setParameter('oneup_uploader.controllers', $controllers);
+ $controllers[$key] = array($controllerName, array(
+ 'enable_progress' => $mapping['enable_progress'],
+ 'enable_cancelation' => $mapping['enable_cancelation']
+ ));
}
protected function createChunkStorageService()
@@ -130,7 +139,7 @@ class OneupUploaderExtension extends Extension
}
}
- protected function createStorageService($config, $key, $orphanage = null)
+ protected function createStorageService(&$config, $key, $orphanage = null)
{
$storageService = null;
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 98707b7..4f5a286 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -57,7 +57,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
try {
$this->filesystem->delete($key);
} catch (\Exception $e) {
- //do nothing
+ continue;
}
}
}
@@ -81,8 +81,6 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
'chunk' => $chunk,
'original' => $original
);
-
- return;
}
public function assembleChunks($chunks, $removeChunk, $renameChunk)
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 0c73be5..0b6904b 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -42,6 +42,8 @@ class GaufretteFile extends File implements FileInterface
// Fail gracefully if there was a problem with opening the file and
// let gaufrette load the file into memory allowing it to throw exceptions
// if that doesn't work either.
+ // Not empty to make the scrutiziner happy.
+ return parent::getSize();
}
}
}
| 0
|
4aac33eb36be7760ee5449cfc6100250e54401a2
|
1up-lab/OneupUploaderBundle
|
Merge branch 'ThomasLandauer-master'
|
commit 4aac33eb36be7760ee5449cfc6100250e54401a2 (from 15f3614144d72b166d82a3e1586c2e66a357c0d1)
Merge: 15f3614 b6d5a57
Author: David Greminger <[email protected]>
Date: Fri Dec 23 15:05:08 2016 +0100
Merge branch '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
| 0
|
06bbbe2a98e10dbab2cb487c78487bb7937f7a9b
|
1up-lab/OneupUploaderBundle
|
Fixes wrong class name in RouteLoaderTest.
|
commit 06bbbe2a98e10dbab2cb487c78487bb7937f7a9b
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:50:19 2013 +0200
Fixes wrong class name in RouteLoaderTest.
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index c1e6edd..4bd7ca9 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Tests\Routing;
use Oneup\UploaderBundle\Routing\RouteLoader;
-class RoutingTest extends \PHPUnit_Framework_TestCase
+class RouteLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testRouteLoader()
{
| 0
|
1fd249208fd44bb89ebd93a21d8a7e6f2f9af505
|
1up-lab/OneupUploaderBundle
|
Changed request to master request
|
commit 1fd249208fd44bb89ebd93a21d8a7e6f2f9af505
Author: Martin Aarhof <[email protected]>
Date: Wed Dec 9 10:25:43 2015 +0100
Changed request to master request
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 62f9df1..4cd14c2 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -45,7 +45,7 @@ abstract class AbstractChunkedController extends AbstractController
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
// get basic container stuff
- $request = $this->container->get('request');
+ $request = $this->container->get('request_stack')->getMasterRequest();
$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..7341727 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -38,7 +38,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 +54,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 +73,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 +100,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 +129,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 +147,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 +171,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);
}
@@ -188,7 +188,7 @@ abstract class AbstractController
*/
protected function createSupportedJsonResponse($data)
{
- $request = $this->container->get('request');
+ $request = $this->getRequest();
$response = new JsonResponse($data);
$response->headers->set('Vary', 'Accept');
@@ -198,4 +198,15 @@ abstract class AbstractController
return $response;
}
+
+ /**
+ * Get the master request
+ *
+ * @return Request
+ */
+ protected function getRequest()
+ {
+ 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..11b5339 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);
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..59fc218 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,7 @@
],
"require": {
- "symfony/framework-bundle": ">=2.2",
+ "symfony/framework-bundle": ">=2.4",
"symfony/finder": ">=2.2.0"
},
| 0
|
f7ef19a152ab4d8827807fa5e670f7bb1300bf5d
|
1up-lab/OneupUploaderBundle
|
Swapped variables.
|
commit f7ef19a152ab4d8827807fa5e670f7bb1300bf5d
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 17:13:05 2013 +0200
Swapped variables.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 8174498..f643686 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -113,8 +113,8 @@ class OneupUploaderExtension extends Extension
{
$customFrontend = $mapping['custom_frontend'];
- $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['class']);
- $controllerType = $customFrontend['name'];
+ $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
+ $controllerType = $customFrontend['class'];
if(empty($controllerName) || empty($controllerType))
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.');
| 0
|
56143a378caa904079ef1fdfbb14dc06535a8d09
|
1up-lab/OneupUploaderBundle
|
Moved file retrieval of MooController to a separte function in order to be able to test it.
|
commit 56143a378caa904079ef1fdfbb14dc06535a8d09
Author: Jim Schmid <[email protected]>
Date: Fri May 31 17:40:37 2013 +0200
Moved file retrieval of MooController to a separte function in order to be able to test it.
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 949663d..9dc64b4 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;
+ $file = $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 $file;
+ }
}
\ No newline at end of file
| 0
|
85dd84a7577795dbad6d19ae364a8c158f07da24
|
1up-lab/OneupUploaderBundle
|
had to lower interface requirements for the controllers
|
commit 85dd84a7577795dbad6d19ae364a8c158f07da24
Author: mitom <[email protected]>
Date: Thu Oct 10 16:36:49 2013 +0200
had to lower interface requirements for the controllers
diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php
index ae73615..f2613bf 100644
--- a/Uploader/Storage/FilesystemStorage.php
+++ b/Uploader/Storage/FilesystemStorage.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
-class FilesystemStorage implements FilesystemStorageInterface
+class FilesystemStorage implements StorageInterface
{
protected $directory;
@@ -13,7 +13,7 @@ class FilesystemStorage implements FilesystemStorageInterface
$this->directory = $directory;
}
- public function upload(FilesystemFile $file, $name, $path = null)
+ public function upload($file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
$path = sprintf('%s/%s', $this->directory, $path);
diff --git a/Uploader/Storage/FilesystemStorageInterface.php b/Uploader/Storage/FilesystemStorageInterface.php
deleted file mode 100644
index 875ea4a..0000000
--- a/Uploader/Storage/FilesystemStorageInterface.php
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Uploader\Storage;
-
-use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
-
-interface FilesystemStorageInterface
-{
- /**
- * Uploads a File instance to the configured storage.
- * Requires local files, it doesn't make sense to upload to
- * a graufrette filesystem first, and then move it to a local one.
- *
- * @param FilesystemFile $file
- * @param string $name
- * @param string $path
- */
- public function upload(FilesystemFile $file, $name, $path = null);
-}
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index c376167..1c0bc9c 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -19,7 +19,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
- public function upload(FileInterface $file, $name, $path = null)
+ public function upload($file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index a50a3bd..ffdd2ae 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Finder\Finder;
@@ -28,7 +29,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte
$this->type = $type;
}
- public function upload(FileInterface $file, $name, $path = null)
+ public function upload($file, $name, $path = null)
{
if(!$this->session->isStarted())
throw new \RuntimeException('You need a running session in order to run the Orphanage.');
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index d028b9b..0c7e4b5 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -9,9 +9,9 @@ interface StorageInterface
/**
* Uploads a File instance to the configured storage.
*
- * @param FileInterface $file
+ * @param $file
* @param string $name
* @param string $path
*/
- public function upload(FileInterface $file, $name, $path = null);
+ public function upload($file, $name, $path = null);
}
| 0
|
1f9dbbc3ca57fc5a890e98bd9c55560463198547
|
1up-lab/OneupUploaderBundle
|
Added cancel helper functions incl. Twig extension.
|
commit 1f9dbbc3ca57fc5a890e98bd9c55560463198547
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 11:28:41 2013 +0200
Added cancel helper functions incl. Twig extension.
diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php
index f4a3490..c433675 100644
--- a/Templating/Helper/UploaderHelper.php
+++ b/Templating/Helper/UploaderHelper.php
@@ -29,6 +29,11 @@ class UploaderHelper extends Helper
return $this->router->generate(sprintf('_uploader_progress_%s', $key));
}
+ public function cancel($key)
+ {
+ return $this->router->generate(sprintf('_uploader_cancel_%s', $key));
+ }
+
public function uploadKey()
{
return ini_get('session.upload_progress.name');
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index e33b9b4..2665a89 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -23,6 +23,7 @@ class UploaderExtension extends \Twig_Extension
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')
);
}
@@ -37,6 +38,11 @@ class UploaderExtension extends \Twig_Extension
return $this->helper->progress($key);
}
+ public function cancel($key)
+ {
+ return $this->helper->cancel($key);
+ }
+
public function uploadKey()
{
return $this->helper->uploadKey();
| 0
|
1538a2bc1afc2d53f347b5e4d9bd38a6043564c2
|
1up-lab/OneupUploaderBundle
|
composer added http-kernel
|
commit 1538a2bc1afc2d53f347b5e4d9bd38a6043564c2
Author: Martin Aarhof <[email protected]>
Date: Wed Dec 9 19:23:53 2015 +0100
composer added http-kernel
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 5374a8c..8b1dfc5 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -207,6 +207,7 @@ abstract class AbstractController
*/
protected function getRequest()
{
+
if (version_compare(Kernel::VERSION, '2.4', '<=')) {
return $this->container->get('request');
}
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"
},
| 0
|
0b56f487d7eaea52c5dafba82ecceade9f48e343
|
1up-lab/OneupUploaderBundle
|
Cleaned up the mess around ResponseInterface & AbstractResponse
Previsouly both the ResponseInterface and the AbstractResponse - which implemented the Interface - declared the function 'assemble' abstract. This fixes #13.
|
commit 0b56f487d7eaea52c5dafba82ecceade9f48e343
Author: Jim Schmid <[email protected]>
Date: Sun Apr 28 10:58:09 2013 +0200
Cleaned up the mess around ResponseInterface & AbstractResponse
Previsouly both the ResponseInterface and the AbstractResponse - which implemented the Interface - declared the function 'assemble' abstract. This fixes #13.
diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php
index c6b9145..11f67f7 100644
--- a/Uploader/Response/AbstractResponse.php
+++ b/Uploader/Response/AbstractResponse.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Uploader\Response;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
-abstract class AbstractResponse implements ResponseInterface
+abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
{
protected $data;
@@ -12,8 +12,6 @@ abstract class AbstractResponse implements ResponseInterface
{
$this->data = array();
}
-
- abstract public function assemble();
public function offsetSet($offset, $value)
{
diff --git a/Uploader/Response/ResponseInterface.php b/Uploader/Response/ResponseInterface.php
index b1e835e..65fe303 100644
--- a/Uploader/Response/ResponseInterface.php
+++ b/Uploader/Response/ResponseInterface.php
@@ -2,7 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Response;
-interface ResponseInterface extends \ArrayAccess
+interface ResponseInterface
{
public function assemble();
}
\ No newline at end of file
| 0
|
d60f1ae8960853385ad3f803bb3fcd3a5651c2c6
|
1up-lab/OneupUploaderBundle
|
Allow PUT and PATCH verbs for upload
|
commit d60f1ae8960853385ad3f803bb3fcd3a5651c2c6
Author: Giorgio Premi <[email protected]>
Date: Mon Mar 2 12:45:23 2015 +0100
Allow PUT and PATCH verbs for upload
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 4e8df11..cd8c070 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -36,7 +36,7 @@ class RouteLoader extends Loader
array(),
'',
array(),
- array('POST')
+ array('POST', 'PUT', 'PATCH')
);
if ($options['enable_progress'] === true) {
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index b5460ef..2b0abf7 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -51,14 +51,16 @@ abstract class AbstractControllerTest extends WebTestCase
$this->implTestCallBy('DELETE');
}
+ public function testCallByPatch()
+ {
+ $this->implTestCallBy('PATCH');
+ }
+
public function testCallByPost()
{
$this->implTestCallBy('POST');
}
- /**
- * @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
- */
public function testCallByPut()
{
$this->implTestCallBy('PUT');
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index a09385e..95b35ab 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -34,7 +34,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertEquals('json', $route->getDefault('_format'));
- $this->assertEquals(array('POST'), $route->getMethods());
+ $this->assertContains('POST', $route->getMethods());
}
}
@@ -56,7 +56,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertEquals('json', $route->getDefault('_format'));
- $this->assertEquals(array('POST'), $route->getMethods());
+ $this->assertContains('POST', $route->getMethods());
$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
| 0
|
74453d48200ea6847c13dd246515c0f419bb1f55
|
1up-lab/OneupUploaderBundle
|
version 1.4 seems outdated
I think is better to skip the version part in installation with composer, nowadays composer seems smart enough to catch the right stable version; so you don't need to keep track of this small but important changes to docs
|
commit 74453d48200ea6847c13dd246515c0f419bb1f55
Author: m47730 <[email protected]>
Date: Mon Oct 23 15:58:34 2017 +0200
version 1.4 seems outdated
I think is better to skip the version part in installation with composer, nowadays composer seems smart enough to catch the right stable version; so you don't need to keep track of this small but important changes to docs
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 3942d44..2e5f82e 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -34,7 +34,7 @@ Perform the following steps to install and use the basic functionality of the On
Add OneupUploaderBundle to your composer.json using the following construct:
- $ composer require oneup/uploader-bundle "~1.4"
+ $ composer require oneup/uploader-bundle
Composer will install the bundle to your project's ``vendor/oneup/uploader-bundle`` directory.
| 0
|
2c4b17dbc589c2c716e4008a7b27633d3d3864da
|
1up-lab/OneupUploaderBundle
|
Darn, forgot to delete some debug stuff in AbstractController.
|
commit 2c4b17dbc589c2c716e4008a7b27633d3d3864da
Author: Jim Schmid <[email protected]>
Date: Thu Apr 18 19:08:49 2013 +0200
Darn, forgot to delete some debug stuff in AbstractController.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 75e1cc8..ac8a1f0 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -55,8 +55,6 @@ abstract class AbstractController
$dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent);
- var_dump(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type));
-
if(!$this->config['use_orphanage'])
{
// dispatch post persist event (both the specific and the general)
| 0
|
abe30c93f25b816fe66d4b9519866de2ecc0e029
|
1up-lab/OneupUploaderBundle
|
Run tests instead of skip them (#393)
|
commit abe30c93f25b816fe66d4b9519866de2ecc0e029
Author: David Greminger <[email protected]>
Date: Sat Dec 5 11:05:05 2020 +0100
Run tests instead of skip them (#393)
diff --git a/tests/Controller/AbstractValidationTest.php b/tests/Controller/AbstractValidationTest.php
index 7431df8..8b9803a 100644
--- a/tests/Controller/AbstractValidationTest.php
+++ b/tests/Controller/AbstractValidationTest.php
@@ -106,8 +106,6 @@ abstract class AbstractValidationTest extends AbstractControllerTest
public function testAgainstIncorrectMimeType(): void
{
- $this->markTestSkipped('Mock mime type getter.');
-
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
diff --git a/tests/Controller/BlueimpValidationTest.php b/tests/Controller/BlueimpValidationTest.php
index a2cf5ec..eb68247 100644
--- a/tests/Controller/BlueimpValidationTest.php
+++ b/tests/Controller/BlueimpValidationTest.php
@@ -71,8 +71,6 @@ class BlueimpValidationTest extends AbstractValidationTest
public function testAgainstIncorrectMimeType(): void
{
- $this->markTestSkipped('Mock mime type getter.');
-
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
| 0
|
c9c4c1946b430f1d1226958176eb2a26d71cc5e4
|
1up-lab/OneupUploaderBundle
|
Removed unused variables on YUI3Controller.
|
commit c9c4c1946b430f1d1226958176eb2a26d71cc5e4
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 11:25:42 2013 +0200
Removed unused variables on YUI3Controller.
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index 8ade2ec..b063e92 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -13,9 +13,6 @@ class YUI3Controller 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
|
ca5fef66aacb89a73eb49f5d9962df61e1d138c8
|
1up-lab/OneupUploaderBundle
|
Don't label bug issues as stale
|
commit ca5fef66aacb89a73eb49f5d9962df61e1d138c8
Author: David Greminger <[email protected]>
Date: Tue Sep 8 08:34:14 2020 +0200
Don't label bug issues as stale
diff --git a/.github/stale.yml b/.github/stale.yml
index aa1ae8c..068b8a2 100644
--- a/.github/stale.yml
+++ b/.github/stale.yml
@@ -6,6 +6,7 @@ daysUntilClose: 7
exemptLabels:
- postponed
- enhancement
+ - bug
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
| 0
|
8279b7e418340ee66d4f625ab1f1d485415dec60
|
1up-lab/OneupUploaderBundle
|
Improve custom namer doc
|
commit 8279b7e418340ee66d4f625ab1f1d485415dec60
Author: JHGitty <[email protected]>
Date: Sat Jan 30 15:53:32 2016 +0100
Improve custom namer doc
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index c83002d..bc4240f 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;
@@ -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.
| 0
|
db50c6257f464f9235869cfe01703bc8f698ddfe
|
1up-lab/OneupUploaderBundle
|
Added Tests for Plupload, Uploadify and YUI3 Controller.
|
commit db50c6257f464f9235869cfe01703bc8f698ddfe
Author: Jim Schmid <[email protected]>
Date: Mon May 6 23:02:52 2013 +0200
Added Tests for Plupload, Uploadify and YUI3 Controller.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 7e78b16..d5265b7 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -34,6 +34,21 @@ oneup_uploader:
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+ yui3:
+ frontend: yui3
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
+ plupload:
+ frontend: plupload
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
+ uploadify:
+ frontend: uploadify
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
blueimp:
frontend: blueimp
storage:
diff --git a/Tests/Controller/PluploadTest.php b/Tests/Controller/PluploadTest.php
new file mode 100644
index 0000000..ddc337f
--- /dev/null
+++ b/Tests/Controller/PluploadTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class PluploadTest extends AbstractControllerTest
+{
+ protected function getConfigKey()
+ {
+ return 'plupload';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getRequestFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.txt',
+ 'text/plain',
+ 128
+ );
+ }
+}
diff --git a/Tests/Controller/UploadifyTest.php b/Tests/Controller/UploadifyTest.php
new file mode 100644
index 0000000..8876760
--- /dev/null
+++ b/Tests/Controller/UploadifyTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class UploadifyTest extends AbstractControllerTest
+{
+ protected function getConfigKey()
+ {
+ return 'uploadify';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getRequestFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.txt',
+ 'text/plain',
+ 128
+ );
+ }
+}
diff --git a/Tests/Controller/YUI3Test.php b/Tests/Controller/YUI3Test.php
new file mode 100644
index 0000000..521d890
--- /dev/null
+++ b/Tests/Controller/YUI3Test.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class YUI3Test extends AbstractControllerTest
+{
+ protected function getConfigKey()
+ {
+ return 'yui3';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getRequestFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.txt',
+ 'text/plain',
+ 128
+ );
+ }
+}
| 0
|
4674d09bebe1f0ee1a8bac9800f64c980e00147a
|
1up-lab/OneupUploaderBundle
|
Changed validation event name.
|
commit 4674d09bebe1f0ee1a8bac9800f64c980e00147a
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 19:15:31 2013 +0200
Changed validation event name.
diff --git a/UploadEvents.php b/UploadEvents.php
index 8bec67f..b4e6aeb 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -6,5 +6,5 @@ final class UploadEvents
{
const POST_PERSIST = 'oneup_uploader.post_persist';
const POST_UPLOAD = 'oneup_uploader.post_upload';
- const VALIDATION = 'oneup_uploader.validate';
+ const VALIDATION = 'oneup_uploader.validation';
}
\ No newline at end of file
| 0
|
5e0567fd1ffea6b99231f0c9965296a080855f2f
|
1up-lab/OneupUploaderBundle
|
Clearified the previous comments.
|
commit 5e0567fd1ffea6b99231f0c9965296a080855f2f
Author: Jim Schmid <[email protected]>
Date: Fri May 31 18:15:52 2013 +0200
Clearified the previous comments.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 3bd1247..de094cb 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -31,7 +31,7 @@ abstract class AbstractChunkedController extends AbstractController
*
* This function also calls the chunk manager if the function
* parseChunkedRequest has set true for the "last" key of the
- * returned array.
+ * returned array to reassemble the uploaded chunks.
*
* @param file The uploaded chunk.
*/
| 0
|
47c9e32a13e4cec964845e6ad09708643b66fe79
|
1up-lab/OneupUploaderBundle
|
remove file from gaufrette chunk storage after upload
|
commit 47c9e32a13e4cec964845e6ad09708643b66fe79
Author: mitom <[email protected]>
Date: Mon Oct 14 11:18:00 2013 +0200
remove file from gaufrette chunk storage after upload
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
|
de4fb3797e133b11198e0d577fd8fec4de740495
|
1up-lab/OneupUploaderBundle
|
Fix broken links in doc (#443)
|
commit de4fb3797e133b11198e0d577fd8fec4de740495
Author: Jérémy DECOOL <[email protected]>
Date: Thu Mar 21 08:58:08 2024 +0100
Fix broken links in doc (#443)
diff --git a/doc/frontend_blueimp.md b/doc/frontend_blueimp.md
index 86ba4ef..69d05a2 100644
--- a/doc/frontend_blueimp.md
+++ b/doc/frontend_blueimp.md
@@ -46,7 +46,7 @@ security:
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_dropzone.md b/doc/frontend_dropzone.md
index e1cb572..1d6302a 100644
--- a/doc/frontend_dropzone.md
+++ b/doc/frontend_dropzone.md
@@ -26,7 +26,7 @@ Be sure to check out the [official manual](http://www.dropzonejs.com/) for detai
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_fancyupload.md b/doc/frontend_fancyupload.md
index 5cf7bb5..95952c1 100644
--- a/doc/frontend_fancyupload.md
+++ b/doc/frontend_fancyupload.md
@@ -110,7 +110,7 @@ Be sure to check out the [official manual](http://digitarald.de/project/fancyupl
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_fineuploader.md b/doc/frontend_fineuploader.md
index 0976de5..fb83118 100644
--- a/doc/frontend_fineuploader.md
+++ b/doc/frontend_fineuploader.md
@@ -38,7 +38,7 @@ Be sure to check out the [official manual](https://github.com/FineUploader/fine-
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_mooupload.md b/doc/frontend_mooupload.md
index 68e1ac0..2f99ca2 100644
--- a/doc/frontend_mooupload.md
+++ b/doc/frontend_mooupload.md
@@ -37,7 +37,7 @@ Be sure to check out the [official manual](https://github.com/juanparati/MooUplo
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_plupload.md b/doc/frontend_plupload.md
index 3dac128..511fcf0 100644
--- a/doc/frontend_plupload.md
+++ b/doc/frontend_plupload.md
@@ -52,7 +52,7 @@ security:
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/doc/frontend_uploadify.md b/doc/frontend_uploadify.md
index 0e005d9..70774c6 100644
--- a/doc/frontend_uploadify.md
+++ b/doc/frontend_uploadify.md
@@ -39,7 +39,7 @@ Be sure to check out the [official manual](http://www.uploadify.com/documentatio
Next steps
----------
-After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/Resources/doc/index.md#next-steps).
+After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
diff --git a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
index 3a6c06e..8a4f5c8 100644
--- a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
+++ b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
@@ -65,8 +65,8 @@ class GaufretteAmazonS3StorageTest extends TestCase
fclose($pointer);
$service = new AmazonClient([
- 'key' => getenv('AWS_ACCESS_KEY_ID'),
- 'secret' => getenv('AWS_SECRET_ACCESS_KEY'),
+ 'key' => getenv('AWS_ACCESS_KEY_ID'),
+ 'secret' => getenv('AWS_SECRET_ACCESS_KEY'),
]);
$adapter = new S3Adapter($service, getenv('AWS_BUCKET'));
$this->filesystem = new GaufretteFilesystem($adapter);
| 0
|
71bb2be5fb0afdf30f5dbfb2cccf280af994a432
|
1up-lab/OneupUploaderBundle
|
Added Upgrade notes for version 0.9.5
|
commit 71bb2be5fb0afdf30f5dbfb2cccf280af994a432
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 21:57:32 2013 +0300
Added Upgrade notes for version 0.9.5
diff --git a/README.md b/README.md
index d828af8..2592a61 100644
--- a/README.md
+++ b/README.md
@@ -30,7 +30,8 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
-Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version 0.9.3, update your EventListener accordingly.
+* Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly.
+* 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).
License
-------
| 0
|
39c94c573d5ae718efa305944600fd65d0219573
|
1up-lab/OneupUploaderBundle
|
fixed messy type hinting for more comprehensible structure
|
commit 39c94c573d5ae718efa305944600fd65d0219573
Author: mitom <[email protected]>
Date: Thu Oct 10 14:54:23 2013 +0200
fixed messy type hinting for more comprehensible structure
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 6d5f0b4..03e14cb 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -6,7 +6,6 @@ use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\FileBag;
diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php
index c6c9001..ae73615 100644
--- a/Uploader/Storage/FilesystemStorage.php
+++ b/Uploader/Storage/FilesystemStorage.php
@@ -2,10 +2,9 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Oneup\UploaderBundle\Uploader\File\FileInterface;
-use Symfony\Component\HttpFoundation\File\File;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
-class FilesystemStorage implements StorageInterface
+class FilesystemStorage implements FilesystemStorageInterface
{
protected $directory;
@@ -14,12 +13,8 @@ class FilesystemStorage implements StorageInterface
$this->directory = $directory;
}
- public function upload(FileInterface $file, $name, $path = null)
+ public function upload(FilesystemFile $file, $name, $path = null)
{
- if (!($file instanceof File)) {
- throw new \InvalidArgumentException('file must be an instance of Symfony\Component\HttpFoundation\File\File');
- }
-
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
$path = sprintf('%s/%s', $this->directory, $path);
diff --git a/Uploader/Storage/FilesystemStorageInterface.php b/Uploader/Storage/FilesystemStorageInterface.php
new file mode 100644
index 0000000..875ea4a
--- /dev/null
+++ b/Uploader/Storage/FilesystemStorageInterface.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+
+interface FilesystemStorageInterface
+{
+ /**
+ * Uploads a File instance to the configured storage.
+ * Requires local files, it doesn't make sense to upload to
+ * a graufrette filesystem first, and then move it to a local one.
+ *
+ * @param FilesystemFile $file
+ * @param string $name
+ * @param string $path
+ */
+ public function upload(FilesystemFile $file, $name, $path = null);
+}
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index a9e2332..d028b9b 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -3,16 +3,15 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
-use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
{
/**
* Uploads a File instance to the configured storage.
*
- * @param File $file
- * @param string $name
- * @param string $path
+ * @param FileInterface $file
+ * @param string $name
+ * @param string $path
*/
public function upload(FileInterface $file, $name, $path = null);
}
| 0
|
c48a3db300cf8898bb2182812f1dfb5bd5e28bc8
|
1up-lab/OneupUploaderBundle
|
bugfix: when using AwsS3 adapter the mimeType was not being set.
|
commit c48a3db300cf8898bb2182812f1dfb5bd5e28bc8
Author: Paulo Ribeiro <[email protected]>
Date: Wed Mar 26 09:53:42 2014 -0300
bugfix: when using AwsS3 adapter the mimeType was not being set.
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 0b6904b..68c51b6 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -79,6 +79,11 @@ 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) {
+ $metadata = $this->filesystem->getAdapter()->getMetadata($this->getBasename());
+ if (isset($metadata['ContentType'])) {
+ $this->mimeType = $metadata['ContentType'];
+ }
}
return $this->mimeType;
| 0
|
e39ec00ec362fec0e2df73d707b86b53ee85cc31
|
1up-lab/OneupUploaderBundle
|
Makes the buffer size for syncing files to gaufrette storages customizable.
This fixes #37.
|
commit e39ec00ec362fec0e2df73d707b86b53ee85cc31
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 20:16:55 2013 +0200
Makes the buffer size for syncing files to gaufrette storages customizable.
This fixes #37.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 8543d7d..6472e05 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -57,6 +57,7 @@ class Configuration implements ConfigurationInterface
->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
+ ->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->end()
->end()
->arrayNode('allowed_extensions')
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 4e9b72a..fa4cb90 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -84,6 +84,7 @@ class OneupUploaderExtension extends Extension
$container
->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $mapping['storage']['type']))
->addArgument(new Reference($mapping['storage']['filesystem']))
+ ->addArgument($this->getValueInBytes($mapping['storage']['sync_buffer_size']))
;
}
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index 7273963..b75fee4 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -26,11 +26,12 @@ oneup_uploader:
type: filesystem
filesystem: ~
directory: ~
+ sync_buffer_size: 100K
allowed_extensions: []
disallowed_extensions: []
allowed_mimetypes: []
disallowed_mimetypes: []
- error_handler: oneup_uploader.error_handler.noop
+ error_handler: oneup_uploader.error_handler.noop
# Set max_size to -1 for gracefully downgrade this number to the systems max upload size.
max_size: 9223372036854775807
diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md
index 14e1788..6c93347 100644
--- a/Resources/doc/gaufrette_storage.md
+++ b/Resources/doc/gaufrette_storage.md
@@ -74,3 +74,17 @@ oneup_uploader:
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`.
+
+```yml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ type: gaufrette
+ filesystem: gaufrette.gallery_filesystem
+ sync_buffer_size: 1M
+```
+
diff --git a/Tests/Uploader/Storage/GaufretteStorageTest.php b/Tests/Uploader/Storage/GaufretteStorageTest.php
index d2656ee..f9ecfe6 100644
--- a/Tests/Uploader/Storage/GaufretteStorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteStorageTest.php
@@ -28,7 +28,7 @@ class GaufretteStorageTest extends \PHPUnit_Framework_TestCase
$adapter = new Adapter($this->directory, true);
$filesystem = new GaufretteFilesystem($adapter);
- $this->storage = new GaufretteStorage($filesystem);
+ $this->storage = new GaufretteStorage($filesystem, 100000);
}
public function testUpload()
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index ea8a6b3..2fbd349 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -13,10 +13,12 @@ use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
class GaufretteStorage implements StorageInterface
{
protected $filesystem;
+ protected $bufferSize;
- public function __construct(Filesystem $filesystem)
+ public function __construct(Filesystem $filesystem, $bufferSize)
{
$this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
}
public function upload(File $file, $name, $path = null)
@@ -40,7 +42,7 @@ class GaufretteStorage implements StorageInterface
$dst->open(new StreamMode('wb+'));
while (!$src->eof()) {
- $data = $src->read(100000);
+ $data = $src->read($this->bufferSize);
$written = $dst->write($data);
}
| 0
|
c7c1d008b5afa02043303e6468cda82a45dc3f8c
|
1up-lab/OneupUploaderBundle
|
Merge branch 'validationEventWithResponse' of git://github.com/derpue/OneupUploaderBundle into derpue-validationEventWithResponse
|
commit c7c1d008b5afa02043303e6468cda82a45dc3f8c (from c70ac38252200356540ec27b67853b2eb1106c53)
Merge: c70ac38 a4eca39
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:10:34 2017 +0100
Merge branch 'validationEventWithResponse' of git://github.com/derpue/OneupUploaderBundle into 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;
+ }
+
}
commit c7c1d008b5afa02043303e6468cda82a45dc3f8c (from a4eca39e7ea9af1950855c031887d6df96f34906)
Merge: c70ac38 a4eca39
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:10:34 2017 +0100
Merge branch 'validationEventWithResponse' of git://github.com/derpue/OneupUploaderBundle into derpue-validationEventWithResponse
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 75d64b4..ef2d38e 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -75,6 +75,27 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->scalarNode('route_prefix')->defaultValue('')->end()
+ ->arrayNode('endpoints')
+ ->beforeNormalization()
+ ->ifString()
+ ->then(function ($v) {
+ if (substr($v, -1) != '/') {
+ $v .= '/';
+ }
+ return [
+ 'upload' => $v.'upload',
+ 'progress' => $v.'progress',
+ 'cancel' => $v.'cancel',
+ ];
+ })
+ ->end()
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('upload')->defaultNull()->end()
+ ->scalarNode('progress')->defaultNull()->end()
+ ->scalarNode('cancel')->defaultNull()->end()
+ ->end()
+ ->end()
->arrayNode('allowed_mimetypes')
->prototype('scalar')->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index c2c14eb..61dc35f 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -84,7 +84,8 @@ class OneupUploaderExtension extends Extension
return array($controllerName, array(
'enable_progress' => $mapping['enable_progress'],
'enable_cancelation' => $mapping['enable_cancelation'],
- 'route_prefix' => $mapping['route_prefix']
+ 'route_prefix' => $mapping['route_prefix'],
+ 'endpoints' => $mapping['endpoints'],
));
}
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index 1f51fb2..d6aefe2 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.plupload.class">Oneup\UploaderBundle\Uploader\ErrorHandler\PluploadErrorHandler</parameter>
<parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter>
</parameters>
@@ -19,8 +20,8 @@
<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.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" />
+ <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.plupload.class%" public="false" />
<service id="oneup_uploader.error_handler.custom" class="%oneup_uploader.error_handler.noop.class%" public="false" />
</services>
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index a7cee8a..5e89c4a 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -35,6 +35,10 @@ oneup_uploader:
stream_wrapper: ~
sync_buffer_size: 100K
route_prefix:
+ endpoints:
+ upload: ~
+ progress: ~
+ cancel: ~
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index cd8c070..6dbdc4a 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -30,7 +30,7 @@ class RouteLoader extends Loader
$options = $controllerArray[1];
$upload = new Route(
- sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type),
+ $options['endpoints']['upload'] ?: sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type),
array('_controller' => $service . ':upload', '_format' => 'json'),
array(),
array(),
@@ -41,7 +41,7 @@ class RouteLoader extends Loader
if ($options['enable_progress'] === true) {
$progress = new Route(
- sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type),
+ $options['endpoints']['progress'] ?: sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type),
array('_controller' => $service . ':progress', '_format' => 'json'),
array(),
array(),
@@ -55,7 +55,7 @@ class RouteLoader extends Loader
if ($options['enable_cancelation'] === true) {
$progress = new Route(
- sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type),
+ $options['endpoints']['cancel'] ?: sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type),
array('_controller' => $service . ':cancel', '_format' => 'json'),
array(),
array(),
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 95b35ab..d462101 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -15,12 +15,22 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
'cat' => array($cat, array(
'enable_progress' => false,
'enable_cancelation' => false,
- 'route_prefix' => ''
+ 'route_prefix' => '',
+ 'endpoints' => array(
+ 'upload' => null,
+ 'progress' => null,
+ 'cancel' => null,
+ ),
)),
'dog' => array($dog, array(
'enable_progress' => true,
'enable_cancelation' => true,
- 'route_prefix' => ''
+ 'route_prefix' => '',
+ 'endpoints' => array(
+ 'upload' => null,
+ 'progress' => null,
+ 'cancel' => null,
+ ),
)),
));
@@ -47,7 +57,12 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
'cat' => array($cat, array(
'enable_progress' => false,
'enable_cancelation' => false,
- 'route_prefix' => $prefix
+ 'route_prefix' => $prefix,
+ 'endpoints' => array(
+ 'upload' => null,
+ 'progress' => null,
+ 'cancel' => null,
+ ),
))
));
@@ -61,4 +76,33 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
}
+
+ public function testCustomEndpointRoutes()
+ {
+ $customEndpointUpload = '/grumpy/cats/upload';
+ $cat = 'GrumpyCatController';
+
+ $routeLoader = new RouteLoader(array(
+ 'cat' => array($cat, array(
+ 'enable_progress' => false,
+ 'enable_cancelation' => false,
+ 'route_prefix' => '',
+ 'endpoints' => array(
+ 'upload' => $customEndpointUpload,
+ 'progress' => null,
+ 'cancel' => null,
+ ),
+ ))
+ ));
+
+ $routes = $routeLoader->load(null);
+
+ foreach ($routes as $route) {
+ $this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
+ $this->assertEquals('json', $route->getDefault('_format'));
+ $this->assertContains('POST', $route->getMethods());
+
+ $this->assertEquals($customEndpointUpload, $route->getPath());
+ }
+ }
}
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/ErrorHandler/PluploadErrorHandler.php b/Uploader/ErrorHandler/PluploadErrorHandler.php
new file mode 100644
index 0000000..6716c87
--- /dev/null
+++ b/Uploader/ErrorHandler/PluploadErrorHandler.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 PluploadErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(AbstractResponse $response, Exception $exception)
+ {
+ /* Plupload only needs an error message so it can be handled client side */
+ $message = $exception->getMessage();
+ $response['error'] = $message;
+ }
+}
+
+?>
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
|
575f6b056a722b5aeb0c2d03eb58538ea9a71ddd
|
1up-lab/OneupUploaderBundle
|
Implemented chunked uploads.
|
commit 575f6b056a722b5aeb0c2d03eb58538ea9a71ddd
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 15:11:36 2013 +0100
Implemented chunked uploads.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 2ad0377..97d7550 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -2,7 +2,9 @@
namespace Oneup\UploaderBundle\Controller;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\Finder\Finder;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
@@ -14,7 +16,7 @@ class UploaderController implements UploadControllerInterface
protected $namer;
protected $storage;
- public function __construct($request, $namer, $storage, $dispatcher, $type, $config)
+ public function __construct($request, $namer, $storage, $dispatcher, $type, $config, $chunkManager)
{
$this->request = $request;
$this->namer = $namer;
@@ -22,45 +24,70 @@ class UploaderController implements UploadControllerInterface
$this->config = $config;
$this->dispatcher = $dispatcher;
$this->type = $type;
+ $this->chunkManager = $chunkManager;
}
public function upload()
{
$totalParts = $this->request->get('qqtotalparts', 1);
-
- return $totalParts > 1 ? $this->handleChunkedUpload() : $this->handleUpload();
- }
-
- protected function handleUpload()
- {
- // get filebag from request
$files = $this->request->files;
foreach($files as $file)
{
- $name = $this->namer->name($file, $this->config['directory_prefix']);
+ $ret = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+ }
+
+ return $ret;
+ }
+
+ protected function handleUpload(UploadedFile $file)
+ {
+ $name = $this->namer->name($file, $this->config['directory_prefix']);
- $postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array(
- 'use_orphanage' => $this->config['use_orphanage'],
- 'file_name' => $name,
- ));
- $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
+ $postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array(
+ 'use_orphanage' => $this->config['use_orphanage'],
+ 'file_name' => $name,
+ ));
+ $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
- if(!$this->config['use_orphanage'])
- {
- $uploaded = $this->storage->upload($file, $name);
+ if(!$this->config['use_orphanage'])
+ {
+ $uploaded = $this->storage->upload($file, $name);
- // dispatch post upload event
- $postPersistEvent = new PostPersistEvent($uploaded, $this->request, $this->type);
- $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
- }
+ // dispatch post upload event
+ $postPersistEvent = new PostPersistEvent($uploaded, $this->request, $this->type);
+ $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
}
return new JsonResponse(array('success' => true));
}
- protected function handleChunkedUpload()
+ protected function handleChunkedUpload(UploadedFile $file)
{
+ $request = $this->request;
+
+ // getting information about chunks
+ $index = $request->get('qqpartindex');
+ $total = $request->get('qqtotalparts');
+ $uuid = $request->get('qquuid');
+ $orig = $request->get('qqfilename');
+
+ $this->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 = $this->chunkManager->getChunks($uuid);
+
+ // assemble parts
+ $assembled = $this->chunkManager->assembleChunks($chunks);
+
+ return $this->handleUpload(new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true));
+ }
+ return new JsonResponse(array('success' => true));
}
}
\ No newline at end of file
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index b07d7a2..4e363cd 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -120,6 +120,8 @@ class OneupUploaderExtension extends Extension
->addArgument($type)
->addArgument($mapping)
+ ->addArgument(new Reference('oneup_uploader.chunk_manager'))
+
->addTag('oneup_uploader.routable', array('type' => $type))
->setScope('request')
;
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 04ce1ea..83369bf 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -15,7 +15,7 @@
</parameters>
<services>
- <service id="oneup_uploader.chunks_manager" class="%oneup_uploader.chunks.manager.class%">
+ <service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
</service>
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 74ced99..1da9eb3 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -2,10 +2,12 @@
namespace Oneup\UploaderBundle\Uploader\Chunk;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
+use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
class ChunkManager implements ChunkManagerInterface
{
@@ -16,8 +18,8 @@ class ChunkManager implements ChunkManagerInterface
public function warmup()
{
- $fileSystem = new FileSystem();
- $fileSystem->mkdir($this->configuration['directory']);
+ $filesystem = new FileSystem();
+ $filesystem->mkdir($this->configuration['directory']);
}
public function clear()
@@ -42,4 +44,59 @@ class ChunkManager implements ChunkManagerInterface
$system->remove($file);
}
}
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $filesystem = new Filesystem();
+ $path = sprintf('%s/%s', $this->configuration['directory'], $uuid);
+ $name = sprintf('%s_%s', $index, $original);
+
+ // create directory if it does not yet exist
+ if(!$filesystem->exists($path))
+ $filesystem->mkdir(sprintf('%s/%s', $this->configuration['directory'], $uuid));
+
+ $chunk->move($path, $name);
+ }
+
+ public function assembleChunks($chunks)
+ {
+ // I don't really get it why getIterator()->current() always
+ // gives me a null-value, due to that I've to implement this
+ // in a rather unorthodox way.
+ $i = 0;
+ $base = null;
+
+ foreach($chunks as $file)
+ {
+ if($i++ == 0)
+ {
+ $base = $file;
+
+ // proceed with next files, as we have our
+ // base data-container
+ continue;
+ }
+
+ if(false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX))
+ throw new \RuntimeException('Reassembling chunks failed.');
+ }
+
+ return $base;
+ }
+
+ public function getChunks($uuid)
+ {
+ $finder = new Finder();
+ $finder
+ ->in(sprintf('%s/%s', $this->configuration['directory'], $uuid))->files()->sort(function(\SplFileInfo $a, \SplFileInfo $b) {
+ $t = explode('_', $a->getBasename());
+ $s = explode('_', $b->getBasename());
+ $t = (int) $t[0];
+ $s = (int) $s[0];
+
+ return $s < $t;
+ });
+
+ return $finder;
+ }
}
\ No newline at end of file
diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php
index 9d9c8b9..07e04d9 100644
--- a/Uploader/Naming/UniqidNamer.php
+++ b/Uploader/Naming/UniqidNamer.php
@@ -10,7 +10,7 @@ class UniqidNamer implements NamerInterface
public function name(UploadedFile $file, $prefix = null)
{
$prefix = !is_null($prefix) ? $prefix . '/' : '';
-
+
return sprintf('%s%s.%s', $prefix, uniqid(), $file->guessExtension());
}
}
\ No newline at end of file
| 0
|
c5f2103be282a538b9de78a177cfe34f0f198c2c
|
1up-lab/OneupUploaderBundle
|
Added contentType to metadata if Gaufrette\Adapter supports Metadata.
|
commit c5f2103be282a538b9de78a177cfe34f0f198c2c
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 12:12:07 2013 +0200
Added contentType to metadata if Gaufrette\Adapter supports Metadata.
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index fac7bbe..5823d50 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\File\File;
use Gaufrette\Stream\Local as LocalStream;
use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
+use Gaufrette\Adapter\MetadataSupporter;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
@@ -20,9 +21,13 @@ class GaufretteStorage implements StorageInterface
public function upload(File $file, $name, $path = null)
{
- $name = is_null($name) ? $file->getRelativePathname() : $name;
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
+ if($this->filesystem->getAdapter() instanceof MetadataSupporter)
+ {
+ $this->filesystem->getAdapter()->setMetadata($name, array('contentType' => $file->getMimeType()));
+ }
+
$src = new LocalStream($file->getPathname());
$dst = $this->filesystem->createStream($path);
| 0
|
0d1f577e04c9f1d07444e270552af2de868ea683
|
1up-lab/OneupUploaderBundle
|
Throw an exception if a user wants to use Gaufrette without having installed it.
|
commit 0d1f577e04c9f1d07444e270552af2de868ea683
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:56:53 2013 +0200
Throw an exception if a user wants to use Gaufrette without having installed it.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 11e76ac..32d23a5 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -4,6 +4,7 @@ namespace Oneup\UploaderBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
@@ -67,6 +68,9 @@ class OneupUploaderExtension extends Extension
if($mapping['storage']['type'] == 'gaufrette')
{
+ if(!class_exists('Gaufrette\\Filesystem'))
+ throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a storage service.');
+
$container
->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type'])))
->addArgument(new Reference($mapping['storage']['filesystem']))
| 0
|
412129ae9b648bbb4778d126778cb2030d6ee43a
|
1up-lab/OneupUploaderBundle
|
Set output format of Controller to 'json'
|
commit 412129ae9b648bbb4778d126778cb2030d6ee43a
Author: Jim Schmid <[email protected]>
Date: Tue Mar 12 18:18:28 2013 +0100
Set output format of Controller to 'json'
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 771fb01..572f522 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -34,7 +34,7 @@ class RouteLoader extends Loader
{
$route = new Route(
sprintf('/_uploader/%s', $type),
- array('_controller' => $service . ':upload'),
+ array('_controller' => $service . ':upload', '_format' => 'json'),
array('_method' => 'POST')
);
| 0
|
a488f6f8f32f51e49c5ee02695e24cff40ee6b02
|
1up-lab/OneupUploaderBundle
|
Fix links
|
commit a488f6f8f32f51e49c5ee02695e24cff40ee6b02
Author: David Greminger <[email protected]>
Date: Fri Mar 27 16:53:48 2020 +0100
Fix links
diff --git a/README.md b/README.md
index cd057cb..f9b252e 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
-* Version **3.0.0** supports now Symfony 5 (kudos to @steveWinter, @gubler, @patrickbussmann, @ErnadoO and @enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
+* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter], @[gubler], @[patrickbussmann], @[ErnadoO] and @[enumag]), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
* 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).
| 0
|
ab23ea0a9ba1450e42c188bd17c01f6b9e0cfdc5
|
1up-lab/OneupUploaderBundle
|
Added PHP 5.6 and HHVM to travis.yml
|
commit ab23ea0a9ba1450e42c188bd17c01f6b9e0cfdc5
Author: Tobias Nyholm <[email protected]>
Date: Thu Jul 17 07:23:24 2014 +0200
Added PHP 5.6 and HHVM to travis.yml
diff --git a/.travis.yml b/.travis.yml
index bd24695..1d74818 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,27 @@
language: php
php:
- - 5.3
- - 5.4
- - 5.5
+ - 5.3
+ - 5.4
+ - 5.5
+ - 5.6
+ - hhvm
env:
- SYMFONY_VERSION=2.3.*
- - SYMFONY_VERSION=2.4.*
- - SYMFONY_VERSION=2.5.*
+
+matrix:
+ allow_failures:
+ - env: SYMFONY_VERSION=dev-master
+ - php: hhvm
+ include:
+ - php: 5.5
+ env: SYMFONY_VERSION=2.4.*
+ - php: 5.5
+ env: SYMFONY_VERSION=2.5.*
+ - php: 5.5
+ env: SYMFONY_VERSION=dev-master
before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
- - composer install --dev --prefer-source
\ No newline at end of file
+ - composer install --dev --prefer-source
| 0
|
a23bcbf0b9583cadbed778e3b57761d68a1b22b9
|
1up-lab/OneupUploaderBundle
|
addToOffset is now using arrays instead of variable argument list.
|
commit a23bcbf0b9583cadbed778e3b57761d68a1b22b9
Author: Jim Schmid <[email protected]>
Date: Mon Jul 15 11:17:01 2013 +0200
addToOffset is now using arrays instead of variable argument list.
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index 299dae1..d9adf89 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -16,6 +16,6 @@ class BlueimpErrorHandler implements ErrorHandlerInterface
$message = $exception->getMessage();
}
- $response->addToOffset(array('error' => $message), 'files');
+ $response->addToOffset(array('error' => $message), array('files'));
}
}
diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php
index 3745f62..fb5cc27 100644
--- a/Uploader/Response/AbstractResponse.php
+++ b/Uploader/Response/AbstractResponse.php
@@ -38,29 +38,26 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
* This function will take a path of arrays and add a new element to it, creating the path if needed.
*
* @param mixed $value
- * @param mixed $offset,...
+ * @param array $offsets
+ *
+ * @throws \InvalidArgumentException if the path contains non-array items.
*
- * @throws \InvalidArgumentException if the path contains non-array or unset items.
*/
- public function addToOffset($value, $offset)
+ public function addToOffset($value, array $offsets)
{
- $args = func_get_args();
- array_shift($args);
-
$element =& $this->data;
-
- foreach ($args as $offset) {
+ foreach ($offsets as $offset) {
if (isset($element[$offset])) {
if (is_array($element[$offset])) {
$element =& $element[$offset];
} else {
- throw new \InvalidArgumentException('The specified offset is set but is not an array at ' . $offset);
+ throw new \InvalidArgumentException("The specified offset is set but is not an array at" . $offset);
}
} else {
$element[$offset] = array();
$element =& $element[$offset];
}
}
- $element[] = $value;
+ $element = $value;
}
}
| 0
|
99a92fc5c07707a91366143a1b01b416bea42862
|
1up-lab/OneupUploaderBundle
|
Fixed typo in index.md
|
commit 99a92fc5c07707a91366143a1b01b416bea42862
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 09:12:25 2013 +0200
Fixed typo in index.md
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index c4c35a8..06d8d3b 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -3,7 +3,7 @@ Getting started
## Prerequisites
-This bundle tested using Symfony2 versions 2.1+.
+This bundle is tested using Symfony2 versions 2.1+.
### Translations
If you wish to use the default texts provided with this bundle, you have to make sure that you have translator
| 0
|
e026383870c05cf02340b75b0f65cecc007a836b
|
1up-lab/OneupUploaderBundle
|
Changed description in composer.json
|
commit e026383870c05cf02340b75b0f65cecc007a836b
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 11:10:21 2013 +0200
Changed description in composer.json
diff --git a/composer.json b/composer.json
index 35989f8..9b93984 100644
--- a/composer.json
+++ b/composer.json
@@ -1,8 +1,8 @@
{
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
- "description": "valums/file-uploader integration",
- "keywords": ["fileupload", "upload", "multifileupload"],
+ "description": "widen/file-uploader integration",
+ "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans"],
"homepage": "http://1up.io",
"license": "MIT",
"authors": [
| 0
|
c0138f647c8aee974ac085708a543dec20d52c29
|
1up-lab/OneupUploaderBundle
|
Made getFiles on Orphanage public.
Addresses #48.
|
commit c0138f647c8aee974ac085708a543dec20d52c29
Author: Jim Schmid <[email protected]>
Date: Fri Sep 20 08:00:51 2013 +0200
Made getFiles on Orphanage public.
Addresses #48.
diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index 303faae..59478cd 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -41,6 +41,11 @@ class AcmeController extends Controller
public function storeAction()
{
$manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery');
+
+ // get files
+ $files = $manager->getFiles();
+
+ // upload all files to the configured storage
$files = $manager->uploadFiles();
}
}
diff --git a/Tests/Uploader/Storage/OrphanageStorageTest.php b/Tests/Uploader/Storage/OrphanageStorageTest.php
index 3ca429a..bcaf525 100644
--- a/Tests/Uploader/Storage/OrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/OrphanageStorageTest.php
@@ -108,6 +108,13 @@ class OrphanageStorageTest extends \PHPUnit_Framework_TestCase
$this->assertCount(0, $files);
}
+ public function testIfGetFilesMethodIsAccessible()
+ {
+ // since ticket #48, getFiles has to be public
+ $method = new \ReflectionMethod($this->orphanage, 'getFiles');
+ $this->assertTrue($method->isPublic());
+ }
+
public function tearDown()
{
$filesystem = new Filesystem();
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index 38c4e96..d0787d0 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -54,7 +54,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte
}
}
- protected function getFiles()
+ public function getFiles()
{
$finder = new Finder();
$finder->in($this->getFindPath())->files();
| 0
|
f0d90b18c26a695a0d5e506a29c6e787ac91cac8
|
1up-lab/OneupUploaderBundle
|
Added Readme file with travis status image.
|
commit f0d90b18c26a695a0d5e506a29c6e787ac91cac8
Author: Jim Schmid <[email protected]>
Date: Fri Mar 8 19:08:34 2013 +0100
Added Readme file with travis status image.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..0961964
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+OneupUploaderBundle
+===================
+
+[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
\ No newline at end of file
| 0
|
dbb3e4adf7ada500d9bb9aba6ea7d3f9154106a9
|
1up-lab/OneupUploaderBundle
|
Do not rely on the size sent by the client, use the internal one instead.
|
commit dbb3e4adf7ada500d9bb9aba6ea7d3f9154106a9
Author: Jim Schmid <[email protected]>
Date: Tue Apr 23 20:55:26 2013 +0200
Do not rely on the size sent by the client, use the internal one instead.
diff --git a/EventListener/MaxSizeValidationListener.php b/EventListener/MaxSizeValidationListener.php
index b14fca9..e3b6d90 100644
--- a/EventListener/MaxSizeValidationListener.php
+++ b/EventListener/MaxSizeValidationListener.php
@@ -12,8 +12,8 @@ class MaxSizeValidationListener
$config = $event->getConfig();
$file = $event->getFile();
- if($file->getClientSize() > $config['max_size']) {
+ if($file->getSize() > $config['max_size']) {
throw new ValidationException('error.maxsize');
}
}
-}
\ No newline at end of file
+}
| 0
|
78c7a25b0cd75a6770b00f220bcb6196a930c8b8
|
1up-lab/OneupUploaderBundle
|
Removed Symfony 2.3 from test configuration
|
commit 78c7a25b0cd75a6770b00f220bcb6196a930c8b8
Author: David Greminger <[email protected]>
Date: Thu Dec 10 14:23:17 2015 +0100
Removed Symfony 2.3 from test configuration
diff --git a/.travis.yml b/.travis.yml
index 1734c3f..83d8577 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,6 @@ php:
- hhvm
env:
- - SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.7.*
- SYMFONY_VERSION=2.8.*
@@ -24,8 +23,6 @@ matrix:
- env: SYMFONY_VERSION=dev-master
include:
- - php: 5.6
- env: SYMFONY_VERSION=2.3.*
- php: 5.6
env: SYMFONY_VERSION=2.4.*
- php: 5.6
| 0
|
cf5b24b8c21b8fe1301d546b24c247cdea2e2f88
|
1up-lab/OneupUploaderBundle
|
Do not rename chunks if the upload process is not yet finished.
Otherwise you will end up having a completly broken order of reassembling.
Addresses: #21
|
commit cf5b24b8c21b8fe1301d546b24c247cdea2e2f88
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:44:36 2013 +0200
Do not rename chunks if the upload process is not yet finished.
Otherwise you will end up having a completly broken order of reassembling.
Addresses: #21
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
|
d6d75255d3cf6334c286b440ec53c736ec76ca7d
|
1up-lab/OneupUploaderBundle
|
Added check for max_size: -1 (#329)
|
commit d6d75255d3cf6334c286b440ec53c736ec76ca7d
Author: Nikita Pimoshenko <[email protected]>
Date: Tue Jun 5 10:34:16 2018 +0200
Added check for max_size: -1 (#329)
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 6371cd8..4ed42dd 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -291,6 +291,10 @@ class OneupUploaderExtension extends Extension
$maxPost = $this->getValueInBytes(ini_get('upload_max_filesize'));
$maxFile = $this->getValueInBytes(ini_get('post_max_size'));
+ if ($input < 0) {
+ return min($maxPost, $maxFile);
+ }
+
return min(min($input, $maxPost), $maxFile);
}
| 0
|
fb96cf42e700e311e867948893695574a5ee3cd6
|
1up-lab/OneupUploaderBundle
|
Removed strict typing of paragraph 'file' on the Events. This is because we don't share a proper interface with Gaufrette\File yet.
|
commit fb96cf42e700e311e867948893695574a5ee3cd6
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 16:57:16 2013 +0200
Removed strict typing of paragraph 'file' on the Events. This is because we don't share a proper interface with Gaufrette\File yet.
diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php
index 60fb8f7..8ff3e63 100644
--- a/Event/PostPersistEvent.php
+++ b/Event/PostPersistEvent.php
@@ -17,7 +17,7 @@ class PostPersistEvent extends Event
protected $response;
protected $config;
- public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config)
+ public function __construct($file, UploaderResponse $response, Request $request, $type, array $config)
{
$this->file = $file;
$this->request = $request;
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index 216e58d..1440f00 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -17,7 +17,7 @@ class PostUploadEvent extends Event
protected $response;
protected $config;
- public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config)
+ public function __construct($file, UploaderResponse $response, Request $request, $type, array $config)
{
$this->file = $file;
$this->request = $request;
| 0
|
394a7ab76529737357862237f188f0cbbb2f69f5
|
1up-lab/OneupUploaderBundle
|
Upload large files with flysystem
Fixes a memory problem that occurs when uploading large files.
|
commit 394a7ab76529737357862237f188f0cbbb2f69f5
Author: rs <[email protected]>
Date: Mon Feb 8 10:01:50 2016 +0100
Upload large files with flysystem
Fixes a memory problem that occurs when uploading large files.
diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php
index 4d0212d..9a98720 100644
--- a/Uploader/Storage/FlysystemStorage.php
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -44,7 +44,11 @@ class FlysystemStorage implements StorageInterface
}
}
- $this->filesystem->put($name, file_get_contents($file));
+ $stream = fopen($file->getPathname(), 'r+');
+ $this->filesystem->putStream($name, $stream);
+ if (is_resource($stream)) {
+ fclose($stream);
+ }
if ($file instanceof FlysystemFile) {
$file->delete();
| 0
|
222e4d52c9c042f9dbc17f331daaf6d13fbed80f
|
1up-lab/OneupUploaderBundle
|
Adapted the FineUploaderController to the new abstract structure.
|
commit 222e4d52c9c042f9dbc17f331daaf6d13fbed80f
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 23:46:50 2013 +0200
Adapted the FineUploaderController to the new abstract structure.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 60800cf..c53e574 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -11,12 +11,11 @@ use Symfony\Component\HttpFoundation\Request;
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\EmptyResponse;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
-abstract class AbstractController implements UploadControllerInterface
+abstract class AbstractController
{
protected $container;
protected $storage;
@@ -30,6 +29,8 @@ abstract class AbstractController implements UploadControllerInterface
$this->config = $config;
$this->type = $type;
}
+
+ abstract public function upload();
protected function handleUpload(UploadedFile $file)
{
@@ -45,9 +46,9 @@ abstract class AbstractController implements UploadControllerInterface
return $uploaded;
}
- protected function dispatchEvents($uploaded, ResponseInterface $response)
+ protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
{
- $request = $this->container->get('request');
+ $dispatcher = $this->container->get('event_dispatcher');
$postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
$dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index a4f4d56..e2c6026 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -37,7 +37,7 @@ class BlueimpController extends AbstractChunkedController
$uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
// dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response);
+ $this->dispatchEvents($uploaded, $response, $request);
}
catch(UploadException $e)
{
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 178378e..7fcbace 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -6,33 +6,20 @@ 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\UploadControllerInterface;
+use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
-class FineUploaderController implements UploadControllerInterface
+class FineUploaderController extends AbstractChunkedController
{
- 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 FineUploaderResponse();
@@ -45,16 +32,9 @@ class FineUploaderController implements UploadControllerInterface
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);
- }
+
+ // dispatch POST_PERSIST AND POST_UPLOAD events
+ $this->dispatchEvents($uploaded, $response, $request);
}
catch(UploadException $e)
{
@@ -69,76 +49,14 @@ class FineUploaderController implements UploadControllerInterface
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)
+ protected function parseChunkedRequest(Request $request)
{
- $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');
+ $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
| 0
|
8c355cf1a9dfc5ec103193eb022c1c6b90ca9677
|
1up-lab/OneupUploaderBundle
|
Documented the testing process.
|
commit 8c355cf1a9dfc5ec103193eb022c1c6b90ca9677
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 09:08:48 2013 +0200
Documented the testing process.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 29a4395..c4c35a8 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -117,5 +117,5 @@ some more advanced features.
* Using the Orphanage
* [Use Gaufrette as storage layer](gaufrette_storage.md)
* [Include your own Namer](custom_namer.md)
-* Testing this bundle
+* [Testing this bundle](testing.md)
* [Configuration Reference](configuration_reference.md)
diff --git a/Resources/doc/testing.md b/Resources/doc/testing.md
new file mode 100644
index 0000000..8db8597
--- /dev/null
+++ b/Resources/doc/testing.md
@@ -0,0 +1,62 @@
+Testing the Bundle
+==================
+
+## Install the Environment
+
+In order to run the UnitTests of this bundle, clone it first
+
+ $> git clone git://github.com/1up-lab/OneupUploaderBundle.git
+
+After the cloning process, install all vendors by running the corresponding composer command.
+
+ $> php composer.phar udpate --dev
+
+## Run UnitTests
+You can run the unit tests by simply performing the follwowing command.
+
+ $> phpunit
+
+## Testing Code Coverage
+PHPUnit comes bundles with a handy feature to test the code coverage of a project. I recommend using the following configuration to enable the creation of code coverage reports in the `log` directory in the root of this bundle. This directory is gitignored by default.
+
+Copy the `phpunit.xml.dist` to `phpunit.xml` and use this configuration.
+
+```xml
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
+
+ <testsuites>
+ <testsuite name="OneupUploaderBundle test suite">
+ <directory suffix="Test.php">./Tests</directory>
+ </testsuite>
+ </testsuites>
+
+ <filter>
+ <whitelist>
+ <directory>./</directory>
+ <exclude>
+ <directory>./Command</directory>
+ <directory>./DependencyInjection</directory>
+ <directory>./Event</directory>
+ <directory>./Resources</directory>
+ <directory>./Tests</directory>
+ <directory>./vendor</directory>
+ <directory>./OneupUploaderBundle.php</directory>
+ </exclude>
+ </whitelist>
+ </filter>
+
+ <logging>
+ <log type="coverage-html" target="./log/codeCoverage" charset="UTF-8" yui="true" highlight="true"
+ lowUpperBound="50" highLowerBound="80"/>
+ </logging>
+
+</phpunit>
+```
+
+The directories `Command`, `DependencyInjection` and `Event` are excluded from the code coverage report, as these directories contain files that don't necessarily need to be unit tested.
+
+Run the test suite and generate reports by running:
+
+ $> phpunit
\ No newline at end of file
| 0
|
948d850bde7cb8758f083ac806a6a350cf305456
|
1up-lab/OneupUploaderBundle
|
Merge branch 'release-1.0' of https://github.com/mitom/OneupUploaderBundle into release-1.0
|
commit 948d850bde7cb8758f083ac806a6a350cf305456 (from 082f119827d52101398ec25abd4fc1278e7b1ad1)
Merge: 082f119 160c9a1
Author: mitom <[email protected]>
Date: Fri Oct 11 13:07:48 2013 +0200
Merge branch 'release-1.0' of https://github.com/mitom/OneupUploaderBundle into release-1.0
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index 4f5c5e1..b6c560d 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -31,11 +31,48 @@ You can configure the `ChunkManager` by using the following configuration parame
oneup_uploader:
chunks:
maxage: 86400
- directory: %kernel.cache_dir%/uploader/chunks
+ storage:
+ directory: %kernel.cache_dir%/uploader/chunks
```
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.
+The configuration for the Gaufrette chunk storage should look as the following:
+```
+oneup_uploader:
+ chunks:
+ maxage: 86400
+ storage:
+ type: gaufrette
+ 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)
+
+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.
+
+> 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```.
+
+The chunks will be read directly from the tmp 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.
+
+> The ```load distribution``` is forcefully turned on, if you use gaufrette as the chunk storage.
+
+
## Clean up
The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle.
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index b75fee4..0a712c9 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -7,7 +7,13 @@ All available configuration options along with their default values are listed b
oneup_uploader:
chunks:
maxage: 604800
- directory: ~
+ storage:
+ type: filesystem
+ directory: ~
+ filesystem: ~
+ sync_buffer_size: 100K
+ stream_wrapper: ~
+ prefix: 'chunks'
load_distribution: true
orphanage:
maxage: 604800
@@ -26,6 +32,7 @@ oneup_uploader:
type: filesystem
filesystem: ~
directory: ~
+ stream_wrapper: ~
sync_buffer_size: 100K
allowed_extensions: []
disallowed_extensions: []
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index 4aaeabc..9b59e58 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -12,19 +12,19 @@ First, create a custom namer which implements ```Oneup\UploaderBundle\Uploader\N
namespace Acme\DemoBundle;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
class CatNamer implements NamerInterface
{
- public function name(UploadedFile $file)
+ public function name(FileInterface $file)
{
return 'grumpycat.jpg';
}
}
```
-To match the `NamerInterface` you have to implement the function `name()` which expects an `UploadedFile` 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.
Next, register your created namer as a service in your `services.xml`
diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md
index 6c93347..c03ba84 100644
--- a/Resources/doc/gaufrette_storage.md
+++ b/Resources/doc/gaufrette_storage.md
@@ -88,3 +88,27 @@ oneup_uploader:
sync_buffer_size: 1M
```
+You may also specify the stream wrapper protocol for your filesystem:
+```yml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ type: gaufrette
+ 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
+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 (```/```).
+
+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)
commit 948d850bde7cb8758f083ac806a6a350cf305456 (from 160c9a163d34b03c5413cee193743bc0407471f1)
Merge: 082f119 160c9a1
Author: mitom <[email protected]>
Date: Fri Oct 11 13:07:48 2013 +0200
Merge branch 'release-1.0' of https://github.com/mitom/OneupUploaderBundle into release-1.0
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index a86036f..b25c844 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -50,8 +50,13 @@ class OneupUploaderExtension extends Extension
protected function processOrphanageConfig()
{
- $this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ?
- sprintf('%s/uploader/orphanage', $this->container->getParameter('kernel.cache_dir')) :
+ if ($this->config['chunks']['storage']['type'] === 'filesystem') {
+ $defaultDir = sprintf('%s/uploader/orphanage', $this->container->getParameter('kernel.cache_dir'));
+ } else {
+ $defaultDir = 'orphanage';
+ }
+
+ $this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ? $defaultDir:
$this->normalizePath($this->config['orphanage']['directory'])
;
}
@@ -75,7 +80,7 @@ class OneupUploaderExtension extends Extension
protected function createController($key, $config)
{
// create the storage service according to the configuration
- $storageService = $this->createStorageService($config['storage'], $key, isset($config['orphanage']) ? :null);
+ $storageService = $this->createStorageService($config['storage'], $key, $config['use_orphanage']);
if ($config['frontend'] != 'custom') {
$controllerName = sprintf('oneup_uploader.controller.%s', $key);
@@ -149,13 +154,15 @@ class OneupUploaderExtension extends Extension
$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;
}
}
- protected function createStorageService(&$config, $key, $orphanage = null)
+ protected function createStorageService(&$config, $key, $orphanage = false)
{
$storageService = null;
@@ -201,6 +208,7 @@ class OneupUploaderExtension extends Extension
->register($orphanageName, '%oneup_uploader.orphanage.class%')
->addArgument($storageService)
->addArgument(new Reference('session'))
+ ->addArgument(new Reference('oneup_uploader.chunks_storage'))
->addArgument($this->config['orphanage'])
->addArgument($key)
;
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 66c7e70..c970994 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -11,7 +11,7 @@
<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.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.class">Oneup\UploaderBundle\Uploader\Storage\FilesystemOrphanageStorage</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>
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 19fea99..95667fd 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -4,7 +4,6 @@ namespace Oneup\UploaderBundle\Tests\Controller;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
-use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\UploadEvents;
class BlueimpValidationTest extends AbstractValidationTest
diff --git a/Tests/Uploader/Storage/OrphanageStorageTest.php b/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
similarity index 89%
rename from Tests/Uploader/Storage/OrphanageStorageTest.php
rename to Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
index b2eed0a..2278b96 100644
--- a/Tests/Uploader/Storage/OrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
@@ -3,16 +3,17 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemOrphanageStorage;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage as FilesystemChunkStorage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
-use Oneup\UploaderBundle\Uploader\Storage\OrphanageStorage;
use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-class OrphanageStorageTest extends \PHPUnit_Framework_TestCase
+class FilesystemOrphanageStorageTest extends \PHPUnit_Framework_TestCase
{
protected $tempDirectory;
protected $realDirectory;
@@ -45,6 +46,8 @@ class OrphanageStorageTest extends \PHPUnit_Framework_TestCase
// create underlying storage
$this->storage = new FilesystemStorage($this->realDirectory);
+ // is ignored anyways
+ $chunkStorage = new FilesystemChunkStorage('/tmp/');
// create orphanage
$session = new Session(new MockArraySessionStorage());
@@ -52,7 +55,7 @@ class OrphanageStorageTest extends \PHPUnit_Framework_TestCase
$config = array('directory' => $this->tempDirectory);
- $this->orphanage = new OrphanageStorage($this->storage, $session, $config, 'cat');
+ $this->orphanage = new FilesystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
}
public function testUpload()
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 4f5a286..cfd55e3 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -27,9 +27,18 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
$this->streamWrapperPrefix = $streamWrapperPrefix;
}
- public function clear($maxAge)
+ /**
+ * Clears files and folders older than $maxAge in $prefix
+ * $prefix must be passable so it can clean the orphanage too
+ * as it is forced to be the same filesystem.
+ *
+ * @param $maxAge
+ * @param null $prefix
+ */
+ public function clear($maxAge, $prefix = null)
{
- $matches = $this->filesystem->listKeys($this->prefix);
+ $prefix = $prefix ? :$this->prefix;
+ $matches = $this->filesystem->listKeys($prefix);
$limit = time()+$maxAge;
$toDelete = array();
@@ -140,4 +149,9 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
{
return $this->filesystem->listKeys($this->prefix.'/'.$uuid)['keys'];
}
+
+ public function getFilesystem()
+ {
+ return $this->filesystem;
+ }
}
diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php
index 3ae16c5..58868b8 100644
--- a/Uploader/Gaufrette/StreamManager.php
+++ b/Uploader/Gaufrette/StreamManager.php
@@ -10,7 +10,7 @@ use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
class StreamManager
{
protected $filesystem;
- protected $buffersize;
+ public $buffersize;
protected function createSourceStream(FileInterface $file)
{
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index b09dd25..6903db7 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -24,6 +24,14 @@ class OrphanageManager
public function clear()
{
+ // 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->clear($this->config['maxage'], $this->config['directory']);
+
+ return;
+ }
$system = new Filesystem();
$finder = new Finder();
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/FilesystemOrphanageStorage.php
similarity index 85%
rename from Uploader/Storage/OrphanageStorage.php
rename to Uploader/Storage/FilesystemOrphanageStorage.php
index 22656aa..e0026cc 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/FilesystemOrphanageStorage.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\ChunkStorageInterface;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -12,17 +13,18 @@ use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface;
-class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInterface
+class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageStorageInterface
{
protected $storage;
protected $session;
protected $config;
protected $type;
- public function __construct(StorageInterface $storage, SessionInterface $session, $config, $type)
+ public function __construct(StorageInterface $storage, SessionInterface $session, ChunkStorageInterface $chunkStorage, $config, $type)
{
parent::__construct($config['directory']);
+ // We can just ignore the chunkstorage here, it's not needed to access the files
$this->storage = $storage;
$this->session = $session;
$this->config = $config;
diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php
new file mode 100644
index 0000000..40f83f9
--- /dev/null
+++ b/Uploader/Storage/GaufretteOrphanageStorage.php
@@ -0,0 +1,93 @@
+<?php
+
+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;
+
+class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface
+{
+ protected $storage;
+ protected $session;
+ protected $chunkStorage;
+ protected $config;
+ protected $type;
+
+ /**
+ * @param StorageInterface $storage
+ * @param SessionInterface $session
+ * @param GaufretteChunkStorage $chunkStorage This class is only used if the gaufrette chunk storage is used.
+ * @param $config
+ * @param $type
+ */
+ public function __construct(StorageInterface $storage, SessionInterface $session, GaufretteChunkStorage $chunkStorage, $config, $type)
+ {
+ // initiate the storage on the chunk storage's filesystem
+ // the prefix and stream wrapper are unnecessary.
+ parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, null, null);
+
+ $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()
+ {
+ try {
+ $files = $this->getFiles();
+ $return = array();
+
+ foreach ($files as $key => $file) {
+ try {
+ $return[] = $this->storage->upload($file, str_replace($this->getPath(), '', $key));
+ } catch (\Exception $e) {
+ // don't delete the file, if the upload failed beaces
+ // 1, it may not exist and deleting would throw another exception;
+ // 2, don't lose it on network related errors
+ continue;
+ }
+
+ $this->chunkStorage->getFilesystem()->delete($key);
+ }
+
+ return $return;
+ } catch (\Exception $e) {
+ return array();
+ }
+ }
+
+ public function getFiles()
+ {
+ $keys = $this->chunkStorage->getFilesystem()->listKeys($this->getPath())['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 GaufretteFile(new File($key, $this->chunkStorage->getFilesystem()), $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);
+ }
+
+}
| 0
|
3b9b5c32061099649664a21e37b0fb7502620e48
|
1up-lab/OneupUploaderBundle
|
Removed unused namespaces.
|
commit 3b9b5c32061099649664a21e37b0fb7502620e48
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 17:03:17 2013 +0200
Removed unused namespaces.
diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php
index 8ff3e63..6fed87f 100644
--- a/Event/PostPersistEvent.php
+++ b/Event/PostPersistEvent.php
@@ -4,9 +4,6 @@ namespace Oneup\UploaderBundle\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
-
-use Gaufrette\File;
-
use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
class PostPersistEvent extends Event
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index 1440f00..9dfd6ce 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -4,9 +4,6 @@ namespace Oneup\UploaderBundle\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
-
-use Gaufrette\File;
-
use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
class PostUploadEvent extends Event
| 0
|
bbb79f2228e70a4845c60d32f125cfda1905667e
|
1up-lab/OneupUploaderBundle
|
Do not encourage to work on dev-master.
|
commit bbb79f2228e70a4845c60d32f125cfda1905667e
Author: Jim Schmid <[email protected]>
Date: Fri Aug 16 11:47:55 2013 +0200
Do not encourage to work on dev-master.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 4080132..8d85022 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": "dev-master"
+ "oneup/uploader-bundle": "0.9.*@dev"
}
}
```
| 0
|
71acfbea43e12eeac73d76c72be2f35ba2c11f33
|
1up-lab/OneupUploaderBundle
|
added missing files
|
commit 71acfbea43e12eeac73d76c72be2f35ba2c11f33
Author: mitom <[email protected]>
Date: Fri Oct 11 14:27:09 2013 +0200
added missing files
diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
new file mode 100644
index 0000000..bc3a671
--- /dev/null
+++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+use Gaufrette\File;
+use Gaufrette\Filesystem as GaufretteFilesystem;
+
+use Gaufrette\Adapter\Local as Adapter;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage as GaufretteChunkStorage;
+
+use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
+use Oneup\UploaderBundle\Uploader\Storage\GaufretteOrphanageStorage;
+use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\HttpFoundation\Session\Session;
+use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
+
+class GaufretteOrphanageStorageTest 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();
+
+ $filesystem = new \Symfony\Component\Filesystem\Filesystem();
+ $filesystem->mkdir($this->realDirectory);
+ $filesystem->mkdir($this->chunkDirectory);
+ $filesystem->mkdir($this->tempDirectory);
+
+ $adapter = new Adapter($this->realDirectory, true);
+ $filesystem = new GaufretteFilesystem($adapter);
+
+ $this->storage = new GaufretteStorage($filesystem, 100000);
+
+ $chunkStorage = new GaufretteChunkStorage($filesystem, 100000, null, 'chunks');
+
+ // create orphanage
+ $session = new Session(new MockArraySessionStorage());
+ $session->start();
+
+ $config = array('directory' => 'orphanage');
+
+ $this->orphanage = new GaufretteOrphanageStorage($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 GaufretteFile(new File($fileKey, $filesystem), $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);
+ }
+
+}
diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php
new file mode 100644
index 0000000..bc536ac
--- /dev/null
+++ b/Tests/Uploader/Storage/OrphanageTest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\Session\Session;
+
+abstract class OrphanageTest extends \PHPUnit_Framework_Testcase
+{
+ protected $tempDirectory;
+ protected $realDirectory;
+ protected $orphanage;
+ protected $storage;
+ protected $payloads;
+ protected $numberOfPayloads;
+
+ 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();
+ $finder->in($this->realDirectory)->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)->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 testIfGetFilesMethodIsAccessible()
+ {
+ // since ticket #48, getFiles has to be public
+ $method = new \ReflectionMethod($this->orphanage, 'getFiles');
+ $this->assertTrue($method->isPublic());
+ }
+
+ public function tearDown()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->tempDirectory);
+ $filesystem->remove($this->realDirectory);
+ }
+}
| 0
|
da1b78f9586142140eba9645122ed4bfb73d1b05
|
1up-lab/OneupUploaderBundle
|
Update docs with a how-to for php file config (#382)
|
commit da1b78f9586142140eba9645122ed4bfb73d1b05
Author: Gustavo Nieves <[email protected]>
Date: Mon Aug 3 02:30:59 2020 -0500
Update docs with a how-to for php file config (#382)
diff --git a/doc/index.md b/doc/index.md
index 50b7929..3ef1c98 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -160,6 +160,7 @@ some more advanced features.
* [Template helpers Reference](templating.md)
* [Configuration Reference](configuration_reference.md)
* [Testing this bundle](testing.md)
+* [Config based on PHP files](php_config.md)
## FAQ
diff --git a/doc/php_config.md b/doc/php_config.md
new file mode 100644
index 0000000..56170d9
--- /dev/null
+++ b/doc/php_config.md
@@ -0,0 +1,23 @@
+# Config based on PHP files
+
+If you're using Symfony 5 and want to configure this bundle with a PHP file instead of a YAML,
+you can set up the `config/packages/oneup_uploader.php` file like this:
+
+```php
+
+<?php declare(strict_types=1);
+
+use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
+
+return static function (ContainerConfigurator $configurator): void
+{
+ $configurator->extension('oneup_uploader', [
+ 'mappings' => [
+ 'gallery' => [
+ 'frontend' => 'dropzone'
+ ]
+ ]
+ ]);
+};
+
+```
| 0
|
e14e59e361b2a5d123328aa39fd1289060b19b39
|
1up-lab/OneupUploaderBundle
|
Added RoutingTest to test the RouteLoader.
|
commit e14e59e361b2a5d123328aa39fd1289060b19b39
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:49:26 2013 +0200
Added RoutingTest to test the RouteLoader.
diff --git a/Tests/Routing/RoutingTest.php b/Tests/Routing/RoutingTest.php
new file mode 100644
index 0000000..c1e6edd
--- /dev/null
+++ b/Tests/Routing/RoutingTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Routing;
+
+use Oneup\UploaderBundle\Routing\RouteLoader;
+
+class RoutingTest extends \PHPUnit_Framework_TestCase
+{
+ public function testRouteLoader()
+ {
+ $routeLoader = new RouteLoader();
+
+ // for code coverage
+ $this->assertTrue($routeLoader->supports('grumpy', 'uploader'));
+
+ $cat = 'GrumpyCatController';
+ $dog = 'HelloThisIsDogController';
+
+ // add a new controller and check if the route will be added
+ $routeLoader->addController('cat', $cat);
+ $routeLoader->addController('dog', $dog);
+ $routes = $routeLoader->load(null);
+
+ $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
+ $this->assertCount(2, $routes);
+
+ 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
| 0
|
8cd497ebb4a9e00b6b9babf5286e494b1ed06782
|
1up-lab/OneupUploaderBundle
|
Added php7.0 to allowed failures, updated composer version constraints to use symfony3.0
|
commit 8cd497ebb4a9e00b6b9babf5286e494b1ed06782
Author: David Greminger <[email protected]>
Date: Thu Dec 10 11:37:06 2015 +0100
Added php7.0 to allowed failures, updated composer version constraints to use symfony3.0
diff --git a/.travis.yml b/.travis.yml
index 26b3eb4..1734c3f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,6 +20,7 @@ cache:
matrix:
allow_failures:
- php: hhvm
+ - php: 7.0
- env: SYMFONY_VERSION=dev-master
include:
diff --git a/composer.json b/composer.json
index 3d9a755..7f745ad 100644
--- a/composer.json
+++ b/composer.json
@@ -15,9 +15,9 @@
],
"require": {
- "symfony/framework-bundle": "^2.3.0",
- "symfony/http-kernel": "^2.3.0",
- "symfony/finder": ">=2.2.0"
+ "symfony/framework-bundle": "^2.3.0|~3.0",
+ "symfony/http-kernel": "^2.3.0|~3.0",
+ "symfony/finder": ">=2.2.0|~3.0"
},
"require-dev": {
@@ -27,7 +27,7 @@
"symfony/security-bundle": "2.*",
"sensio/framework-extra-bundle": "2.*",
"symfony/browser-kit": "2.*",
- "phpunit/phpunit": "~4.1"
+ "phpunit/phpunit": "~4.4"
},
"suggest": {
| 0
|
03231b8e00cee33658243ec2071a1576280e86f5
|
1up-lab/OneupUploaderBundle
|
Merge branch 'fix/validation-event-bc'
|
commit 03231b8e00cee33658243ec2071a1576280e86f5 (from c71ac47cdd4ab545444c4735e0f6c41dd5d2f977)
Merge: c71ac47 efaaa65
Author: David Greminger <[email protected]>
Date: Thu Nov 23 10:12:03 2017 +0100
Merge branch 'fix/validation-event-bc'
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
|
baede5317fe99025e74a944aaeec833d84dc4a04
|
1up-lab/OneupUploaderBundle
|
Removed unneccessary data from example.
|
commit baede5317fe99025e74a944aaeec833d84dc4a04
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 14:27:08 2013 +0200
Removed unneccessary data from example.
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index aff8967..741e1f2 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -47,9 +47,6 @@ FineUploader supports passing custom data through the request as the following e
<script type="text/javascript">
var uploader = new qq.FineUploader({
element: document.getElementById('fine-uploader'),
- text: {
- uploadButton: "{{ 'edit.selectfile' | trans({}, 'myphotos') }}"
- },
request: {
endpoint: "{{ path('_uploader_gallery') }}",
params: {
| 0
|
594def5adbe91d7646d2330b3f11d229b1595874
|
1up-lab/OneupUploaderBundle
|
Allow Symfony 7 (#436)
* 1. Implemented the AsCommand attributes for final $defaultName
2. Removed support for PHP <8.0
3. Reworked the __construct methods to be on-par with php >=8.0
4. Removed all rferences to GetMasterRequest - using only getMainRequest now
5. Fixed custom_uploader.md documentation to use getMainRequest
* Changed the ci.yml fot gihub actions
* Ran php cs fixer for code style
Reran testes, all passes
* Updated php_cs_fixer to v4
Changed the config file to work with the new version
Ran php_cs_fixer on codebase
Tests still pass
* Updated php_stan and config file
* Updated php unit-brdge to v6.0.*
* Add tyope hint var comment/Annotation to the $helper class
* Fixe some more phpstan issues with regards to type hints and retur types
* Some mroe php cs fixer changes
* Removed unused sensio/framework-extra-bundle + updated symfony/phpunit-bridge version constraint
* Allow Symfony 7
* Updated CI to test SF 6.2 - 7.0
* Fixes phpstan errors
* Refactored phpstan fixes
* Fix CI for prefer lowest run
* Drop support for symfony/* ^4.4
* Fix CI for Yaml incompatibility
---------
Co-authored-by: Johan Kasselman <[email protected]>
|
commit 594def5adbe91d7646d2330b3f11d229b1595874
Author: Evert Harmeling <[email protected]>
Date: Mon Feb 5 12:59:17 2024 +0100
Allow Symfony 7 (#436)
* 1. Implemented the AsCommand attributes for final $defaultName
2. Removed support for PHP <8.0
3. Reworked the __construct methods to be on-par with php >=8.0
4. Removed all rferences to GetMasterRequest - using only getMainRequest now
5. Fixed custom_uploader.md documentation to use getMainRequest
* Changed the ci.yml fot gihub actions
* Ran php cs fixer for code style
Reran testes, all passes
* Updated php_cs_fixer to v4
Changed the config file to work with the new version
Ran php_cs_fixer on codebase
Tests still pass
* Updated php_stan and config file
* Updated php unit-brdge to v6.0.*
* Add tyope hint var comment/Annotation to the $helper class
* Fixe some more phpstan issues with regards to type hints and retur types
* Some mroe php cs fixer changes
* Removed unused sensio/framework-extra-bundle + updated symfony/phpunit-bridge version constraint
* Allow Symfony 7
* Updated CI to test SF 6.2 - 7.0
* Fixes phpstan errors
* Refactored phpstan fixes
* Fix CI for prefer lowest run
* Drop support for symfony/* ^4.4
* Fix CI for Yaml incompatibility
---------
Co-authored-by: Johan Kasselman <[email protected]>
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b04960f..c78c8b7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,80 +1,93 @@
name: CI
on:
- pull_request: ~
- push:
- branches:
- - master
- tags:
- - '*'
+ pull_request: ~
+ push:
+ branches:
+ - master
+ tags:
+ - '*'
jobs:
- coding-style:
- name: Coding Style
- runs-on: ubuntu-latest
- steps:
- - name: Setup PHP
- uses: shivammathur/[email protected]
- with:
- php-version: 7.4
- extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
- coverage: none
+ coding-style:
+ name: Coding Style
+ runs-on: ubuntu-latest
+ steps:
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: 8.0
+ extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo, zlib
+ coverage: none
- - name: Checkout
- uses: actions/checkout@v2
+ - name: Checkout
+ uses: actions/checkout@v3
- - name: Install the dependencies
- run: composer install --no-interaction --no-suggest
- - name: Check the coding style
- run: vendor/bin/php-cs-fixer fix --diff --dry-run
- - name: Analyze the code
- run: vendor/bin/phpstan analyze src/ tests/ --level=max
+ - name: Install the dependencies
+ run: composer install --no-interaction
- tests:
- name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }}
- runs-on: ubuntu-latest
- strategy:
- fail-fast: false
- matrix:
- php: [7.4, 8.0]
- symfony: [4.4, 5.4, 6.0]
- exclude:
- # Symfony 6.0 does not supports php <8.0
- - php: 7.4
- symfony: 6.0
- steps:
- - name: Setup PHP
- uses: shivammathur/[email protected]
- with:
- php-version: ${{ matrix.php }}
- extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
- coverage: none
+ - name: Check the coding style
+ run: vendor/bin/php-cs-fixer fix --diff --dry-run
- - name: Checkout
- uses: actions/checkout@v2
+ - name: Analyze the code
+ run: vendor/bin/phpstan analyze
- - name: Install the dependencies
- run: |
- composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }}
- composer install --no-interaction --no-suggest
- - name: Run the unit tests
- run: vendor/bin/phpunit --colors=always
+ tests:
+ name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }}
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ php: [8.0, 8.1, 8.2]
+ symfony: [5.4, 6.0, 6.1, 6.2, 6.3, 6.4, 7.0]
+ exclude:
+ - php: 8.0
+ symfony: 6.1
+ - php: 8.0
+ symfony: 6.2
+ - php: 8.0
+ symfony: 6.3
+ - php: 8.0
+ symfony: 6.4
+ - php: 8.0
+ symfony: 7.0
+ - php: 8.1
+ symfony: 7.0
+ steps:
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php }}
+ extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
+ coverage: none
- prefer-lowest:
- name: Prefer Lowest
- runs-on: ubuntu-latest
- steps:
- - name: Setup PHP
- uses: shivammathur/[email protected]
- with:
- php-version: 7.4
- extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
- coverage: none
+ - name: Checkout
+ uses: actions/checkout@v3
- - name: Checkout
- uses: actions/checkout@v2
+ - name: Install the dependencies
+ run: |
+ composer require symfony/framework-bundle:^${{ matrix.symfony }} symfony/http-foundation:^${{ matrix.symfony }} symfony/yaml:^${{ matrix.symfony }}
+ composer install --no-interaction --no-suggest
- - name: Install the dependencies
- run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest
- - name: Run the unit tests
- run: vendor/bin/phpunit --colors=always
+ - name: Run the unit tests
+ run: vendor/bin/phpunit --colors=always
+
+ prefer-lowest:
+ name: Prefer Lowest
+ runs-on: ubuntu-latest
+ steps:
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: 8.0
+ extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib
+ coverage: none
+
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Install the dependencies
+ run: composer update --prefer-lowest --prefer-stable --no-interaction
+
+ - name: Run the unit tests
+ run: vendor/bin/phpunit --colors=always
diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php
similarity index 84%
rename from .php_cs.dist
rename to .php-cs-fixer.dist.php
index 428e683..9b9b5f7 100644
--- a/.php_cs.dist
+++ b/.php-cs-fixer.dist.php
@@ -1,17 +1,19 @@
<?php
+use PhpCsFixer\Config;
$finder = PhpCsFixer\Finder::create()
->in([__DIR__ . '/src', __DIR__ . '/tests'])
->exclude(['App/cache', 'App/var'])
;
-return PhpCsFixer\Config::create()
+$config = new Config();
+return $config
->setRules([
'@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
- '@PHP71Migration' => true,
- '@PHP71Migration:risky' => true,
+ '@PHP80Migration' => true,
+ '@PHP80Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'align_multiline_comment' => true,
@@ -21,11 +23,7 @@ return PhpCsFixer\Config::create()
],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
- 'general_phpdoc_annotation_remove' => [
- 'author',
- 'expectedException',
- 'expectedExceptionMessage',
- ],
+ 'general_phpdoc_annotation_remove' => true,
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
diff --git a/composer.json b/composer.json
index f170b07..8924951 100644
--- a/composer.json
+++ b/composer.json
@@ -32,33 +32,32 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
- "symfony/asset": "^4.4 || ^5.4 || ^6.0",
+ "php": "^8.0",
+ "symfony/asset": "^5.4 || ^6.0 || ^7.0",
"symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0",
- "symfony/finder": "^4.4 || ^5.4 || ^6.0",
- "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0",
- "symfony/mime": "^4.4 || ^5.4 || ^6.0",
- "symfony/templating": "^4.4 || ^5.4 || ^6.0",
- "symfony/translation": "^4.4 || ^5.4 || ^6.0",
+ "symfony/finder": "^5.4 || ^6.0 || ^7.0",
+ "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
+ "symfony/mime": "^5.4 || ^6.0 || ^7.0",
+ "symfony/templating": "^5.4 || ^6.0 || ^7.0",
+ "symfony/translation": "^5.4 || ^6.0 || ^7.0",
"symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0",
- "symfony/yaml": "^4.4 || ^5.4 || ^6.0",
+ "symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"twig/twig": "^2.4 || ^3.0"
},
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"doctrine/common": "^2.12 || ^3.0",
"doctrine/doctrine-bundle": "^2.4",
- "friendsofphp/php-cs-fixer": "^2.16",
+ "friendsofphp/php-cs-fixer": "^3.40",
"knplabs/gaufrette": "^0.9",
+ "m2mtech/flysystem-stream-wrapper": "^1.0",
"oneup/flysystem-bundle": "^4.1",
- "phpstan/phpstan": "^0.12.10",
+ "phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^9.5",
- "sensio/framework-extra-bundle": "^5.0 || ^6.0",
- "m2mtech/flysystem-stream-wrapper": "^1.0",
- "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0",
- "symfony/phpunit-bridge": "^5.4",
- "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0",
- "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0",
+ "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
+ "symfony/phpunit-bridge": "^6.0.17 || ^7.0",
+ "symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
+ "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
"twistor/flysystem-stream-wrapper": "^1.0"
},
"suggest": {
diff --git a/doc/custom_uploader.md b/doc/custom_uploader.md
index 5e267f5..93a3a16 100644
--- a/doc/custom_uploader.md
+++ b/doc/custom_uploader.md
@@ -33,14 +33,18 @@ namespace Acme\DemoBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Oneup\UploaderBundle\Controller\UploaderController;
-use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;use Symfony\Component\HttpFoundation\RequestStack;
class CustomUploader extends UploaderController
{
+
+ public function __construct(protected RequestStack $requestStack) {
+ }
+
public function upload()
{
// get some basic stuff together
- $request = $this->container->get('request_stack')->getMasterRequest();
+ $request = $this->requestStack->getMainRequest();
$response = new EmptyResponse();
// get file from request (your own logic)
@@ -100,7 +104,7 @@ class FineUploaderResponse extends AbstractResponse
public function assemble()
{
// explicitly overwrite success and error key
- // as these keys are used internaly by the
+ // as these keys are used internally by the
// frontend uploader
$data = $this->data;
$data['success'] = $this->success;
diff --git a/phpstan.neon b/phpstan.neon
index b945375..db97df9 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,21 +1,44 @@
parameters:
- bootstrapFiles:
- - %rootDir%/../../../vendor/autoload.php
-
- excludes_analyse:
+ level: 9
+ paths:
+ - src
+ - tests
+ excludePaths:
- src/DependencyInjection/Configuration.php
- tests/App/cache
- tests/App/logs
- tests/App/var
- var
- vendor
-
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: false
ignoreErrors:
+ - '#Cannot cast mixed to int\.#'
+ - '#Cannot call method addListener\(\) on mixed\.#'
+ - '#Cannot call method getSize\(\) on mixed\.#'
+ - '#Cannot call method maxSize\(\) on mixed\.#'
+ - '#Cannot call method getPathname\(\) on mixed\.#'
+ - '#Cannot call method getPath\(\) on mixed\.#'
+ - '#Cannot call method getRealPath\(\) on mixed\.#'
+ - '#Cannot call method getBasename\(\) on mixed\.#'
- '#Method Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface::dispatch\(\) invoked with 2 parameters, 1 required\.#'
+ -
+ message: '#Cannot use array destructuring on array<int, string>\|false\.#'
+ path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php'
+ -
+ message: '#Binary operation "/" between string and int results in an error\.#'
+ path: '%currentWorkingDirectory%/src/Controller/BlueimpController.php'
+ -
+ message: '#Dead catch - Gaufrette\\Exception\\FileNotFound is never thrown in the try block\.#'
+ path: '%currentWorkingDirectory%/src/Uploader/Chunk/Storage/GaufretteStorage.php'
+ -
+ message: '#Parameter \#1 \$finfo of function finfo_file|finfo_close expects finfo, resource given\.#'
+ path: '%currentWorkingDirectory%/src/Uploader/File/GaufretteFile.php'
+ -
+ message: '#Parameter \#2 ...\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.#'
+ path: '%currentWorkingDirectory%/src/Controller/PluploadController.php'
-
message: '#Parameter \#1 \$parameters of class Symfony\\Component\\HttpFoundation\\FileBag constructor expects array<Symfony\\Component\\HttpFoundation\\File\\UploadedFile>, array<int, Symfony\\Component\\HttpFoundation\\File\\UploadedFile\|null> given\.#'
path: '%currentWorkingDirectory%/tests/Controller/FileBagExtractorTest.php'
diff --git a/src/Command/ClearChunkCommand.php b/src/Command/ClearChunkCommand.php
index 4385071..eda3ee6 100644
--- a/src/Command/ClearChunkCommand.php
+++ b/src/Command/ClearChunkCommand.php
@@ -5,14 +5,16 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Command;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+#[AsCommand(
+ name: 'oneup:uploader:clear-chunks'
+)]
class ClearChunkCommand extends Command
{
- protected static $defaultName = 'oneup:uploader:clear-chunks'; // Make command lazy load
-
/**
* @var ChunkManager
*/
diff --git a/src/Command/ClearOrphansCommand.php b/src/Command/ClearOrphansCommand.php
index 80b7814..717c59f 100644
--- a/src/Command/ClearOrphansCommand.php
+++ b/src/Command/ClearOrphansCommand.php
@@ -5,10 +5,14 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Command;
use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager;
+use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
+#[AsCommand(
+ name: 'oneup:uploader:clear-orphans'
+)]
class ClearOrphansCommand extends Command
{
protected static $defaultName = 'oneup:uploader:clear-orphans';
diff --git a/src/Controller/AbstractChunkedController.php b/src/Controller/AbstractChunkedController.php
index 20234f6..c169915 100644
--- a/src/Controller/AbstractChunkedController.php
+++ b/src/Controller/AbstractChunkedController.php
@@ -7,6 +7,7 @@ namespace Oneup\UploaderBundle\Controller;
use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
@@ -70,7 +71,10 @@ abstract class AbstractChunkedController extends AbstractController
// with reassembling the parts
if ($last) {
$path = $assembled->getPath();
- $this->handleUpload($assembled, $response, $request);
+ if ($assembled instanceof File) {
+ $this->handleUpload($assembled, $response, $request);
+ }
+ // @todo $assembled is of type mixed, so would error without check
$chunkManager->cleanup($path);
}
diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php
index 8d77b50..76ba042 100644
--- a/src/Controller/AbstractController.php
+++ b/src/Controller/AbstractController.php
@@ -15,6 +15,7 @@ use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\FileBag;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -24,38 +25,8 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
abstract class AbstractController
{
- /**
- * @var ErrorHandlerInterface
- */
- protected $errorHandler;
-
- /**
- * @var ContainerInterface
- */
- protected $container;
-
- /**
- * @var StorageInterface
- */
- protected $storage;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var string
- */
- protected $type;
-
- public function __construct(ContainerInterface $container, StorageInterface $storage, ErrorHandlerInterface $errorHandler, array $config, string $type)
+ public function __construct(protected ContainerInterface $container, protected StorageInterface $storage, protected ErrorHandlerInterface $errorHandler, protected array $config, protected string $type)
{
- $this->errorHandler = $errorHandler;
- $this->container = $container;
- $this->storage = $storage;
- $this->config = $config;
- $this->type = $type;
}
abstract public function upload(): JsonResponse;
@@ -66,12 +37,13 @@ abstract class AbstractController
$session = $request->getSession();
- $prefix = (string) ini_get('session.upload_progress.prefix');
- $name = (string) ini_get('session.upload_progress.name');
-
+ $prefix = (string) \ini_get('session.upload_progress.prefix');
+ $name = (string) \ini_get('session.upload_progress.name');
+ /** @var string $value */
+ $value = $request->get($name);
// assemble session key
// ref: http://php.net/manual/en/session.upload-progress.php
- $key = sprintf('%s.%s', $prefix, $request->get($name));
+ $key = sprintf('%s.%s', $prefix, $value);
$value = $session->get($key);
return new JsonResponse($value);
@@ -83,11 +55,13 @@ abstract class AbstractController
$session = $request->getSession();
- $prefix = (string) ini_get('session.upload_progress.prefix');
- $name = (string) ini_get('session.upload_progress.name');
-
- $key = sprintf('%s.%s', $prefix, $request->get($name));
+ $prefix = (string) \ini_get('session.upload_progress.prefix');
+ $name = (string) \ini_get('session.upload_progress.name');
+ /** @var string $value */
+ $value = $request->get($name);
+ $key = sprintf('%s.%s', $prefix, $value);
+ /** @var array $progress */
$progress = $session->get($key);
$progress['cancel_upload'] = false;
@@ -127,9 +101,9 @@ abstract class AbstractController
*
* Note: The return value differs when
*
- * @param mixed $file The file to upload
+ * @param File $file The file to upload
*/
- protected function handleUpload($file, ResponseInterface $response, Request $request): void
+ protected function handleUpload(File $file, ResponseInterface $response, Request $request): void
{
// wrap the file if it is not done yet which can only happen
// if it wasn't a chunked upload, in which case it is definitely
@@ -148,6 +122,7 @@ abstract class AbstractController
$name = $namer->name($file);
// perform the real upload
+ /** @var File $uploaded */
$uploaded = $this->storage->upload($file, $name);
$this->dispatchPostEvents($uploaded, $response, $request);
@@ -156,9 +131,9 @@ abstract class AbstractController
/**
* This function is a helper function which dispatches pre upload event.
*
- * @param FileInterface $uploaded the uploaded file
- * @param ResponseInterface $response a response object
- * @param Request $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): void
{
@@ -172,9 +147,9 @@ abstract class AbstractController
* This function is a helper function which dispatches post upload
* and post persist events.
*
- * @param mixed $uploaded the uploaded file
+ * @param File $uploaded the uploaded file
*/
- protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request): void
+ protected function dispatchPostEvents(File $uploaded, ResponseInterface $response, Request $request): void
{
// dispatch post upload event (both the specific and the general)
$postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
@@ -201,10 +176,8 @@ abstract class AbstractController
*
* On top of that, if the client does not support the application/json type,
* then the content type of the response will be set to text/plain instead.
- *
- * @param mixed $data
*/
- protected function createSupportedJsonResponse($data, int $statusCode = 200): JsonResponse
+ protected function createSupportedJsonResponse(mixed $data, int $statusCode = 200): JsonResponse
{
$request = $this->getRequest();
$response = new JsonResponse($data, $statusCode);
@@ -223,9 +196,7 @@ abstract class AbstractController
$requestStack = $this->container->get('request_stack');
/** @var Request $request */
- $request = method_exists($requestStack, 'getMainRequest')
- ? $requestStack->getMainRequest()
- : $requestStack->getMasterRequest();
+ $request = $requestStack->getMainRequest();
return $request;
}
diff --git a/src/Controller/BlueimpController.php b/src/Controller/BlueimpController.php
index aa1c778..d2cf2d9 100644
--- a/src/Controller/BlueimpController.php
+++ b/src/Controller/BlueimpController.php
@@ -39,11 +39,14 @@ class BlueimpController extends AbstractChunkedController
$session = $request->getSession();
- $prefix = (string) ini_get('session.upload_progress.prefix');
- $name = (string) ini_get('session.upload_progress.name');
+ $prefix = (string) \ini_get('session.upload_progress.prefix');
+ $name = (string) \ini_get('session.upload_progress.name');
+ /** @var string $value */
+ $value = $request->get($name);
// ref: https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-Session-Upload-Progress
- $key = sprintf('%s.%s', $prefix, $request->get($name));
+ $key = sprintf('%s.%s', $prefix, $value);
+ /** @var array<string, mixed> $value */
$value = $session->get($key);
$progress = [
diff --git a/src/Controller/DropzoneController.php b/src/Controller/DropzoneController.php
index 3b642f8..ccc5fd6 100644
--- a/src/Controller/DropzoneController.php
+++ b/src/Controller/DropzoneController.php
@@ -29,7 +29,7 @@ class DropzoneController extends AbstractChunkedController
$this->handleUpload($file, $response, $request)
;
} catch (UploadException $e) {
- $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x
+ $statusCode = 500; // Dropzone displays error if HTTP response is 40x or 50x
$this->errorHandler->addException($response, $e);
/** @var TranslatorInterface $translator */
@@ -53,10 +53,11 @@ class DropzoneController extends AbstractChunkedController
$uuid = $request->get('dzuuid');
/**
- * @var UploadedFile
+ * @var UploadedFile $file
*/
- $file = $request->files->get('file')->getClientOriginalName();
- $orig = $file;
+ $file = $request->files->get('file');
+ $fileName = $file->getClientOriginalName();
+ $orig = $fileName;
return [$last, $uuid, $index, $orig];
}
diff --git a/src/Controller/MooUploadController.php b/src/Controller/MooUploadController.php
index 59abc91..176729d 100644
--- a/src/Controller/MooUploadController.php
+++ b/src/Controller/MooUploadController.php
@@ -74,7 +74,9 @@ class MooUploadController extends AbstractChunkedController
try {
// loop through every file that has been uploaded before
- foreach ($chunkManager->getChunks((string) $uuid) as $file) {
+ /** @var iterable $chunks */
+ $chunks = $chunkManager->getChunks((string) $uuid);
+ foreach ($chunks as $file) {
$size += $file->getSize();
}
} catch (\InvalidArgumentException $e) {
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
index ae0ac4a..e8fff45 100644
--- a/src/DependencyInjection/Configuration.php
+++ b/src/DependencyInjection/Configuration.php
@@ -106,9 +106,7 @@ class Configuration implements ConfigurationInterface
->prototype('scalar')
->beforeNormalization()
->ifString()
- ->then(function ($v) {
- return strtolower($v);
- })
+ ->then(fn ($v) => strtolower($v))
->end()
->end()
->end()
diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php
index 56195e5..af23747 100644
--- a/src/DependencyInjection/OneupUploaderExtension.php
+++ b/src/DependencyInjection/OneupUploaderExtension.php
@@ -108,12 +108,12 @@ class OneupUploaderExtension extends Extension
} else {
$customFrontend = $config['custom_frontend'];
- $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
- $controllerType = $customFrontend['class'];
-
- if (empty($controllerName) || empty($controllerType)) {
+ if (empty($customFrontend['name']) || empty($customFrontend['class'])) {
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.');
}
+
+ $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
+ $controllerType = $customFrontend['class'];
}
$errorHandler = $this->createErrorHandler($config);
@@ -271,7 +271,7 @@ class OneupUploaderExtension extends Extension
break;
}
- if (\strlen($filesystem) <= 0) {
+ if ('' === $filesystem) {
throw new ServiceNotFoundException('Empty service name');
}
@@ -285,14 +285,11 @@ class OneupUploaderExtension extends Extension
->addArgument($prefix);
}
- /**
- * @param mixed $input
- */
- protected function getMaxUploadSize($input): int
+ protected function getMaxUploadSize(mixed $input): int
{
$input = $this->getValueInBytes($input);
- $maxPost = $this->getValueInBytes(ini_get('upload_max_filesize'));
- $maxFile = $this->getValueInBytes(ini_get('post_max_size'));
+ $maxPost = $this->getValueInBytes(\ini_get('upload_max_filesize'));
+ $maxFile = $this->getValueInBytes(\ini_get('post_max_size'));
if ($input < 0) {
return min($maxPost, $maxFile);
@@ -301,24 +298,25 @@ class OneupUploaderExtension extends Extension
return min(min($input, $maxPost), $maxFile);
}
- /**
- * @param mixed $input
- */
- protected function getValueInBytes($input): int
+ protected function getValueInBytes(mixed $input): int
{
// see: http://www.php.net/manual/en/function.ini-get.php
+ if (!\is_scalar($input)) {
+ return -1;
+ }
+
$input = trim((string) $input);
$last = strtolower($input[\strlen($input) - 1]);
$numericInput = (float) substr($input, 0, -1);
switch ($last) {
case 'g': $numericInput *= 1024;
- // no break
+ // no break
case 'm': $numericInput *= 1024;
- // no break
+ // no break
case 'k': $numericInput *= 1024;
- return (int) $numericInput;
+ return (int) $numericInput;
}
return (int) $input;
diff --git a/src/Event/PostChunkUploadEvent.php b/src/Event/PostChunkUploadEvent.php
index 83f9292..fe2014e 100644
--- a/src/Event/PostChunkUploadEvent.php
+++ b/src/Event/PostChunkUploadEvent.php
@@ -13,53 +13,11 @@ class PostChunkUploadEvent extends Event
{
public const NAME = UploadEvents::POST_CHUNK_UPLOAD;
- /**
- * @var mixed
- */
- protected $chunk;
-
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @var string
- */
- protected $type;
-
- /**
- * @var ResponseInterface
- */
- protected $response;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var bool
- */
- protected $isLast;
-
- /**
- * @param mixed $chunk
- */
- public function __construct($chunk, ResponseInterface $response, Request $request, bool $isLast, string $type, array $config)
+ public function __construct(protected mixed $chunk, protected ResponseInterface $response, protected Request $request, protected bool $isLast, protected string $type, protected array $config)
{
- $this->chunk = $chunk;
- $this->request = $request;
- $this->response = $response;
- $this->isLast = $isLast;
- $this->type = $type;
- $this->config = $config;
}
- /**
- * @return mixed
- */
- public function getChunk()
+ public function getChunk(): mixed
{
return $this->chunk;
}
diff --git a/src/Event/PostPersistEvent.php b/src/Event/PostPersistEvent.php
index d5db86c..5cc6b60 100644
--- a/src/Event/PostPersistEvent.php
+++ b/src/Event/PostPersistEvent.php
@@ -15,41 +15,8 @@ class PostPersistEvent extends Event
{
public const NAME = UploadEvents::POST_PERSIST;
- /**
- * @var FileInterface|File
- */
- protected $file;
-
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @var string
- */
- protected $type;
-
- /**
- * @var ResponseInterface
- */
- protected $response;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @param FileInterface|File $file
- */
- public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
+ public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config)
{
- $this->file = $file;
- $this->request = $request;
- $this->response = $response;
- $this->type = $type;
- $this->config = $config;
}
/**
diff --git a/src/Event/PostUploadEvent.php b/src/Event/PostUploadEvent.php
index 3149547..f1b575c 100644
--- a/src/Event/PostUploadEvent.php
+++ b/src/Event/PostUploadEvent.php
@@ -15,41 +15,8 @@ class PostUploadEvent extends Event
{
public const NAME = UploadEvents::POST_UPLOAD;
- /**
- * @var FileInterface|File
- */
- protected $file;
-
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @var string
- */
- protected $type;
-
- /**
- * @var ResponseInterface
- */
- protected $response;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @param FileInterface|File $file
- */
- public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
+ public function __construct(protected FileInterface|File $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config)
{
- $this->file = $file;
- $this->request = $request;
- $this->response = $response;
- $this->type = $type;
- $this->config = $config;
}
/**
diff --git a/src/Event/PreUploadEvent.php b/src/Event/PreUploadEvent.php
index 9398907..158be01 100644
--- a/src/Event/PreUploadEvent.php
+++ b/src/Event/PreUploadEvent.php
@@ -15,41 +15,8 @@ class PreUploadEvent extends Event
{
public const NAME = UploadEvents::PRE_UPLOAD;
- /**
- * @var FileInterface|File
- */
- protected $file;
-
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @var string
- */
- protected $type;
-
- /**
- * @var ResponseInterface
- */
- protected $response;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @param FileInterface|File $file
- */
- public function __construct($file, ResponseInterface $response, Request $request, string $type, array $config)
+ public function __construct(protected File|FileInterface $file, protected ResponseInterface $response, protected Request $request, protected string $type, protected array $config)
{
- $this->file = $file;
- $this->request = $request;
- $this->response = $response;
- $this->type = $type;
- $this->config = $config;
}
/**
diff --git a/src/Event/ValidationEvent.php b/src/Event/ValidationEvent.php
index 1481b00..d41a05b 100644
--- a/src/Event/ValidationEvent.php
+++ b/src/Event/ValidationEvent.php
@@ -15,41 +15,8 @@ class ValidationEvent extends Event
{
public const NAME = UploadEvents::VALIDATION;
- /**
- * @var FileInterface|File
- */
- protected $file;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var string
- */
- protected $type;
-
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @var ResponseInterface|null
- */
- protected $response;
-
- /**
- * @param FileInterface|File $file
- */
- public function __construct($file, Request $request, array $config, string $type, ResponseInterface $response = null)
+ public function __construct(protected FileInterface|File $file, protected Request $request, protected array $config, protected string $type, protected ?ResponseInterface $response = null)
{
- $this->file = $file;
- $this->config = $config;
- $this->type = $type;
- $this->request = $request;
- $this->response = $response;
}
/**
diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php
index 0f38843..39279c0 100644
--- a/src/Routing/RouteLoader.php
+++ b/src/Routing/RouteLoader.php
@@ -10,30 +10,17 @@ use Symfony\Component\Routing\RouteCollection;
class RouteLoader extends Loader
{
- /**
- * @var array
- */
- protected $controllers;
-
- public function __construct(array $controllers)
+ public function __construct(protected array $controllers)
{
- $this->controllers = $controllers;
+ parent::__construct();
}
- /**
- * @param mixed $resource
- * @param string|null $type
- */
- public function supports($resource, $type = null): bool
+ public function supports(mixed $resource, string $type = null): bool
{
return 'uploader' === $type;
}
- /**
- * @param mixed $resource
- * @param string|null $type
- */
- public function load($resource, $type = null): RouteCollection
+ public function load(mixed $resource, string $type = null): RouteCollection
{
$routes = new RouteCollection();
$separator = '::';
diff --git a/src/Templating/Helper/UploaderHelper.php b/src/Templating/Helper/UploaderHelper.php
index 6fb0664..70e89ae 100644
--- a/src/Templating/Helper/UploaderHelper.php
+++ b/src/Templating/Helper/UploaderHelper.php
@@ -9,20 +9,8 @@ use Symfony\Component\Templating\Helper\Helper;
class UploaderHelper extends Helper
{
- /**
- * @var RouterInterface
- */
- protected $router;
-
- /**
- * @var array
- */
- protected $maxsize;
-
- public function __construct(RouterInterface $router, array $maxsize)
+ public function __construct(protected RouterInterface $router, protected array $maxsize)
{
- $this->router = $router;
- $this->maxsize = $maxsize;
}
public function getName(): string
@@ -47,13 +35,10 @@ class UploaderHelper extends Helper
public function uploadKey(): string
{
- return (string) ini_get('session.upload_progress.name');
+ return (string) \ini_get('session.upload_progress.name');
}
- /**
- * @return mixed
- */
- public function maxSize(string $key)
+ public function maxSize(string $key): int
{
if (!\array_key_exists($key, $this->maxsize)) {
throw new \InvalidArgumentException('No such mapping found to get maxsize for.');
diff --git a/src/Twig/Extension/UploaderExtension.php b/src/Twig/Extension/UploaderExtension.php
index 6e291e6..ec62cc1 100644
--- a/src/Twig/Extension/UploaderExtension.php
+++ b/src/Twig/Extension/UploaderExtension.php
@@ -10,14 +10,8 @@ use Twig\TwigFunction;
class UploaderExtension extends AbstractExtension
{
- /**
- * @var UploaderHelper
- */
- protected $helper;
-
- public function __construct(UploaderHelper $helper)
+ public function __construct(protected UploaderHelper $helper)
{
- $this->helper = $helper;
}
public function getName(): string
@@ -56,10 +50,7 @@ class UploaderExtension extends AbstractExtension
return $this->helper->uploadKey();
}
- /**
- * @return mixed
- */
- public function maxSize(string $key)
+ public function maxSize(string $key): int
{
return $this->helper->maxSize($key);
}
diff --git a/src/Uploader/Chunk/ChunkManager.php b/src/Uploader/Chunk/ChunkManager.php
index 9d52e13..989f8a0 100644
--- a/src/Uploader/Chunk/ChunkManager.php
+++ b/src/Uploader/Chunk/ChunkManager.php
@@ -9,20 +9,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
class ChunkManager implements ChunkManagerInterface
{
- /**
- * @var array
- */
- protected $configuration;
-
- /**
- * @var ChunkStorageInterface
- */
- protected $storage;
-
- public function __construct(array $configuration, ChunkStorageInterface $storage)
+ public function __construct(protected array $configuration, protected ChunkStorageInterface $storage)
{
- $this->configuration = $configuration;
- $this->storage = $storage;
}
public function clear(): void
@@ -30,12 +18,12 @@ class ChunkManager implements ChunkManagerInterface
$this->storage->clear($this->configuration['maxage']);
}
- public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original)
+ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed
{
return $this->storage->addChunk($uuid, $index, $chunk, $original);
}
- public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false)
+ public function assembleChunks(mixed $chunks, bool $removeChunk = true, bool $renameChunk = false): mixed
{
return $this->storage->assembleChunks($chunks, $removeChunk, $renameChunk);
}
@@ -45,7 +33,7 @@ class ChunkManager implements ChunkManagerInterface
$this->storage->cleanup($path);
}
- public function getChunks(string $uuid)
+ public function getChunks(string $uuid): mixed
{
return $this->storage->getChunks($uuid);
}
diff --git a/src/Uploader/Chunk/ChunkManagerInterface.php b/src/Uploader/Chunk/ChunkManagerInterface.php
index 579d406..f4aac04 100644
--- a/src/Uploader/Chunk/ChunkManagerInterface.php
+++ b/src/Uploader/Chunk/ChunkManagerInterface.php
@@ -4,35 +4,27 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\Chunk;
-use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
interface ChunkManagerInterface
{
/**
* Adds a new Chunk to a given uuid.
- *
- * @return mixed
*/
- public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original);
+ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed;
/**
* Assembles the given chunks and return the resulting file.
*
- * @param mixed $chunks
- * @param bool $removeChunk remove the chunk file once its assembled
- * @param bool $renameChunk rename the chunk file once its assembled
- *
- * @return mixed
+ * @param bool $removeChunk remove the chunk file once its assembled
+ * @param bool $renameChunk rename the chunk file once its assembled
*/
- public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false);
+ public function assembleChunks(mixed $chunks, bool $removeChunk = true, bool $renameChunk = false): mixed;
/**
* Get chunks associated with the given uuid.
- *
- * @return mixed
*/
- public function getChunks(string $uuid);
+ public function getChunks(string $uuid): mixed;
/**
* Clean a given path.
diff --git a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php
index 5d4bfc3..11f8225 100644
--- a/src/Uploader/Chunk/Storage/ChunkStorageInterface.php
+++ b/src/Uploader/Chunk/Storage/ChunkStorageInterface.php
@@ -10,22 +10,11 @@ interface ChunkStorageInterface
{
public function clear(int $maxAge): void;
- /**
- * @return mixed
- */
- public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original);
-
- /**
- * @param mixed $chunks
- *
- * @return mixed
- */
- public function assembleChunks($chunks, bool $removeChunk, bool $renameChunk);
+ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed;
+
+ public function assembleChunks(mixed $chunks, bool $removeChunk, bool $renameChunk): mixed;
public function cleanup(string $path): void;
- /**
- * @return mixed
- */
- public function getChunks(string $uuid);
+ public function getChunks(string $uuid): mixed;
}
diff --git a/src/Uploader/Chunk/Storage/FilesystemStorage.php b/src/Uploader/Chunk/Storage/FilesystemStorage.php
index 760084d..4262bf3 100644
--- a/src/Uploader/Chunk/Storage/FilesystemStorage.php
+++ b/src/Uploader/Chunk/Storage/FilesystemStorage.php
@@ -12,14 +12,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
class FilesystemStorage implements ChunkStorageInterface
{
- /**
- * @var string
- */
- protected $directory;
-
- public function __construct(string $directory)
+ public function __construct(protected string $directory)
{
- $this->directory = $directory;
}
public function clear(int $maxAge): void
diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php
index 9b3a642..f28bd0c 100644
--- a/src/Uploader/Chunk/Storage/FlysystemStorage.php
+++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -13,40 +13,13 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
class FlysystemStorage implements ChunkStorageInterface
{
- /**
- * @var int
- */
- public $bufferSize;
-
- /**
- * @var array
- */
- protected $unhandledChunk;
-
- /**
- * @var string
- */
- protected $prefix;
+ protected array $unhandledChunk = [];
- /**
- * @var string
- */
- protected $streamWrapperPrefix;
-
- /**
- * @var FilesystemOperator
- */
- private $filesystem;
-
- public function __construct(Filesystem $filesystem, int $bufferSize, string $streamWrapperPrefix, string $prefix)
+ public function __construct(protected Filesystem $filesystem, public int $bufferSize, protected string $streamWrapperPrefix, protected string $prefix)
{
- $this->filesystem = $filesystem;
- $this->bufferSize = $bufferSize;
- $this->prefix = $prefix;
- $this->streamWrapperPrefix = $streamWrapperPrefix;
}
- public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void
+ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed
{
// Prevent path traversal attacks
$uuid = basename($uuid);
@@ -57,6 +30,8 @@ class FlysystemStorage implements ChunkStorageInterface
'chunk' => $chunk,
'original' => $original,
];
+
+ return null;
}
/**
@@ -168,7 +143,7 @@ class FlysystemStorage implements ChunkStorageInterface
$uuid = basename($uuid);
return $this->filesystem->listContents($this->prefix . '/' . $uuid)
- ->filter(function (StorageAttributes $attributes) { return $attributes->isFile(); })
+ ->filter(fn (StorageAttributes $attributes) => $attributes->isFile())
->sortByPath()
->map(function (StorageAttributes $attributes) {
return [
diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php
index 581adea..345f028 100644
--- a/src/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -20,24 +20,14 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
*/
protected $unhandledChunk;
- /**
- * @var string
- */
- protected $prefix;
-
- /**
- * @var string|null
- */
- protected $streamWrapperPrefix;
-
- public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?string $streamWrapperPrefix, string $prefix)
+ public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix, protected string $prefix)
{
$base = interface_exists(FilesystemInterface::class)
? FilesystemInterface::class
: Filesystem::class;
if (!$filesystem instanceof $base) {
- throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, \get_class($filesystem)));
+ throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, $filesystem::class));
}
if ($filesystem instanceof Filesystem && !($filesystem->getAdapter() instanceof StreamFactory)) {
@@ -45,8 +35,6 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
}
$this->filesystem = $filesystem;
$this->buffersize = $bufferSize;
- $this->prefix = $prefix;
- $this->streamWrapperPrefix = $streamWrapperPrefix;
}
/**
@@ -105,7 +93,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
* for gaufrette based chunk storage therefore assembleChunks will
* be called in the same request.
*/
- public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): void
+ public function addChunk(string $uuid, int $index, UploadedFile $chunk, string $original): mixed
{
// Prevent path traversal attacks
$uuid = basename($uuid);
@@ -116,6 +104,8 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
'chunk' => $chunk,
'original' => $original,
];
+
+ return null;
}
/**
diff --git a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php
index 2af40b4..3fd3f40 100644
--- a/src/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/src/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -4,23 +4,16 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
-use Exception;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
class BlueimpErrorHandler implements ErrorHandlerInterface
{
- /**
- * @var TranslatorInterface
- */
- private $translator;
-
- public function __construct(TranslatorInterface $translator)
+ public function __construct(private TranslatorInterface $translator)
{
- $this->translator = $translator;
}
- public function addException(AbstractResponse $response, Exception $exception): void
+ public function addException(AbstractResponse $response, \Exception $exception): void
{
$message = $this->translator->trans($exception->getMessage(), [], 'OneupUploaderBundle');
$response->addToOffset(['error' => $message], ['files']);
diff --git a/src/Uploader/ErrorHandler/DropzoneErrorHandler.php b/src/Uploader/ErrorHandler/DropzoneErrorHandler.php
index f1d578d..3430f1f 100755
--- a/src/Uploader/ErrorHandler/DropzoneErrorHandler.php
+++ b/src/Uploader/ErrorHandler/DropzoneErrorHandler.php
@@ -4,12 +4,11 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
-use Exception;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
class DropzoneErrorHandler implements ErrorHandlerInterface
{
- public function addException(AbstractResponse $response, Exception $exception): void
+ public function addException(AbstractResponse $response, \Exception $exception): void
{
$errors[] = $exception;
$message = $exception->getMessage();
diff --git a/src/Uploader/ErrorHandler/ErrorHandlerInterface.php b/src/Uploader/ErrorHandler/ErrorHandlerInterface.php
index a1b3571..28875e4 100644
--- a/src/Uploader/ErrorHandler/ErrorHandlerInterface.php
+++ b/src/Uploader/ErrorHandler/ErrorHandlerInterface.php
@@ -4,10 +4,9 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
-use Exception;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
interface ErrorHandlerInterface
{
- public function addException(AbstractResponse $response, Exception $exception): void;
+ public function addException(AbstractResponse $response, \Exception $exception): void;
}
diff --git a/src/Uploader/ErrorHandler/NoopErrorHandler.php b/src/Uploader/ErrorHandler/NoopErrorHandler.php
index 71826d3..57dea36 100644
--- a/src/Uploader/ErrorHandler/NoopErrorHandler.php
+++ b/src/Uploader/ErrorHandler/NoopErrorHandler.php
@@ -4,12 +4,11 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
-use Exception;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
class NoopErrorHandler implements ErrorHandlerInterface
{
- public function addException(AbstractResponse $response, Exception $exception): void
+ public function addException(AbstractResponse $response, \Exception $exception): void
{
// noop
}
diff --git a/src/Uploader/ErrorHandler/PluploadErrorHandler.php b/src/Uploader/ErrorHandler/PluploadErrorHandler.php
index 6d4c0d7..1ad33e7 100644
--- a/src/Uploader/ErrorHandler/PluploadErrorHandler.php
+++ b/src/Uploader/ErrorHandler/PluploadErrorHandler.php
@@ -4,12 +4,11 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
-use Exception;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
class PluploadErrorHandler implements ErrorHandlerInterface
{
- public function addException(AbstractResponse $response, Exception $exception): void
+ public function addException(AbstractResponse $response, \Exception $exception): void
{
/* Plupload only needs an error message so it can be handled client side */
$message = $exception->getMessage();
diff --git a/src/Uploader/File/FileInterface.php b/src/Uploader/File/FileInterface.php
index cea4878..d69b13e 100644
--- a/src/Uploader/File/FileInterface.php
+++ b/src/Uploader/File/FileInterface.php
@@ -4,8 +4,6 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\File;
-use Symfony\Component\HttpFoundation\File\File;
-
/**
* Every function in this interface should be considered unsafe.
* They are only meant to abstract away some basic file functionality.
@@ -39,7 +37,7 @@ interface FileInterface
/**
* Returns the guessed mime type of the file.
*
- * @return string
+ * @return string|null
*/
public function getMimeType();
@@ -55,8 +53,5 @@ interface FileInterface
*/
public function getExtension(): string;
- /**
- * @return mixed
- */
- public function getFileSystem();
+ public function getFileSystem(): mixed;
}
diff --git a/src/Uploader/File/FilesystemFile.php b/src/Uploader/File/FilesystemFile.php
index 5e35356..e63f00c 100644
--- a/src/Uploader/File/FilesystemFile.php
+++ b/src/Uploader/File/FilesystemFile.php
@@ -23,7 +23,7 @@ class FilesystemFile extends UploadedFile implements FileInterface
return $this->getClientOriginalExtension();
}
- public function getFileSystem()
+ public function getFileSystem(): mixed
{
return null;
}
diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php
index ab179a9..a0bd166 100644
--- a/src/Uploader/File/FlysystemFile.php
+++ b/src/Uploader/File/FlysystemFile.php
@@ -9,22 +9,14 @@ use League\Flysystem\FilesystemOperator;
class FlysystemFile implements FileInterface
{
- /** @var string */
- private $pathname;
-
- /** @var FilesystemOperator */
- private $filesystem;
-
- public function __construct(string $pathname, FilesystemOperator $filesystem)
+ public function __construct(private string $pathname, private FilesystemOperator $filesystem)
{
- $this->pathname = $pathname;
- $this->filesystem = $filesystem;
}
/**
* @throws FilesystemException
*/
- public function getSize(): int
+ public function getSize()
{
return $this->filesystem->fileSize($this->pathname);
}
@@ -42,7 +34,7 @@ class FlysystemFile implements FileInterface
/**
* @throws FilesystemException
*/
- public function getMimeType(): string
+ public function getMimeType()
{
return $this->filesystem->mimeType($this->pathname);
}
diff --git a/src/Uploader/File/GaufretteFile.php b/src/Uploader/File/GaufretteFile.php
index 82c7664..f7e24db 100644
--- a/src/Uploader/File/GaufretteFile.php
+++ b/src/Uploader/File/GaufretteFile.php
@@ -11,21 +11,14 @@ use Gaufrette\FilesystemInterface;
class GaufretteFile extends File implements FileInterface
{
- /**
- * @var string|null
- */
- protected $streamWrapperPrefix;
-
/**
* @var string
*/
protected $mimeType;
- public function __construct(File $file, FilesystemInterface $filesystem, string $streamWrapperPrefix = null)
+ public function __construct(File $file, FilesystemInterface $filesystem, protected ?string $streamWrapperPrefix = null)
{
parent::__construct($file->getKey(), $filesystem);
-
- $this->streamWrapperPrefix = $streamWrapperPrefix;
}
/**
@@ -38,7 +31,7 @@ class GaufretteFile extends File implements FileInterface
* and will have heavy performance footprint.
* !! ------- !!
*/
- public function getSize(): int
+ public function getSize()
{
// This can only work on streamable files, so basically local files,
// still only perform it once even on local files to avoid bothering the filesystem.php g
@@ -74,7 +67,7 @@ class GaufretteFile extends File implements FileInterface
return pathinfo($this->getKey(), \PATHINFO_BASENAME);
}
- public function getMimeType(): string
+ public function getMimeType()
{
// This can only work on streamable files, so basically local files,
// still only perform it once even on local files to avoid bothering the filesystem.
diff --git a/src/Uploader/Orphanage/OrphanageManager.php b/src/Uploader/Orphanage/OrphanageManager.php
index 8a15620..500e6f1 100644
--- a/src/Uploader/Orphanage/OrphanageManager.php
+++ b/src/Uploader/Orphanage/OrphanageManager.php
@@ -12,20 +12,8 @@ use Symfony\Component\Finder\Finder;
class OrphanageManager
{
- /**
- * @var ContainerInterface
- */
- protected $container;
-
- /**
- * @var array
- */
- protected $config;
-
- public function __construct(ContainerInterface $container, array $config)
+ public function __construct(protected ContainerInterface $container, protected array $config)
{
- $this->container = $container;
- $this->config = $config;
}
public function has(string $key): bool
diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php
index e2507e0..38e6628 100644
--- a/src/Uploader/Response/AbstractResponse.php
+++ b/src/Uploader/Response/AbstractResponse.php
@@ -6,44 +6,26 @@ namespace Oneup\UploaderBundle\Uploader\Response;
abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
{
- /**
- * @var array
- */
- protected $data;
-
- public function __construct()
+ public function __construct(protected array $data = [])
{
- $this->data = [];
}
- /**
- * @param mixed $offset
- * @param mixed $value
- */
public function offsetSet($offset, $value): void
{
null === $offset ? $this->data[] = $value : $this->data[$offset] = $value;
}
- /**
- * @param mixed $offset
- */
public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
}
- /**
- * @param mixed $offset
- */
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
/**
- * @param mixed $offset
- *
* @return mixed|null
*/
#[\ReturnTypeWillChange]
@@ -53,14 +35,12 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
}
/**
- * The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar
+ * The \ArrayAccess interface does not support multidimensional array syntax such as $array["foo"][] = bar
* This function will take a path of arrays and add a new element to it, creating the path if needed.
*
- * @param mixed $value
- *
* @throws \InvalidArgumentException if the path contains non-array items
*/
- public function addToOffset($value, array $offsets): void
+ public function addToOffset(array $value, array $offsets): void
{
$element = &$this->data;
foreach ($offsets as $offset) {
diff --git a/src/Uploader/Response/FineUploaderResponse.php b/src/Uploader/Response/FineUploaderResponse.php
index 907a7bc..b37b310 100644
--- a/src/Uploader/Response/FineUploaderResponse.php
+++ b/src/Uploader/Response/FineUploaderResponse.php
@@ -6,28 +6,15 @@ namespace Oneup\UploaderBundle\Uploader\Response;
class FineUploaderResponse extends AbstractResponse
{
- /**
- * @var bool
- */
- protected $success;
-
- /**
- * @var string|null
- */
- protected $error;
-
- public function __construct()
+ public function __construct(protected bool $success = true, protected ?string $error = null)
{
- $this->success = true;
- $this->error = null;
-
parent::__construct();
}
public function assemble(): array
{
// explicitly overwrite success and error key
- // as these keys are used internaly by the
+ // as these keys are used internally by the
// frontend uploader
$data = $this->data;
$data['success'] = $this->success;
diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php
index f566c9c..3a5cad9 100644
--- a/src/Uploader/Response/MooUploadResponse.php
+++ b/src/Uploader/Response/MooUploadResponse.php
@@ -6,41 +6,13 @@ namespace Oneup\UploaderBundle\Uploader\Response;
class MooUploadResponse extends AbstractResponse
{
- /**
- * @var int|string
- */
- protected $id;
-
- /**
- * @var string|null
- */
- protected $name;
-
- /**
- * @var int
- */
- protected $size;
-
- /**
- * @var int
- */
- protected $error;
-
- /**
- * @var bool
- */
- protected $finish;
-
- /**
- * @var string
- */
- protected $uploadedName;
-
- public function __construct()
- {
- $this->finish = true;
- $this->error = 0;
+ protected int|string|null $id;
+ protected ?string $name;
+ protected int $size;
+ protected string $uploadedName;
+ public function __construct(protected bool $finish = true, protected int $error = 0)
+ {
parent::__construct();
}
@@ -58,20 +30,14 @@ class MooUploadResponse extends AbstractResponse
return $data;
}
- /**
- * @param mixed $id
- */
- public function setId($id): self
+ public function setId(int|string|null $id): self
{
$this->id = $id;
return $this;
}
- /**
- * @return mixed
- */
- public function getId()
+ public function getId(): int|string|null
{
return $this->id;
}
@@ -88,10 +54,7 @@ class MooUploadResponse extends AbstractResponse
return $this->name;
}
- /**
- * @param mixed $size
- */
- public function setSize($size): self
+ public function setSize(mixed $size): self
{
$this->size = (int) $size;
diff --git a/src/Uploader/Storage/FilesystemOrphanageStorage.php b/src/Uploader/Storage/FilesystemOrphanageStorage.php
index 7ed19a3..83cfaa1 100644
--- a/src/Uploader/Storage/FilesystemOrphanageStorage.php
+++ b/src/Uploader/Storage/FilesystemOrphanageStorage.php
@@ -15,43 +15,18 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageStorageInterface
{
- /**
- * @var StorageInterface
- */
- protected $storage;
-
/**
* @var SessionInterface
*/
protected $session;
- /**
- * @var ChunkStorage
- */
- protected $chunkStorage;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var string
- */
- protected $type;
-
- public function __construct(StorageInterface $storage, RequestStack $requestStack, ChunkStorage $chunkStorage, array $config, string $type)
+ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type)
{
parent::__construct($config['directory']);
/** @var Request $request */
$request = $requestStack->getCurrentRequest();
-
- $this->storage = $storage;
$this->session = $request->getSession();
- $this->chunkStorage = $chunkStorage;
- $this->config = $config;
- $this->type = $type;
}
/**
@@ -80,7 +55,8 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS
foreach ($files as $file) {
$return[] = $this->storage->upload(
new FilesystemFile(new File($file->getPathname())),
- ltrim(str_replace($this->getFindPath(), '', (string) $file), '/'));
+ ltrim(str_replace($this->getFindPath(), '', (string) $file), '/')
+ );
}
return $return;
@@ -96,10 +72,10 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS
try {
$finder->in($this->getFindPath())->files();
} catch (\InvalidArgumentException $e) {
- //catch non-existing directory exception.
- //This can happen if getFiles is called and no file has yet been uploaded
+ // catch non-existing directory exception.
+ // This can happen if getFiles is called and no file has yet been uploaded
- //push empty array into the finder so we can emulate no files found
+ // push empty array into the finder so we can emulate no files found
$finder->append([]);
}
diff --git a/src/Uploader/Storage/FilesystemStorage.php b/src/Uploader/Storage/FilesystemStorage.php
index 3bcd28c..a67f7a2 100644
--- a/src/Uploader/Storage/FilesystemStorage.php
+++ b/src/Uploader/Storage/FilesystemStorage.php
@@ -10,14 +10,8 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
class FilesystemStorage implements StorageInterface
{
- /**
- * @var string
- */
- protected $directory;
-
- public function __construct(string $directory)
+ public function __construct(protected string $directory)
{
- $this->directory = $directory;
}
/**
diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php
index 49307c8..9f51f63 100644
--- a/src/Uploader/Storage/FlysystemOrphanageStorage.php
+++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -16,32 +16,12 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageStorageInterface
{
- /**
- * @var StorageInterface
- */
- protected $storage;
-
/**
* @var SessionInterface
*/
protected $session;
- /**
- * @var ChunkStorage
- */
- protected $chunkStorage;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var string
- */
- protected $type;
-
- public function __construct(StorageInterface $storage, RequestStack $requestStack, ChunkStorage $chunkStorage, array $config, string $type)
+ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected ChunkStorage $chunkStorage, protected array $config, protected string $type)
{
/*
* initiate the storage on the chunk storage's filesystem
@@ -51,12 +31,7 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
/** @var Request $request */
$request = $requestStack->getCurrentRequest();
-
- $this->storage = $storage;
- $this->chunkStorage = $chunkStorage;
$this->session = $request->getSession();
- $this->config = $config;
- $this->type = $type;
}
/**
diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php
index 854757d..c689587 100644
--- a/src/Uploader/Storage/FlysystemStorage.php
+++ b/src/Uploader/Storage/FlysystemStorage.php
@@ -14,26 +14,8 @@ use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
class FlysystemStorage implements StorageInterface
{
- /**
- * @var string|null
- */
- protected $streamWrapperPrefix;
-
- /**
- * @var int
- */
- protected $bufferSize;
-
- /**
- * @var FilesystemOperator
- */
- private $filesystem;
-
- public function __construct(FilesystemOperator $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null)
+ public function __construct(private FilesystemOperator $filesystem, protected int $bufferSize, protected ?string $streamWrapperPrefix = null)
{
- $this->filesystem = $filesystem;
- $this->bufferSize = $bufferSize;
- $this->streamWrapperPrefix = $streamWrapperPrefix;
}
/**
@@ -73,8 +55,10 @@ class FlysystemStorage implements StorageInterface
}
if ($file instanceof FileInterface) {
+ /** @var FilesystemOperator $filesystem */
+ $filesystem = $file->getFilesystem();
$manager = new MountManager([
- 'chunks' => $file->getFilesystem(),
+ 'chunks' => $filesystem,
'dest' => $this->filesystem,
]);
diff --git a/src/Uploader/Storage/GaufretteOrphanageStorage.php b/src/Uploader/Storage/GaufretteOrphanageStorage.php
index cfab590..bac1a92 100644
--- a/src/Uploader/Storage/GaufretteOrphanageStorage.php
+++ b/src/Uploader/Storage/GaufretteOrphanageStorage.php
@@ -14,32 +14,12 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface
{
- /**
- * @var StorageInterface
- */
- protected $storage;
-
/**
* @var SessionInterface
*/
protected $session;
- /**
- * @var GaufretteChunkStorage
- */
- protected $chunkStorage;
-
- /**
- * @var array
- */
- protected $config;
-
- /**
- * @var string
- */
- protected $type;
-
- public function __construct(StorageInterface $storage, RequestStack $requestStack, GaufretteChunkStorage $chunkStorage, array $config, string $type)
+ public function __construct(protected StorageInterface $storage, RequestStack $requestStack, protected GaufretteChunkStorage $chunkStorage, protected array $config, protected string $type)
{
/*
* initiate the storage on the chunk storage's filesystem
@@ -49,12 +29,7 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto
/** @var Request $request */
$request = $requestStack->getCurrentRequest();
-
- $this->storage = $storage;
- $this->chunkStorage = $chunkStorage;
$this->session = $request->getSession();
- $this->config = $config;
- $this->type = $type;
}
/**
diff --git a/src/Uploader/Storage/GaufretteStorage.php b/src/Uploader/Storage/GaufretteStorage.php
index 98e0267..ea2cd83 100644
--- a/src/Uploader/Storage/GaufretteStorage.php
+++ b/src/Uploader/Storage/GaufretteStorage.php
@@ -14,24 +14,18 @@ use Symfony\Component\Filesystem\Filesystem as LocalFilesystem;
class GaufretteStorage extends StreamManager implements StorageInterface
{
- /**
- * @var string|null
- */
- protected $streamWrapperPrefix;
-
- public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null)
+ public function __construct(FilesystemInterface $filesystem, int $bufferSize, protected ?string $streamWrapperPrefix = null)
{
$base = interface_exists(FilesystemInterface::class)
? FilesystemInterface::class
: Filesystem::class;
if (!$filesystem instanceof $base) {
- throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, \get_class($filesystem)));
+ throw new \InvalidArgumentException(sprintf('Expected an instance of "%s", got "%s".', $base, $filesystem::class));
}
$this->filesystem = $filesystem;
$this->buffersize = $bufferSize;
- $this->streamWrapperPrefix = $streamWrapperPrefix;
}
/**
diff --git a/tests/App/Kernel.php b/tests/App/Kernel.php
index 1a15234..fec971f 100644
--- a/tests/App/Kernel.php
+++ b/tests/App/Kernel.php
@@ -3,7 +3,6 @@
declare(strict_types=1);
use Oneup\UploaderBundle\OneupUploaderBundle;
-use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
@@ -16,7 +15,6 @@ class Kernel extends BaseKernel
$bundles = [
new FrameworkBundle(),
new SecurityBundle(),
- new SensioFrameworkExtraBundle(),
// bundle to test
new OneupUploaderBundle(),
diff --git a/tests/App/config/config.yml b/tests/App/config/config.yml
index 3eda25a..7203fcc 100644
--- a/tests/App/config/config.yml
+++ b/tests/App/config/config.yml
@@ -1,6 +1,4 @@
framework:
- annotations:
- enabled: true
translator: { fallback: en }
secret: secret
router:
diff --git a/tests/Controller/AbstractUploadTest.php b/tests/Controller/AbstractUploadTest.php
index aef114a..b849450 100644
--- a/tests/Controller/AbstractUploadTest.php
+++ b/tests/Controller/AbstractUploadTest.php
@@ -87,8 +87,5 @@ abstract class AbstractUploadTest extends AbstractControllerTest
abstract protected function getRequestParameters(): array;
- /**
- * @return mixed
- */
- abstract protected function getRequestFile();
+ abstract protected function getRequestFile(): mixed;
}
diff --git a/tests/Controller/AbstractValidationTest.php b/tests/Controller/AbstractValidationTest.php
index 8b9803a..16c2f60 100644
--- a/tests/Controller/AbstractValidationTest.php
+++ b/tests/Controller/AbstractValidationTest.php
@@ -6,6 +6,7 @@ namespace Oneup\UploaderBundle\Tests\Controller;
use Oneup\UploaderBundle\Event\ValidationEvent;
use Psr\Container\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
abstract class AbstractValidationTest extends AbstractControllerTest
{
@@ -18,7 +19,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest
$client->request('POST', $endpoint, $this->getRequestParameters(), [$this->getOversizedFile()], $this->requestHeaders);
$response = $client->getResponse();
- //$this->assertTrue($response->isNotSuccessful());
+ // $this->assertTrue($response->isNotSuccessful());
$this->assertSame($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
}
@@ -113,30 +114,18 @@ abstract class AbstractValidationTest extends AbstractControllerTest
$client->request('POST', $endpoint, $this->getRequestParameters(), [$this->getFileWithIncorrectMimeType()], $this->requestHeaders);
$response = $client->getResponse();
- //$this->assertTrue($response->isNotSuccessful());
+ // $this->assertTrue($response->isNotSuccessful());
$this->assertSame($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
}
- /**
- * @return mixed
- */
- abstract protected function getFileWithCorrectMimeType();
-
- /**
- * @return mixed
- */
- abstract protected function getFileWithCorrectMimeTypeAndIncorrectExtension();
-
- /**
- * @return mixed
- */
- abstract protected function getFileWithIncorrectMimeType();
-
- /**
- * @return mixed
- */
- abstract protected function getOversizedFile();
+ abstract protected function getFileWithCorrectMimeType(): UploadedFile;
+
+ abstract protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile;
+
+ abstract protected function getFileWithIncorrectMimeType(): UploadedFile;
+
+ abstract protected function getOversizedFile(): UploadedFile;
abstract protected function getRequestParameters(): array;
}
diff --git a/tests/Controller/BlueimpTest.php b/tests/Controller/BlueimpTest.php
index 9d0f5b1..73c58e4 100644
--- a/tests/Controller/BlueimpTest.php
+++ b/tests/Controller/BlueimpTest.php
@@ -7,6 +7,7 @@ namespace Oneup\UploaderBundle\Tests\Controller;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Event\PreUploadEvent;
use Psr\Container\ContainerInterface;
+use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -53,6 +54,7 @@ class BlueimpTest extends AbstractUploadTest
$container = $client->getContainer();
$endpoint = $this->helper->endpoint($this->getConfigKey());
+ /** @var EventDispatcher $dispatcher */
$dispatcher = $container->get('event_dispatcher');
// event data
diff --git a/tests/Controller/BlueimpValidationTest.php b/tests/Controller/BlueimpValidationTest.php
index eb68247..0722c0a 100644
--- a/tests/Controller/BlueimpValidationTest.php
+++ b/tests/Controller/BlueimpValidationTest.php
@@ -17,11 +17,11 @@ class BlueimpValidationTest extends AbstractValidationTest
/** @var KernelBrowser $client */
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getOversizedFile(), $this->requestHeaders);
+ $file = ['files' => [$this->getOversizedFile()]];
+ $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders);
$response = $client->getResponse();
- //$this->assertTrue($response->isNotSuccessful());
+ // $this->assertTrue($response->isNotSuccessful());
$this->assertSame($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
$this->assertFalse(strpos((string) $response->getContent(), 'error.maxsize'), 'Failed to translate error id into lang');
@@ -43,8 +43,8 @@ class BlueimpValidationTest extends AbstractValidationTest
$dispatcher->addListener(ValidationEvent::NAME, static function () use (&$validationCount): void {
++$validationCount;
});
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType(), $this->requestHeaders);
+ $file = ['files' => [$this->getFileWithCorrectMimeType()]];
+ $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders);
$this->assertSame(1, $validationCount);
}
@@ -54,8 +54,8 @@ class BlueimpValidationTest extends AbstractValidationTest
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType(), $this->requestHeaders);
+ $file = ['files' => [$this->getFileWithCorrectMimeType()]];
+ $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders);
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
@@ -74,11 +74,11 @@ class BlueimpValidationTest extends AbstractValidationTest
// assemble a request
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
-
- $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectMimeType(), $this->requestHeaders);
+ $file = [$this->getFileWithIncorrectMimeType()];
+ $client->request('POST', $endpoint, $this->getRequestParameters(), $file, $this->requestHeaders);
$response = $client->getResponse();
- //$this->assertTrue($response->isNotSuccessful());
+ // $this->assertTrue($response->isNotSuccessful());
$this->assertSame($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
}
@@ -93,39 +93,39 @@ class BlueimpValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile(): array
+ protected function getOversizedFile(): UploadedFile
{
- return ['files' => [new UploadedFile(
+ return new UploadedFile(
$this->createTempFile(512),
'cat.ok',
'text/plain'
- )]];
+ );
}
- protected function getFileWithCorrectMimeType(): array
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
- return ['files' => [new UploadedFile(
+ return new UploadedFile(
$this->createTempFile(128),
'cat.txt',
'text/plain'
- )]];
+ );
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): array
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
- return ['files' => [new UploadedFile(
+ return new UploadedFile(
$this->createTempFile(128),
'cat.txxt',
'text/plain'
- )]];
+ );
}
- protected function getFileWithIncorrectMimeType(): array
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
- return [new UploadedFile(
+ return new UploadedFile(
$this->createTempFile(128),
'cat.ok',
'image/gif'
- )];
+ );
}
}
diff --git a/tests/Controller/DropzoneValidationTest.php b/tests/Controller/DropzoneValidationTest.php
index 3d0b2f9..0d6f0bf 100644
--- a/tests/Controller/DropzoneValidationTest.php
+++ b/tests/Controller/DropzoneValidationTest.php
@@ -18,7 +18,7 @@ class DropzoneValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile()
+ protected function getOversizedFile(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(512),
@@ -27,7 +27,7 @@ class DropzoneValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeType()
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -36,7 +36,7 @@ class DropzoneValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension()
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -45,7 +45,7 @@ class DropzoneValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithIncorrectMimeType()
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
diff --git a/tests/Controller/FancyUploadValidationTest.php b/tests/Controller/FancyUploadValidationTest.php
index 218aa77..89afc18 100644
--- a/tests/Controller/FancyUploadValidationTest.php
+++ b/tests/Controller/FancyUploadValidationTest.php
@@ -18,7 +18,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile()
+ protected function getOversizedFile(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(512),
@@ -27,7 +27,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeType()
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -36,7 +36,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension()
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -45,7 +45,7 @@ class FancyUploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithIncorrectMimeType()
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
diff --git a/tests/Controller/FileBagExtractorTest.php b/tests/Controller/FileBagExtractorTest.php
index 6b3d9d7..660a9ff 100644
--- a/tests/Controller/FileBagExtractorTest.php
+++ b/tests/Controller/FileBagExtractorTest.php
@@ -83,10 +83,7 @@ class FileBagExtractorTest extends TestCase
$this->assertCount(3, $result);
}
- /**
- * @return mixed
- */
- protected function invoke(FileBag $bag)
+ protected function invoke(FileBag $bag): mixed
{
return $this->method->invoke($this->mock, $bag);
}
diff --git a/tests/Controller/FineUploaderValidationTest.php b/tests/Controller/FineUploaderValidationTest.php
index e3b17d4..842b83b 100644
--- a/tests/Controller/FineUploaderValidationTest.php
+++ b/tests/Controller/FineUploaderValidationTest.php
@@ -18,7 +18,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile()
+ protected function getOversizedFile(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(512),
@@ -27,7 +27,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeType()
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -36,7 +36,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension()
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -45,7 +45,7 @@ class FineUploaderValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithIncorrectMimeType()
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
diff --git a/tests/Controller/PluploadValidationTest.php b/tests/Controller/PluploadValidationTest.php
index 9596859..0e8745a 100644
--- a/tests/Controller/PluploadValidationTest.php
+++ b/tests/Controller/PluploadValidationTest.php
@@ -18,7 +18,7 @@ class PluploadValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile()
+ protected function getOversizedFile(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(512),
@@ -27,7 +27,7 @@ class PluploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeType()
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -36,7 +36,7 @@ class PluploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension()
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -45,7 +45,7 @@ class PluploadValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithIncorrectMimeType()
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
diff --git a/tests/Controller/UploadifyValidationTest.php b/tests/Controller/UploadifyValidationTest.php
index 29f5a2d..e1587cb 100644
--- a/tests/Controller/UploadifyValidationTest.php
+++ b/tests/Controller/UploadifyValidationTest.php
@@ -18,7 +18,7 @@ class UploadifyValidationTest extends AbstractValidationTest
return [];
}
- protected function getOversizedFile()
+ protected function getOversizedFile(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(512),
@@ -27,7 +27,7 @@ class UploadifyValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeType()
+ protected function getFileWithCorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -36,7 +36,7 @@ class UploadifyValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithCorrectMimeTypeAndIncorrectExtension()
+ protected function getFileWithCorrectMimeTypeAndIncorrectExtension(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
@@ -45,7 +45,7 @@ class UploadifyValidationTest extends AbstractValidationTest
);
}
- protected function getFileWithIncorrectMimeType()
+ protected function getFileWithIncorrectMimeType(): UploadedFile
{
return new UploadedFile(
$this->createTempFile(128),
diff --git a/tests/DependencyInjection/OneupUploaderExtensionTest.php b/tests/DependencyInjection/OneupUploaderExtensionTest.php
index 2b8a0b0..86fc33f 100644
--- a/tests/DependencyInjection/OneupUploaderExtensionTest.php
+++ b/tests/DependencyInjection/OneupUploaderExtensionTest.php
@@ -76,8 +76,8 @@ class OneupUploaderExtensionTest extends TestCase
$getValueInBytes->setAccessible(true);
$store = [
- $getValueInBytes->invoke($mock, ini_get('upload_max_filesize')),
- $getValueInBytes->invoke($mock, ini_get('post_max_size')),
+ $getValueInBytes->invoke($mock, \ini_get('upload_max_filesize')),
+ $getValueInBytes->invoke($mock, \ini_get('post_max_size')),
];
$min = min($store);
diff --git a/tests/Templating/TemplateHelperTest.php b/tests/Templating/TemplateHelperTest.php
index a0abf71..51a3ec8 100644
--- a/tests/Templating/TemplateHelperTest.php
+++ b/tests/Templating/TemplateHelperTest.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Tests\Templating;
+use Oneup\UploaderBundle\Templating\Helper\UploaderHelper;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@@ -20,6 +21,7 @@ class TemplateHelperTest extends WebTestCase
/** @var ContainerInterface $container */
$container = $client->getContainer();
+ /** @var UploaderHelper $helper */
$helper = $container->get('oneup_uploader.templating.uploader_helper');
// this is for code coverage
diff --git a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
index a3ba11c..e9b7c45 100644
--- a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
+++ b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
@@ -74,6 +74,7 @@ class FlysystemStorageTest extends ChunkStorageTest
$system->dumpFile($dir . '/chunk3', 'test');
$timeTo = time();
+ /** @var array $files */
$files = $this->storage->getChunks($uuid);
$this->assertCount(3, $files);
$file = $files[0];
diff --git a/tests/Uploader/File/FilesystemFileTest.php b/tests/Uploader/File/FilesystemFileTest.php
index d73ac35..a8a369c 100644
--- a/tests/Uploader/File/FilesystemFileTest.php
+++ b/tests/Uploader/File/FilesystemFileTest.php
@@ -20,7 +20,7 @@ class FilesystemFileTest extends FileTest
$this->basename = 'test_file.txt';
$this->pathname = $this->path . '/' . $this->basename;
$this->extension = 'txt';
- $this->size = 9; //something = 9 bytes
+ $this->size = 9; // something = 9 bytes
$this->mimeType = 'text/plain';
file_put_contents($this->pathname, 'something');
diff --git a/tests/Uploader/File/GaufretteFileTest.php b/tests/Uploader/File/GaufretteFileTest.php
index 45bd080..1febc13 100644
--- a/tests/Uploader/File/GaufretteFileTest.php
+++ b/tests/Uploader/File/GaufretteFileTest.php
@@ -31,7 +31,7 @@ class GaufretteFileTest extends FileTest
$this->basename = 'test_file.txt';
$this->pathname = $this->path . '/' . $this->basename;
$this->extension = 'txt';
- $this->size = 9; //something = 9 bytes
+ $this->size = 9; // something = 9 bytes
$this->mimeType = 'text/plain';
file_put_contents(sys_get_temp_dir() . '/' . $this->pathname, 'something');
diff --git a/tests/Uploader/Naming/UrlSafeNamerTest.php b/tests/Uploader/Naming/UrlSafeNamerTest.php
index 275ddd0..ae43538 100644
--- a/tests/Uploader/Naming/UrlSafeNamerTest.php
+++ b/tests/Uploader/Naming/UrlSafeNamerTest.php
@@ -22,7 +22,7 @@ class UrlSafeNamerTest extends FileTest
$this->basename = 'test_file.txt';
$this->pathname = $this->path . '/' . $this->basename;
$this->extension = 'txt';
- $this->size = 9; //something = 9 bytes
+ $this->size = 9; // something = 9 bytes
$this->mimeType = 'text/plain';
file_put_contents($this->pathname, 'something');
diff --git a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
index 764d943..3dc7b02 100644
--- a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
+++ b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -81,7 +81,7 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
- //file key needs to be relative to the root of the flysystem filesystem
+ // file key needs to be relative to the root of the flysystem filesystem
// It seems that tempnam on OS X prepends 'private' to chunkDirectory, so strip that off as well
$fileKey = str_replace([$this->realDirectory, '/private'], '', $file);
diff --git a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
index 46cc9d1..3a6c06e 100644
--- a/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
+++ b/tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php
@@ -42,9 +42,9 @@ class GaufretteAmazonS3StorageTest extends TestCase
protected function setUp(): void
{
if (
- false === getenv('AWS_ACCESS_KEY_ID') ||
- false === getenv('AWS_SECRET_ACCESS_KEY') ||
- false === getenv('AWS_BUCKET')
+ false === getenv('AWS_ACCESS_KEY_ID')
+ || false === getenv('AWS_SECRET_ACCESS_KEY')
+ || false === getenv('AWS_BUCKET')
) {
$this->markTestSkipped('Missing AWS_* ENV variables.');
}
diff --git a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
index a1fde8e..e123521 100644
--- a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
+++ b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -81,7 +81,7 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
- //gaufrette needs the key relative to it's root
+ // gaufrette needs the key relative to it's root
$fileKey = str_replace($this->realDirectory, '', $file);
$this->payloads[] = new GaufretteFile(new File($fileKey, $filesystem), $filesystem);
@@ -134,6 +134,6 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
public function checkIfTempnameMatchesAfterCreation(): bool
{
- return 0 === strpos((string) @tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory);
+ return str_starts_with((string) @tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory);
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index f10afb3..b12496a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -4,12 +4,12 @@ declare(strict_types=1);
if (!($loader = @include __DIR__ . '/../vendor/autoload.php')) {
echo <<<'EOT'
-You need to install the project dependencies using Composer:
-$ wget http://getcomposer.org/composer.phar
-OR
-$ curl -s https://getcomposer.org/installer | php
-$ php composer.phar install --dev
-$ phpunit
-EOT;
+ You need to install the project dependencies using Composer:
+ $ wget https://getcomposer.org/composer.phar
+ OR
+ $ curl -s https://getcomposer.org/installer | php
+ $ php composer.phar install --dev
+ $ phpunit
+ EOT;
exit(1);
}
| 0
|
52865bd21f1b8921bec55ed499be41b8a6e78377
|
1up-lab/OneupUploaderBundle
|
Readded the codeblock for the assembling of chunks if load distribution is false.
|
commit 52865bd21f1b8921bec55ed499be41b8a6e78377
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:47:33 2013 +0200
Readded the codeblock for the assembling of chunks if load distribution is false.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index c197ec1..d7b0365 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -66,6 +66,11 @@ abstract class AbstractChunkedController extends AbstractController
// if all chunks collected and stored, proceed
// with reassembling the parts
if ($last) {
+ if (!$chunkManager->getLoadDistribution()) {
+ $chunks = $chunkManager->getChunks($uuid);
+ $assembled = $chunkManager->assembleChunks($chunks, true, true);
+ }
+
$path = $assembled->getPath();
// create a temporary uploaded file to meet the interface restrictions
| 0
|
8b562d2775d535a9a74db4537c4ac09d71f97a04
|
1up-lab/OneupUploaderBundle
|
Added some more information to composer.json
|
commit 8b562d2775d535a9a74db4537c4ac09d71f97a04
Author: Jim Schmid <[email protected]>
Date: Wed Jun 19 18:42:11 2013 +0200
Added some more information to composer.json
diff --git a/composer.json b/composer.json
index ac41496..cf5518a 100644
--- a/composer.json
+++ b/composer.json
@@ -8,7 +8,9 @@
"authors": [
{
"name": "Jim Schmid",
- "email": "[email protected]"
+ "email": "[email protected]",
+ "homepage": "http://1up.io",
+ "role": "Developer"
}
],
| 0
|
366f33912ee94184b8f4b74957e2086999453d81
|
1up-lab/OneupUploaderBundle
|
Added a new MaxSizeValidationListener.
|
commit 366f33912ee94184b8f4b74957e2086999453d81
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 19:16:03 2013 +0200
Added a new MaxSizeValidationListener.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index bf0121f..81804fc 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -22,6 +22,7 @@ class OneupUploaderExtension extends Extension
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
$loader->load('templating.xml');
+ $loader->load('validation.xml');
if($config['twig'])
{
diff --git a/EventListener/MaxSizeValidationListener.php b/EventListener/MaxSizeValidationListener.php
new file mode 100644
index 0000000..b14fca9
--- /dev/null
+++ b/EventListener/MaxSizeValidationListener.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class MaxSizeValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ if($file->getClientSize() > $config['max_size']) {
+ throw new ValidationException('error.maxsize');
+ }
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml
new file mode 100644
index 0000000..ac5322b
--- /dev/null
+++ b/Resources/config/validation.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<container xmlns="http://symfony.com/schema/dic/services"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+ <services>
+
+ <service id="oneup_uploader.validation.max_size_listener" class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener">
+ <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
+ </service>
+
+ </services>
+
+</container>
\ No newline at end of file
diff --git a/Uploader/Exception/ValidationException.php b/Uploader/Exception/ValidationException.php
new file mode 100644
index 0000000..ced7379
--- /dev/null
+++ b/Uploader/Exception/ValidationException.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Exception;
+
+class ValidationException extends \DomainException
+{
+
+}
\ No newline at end of file
| 0
|
db7fa541741883f11506758fe711529be14808b8
|
1up-lab/OneupUploaderBundle
|
Updated copyright and authors section
|
commit db7fa541741883f11506758fe711529be14808b8
Author: David Greminger <[email protected]>
Date: Fri Jan 12 13:54:19 2018 +0100
Updated copyright and authors section
diff --git a/Resources/meta/LICENSE b/Resources/meta/LICENSE
index bebab95..d4f24ca 100644
--- a/Resources/meta/LICENSE
+++ b/Resources/meta/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2015 1up GmbH
+Copyright (c) 2018 1up GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/composer.json b/composer.json
index dc5b01b..591ce8c 100644
--- a/composer.json
+++ b/composer.json
@@ -11,6 +11,12 @@
"email": "[email protected]",
"homepage": "http://1up.io",
"role": "Developer"
+ },
+ {
+ "name": "David Greminger",
+ "email": "[email protected]",
+ "homepage": "http://1up.io",
+ "role": "Developer"
}
],
| 0
|
5ec3508c5a8ddcbd9a4d96b77e5b415a15599806
|
1up-lab/OneupUploaderBundle
|
Merge pull request #268 from bronek89/master
Remove metric suffix from input before multiplication (PHP 7.1 notice)
|
commit 5ec3508c5a8ddcbd9a4d96b77e5b415a15599806 (from a8c1e536657bbee48b0e442067aab1aaf2a9cda6)
Merge: a8c1e53 cb9e36c
Author: David Greminger <[email protected]>
Date: Sat Oct 8 16:29:52 2016 +0200
Merge pull request #268 from bronek89/master
Remove metric suffix from input before multiplication (PHP 7.1 notice)
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 5ffbe09..0d472ff 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -294,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;
| 0
|
1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989
|
1up-lab/OneupUploaderBundle
|
Fixes broken PR #357
|
commit 1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989
Author: David Greminger <[email protected]>
Date: Fri Apr 5 13:56:57 2019 +0200
Fixes broken PR #357
diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php
index df2b388..df59977 100644
--- a/Command/ClearChunkCommand.php
+++ b/Command/ClearChunkCommand.php
@@ -30,6 +30,6 @@ class ClearChunkCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
- $manager->clear();
+ $this->manager->clear();
}
}
diff --git a/Command/ClearOrphansCommand.php b/Command/ClearOrphansCommand.php
index 34eff28..af4a87c 100644
--- a/Command/ClearOrphansCommand.php
+++ b/Command/ClearOrphansCommand.php
@@ -30,6 +30,6 @@ class ClearOrphansCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
- $manager->clear();
+ $this->manager->clear();
}
}
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 29b3993..b5ca94e 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -53,9 +53,11 @@
<!-- commands -->
<service id="oneup_uploader.command.clear_chunks" class="%oneup_uploader.command.clear_chunks.class%">
+ <argument type="service" id="oneup_uploader.chunk_manager" />
<tag name="console.command" command="oneup:uploader:clear-chunks" />
</service>
<service id="oneup_uploader.command.clear_orphans" class="%oneup_uploader.command.clear_orphans.class%">
+ <argument type="service" id="oneup_uploader.orphanage_manager" />
<tag name="console.command" command="oneup:uploader:clear-orphans" />
</service>
| 0
|
2227d8b30493cab5399622be7d824eddd5d5e088
|
1up-lab/OneupUploaderBundle
|
Strip down AppKernel for testing environment to the basic parts.
|
commit 2227d8b30493cab5399622be7d824eddd5d5e088
Author: Jim Schmid <[email protected]>
Date: Mon May 6 22:30:34 2013 +0200
Strip down AppKernel for testing environment to the basic parts.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index c399626..de85d76 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -4,15 +4,10 @@ framework:
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
- form: ~
- csrf_protection: ~
- validation: { enable_annotations: true }
templating:
engines: ['php']
default_locale: en
- trusted_proxies: ~
session: ~
- fragments: ~
test: ~
monolog:
| 0
|
bafaa89108f01ad790c750c9155836a658e1ecc1
|
1up-lab/OneupUploaderBundle
|
Removed unused die()
|
commit bafaa89108f01ad790c750c9155836a658e1ecc1
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 22:51:06 2013 +0200
Removed unused die()
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index c9b6286..438bd08 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -141,8 +141,6 @@ class BlueimpController implements UploadControllerInterface
}
return $uploaded;
-
- die();
}
protected function validate(UploadedFile $file)
| 0
|
2f43407791a91f31b50f12c384371537d70b4c12
|
1up-lab/OneupUploaderBundle
|
Removed configuration setting 'enable' on chunk-config.
|
commit 2f43407791a91f31b50f12c384371537d70b4c12
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 18:14:25 2013 +0200
Removed configuration setting 'enable' on chunk-config.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index b59d866..4deb776 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -17,7 +17,6 @@ class Configuration implements ConfigurationInterface
->arrayNode('chunks')
->addDefaultsIfNotSet()
->children()
- ->booleanNode('enabled')->defaultFalse()->end()
->scalarNode('maxage')->defaultValue(604800)->end()
->scalarNode('directory')->defaultNull()->end()
->end()
@@ -35,7 +34,6 @@ class Configuration implements ConfigurationInterface
->requiresAtLeastOneElement()
->prototype('array')
->children()
-
->arrayNode('storage')
->addDefaultsIfNotSet()
->children()
| 0
|
16cfcc0006f64ad89908fe34d77265c554ae1b8e
|
1up-lab/OneupUploaderBundle
|
Removed depending.in batch
This service is unstable at it's best, leading to unloaded status images.
|
commit 16cfcc0006f64ad89908fe34d77265c554ae1b8e
Author: Jim Schmid <[email protected]>
Date: Thu Dec 19 10:40:25 2013 +0100
Removed depending.in batch
This service is unstable at it's best, leading to unloaded status images.
diff --git a/README.md b/README.md
index 7ddeab2..daa5eac 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,6 @@ Features included:
* Fully unit tested
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
-[](http://depending.in/1up-lab/OneupUploaderBundle)
[](https://packagist.org/packages/oneup/uploader-bundle)
Documentation
| 0
|
bcde9b99fc62015b4e93abf68dfc9fb51a146c22
|
1up-lab/OneupUploaderBundle
|
Merge pull request #105 from Schyzophrenic/master
[Doc] Add Exception about the ValidationEvent
|
commit bcde9b99fc62015b4e93abf68dfc9fb51a146c22 (from 3e763f0e6d65c6ce9a49d550dab0482562951dcf)
Merge: 3e763f0 8a40040
Author: Jim Schmid <[email protected]>
Date: Sat May 10 21:10:55 2014 +0200
Merge pull request #105 from Schyzophrenic/master
[Doc] Add Exception about the ValidationEvent
diff --git a/Resources/doc/response.md b/Resources/doc/response.md
index bfef2ca..39d9968 100644
--- a/Resources/doc/response.md
+++ b/Resources/doc/response.md
@@ -1,7 +1,7 @@
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`.
+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` (except the `ValidationEvent`).
```php
namespace Acme\HelloBundle\EventListener;
@@ -33,4 +33,4 @@ $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
+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.
| 0
|
461e503cef5d1f73b784aecf1131a79fcc8ed181
|
1up-lab/OneupUploaderBundle
|
Update readme according to Symfony 6 support
|
commit 461e503cef5d1f73b784aecf1131a79fcc8ed181
Author: David Greminger <[email protected]>
Date: Mon Mar 21 14:30:30 2022 +0100
Update readme according to Symfony 6 support
diff --git a/README.md b/README.md
index 4b177c6..eaa78ab 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `docs/index.md`
Upgrade Notes
-------------
+* Version **3.2.0** supports now Symfony 6 (kudos to @[pich](https://github.com/pich)), see [#421](https://github.com/1up-lab/OneupUploaderBundle/pull/421)! PHP 7.2/7.3 support was dropped.
* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter](https://github.com/steveWinter), @[gubler](https://github.com/gubler), @[patrickbussmann](https://github.com/patrickbussmann), @[ErnadoO](https://github.com/ErnadoO) and @[enumag](https://github.com/enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
* 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).
| 0
|
8a2fc86ac9d83457193c40cbc006f5799495e2b0
|
1up-lab/OneupUploaderBundle
|
Removed default value 'fineuploader' for frontend key in Configuration.
This was a legacy decision which will be changed in 1.0.0.
The first version of this Bundle only supported Fineuploader which
would have been a BC break if 'fineuploader' was not the default value.
|
commit 8a2fc86ac9d83457193c40cbc006f5799495e2b0
Author: Jim Schmid <[email protected]>
Date: Tue Oct 8 20:31:29 2013 +0200
Removed default value 'fineuploader' for frontend key in Configuration.
This was a legacy decision which will be changed in 1.0.0.
The first version of this Bundle only supported Fineuploader which
would have been a BC break if 'fineuploader' was not the default value.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index e18268a..97b1eef 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -38,7 +38,6 @@ class Configuration implements ConfigurationInterface
->children()
->enumNode('frontend')
->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom'))
- ->defaultValue('fineuploader')
->end()
->arrayNode('custom_frontend')
->addDefaultsIfNotSet()
| 0
|
d6e903cb570b486aba0c1b3ce0bf60be72d32014
|
1up-lab/OneupUploaderBundle
|
Merge branch 'patch-1' of https://github.com/brandon1499/OneupUploaderBundle into brandon1499-patch-1
|
commit d6e903cb570b486aba0c1b3ce0bf60be72d32014 (from 5b1b2076daab43b3e8aaed9e0b43cb537142c456)
Merge: 5b1b207 55fc9c2
Author: David Greminger <[email protected]>
Date: Fri Sep 15 16:32:26 2017 +0200
Merge branch 'patch-1' of https://github.com/brandon1499/OneupUploaderBundle into 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);
}
commit d6e903cb570b486aba0c1b3ce0bf60be72d32014 (from 55fc9c277c8e577514b37c816c1dab27a5fd193f)
Merge: 5b1b207 55fc9c2
Author: David Greminger <[email protected]>
Date: Fri Sep 15 16:32:26 2017 +0200
Merge branch 'patch-1' of https://github.com/brandon1499/OneupUploaderBundle into brandon1499-patch-1
diff --git a/.travis.yml b/.travis.yml
index c044e39..0e69924 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ php:
- 5.5
- 5.6
- 7.0
+ - 7.1
- hhvm
env:
@@ -20,6 +21,7 @@ matrix:
allow_failures:
- php: hhvm
- php: 7.0
+ - php: 7.1
- env: SYMFONY_VERSION=dev-master
include:
@@ -42,3 +44,5 @@ before_script:
- composer selfupdate
- composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source
- composer install --dev --prefer-source
+
+script: ./vendor/bin/phpunit
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 0d472ff..c2c14eb 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -294,7 +294,7 @@ 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);
+ $numericInput = (float) substr($input, 0, -1);
switch ($last) {
case 'g': $numericInput *= 1024;
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/config/errorhandler.xml b/Resources/config/errorhandler.xml
index bf580bf..1f51fb2 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -12,7 +12,9 @@
<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.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false">
+ <argument type="service" id="translator"/>
+ </service>
<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" />
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 1aa1cfd..3471492 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -31,6 +31,11 @@ class UploadListener
public function onUpload(PostPersistEvent $event)
{
//...
+
+ //if everything went fine
+ $response = $event->getResponse();
+ $response['success'] = true;
+ return $response;
}
}
```
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
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 7ba1307..871e687 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
use Oneup\UploaderBundle\UploadEvents;
@@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest
public function testAgainstMaxSize()
{
// assemble a request
+ /** @var Client $client */
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
@@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
+ $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang");
}
public function testEvents()
diff --git a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
index a277d7e..102e954 100644
--- a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -29,15 +29,15 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
$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);
+ if (!$this->checkIfTempnameMatchesAfterCreation()) {
+ $this->markTestSkipped('Temporary directories do not match');
+ }
+
$adapter = new Adapter($this->realDirectory, true);
$filesystem = new FSAdapter($adapter);
@@ -61,7 +61,7 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
fwrite($pointer, str_repeat('A', 1024), 1024);
fclose($pointer);
- //gaufrette needs the key relative to it's root
+ //file key needs to be relative to the root of the flysystem filesystem
$fileKey = str_replace($this->realDirectory, '', $file);
$this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem);
@@ -95,7 +95,9 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
$this->assertCount($this->numberOfPayloads, $finder);
$finder = new Finder();
- $finder->in($this->realDirectory)->exclude(array($this->orphanageKey, $this->chunksKey))->files();
+ $finder->in($this->realDirectory)
+ ->exclude(array($this->orphanageKey, $this->chunksKey))
+ ->files();
$this->assertCount(0, $finder);
$files = $this->orphanage->uploadFiles();
@@ -114,6 +116,10 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
public function checkIfTempnameMatchesAfterCreation()
{
- return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ $testName = tempnam($this->chunkDirectory, 'uploader');
+ $result = strpos($testName, $this->chunkDirectory) === 0;
+ unlink($testName);
+
+ return $result;
}
}
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/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index c8839b7..be5e088 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+use Symfony\Component\Translation\TranslatorInterface;
class BlueimpErrorHandler implements ErrorHandlerInterface
{
+ /**
+ * @var TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct(TranslatorInterface $translator)
+ {
+ $this->translator = $translator;
+ }
+
public function addException(AbstractResponse $response, Exception $exception)
{
- $message = $exception->getMessage();
+ $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle');
$response->addToOffset(array('error' => $message), array('files'));
}
}
diff --git a/Uploader/Storage/FlysystemOrphanageStorage.php b/Uploader/Storage/FlysystemOrphanageStorage.php
index d9947c3..376deb5 100644
--- a/Uploader/Storage/FlysystemOrphanageStorage.php
+++ b/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -71,13 +71,19 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
public function getFiles()
{
- $keys = $this->chunkStorage->getFilesystem()->listFiles($this->getPath());
- $keys = $keys['keys'];
+ $fileList = $this->chunkStorage
+ ->getFilesystem()
+ ->listContents($this->getPath());
$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());
+ foreach ($fileList as $fileDetail) {
+ $key = $fileDetail['path'];
+ if ($fileDetail['type'] == 'file') {
+ $files[$key] = new FlysystemFile(
+ new File($this->chunkStorage->getFilesystem(), $key),
+ $this->chunkStorage->getFilesystem()
+ );
+ }
}
return $files;
| 0
|
aa81633b09b91b6506977f7ce1ab11be42a38c8a
|
1up-lab/OneupUploaderBundle
|
Code highlighter bricks on GitHub, give it another try.
|
commit aa81633b09b91b6506977f7ce1ab11be42a38c8a
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 10:16:36 2013 +0200
Code highlighter bricks on GitHub, give it another try.
diff --git a/Resources/doc/response.md b/Resources/doc/response.md
index 6cb75f4..ed7e449 100644
--- a/Resources/doc/response.md
+++ b/Resources/doc/response.md
@@ -19,7 +19,7 @@ class UploadListener
The `UploaderResponse` class implements the `ArrayAccess` interface, so you can just add data using it like an array:
-´´´php
+```php
$response['id'] = $uploadedImage->getId();
$response['url'] = $uploadedImage->getUrl();
```
| 0
|
50b8167a6845d5774b170733a7b6e774f2fdf96a
|
1up-lab/OneupUploaderBundle
|
Added .scrutinizer.yml file.
|
commit 50b8167a6845d5774b170733a7b6e774f2fdf96a
Author: Jim Schmid <[email protected]>
Date: Sun Apr 14 15:28:12 2013 +0200
Added .scrutinizer.yml file.
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
new file mode 100644
index 0000000..764db5d
--- /dev/null
+++ b/.scrutinizer.yml
@@ -0,0 +1,6 @@
+tools:
+ php_code_sniffer: true
+ php_cs_fixer: true
+ php_mess_detector: true
+ php_analyzer: true
+ sensiolabs_security_checker: true
\ No newline at end of file
| 0
|
a47326e29906cb017ed5c653439305241be1a819
|
1up-lab/OneupUploaderBundle
|
Update gaufrette_storage.md
|
commit a47326e29906cb017ed5c653439305241be1a819
Author: mitom <[email protected]>
Date: Fri Oct 11 10:45:53 2013 +0200
Update gaufrette_storage.md
diff --git a/Resources/doc/gaufrette_storage.md b/Resources/doc/gaufrette_storage.md
index 6c93347..c03ba84 100644
--- a/Resources/doc/gaufrette_storage.md
+++ b/Resources/doc/gaufrette_storage.md
@@ -88,3 +88,27 @@ oneup_uploader:
sync_buffer_size: 1M
```
+You may also specify the stream wrapper protocol for your filesystem:
+```yml
+# app/config/config.yml
+
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ type: gaufrette
+ 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
+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 (```/```).
+
+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)
| 0
|
18507cfb909f0d0a37b8a49cd0b06c6caa8fe1e6
|
1up-lab/OneupUploaderBundle
|
Clear recommendation to test with Dropzone first
Please explain the following sentence:
"To enable the dynamic routes, add the following to your routing configuration file."
Is having dynamic routes mandatory or optional? What are dynamic routes at all?
|
commit 18507cfb909f0d0a37b8a49cd0b06c6caa8fe1e6
Author: Thomas Landauer <[email protected]>
Date: Mon Oct 26 16:00:14 2015 +0100
Clear recommendation to test with Dropzone first
Please explain the following sentence:
"To enable the dynamic routes, add the following to your routing configuration file."
Is having dynamic routes mandatory or optional? What are dynamic routes at all?
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
|
f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be
|
1up-lab/OneupUploaderBundle
|
Changed the value string of the events. (BC-Break)
|
commit f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be
Author: Jim Schmid <[email protected]>
Date: Sat Apr 13 12:34:19 2013 +0200
Changed the value string of the events. (BC-Break)
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 84af61e..1163dee 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -33,7 +33,7 @@ And register it in your `services.xml`.
<services>
<service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener">
<argument type="service" id="doctrine" />
- <tag name="kernel.event_listener" event="oneup.uploader.post.persist" method="onUpload" />
+ <tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" />
</service>
</services>
```
@@ -41,11 +41,12 @@ And register it in your `services.xml`.
You can now implement you custom logic in the `onUpload` method of your EventListener.
## Use custom input data
-FineUploader supports passing custom data through the request as the following examples states. For example you can pass the id of an entity you wish to paste the images to.
+Many of the supported frontends support passing custom data through the request. Here's an example for [FineUploader](frontend_fineuploader.md) sending an id of an Entity along the normal request.
```html
<script type="text/javascript">
-var uploader = new qq.FineUploader({
+var uploader = new qq.FineUploader(
+{
element: document.getElementById('fine-uploader'),
request: {
endpoint: "{{ oneup_uploader_endpoint('gallery') }}",
@@ -57,7 +58,7 @@ var uploader = new qq.FineUploader({
</script>
```
-As you can see, we extended the `request` part of the Fine Uploader by adding a `params` section. These variables are accessible through the request object in the EventHander.
+As you can see, we extended the `request` part of the FineUploader by adding a `params` section. These variables are accessible through the request object in the EventHander.
```php
public function onUpload(PostPersistEvent $event)
diff --git a/UploadEvents.php b/UploadEvents.php
index 6a9967b..34e287c 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -4,6 +4,6 @@ namespace Oneup\UploaderBundle;
final class UploadEvents
{
- const POST_PERSIST = 'oneup.uploader.post.persist';
- const POST_UPLOAD = 'oneup.uploader.post.upload';
+ const POST_PERSIST = 'oneup_uploader.post_persist';
+ const POST_UPLOAD = 'oneup_uploader.post_upload';
}
\ No newline at end of file
| 0
|
d64ade8872f7a3e06a7c94b9620a398ca766974b
|
1up-lab/OneupUploaderBundle
|
Removed a notice which was stating that there is a default value for fronend config.
|
commit d64ade8872f7a3e06a7c94b9620a398ca766974b
Author: Jim Schmid <[email protected]>
Date: Tue Oct 8 21:03:16 2013 +0200
Removed a notice which was stating that there is a default value for fronend config.
diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md
index b024857..50ea10d 100644
--- a/Resources/doc/frontend_fineuploader.md
+++ b/Resources/doc/frontend_fineuploader.md
@@ -32,6 +32,4 @@ oneup_uploader:
frontend: fineuploader
```
-> 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.
| 0
|
249977688334962d0f8d7714ff50f59b349d840e
|
1up-lab/OneupUploaderBundle
|
Removed unused property.
|
commit 249977688334962d0f8d7714ff50f59b349d840e
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:49:10 2013 +0200
Removed unused property.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 016fb2b..c7dfb91 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -8,7 +8,6 @@ use Symfony\Component\Routing\RouteCollection;
class RouteLoader extends Loader
{
- protected $name;
protected $controllers;
public function __construct()
| 0
|
50c5ddae3219937270b793fe647a0e29f4e2b128
|
1up-lab/OneupUploaderBundle
|
Added a license file.
|
commit 50c5ddae3219937270b793fe647a0e29f4e2b128
Author: Jim Schmid <[email protected]>
Date: Sat Mar 9 11:46:09 2013 +0100
Added a license file.
diff --git a/Resources/meta/LICENSE b/Resources/meta/LICENSE
new file mode 100644
index 0000000..44d421f
--- /dev/null
+++ b/Resources/meta/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2013 1up GmbH
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
| 0
|
3ecd0b845d996916abc37d1e5052902756965ba5
|
1up-lab/OneupUploaderBundle
|
Fix for blueimp uploading not translating error messages
|
commit 3ecd0b845d996916abc37d1e5052902756965ba5
Author: Jason Playne <[email protected]>
Date: Tue Mar 14 11:13:35 2017 +0800
Fix for blueimp uploading not translating error messages
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index bf580bf..1f51fb2 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -12,7 +12,9 @@
<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.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false">
+ <argument type="service" id="translator"/>
+ </service>
<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" />
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 7ba1307..871e687 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
use Oneup\UploaderBundle\UploadEvents;
@@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest
public function testAgainstMaxSize()
{
// assemble a request
+ /** @var Client $client */
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
@@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
+ $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang");
}
public function testEvents()
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index c8839b7..be5e088 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+use Symfony\Component\Translation\TranslatorInterface;
class BlueimpErrorHandler implements ErrorHandlerInterface
{
+ /**
+ * @var TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct(TranslatorInterface $translator)
+ {
+ $this->translator = $translator;
+ }
+
public function addException(AbstractResponse $response, Exception $exception)
{
- $message = $exception->getMessage();
+ $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle');
$response->addToOffset(array('error' => $message), array('files'));
}
}
| 0
|
c07642908590218c4a01b4fea7d325beb11cbc48
|
1up-lab/OneupUploaderBundle
|
Something has fallen through the net.
|
commit c07642908590218c4a01b4fea7d325beb11cbc48
Author: Jim Schmid <[email protected]>
Date: Mon Jul 15 12:26:22 2013 +0200
Something has fallen through the net.
diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php
index fb5cc27..e9b1c30 100644
--- a/Uploader/Response/AbstractResponse.php
+++ b/Uploader/Response/AbstractResponse.php
@@ -58,6 +58,6 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
$element =& $element[$offset];
}
}
- $element = $value;
+ $element[] = $value;
}
}
| 0
|
74099dfe0e4da77cd71d7466f071274d33046c35
|
1up-lab/OneupUploaderBundle
|
Merge pull request #264 from zestic/iampersistent-patch-1
Add documentation for flysystem
|
commit 74099dfe0e4da77cd71d7466f071274d33046c35 (from 8389a0a5d0b06c084ebbad7b35f9afc10d122a7b)
Merge: 8389a0a f41e06b
Author: David Greminger <[email protected]>
Date: Tue Oct 4 15:27:15 2016 +0200
Merge pull request #264 from zestic/iampersistent-patch-1
Add documentation for 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
+```
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 7b6601e..1b07234 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -137,6 +137,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)
commit 74099dfe0e4da77cd71d7466f071274d33046c35 (from f41e06bf3252be7d661e11d4ab9b874971855eb7)
Merge: 8389a0a f41e06b
Author: David Greminger <[email protected]>
Date: Tue Oct 4 15:27:15 2016 +0200
Merge pull request #264 from zestic/iampersistent-patch-1
Add documentation for flysystem
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
|
7cf2a6dba946b53d22b1d3568af2c73327dedf3c
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit 7cf2a6dba946b53d22b1d3568af2c73327dedf3c (from 8b562d2775d535a9a74db4537c4ac09d71f97a04)
Merge: 8b562d2 da8f5e0
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 17:15:13 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 47e07a4..49bce30 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -76,7 +76,7 @@ abstract class AbstractController
// dispatch post persist event (both the specific and the general)
$postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config);
$dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
- $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postPersistEvent);
+ $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_PERSIST, $this->type), $postPersistEvent);
}
}
diff --git a/Resources/doc/testing.md b/Resources/doc/testing.md
index 7da4cb2..91a37a6 100644
--- a/Resources/doc/testing.md
+++ b/Resources/doc/testing.md
@@ -14,6 +14,17 @@ You can run the unit tests by simply performing the follwowing command.
$> phpunit
+If you are using the Gaufrette storage to upload files to an Amazon S3 instance be sure to add your AWS credentials by exporting them as environment variables.
+It will enable an otherwise skipped test.
+
+```bash
+export AWS_ACCESS_KEY_ID="your-id-here"
+export AWS_SECRET_ACCESS_KEY="your-key-here"
+export AWS_BUCKET="your-bucket-name-here"
+```
+
+Details can be found in the corresponding [pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/18).
+
## Testing Code Coverage
PHPUnit comes bundles with a handy feature to test the code coverage of a project. I recommend using the following configuration to enable the creation of code coverage reports in the `log` directory in the root of this bundle. This directory is gitignored by default.
@@ -57,4 +68,4 @@ The directories `Command`, `DependencyInjection` and `Event` are excluded from t
Run the test suite and generate reports by running:
- $> phpunit
\ No newline at end of file
+ $> phpunit
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 cf5518a..221dcaa 100644
--- a/composer.json
+++ b/composer.json
@@ -20,6 +20,7 @@
},
"require-dev": {
+ "amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
"symfony/class-loader": "2.*",
"symfony/security-bundle": "2.*",
commit 7cf2a6dba946b53d22b1d3568af2c73327dedf3c (from da8f5e0dfd8064d215e76eb1a44e6a0738270fdd)
Merge: 8b562d2 da8f5e0
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 17:15:13 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
diff --git a/composer.json b/composer.json
index e3ca30d..221dcaa 100644
--- a/composer.json
+++ b/composer.json
@@ -8,7 +8,9 @@
"authors": [
{
"name": "Jim Schmid",
- "email": "[email protected]"
+ "email": "[email protected]",
+ "homepage": "http://1up.io",
+ "role": "Developer"
}
],
| 0
|
ef9a63da0a79739cda2b8357f256cf51d097606a
|
1up-lab/OneupUploaderBundle
|
Normalized composer.json
|
commit ef9a63da0a79739cda2b8357f256cf51d097606a
Author: David Greminger <[email protected]>
Date: Fri Oct 23 11:08:14 2020 +0200
Normalized composer.json
diff --git a/composer.json b/composer.json
index ef7faad..001ef57 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,19 @@
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
"description": "This Symfony bundle provides a server implementation for handling single and multiple file uploads using either FineUploader, jQuery File Uploader, YUI3 Uploader, Uploadify, FancyUpload, MooUpload, Plupload or Dropzone. Features include chunked uploads, orphanages, Gaufrette and Flysystem support.",
- "keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload", "Dropzone"],
+ "keywords": [
+ "fileupload",
+ "upload",
+ "FineUploader",
+ "blueimp",
+ "jQuery File Uploader",
+ "YUI3 Uploader",
+ "Uploadify",
+ "FancyUpload",
+ "MooUpload",
+ "Plupload",
+ "Dropzone"
+ ],
"homepage": "https://1up.io",
"license": "MIT",
"authors": [
@@ -19,45 +31,42 @@
"role": "Developer"
}
],
-
"require": {
"php": "^7.2.5",
- "symfony/asset": "^4.4|^5.0",
- "symfony/event-dispatcher-contracts": "^1.0|^2.0",
- "symfony/finder": "^4.4|^5.0",
- "symfony/framework-bundle": "^4.4|^5.0",
- "symfony/mime": "^4.4|^5.0",
- "symfony/templating": "^4.4|^5.0",
- "symfony/translation": "^4.4|^5.0",
- "symfony/translation-contracts": "^1.0|^2.0",
- "symfony/yaml": "^4.4|^5.0",
- "twig/twig": "^2.4|^3.0"
+ "symfony/asset": "^4.4 || ^5.0",
+ "symfony/event-dispatcher-contracts": "^1.0 || ^2.0",
+ "symfony/finder": "^4.4 || ^5.0",
+ "symfony/framework-bundle": "^4.4 || ^5.0",
+ "symfony/mime": "^4.4 || ^5.0",
+ "symfony/templating": "^4.4 || ^5.0",
+ "symfony/translation": "^4.4 || ^5.0",
+ "symfony/translation-contracts": "^1.0 || ^2.0",
+ "symfony/yaml": "^4.4 || ^5.0",
+ "twig/twig": "^2.4 || ^3.0"
},
-
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"doctrine/common": "^2.12",
"friendsofphp/php-cs-fixer": "^2.16",
"knplabs/gaufrette": "^0.9",
- "oneup/flysystem-bundle": "^1.2|^2.0|^3.0",
+ "oneup/flysystem-bundle": "^1.2 || ^2.0 || ^3.0",
"phpstan/phpstan": "^0.12.10",
"phpunit/phpunit": "^8.5",
"sensio/framework-extra-bundle": "^5.0",
- "symfony/browser-kit": "^4.4|^5.0",
+ "symfony/browser-kit": "^4.4 || ^5.0",
"symfony/phpunit-bridge": "^5.0",
- "symfony/security-bundle": "^4.4|^5.0",
- "symfony/var-dumper": "^4.4|^5.0",
+ "symfony/security-bundle": "^4.4 || ^5.0",
+ "symfony/var-dumper": "^4.4 || ^5.0",
"twistor/flysystem-stream-wrapper": "^1.0"
},
- "config": {
- "sort-packages": true
- },
"suggest": {
"knplabs/knp-gaufrette-bundle": "0.1.*",
"oneup/flysystem-bundle": "^3.0",
"twistor/flysystem-stream-wrapper": "^1.0 (Required when using Flysystem)"
},
-
+ "config": {
+ "sort-packages": true
+ },
"autoload": {
"psr-4": {
"Oneup\\UploaderBundle\\": "src"
@@ -67,6 +76,8 @@
"psr-4": {
"Oneup\\UploaderBundle\\Tests\\": "tests"
},
- "classmap": [ "tests/App/Kernel.php"]
+ "classmap": [
+ "tests/App/Kernel.php"
+ ]
}
}
| 0
|
0882627712c313ac6cd58bf808fa6da61d911481
|
1up-lab/OneupUploaderBundle
|
Added MooUploadTest.
|
commit 0882627712c313ac6cd58bf808fa6da61d911481
Author: Jim Schmid <[email protected]>
Date: Fri May 31 17:47:52 2013 +0200
Added MooUploadTest.
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 9dc64b4..1b06878 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -23,7 +23,7 @@ class MooUploadController extends AbstractChunkedController
$response = new MooUploadResponse();
$headers = $request->headers;
- $file = $this->getUploadedFile($request);
+ list($file, $uploadFileName) = $this->getUploadedFile($request);
// we have to get access to this object in another method
$this->response = $response;
@@ -125,6 +125,6 @@ class MooUploadController extends AbstractChunkedController
// create an uploaded file to upload
$file = new UploadedFile($tempFile, $uploadFileName, null, null, null, true);
- return $file;
+ 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
+ ));
+ }
+}
| 0
|
645c008b7a025f199de7b787c2138fac56a438a3
|
1up-lab/OneupUploaderBundle
|
Merge branch 'master' of git://github.com/MJBGO/OneupUploaderBundle into MJBGO-master
|
commit 645c008b7a025f199de7b787c2138fac56a438a3 (from 17264b2a45f9d6acee144e4369b6abf3e19fea60)
Merge: 17264b2 dc7c5f6
Author: David Greminger <[email protected]>
Date: Tue Nov 21 15:43:20 2017 +0100
Merge branch 'master' of git://github.com/MJBGO/OneupUploaderBundle into MJBGO-master
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index 1f51fb2..d6aefe2 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.plupload.class">Oneup\UploaderBundle\Uploader\ErrorHandler\PluploadErrorHandler</parameter>
<parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter>
</parameters>
@@ -19,8 +20,8 @@
<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.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" />
+ <service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.plupload.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/PluploadErrorHandler.php b/Uploader/ErrorHandler/PluploadErrorHandler.php
new file mode 100644
index 0000000..6716c87
--- /dev/null
+++ b/Uploader/ErrorHandler/PluploadErrorHandler.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 PluploadErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(AbstractResponse $response, Exception $exception)
+ {
+ /* Plupload only needs an error message so it can be handled client side */
+ $message = $exception->getMessage();
+ $response['error'] = $message;
+ }
+}
+
+?>
commit 645c008b7a025f199de7b787c2138fac56a438a3 (from dc7c5f6361c073d428b569e8b14cb29e638607e4)
Merge: 17264b2 dc7c5f6
Author: David Greminger <[email protected]>
Date: Tue Nov 21 15:43:20 2017 +0100
Merge branch 'master' of git://github.com/MJBGO/OneupUploaderBundle into MJBGO-master
diff --git a/.travis.yml b/.travis.yml
index 5a3affa..15534ea 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,28 +1,28 @@
language: php
php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
- - hhvm
+ - 7.0
+ - 7.1
env:
- - SYMFONY_VERSION=2.3.*
+ - SYMFONY_VERSION=2.7.*
+ - SYMFONY_VERSION=2.8.*
+ - SYMFONY_VERSION=3.3.*
+ - SYMFONY_VERSION=dev-master
+
+cache:
+ directories:
+ - $COMPOSER_CACHE_DIR
matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
- - php: hhvm
- include:
- - php: 5.5
- env: SYMFONY_VERSION=2.4.*
- - php: 5.5
- env: SYMFONY_VERSION=2.5.*
- - php: 5.5
- env: SYMFONY_VERSION=dev-master
-before_script:
+before_install:
- composer selfupdate
- - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
- - composer install --dev --prefer-source
+
+before_script:
+ - travis_wait composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
+ - travis_wait 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 0c8a5b0..b4fdc99 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -4,25 +4,30 @@ 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');
+ $response = $this->createSupportedJsonResponse(array('error'=>$message ));
+ $response->setStatusCode(400);
+ return $response;
}
}
- 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 34e707d..c2c14eb 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;
@@ -69,7 +73,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']
;
@@ -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 = (float) 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/Event/PostChunkUploadEvent.php b/Event/PostChunkUploadEvent.php
index 9b32dfd..32e8fe7 100644
--- a/Event/PostChunkUploadEvent.php
+++ b/Event/PostChunkUploadEvent.php
@@ -8,7 +8,7 @@ use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
class PostChunkUploadEvent extends Event
{
- protected $file;
+ protected $chunk;
protected $request;
protected $type;
protected $response;
diff --git a/README.md b/README.md
index daa5eac..377fb9d 100644
--- a/README.md
+++ b/README.md
@@ -1,22 +1,23 @@
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 Symfony 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:
* 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
@@ -33,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 f0eb112..d6aefe2 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -7,18 +7,21 @@
<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.plupload.class">Oneup\UploaderBundle\Uploader\ErrorHandler\PluploadErrorHandler</parameter>
+ <parameter key="oneup_uploader.error_handler.dropzone.class">Oneup\UploaderBundle\Uploader\ErrorHandler\DropzoneErrorHandler</parameter>
</parameters>
<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.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false">
+ <argument type="service" id="translator"/>
+ </service>
<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.dropzone" class="%oneup_uploader.error_handler.dropzone.class%" public="false" />
<service id="oneup_uploader.error_handler.plupload" class="%oneup_uploader.error_handler.plupload.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 c970994..4389640 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -6,10 +6,13 @@
<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.urlsafename.class">Oneup\UploaderBundle\Uploader\Naming\UrlSafeNamer</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>
@@ -38,6 +41,7 @@
<!-- namer -->
<service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" />
+ <service id="oneup_uploader.namer.urlsafe" class="%oneup_uploader.namer.urlsafename.class%" />
<!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
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..421b66a 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -11,20 +11,31 @@ 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)
{
//...
+
+ //if everything went fine
+ $response = $event->getResponse();
+ $response['success'] = true;
+ return $response;
}
}
```
@@ -33,13 +44,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:
+ app.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 +110,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..37be120 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -1,7 +1,24 @@
Custom Namer
============
-The purpose of a namer service is to name an uploaded file before it is stored to the storage layer. Currently the OneupUploaderBundle only provides a single namer service called `UniqidNamer`, which will return a system wide unique filename using the `uniqid()` function.
+The purpose of a namer service is to name an uploaded file before it is stored to the storage layer.
+
+Currently the OneupUploaderBundle provides two namer methods.
+- Default used is a namer called `UniqidNamer`, which will return a system wide unique filename using the `uniqid()` function.
+- The other method called `UrlSafeNamer` using `random_bytes` function, see [Using UrlSafeNamer](#urlsafenamer) how to use it
+
+## UrlSafeNamer
+
+To enable UrlSafeNamer you will need to change your namer in your mappings to `oneup_uploader.namer.urlsafe`
+
+Example
+
+```yml
+oneup_uploader:
+ mappings:
+ gallery:
+ namer: oneup_uploader.namer.urlsafe
+```
## Use a custom namer
@@ -10,7 +27,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 +41,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 +51,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_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>
```
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/frontend_plupload.md b/Resources/doc/frontend_plupload.md
index deb1ce0..0c2e01d 100644
--- a/Resources/doc/frontend_plupload.md
+++ b/Resources/doc/frontend_plupload.md
@@ -1,7 +1,7 @@
Use Plupload in your Symfony2 application
=========================================
-Download [Plupload](http://http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`.
+Download [Plupload](http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`.
```html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 2e90a51..2e5f82e 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
- $> 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
@@ -72,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.
@@ -85,13 +78,43 @@ 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)".
+
+If you want to use your own path, for example /data/uploads :
+
+```yaml
+# app/config/config.yml
-### Step 4: Prepare your frontend
+oneup_uploader:
+ mappings:
+ gallery:
+ storage:
+ directory: "%kernel.root_dir%/../data/uploads/"
+```
+
+### 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');
@@ -104,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
@@ -122,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/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index 6848615..9e4db06 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -53,6 +53,18 @@ class AcmeController extends Controller
You will get an array containing the moved files.
+Note that you can move only one or a set of defined files out of the orphanage by passing an array to $manager->getFiles().
+For instance, you can use this to move a specific file:
+```php
+ // get files
+ $files = $manager->getFiles();
+
+ // reduce the scope of the Finder object to what you want
+ $files->files()->name($filename);
+ $manager->uploadFiles(iterator_to_array($files));
+```
+In this example, $filename is the name of the file you want to move out of the orphanage.
+
> If you are using Gaufrette, these files are instances of `Gaufrette\File`, otherwise `SplFileInfo`.
## Configure the Orphanage
diff --git a/Resources/meta/LICENSE b/Resources/meta/LICENSE
index 44d421f..bebab95 100644
--- a/Resources/meta/LICENSE
+++ b/Resources/meta/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2013 1up GmbH
+Copyright (c) 2015 1up GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
\ No newline at end of file
+THE SOFTWARE.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index fad6c0f..cd8c070 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -32,14 +32,22 @@ class RouteLoader extends Loader
$upload = new Route(
sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type),
array('_controller' => $service . ':upload', '_format' => 'json'),
- array('_method' => 'POST')
+ array(),
+ array(),
+ '',
+ array(),
+ array('POST', 'PUT', 'PATCH')
);
if ($options['enable_progress'] === true) {
$progress = new Route(
sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type),
array('_controller' => $service . ':progress', '_format' => 'json'),
- array('_method' => 'POST')
+ array(),
+ array(),
+ '',
+ array(),
+ array('POST')
);
$routes->add(sprintf('_uploader_progress_%s', $type), $progress);
@@ -49,7 +57,11 @@ class RouteLoader extends Loader
$progress = new Route(
sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type),
array('_controller' => $service . ':cancel', '_format' => 'json'),
- array('_method' => 'POST')
+ array(),
+ array(),
+ '',
+ array(),
+ array('POST')
);
$routes->add(sprintf('_uploader_cancel_%s', $type), $progress);
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index 9e6d26a..2b0abf7 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -40,8 +40,7 @@ abstract class AbstractControllerTest extends WebTestCase
*/
public function testCallByGet()
{
- $endpoint = $this->helper->endpoint($this->getConfigKey());
- $this->client->request('GET', $endpoint);
+ $this->implTestCallBy('GET');
}
/**
@@ -49,25 +48,30 @@ abstract class AbstractControllerTest extends WebTestCase
*/
public function testCallByDelete()
{
- $endpoint = $this->helper->endpoint($this->getConfigKey());
- $this->client->request('DELETE', $endpoint);
+ $this->implTestCallBy('DELETE');
}
- /**
- * @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
- */
- public function testCallByPut()
+ public function testCallByPatch()
{
- $endpoint = $this->helper->endpoint($this->getConfigKey());
- $this->client->request('PUT', $endpoint);
+ $this->implTestCallBy('PATCH');
}
public function testCallByPost()
+ {
+ $this->implTestCallBy('POST');
+ }
+
+ public function testCallByPut()
+ {
+ $this->implTestCallBy('PUT');
+ }
+
+ protected function implTestCallBy($method)
{
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
- $client->request('POST', $endpoint, array(), array(), $this->requestHeaders);
+ $client->request($method, $endpoint, array(), array(), $this->requestHeaders);
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 7ba1307..871e687 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
use Oneup\UploaderBundle\UploadEvents;
@@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest
public function testAgainstMaxSize()
{
// assemble a request
+ /** @var Client $client */
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
@@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
+ $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang");
}
public function testEvents()
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 4058039..95b35ab 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -33,8 +33,8 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
- $this->assertEquals($route->getDefault('_format'), 'json');
- $this->assertEquals($route->getRequirement('_method'), 'POST');
+ $this->assertEquals('json', $route->getDefault('_format'));
+ $this->assertContains('POST', $route->getMethods());
}
}
@@ -55,8 +55,8 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
- $this->assertEquals($route->getDefault('_format'), 'json');
- $this->assertEquals($route->getRequirement('_method'), 'POST');
+ $this->assertEquals('json', $route->getDefault('_format'));
+ $this->assertContains('POST', $route->getMethods());
$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
diff --git a/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php
index af1f32f..ca14e11 100644
--- a/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php
+++ b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php
@@ -2,18 +2,22 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\ChunkStorageInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase
{
protected $tmpDir;
+ /**
+ * @var ChunkStorageInterface
+ */
protected $storage;
public function testExistanceOfTmpDir()
{
$this->assertTrue(is_dir($this->tmpDir));
- $this->assertTrue(is_writeable($this->tmpDir));
+ $this->assertTrue(is_writable($this->tmpDir));
}
public function testFillOfTmpDir()
@@ -30,7 +34,7 @@ abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase
public function testChunkCleanup()
{
// get a manager configured with a max-age of 5 minutes
- $maxage = 5 * 60;
+ $maxage = 5 * 60;
$numberOfFiles = 10;
$finder = new Finder();
@@ -42,7 +46,7 @@ abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase
$this->storage->clear($maxage);
$this->assertTrue(is_dir($this->tmpDir));
- $this->assertTrue(is_writeable($this->tmpDir));
+ $this->assertTrue(is_writable($this->tmpDir));
$this->assertCount(5, $finder);
@@ -66,8 +70,8 @@ abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase
{
$system = new Filesystem();
- for ($i = 0; $i < $number; $i ++) {
- $system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
+ for ($i = 0; $i < $number; ++$i) {
+ $system->touch(sprintf('%s/%s', $this->tmpDir, uniqid('', true)), time() - $i * 60);
}
}
}
diff --git a/Tests/Uploader/Chunk/Storage/FlysystemStorageTest.php b/Tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
new file mode 100644
index 0000000..8d553a1
--- /dev/null
+++ b/Tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
+
+use League\Flysystem\Adapter\Local as Adapter;
+use League\Flysystem\Filesystem as LeagueFilesystem;
+use League\Flysystem\Plugin\ListFiles;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage;
+use Symfony\Component\Filesystem\Filesystem;
+use Twistor\FlysystemStreamWrapper;
+
+class FlysystemStorageTest extends ChunkStorageTest
+{
+ protected $parentDir;
+ protected $chunkKey = 'chunks';
+ protected $chunkDir;
+
+ public function setUp()
+ {
+ // create a cache dir
+ $parentDir = sprintf('/tmp/%s', uniqid('', true));
+
+ $system = new Filesystem();
+ $system->mkdir($parentDir);
+
+ $this->parentDir = $parentDir;
+
+ $adapter = new Adapter($this->parentDir);
+
+ $filesystem = new LeagueFilesystem($adapter);
+ $filesystem->addPlugin(new ListFiles());
+
+ FlysystemStreamWrapper::register('tests', $filesystem);
+
+ $this->storage = new FlysystemStorage($filesystem, 100000, 'tests:/', $this->chunkKey);
+ $this->tmpDir = $this->parentDir.'/'.$this->chunkKey;
+
+ $system->mkdir($this->tmpDir);
+ }
+
+ public function tearDown()
+ {
+ $system = new Filesystem();
+ $system->remove($this->parentDir);
+
+ FlysystemStreamWrapper::unregister('tests');
+ }
+}
diff --git a/Tests/Uploader/Naming/UrlSafeNamerTest.php b/Tests/Uploader/Naming/UrlSafeNamerTest.php
new file mode 100644
index 0000000..1707940
--- /dev/null
+++ b/Tests/Uploader/Naming/UrlSafeNamerTest.php
@@ -0,0 +1,53 @@
+<?php
+namespace Oneup\UploaderBundle\Tests\Uploader\Naming;
+
+use Oneup\UploaderBundle\Tests\Uploader\File\FileTest;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Oneup\UploaderBundle\Uploader\Naming\UrlSafeNamer;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class UrlSafeNamerTest extends FileTest
+{
+
+ public function setUp()
+ {
+ $this->path = sys_get_temp_dir(). '/oneup_namer_test';
+ mkdir($this->path);
+
+ $this->basename = 'test_file.txt';
+ $this->pathname = $this->path .'/'. $this->basename;
+ $this->extension = 'txt';
+ $this->size = 9; //something = 9 bytes
+ $this->mimeType = 'text/plain';
+
+ file_put_contents($this->pathname, 'something');
+
+ $this->file = new FilesystemFile(new UploadedFile($this->pathname, 'test_file.txt', null, null, null, true));
+ }
+
+ public function testCanGetString()
+ {
+ $namer = new UrlSafeNamer();
+ $this->assertTrue(is_string($namer->name($this->file)));
+ $this->assertStringEndsWith($this->extension, $namer->name($this->file));
+ }
+
+ public function test_two_file_names_not_equal()
+ {
+ $namer = new UrlSafeNamer();
+ // Trying 200 times just to be sure
+ for($i = 0; $i < 200; $i++) {
+ $name1 = $namer->name($this->file);
+ $name2 = $namer->name($this->file);
+ $this->assertNotEquals($name1, $name2);
+ }
+
+ }
+
+ public function tearDown()
+ {
+ unlink($this->pathname);
+ rmdir($this->path);
+ }
+
+}
diff --git a/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
new file mode 100644
index 0000000..af5a194
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -0,0 +1,120 @@
+<?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;
+use Twistor\FlysystemStreamWrapper;
+
+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();
+
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($this->realDirectory);
+ $filesystem->mkdir($this->chunkDirectory);
+ $filesystem->mkdir($this->tempDirectory);
+
+ $adapter = new Adapter($this->realDirectory);
+ $filesystem = new FSAdapter($adapter);
+
+ FlysystemStreamWrapper::register('tests', $filesystem);
+
+ $this->storage = new Storage($filesystem, 100000);
+
+ $chunkStorage = new ChunkStorage($filesystem, 100000, 'tests:/', '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);
+
+ //file key needs to be relative to the root of the flysystem filesystem
+ $fileKey = str_replace($this->realDirectory, '', $file);
+
+ $this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem);
+ }
+ }
+
+ public function tearDown()
+ {
+ (new Filesystem())->remove($this->realDirectory);
+
+ FlysystemStreamWrapper::unregister('tests');
+ }
+
+ 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);
+ }
+}
diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php
new file mode 100644
index 0000000..121a7ec
--- /dev/null
+++ b/Tests/Uploader/Storage/FlysystemStorageTest.php
@@ -0,0 +1,77 @@
+<?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 testUploadWithPath()
+ {
+ $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true));
+ $this->storage->upload($payload, 'notsogrumpyanymore.jpeg', 'cat');
+
+ $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/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();
diff --git a/Uploader/Chunk/Storage/FlysystemStorage.php b/Uploader/Chunk/Storage/FlysystemStorage.php
new file mode 100644
index 0000000..77eabc6
--- /dev/null
+++ b/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -0,0 +1,152 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
+
+use League\Flysystem\FileNotFoundException;
+use League\Flysystem\Filesystem;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
+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 (null === $streamWrapperPrefix) {
+ throw new \InvalidArgumentException('Stream wrapper must be configured.');
+ }
+
+ $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->listContents($prefix, true);
+
+ $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 as $key) {
+ $path = $key['path'];
+ $timestamp = isset($key['timestamp']) ? $key['timestamp'] : $this->filesystem->getTimestamp($path);
+
+ if ($maxAge <= $now - $timestamp) {
+ $toDelete[] = $path;
+ }
+ }
+
+ foreach ($toDelete as $path) {
+ // The filesystem will throw exceptions if
+ // a directory is not empty
+ try {
+ $this->filesystem->delete($path);
+ } 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]['path'], PATHINFO_BASENAME);
+ }
+
+ $mode = 'ab';
+ if (0 === $this->unhandledChunk['index']) {
+ // if it's the first chunk overwrite the already existing part
+ // to avoid appending to earlier failed uploads
+ $mode = 'wb';
+ }
+
+ $file = fopen($this->unhandledChunk['chunk']->getPathname(), 'rb');
+ $dest = fopen($this->streamWrapperPrefix.'/'.$path.$target, $mode);
+
+ stream_copy_to_stream($file, $dest);
+
+ fclose($file);
+ fclose($dest);
+
+ if ($renameChunk) {
+ $name = $this->unhandledChunk['original'];
+ /* 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)
+ {
+ try {
+ $this->filesystem->delete($path);
+ } catch (FileNotFoundException $e) {
+ // File already gone.
+ }
+ }
+
+ public function getChunks($uuid)
+ {
+ return $this->filesystem->listFiles($this->prefix.'/'.$uuid);
+ }
+
+ public function getFilesystem()
+ {
+ return $this->filesystem;
+ }
+
+ public function getStreamWrapperPrefix()
+ {
+ return $this->streamWrapperPrefix;
+ }
+}
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index c8839b7..be5e088 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+use Symfony\Component\Translation\TranslatorInterface;
class BlueimpErrorHandler implements ErrorHandlerInterface
{
+ /**
+ * @var TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct(TranslatorInterface $translator)
+ {
+ $this->translator = $translator;
+ }
+
public function addException(AbstractResponse $response, Exception $exception)
{
- $message = $exception->getMessage();
+ $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle');
$response->addToOffset(array('error' => $message), array('files'));
}
}
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/Naming/UrlSafeNamer.php b/Uploader/Naming/UrlSafeNamer.php
new file mode 100644
index 0000000..7ff6660
--- /dev/null
+++ b/Uploader/Naming/UrlSafeNamer.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Naming;
+
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+
+class UrlSafeNamer implements NamerInterface
+{
+
+ /**
+ * Name a given file and return the name
+ *
+ * @param FileInterface $file
+ * @return string
+ */
+ public function name(FileInterface $file)
+ {
+ $bytes = random_bytes(256 / 8);
+ return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=') . '.' . $file->getExtension();
+ }
+}
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index 6903db7..4733b76 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -17,6 +17,11 @@ class OrphanageManager
$this->config = $config;
}
+ public function has($key)
+ {
+ return $this->container->has(sprintf('oneup_uploader.orphanage.%s', $key));
+ }
+
public function get($key)
{
return $this->container->get(sprintf('oneup_uploader.orphanage.%s', $key));
@@ -27,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;
@@ -47,5 +52,21 @@ class OrphanageManager
foreach ($finder as $file) {
$system->remove($file);
}
+
+ // Now that the files are cleaned, we check if we need to remove some directories as well
+ // We use a new instance of the Finder as it as a state
+ $finder = new Finder();
+ $finder->in($this->config['directory'])->directories();
+
+ $dirArray = iterator_to_array($finder, false);
+ $size = sizeof($dirArray);
+
+ // We crawl the array backward as the Finder returns the parent first
+ for ($i = $size-1; $i >= 0; $i--) {
+ $dir = $dirArray[$i];
+ if (!(new \FilesystemIterator($dir))->valid()) {
+ $system->remove($dir);
+ }
+ }
}
}
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..6cc00ab
--- /dev/null
+++ b/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -0,0 +1,100 @@
+<?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()
+ {
+ $fileList = $this->chunkStorage
+ ->getFilesystem()
+ ->listContents($this->getPath());
+ $files = array();
+
+ foreach ($fileList as $fileDetail) {
+ $key = $fileDetail['path'];
+ if ($fileDetail['type'] == 'file') {
+ $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..c3783ac
--- /dev/null
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+use League\Flysystem\Filesystem;
+use League\Flysystem\MountManager;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+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 = null === $path ? $name : sprintf('%s/%s', $path, $name);
+
+ if ($file instanceof FilesystemFile) {
+ $stream = fopen($file->getPathname(), 'rb+');
+ $this->filesystem->putStream($path, $stream, array(
+ 'mimetype' => $file->getMimeType()
+ ));
+
+ if (is_resource($stream)) {
+ fclose($stream);
+ }
+
+ $filesystem = new LocalFilesystem();
+ $filesystem->remove($file->getPathname());
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+ if ($file instanceof FlysystemFile && $file->getFilesystem() === $this->filesystem) {
+ $file->getFilesystem()->rename($file->getPath(), $path);
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+
+ $manager = new MountManager([
+ 'chunks' => $file->getFilesystem(),
+ 'dest' => $this->filesystem,
+ ]);
+
+ $manager->move(sprintf('chunks://%s', $file->getPathname()), sprintf('dest://%s', $path));
+
+ return new FlysystemFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
+ }
+}
diff --git a/composer.json b/composer.json
index aa66e5d..d68b779 100644
--- a/composer.json
+++ b/composer.json
@@ -15,22 +15,31 @@
],
"require": {
- "symfony/framework-bundle": ">=2.2",
- "symfony/finder": ">=2.2.0"
+ "php":">=5.4",
+ "symfony/framework-bundle": "^2.4|^3.0",
+ "symfony/finder": "^2.4|^3.0",
+ "symfony/translation": "^2.4|^3.0",
+ "symfony/asset": "^2.4|^3.0",
+ "symfony/templating": "^2.4|^3.0",
+ "paragonie/random_compat": "^1.1|^2.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"
+ "oneup/flysystem-bundle": "^1.2",
+ "phpunit/phpunit": "^4.4",
+ "sensio/framework-extra-bundle": "2.*|^3.0",
+ "symfony/browser-kit": "2.*|^3.0",
+ "symfony/class-loader": "2.*|^3.0",
+ "symfony/security-bundle": "2.*|^3.0",
+ "twistor/flysystem-stream-wrapper": "^1.0"
},
"suggest": {
- "knplabs/knp-gaufrette-bundle": "0.1.*"
+ "knplabs/knp-gaufrette-bundle": "0.1.*",
+ "oneup/flysystem-bundle": "^1.2",
+ "twistor/flysystem-stream-wrapper": "^1.0 (Required when using Flysystem)"
},
"autoload": {
| 0
|
ef0866987f32ec66fcea3db5af853c2a0d23cf17
|
1up-lab/OneupUploaderBundle
|
Adjusted test to Symfony3 and PHP > 5.5.9
|
commit ef0866987f32ec66fcea3db5af853c2a0d23cf17
Author: David Greminger <[email protected]>
Date: Thu Dec 10 15:54:45 2015 +0100
Adjusted test to Symfony3 and PHP > 5.5.9
diff --git a/.travis.yml b/.travis.yml
index 097154d..f81a416 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,12 +10,8 @@ php:
env:
- SYMFONY_VERSION=2.4.*
- - SYMFONY_VERSION=2.5.*
- - SYMFONY_VERSION=2.6.*
- SYMFONY_VERSION=2.7.*
- SYMFONY_VERSION=2.8.*
- - SYMFONY_VERSION=3.0.*
- - SYMFONY_VERSION=dev-master
cache:
directories:
@@ -27,6 +23,22 @@ matrix:
- php: 7.0
- env: SYMFONY_VERSION=dev-master
+ include:
+ - php: 5.6
+ env: SYMFONY_VERSION=2.4.*
+ - php: 5.6
+ env: SYMFONY_VERSION=2.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/http-kernel:${SYMFONY_VERSION} --prefer-source
| 0
|
6e27f44a53a1653c74cf4ab8d4d0c1e5e8fa909c
|
1up-lab/OneupUploaderBundle
|
Adjusted version constraints for Symfony3.0.*
|
commit 6e27f44a53a1653c74cf4ab8d4d0c1e5e8fa909c
Author: David Greminger <[email protected]>
Date: Thu Dec 10 14:22:26 2015 +0100
Adjusted version constraints for Symfony3.0.*
diff --git a/composer.json b/composer.json
index 7f745ad..3d765c4 100644
--- a/composer.json
+++ b/composer.json
@@ -15,18 +15,18 @@
],
"require": {
- "symfony/framework-bundle": "^2.3.0|~3.0",
- "symfony/http-kernel": "^2.3.0|~3.0",
- "symfony/finder": ">=2.2.0|~3.0"
+ "symfony/framework-bundle": "2.4.*",
+ "symfony/http-kernel": "^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.*",
+ "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"
},
| 0
|
6986af599e9df195ea212efddbdd1db0b541375e
|
1up-lab/OneupUploaderBundle
|
Fixes a bug in Configuration.php - wrong array key
|
commit 6986af599e9df195ea212efddbdd1db0b541375e
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 16:27:53 2013 +0200
Fixes a bug in Configuration.php - wrong array key
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index e8a53dd..8174498 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -104,7 +104,7 @@ class OneupUploaderExtension extends Extension
}
}
- if($mapping['frontent'] != 'custom')
+ if($mapping['frontend'] != 'custom')
{
$controllerName = sprintf('oneup_uploader.controller.%s', $key);
$controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $mapping['frontend']);
@@ -117,7 +117,7 @@ class OneupUploaderExtension extends Extension
$controllerType = $customFrontend['name'];
if(empty($controllerName) || empty($controllerType))
- throw new ServiceNotFoundException('Empty controller class. If you really want to use a custom frontend implementation, be sure to provide a class and a name.');
+ 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.');
}
// create controllers based on mapping
| 0
|
86efe3662c06ca6decbf997d9528bcae3e8c9fd0
|
1up-lab/OneupUploaderBundle
|
Blacklist test against a files mime type.
|
commit 86efe3662c06ca6decbf997d9528bcae3e8c9fd0
Author: Jim Schmid <[email protected]>
Date: Tue Apr 23 21:16:02 2013 +0200
Blacklist test against a files mime type.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 5c713c0..c22b3d1 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -67,6 +67,9 @@ class Configuration implements ConfigurationInterface
->arrayNode('allowed_mimetypes')
->prototype('scalar')->end()
->end()
+ ->arrayNode('disallowed_mimetypes')
+ ->prototype('scalar')->end()
+ ->end()
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
diff --git a/EventListener/DisallowedMimetypeValidationListener.php b/EventListener/DisallowedMimetypeValidationListener.php
new file mode 100644
index 0000000..3981298
--- /dev/null
+++ b/EventListener/DisallowedMimetypeValidationListener.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class DisallowedMimetypeValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ if(count($config['disallowed_mimetypes']) == 0) {
+ return;
+ }
+
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ $mimetype = finfo_file($finfo, $file->getRealpath());
+
+ if(in_array($mimetype, $config['disallowed_mimetypes'])) {
+ throw new ValidationException('error.blacklist');
+ }
+ }
+}
diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml
index 51b1449..a47e6a9 100644
--- a/Resources/config/validators.xml
+++ b/Resources/config/validators.xml
@@ -19,6 +19,10 @@
<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>
+
+ <service id="oneup_uploader.validation_listener.disallowed_mimetype" class="Oneup\UploaderBundle\EventListener\DisallowedMimetypeValidationListener">
+ <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
+ </service>
</services>
</container>
| 0
|
0f34d8cbe4b933d5e2b8ba330d20e11dd4bf80d7
|
1up-lab/OneupUploaderBundle
|
Upload to the cache directory.
|
commit 0f34d8cbe4b933d5e2b8ba330d20e11dd4bf80d7
Author: Jim Schmid <[email protected]>
Date: Mon May 6 21:57:46 2013 +0200
Upload to the cache directory.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index d61f898..7c7d4c8 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -1,5 +1,4 @@
framework:
- #esi: ~
translator: { fallback: en }
secret: secret
router:
@@ -10,7 +9,6 @@ framework:
validation: { enable_annotations: true }
templating:
engines: ['php']
- #assets_version: SomeVersionScheme
default_locale: en
trusted_proxies: ~
session: ~
@@ -30,4 +28,6 @@ monolog:
oneup_uploader:
mappings:
- gallery: ~
\ No newline at end of file
+ blueimp:
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
\ No newline at end of file
| 0
|
5e789d8b759d1977643a5ac99b3291fd30d866f5
|
1up-lab/OneupUploaderBundle
|
made docs a bit nicer with a check
|
commit 5e789d8b759d1977643a5ac99b3291fd30d866f5
Author: mitom <[email protected]>
Date: Mon Oct 14 20:56:48 2013 +0200
made docs a bit nicer with a check
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index c017bdc..a3f55dc 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -63,6 +63,12 @@ class OneupUploaderExtension extends Extension
protected function processMapping($key, &$mapping)
{
+ if ($this->config['chunks']['storage']['type'] === 'gaufrette') {
+ if ($mapping['storage']['type'] !== 'gaufrette') {
+ throw new \InvalidArgumentException('If you use a gaufrette based chunk storage, you may only use gaufrette based storages too.');
+ }
+ }
+
$mapping['max_size'] = $mapping['max_size'] < 0 ?
$this->getMaxUploadSize($mapping['max_size']) :
$mapping['max_size']
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index fd6d87a..2f53fb7 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -69,7 +69,7 @@ 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 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!
+> :exclamation: If you use a gaufrette filesystem as chunk storage, you may only use gaufrette filesystems in your mappings too!
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.
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.