commit_id
stringlengths 40
40
| owner
stringclasses 29
values | repo
stringclasses 30
values | commit_message
stringlengths 1
409k
| diff
stringlengths 147
117M
| label
int64 0
0
|
|---|---|---|---|---|---|
41df4540fe52c4b71f5280b5be1e8aa440c71cd7
|
1up-lab
|
OneupUploaderBundle
|
Testing ChunkManager (basic implementation).
|
commit 41df4540fe52c4b71f5280b5be1e8aa440c71cd7
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 12:12:35 2013 +0100
Testing ChunkManager (basic implementation).
diff --git a/Tests/Uploader/Chunk/ChunkManagerTest.php b/Tests/Uploader/Chunk/ChunkManagerTest.php
new file mode 100644
index 0000000..85967a9
--- /dev/null
+++ b/Tests/Uploader/Chunk/ChunkManagerTest.php
@@ -0,0 +1,100 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Chunk;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+
+use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
+
+class ChunkManagerTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tmpDir;
+
+ public function setUp()
+ {
+ // create a cache dir
+ $tmpDir = sprintf('/tmp/%s', uniqid());
+
+ $system = new Filesystem();
+ $system->mkdir($tmpDir);
+
+ $this->tmpDir = $tmpDir;
+ }
+
+ public function tearDown()
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ // first remove every file in temporary directory
+ foreach($finder->in($this->tmpDir) as $file)
+ {
+ $system->remove($file);
+ }
+
+ // and finally remove the directory itself
+ $system->remove($this->tmpDir);
+ }
+
+ public function testExistanceOfTmpDir()
+ {
+ $this->assertTrue(is_dir($this->tmpDir));
+ $this->assertTrue(is_writeable($this->tmpDir));
+ }
+
+ public function testFillOfTmpDir()
+ {
+ $finder = new Finder();
+ $finder->in($this->tmpDir);
+
+ $numberOfFiles = 10;
+
+ $this->fillDirectory($numberOfFiles);
+ $this->assertCount($numberOfFiles, $finder);
+ }
+
+ public function testChunkCleanup()
+ {
+ // get a manager configured with a max-age of 5 minutes
+ $maxage = 5 * 60;
+ $manager = $this->getManager($maxage);
+ $numberOfFiles = 10;
+
+ $finder = new Finder();
+ $finder->in($this->tmpDir);
+
+ $this->fillDirectory($numberOfFiles);
+ $this->assertCount(10, $finder);
+
+ $manager->clear();
+
+ $this->assertTrue(is_dir($this->tmpDir));
+ $this->assertTrue(is_writeable($this->tmpDir));
+
+ $this->assertCount(5, $finder);
+
+ foreach($finder as $file)
+ {
+ $this->assertGreaterThanOrEqual(time() - $maxage, filemtime($file));
+ }
+ }
+
+ protected function getManager($maxage)
+ {
+ return new ChunkManager(array(
+ 'directory' => $this->tmpDir,
+ 'maxage' => $maxage
+ ));
+ }
+
+ protected function fillDirectory($number)
+ {
+ $system = new Filesystem();
+
+ for($i = 0; $i < $number; $i ++)
+ {
+ $system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 332ae47..1b184f5 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -1,11 +1,13 @@
<?php
-namespace Oneup\UploaderBundle\Uploder\Chunk;
+namespace Oneup\UploaderBundle\Uploader\Chunk;
+use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
-use Oneup\UploaderBundle\Uploader\ChunkManagerInterface;
-class ChunkManager implements ChunkManagerInterafce
+use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
+
+class ChunkManager implements ChunkManagerInterface
{
public function __construct($configuration)
{
@@ -20,9 +22,14 @@ class ChunkManager implements ChunkManagerInterafce
public function clear()
{
- $fileSystem = new FileSystem();
- $fileSystem->remove($this->configuration['directory']);
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
- $this->warmup();
+ foreach($finder as $file)
+ {
+ $system->remove($file);
+ }
}
}
\ No newline at end of file
| 0
|
01718556b0a231a26930fd5e32550992b3d1e350
|
1up-lab
|
OneupUploaderBundle
|
Removed unused dependencies in tests.
|
commit 01718556b0a231a26930fd5e32550992b3d1e350
Author: Jim Schmid <[email protected]>
Date: Tue Aug 13 16:23:31 2013 +0200
Removed unused dependencies in tests.
diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php
index 7a15fe8..f1aa6f0 100644
--- a/Tests/App/AppKernel.php
+++ b/Tests/App/AppKernel.php
@@ -10,9 +10,7 @@ class AppKernel extends Kernel
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
- new Symfony\Bundle\MonologBundle\MonologBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
- new JMS\SerializerBundle\JMSSerializerBundle($this),
// bundle to test
new Oneup\UploaderBundle\OneupUploaderBundle(),
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 5c31e2c..43d37c3 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -10,17 +10,6 @@ framework:
session: ~
test: ~
-monolog:
- handlers:
- main:
- type: fingers_crossed
- action_level: error
- handler: nested
- nested:
- type: stream
- path: %kernel.logs_dir%/%kernel.environment%.log
- level: debug
-
oneup_uploader:
mappings:
diff --git a/composer.json b/composer.json
index df76f99..f2b846a 100644
--- a/composer.json
+++ b/composer.json
@@ -22,14 +22,8 @@
"require-dev": {
"amazonwebservices/aws-sdk-for-php": "1.5.*",
"knplabs/gaufrette": "0.2.*@dev",
- "symfony/class-loader": "2.*",
"symfony/security-bundle": "2.*",
- "symfony/monolog-bundle": "2.*",
"sensio/framework-extra-bundle": "2.*",
- "jms/serializer-bundle": "dev-master",
- "symfony/yaml": "2.*",
- "symfony/form": "2.*",
- "symfony/twig-bundle": "2.*",
"symfony/browser-kit": "2.*",
"phpunit/phpunit": "3.7.*"
},
| 0
|
59fc81f467dde376f02d4f38913ce834dacdf878
|
1up-lab
|
OneupUploaderBundle
|
Added a Command for clearing chunks: oneup:uploader:clear-chunks
|
commit 59fc81f467dde376f02d4f38913ce834dacdf878
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 13:40:26 2013 +0100
Added a Command for clearing chunks: oneup:uploader:clear-chunks
diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php
new file mode 100644
index 0000000..50bca9f
--- /dev/null
+++ b/Command/ClearChunkCommand.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Oneup\UploaderBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class ClearChunkCommand extends ContainerAwareCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('oneup:uploader:clear-chunks')
+ ->setDescription('Clear chunks according to the max-age you defined in your configuration.')
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $manager = $this->getContainer()->get('oneup_uploader.chunks.manager');
+ $manager->clear();
+ }
+}
\ No newline at end of file
| 0
|
687dc14ee3f292d438adbc88c3dd913d7e09d815
|
1up-lab
|
OneupUploaderBundle
|
Added MooUpload tag to composer.json
|
commit 687dc14ee3f292d438adbc88c3dd913d7e09d815
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 14:59:44 2013 +0200
Added MooUpload tag to composer.json
diff --git a/composer.json b/composer.json
index a8ae808..36f6e82 100644
--- a/composer.json
+++ b/composer.json
@@ -1,8 +1,8 @@
{
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
- "description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support...",
- "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload"],
+ "description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support.",
+ "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload"],
"homepage": "http://1up.io",
"license": "MIT",
"authors": [
| 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
|
e6f99c59d9b613fd35e0c1cb9cfc663dc53705c3
|
1up-lab
|
OneupUploaderBundle
|
Introduced getFiles function on AbstractController
This method will flatten a given file bag and extract all UploadedFile instances.
Addresses: #28 & #29.
|
commit e6f99c59d9b613fd35e0c1cb9cfc663dc53705c3
Author: Jim Schmid <[email protected]>
Date: Thu Jul 18 10:31:22 2013 +0200
Introduced getFiles function on AbstractController
This method will flatten a given file bag and extract all UploadedFile instances.
Addresses: #28 & #29.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 865517d..9f6c7f0 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -6,6 +6,7 @@ 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;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PreUploadEvent;
@@ -68,6 +69,29 @@ abstract class AbstractController
return new JsonResponse(true);
}
+ /**
+ * Flattens a given filebag to extract all files.
+ *
+ * @param bag The filebag to use
+ * @return array An array of files
+ */
+ protected function getFiles(FileBag $bag)
+ {
+ $files = array();
+ $fileBag = $bag->all();
+ $fileIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fileBag), \RecursiveIteratorIterator::SELF_FIRST);
+
+ foreach ($fileIterator as $file) {
+ if (is_array($file)) {
+ continue;
+ }
+
+ $files[] = $file;
+ }
+
+ return $files;
+ }
+
/**
* This internal function handles the actual upload process
* and will most likely be called from the upload()
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index c0842a8..3e1578b 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -15,7 +15,7 @@ class BlueimpController extends AbstractChunkedController
{
$request = $this->container->get('request');
$response = new EmptyResponse();
- $files = $request->files->get('files');
+ $files = $this->getFiles($request->files);
$chunked = !is_null($request->headers->get('content-range'));
diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php
index 00858f6..8901b2e 100644
--- a/Controller/FancyUploadController.php
+++ b/Controller/FancyUploadController.php
@@ -14,7 +14,7 @@ class FancyUploadController extends AbstractController
{
$request = $this->container->get('request');
$response = new EmptyResponse();
- $files = $request->files;
+ $files = $this->getFiles($request->files);
foreach ($files as $file) {
try {
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index a9dc1b1..e279e8b 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -18,7 +18,7 @@ class FineUploaderController extends AbstractChunkedController
$response = new FineUploaderResponse();
$totalParts = $request->get('qqtotalparts', 1);
- $files = $request->files;
+ $files = $this->getFiles($request->files);
$chunked = $totalParts > 1;
foreach ($files as $file) {
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index d2b6a8a..9f06c18 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -15,7 +15,7 @@ class PluploadController extends AbstractChunkedController
{
$request = $this->container->get('request');
$response = new EmptyResponse();
- $files = $request->files;
+ $files = $this->getFiles($request->files);
$chunked = !is_null($request->get('chunks'));
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index de75cdd..a98f7e8 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -14,7 +14,7 @@ class UploadifyController extends AbstractController
{
$request = $this->container->get('request');
$response = new EmptyResponse();
- $files = $request->files;
+ $files = $this->getFiles($request->files);
foreach ($files as $file) {
try {
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index ac4760c..8638ad6 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -14,7 +14,7 @@ class YUI3Controller extends AbstractController
{
$request = $this->container->get('request');
$response = new EmptyResponse();
- $files = $request->files;
+ $files = $this->getFiles($request->files);
foreach ($files as $file) {
try {
| 0
|
141e0ca71fb6ff5e8a807199aac2982ee429c17b
|
1up-lab
|
OneupUploaderBundle
|
Fix .gitignore
|
commit 141e0ca71fb6ff5e8a807199aac2982ee429c17b
Author: David Greminger <[email protected]>
Date: Fri Oct 23 11:28:52 2020 +0200
Fix .gitignore
diff --git a/.gitignore b/.gitignore
index 99971d8..0204479 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,8 +3,9 @@ phpunit.xml
vendor
log
var
-Tests/App/cache
-Tests/App/logs
+tests/App/cache
+tests/App/logs
+tests/var
.idea
.phpunit.result.cache
| 0
|
c5e249ba547b3179ca83b09628322273ef364806
|
1up-lab
|
OneupUploaderBundle
|
Added PHPDoc block for ErrorHandlerInterface.
|
commit c5e249ba547b3179ca83b09628322273ef364806
Author: Jim Schmid <[email protected]>
Date: Tue Aug 13 15:41:00 2013 +0200
Added PHPDoc block for ErrorHandlerInterface.
diff --git a/Uploader/ErrorHandler/ErrorHandlerInterface.php b/Uploader/ErrorHandler/ErrorHandlerInterface.php
index 4d59aa3..453de0d 100644
--- a/Uploader/ErrorHandler/ErrorHandlerInterface.php
+++ b/Uploader/ErrorHandler/ErrorHandlerInterface.php
@@ -7,5 +7,13 @@ use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
interface ErrorHandlerInterface
{
+ /**
+ * Adds an exception to a given response
+ *
+ * @param AbstractResponse $response
+ * @param Exception $exception
+ *
+ * @return void
+ */
public function addException(AbstractResponse $response, Exception $exception);
}
| 0
|
130bef29476e69601526ca47adbdc18ad8ee3f6f
|
1up-lab
|
OneupUploaderBundle
|
separated storages both in definition and configuration
|
commit 130bef29476e69601526ca47adbdc18ad8ee3f6f
Author: mitom <[email protected]>
Date: Thu Oct 10 12:27:42 2013 +0200
separated storages both in definition and configuration
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index ab37255..1cf8414 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
+ ->scalarNode('prefix')->defaultValue('chunks')->end()
->end()
->end()
->booleanNode('load_distribution')->defaultTrue()->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 72445fa..6a8bff1 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -32,17 +32,7 @@ class OneupUploaderExtension extends Extension
$loader->load('twig.xml');
}
- if ($this->config['chunks']['storage']['type'] === 'filesystem' &&
- !isset($this->config['chunks']['storage']['directory'])) {
- $this->config['chunks']['storage']['directory'] = sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir'));
- } elseif ($this->config['chunks']['storage']['type'] === 'gaufrette' ) {
- // Force load distribution when using gaufrette chunk storage
- $this->config['chunks']['load_distribution'] = true;
- }
-
- // register the service for the chunk storage
- $this->createStorageService($this->config['chunks']['storage'], 'chunk');
-
+ $this->createChunkStorageService();
$this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ?
sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir')) :
@@ -56,10 +46,6 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach ($this->config['mappings'] as $key => $mapping) {
- if ($key === 'chunk') {
- throw new InvalidArgumentException('"chunk" is a protected mapping name, please use a different one.');
- }
-
$mapping['max_size'] = $mapping['max_size'] < 0 ?
$this->getMaxUploadSize($mapping['max_size']) :
$mapping['max_size']
@@ -114,42 +100,57 @@ class OneupUploaderExtension extends Extension
$container->setParameter('oneup_uploader.controllers', $controllers);
}
- protected function createStorageService($storage, $key, $orphanage = null)
+ protected function createChunkStorageService()
+ {
+ $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['prefix']);
+
+ // 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)
{
$storageService = null;
// if a service is given, return a reference to this service
// this allows a user to overwrite the storage layer if needed
- if (isset($storage['service']) && !is_null($storage['service'])) {
- $storageService = new Reference($storage['storage']['service']);
+ if (!is_null($config['service'])) {
+ $storageService = new Reference($config['storage']['service']);
} else {
// no service was given, so we create one
$storageName = sprintf('oneup_uploader.storage.%s', $key);
+ $storageClass = sprintf('%%oneup_uploader.storage.%s.class%%', $config['type']);
- if ($storage['type'] == 'filesystem') {
- $storage['directory'] = is_null($storage['directory']) ?
+ if ($config['type'] == 'filesystem') {
+ $config['directory'] = is_null($config['directory']) ?
sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
- $this->normalizePath($storage['directory'])
+ $this->normalizePath($config['directory'])
;
$this->container
- ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $storage['type']))
- ->addArgument($storage['directory'])
+ ->register($storageName, $storageClass)
+ ->addArgument($config['directory'])
;
}
- if ($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.');
-
- if(strlen($storage['filesystem']) <= 0)
- throw new ServiceNotFoundException('Empty service name');
-
- $this->container
- ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $storage['type']))
- ->addArgument(new Reference($storage['filesystem']))
- ->addArgument($this->getValueInBytes($storage['sync_buffer_size']))
- ;
+ if ($config['type'] == 'gaufrette') {
+ $this->registerGaufretteStorage($storageName, $storageClass, $config['filesystem'], $config['sync_buffer_size']);
}
$storageService = new Reference($storageName);
@@ -175,6 +176,21 @@ class OneupUploaderExtension extends Extension
return $storageService;
}
+ protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $prefix = '')
+ {
+ if(!class_exists('Gaufrette\\Filesystem'))
+ throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a chunk storage service.');
+
+ if(strlen($filesystem) <= 0)
+ throw new ServiceNotFoundException('Empty service name');
+
+ $this->container
+ ->register($key, $class)
+ ->addArgument(new Reference($filesystem))
+ ->addArgument($this->getValueInBytes($buffer))
+ ->addArgument($prefix)
+ ;
+ }
protected function getMaxUploadSize($input)
{
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 3c95386..66c7e70 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -5,6 +5,8 @@
<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.filesystem.class">Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage</parameter>
<parameter key="oneup_uploader.namer.uniqid.class">Oneup\UploaderBundle\Uploader\Naming\UniqidNamer</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.storage.gaufrette.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
@@ -26,7 +28,7 @@
<!-- managers -->
<service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
- <argument type="service" id="oneup_uploader.storage.chunk" />
+ <argument type="service" id="oneup_uploader.chunks_storage" />
</service>
<service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%">
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 39bd2d2..49050c0 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -2,11 +2,8 @@
namespace Oneup\UploaderBundle\Uploader\Chunk;
-use Oneup\UploaderBundle\Uploader\Storage\ChunkStorageInterface;
-use Symfony\Component\HttpFoundation\File\File;
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\ChunkStorageInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Filesystem\Filesystem;
use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php
index 99ad60c..c89d9bf 100644
--- a/Uploader/Chunk/ChunkManagerInterface.php
+++ b/Uploader/Chunk/ChunkManagerInterface.php
@@ -21,9 +21,9 @@ interface ChunkManagerInterface
/**
* Assembles the given chunks and return the resulting file.
*
- * @param $chunks
- * @param bool $removeChunk Remove the chunk file once its assembled.
- * @param bool $renameChunk Rename the chunk file once its assembled.
+ * @param $chunks
+ * @param bool $removeChunk Remove the chunk file once its assembled.
+ * @param bool $renameChunk Rename the chunk file once its assembled.
*
* @return File
*/
diff --git a/Uploader/Storage/ChunkStorageInterface.php b/Uploader/Chunk/Storage/ChunkStorageInterface.php
similarity index 86%
rename from Uploader/Storage/ChunkStorageInterface.php
rename to Uploader/Chunk/Storage/ChunkStorageInterface.php
index b9fa1f6..2be1146 100644
--- a/Uploader/Storage/ChunkStorageInterface.php
+++ b/Uploader/Chunk/Storage/ChunkStorageInterface.php
@@ -1,7 +1,6 @@
<?php
-namespace Oneup\UploaderBundle\Uploader\Storage;
-
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -16,4 +15,4 @@ interface ChunkStorageInterface
public function cleanup($path);
public function getChunks($uuid);
-}
\ No newline at end of file
+}
diff --git a/Uploader/Chunk/Storage/FilesystemStorage.php b/Uploader/Chunk/Storage/FilesystemStorage.php
new file mode 100644
index 0000000..8855188
--- /dev/null
+++ b/Uploader/Chunk/Storage/FilesystemStorage.php
@@ -0,0 +1,123 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
+
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\HttpFoundation\File\File;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FilesystemStorage implements ChunkStorageInterface
+{
+ protected $directory;
+
+ public function __construct($directory)
+ {
+ $this->directory = $directory;
+ }
+
+ public function clear($maxAge)
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ try {
+ $finder->in($this->directory)->date('<=' . -1 * (int) $maxAge . 'seconds')->files();
+ } catch (\InvalidArgumentException $e) {
+ // the finder will throw an exception of type InvalidArgumentException
+ // if the directory he should search in does not exist
+ // in that case we don't have anything to clean
+ return;
+ }
+
+ foreach ($finder as $file) {
+ $system->remove($file);
+ }
+ }
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $filesystem = new Filesystem();
+ $path = sprintf('%s/%s', $this->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->directory, $uuid));
+
+ return $chunk->move($path, $name);
+ }
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk)
+ {
+ if (!($chunks instanceof \IteratorAggregate)) {
+ throw new \InvalidArgumentException('The first argument must implement \IteratorAggregate interface.');
+ }
+
+ $iterator = $chunks->getIterator()->getInnerIterator();
+
+ $base = $iterator->current();
+ $iterator->next();
+
+ while ($iterator->valid()) {
+
+ $file = $iterator->current();
+
+ if (false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX)) {
+ throw new \RuntimeException('Reassembling chunks failed.');
+ }
+
+ if ($removeChunk) {
+ $filesystem = new Filesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
+ $iterator->next();
+ }
+
+ $name = $base->getBasename();
+
+ if ($renameChunk) {
+ // remove the prefix added by self::addChunk
+ $name = preg_replace('/^(\d+)_/', '', $base->getBasename());
+ }
+
+ $assembled = new File($base->getRealPath());
+ $assembled = $assembled->move($base->getPath(), $name);
+
+ // the file is only renamed before it is uploaded
+ if ($renameChunk) {
+ // create an file to meet interface restrictions
+ $assembled = new FilesystemFile(new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, $assembled->getSize(), null, true));
+ }
+
+ return $assembled;
+ }
+
+ public function cleanup($path)
+ {
+ // cleanup
+ $filesystem = new Filesystem();
+ $filesystem->remove($path);
+
+ return true;
+ }
+
+ public function getChunks($uuid)
+ {
+ $finder = new Finder();
+ $finder
+ ->in(sprintf('%s/%s', $this->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;
+ }
+}
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
new file mode 100644
index 0000000..00b0031
--- /dev/null
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -0,0 +1,143 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
+
+use Gaufrette\Adapter\StreamFactory;
+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;
+
+class GaufretteStorage extends StreamManager implements ChunkStorageInterface
+{
+ protected $unhandledChunk;
+ protected $prefix;
+
+ public function __construct(Filesystem $filesystem, $bufferSize, $prefix)
+ {
+ if (!($filesystem->getAdapter() instanceof StreamFactory)) {
+ throw new \InvalidArgumentException('The filesystem used as chunk storage must implement StreamFactory');
+ }
+ $this->filesystem = $filesystem;
+ $this->bufferSize = $bufferSize;
+ $this->prefix = $prefix;
+ }
+
+ public function clear($maxAge)
+ {
+ $matches = $this->filesystem->listKeys($this->prefix);
+
+ $limit = time()+$maxAge;
+ $toDelete = array();
+
+ // Collect the directories that are old,
+ // this also means the files inside are old
+ // but after the files are deleted the dirs
+ // would remain
+ foreach ($matches['dirs'] as $key) {
+ if ($limit < $this->filesystem->mtime($key)) {
+ $toDelete[] = $key;
+ }
+ }
+ // The same directory is returned for every file it contains
+ array_unique($toDelete);
+ foreach ($matches['keys'] as $key) {
+ if ($limit < $this->filesystem->mtime($key)) {
+ $this->filesystem->delete($key);
+ }
+ }
+
+ foreach ($toDelete as $key) {
+ // The filesystem will throw exceptions if
+ // a directory is not empty
+ try {
+ $this->filesystem->delete($key);
+ } catch (\Exception $e) {
+ //do nothing
+ }
+ }
+ }
+
+ /**
+ * Only saves the information about the chunk to avoid moving it
+ * forth-and-back to reassemble it. Load distribution is enforced
+ * for gaufrette based chunk storage therefore assembleChunks will
+ * be called in the same request.
+ *
+ * @param $uuid
+ * @param $index
+ * @param UploadedFile $chunk
+ * @param $original
+ */
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $this->unhandledChunk = array(
+ 'uuid' => $uuid,
+ 'index' => $index,
+ 'chunk' => $chunk,
+ 'original' => $original
+ );
+
+ return;
+ }
+
+ 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;
+ $this->ensureRemotePathExists($path.$target);
+ } else {
+ /*
+ * The array only contains items with matching prefix until the filename
+ * therefore the order will be decided depending on the filename
+ * It is only case-insensitive to be overly-careful.
+ */
+ sort($chunks, SORT_STRING | SORT_FLAG_CASE);
+ $target = pathinfo($chunks[0], PATHINFO_BASENAME);
+ }
+
+ $dst = $this->filesystem->createStream($path.$target);
+ if ($this->unhandledChunk['index'] === 0) {
+ // if it's the first chunk overwrite the already existing part
+ // to avoid appending to earlier failed uploads
+ $this->openStream($dst, 'w');
+ } else {
+ $this->openStream($dst, 'a');
+ }
+
+
+ // Meet the interface requirements
+ $uploadedFile = new FilesystemFile($this->unhandledChunk['chunk']);
+
+ $this->stream($uploadedFile, $dst);
+
+ if ($renameChunk) {
+ $name = preg_replace('/^(\d+)_/', '', $target);
+ $this->filesystem->rename($path.$target, $path.$name);
+ $target = $name;
+ }
+ $uploaded = $this->filesystem->get($path.$target);
+
+ if (!$renameChunk) {
+ return $uploaded;
+ }
+
+ return new GaufretteFile($uploaded, $this->filesystem);
+ }
+
+ public function cleanup($path)
+ {
+ $this->filesystem->delete($path);
+ }
+
+ public function getChunks($uuid)
+ {
+ return $this->filesystem->listKeys($this->prefix.'/'.$uuid)['keys'];
+ }
+}
diff --git a/Uploader/File/FileInterface.php b/Uploader/File/FileInterface.php
index 47e4266..511169d 100644
--- a/Uploader/File/FileInterface.php
+++ b/Uploader/File/FileInterface.php
@@ -21,10 +21,17 @@ interface FileInterface
public function getSize();
/**
- * Returns the directory of the file without the filename
+ * Returns the path of the file
*
* @return string
*/
+ public function getPathname();
+
+ /**
+ * Return the path of the file without the filename
+ *
+ * @return mixed
+ */
public function getPath();
/**
@@ -35,11 +42,11 @@ interface FileInterface
public function getMimeType();
/**
- * Returns the filename of the file
+ * Returns the basename of the file
*
* @return string
*/
- public function getName();
+ public function getBasename();
/**
* Returns the guessed extension of the file
@@ -47,4 +54,4 @@ interface FileInterface
* @return mixed
*/
public function getExtension();
-}
\ No newline at end of file
+}
diff --git a/Uploader/File/FilesystemFile.php b/Uploader/File/FilesystemFile.php
index eed8d67..f30d028 100644
--- a/Uploader/File/FilesystemFile.php
+++ b/Uploader/File/FilesystemFile.php
@@ -10,6 +10,6 @@ class FilesystemFile extends UploadedFile implements FileInterface
public function __construct(UploadedFile $file)
{
$this->file = $file;
- parent::__construct($file->getPath(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
+ parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
}
-}
\ No newline at end of file
+}
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index 7771c4a..fd0701a 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -9,7 +9,8 @@ class GaufretteFile extends File implements FileInterface
{
protected $filesystem;
- public function __construct(File $file, Filesystem $filesystem) {
+ public function __construct(File $file, Filesystem $filesystem)
+ {
parent::__construct($file->getKey(), $filesystem);
$this->filesystem = $filesystem;
}
@@ -30,12 +31,17 @@ class GaufretteFile extends File implements FileInterface
return parent::getSize();
}
+ public function getPathname()
+ {
+ return $this->getKey();
+ }
+
public function getPath()
{
return pathinfo($this->getKey(), PATHINFO_DIRNAME);
}
- public function getName()
+ public function getBasename()
{
return pathinfo($this->getKey(), PATHINFO_BASENAME);
}
@@ -46,6 +52,7 @@ class GaufretteFile extends File implements FileInterface
public function getMimeType()
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
+
return finfo_file($finfo, $this->getKey());
}
@@ -59,4 +66,4 @@ class GaufretteFile extends File implements FileInterface
return $this->filesystem;
}
-}
\ No newline at end of file
+}
diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php
new file mode 100644
index 0000000..3ae16c5
--- /dev/null
+++ b/Uploader/Gaufrette/StreamManager.php
@@ -0,0 +1,59 @@
+<?php
+namespace Oneup\UploaderBundle\Uploader\Gaufrette;
+
+use Gaufrette\Stream;
+use Gaufrette\StreamMode;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Gaufrette\Stream\Local as LocalStream;
+use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
+
+class StreamManager
+{
+ protected $filesystem;
+ protected $buffersize;
+
+ protected function createSourceStream(FileInterface $file)
+ {
+ if ($file instanceof GaufretteFile) {
+ // The file is always streamable as the chunk storage only allows
+ // adapters that implement StreamFactory
+ return $file->createStream();
+ }
+
+ return new LocalStream($file->getPathname());
+ }
+
+ 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))
+ $this->filesystem->write($path, '', true);
+ }
+
+ protected function openStream(Stream $stream, $mode)
+ {
+ // always use binary mode
+ $mode = $mode.'b+';
+
+ return $stream->open(new StreamMode($mode));
+ }
+
+ protected function stream(FileInterface $file, Stream $dst)
+ {
+ $src = $this->createSourceStream($file);
+
+ // always use reading only for the source
+ $this->openStream($src, 'r');
+
+ while (!$src->eof()) {
+ $data = $src->read($this->bufferSize);
+ $dst->write($data);
+ }
+
+ $dst->close();
+ $src->close();
+ }
+
+}
diff --git a/Uploader/Naming/NamerInterface.php b/Uploader/Naming/NamerInterface.php
index 173e0b8..fabd017 100644
--- a/Uploader/Naming/NamerInterface.php
+++ b/Uploader/Naming/NamerInterface.php
@@ -2,7 +2,6 @@
namespace Oneup\UploaderBundle\Uploader\Naming;
-
use Oneup\UploaderBundle\Uploader\File\FileInterface;
interface NamerInterface
diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php
index 80bc741..34a7141 100644
--- a/Uploader/Naming/UniqidNamer.php
+++ b/Uploader/Naming/UniqidNamer.php
@@ -2,7 +2,6 @@
namespace Oneup\UploaderBundle\Uploader\Naming;
-
use Oneup\UploaderBundle\Uploader\File\FileInterface;
class UniqidNamer implements NamerInterface
diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php
index d443f3c..c6c9001 100644
--- a/Uploader/Storage/FilesystemStorage.php
+++ b/Uploader/Storage/FilesystemStorage.php
@@ -3,14 +3,9 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
-use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\File;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-
-class FilesystemStorage implements StorageInterface,ChunkStorageInterface
+class FilesystemStorage implements StorageInterface
{
protected $directory;
@@ -37,107 +32,4 @@ class FilesystemStorage implements StorageInterface,ChunkStorageInterface
return $file;
}
-
- public function clear($maxAge)
- {
- $system = new Filesystem();
- $finder = new Finder();
-
- try {
- $finder->in($this->directory)->date('<=' . -1 * (int) $maxAge . 'seconds')->files();
- } catch (\InvalidArgumentException $e) {
- // the finder will throw an exception of type InvalidArgumentException
- // if the directory he should search in does not exist
- // in that case we don't have anything to clean
- return;
- }
-
- foreach ($finder as $file) {
- $system->remove($file);
- }
- }
-
- public function addChunk($uuid, $index, UploadedFile $chunk, $original)
- {
- $filesystem = new Filesystem();
- $path = sprintf('%s/%s', $this->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->directory, $uuid));
-
- return $chunk->move($path, $name);
- }
-
- public function assembleChunks($chunks, $removeChunk, $renameChunk)
- {
- if (!($chunks instanceof \IteratorAggregate)) {
- throw new \InvalidArgumentException('The first argument must implement \IteratorAggregate interface.');
- }
-
- $iterator = $chunks->getIterator()->getInnerIterator();
-
- $base = $iterator->current();
- $iterator->next();
-
- while ($iterator->valid()) {
-
- $file = $iterator->current();
-
- if (false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX)) {
- throw new \RuntimeException('Reassembling chunks failed.');
- }
-
- if ($removeChunk) {
- $filesystem = new Filesystem();
- $filesystem->remove($file->getPathname());
- }
-
- $iterator->next();
- }
-
- $name = $base->getBasename();
-
- if ($renameChunk) {
- // remove the prefix added by self::addChunk
- $name = preg_replace('/^(\d+)_/', '', $base->getBasename());
- }
-
- $assembled = new File($base->getRealPath());
- $assembled = $assembled->move($base->getPath(), $name);
-
- // the file is only renamed before it is uploaded
- if ($renameChunk) {
- // create an file to meet interface restrictions
- $assembled = new FilesystemFile(new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, $assembled->getSize(), null, true));
- }
-
- return $assembled;
- }
-
- public function cleanup($path)
- {
- // cleanup
- $filesystem = new Filesystem();
- $filesystem->remove($path);
-
- return true;
- }
-
- public function getChunks($uuid)
- {
- $finder = new Finder();
- $finder
- ->in(sprintf('%s/%s', $this->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;
- }
}
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 6c82693..35d46b7 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -4,19 +4,12 @@ namespace Oneup\UploaderBundle\Uploader\Storage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
-use Gaufrette\Stream\Local as LocalStream;
-use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
use Gaufrette\Adapter\MetadataSupporter;
+use Oneup\UploaderBundle\Uploader\Gaufrette\StreamManager;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-
-class GaufretteStorage implements StorageInterface, ChunkStorageInterface
+class GaufretteStorage extends StreamManager implements StorageInterface
{
- protected $filesystem;
- protected $bufferSize;
- protected $unhandledChunk;
- protected $chunkPrefix = 'chunks';
public function __construct(Filesystem $filesystem, $bufferSize)
{
@@ -36,138 +29,17 @@ class GaufretteStorage implements StorageInterface, ChunkStorageInterface
}
}
- $this->stream($file, $path, $name);
-
- return $this->filesystem->get($path);
- }
-
- public function clear($maxAge)
- {
- $matches = $this->filesystem->listKeys($this->chunkPrefix);
-
- $limit = time()+$maxAge;
- $toDelete = array();
-
- // Collect the directories that are old,
- // this also means the files inside are old
- // but after the files are deleted the dirs
- // would remain
- foreach ($matches['dirs'] as $key) {
- if ($limit < $this->filesystem->mtime($key)) {
- $toDelete[] = $key;
- }
- }
- // The same directory is returned for every file it contains
- array_unique($toDelete);
- foreach ($matches['keys'] as $key) {
- if ($limit < $this->filesystem->mtime($key)) {
- $this->filesystem->delete($key);
- }
- }
-
- foreach($toDelete as $key) {
- // The filesystem will throw exceptions if
- // a directory is not empty
- try {
- $this->filesystem->delete($key);
- } catch (\Exception $e) {
- //do nothing
- }
- }
- }
-
- /**
- * Only saves the information about the chunk to avoid moving it
- * forth-and-back to reassemble it. Load distribution is enforced
- * for gaufrette based chunk storage therefore assembleChunks will
- * be called in the same request.
- *
- * @param $uuid
- * @param $index
- * @param UploadedFile $chunk
- * @param $original
- */
- public function addChunk($uuid, $index, UploadedFile $chunk, $original)
- {
- $this->unhandledChunk = array(
- 'uuid' => $uuid,
- 'index' => $index,
- 'chunk' => $chunk,
- 'original' => $original
- );
- return;
- }
-
- public function assembleChunks($chunks, $removeChunk, $renameChunk)
- {
- // the index is only added to be in sync with the filesystem storage
- $path = $this->chunkPrefix.'/'.$this->unhandledChunk['uuid'].'/';
- $filename = $this->unhandledChunk['index'].'_'.$this->unhandledChunk['original'];
-
- if (empty($chunks)) {
- $target = $filename;
- } else {
- /*
- * The array only contains items with matching prefix until the filename
- * therefore the order will be decided depending on the filename
- * It is only case-insensitive to be overly-careful.
- */
- sort($chunks, SORT_STRING | SORT_FLAG_CASE);
- $target = pathinfo($chunks[0], PATHINFO_BASENAME);
- }
-
- $this->stream($this->unhandledChunk['chunk'], $path, $target);
-
- if ($renameChunk) {
- $name = preg_replace('/^(\d+)_/', '', $target);
- $this->filesystem->rename($path.$target, $path.$name);
- $target = $name;
- }
- $uploaded = $this->filesystem->get($path.$target);
-
- if (!$renameChunk) {
- return $uploaded;
- }
-
- return new GaufretteFile($uploaded, $this->filesystem);
- }
-
- public function cleanup($path)
- {
- $this->filesystem->delete($path);
- }
-
- public function getChunks($uuid)
- {
- return $this->filesystem->listKeys($this->chunkPrefix.'/'.$uuid)['keys'];
- }
-
- protected function stream($file, $path, $name)
- {
if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
$this->filesystem->getAdapter()->setMetadata($name, array('contentType' => $file->getMimeType()));
}
-
- $path = $path.$name;
- // this is a somehow ugly workaround introduced
- // because the stream-mode is not able to create
- // subdirectories.
- if(!$this->filesystem->has($path))
- $this->filesystem->write($path, '', true);
-
- $src = new LocalStream($file->getPathname());
+ $this->ensureRemotePathExists($path.$name);
$dst = $this->filesystem->createStream($path);
- $src->open(new StreamMode('rb+'));
- $dst->open(new StreamMode('ab+'));
+ $this->openStream($dst, 'w');
- while (!$src->eof()) {
- $data = $src->read($this->bufferSize);
- $dst->write($data);
- }
+ $this->stream($file, $dst);
- $dst->close();
- $src->close();
+ return $this->filesystem->get($path);
}
}
| 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
|
eac95c5cce541aa95cf549ea8d8e3be0009a9e58
|
1up-lab
|
OneupUploaderBundle
|
Update configuration_reference.md
|
commit eac95c5cce541aa95cf549ea8d8e3be0009a9e58
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 09:42:14 2013 +0300
Update configuration_reference.md
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index 18a156e..65cf43c 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -1,7 +1,7 @@
Configuration Reference
=======================
-All available configuration options are listed below with their default values.
+All available configuration options along with their default values are listed below.
``` yaml
oneup_uploader:
@@ -25,4 +25,4 @@ oneup_uploader:
max_size: 9223372036854775807
use_orphanage: false
namer: oneup_uploader.namer.uniqid
-```
\ No newline at end of file
+```
| 0
|
d2652914296766d29f7ecff02058f4777a708b74
|
1up-lab
|
OneupUploaderBundle
|
Use 1.0 version of this bundle.
|
commit d2652914296766d29f7ecff02058f4777a708b74
Author: Jim Schmid <[email protected]>
Date: Wed Oct 23 15:17:17 2013 +0200
Use 1.0 version of this bundle.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 430fc08..bf97ce0 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -34,7 +34,7 @@ Add OneupUploaderBundle to your composer.json using the following construct:
```js
{
"require": {
- "oneup/uploader-bundle": "0.9.*@dev"
+ "oneup/uploader-bundle": "1.0.*@dev"
}
}
```
@@ -71,7 +71,8 @@ This bundle was designed to just work out of the box. The only thing you have to
oneup_uploader:
mappings:
- gallery: ~
+ gallery:
+ frontend: blueimp # or any uploader you use in the frontend
```
To enable the dynamic routes, add the following to your routing configuration file.
| 0
|
a6df30d55b6c8c2672d29d638e5913edfe4a1f4e
|
1up-lab
|
OneupUploaderBundle
|
Refactored validation system to use the EventDispatcher.
|
commit a6df30d55b6c8c2672d29d638e5913edfe4a1f4e
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 18:49:24 2013 +0200
Refactored validation system to use the EventDispatcher.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index ac8a1f0..23fb699 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -11,6 +11,7 @@ use Symfony\Component\HttpFoundation\Request;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
@@ -66,21 +67,17 @@ abstract class AbstractController
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');
+ $dispatcher = $this->container->get('event_dispatcher');
+ $event = new ValidationEvent($file, $this->config, $this->type);
+ try
+ {
+ $dispatcher->dispatch(UploadEvents::VALIDATION, $event);
+ }
+ catch(ValidationException $exception)
+ {
+ // pass the exception one level up
+ throw new UploadException($exception->getMessage());
+ }
}
}
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
new file mode 100644
index 0000000..5fd4d98
--- /dev/null
+++ b/Event/ValidationEvent.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Oneup\UploaderBundle\Event;
+
+use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class ValidationEvent extends Event
+{
+ protected $file;
+ protected $config;
+
+ public function __construct(UploadedFile $file, array $config, $type)
+ {
+ $this->file = $file;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ public function getFile()
+ {
+ return $this->file;
+ }
+
+ public function getConfig()
+ {
+ return $this->config;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+}
diff --git a/UploadEvents.php b/UploadEvents.php
index 34e287c..8bec67f 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -6,4 +6,5 @@ final class UploadEvents
{
const POST_PERSIST = 'oneup_uploader.post_persist';
const POST_UPLOAD = 'oneup_uploader.post_upload';
+ const VALIDATION = 'oneup_uploader.validate';
}
\ No newline at end of file
| 0
|
09f78d50e30bc70221010f84d36a8bfd00da8b4d
|
1up-lab
|
OneupUploaderBundle
|
Removed DeletableListener as it is not used anymore.
|
commit 09f78d50e30bc70221010f84d36a8bfd00da8b4d
Author: Jim Schmid <[email protected]>
Date: Wed Mar 27 17:54:58 2013 +0100
Removed DeletableListener as it is not used anymore.
diff --git a/EventListener/DeletableListener.php b/EventListener/DeletableListener.php
deleted file mode 100644
index 38c752b..0000000
--- a/EventListener/DeletableListener.php
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\EventListener;
-
-use Symfony\Component\HttpFoundation\Session\SessionInterface;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
-use Oneup\UploaderBundle\Event\PostUploadEvent;
-use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Uploader\Deletable\DeletableManagerInterface;
-
-class DeletableListener implements EventSubscriberInterface
-{
- protected $manager;
-
- public function __construct(DeletableManagerInterface $manager)
- {
- $this->manager = $manager;
- }
-
- public function register(PostUploadEvent $event)
- {
- $options = $event->getOptions();
- $request = $event->getRequest();
- $file = $event->getFile();
- $type = $event->getType();
-
- if(!array_key_exists('deletable', $options) || !$options['deletable'])
- return;
-
- if(!array_key_exists('file_name', $options))
- return;
-
- $uuid = $request->get('qquuid');
-
- $this->manager->addFile($type, $uuid, $options['file_name']);
- }
-
- public static function getSubscribedEvents()
- {
- return array(
- UploadEvents::POST_UPLOAD => 'register',
- );
- }
-}
| 0
|
5baa9266d9e063bc2ee2b92d3d7ab5761559f188
|
1up-lab
|
OneupUploaderBundle
|
Added validator to validate disallowed extensions.
|
commit 5baa9266d9e063bc2ee2b92d3d7ab5761559f188
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 19:36:05 2013 +0200
Added validator to validate disallowed extensions.
diff --git a/EventListener/DisallowedExtensionValidationListener.php b/EventListener/DisallowedExtensionValidationListener.php
new file mode 100644
index 0000000..26a5f3a
--- /dev/null
+++ b/EventListener/DisallowedExtensionValidationListener.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class DisallowedExtensionValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+
+ if(count($config['disallowed_extensions']) > 0 && in_array($extension, $config['disallowed_extensions'])) {
+ throw new ValidationException('error.blacklist');
+ }
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml
index a272a48..3daeb90 100644
--- a/Resources/config/validation.xml
+++ b/Resources/config/validation.xml
@@ -6,11 +6,24 @@
<services>
- <service id="oneup_uploader.validation_listener.max_size" class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener">
+ <service
+ id="oneup_uploader.validation_listener.max_size"
+ class="Oneup\UploaderBundle\EventListener\MaxSizeValidationListener"
+ >
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
- <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener">
+ <service
+ id="oneup_uploader.validation_listener.allowed_extension"
+ class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener"
+ >
+ <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
+ </service>
+
+ <service
+ id="oneup_uploader.validation_listener.disallowed_extension"
+ class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener"
+ >
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
| 0
|
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
|
c0d9cce3e2c5b2ecb6253d719d8471049451ae2b
|
1up-lab
|
OneupUploaderBundle
|
Added documentation headers to ChunkManagerInterface.
|
commit c0d9cce3e2c5b2ecb6253d719d8471049451ae2b
Author: Jim Schmid <[email protected]>
Date: Tue Aug 13 09:36:44 2013 +0200
Added documentation headers to ChunkManagerInterface.
diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php
index 1ba2c15..0991a3e 100644
--- a/Uploader/Chunk/ChunkManagerInterface.php
+++ b/Uploader/Chunk/ChunkManagerInterface.php
@@ -6,9 +6,50 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
interface ChunkManagerInterface
{
- public function clear();
+ /**
+ * Adds a new Chunk to a given uuid.
+ *
+ * @param string $uuid
+ * @param int $index
+ * @param UploadedFile $chunk
+ * @param string $original The file name of the original file
+ *
+ * @return File The moved chunk file.
+ */
public function addChunk($uuid, $index, UploadedFile $chunk, $original);
+
+ /**
+ * Assembles the given chunks and return the resulting file.
+ *
+ * @param \IteratorAggregate $chunks
+ * @param bool $removeChunk Remove the chunk file once its assembled.
+ * @param bool $renameChunk Rename the chunk file once its assembled.
+ *
+ * @return File
+ */
public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false);
- public function cleanup($path);
+
+ /**
+ * Get chunks associated with the given uuid.
+ *
+ * @param string $uuid
+ *
+ * @return Finder A finder instance
+ */
public function getChunks($uuid);
+
+ /**
+ * Clean a given path.
+ *
+ * @param string $path
+ * @return bool
+ */
+ public function cleanup($path);
+
+ /**
+ * Clears the chunk manager directory. Remove all files older than the configured maxage.
+ *
+ * @return void
+ */
+ public function clear();
}
| 0
|
36de4a72e1cbb4e29d11b2046becdea5664a9ea9
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #165 from Gladhon/master
Add Errorhandling to Dropzone
|
commit 36de4a72e1cbb4e29d11b2046becdea5664a9ea9
Merge: 98a3430 1fd15f7
Author: Jim Schmid <[email protected]>
Date: Fri Feb 20 18:20:39 2015 +0100
Merge pull request #165 from Gladhon/master
Add Errorhandling to Dropzone
| 0
|
fa28731786627e4378a205e6c2a265c404e19204
|
1up-lab
|
OneupUploaderBundle
|
Update bundle configuration for Symfony 4.2 change, see https://github.com/symfony/symfony/blob/master/UPGRADE-4.2.md#config)
|
commit fa28731786627e4378a205e6c2a265c404e19204
Author: David Greminger <[email protected]>
Date: Mon Dec 3 09:32:12 2018 +0100
Update bundle configuration for Symfony 4.2 change, see https://github.com/symfony/symfony/blob/master/UPGRADE-4.2.md#config)
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index cf88563..cb39ca1 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -9,8 +9,14 @@ class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
- $treeBuilder = new TreeBuilder();
- $rootNode = $treeBuilder->root('oneup_uploader');
+ $treeBuilder = new TreeBuilder('oneup_uploader');
+
+ if (method_exists($treeBuilder, 'getRootNode')) {
+ $rootNode = $treeBuilder->getRootNode();
+ } else {
+ // BC layer for symfony/config 4.1 and older
+ $rootNode = $treeBuilder->root('oneup_uploader');
+ }
$rootNode
->children()
| 0
|
52303cf5d4387b7f320ffb6fd46a0687a51d98ee
|
1up-lab
|
OneupUploaderBundle
|
Fix unnamed directory when uploading to Amazon S3
|
commit 52303cf5d4387b7f320ffb6fd46a0687a51d98ee
Author: Diego Lázaro <[email protected]>
Date: Sat Apr 16 18:38:05 2016 +0200
Fix unnamed directory when uploading to Amazon S3
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;
| 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
|
05823b4693d9b9d2aae630a2b01f3cc6806e231a
|
1up-lab
|
OneupUploaderBundle
|
Added first chunked upload test for Plupload.
|
commit 05823b4693d9b9d2aae630a2b01f3cc6806e231a
Author: Jim Schmid <[email protected]>
Date: Mon May 6 23:20:01 2013 +0200
Added first chunked upload test for Plupload.
diff --git a/Tests/Controller/AbstractChunkedControllerTest.php b/Tests/Controller/AbstractChunkedControllerTest.php
new file mode 100644
index 0000000..61ea9c8
--- /dev/null
+++ b/Tests/Controller/AbstractChunkedControllerTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+abstract class AbstractChunkedControllerTest extends AbstractControllerTest
+{
+ protected $total = 6;
+
+ abstract protected function getNextRequestParameters($i);
+ abstract protected function getNextFile($i);
+
+ public function testChunkedUpload()
+ {
+ // assemble a request
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+
+ for($i = 0; $i < $this->total; $i ++) {
+ $client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($this->getNextFile($i)));
+ $response = $client->getResponse();
+
+ $this->assertTrue($response->isSuccessful());
+ $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
+ }
+
+ foreach($this->getUploadedFiles() as $file) {
+ $this->assertTrue($file->isFile());
+ $this->assertTrue($file->isReadable());
+ $this->assertEquals(120, $file->getSize());
+ }
+ }
+}
diff --git a/Tests/Controller/PluploadTest.php b/Tests/Controller/PluploadTest.php
index 216886f..1cb80a8 100644
--- a/Tests/Controller/PluploadTest.php
+++ b/Tests/Controller/PluploadTest.php
@@ -39,10 +39,10 @@ class PluploadTest extends AbstractChunkedControllerTest
protected function getNextFile($i)
{
return new UploadedFile(
- $this->createTempFile(21),
+ $this->createTempFile(20),
'cat.txt',
'text/plain',
- 21
+ 20
);
}
}
| 0
|
64f970e45a8677a376b9e38ce63e1402469320d6
|
1up-lab
|
OneupUploaderBundle
|
Semantical typo fix (#315)
|
commit 64f970e45a8677a376b9e38ce63e1402469320d6
Author: Łukasz Chruściel <[email protected]>
Date: Wed Jan 31 07:08:41 2018 +0100
Semantical typo fix (#315)
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 55d57a0..1a12021 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -139,9 +139,9 @@ abstract class AbstractController
$dispatcher = $this->container->get('event_dispatcher');
// dispatch pre upload event (both the specific and the general)
- $postUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config);
- $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $postUploadEvent);
- $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $this->type), $postUploadEvent);
+ $preUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config);
+ $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $preUploadEvent);
+ $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $this->type), $preUploadEvent);
}
/**
| 0
|
3b43437a8c49a023ae702f6544a408bef25fd7bc
|
1up-lab
|
OneupUploaderBundle
|
Fixed wrong event name for persist
|
commit 3b43437a8c49a023ae702f6544a408bef25fd7bc
Author: Jacek Jędrzejewski <[email protected]>
Date: Mon Jun 17 17:54:26 2013 +0300
Fixed wrong event name for persist
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);
}
}
| 0
|
d161b18bf148228c70d730d40def3125f667a94b
|
1up-lab
|
OneupUploaderBundle
|
Testing existance of moved files as well as clean up afterwards.
|
commit d161b18bf148228c70d730d40def3125f667a94b
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:07:58 2013 +0200
Testing existance of moved files as well as clean up afterwards.
diff --git a/Tests/Controller/ControllerTest.php b/Tests/Controller/ControllerTest.php
index 567d066..bf433f9 100644
--- a/Tests/Controller/ControllerTest.php
+++ b/Tests/Controller/ControllerTest.php
@@ -2,6 +2,8 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
@@ -35,10 +37,20 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
);
$controller = new UploaderController($container, $storage, $config, 'cat');
- $controller->upload();
+ $response = $controller->upload();
// check if original file has been moved
$this->assertFalse(file_exists($this->tempFile));
+
+ // testing response
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
+ $this->assertEquals(200, $response->getStatusCode());
+
+ // check if file is present
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/uploader')->files();
+
+ $this->assertCount(1, $finder);
}
protected function getContainerMock()
@@ -98,4 +110,11 @@ class ControllerTest extends \PHPUnit_Framework_TestCase
{
return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
}
+
+ public function tearDown()
+ {
+ // remove all files in tmp folder
+ $filesystem = new Filesystem();
+ $filesystem->remove(sys_get_temp_dir() . '/uploader');
+ }
}
\ No newline at end of file
| 0
|
5d7b5b155782f157cdaf7cd1473bf5c4e72a9837
|
1up-lab
|
OneupUploaderBundle
|
Meh, last commit wasn't the rest. But no, I won't amend. :)
|
commit 5d7b5b155782f157cdaf7cd1473bf5c4e72a9837
Author: Jim Schmid <[email protected]>
Date: Wed Mar 27 18:21:31 2013 +0100
Meh, last commit wasn't the rest. But no, I won't amend. :)
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index c4b8570..10ffce6 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -82,8 +82,7 @@ class UploaderController implements UploadControllerInterface
$postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array(
'use_orphanage' => $this->config['use_orphanage'],
- 'file_name' => $name,
- 'deletable' => $this->config['deletable'],
+ 'file_name' => $name
));
$this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 726e84d..3ccc0a0 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -38,21 +38,7 @@ class RouteLoader extends Loader
array('_method' => 'POST')
);
- $delete = new Route(
- sprintf('/_uploader/%s/delete/{uuid}', $type),
- array('_controller' => $service . ':delete', '_format' => 'json'),
- array('_method' => 'DELETE', 'uuid' => '[A-z0-9-]*')
- );
-
- $base = new Route(
- sprintf('/_uploader/%s/delete', $type),
- array('_controller' => $service . ':delete', '_format' => 'json'),
- array('_method' => 'DELETE')
- );
-
$routes->add(sprintf('_uploader_%s_upload', $type), $upload);
- $routes->add(sprintf('_uploader_%s_delete', $type), $delete);
- $routes->add(sprintf('_uploader_%s_delete_base', $type), $base);
}
return $routes;
diff --git a/UploadEvents.php b/UploadEvents.php
index f272c9d..6a9967b 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -6,5 +6,4 @@ final class UploadEvents
{
const POST_PERSIST = 'oneup.uploader.post.persist';
const POST_UPLOAD = 'oneup.uploader.post.upload';
- const POST_DELETE = 'oneup.uploader.post.delete';
}
\ No newline at end of file
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 38eb9c8..74a63df 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -7,5 +7,4 @@ use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
{
public function upload(File $file, $name);
- public function remove($type, $uuid);
}
\ No newline at end of file
| 0
|
dac856885ff3c980f82c7e3cd70e4cd755f39fe7
|
1up-lab
|
OneupUploaderBundle
|
Removed warning in Readme.
|
commit dac856885ff3c980f82c7e3cd70e4cd755f39fe7
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 18:08:09 2013 +0200
Removed warning in Readme.
diff --git a/README.md b/README.md
index cfdfbdb..0df2f93 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,3 @@
-***
-
-**Warning**: There is currently a pretty serious issue reported. Until further notice,
-consider chunked uploads as *not-working*. It is highly recommended to switch from chunked
-uploads to non-chunked uploads until this issue is fixed again. You can find more
-information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21).
-
-***
-
-
OneupUploaderBundle
===================
| 0
|
abb29a42947ea431d0c9b5f3c9092dbe334bd594
|
1up-lab
|
OneupUploaderBundle
|
Added new config option to the configuration reference.
|
commit abb29a42947ea431d0c9b5f3c9092dbe334bd594
Author: Jim Schmid <[email protected]>
Date: Wed Mar 5 07:27:06 2014 +0100
Added new config option to the configuration reference.
diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md
index dcc5a20..6b0d248 100644
--- a/Resources/doc/configuration_reference.md
+++ b/Resources/doc/configuration_reference.md
@@ -34,6 +34,7 @@ oneup_uploader:
directory: ~
stream_wrapper: ~
sync_buffer_size: 100K
+ route_prefix:
allowed_mimetypes: []
disallowed_mimetypes: []
error_handler: oneup_uploader.error_handler.noop
| 0
|
155aca367c31eaed594f45ff88b8ce9de2adfd01
|
1up-lab
|
OneupUploaderBundle
|
gaufrette orphanage fixes and tests
|
commit 155aca367c31eaed594f45ff88b8ce9de2adfd01
Author: mitom <[email protected]>
Date: Fri Oct 11 14:25:00 2013 +0200
gaufrette orphanage fixes and tests
diff --git a/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php b/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
index 2278b96..d647848 100644
--- a/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/FilesystemOrphanageStorageTest.php
@@ -5,7 +5,6 @@ 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;
@@ -13,15 +12,8 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-class FilesystemOrphanageStorageTest extends \PHPUnit_Framework_TestCase
+class FilesystemOrphanageStorageTest extends OrphanageTest
{
- protected $tempDirectory;
- protected $realDirectory;
- protected $orphanage;
- protected $storage;
- protected $payloads;
- protected $numberOfPayloads;
-
public function setUp()
{
$this->numberOfPayloads = 5;
@@ -57,72 +49,4 @@ class FilesystemOrphanageStorageTest extends \PHPUnit_Framework_TestCase
$this->orphanage = new FilesystemOrphanageStorage($this->storage, $session, $chunkStorage, $config, 'cat');
}
-
- 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);
- }
}
diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php
index ec02d6b..e087c1b 100644
--- a/Uploader/Storage/GaufretteOrphanageStorage.php
+++ b/Uploader/Storage/GaufretteOrphanageStorage.php
@@ -55,13 +55,9 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto
try {
$return[] = $this->storage->upload($file, str_replace($this->getPath(), '', $key));
} catch (\Exception $e) {
- // don't delete the file, if the upload failed because
- // 1, it may not exist and deleting would throw another exception;
- // 2, don't lose it on network related errors
+ // well, we tried.
continue;
}
-
- $this->chunkStorage->getFilesystem()->delete($key);
}
return $return;
| 0
|
559f4d3139e7e428fba7b972386ed45c2ab076ef
|
1up-lab
|
OneupUploaderBundle
|
Added TypeHinting for Controller constructor.
|
commit 559f4d3139e7e428fba7b972386ed45c2ab076ef
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 17:10:51 2013 +0100
Added TypeHinting for Controller constructor.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 09f386a..ebd2c39 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -5,12 +5,17 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Finder\Finder;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
+use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
class UploaderController implements UploadControllerInterface
{
@@ -22,7 +27,7 @@ class UploaderController implements UploadControllerInterface
protected $type;
protected $chunkManager;
- public function __construct($request, $namer, $storage, $dispatcher, $type, $config, $chunkManager)
+ public function __construct(Request $request, NamerInterface $namer, StorageInterface $storage, EventDispatcherInterface $dispatcher, $type, array $config, ChunkManagerInterface $chunkManager)
{
$this->request = $request;
$this->namer = $namer;
| 0
|
eb609baf31012cf67fb776953bdee2bd484e58eb
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'nathanmarcos-master'
|
commit eb609baf31012cf67fb776953bdee2bd484e58eb
Merge: 645d017 0cad080
Author: David Greminger <[email protected]>
Date: Mon Jun 20 09:58:42 2016 +0200
Merge branch 'nathanmarcos-master'
| 0
|
5f8d0514844fa2ec4d8059236263d1057a2b9db9
|
1up-lab
|
OneupUploaderBundle
|
Forgot to commit composer.json with new tags.
|
commit 5f8d0514844fa2ec4d8059236263d1057a2b9db9
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 16:02:34 2013 +0200
Forgot to commit composer.json with new tags.
diff --git a/composer.json b/composer.json
index 99e963e..8124134 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
"description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support.",
- "keywords": ["fileupload", "upload", "multifileupload", "chunked upload", "orphans", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"],
+ "keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"],
"homepage": "http://1up.io",
"license": "MIT",
"authors": [
| 0
|
b068ec3854b32a62367b56bab04d773628aad895
|
1up-lab
|
OneupUploaderBundle
|
Added a per-frontend configurable ErrorHandler.
|
commit b068ec3854b32a62367b56bab04d773628aad895
Author: Jim Schmid <[email protected]>
Date: Sun Jul 14 23:08:43 2013 +0200
Added a per-frontend configurable ErrorHandler.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index c72861e..4adb51e 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -16,6 +16,7 @@ use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
abstract class AbstractController
{
@@ -24,8 +25,9 @@ abstract class AbstractController
protected $config;
protected $type;
- public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
+ public function __construct(ContainerInterface $container, StorageInterface $storage, ErrorHandlerInterface $errorHandler, array $config, $type)
{
+ $this->errorHandler = $errorHandler;
$this->container = $container;
$this->storage = $storage;
$this->config = $config;
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index 607797b..7ab6fe0 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -28,8 +28,7 @@ class BlueimpController extends AbstractChunkedController
$this->handleUpload($file, $response, $request)
;
} catch (UploadException $e) {
- // return nothing
- return new JsonResponse(array());
+ $this->errorHandler->addException($response, $e);
}
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9b4c457..6a1736f 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -70,6 +70,7 @@ class Configuration implements ConfigurationInterface
->arrayNode('disallowed_mimetypes')
->prototype('scalar')->end()
->end()
+ ->scalarNode('error_handler')->defaultValue('oneup_uploader.error_handler.noop')->end()
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->booleanNode('enable_progress')->defaultFalse()->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index d1435fa..b83a59a 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -23,6 +23,7 @@ class OneupUploaderExtension extends Extension
$loader->load('uploader.xml');
$loader->load('templating.xml');
$loader->load('validators.xml');
+ $loader->load('errorhandler.xml');
if ($config['twig']) {
$loader->load('twig.xml');
@@ -115,6 +116,8 @@ class OneupUploaderExtension extends Extension
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.');
}
+
+ $errorHandler = new Reference($mapping['error_handler']);
// create controllers based on mapping
$container
@@ -122,6 +125,7 @@ class OneupUploaderExtension extends Extension
->addArgument(new Reference('service_container'))
->addArgument($storageService)
+ ->addArgument($errorHandler)
->addArgument($mapping)
->addArgument($key)
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
new file mode 100644
index 0000000..025e38a
--- /dev/null
+++ b/Resources/config/errorhandler.xml
@@ -0,0 +1,16 @@
+<?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">
+
+ <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>
+ </parameters>
+
+ <services>
+ <service id="oneup_uploader.error_handler.noop" 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" />
+ </services>
+
+</container>
diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml
index 8f435c5..5b2ffe0 100644
--- a/Resources/config/validators.xml
+++ b/Resources/config/validators.xml
@@ -8,7 +8,7 @@
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
- <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener" >
+ <service id="oneup_uploader.validation_listener.allowed_extension" class="Oneup\UploaderBundle\EventListener\AllowedExtensionValidationListener">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
new file mode 100644
index 0000000..5187f90
--- /dev/null
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+class BlueimpErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(ResponseInterface $response, UploadException $exception)
+ {
+ $response->addToOffset($exception->getMessage(), 'files');
+ }
+}
diff --git a/Uploader/ErrorHandler/ErrorHandlerInterface.php b/Uploader/ErrorHandler/ErrorHandlerInterface.php
new file mode 100644
index 0000000..9b7a50a
--- /dev/null
+++ b/Uploader/ErrorHandler/ErrorHandlerInterface.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+interface ErrorHandlerInterface
+{
+ public function addException(ResponseInterface $response, UploadException $exception);
+}
diff --git a/Uploader/ErrorHandler/NoopErrorHandler.php b/Uploader/ErrorHandler/NoopErrorHandler.php
new file mode 100644
index 0000000..e131408
--- /dev/null
+++ b/Uploader/ErrorHandler/NoopErrorHandler.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+class NoopErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(ResponseInterface $response, UploadException $exception)
+ {
+ // noop
+ }
+}
| 0
|
66de7cc175a134c8009f1cd9612e0b22ee8cce12
|
1up-lab
|
OneupUploaderBundle
|
The parameter is now required for Storage::upload()
|
commit 66de7cc175a134c8009f1cd9612e0b22ee8cce12
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 20:12:55 2013 +0200
The parameter is now required for Storage::upload()
diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php
index f756476..fcc3e51 100644
--- a/Uploader/Storage/FilesystemStorage.php
+++ b/Uploader/Storage/FilesystemStorage.php
@@ -16,7 +16,7 @@ class FilesystemStorage implements StorageInterface
$this->directory = $directory;
}
- public function upload(File $file, $name = null, $path = null)
+ public function upload(File $file, $name, $path = null)
{
$filesystem = new Filesystem();
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 7f3978e..fac7bbe 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -18,7 +18,7 @@ class GaufretteStorage implements StorageInterface
$this->filesystem = $filesystem;
}
- public function upload(File $file, $name = null, $path = null)
+ 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);
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index f048df2..6477358 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -28,7 +28,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte
$this->type = $type;
}
- public function upload(File $file, $name = null, $path = null)
+ public function upload(File $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 3684604..e4e3dce 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -6,5 +6,5 @@ use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
{
- public function upload(File $file, $name = null, $path = null);
+ public function upload(File $file, $name, $path = null);
}
\ No newline at end of file
| 0
|
223e4369af3adc417bdeb7bc2c5a34e831022232
|
1up-lab
|
OneupUploaderBundle
|
Added Symfony2 version 2.5 to automated tests and dropped 2.2
|
commit 223e4369af3adc417bdeb7bc2c5a34e831022232
Author: Jim Schmid <[email protected]>
Date: Wed Jun 25 13:55:25 2014 +0200
Added Symfony2 version 2.5 to automated tests and dropped 2.2
diff --git a/.travis.yml b/.travis.yml
index 3381bd6..e3c5391 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,9 +5,9 @@ php:
- 5.4
env:
- - SYMFONY_VERSION=2.2.*
- SYMFONY_VERSION=2.3.*
- SYMFONY_VERSION=2.4.*
+ - SYMFONY_VERSION=2.5.*
before_script:
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
| 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
|
977c9c0022c03d2eceed63eb49fae6c5ad84290f
|
1up-lab
|
OneupUploaderBundle
|
Fix exception when parameter does not exist (#400)
|
commit 977c9c0022c03d2eceed63eb49fae6c5ad84290f
Author: David Greminger <[email protected]>
Date: Tue Feb 9 18:25:30 2021 +0100
Fix exception when parameter does not exist (#400)
diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php
index 889a698..b688707 100644
--- a/src/DependencyInjection/OneupUploaderExtension.php
+++ b/src/DependencyInjection/OneupUploaderExtension.php
@@ -342,17 +342,17 @@ class OneupUploaderExtension extends Extension
{
$projectDir = '';
- /** @var string $kernelProjectDir */
- $kernelProjectDir = $this->container->getParameter('kernel.project_dir');
-
- /** @var string $kernelRootDir */
- $kernelRootDir = $this->container->getParameter('kernel.root_dir');
-
if ($this->container->hasParameter('kernel.project_dir')) {
+ /** @var string $kernelProjectDir */
+ $kernelProjectDir = $this->container->getParameter('kernel.project_dir');
+
$projectDir = $kernelProjectDir;
}
if ($this->container->hasParameter('kernel.root_dir')) {
+ /** @var string $kernelRootDir */
+ $kernelRootDir = $this->container->getParameter('kernel.root_dir');
+
$projectDir = sprintf('%s/..', $kernelRootDir);
}
| 0
|
09243d68e30e4a5e8112f6443323f1ccd6743d65
|
1up-lab
|
OneupUploaderBundle
|
Do not use deprecated _method requirement
|
commit 09243d68e30e4a5e8112f6443323f1ccd6743d65
Author: Giorgio Premi <[email protected]>
Date: Mon Mar 2 12:44:48 2015 +0100
Do not use deprecated _method requirement
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index fad6c0f..4e8df11 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')
);
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..b5460ef 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,8 +48,12 @@ abstract class AbstractControllerTest extends WebTestCase
*/
public function testCallByDelete()
{
- $endpoint = $this->helper->endpoint($this->getConfigKey());
- $this->client->request('DELETE', $endpoint);
+ $this->implTestCallBy('DELETE');
+ }
+
+ public function testCallByPost()
+ {
+ $this->implTestCallBy('POST');
}
/**
@@ -58,16 +61,15 @@ abstract class AbstractControllerTest extends WebTestCase
*/
public function testCallByPut()
{
- $endpoint = $this->helper->endpoint($this->getConfigKey());
- $this->client->request('PUT', $endpoint);
+ $this->implTestCallBy('PUT');
}
- public function testCallByPost()
+ 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/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 4058039..a09385e 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->assertEquals(array('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->assertEquals(array('POST'), $route->getMethods());
$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
| 0
|
4f8c95c89eb33908a266949bde01232e91d25f5e
|
1up-lab
|
OneupUploaderBundle
|
CS Fixes
|
commit 4f8c95c89eb33908a266949bde01232e91d25f5e
Author: David Greminger <[email protected]>
Date: Mon Jul 16 12:48:41 2018 +0200
CS Fixes
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index cff222d..73450a9 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -47,7 +47,7 @@ abstract class AbstractChunkedController extends AbstractController
$chunkManager = $this->container->get('oneup_uploader.chunk_manager');
// get information about this chunked request
- list($last, $uuid, $index, $orig) = $this->parseChunkedRequest($request);
+ [$last, $uuid, $index, $orig] = $this->parseChunkedRequest($request);
$chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index 563bb94..434dc27 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -58,7 +58,7 @@ class BlueimpController extends AbstractChunkedController
$attachmentName = rawurldecode(preg_replace('/(^[^"]+")|("$)/', '', $request->headers->get('content-disposition')));
// split the header string to the appropriate parts
- list(, $startByte, $endByte, $totalBytes) = preg_split('/[^0-9]+/', $headerRange);
+ [, $startByte, $endByte, $totalBytes] = preg_split('/[^0-9]+/', $headerRange);
// getting information about chunks
// note: We don't have a chance to get the last $total
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 16d22ac..5de4e19 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -17,7 +17,7 @@ class MooUploadController extends AbstractChunkedController
$response = new MooUploadResponse();
$headers = $request->headers;
- list($file, $uploadFileName) = $this->getUploadedFile($request);
+ [$file, $uploadFileName] = $this->getUploadedFile($request);
// we have to get access to this object in another method
$this->response = $response;
diff --git a/DependencyInjection/Compiler/OneUpPass.php b/DependencyInjection/Compiler/ControllerPass.php
similarity index 73%
rename from DependencyInjection/Compiler/OneUpPass.php
rename to DependencyInjection/Compiler/ControllerPass.php
index 2fff4b7..347cb4a 100644
--- a/DependencyInjection/Compiler/OneUpPass.php
+++ b/DependencyInjection/Compiler/ControllerPass.php
@@ -5,21 +5,19 @@ namespace Oneup\UploaderBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-class OneUpPass implements CompilerPassInterface
+class ControllerPass implements CompilerPassInterface
{
- public function process(ContainerBuilder $container)
+ public function process(ContainerBuilder $container): void
{
// Find autowired controllers
$autowired_controllers = $container->findTaggedServiceIds('controller.service_arguments');
// Find OneUp controllers
$controllers = $container->findTaggedServiceIds('oneup_uploader.controller');
- foreach($controllers as $id => $tags) {
-
+ foreach ($controllers as $id => $tags) {
// Get fully qualified name of service
$fqdn = $container->getDefinition($id)->getClass();
- if(isset($autowired_controllers[$fqdn])) {
-
+ if (isset($autowired_controllers[$fqdn])) {
// Retrieve auto wired controller
$autowired_definition = $container->getDefinition($fqdn);
@@ -27,17 +25,17 @@ class OneUpPass implements CompilerPassInterface
$arguments = $container->getDefinition($id)->getArguments();
// Add arguments to auto wired controller
- if(empty($autowired_definition->getArguments())) {
- foreach($arguments as $argument) {
+ if (empty($autowired_definition->getArguments())) {
+ foreach ($arguments as $argument) {
$autowired_definition->addArgument($argument);
}
}
// Remove autowire
- if(method_exists($autowired_definition, 'setAutowired')) {
+ if (method_exists($autowired_definition, 'setAutowired')) {
$autowired_definition->setAutowired(false);
}
}
}
}
-}
\ No newline at end of file
+}
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 6285220..6ae8f8f 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -61,7 +61,7 @@ class OneupUploaderExtension extends Extension
protected function processOrphanageConfig()
{
- if ($this->config['chunks']['storage']['type'] === 'filesystem') {
+ if ('filesystem' === $this->config['chunks']['storage']['type']) {
$defaultDir = sprintf('%s/uploader/orphanage', $this->container->getParameter('kernel.cache_dir'));
} else {
$defaultDir = 'orphanage';
@@ -207,7 +207,7 @@ class OneupUploaderExtension extends Extension
// root_folder is true, remove the mapping name folder from path
$folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key;
- $config['directory'] = null === $config['directory'] ?
+ $config['directory'] = null === $config['directory'] ?
\sprintf('%s/uploads/%s', $this->getTargetDir(), $folder) :
$this->normalizePath($config['directory'])
;
@@ -332,7 +332,7 @@ class OneupUploaderExtension extends Extension
return rtrim($input, '/').'/';
}
-
+
protected function getTargetDir()
{
$projectDir = $this->container->hasParameter('kernel.project_dir') ?
diff --git a/OneupUploaderBundle.php b/OneupUploaderBundle.php
index 66e21b9..2d3f0c3 100644
--- a/OneupUploaderBundle.php
+++ b/OneupUploaderBundle.php
@@ -2,15 +2,15 @@
namespace Oneup\UploaderBundle;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Oneup\UploaderBundle\DependencyInjection\Compiler\ControllerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Oneup\UploaderBundle\DependencyInjection\Compiler\OneUpPass;
+use Symfony\Component\HttpKernel\Bundle\Bundle;
class OneupUploaderBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
- $container->addCompilerPass(new OneUpPass());
+ $container->addCompilerPass(new ControllerPass());
}
-}
\ No newline at end of file
+}
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index d0c5cef..e72f144 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -98,7 +98,7 @@ abstract class AbstractControllerTest extends WebTestCase
abstract protected function getConfigKey();
- protected function implTestCallBy($method, $expectedStatusCode = 200, $expectedContentType='application/json')
+ protected function implTestCallBy($method, $expectedStatusCode = 200, $expectedContentType = 'application/json')
{
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
@@ -110,7 +110,7 @@ abstract class AbstractControllerTest extends WebTestCase
$client->request($method, $endpoint, [], [], $this->requestHeaders);
$response = $client->getResponse();
- $this->assertEquals($expectedStatusCode, $response->getStatusCode());
+ $this->assertSame($expectedStatusCode, $response->getStatusCode());
$this->assertContains($expectedContentType, $response->headers->get('Content-Type'));
}
diff --git a/Uploader/Storage/FlysystemStorage.php b/Uploader/Storage/FlysystemStorage.php
index 7f1bff2..913de52 100644
--- a/Uploader/Storage/FlysystemStorage.php
+++ b/Uploader/Storage/FlysystemStorage.php
@@ -40,9 +40,9 @@ class FlysystemStorage implements StorageInterface
if ($file instanceof FilesystemFile) {
$stream = fopen($file->getPathname(), 'r+b');
- $this->filesystem->putStream($path, $stream, array(
- 'mimetype' => $file->getMimeType()
- ));
+ $this->filesystem->putStream($path, $stream, [
+ 'mimetype' => $file->getMimeType(),
+ ]);
if (is_resource($stream)) {
fclose($stream);
| 0
|
42b6ff7e97cf6ccff2402c1000a50f7a1bdf8fc7
|
1up-lab
|
OneupUploaderBundle
|
Print a valuable exception message if filesystem key is empty.
|
commit 42b6ff7e97cf6ccff2402c1000a50f7a1bdf8fc7
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 20:01:48 2013 +0200
Print a valuable exception message if filesystem key is empty.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 32d23a5..c828879 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -5,6 +5,7 @@ namespace Oneup\UploaderBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
+use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
@@ -71,6 +72,9 @@ class OneupUploaderExtension extends Extension
if(!class_exists('Gaufrette\\Filesystem'))
throw new InvalidArgumentException('You have to install Gaufrette in order to use it as a storage service.');
+ if(strlen($mapping['storage']['filesystem']) <= 0)
+ throw new ServiceNotFoundException('Empty service name');
+
$container
->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type'])))
->addArgument(new Reference($mapping['storage']['filesystem']))
| 0
|
2d8f07a3c9847132c1ead0d0bf7efc9b71e313e7
|
1up-lab
|
OneupUploaderBundle
|
Fixed RouteLoaderTest, we're now working with arrays.
|
commit 2d8f07a3c9847132c1ead0d0bf7efc9b71e313e7
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 11:16:21 2013 +0200
Fixed RouteLoaderTest, we're now working with arrays.
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 017a94e..9a362f5 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -12,8 +12,8 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
$dog = 'HelloThisIsDogController';
$routeLoader = new RouteLoader(array(
- 'cat' => $cat,
- 'dog' => $dog
+ 'cat' => array($cat, array('use_upload_progress' => false)),
+ 'dog' => array($dog, array('use_upload_progress' => true)),
));
$routes = $routeLoader->load(null);
@@ -21,7 +21,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
// for code coverage
$this->assertTrue($routeLoader->supports('grumpy', 'uploader'));
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
- $this->assertCount(2, $routes);
+ $this->assertCount(3, $routes);
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
| 0
|
b0e8666cbfe5a21cb3c9825bcdf7de02e2d3a4d5
|
1up-lab
|
OneupUploaderBundle
|
Renamed chunk_manager to chunks
To match the DI configuration
|
commit b0e8666cbfe5a21cb3c9825bcdf7de02e2d3a4d5
Author: Dirk Luijk <[email protected]>
Date: Wed Jul 24 15:45:06 2013 +0200
Renamed chunk_manager to chunks
To match the DI configuration
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index d649a14..4f5c5e1 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -29,7 +29,7 @@ You can configure the `ChunkManager` by using the following configuration parame
```
oneup_uploader:
- chunk_manager:
+ chunks:
maxage: 86400
directory: %kernel.cache_dir%/uploader/chunks
```
| 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
|
da09f881c78b58a869ade9ecfa00b730f02bb9aa
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #11 from 1up-lab/plupload
Implemented Plupload
|
commit da09f881c78b58a869ade9ecfa00b730f02bb9aa
Merge: 59659bd 5f8d051
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 07:03:37 2013 -0700
Merge pull request #11 from 1up-lab/plupload
Implemented Plupload
| 0
|
9ea61f30b4b634ef5bc27e44bb69954524915bd9
|
1up-lab
|
OneupUploaderBundle
|
Fix issue #340 for Symfony < 4.1
|
commit 9ea61f30b4b634ef5bc27e44bb69954524915bd9
Author: David Greminger <[email protected]>
Date: Wed Jul 18 12:25:15 2018 +0200
Fix issue #340 for Symfony < 4.1
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index dda6d65..c242fc2 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Routing;
use Symfony\Component\Config\Loader\Loader;
+use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@@ -23,6 +24,12 @@ class RouteLoader extends Loader
public function load($resource, $type = null)
{
$routes = new RouteCollection();
+ $separator = ':';
+
+ // Double colon separators are used in Symfony >= 4.1 (see #340)
+ if (version_compare(Kernel::VERSION, '4.1', '>=')) {
+ $separator .= ':';
+ }
foreach ($this->controllers as $type => $controllerArray) {
$service = $controllerArray[0];
@@ -30,7 +37,7 @@ class RouteLoader extends Loader
$upload = new Route(
$options['endpoints']['upload'] ?: sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type),
- ['_controller' => $service.'::upload', '_format' => 'json'],
+ ['_controller' => $service.$separator.'upload', '_format' => 'json'],
[],
[],
'',
@@ -41,7 +48,7 @@ class RouteLoader extends Loader
if (true === $options['enable_progress']) {
$progress = new Route(
$options['endpoints']['progress'] ?: sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type),
- ['_controller' => $service.'::progress', '_format' => 'json'],
+ ['_controller' => $service.$separator.'progress', '_format' => 'json'],
[],
[],
'',
@@ -55,7 +62,7 @@ class RouteLoader extends Loader
if (true === $options['enable_cancelation']) {
$progress = new Route(
$options['endpoints']['cancel'] ?: sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type),
- ['_controller' => $service.'::cancel', '_format' => 'json'],
+ ['_controller' => $service.$separator.'cancel', '_format' => 'json'],
[],
[],
'',
| 0
|
9dbd9056dfe403ce6f1273d2d75fe814d517731a
|
1up-lab
|
OneupUploaderBundle
|
Distribute the load of assembling chunks to every upload request.
This is a configurable option, as it could be the case that chunks
will be uploaded asynchronous and therefore not in the correct order.
Fixes #24.
|
commit 9dbd9056dfe403ce6f1273d2d75fe814d517731a
Author: Jim Schmid <[email protected]>
Date: Mon Jul 15 01:24:35 2013 +0200
Distribute the load of assembling chunks to every upload request.
This is a configurable option, as it could be the case that chunks
will be uploaded asynchronous and therefore not in the correct order.
Fixes #24.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 4d797d1..f053703 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -57,16 +57,20 @@ abstract class AbstractChunkedController extends AbstractController
$chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
$this->dispatchChunkEvents($chunk, $response, $request, $last);
+
+ if ($chunkManager->getLoadDistribution()) {
+ $chunks = $chunkManager->getChunks($uuid);
+ $assembled = $chunkManager->assembleChunks($chunks);
+ }
// if all chunks collected and stored, proceed
// with reassembling the parts
if ($last) {
- // we'll take the first chunk and append the others to it
- // this way we don't need another file in temporary space for assembling
- $chunks = $chunkManager->getChunks($uuid);
-
- // assemble parts
- $assembled = $chunkManager->assembleChunks($chunks);
+ 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/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9b4c457..02085e0 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -19,6 +19,7 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('maxage')->defaultValue(604800)->end()
->scalarNode('directory')->defaultNull()->end()
+ ->booleanNode('load_distribution')->defaultTrue()->end()
->end()
->end()
->arrayNode('orphanage')
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 5bfa4b5..310cd0b 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)
+ public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true)
{
$iterator = $chunks->getIterator()->getInnerIterator();
@@ -63,6 +63,11 @@ class ChunkManager implements ChunkManagerInterface
throw new \RuntimeException('Reassembling chunks failed.');
}
+ if ($removeChunk) {
+ $filesystem = new Filesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
$iterator->next();
}
@@ -97,4 +102,9 @@ class ChunkManager implements ChunkManagerInterface
return $finder;
}
+
+ public function getLoadDistribution()
+ {
+ return $this->configuration['load_distribution'];
+ }
}
| 0
|
e1e139af3c63d0a19f6f8b06591987fb4ca0d6bb
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'derpue-validationEventWithResponse'
|
commit e1e139af3c63d0a19f6f8b06591987fb4ca0d6bb
Merge: c70ac38 c7c1d00
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:16:34 2017 +0100
Merge branch 'derpue-validationEventWithResponse'
| 0
|
b17bee4fbd2d39a603218f2959bb0389e7828e6a
|
1up-lab
|
OneupUploaderBundle
|
Fix configuration for storage service creation
|
commit b17bee4fbd2d39a603218f2959bb0389e7828e6a
Author: PaulM <[email protected]>
Date: Tue Oct 15 11:11:53 2013 +0200
Fix configuration for storage service creation
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index c017bdc..f6720a6 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -169,7 +169,7 @@ class OneupUploaderExtension extends Extension
// if a service is given, return a reference to this service
// this allows a user to overwrite the storage layer if needed
if (!is_null($config['service'])) {
- $storageService = new Reference($config['storage']['service']);
+ $storageService = new Reference($config['service']);
} else {
// no service was given, so we create one
$storageName = sprintf('oneup_uploader.storage.%s', $key);
| 0
|
dd5997eaa5a942434f69dad54f7311ac2f483e3a
|
1up-lab
|
OneupUploaderBundle
|
Fixed typo in extends usage of PHPUnit_Framework_TestCase in OrphanageTest
|
commit dd5997eaa5a942434f69dad54f7311ac2f483e3a
Author: haeber <[email protected]>
Date: Tue Oct 4 15:23:31 2016 +0200
Fixed typo in extends usage of PHPUnit_Framework_TestCase in OrphanageTest
diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php
index ce3f6cd..c539e7f 100644
--- a/Tests/Uploader/Storage/OrphanageTest.php
+++ b/Tests/Uploader/Storage/OrphanageTest.php
@@ -6,7 +6,7 @@ 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;
| 0
|
9a1b5cb2350dc83e1863c68ef07104494a7ce977
|
1up-lab
|
OneupUploaderBundle
|
Tested chunked upload. Bhuuu, that was a hard one.
|
commit 9a1b5cb2350dc83e1863c68ef07104494a7ce977
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 19:10:16 2013 +0200
Tested chunked upload. Bhuuu, that was a hard one.
diff --git a/Tests/Controller/ControllerChunkedUploadTest.php b/Tests/Controller/ControllerChunkedUploadTest.php
new file mode 100644
index 0000000..3c57240
--- /dev/null
+++ b/Tests/Controller/ControllerChunkedUploadTest.php
@@ -0,0 +1,175 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
+use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
+use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
+use Oneup\UploaderBundle\Controller\UploaderController;
+
+class ControllerChunkedUploadTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tempChunks;
+ protected $currentChunk;
+ protected $chunkUuid;
+ protected $numberOfChunks;
+
+ public function setUp()
+ {
+ $this->numberOfChunks = 10;
+
+ // create 10 chunks
+ for($i = 0; $i < $this->numberOfChunks; $i++)
+ {
+ // create temporary file
+ $chunk = tempnam(sys_get_temp_dir(), 'uploader');
+
+ $pointer = fopen($chunk, 'w+');
+ fwrite($pointer, str_repeat('A', 1024), 1024);
+ fclose($pointer);
+
+ $this->tempChunks[] = $chunk;
+ }
+
+ $this->currentChunk = 0;
+ $this->chunkUuid = uniqid();
+ }
+
+ public function testUpload()
+ {
+ $container = $this->getContainerMock();
+ $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
+ $config = array(
+ 'use_orphanage' => false,
+ 'namer' => 'namer',
+ 'max_size' => 2048,
+ 'allowed_extensions' => array(),
+ 'disallowed_extensions' => array()
+ );
+
+ $responses = array();
+ $controller = new UploaderController($container, $storage, $config, 'cat');
+
+ // mock as much requests as there are parts to assemble
+ for($i = 0; $i < $this->numberOfChunks; $i ++)
+ {
+ $responses[] = $controller->upload();
+
+ // will be used internaly
+ $this->currentChunk++;
+ }
+
+ for($i = 0; $i < $this->numberOfChunks; $i ++)
+ {
+ // check if original file has been moved
+ $this->assertFalse(file_exists($this->tempChunks[$i]));
+
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $responses[$i]);
+ $this->assertEquals(200, $responses[$i]->getStatusCode());
+ }
+
+ // check if assembled file is here
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/uploader')->files();
+ $this->assertCount(1, $finder);
+
+ // and check if chunks are gone
+ $finder = new Finder();
+ $finder->in(sys_get_temp_dir() . '/chunks')->files();
+ $this->assertCount(0, $finder);
+ }
+
+ protected function getContainerMock()
+ {
+ $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'containerGetCb')))
+ ;
+
+ return $mock;
+ }
+
+ public function containerGetCb($inp)
+ {
+ if($inp == 'request')
+ return $this->getRequestMock();
+
+ if($inp == 'event_dispatcher')
+ return $this->getEventDispatcherMock();
+
+ if($inp == 'namer')
+ return new UniqidNamer();
+
+ if($inp == 'oneup_uploader.chunk_manager')
+ return $this->getChunkManager();
+ }
+
+ protected function getEventDispatcherMock()
+ {
+ $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $mock
+ ->expects($this->any())
+ ->method('dispatch')
+ ->will($this->returnValue(true))
+ ;
+
+ return $mock;
+ }
+
+ protected function getRequestMock()
+ {
+ $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
+ $mock
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(array($this, 'requestGetCb')))
+ ;
+
+ $mock->files = array(
+ $this->getUploadedFile()
+ );
+
+ return $mock;
+ }
+
+ public function requestGetCb($inp)
+ {
+ if($inp == 'qqtotalparts')
+ return $this->numberOfChunks;
+
+ if($inp == 'qqpartindex')
+ return $this->currentChunk;
+
+ if($inp == 'qquuid')
+ return $this->chunkUuid;
+
+ if($inp == 'qqfilename')
+ return 'grumpy-cat.jpeg';
+ }
+
+ protected function getUploadedFile()
+ {
+ return new UploadedFile($this->tempChunks[$this->currentChunk], 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
+ }
+
+ protected function getChunkManager()
+ {
+ return new ChunkManager(array(
+ 'directory' => sys_get_temp_dir() . '/chunks'
+ ));
+ }
+
+ public function tearDown()
+ {
+ // remove all files in tmp folder
+ $filesystem = new Filesystem();
+ $filesystem->remove(sys_get_temp_dir() . '/uploader');
+ $filesystem->remove(sys_get_temp_dir() . '/chunks');
+ }
+}
\ No newline at end of file
| 0
|
c5a1ce9a0e7b2f84982ccff39ba88832e0602cae
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'bluntelk-master'
|
commit c5a1ce9a0e7b2f84982ccff39ba88832e0602cae
Merge: 14eda43 3ecd0b8
Author: David Greminger <[email protected]>
Date: Fri Mar 17 12:17:45 2017 +0100
Merge branch 'bluntelk-master'
| 0
|
dd1639c6edfd893e4878163cd72b48333264298a
|
1up-lab
|
OneupUploaderBundle
|
Added frontend_fancyupload.md to the correct directory
|
commit dd1639c6edfd893e4878163cd72b48333264298a
Author: Jim Schmid <[email protected]>
Date: Thu Apr 11 22:44:13 2013 +0200
Added frontend_fancyupload.md to the correct directory
diff --git a/Resources/config/frontend_fancyupload.md b/Resources/doc/frontend_fancyupload.md
similarity index 100%
rename from Resources/config/frontend_fancyupload.md
rename to Resources/doc/frontend_fancyupload.md
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 6cd7a2c..663f91e 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -94,6 +94,7 @@ So if you take the mapping described before, the generated route name would be `
* [Use jQuery File Upload](frontend_blueimp.md)
* [Use YUI3 Uploader](frontend_yui3.md)
* [Use Uploadify](frontend_uploadify.md)
+* [Use FancyUpload](frontend_fancyupload.md)
This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them.
| 0
|
b808587d5c344e14006699f9dad9f9762d1051ec
|
1up-lab
|
OneupUploaderBundle
|
Added a YUI3 implementation.
|
commit b808587d5c344e14006699f9dad9f9762d1051ec
Author: Jim Schmid <[email protected]>
Date: Thu Apr 11 20:29:09 2013 +0200
Added a YUI3 implementation.
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
new file mode 100644
index 0000000..8ade2ec
--- /dev/null
+++ b/Controller/YUI3Controller.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+use Oneup\UploaderBundle\Controller\AbstractController;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class 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;
+
+ foreach($files as $file)
+ {
+ try
+ {
+ $uploaded = $this->handleUpload($file);
+
+ // dispatch POST_PERSIST AND POST_UPLOAD events
+ $this->dispatchEvents($uploaded, $response, $request);
+ }
+ catch(UploadException $e)
+ {
+ // return nothing
+ return new JsonResponse(array());
+ }
+ }
+
+ return new JsonResponse($response->assemble());
+ }
+}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 6e065bb..7298bec 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -35,7 +35,7 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->enumNode('frontend')
- ->values(array('fineuploader', 'blueimp', 'uploadify'))
+ ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3'))
->defaultValue('fineuploader')
->end()
->arrayNode('storage')
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 454f024..6933114 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -14,6 +14,7 @@
<parameter key="oneup_uploader.controller.fineuploader.class">Oneup\UploaderBundle\Controller\FineUploaderController</parameter>
<parameter key="oneup_uploader.controller.blueimp.class">Oneup\UploaderBundle\Controller\BlueimpController</parameter>
<parameter key="oneup_uploader.controller.uploadify.class">Oneup\UploaderBundle\Controller\UploadifyController</parameter>
+ <parameter key="oneup_uploader.controller.yui3.class">Oneup\UploaderBundle\Controller\YUI3Controller</parameter>
</parameters>
<services>
| 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
|
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
|
ec662ba25f61230854d6fbbd4706e503a1674c9e
|
1up-lab
|
OneupUploaderBundle
|
Added Upgrade Note for 1.0
|
commit ec662ba25f61230854d6fbbd4706e503a1674c9e
Author: Jim Schmid <[email protected]>
Date: Wed Oct 23 15:24:27 2013 +0200
Added Upgrade Note for 1.0
diff --git a/README.md b/README.md
index a8b708b..0abe5c1 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
+* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
* If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320).
* Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_logic.md#using-chunked-uploads).
| 0
|
fc2ed9a6b798c71951806c8c9ed6e1366856272e
|
1up-lab
|
OneupUploaderBundle
|
Added Request object to ValidationEvent
This current implementation (as of v0.9.8) was made without breaking backwards compatibility.
This means constructor's parameter $request of ValidationEvent defaults to null. Should be
fixed in the next major version.
Details in #23.
|
commit fc2ed9a6b798c71951806c8c9ed6e1366856272e
Author: Jim Schmid <[email protected]>
Date: Sat Sep 14 15:27:12 2013 +0200
Added Request object to ValidationEvent
This current implementation (as of v0.9.8) was made without breaking backwards compatibility.
This means constructor's parameter $request of ValidationEvent defaults to null. Should be
fixed in the next major version.
Details in #23.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 0ab6eec..30b0519 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -164,7 +164,7 @@ abstract class AbstractController
protected function validate(UploadedFile $file)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->config, $this->type);
+ $event = new ValidationEvent($file, $this->config, $this->type, $this->container->get('request'));
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
}
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index a3ecef1..0fa90b0 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -4,17 +4,21 @@ namespace Oneup\UploaderBundle\Event;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\Request;
class ValidationEvent extends Event
{
protected $file;
protected $config;
+ protected $type;
+ protected $request;
- public function __construct(UploadedFile $file, array $config, $type)
+ public function __construct(UploadedFile $file, array $config, $type, Request $request = null)
{
$this->file = $file;
$this->config = $config;
$this->type = $type;
+ $this->request = $request;
}
public function getFile()
@@ -31,4 +35,9 @@ class ValidationEvent extends Event
{
return $this->type;
}
+
+ public function getRequest()
+ {
+ return $this->request;
+ }
}
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index d0e1e60..5461c6b 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -65,6 +65,27 @@ abstract class AbstractValidationTest extends AbstractControllerTest
$this->assertEquals(1, $validationCount);
}
+ public function testIfRequestIsAvailableInEvent()
+ {
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+ $dispatcher = $client->getContainer()->get('event_dispatcher');
+
+ // event data
+ $validationCount = 0;
+
+ $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) {
+ $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $event->getRequest());
+
+ // to be sure this listener is called
+ ++ $validationCount;
+ });
+
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension()));
+
+ $this->assertEquals(1, $validationCount);
+ }
+
public function testAgainstIncorrectExtension()
{
// assemble a request
| 0
|
46acc7713db576a7d5a44b2bc69c4197ae196ae0
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'really-uniquenamer' of https://github.com/lsv/OneupUploaderBundle into lsv-really-uniquenamer
|
commit 46acc7713db576a7d5a44b2bc69c4197ae196ae0
Merge: a453078 8b6c03e
Author: David Greminger <[email protected]>
Date: Fri Sep 15 16:34:54 2017 +0200
Merge branch 'really-uniquenamer' of https://github.com/lsv/OneupUploaderBundle into lsv-really-uniquenamer
diff --cc Resources/config/uploader.xml
index 13d8f30,0e80c99..4389640
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@@ -6,8 -6,8 +6,9 @@@
<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>
diff --cc composer.json
index b0ef8ce,7e123de..a5cea42
--- a/composer.json
+++ b/composer.json
@@@ -15,9 -15,9 +15,10 @@@
],
"require": {
+ "php":">=5.4",
"symfony/framework-bundle": "^2.4.0|~3.0",
- "symfony/finder": "^2.4.0|~3.0"
+ "symfony/finder": "^2.4.0|~3.0",
+ "paragonie/random_compat": "^1.1"
},
"require-dev": {
| 0
|
00e0cef40ff67dc60bbd1130c83d2e5e138567e3
|
1up-lab
|
OneupUploaderBundle
|
Included max_size parameter for mapping-configuration.
|
commit 00e0cef40ff67dc60bbd1130c83d2e5e138567e3
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 15:45:57 2013 +0100
Included max_size parameter for mapping-configuration.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 6feeed0..722172d 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -34,6 +34,10 @@ class UploaderController implements UploadControllerInterface
foreach($files as $file)
{
+ // some error handling
+ if($file->getClientSize() > $this->config['max_size'])
+ return new JsonResponse(array('error' => 'File is too large'));
+
$ret = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 829ae62..04d1ca6 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -35,7 +35,8 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->scalarNode('storage')->isRequired()->end()
- ->scalarNode('directory_prefix')->end()
+ ->scalarNode('max_size')->defaultNull()->end()
+ ->scalarNode('directory_prefix')->defaultNull()->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 4e363cd..e844c04 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -39,11 +39,13 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach($config['mappings'] as $key => $mapping)
{
- if(!array_key_exists('directory_prefix', $mapping))
+ if(is_null($mapping['directory_prefix']))
{
$mapping['directory_prefix'] = $key;
}
+ $mapping['max_size'] = min(min($mapping['max_size'], ini_get('upload_max_filesize')), ini_get('post_max_size'));
+
$mapping['storage'] = $this->registerStorageService($container, $mapping);
$this->registerServicesPerMap($container, $key, $mapping);
}
| 0
|
58b77cf8b2250009543983015708a8b1de372d8d
|
1up-lab
|
OneupUploaderBundle
|
Correctly cast to int (see #316)
|
commit 58b77cf8b2250009543983015708a8b1de372d8d
Author: David Greminger <[email protected]>
Date: Wed Feb 7 15:18:09 2018 +0100
Correctly cast to int (see #316)
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index e026473..563bb94 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -68,7 +68,7 @@ class BlueimpController extends AbstractChunkedController
// any idea to fix this without fetching information about
// previously saved files, let me know.
$size = ($endByte + 1 - $startByte);
- $last = ($endByte + 1) === $totalBytes;
+ $last = ((int) $endByte + 1) === (int) $totalBytes;
$index = $last ? \PHP_INT_MAX : floor($startByte / $size);
// it is possible, that two clients send a file with the
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index a3783f5..95d7784 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -43,7 +43,7 @@ class DropzoneController extends AbstractChunkedController
{
$totalChunkCount = $request->get('dztotalchunkcount');
$index = $request->get('dzchunkindex');
- $last = ($index + 1) === (int) $totalChunkCount;
+ $last = ((int) $index + 1) === (int) $totalChunkCount;
$uuid = $request->get('dzuuid');
/**
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index a2ba606..3357cb7 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -44,7 +44,7 @@ class FineUploaderController extends AbstractChunkedController
$total = $request->get('qqtotalparts');
$uuid = $request->get('qquuid');
$orig = $request->get('qqfilename');
- $last = ($total - 1) === $index;
+ $last = ((int) $total - 1) === (int) $index;
return [$last, $uuid, $index, $orig];
}
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 6d8082c..16d22ac 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -76,7 +76,7 @@ class MooUploadController extends AbstractChunkedController
// size is 0
}
- $last = $headers->get('x-file-size') === ($size + $headers->get('content-length'));
+ $last = (int) $headers->get('x-file-size') === ($size + (int) $headers->get('content-length'));
// store also to response object
$this->response->setFinish($last);
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index 0250ae7..4697d38 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -36,7 +36,7 @@ class PluploadController extends AbstractChunkedController
$orig = $request->get('name');
$index = $request->get('chunk');
- $last = $request->get('chunks') - 1 === $request->get('chunk');
+ $last = (int) $request->get('chunks') - 1 === (int) $request->get('chunk');
// it is possible, that two clients send a file with the
// exact same filename, therefore we have to add the session
| 0
|
a408548b241f47af3539b2137c1817a21a51fde9
|
1up-lab
|
OneupUploaderBundle
|
Refactored Event dispatching (BC-break)
* Moved dispatching to the upload* functions
* Added a new Event which will be fired after a chunk has been uploaded
This is a huge BC-break. It has to be done to address #20 though.
|
commit a408548b241f47af3539b2137c1817a21a51fde9
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 19:46:46 2013 +0200
Refactored Event dispatching (BC-break)
* Moved dispatching to the upload* functions
* Added a new Event which will be fired after a chunk has been uploaded
This is a huge BC-break. It has to be done to address #20 though.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index de094cb..e343807 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -4,7 +4,11 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
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
{
@@ -35,7 +39,7 @@ abstract class AbstractChunkedController extends AbstractController
*
* @param file The uploaded chunk.
*/
- protected function handleChunkedUpload(UploadedFile $file)
+ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
// get basic container stuff
$request = $this->container->get('request');
@@ -47,12 +51,13 @@ abstract class AbstractChunkedController extends AbstractController
// get information about this chunked request
list($last, $uuid, $index, $orig) = $this->parseChunkedRequest($request);
- $uploaded = $chunkManager->addChunk($uuid, $index, $file, $orig);
+ $chunk = $chunkManager->addChunk($uuid, $index, $file, $orig);
+
+ $this->dispatchChunkEvents($chunk, $response, $request, $last);
// if all chunks collected and stored, proceed
// with reassembling the parts
- if($last)
- {
+ if ($last) {
// we'll take the first chunk and append the others to it
// this way we don't need another file in temporary space for assembling
$chunks = $chunkManager->getChunks($uuid);
@@ -66,11 +71,22 @@ abstract class AbstractChunkedController extends AbstractController
// validate this entity and upload on success
$this->validate($uploadedFile);
- $uploaded = $this->handleUpload($uploadedFile);
+ $uploaded = $this->handleUpload($uploadedFile, $response, $request);
$chunkManager->cleanup($path);
}
+ }
+
+ /**
+ * This function is a helper function which dispatches post chunk upload event.
+ */
+ protected function dispatchChunkEvents($uploaded, ResponseInterface $response, Request $request, $isLast)
+ {
+ $dispatcher = $this->container->get('event_dispatcher');
- return $uploaded;
+ // dispatch post upload event (both the specific and the general)
+ $postUploadEvent = new PostChunkUploadEvent($uploaded, $response, $request, $isLast, $this->type, $this->config);
+ $dispatcher->dispatch(UploadEvents::POST_CHUNK_UPLOAD, $postUploadEvent);
+ $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_CHUNK_UPLOAD, $this->type), $postUploadEvent);
}
}
\ No newline at end of file
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 49bce30..bcbe763 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -44,7 +44,7 @@ abstract class AbstractController
* @param UploadedFile The file to upload
* @return File the actual file
*/
- protected function handleUpload(UploadedFile $file)
+ protected function handleUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
$this->validate($file);
@@ -55,7 +55,7 @@ abstract class AbstractController
// perform the real upload
$uploaded = $this->storage->upload($file, $name);
- return $uploaded;
+ $this->dispatchEvents($uploaded, $response, $request);
}
/**
@@ -71,8 +71,7 @@ abstract class AbstractController
$dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent);
- if(!$this->config['use_orphanage'])
- {
+ if (!$this->config['use_orphanage']) {
// 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);
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index 981a4a4..e62ed31 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -23,15 +23,12 @@ class BlueimpController extends AbstractChunkedController
{
$file = $file[0];
- try
- {
- $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
- // dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response, $request);
- }
- catch(UploadException $e)
- {
+ try {
+ $chunked ?
+ $this->handleChunkedUpload($file, $response, $request) :
+ $this->handleUpload($file, $response, $request)
+ ;
+ } catch(UploadException $e) {
// return nothing
return new JsonResponse(array());
}
diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php
index c2e32bd..30a58a8 100644
--- a/Controller/FancyUploadController.php
+++ b/Controller/FancyUploadController.php
@@ -20,7 +20,7 @@ class FancyUploadController extends AbstractController
{
try
{
- $uploaded = $this->handleUpload($file);
+ $uploaded = $this->handleUpload($file, $response, $request);
// dispatch POST_PERSIST AND POST_UPLOAD events
$this->dispatchEvents($uploaded, $response, $request);
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 37aa0b4..c295234 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -25,10 +25,10 @@ class FineUploaderController extends AbstractChunkedController
{
try
{
- $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
- // dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response, $request);
+ $chunked ?
+ $this->handleChunkedUpload($file, $response, $request) :
+ $this->handleUpload($file, $response, $request)
+ ;
}
catch(UploadException $e)
{
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 1b06878..1b2ec9b 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -33,8 +33,6 @@ class MooUploadController extends AbstractChunkedController
try
{
- $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
// fill response object
$response = $this->response;
@@ -42,9 +40,11 @@ class MooUploadController extends AbstractChunkedController
$response->setSize($headers->get('content-length'));
$response->setName($headers->get('x-file-name'));
$response->setUploadedName($uploadFileName);
-
- // dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response, $request);
+
+ $chunked ?
+ $this->handleChunkedUpload($file, $response, $request) :
+ $this->handleUpload($file, $response, $request)
+ ;
}
catch(UploadException $e)
{
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index c445174..60501e9 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -23,10 +23,10 @@ class PluploadController extends AbstractChunkedController
{
try
{
- $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
- // dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response, $request);
+ $chunked ?
+ $this->handleChunkedUpload($file, $response, $request) :
+ $this->handleUpload($file, $response, $request)
+ ;
}
catch(UploadException $e)
{
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index ea18f52..88038a2 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -20,7 +20,7 @@ class UploadifyController extends AbstractController
{
try
{
- $uploaded = $this->handleUpload($file);
+ $uploaded = $this->handleUpload($file, $response, $request);
// dispatch POST_PERSIST AND POST_UPLOAD events
$this->dispatchEvents($uploaded, $response, $request);
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index b063e92..4475947 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -20,7 +20,7 @@ class YUI3Controller extends AbstractController
{
try
{
- $uploaded = $this->handleUpload($file);
+ $uploaded = $this->handleUpload($file, $response, $request);
// dispatch POST_PERSIST AND POST_UPLOAD events
$this->dispatchEvents($uploaded, $response, $request);
diff --git a/Event/PostChunkUploadEvent.php b/Event/PostChunkUploadEvent.php
new file mode 100644
index 0000000..7d5aacd
--- /dev/null
+++ b/Event/PostChunkUploadEvent.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Oneup\UploaderBundle\Event;
+
+use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\HttpFoundation\Request;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+class PostChunkUploadEvent extends Event
+{
+ protected $file;
+ protected $request;
+ protected $type;
+ protected $response;
+ protected $config;
+ protected $isLast;
+
+ public function __construct($chunk, ResponseInterface $response, Request $request, $isLast, $type, array $config)
+ {
+ $this->chunk = $chunk;
+ $this->request = $request;
+ $this->response = $response;
+ $this->isLast = $isLast;
+ $this->type = $type;
+ $this->config = $config;
+ }
+
+ public function getChunk()
+ {
+ return $this->chunk;
+ }
+
+ public function getRequest()
+ {
+ return $this->request;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function getResponse()
+ {
+ return $this->response;
+ }
+
+ public function getConfig()
+ {
+ return $this->config;
+ }
+
+ public function getIsLast()
+ {
+ return $this->isLast;
+ }
+
+ public function isLast()
+ {
+ return $this->isLast;
+ }
+}
diff --git a/Resources/doc/events.md b/Resources/doc/events.md
index 4edba13..a7a5ff5 100644
--- a/Resources/doc/events.md
+++ b/Resources/doc/events.md
@@ -6,6 +6,10 @@ For a list of general Events, you can always have a look at the `UploadEvents.ph
* `oneup_uploader.post_upload` Will be dispatched after a file has been uploaded and moved.
* `oneup_uploader.post_persist` The same as `oneup_uploader.post_upload` but will only be dispatched if no `Orphanage` is used.
+In case you are using chunked uploads on your frontend, you can listen to:
+
+* `oneup_uploader.post_chunk_upload` Will be dispatched after a chunk has been uploaded (including the last and assembled one)
+
Moreover this bundles also dispatches some special kind of generic events you can listen to.
* `oneup_uploader.post_upload.{mapping}`
diff --git a/Tests/Controller/AbstractChunkedUploadTest.php b/Tests/Controller/AbstractChunkedUploadTest.php
index a5dfc2e..dd434c6 100644
--- a/Tests/Controller/AbstractChunkedUploadTest.php
+++ b/Tests/Controller/AbstractChunkedUploadTest.php
@@ -2,7 +2,10 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Component\EventDispatcher\Event;
use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest;
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
abstract class AbstractChunkedUploadTest extends AbstractUploadTest
{
@@ -31,4 +34,38 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest
$this->assertEquals(120, $file->getSize());
}
}
+
+ public function testEvents()
+ {
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+
+ // prepare listener data
+ $me = $this;
+ $chunkCount = 0;
+ $uploadCount = 0;
+ $chunkSize = $this->getNextFile(0)->getSize();
+
+ for($i = 0; $i < $this->total; $i ++) {
+ // each time create a new client otherwise the events won't get dispatched
+ $client = static::createClient();
+ $dispatcher = $client->getContainer()->get('event_dispatcher');
+
+ $dispatcher->addListener(UploadEvents::POST_CHUNK_UPLOAD, function(PostChunkUploadEvent $event) use (&$chunkCount, $chunkSize, &$me) {
+ ++ $chunkCount;
+
+ $chunk = $event->getChunk();
+
+ $me->assertEquals($chunkSize, $chunk->getSize());
+ });
+
+ $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(Event $event) use (&$uploadCount) {
+ ++ $uploadCount;
+ });
+
+ $client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($this->getNextFile($i)));
+ }
+
+ $this->assertEquals($this->total, $chunkCount);
+ $this->assertEquals(1, $uploadCount);
+ }
}
diff --git a/UploadEvents.php b/UploadEvents.php
index b4e6aeb..73f5c93 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -4,7 +4,8 @@ namespace Oneup\UploaderBundle;
final class UploadEvents
{
- const POST_PERSIST = 'oneup_uploader.post_persist';
- const POST_UPLOAD = 'oneup_uploader.post_upload';
- const VALIDATION = 'oneup_uploader.validation';
+ const POST_PERSIST = 'oneup_uploader.post_persist';
+ const POST_UPLOAD = 'oneup_uploader.post_upload';
+ const POST_CHUNK_UPLOAD = 'oneup_uploader.post_chunk_upload';
+ const VALIDATION = 'oneup_uploader.validation';
}
\ No newline at end of file
| 0
|
afc344f16e95c15f41a165cc16b76c4492565f12
|
1up-lab
|
OneupUploaderBundle
|
2018
|
commit afc344f16e95c15f41a165cc16b76c4492565f12
Author: David Greminger <[email protected]>
Date: Tue Feb 6 19:09:57 2018 +0100
2018
diff --git a/Resources/meta/LICENSE b/LICENSE
similarity index 100%
rename from Resources/meta/LICENSE
rename to LICENSE
diff --git a/README.md b/README.md
index c5c5b05..5cad81a 100644
--- a/README.md
+++ b/README.md
@@ -47,7 +47,7 @@ License
This bundle is under the MIT license. See the complete license in the bundle:
- Resources/meta/LICENSE
+ LICENSE
Reporting an issue or a feature request
---------------------------------------
| 0
|
e5de39a8cf22dbc4a00faadaafb60824afd80ffe
|
1up-lab
|
OneupUploaderBundle
|
Rearranged configuration, so it will use the correct storage and filesystem layer.
|
commit e5de39a8cf22dbc4a00faadaafb60824afd80ffe
Author: Jim Schmid <[email protected]>
Date: Thu Mar 28 12:36:23 2013 +0100
Rearranged configuration, so it will use the correct storage and filesystem layer.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 10ffce6..7ca7320 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -79,6 +79,7 @@ class UploaderController implements UploadControllerInterface
throw new UploadException('This extension is not allowed.');
$name = $this->namer->name($file, $this->config['directory_prefix']);
+ $uploaded = $this->storage->upload($file, $name);
$postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array(
'use_orphanage' => $this->config['use_orphanage'],
@@ -88,8 +89,6 @@ class UploaderController implements UploadControllerInterface
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);
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index a90043b..9987fb7 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -18,7 +18,7 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
- ->scalarNode('storage')->defaultNull()->end()
+ ->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('maxage')->defaultValue(604800)->end()
->end()
->end()
@@ -26,7 +26,7 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
- ->scalarNode('storage')->defaultNull()->end()
+ ->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('maxage')->defaultValue(604800)->end()
->end()
->end()
@@ -36,7 +36,7 @@ class Configuration implements ConfigurationInterface
->requiresAtLeastOneElement()
->prototype('array')
->children()
- ->scalarNode('storage')->isRequired()->end()
+ ->scalarNode('filesystem')->isRequired()->end()
->arrayNode('allowed_types')
->prototype('scalar')->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 91e4520..1ca00ec 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -10,7 +10,7 @@ use Symfony\Component\DependencyInjection\Loader;
class OneupUploaderExtension extends Extension
{
- protected static $storageServices = array();
+ protected $storageServices = array();
public function load(array $configs, ContainerBuilder $container)
{
@@ -35,6 +35,7 @@ class OneupUploaderExtension extends Extension
}
$container->setParameter('oneup_uploader.orphanage', $config['orphanage']);
+ //$config['orphanage']['storage'] = $this->registerStorageService($container, $config['orphanage']);
// handle mappings
foreach($config['mappings'] as $key => $mapping)
@@ -46,22 +47,20 @@ class OneupUploaderExtension extends Extension
$mapping['max_size'] = $this->getMaxUploadSize($mapping['max_size']);
- $mapping['storage'] = $this->registerStorageService($container, $mapping);
- $this->registerServicesPerMap($container, $key, $mapping);
+ $mapping['storage'] = $this->registerStorageService($container, $mapping['filesystem']);
+ $this->registerServicesPerMap($container, $key, $mapping, $config);
}
}
- protected function registerStorageService(ContainerBuilder $container, $mapping)
+ protected function registerStorageService(ContainerBuilder $container, $filesystem)
{
- $storage = $mapping['storage'];
-
- // if service has already been declared, return
- if(in_array($storage, self::$storageServices))
- return;
-
// get base name of gaufrette storage
- $name = explode('.', $storage);
+ $name = explode('.', $filesystem);
$name = end($name);
+
+ // if service has already been declared, return
+ if(in_array($name, $this->storageServices))
+ return;
// create name of new storage service
$service = sprintf('oneup_uploader.storage.%s', $name);
@@ -70,37 +69,34 @@ class OneupUploaderExtension extends Extension
->register($service, $container->getParameter('oneup_uploader.storage.class'))
// inject the actual gaufrette filesystem
- ->addArgument(new Reference($storage))
+ ->addArgument(new Reference($filesystem))
;
- self::$storageServices[] = $name;
+ $this->storageServices[] = $name;
return $service;
}
- protected function registerServicesPerMap(ContainerBuilder $container, $type, $mapping)
+ protected function registerServicesPerMap(ContainerBuilder $container, $type, $mapping, $config)
{
if($mapping['use_orphanage'])
{
- // this mapping want to use the orphanage, so create a typed one
+ $orphanage = sprintf('oneup_uploader.orphanage.%s', $type);
+
+ // this mapping wants to use the orphanage, so create
+ // a masked filesystem for the controller
$container
- ->register(sprintf('oneup_uploader.orphanage.%s', $type), $container->getParameter('oneup_uploader.orphanage.class'))
+ ->register($orphanage, $container->getParameter('oneup_uploader.orphanage.class'))
+ ->addArgument(new Reference($config['orphanage']['filesystem']))
+ ->addArgument(new Reference($mapping['filesystem']))
->addArgument(new Reference('session'))
- ->addArgument(new Reference($mapping['storage']))
- ->addArgument($container->getParameter('oneup_uploader.orphanage'))
+ ->addArgument($config['orphanage'])
->addArgument($type)
;
- $container
- ->getDefinition('oneup_uploader.orphanage_manager')
-
- // add this service to the orphanage manager
- ->addMethodCall('addImplementation', array(
- $type,
- new Reference(sprintf('oneup_uploader.orphanage.%s', $type))
- ))
- ;
+ // switch storage of mapping to orphanage
+ $mapping['storage'] = $orphanage;
}
// create controllers based on mapping
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index a463039..f7f7aad 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -1,12 +1,15 @@
<?php
-namespace Oneup\UploaderBundle\Storage;
+namespace Oneup\UploaderBundle\Uploader\Storage;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
-use Gaufrette\Filesystem;
+use Gaufrette\Filesystem as GaufretteFilesystem;
-use Oneup\UploaderBundle\Storage\GaufretteStorage;
+use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage;
+use Oneup\UploaderBundle\Uploader\Storage\OrphanageStorageInterface;
class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInterface
{
@@ -15,7 +18,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter
protected $config;
protected $type;
- public function __construct(Gaufrette $orphanage, Gaufrette $filesystem, SessionInterface $session, $config, $type)
+ public function __construct(GaufretteFilesystem $orphanage, GaufretteFilesystem $filesystem, SessionInterface $session, $config, $type)
{
parent::__construct($orphanage);
| 0
|
b41e553fc30a31ed62eb15830da2115db42d711f
|
1up-lab
|
OneupUploaderBundle
|
Fixed dependency version and hopefully also the travis builds
|
commit b41e553fc30a31ed62eb15830da2115db42d711f
Author: Jim Schmid <[email protected]>
Date: Sat May 4 13:46:43 2013 +0200
Fixed dependency version and hopefully also the travis builds
diff --git a/composer.json b/composer.json
index 6142788..5a86478 100644
--- a/composer.json
+++ b/composer.json
@@ -19,15 +19,15 @@
"require-dev": {
"knplabs/gaufrette": "0.2.*@dev",
- "symfony/class-loader": "dev-master",
- "symfony/security-bundle": "dev-master",
- "symfony/monolog-bundle": "dev-master",
- "sensio/framework-extra-bundle": "dev-master",
+ "symfony/class-loader": "2.*",
+ "symfony/security-bundle": "2.*",
+ "symfony/monolog-bundle": "2.*",
+ "sensio/framework-extra-bundle": "2.*",
"jms/serializer-bundle": "dev-master",
- "symfony/yaml": "dev-master",
+ "symfony/yaml": "2.*",
"symfony/form": "2.*",
- "symfony/twig-bundle": "dev-master",
- "symfony/browser-kit": "dev-master"
+ "symfony/twig-bundle": "2.*",
+ "symfony/browser-kit": "2.*"
},
"suggest": {
| 0
|
3c394b6c7267b25b32732e16433340940674bcda
|
1up-lab
|
OneupUploaderBundle
|
Cleaned up used namespaces on two of the controllers.
|
commit 3c394b6c7267b25b32732e16433340940674bcda
Author: Jim Schmid <[email protected]>
Date: Thu Apr 11 20:43:21 2013 +0200
Cleaned up used namespaces on two of the controllers.
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index e2c6026..311c4fa 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -2,17 +2,11 @@
namespace Oneup\UploaderBundle\Controller;
-use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Event\PostPersistEvent;
-use Oneup\UploaderBundle\Event\PostUploadEvent;
-use Oneup\UploaderBundle\Controller\AbstractController;
-use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
class BlueimpController extends AbstractChunkedController
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 7fcbace..37aa0b4 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -2,17 +2,11 @@
namespace Oneup\UploaderBundle\Controller;
-use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
-use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Event\PostPersistEvent;
-use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Controller\AbstractChunkedController;
-use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
class FineUploaderController extends AbstractChunkedController
| 0
|
dc7c5f6361c073d428b569e8b14cb29e638607e4
|
1up-lab
|
OneupUploaderBundle
|
Update errorhandler.xml
Added plupload
|
commit dc7c5f6361c073d428b569e8b14cb29e638607e4
Author: MJBGO <[email protected]>
Date: Sun Nov 16 00:03:21 2014 +0100
Update errorhandler.xml
Added plupload
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index e684668..f0eb112 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>
</parameters>
<services>
@@ -16,7 +17,7 @@
<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.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>
| 0
|
9d8ebc416365c777fad846c1974be0e0af272e22
|
1up-lab
|
OneupUploaderBundle
|
min(\INF, somewhat below INF) was always returning INF.
|
commit 9d8ebc416365c777fad846c1974be0e0af272e22
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 16:05:36 2013 +0100
min(\INF, somewhat below INF) was always returning INF.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 04d1ca6..fc02a08 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -35,7 +35,7 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->scalarNode('storage')->isRequired()->end()
- ->scalarNode('max_size')->defaultNull()->end()
+ ->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->scalarNode('directory_prefix')->defaultNull()->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index e844c04..91e4520 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -44,7 +44,7 @@ class OneupUploaderExtension extends Extension
$mapping['directory_prefix'] = $key;
}
- $mapping['max_size'] = min(min($mapping['max_size'], ini_get('upload_max_filesize')), ini_get('post_max_size'));
+ $mapping['max_size'] = $this->getMaxUploadSize($mapping['max_size']);
$mapping['storage'] = $this->registerStorageService($container, $mapping);
$this->registerServicesPerMap($container, $key, $mapping);
@@ -128,4 +128,29 @@ class OneupUploaderExtension extends Extension
->setScope('request')
;
}
+
+ protected function getMaxUploadSize($input)
+ {
+ $input = $this->getValueInBytes($input);
+ $maxPost = $this->getValueInBytes(ini_get('upload_max_filesize'));
+ $maxFile = $this->getValueInBytes(ini_get('post_max_size'));
+
+ return min(min($input, $maxPost), $maxFile);
+ }
+
+ protected function getValueInBytes($input)
+ {
+ // see: http://www.php.net/manual/en/function.ini-get.php
+ $input = trim($input);
+ $last = strtolower($input[strlen($input) - 1]);
+
+ switch($last)
+ {
+ case 'g': $input *= 1024;
+ case 'm': $input *= 1024;
+ case 'k': $input *= 1024;
+ }
+
+ return $input;
+ }
}
\ No newline at end of file
diff --git a/Uploader/Orphanage/Orphanage.php b/Uploader/Orphanage/Orphanage.php
index 93b22e6..138d692 100644
--- a/Uploader/Orphanage/Orphanage.php
+++ b/Uploader/Orphanage/Orphanage.php
@@ -4,6 +4,7 @@ namespace Oneup\UploaderBundle\Uploader\Orphanage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
@@ -48,7 +49,7 @@ class Orphanage implements OrphanageInterface
foreach($finder as $file)
{
- $uploaded[] = $this->storage->upload($file);
+ $uploaded[] = $this->storage->upload(new UploadedFile($file->getPathname(), $file->getBasename(), null, null, null, true));
if(!$keep)
{
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 77464be..cfc5d35 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -2,7 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Symfony\Component\Finder\SplFileInfo as File;
+use Symfony\Component\HttpFoundation\File\File;
use Gaufrette\Stream\Local as LocalStream;
use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 0e9b830..1e4a287 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -2,10 +2,10 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Symfony\Component\Finder\SplFileInfo as File;
+use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
{
- public function upload(\SplFileInfo $file, $name);
+ public function upload(File $file, $name);
public function remove(File $file);
}
\ No newline at end of file
| 0
|
343bc34a0ea8922bf4c206f2b80137da3487933f
|
1up-lab
|
OneupUploaderBundle
|
Fixed a bug where chunked uploads where validated twice.
Fixes #36.
|
commit 343bc34a0ea8922bf4c206f2b80137da3487933f
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 19:57:15 2013 +0200
Fixed a bug where chunked uploads where validated twice.
Fixes #36.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index d7b0365..beabd2e 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -75,9 +75,6 @@ abstract class AbstractChunkedController extends AbstractController
// 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, $response, $request);
$chunkManager->cleanup($path);
diff --git a/Tests/Controller/AbstractChunkedUploadTest.php b/Tests/Controller/AbstractChunkedUploadTest.php
index bbc4bc9..e7c207d 100644
--- a/Tests/Controller/AbstractChunkedUploadTest.php
+++ b/Tests/Controller/AbstractChunkedUploadTest.php
@@ -6,6 +6,7 @@ use Symfony\Component\EventDispatcher\Event;
use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest;
use Oneup\UploaderBundle\Event\PostChunkUploadEvent;
use Oneup\UploaderBundle\Event\PreUploadEvent;
+use Oneup\UploaderBundle\Event\ValidationEvent;
use Oneup\UploaderBundle\UploadEvents;
abstract class AbstractChunkedUploadTest extends AbstractUploadTest
@@ -21,6 +22,7 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest
$me = $this;
$endpoint = $this->helper->endpoint($this->getConfigKey());
$basename = '';
+ $validationCount = 0;
for ($i = 0; $i < $this->total; $i ++) {
$file = $this->getNextFile($i);
@@ -38,12 +40,18 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest
$me->assertEquals($file->getBasename(), $basename);
});
+ $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) {
+ ++ $validationCount;
+ });
+
$client->request('POST', $endpoint, $this->getNextRequestParameters($i), array($file));
$response = $client->getResponse();
$this->assertTrue($response->isSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
}
+
+ $this->assertEquals(1, $validationCount);
foreach ($this->getUploadedFiles() as $file) {
$this->assertTrue($file->isFile());
| 0
|
03231b8e00cee33658243ec2071a1576280e86f5
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'fix/validation-event-bc'
|
commit 03231b8e00cee33658243ec2071a1576280e86f5
Merge: c71ac47 efaaa65
Author: David Greminger <[email protected]>
Date: Thu Nov 23 10:12:03 2017 +0100
Merge branch 'fix/validation-event-bc'
| 0
|
77ff8ab11fa0d8b3724be87529e9ce383bc5c730
|
1up-lab
|
OneupUploaderBundle
|
Removed unused prefix input variable.
|
commit 77ff8ab11fa0d8b3724be87529e9ce383bc5c730
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 19:52:12 2013 +0200
Removed unused prefix input variable.
diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php
index 1063205..af408d2 100644
--- a/Uploader/Naming/UniqidNamer.php
+++ b/Uploader/Naming/UniqidNamer.php
@@ -7,7 +7,7 @@ use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
class UniqidNamer implements NamerInterface
{
- public function name(UploadedFile $file, $prefix = null)
+ public function name(UploadedFile $file)
{
return sprintf('%s.%s', uniqid(), $file->guessExtension());
}
| 0
|
8263926a658f9f50add73c1278871e68ee6d8357
|
1up-lab
|
OneupUploaderBundle
|
version compare
|
commit 8263926a658f9f50add73c1278871e68ee6d8357
Author: Martin Aarhof <[email protected]>
Date: Wed Dec 9 16:59:23 2015 +0100
version compare
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index d20bf8f..5374a8c 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -207,7 +207,7 @@ abstract class AbstractController
*/
protected function getRequest()
{
- if (version_compare(Kernel::VERSION, '2.4') === -1) {
+ if (version_compare(Kernel::VERSION, '2.4', '<=')) {
return $this->container->get('request');
}
| 0
|
a4eca39e7ea9af1950855c031887d6df96f34906
|
1up-lab
|
OneupUploaderBundle
|
Add Response Object to ValidationEvent to be able to send error messages back to client
|
commit a4eca39e7ea9af1950855c031887d6df96f34906
Author: derpue <[email protected]>
Date: Wed Nov 8 09:58:47 2017 +0100
Add Response Object to ValidationEvent to be able to send error messages back to client
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 75d3518..fac6246 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -113,7 +113,7 @@ abstract class AbstractController
if (!($file instanceof FileInterface)) {
$file = new FilesystemFile($file);
}
- $this->validate($file);
+ $this->validate($file, $response, $request);
$this->dispatchPreUploadEvent($file, $response, $request);
@@ -169,10 +169,10 @@ abstract class AbstractController
}
}
- protected function validate(FileInterface $file)
+ protected function validate(FileInterface $file,ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
- $event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
+ $event = new ValidationEvent($file, $response, $request, $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index 15e1c18..4240059 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -3,6 +3,7 @@
namespace Oneup\UploaderBundle\Event;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
@@ -12,13 +13,15 @@ class ValidationEvent extends Event
protected $config;
protected $type;
protected $request;
+ protected $response;
- public function __construct(FileInterface $file, Request $request, array $config, $type)
+ public function __construct(FileInterface $file, ResponseInterface $response, Request $request, array $config, $type)
{
$this->file = $file;
$this->config = $config;
$this->type = $type;
$this->request = $request;
+ $this->response = $response;
}
public function getFile()
@@ -40,4 +43,10 @@ class ValidationEvent extends Event
{
return $this->request;
}
+
+ public function getResponse()
+ {
+ return $this->response;
+ }
+
}
| 0
|
f1f84bca6eae7b49f47e43ee21b2bf0a4605e2f8
|
1up-lab
|
OneupUploaderBundle
|
better file size calculation for gaufrette files
|
commit f1f84bca6eae7b49f47e43ee21b2bf0a4605e2f8
Author: mitom <[email protected]>
Date: Thu Oct 10 13:46:35 2013 +0200
better file size calculation for gaufrette files
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 1cf8414..c11e014 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -27,6 +27,7 @@ class Configuration implements ConfigurationInterface
->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
+ ->scalarNode('stream_wrapper')->defaultNull()->end()
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->scalarNode('prefix')->defaultValue('chunks')->end()
->end()
@@ -68,6 +69,7 @@ class Configuration implements ConfigurationInterface
->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
+ ->scalarNode('stream_wrapper')->defaultNull()->end()
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 6a8bff1..5f5ece9 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -116,7 +116,13 @@ class OneupUploaderExtension extends Extension
->addArgument($config['directory'])
;
} else {
- $this->registerGaufretteStorage('oneup_uploader.chunks_storage', $storageClass, $config['filesystem'], $config['sync_buffer_size'], $config['prefix']);
+ $this->registerGaufretteStorage(
+ 'oneup_uploader.chunks_storage',
+ $storageClass, $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper'],
+ $config['prefix']
+ );
// enforce load distribution when using gaufrette as chunk
// torage to avoid moving files forth-and-back
@@ -150,7 +156,13 @@ class OneupUploaderExtension extends Extension
}
if ($config['type'] == 'gaufrette') {
- $this->registerGaufretteStorage($storageName, $storageClass, $config['filesystem'], $config['sync_buffer_size']);
+ $this->registerGaufretteStorage(
+ $storageName,
+ $storageClass,
+ $config['filesystem'],
+ $config['sync_buffer_size'],
+ $config['stream_wrapper']
+ );
}
$storageService = new Reference($storageName);
@@ -176,7 +188,7 @@ class OneupUploaderExtension extends Extension
return $storageService;
}
- protected function registerGaufretteStorage($key, $class, $filesystem, $buffer, $prefix = '')
+ protected function registerGaufretteStorage($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.');
@@ -188,6 +200,7 @@ class OneupUploaderExtension extends Extension
->register($key, $class)
->addArgument(new Reference($filesystem))
->addArgument($this->getValueInBytes($buffer))
+ ->addArgument($streamWrapper)
->addArgument($prefix)
;
}
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 00b0031..98707b7 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -14,8 +14,9 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
{
protected $unhandledChunk;
protected $prefix;
+ protected $streamWrapperPrefix;
- public function __construct(Filesystem $filesystem, $bufferSize, $prefix)
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
{
if (!($filesystem->getAdapter() instanceof StreamFactory)) {
throw new \InvalidArgumentException('The filesystem used as chunk storage must implement StreamFactory');
@@ -23,6 +24,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
$this->filesystem = $filesystem;
$this->bufferSize = $bufferSize;
$this->prefix = $prefix;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
}
public function clear($maxAge)
@@ -128,7 +130,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
return $uploaded;
}
- return new GaufretteFile($uploaded, $this->filesystem);
+ return new GaufretteFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
}
public function cleanup($path)
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
index fd0701a..0c73be5 100644
--- a/Uploader/File/GaufretteFile.php
+++ b/Uploader/File/GaufretteFile.php
@@ -2,17 +2,21 @@
namespace Oneup\UploaderBundle\Uploader\File;
+use Gaufrette\Adapter\StreamFactory;
use Gaufrette\File;
use Gaufrette\Filesystem;
class GaufretteFile extends File implements FileInterface
{
protected $filesystem;
+ protected $streamWrapperPrefix;
+ protected $mimeType;
- public function __construct(File $file, Filesystem $filesystem)
+ public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
{
parent::__construct($file->getKey(), $filesystem);
$this->filesystem = $filesystem;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
}
/**
@@ -20,14 +24,28 @@ class GaufretteFile extends File implements FileInterface
*
* !! WARNING !!
* Calling this loads the entire file into memory,
- * in case of bigger files this could throw exceptions,
+ * unless it is on a stream-capable filesystem.
+ * In case of bigger files this could throw exceptions,
* and will have heavy performance footprint.
* !! ------- !!
*
- * TODO mock/calculate the size if possible and use that instead?
*/
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
+ if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->size) {
+ if ($this->streamWrapperPrefix) {
+ try {
+ $this->setSize(filesize($this->streamWrapperPrefix.$this->getKey()));
+ } catch (\Exception $e) {
+ // 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.
+ }
+ }
+ }
+
return parent::getSize();
}
@@ -51,11 +69,26 @@ class GaufretteFile extends File implements FileInterface
*/
public function getMimeType()
{
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ // 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.
+ if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->mimeType) {
+ if ($this->streamWrapperPrefix) {
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ $this->mimeType = finfo_file($finfo, $this->streamWrapperPrefix.$this->getKey());
+ finfo_close($finfo);
+ }
+ }
- return finfo_file($finfo, $this->getKey());
+ return $this->mimeType;
}
+ /**
+ * Now that we may be able to get the mime-type the extension
+ * COULD be guessed based on that, but it would be even less
+ * accurate as mime-types can have multiple extensions
+ *
+ * @return mixed
+ */
public function getExtension()
{
return pathinfo($this->getKey(), PATHINFO_EXTENSION);
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index c69e3b2..315b92b 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -10,11 +10,13 @@ use Oneup\UploaderBundle\Uploader\Gaufrette\StreamManager;
class GaufretteStorage extends StreamManager implements StorageInterface
{
+ protected $streamWrapperPrefix;
- public function __construct(Filesystem $filesystem, $bufferSize)
+ public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix)
{
$this->filesystem = $filesystem;
$this->bufferSize = $bufferSize;
+ $this->streamWrapperPrefix = $streamWrapperPrefix;
}
public function upload(FileInterface $file, $name, $path = null)
@@ -29,7 +31,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface
if ($file->getFilesystem() == $this->filesystem) {
$file->getFilesystem()->rename($file->getKey(), $path);
- return $this->filesystem->get($path);
+ return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
}
@@ -40,7 +42,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface
$this->stream($file, $dst);
- return $this->filesystem->get($path);
+ return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix);
}
}
| 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
|
f4ee50f60e1e19cbd1ad8671e33afbf46e88df6e
|
1up-lab
|
OneupUploaderBundle
|
Added the possibility to whitelist file extensions per mapping.
|
commit f4ee50f60e1e19cbd1ad8671e33afbf46e88df6e
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 16:36:25 2013 +0100
Added the possibility to whitelist file extensions per mapping.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 722172d..3efe927 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Controller;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Finder\Finder;
@@ -34,11 +35,15 @@ class UploaderController implements UploadControllerInterface
foreach($files as $file)
{
- // some error handling
- if($file->getClientSize() > $this->config['max_size'])
- return new JsonResponse(array('error' => 'File is too large'));
-
- $ret = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+ try
+ {
+ $ret = $totalParts > 1 ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+ }
+ catch(UploadException $e)
+ {
+ // an error happended, return this error message.
+ return new JsonResponse(array('error' => $e->getMessage()));
+ }
}
return $ret;
@@ -46,6 +51,17 @@ class UploaderController implements UploadControllerInterface
protected function handleUpload(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('File is too large.');
+
+ $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_types']) > 0 && !in_array($extension, $this->config['allowed_types']))
+ throw new UploadException('This extension is not allowed.');
+
$name = $this->namer->name($file, $this->config['directory_prefix']);
$postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array(
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index fc02a08..d5a0663 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -35,6 +35,9 @@ class Configuration implements ConfigurationInterface
->prototype('array')
->children()
->scalarNode('storage')->isRequired()->end()
+ ->arrayNode('allowed_types')
+ ->prototype('scalar')->end()
+ ->end()
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->scalarNode('directory_prefix')->defaultNull()->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
| 0
|
2f9cd2b4dd6a67a93ca49b9cc5c7c9aab8bd6fba
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #224 from JHGitty/patch-6
Add warning to custom namer doc
|
commit 2f9cd2b4dd6a67a93ca49b9cc5c7c9aab8bd6fba
Merge: 18a7f31 4c51d95
Author: Jim Schmid <[email protected]>
Date: Mon Feb 8 08:27:01 2016 +0100
Merge pull request #224 from JHGitty/patch-6
Add warning to custom namer doc
| 0
|
e3026276c3009cd92bb77726beae4144444ca53d
|
1up-lab
|
OneupUploaderBundle
|
Added service_container to the list of arguments of the default UploaderController.
|
commit e3026276c3009cd92bb77726beae4144444ca53d
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 19:09:38 2013 +0100
Added service_container to the list of arguments of the default UploaderController.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index c33e281..a511e00 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -5,14 +5,20 @@ namespace Oneup\UploaderBundle\Controller;
class UploaderController
{
protected $mappings;
+ protected $container;
- public function __construct($mappings)
+ public function __construct($mappings, $container)
{
- $this->mappings = $mappings;
+ $this->mappings = $mappings;
+ $this->container = $container;
}
public function upload($mapping)
{
+ $container = $this->container;
+ $config = $this->mappings[$mapping];
+ if(!$container->has($config['storage']))
+ throw new \InvalidArgumentException(sprintf('The storage service "%s" must be defined.'));
}
}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index e440170..dc79a38 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -17,6 +17,7 @@
<!-- controller -->
<service id="oneup_uploader.controller" class="%oneup_uploader.controller.class%">
<argument>%oneup_uploader.mappings%</argument>
+ <argument type="service" id="service_container" />
</service>
<!-- routing -->
| 0
|
283c3ae9f278393e76d242c786107d25a2f78a52
|
1up-lab
|
OneupUploaderBundle
|
Made the whole Orphenage-thingy work.
|
commit 283c3ae9f278393e76d242c786107d25a2f78a52
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 16:45:07 2013 +0100
Made the whole Orphenage-thingy work.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index e9e67b3..b07d7a2 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -78,6 +78,29 @@ class OneupUploaderExtension extends Extension
protected function registerServicesPerMap(ContainerBuilder $container, $type, $mapping)
{
+ if($mapping['use_orphanage'])
+ {
+ // this mapping want to use the orphanage, so create a typed one
+ $container
+ ->register(sprintf('oneup_uploader.orphanage.%s', $type), $container->getParameter('oneup_uploader.orphanage.class'))
+
+ ->addArgument(new Reference('session'))
+ ->addArgument(new Reference($mapping['storage']))
+ ->addArgument($container->getParameter('oneup_uploader.orphanage'))
+ ->addArgument($type)
+ ;
+
+ $container
+ ->getDefinition('oneup_uploader.orphanage_manager')
+
+ // add this service to the orphanage manager
+ ->addMethodCall('addImplementation', array(
+ $type,
+ new Reference(sprintf('oneup_uploader.orphanage.%s', $type))
+ ))
+ ;
+ }
+
// create controllers based on mapping
$container
->register(sprintf('oneup_uploader.controller.%s', $type), $container->getParameter('oneup_uploader.controller.class'))
diff --git a/EventListener/OrphanageListener.php b/EventListener/OrphanageListener.php
index 15bd7c9..f830b39 100644
--- a/EventListener/OrphanageListener.php
+++ b/EventListener/OrphanageListener.php
@@ -7,15 +7,15 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\UploadEvents;
-use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface;
+use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManagerInterface;
class OrphanageListener implements EventSubscriberInterface
{
- protected $orphanage;
+ protected $manager;
- public function __construct(OrphanageInterface $orphanage)
+ public function __construct(OrphanageManagerInterface $manager)
{
- $this->orphanage = $orphanage;
+ $this->manager = $manager;
}
public function add(PostUploadEvent $event)
@@ -23,11 +23,12 @@ class OrphanageListener implements EventSubscriberInterface
$options = $event->getOptions();
$request = $event->getRequest();
$file = $event->getFile();
+ $type = $event->getType();
if(!array_key_exists('use_orphanage', $options) || !$options['use_orphanage'])
return;
- $this->orphanage->addFile($file, $options['file_name']);
+ $this->manager->get($type)->addFile($file, $options['file_name']);
}
public static function getSubscribedEvents()
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index f7efd15..04ce1ea 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -15,17 +15,13 @@
</parameters>
<services>
- <service id="oneup_uploader.chunks.manager" class="%oneup_uploader.chunks.manager.class%">
+ <service id="oneup_uploader.chunks_manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
</service>
<!-- orphanage -->
- <service id="oneup_uploader.orphanage.manager" class="%oneup_uploader.orphanage.manager.class%">
- <argument>%oneup_uploader.orphanage%</argument>
- </service>
-
- <service id="oneup_uploader.orphanage" class="%oneup_uploader.orphanage.class%">
- <argument type="service" id="session" />
+ <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%">
+ <argument type="service" id="service_container" />
<argument>%oneup_uploader.orphanage%</argument>
</service>
@@ -39,7 +35,7 @@
<!-- events -->
<service id="oneup_uploader.listener.orphanage" class="%oneup_uploader.listener.session.class%">
- <argument type="service" id="oneup_uploader.orphanage" />
+ <argument type="service" id="oneup_uploader.orphanage_manager" />
<tag name="kernel.event_subscriber" />
</service>
diff --git a/Uploader/Orphanage/Orphanage.php b/Uploader/Orphanage/Orphanage.php
index 4a7971d..93b22e6 100644
--- a/Uploader/Orphanage/Orphanage.php
+++ b/Uploader/Orphanage/Orphanage.php
@@ -2,20 +2,27 @@
namespace Oneup\UploaderBundle\Uploader\Orphanage;
-
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface;
class Orphanage implements OrphanageInterface
{
protected $session;
+ protected $storage;
+ protected $namer;
protected $config;
+ protected $type;
- public function __construct(SessionInterface $session, $config)
+ public function __construct(SessionInterface $session, StorageInterface $storage, $config, $type)
{
$this->session = $session;
- $this->config = $config;
+ $this->storage = $storage;
+ $this->config = $config;
+ $this->type = $type;
}
public function addFile(File $file, $name)
@@ -27,12 +34,40 @@ class Orphanage implements OrphanageInterface
return $file->move($this->getPath(), $name);
}
- public function getFiles()
+ public function uploadFiles($keep = false)
{
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ if(!$system->exists($this->getPath()))
+ return array();
+
+ $finder->in($this->getPathRelativeToSession())->files();
+ $uploaded = array();
+
+ foreach($finder as $file)
+ {
+ $uploaded[] = $this->storage->upload($file);
+
+ if(!$keep)
+ {
+ $system->remove($file);
+ }
+ }
+
+ return $uploaded;
}
protected function getPath()
+ {
+ $id = $this->session->getId();
+ $path = sprintf('%s/%s/%s', $this->config['directory'], $id, $this->type);
+
+ return $path;
+ }
+
+ protected function getPathRelativeToSession()
{
$id = $this->session->getId();
$path = sprintf('%s/%s', $this->config['directory'], $id);
diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php
index 9657d7a..e993938 100644
--- a/Uploader/Orphanage/OrphanageManager.php
+++ b/Uploader/Orphanage/OrphanageManager.php
@@ -9,9 +9,13 @@ use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManagerInterface;
class OrphanageManager implements OrphanageManagerInterface
{
- public function __construct($configuration)
+ protected $orphanages;
+
+ public function __construct($container, $configuration)
{
+ $this->container = $container;
$this->configuration = $configuration;
+ $this->orphanages = array();
}
public function warmup()
@@ -42,4 +46,22 @@ class OrphanageManager implements OrphanageManagerInterface
$system->remove($file);
}
}
+
+ public function get($type)
+ {
+ return $this->getImplementation($type);
+ }
+
+ public function getImplementation($type)
+ {
+ if(!array_key_exists($type, $this->orphanages))
+ throw new \InvalidArgumentException(sprintf('No Orphanage implementation of type "%s" found.', $type));
+
+ return $this->orphanages[$type];
+ }
+
+ public function addImplementation($type, OrphanageInterface $orphanage)
+ {
+ $this->orphanages[$type] = $orphanage;
+ }
}
\ No newline at end of file
diff --git a/Uploader/Orphanage/OrphanageManagerInterface.php b/Uploader/Orphanage/OrphanageManagerInterface.php
index 52c3807..01bf0dc 100644
--- a/Uploader/Orphanage/OrphanageManagerInterface.php
+++ b/Uploader/Orphanage/OrphanageManagerInterface.php
@@ -2,8 +2,12 @@
namespace Oneup\UploaderBundle\Uploader\Orphanage;
+use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface;
+
interface OrphanageManagerInterface
{
public function warmup();
public function clear();
+ public function getImplementation($type);
+ public function addImplementation($type, OrphanageInterface $orphanage);
}
\ No newline at end of file
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 4268814..77464be 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -2,7 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Symfony\Component\HttpFoundation\File\File;
+use Symfony\Component\Finder\SplFileInfo as File;
use Gaufrette\Stream\Local as LocalStream;
use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
@@ -17,10 +17,11 @@ class GaufretteStorage implements StorageInterface
$this->filesystem = $filesystem;
}
- public function upload(File $file, $name)
+ public function upload(File $file, $name = null)
{
$path = $file->getPathname();
-
+ $name = is_null($name) ? $file->getRelativePathname() : $name;
+
$src = new LocalStream($path);
$dst = $this->filesystem->createStream($name);
@@ -28,7 +29,7 @@ class GaufretteStorage implements StorageInterface
// because the stream-mode is not able to create
// subdirectories.
if(!$this->filesystem->has($name))
- $this->filesystem->createFile($name);
+ $this->filesystem->write($name, '', true);
$src->open(new StreamMode('rb+'));
$dst->open(new StreamMode('ab+'));
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 1e4a287..0e9b830 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -2,10 +2,10 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Symfony\Component\HttpFoundation\File\File;
+use Symfony\Component\Finder\SplFileInfo as File;
interface StorageInterface
{
- public function upload(File $file, $name);
+ public function upload(\SplFileInfo $file, $name);
public function remove(File $file);
}
\ No newline at end of file
| 0
|
1508dfbe4ae522014b68e0b62850acced526c2eb
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #80 from mitom/master
[Critical] fixed uploads not being retryable if there was an error
|
commit 1508dfbe4ae522014b68e0b62850acced526c2eb
Merge: 46ed8f7 b915fe5
Author: Jim Schmid <[email protected]>
Date: Mon Dec 16 06:45:03 2013 -0800
Merge pull request #80 from mitom/master
[Critical] fixed uploads not being retryable if there was an error
| 0
|
725490c30f1eef6774e1f08e719ba128cf94d984
|
1up-lab
|
OneupUploaderBundle
|
Fix CS.
|
commit 725490c30f1eef6774e1f08e719ba128cf94d984
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 14:03:06 2013 +0100
Fix CS.
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 4d1077d..74ced99 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -37,7 +37,6 @@ class ChunkManager implements ChunkManagerInterface
return;
}
-
foreach($finder as $file)
{
$system->remove($file);
| 0
|
2bcb029c5c94479fd0e6648945f29d31b084a55d
|
1up-lab
|
OneupUploaderBundle
|
removed PHP 5.3 support
|
commit 2bcb029c5c94479fd0e6648945f29d31b084a55d
Author: Martin Aarhof <[email protected]>
Date: Fri Jan 22 04:08:18 2016 +0100
removed PHP 5.3 support
diff --git a/.travis.yml b/.travis.yml
index 1564c0e..c044e39 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
language: php
php:
- - 5.3
- 5.4
- 5.5
- 5.6
| 0
|
e5a1fc3b8ff68fdb9853effb2c3d3f548913a963
|
1up-lab
|
OneupUploaderBundle
|
Readded FineUploaderResponse
|
commit e5a1fc3b8ff68fdb9853effb2c3d3f548913a963
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 21:45:08 2013 +0200
Readded FineUploaderResponse
diff --git a/Uploader/Response/FineUploaderResponse.php b/Uploader/Response/FineUploaderResponse.php
new file mode 100644
index 0000000..489ae56
--- /dev/null
+++ b/Uploader/Response/FineUploaderResponse.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
+
+class FineUploaderResponse implements ResponseInterface
+{
+ protected $success;
+ protected $error;
+ protected $data;
+
+ public function __construct()
+ {
+ $this->success = true;
+ $this->error = null;
+ $this->data = array();
+ }
+
+ public function assemble()
+ {
+ // explicitly overwrite success and error key
+ // as these keys are used internaly by the
+ // frontend uploader
+ $data = $this->data;
+ $data['success'] = $this->success;
+
+ if($this->success)
+ unset($data['error']);
+
+ if(!$this->success)
+ $data['error'] = $this->error;
+
+ return $data;
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value;
+ }
+ public function offsetExists($offset)
+ {
+ return isset($this->data[$offset]);
+ }
+ public function offsetUnset($offset)
+ {
+ unset($this->data[$offset]);
+ }
+
+ public function offsetGet($offset)
+ {
+ return isset($this->data[$offset]) ? $this->data[$offset] : null;
+ }
+
+ public function setSuccess($success)
+ {
+ $this->success = (bool) $success;
+
+ return $this;
+ }
+
+ public function getSuccess()
+ {
+ return $this->success;
+ }
+
+ public function setError($msg)
+ {
+ $this->error = $msg;
+
+ return $this;
+ }
+
+ public function getError()
+ {
+ return $this->error;
+ }
+}
\ No newline at end of file
| 0
|
f60ff27889f1889c4908cd043beca1291d8a3f89
|
1up-lab
|
OneupUploaderBundle
|
Added a BlueimpController skeleton.
|
commit f60ff27889f1889c4908cd043beca1291d8a3f89
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 21:07:07 2013 +0200
Added a BlueimpController skeleton.
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
new file mode 100644
index 0000000..064b95f
--- /dev/null
+++ b/Controller/BlueimpController.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostPersistEvent;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\Controller\UploadControllerInterface;
+use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
+
+class FineUploaderController implements UploadControllerInterface
+{
+ protected $container;
+ protected $storage;
+ protected $config;
+ protected $type;
+
+ public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
+ {
+ $this->container = $container;
+ $this->storage = $storage;
+ $this->config = $config;
+ $this->type = $type;
+ }
+
+ public function upload()
+ {
+
+ }
+}
\ No newline at end of file
| 0
|
b1b00b3d69f94e8d895c2245385fe7cc8a3c1bbf
|
1up-lab
|
OneupUploaderBundle
|
Dispatch generic events using the mapping key in the event name.
|
commit b1b00b3d69f94e8d895c2245385fe7cc8a3c1bbf
Author: Jim Schmid <[email protected]>
Date: Thu Apr 18 19:01:20 2013 +0200
Dispatch generic events using the mapping key in the event name.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 07836d0..75e1cc8 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -50,15 +50,19 @@ abstract class AbstractController
{
$dispatcher = $this->container->get('event_dispatcher');
- // dispatch post upload event
+ // dispatch post upload event (both the specific and the general)
$postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
$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
+ // 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);
}
}
@@ -81,4 +85,4 @@ abstract class AbstractController
throw new UploadException('error.blacklist');
}
-}
\ No newline at end of file
+}
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 1163dee..dcb0343 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -6,6 +6,8 @@ In almost every use case you need to further process uploaded files. For example
* `PostUploadEvent`: Will be dispatched after a file has been uploaded and moved.
* `PostPersistEvent`: The same as `PostUploadEvent` but will only be dispatched if no `Orphanage` is used.
+> You'll find more information on this topic in the [Event documentation](events.md)
+
To listen to one of these events you need to create an `EventListener`.
```php
diff --git a/Resources/doc/events.md b/Resources/doc/events.md
new file mode 100644
index 0000000..30244f2
--- /dev/null
+++ b/Resources/doc/events.md
@@ -0,0 +1,17 @@
+OneupUploaderBundle Events
+==========================
+
+For a list of general Events, you can always have a look at the `UploadEvents.php` file in the root of this bundle.
+
+* `oneup_uploader.post_upload` Will be dispatched after a file has been uploaded and moved.
+* `oneup_uploader.post_persist` The same as `oneup_uploader.post_upload` but will only be dispatched if no `Orphanage` is used.
+
+Moreover this bundles also dispatches some special kind of generic events you can listen to.
+
+* `oneup_uploader.post_upload.{mapping}`
+* `oneup_uploader.post_persist.{mapping}`
+
+The `{mapping}` part is the key of your configured mapping. The examples in this documentation always uses the mapping key `gallery`. So the dispatched event would be called `oneup_uploader.post_upload.gallery`.
+Using these generic events can save you some time and coding lines, as you don't have to check for the correct type in the `EventListener`.
+
+See the [custom_logic.md](custom logic section) of this documentation for specific examples on how to use these Events.
\ No newline at end of file
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index a8fe6f9..00bc4ae 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -120,6 +120,7 @@ some more advanced features.
* [Include your own Namer](custom_namer.md)
* [Testing this bundle](testing.md)
* [Support a custom uploader](custom_uploader.md)
+* [General/Generic Events](events.md)
* [Configuration Reference](configuration_reference.md)
## FAQ
| 0
|
99deda33158bd6279b3af4f488007a6541be4ad1
|
1up-lab
|
OneupUploaderBundle
|
Added function comments for AbstractChunkedController.
|
commit 99deda33158bd6279b3af4f488007a6541be4ad1
Author: Jim Schmid <[email protected]>
Date: Fri May 31 18:14:54 2013 +0200
Added function comments for AbstractChunkedController.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index f32cc56..3bd1247 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -8,8 +8,33 @@ use Oneup\UploaderBundle\Controller\AbstractController;
abstract class AbstractChunkedController extends AbstractController
{
+ /**
+ * Parses a chunked request and return relevant information.
+ *
+ * This function must return an array containing the following
+ * keys and their corresponding values:
+ * - last: Wheter this is the last chunk of the uploaded file
+ * - uuid: A unique id which distinguishes two uploaded files
+ * This uuid must stay the same among the task of
+ * uploading a chunked file.
+ * - index: A numerical representation of the currently uploaded
+ * chunk. Must be higher that in the previous request.
+ * - orig: The original file name.
+ *
+ * @param request The request object
+ */
abstract protected function parseChunkedRequest(Request $request);
+ /**
+ * This function will be called in order to upload and save an
+ * uploaded chunk.
+ *
+ * This function also calls the chunk manager if the function
+ * parseChunkedRequest has set true for the "last" key of the
+ * returned array.
+ *
+ * @param file The uploaded chunk.
+ */
protected function handleChunkedUpload(UploadedFile $file)
{
// get basic container stuff
| 0
|
1bf94c18f75f222e8f7852d45d3ecfa7798c7106
|
1up-lab
|
OneupUploaderBundle
|
Rename branch master to main
|
commit 1bf94c18f75f222e8f7852d45d3ecfa7798c7106
Author: David Greminger <[email protected]>
Date: Mon Feb 5 13:14:22 2024 +0100
Rename branch master to main
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c78c8b7..24eb020 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -4,7 +4,7 @@ on:
pull_request: ~
push:
branches:
- - master
+ - main
tags:
- '*'
diff --git a/README.md b/README.md
index c59bc59..a71ab81 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ OneupUploaderBundle
[](https://github.com/1up-lab/OneupUploaderBundle/actions)
[](https://packagist.org/packages/oneup/uploader-bundle)
-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/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/main/doc/custom_uploader.md).
* [Dropzone](http://www.dropzonejs.com/)
* [jQuery File Upload](http://blueimp.github.io/jQuery-File-Upload/)
@@ -30,7 +30,7 @@ Documentation
The entry point of the documentation can be found in the file `docs/index.md`
-[Read the documentation for master](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/index.md)
+[Read the documentation for main](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/index.md)
Upgrade Notes
-------------
@@ -41,8 +41,8 @@ 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/doc/custom_error_handler.md).
-* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/doc/custom_logic.md#using-chunked-uploads).
+* 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/main/doc/custom_error_handler.md).
+* Event dispatching [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/a408548b241f47af3539b2137c1817a21a51fde9) in Version **0.9.5**. The dispatching is now handled in the `upload*` functions. So if you have created your own implementation, be sure to remove the call to the `dispatchEvents` function, otherwise it will be called twice. Furthermore no `POST_UPLOAD` event will be fired anymore after uploading a chunk. You can get more information on this topic in the [documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/main/doc/custom_logic.md#using-chunked-uploads).
* Event names [changed](https://github.com/1up-lab/OneupUploaderBundle/commit/f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be) in Version **0.9.3**, update your EventListener accordingly.
License
diff --git a/doc/frontend_blueimp.md b/doc/frontend_blueimp.md
index db30fdf..86ba4ef 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/master/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/Resources/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 c6b2c64..e1cb572 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/master/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/Resources/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 09896f0..5cf7bb5 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/master/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/Resources/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 8519f97..0976de5 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/master/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/Resources/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 6a1db2c..68e1ac0 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/master/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/Resources/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 0c2e01d..3dac128 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/master/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/Resources/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 ec7bcc9..0e005d9 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/master/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/Resources/doc/index.md#next-steps).
* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
| 0
|
b1543bdbbc86fe874421e09b98c3310312eb17ba
|
1up-lab
|
OneupUploaderBundle
|
Fixed typo in orphanage.md
|
commit b1543bdbbc86fe874421e09b98c3310312eb17ba
Author: FunkeMT <[email protected]>
Date: Mon Feb 17 16:40:50 2014 +0100
Fixed typo in orphanage.md
diff --git a/Resources/doc/orphanage.md b/Resources/doc/orphanage.md
index b4051a2..b489535 100644
--- a/Resources/doc/orphanage.md
+++ b/Resources/doc/orphanage.md
@@ -76,7 +76,7 @@ and default to ```orphanage```.
## Clean up
The `OrphanageManager` can be forced to clean up orphans by using the command provided by the OneupUploaderBundle.
- $> php app/console oneup:uploader:clean-orphans
+ $> php app/console oneup:uploader:clear-orphans
This parameter will clean all orphaned files older than the `maxage` value in your configuration.
| 0
|
9943e13681bdb6620bc7f1f7b95804e399b5cdff
|
1up-lab
|
OneupUploaderBundle
|
Move files to orphanage if mentioned in config.
|
commit 9943e13681bdb6620bc7f1f7b95804e399b5cdff
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 12:04:11 2013 +0100
Move files to orphanage if mentioned in config.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index afa18b3..7c2b423 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -6,6 +6,7 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
@@ -38,16 +39,20 @@ class UploaderController implements UploadControllerInterface
{
$name = $this->namer->name($file, $this->config['directory_prefix']);
+ $postUploadEvent = new PostUploadEvent($file, $this->request, 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);
// dispatch post upload event
- $event = new PostPersistEvent($uploaded, $this->request);
- $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $event);
+ $postPersistEvent = new PostPersistEvent($uploaded, $this->request);
+ $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
}
-
-
}
return new JsonResponse(array('success' => true));
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index 76d4e70..709095b 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -12,10 +12,11 @@ class PostUploadEvent extends Event
protected $file;
protected $request;
- public function __construct(File $file, Request $request)
+ public function __construct(File $file, Request $request, array $options = array())
{
$this->file = $file;
$this->request = $request;
+ $this->options = $options;
}
public function getFile()
@@ -27,4 +28,9 @@ class PostUploadEvent extends Event
{
return $this->request;
}
+
+ public function getOptions()
+ {
+ return $this->options;
+ }
}
\ No newline at end of file
diff --git a/EventListener/OrphanageListener.php b/EventListener/OrphanageListener.php
index ec40914..a7d909f 100644
--- a/EventListener/OrphanageListener.php
+++ b/EventListener/OrphanageListener.php
@@ -18,18 +18,22 @@ class OrphanageListener implements EventSubscriberInterface
$this->orphanage = $orphanage;
}
- public function addToSession(PostUploadEvent $event)
+ public function add(PostUploadEvent $event)
{
+ $options = $event->getOptions();
$request = $event->getRequest();
$file = $event->getFile();
- $this->orphanage->addFile($file);
+ if(!$options['use_orphanage'])
+ return;
+
+ $this->orphanage->addFile($file, $options['file_name']);
}
public static function getSubscribedEvents()
{
return array(
- UploadEvents::POST_UPLOAD => 'addToSession',
+ UploadEvents::POST_UPLOAD => 'add',
);
}
}
\ No newline at end of file
diff --git a/UploadEvents.php b/UploadEvents.php
index 4e90860..6a9967b 100644
--- a/UploadEvents.php
+++ b/UploadEvents.php
@@ -5,5 +5,5 @@ namespace Oneup\UploaderBundle;
final class UploadEvents
{
const POST_PERSIST = 'oneup.uploader.post.persist';
- const POST_UPLOAD = 'oneup.uploader.post.upload':
+ const POST_UPLOAD = 'oneup.uploader.post.upload';
}
\ No newline at end of file
diff --git a/Uploader/Orphanage/Orphanage.php b/Uploader/Orphanage/Orphanage.php
index 8731c09..c7a5506 100644
--- a/Uploader/Orphanage/Orphanage.php
+++ b/Uploader/Orphanage/Orphanage.php
@@ -18,14 +18,17 @@ class Orphanage implements OrphanageInterface
$this->config = $config;
}
- public function addFile(File $file)
+ public function addFile(File $file, $name)
{
+ if(!$this->session->isStarted())
+ throw new \RuntimeException('You need a running session in order to run the Orphanage.');
+
// prefix directory with session id
- $id = $session->getId();
- $path = sprintf('%s/%s/%s', $this->config['directory'], $id, $file->getRealPath());
+ $id = $this->session->getId();
+ $path = sprintf('%s/%s', $this->config['directory'], $id);
- var_dump($path);
- die();
+ // move file to orphanage
+ return $file->move($path, $name);
}
public function removeFile(File $file)
| 0
|
4351643af4dce59605f57a3937f3afbf40da2670
|
1up-lab
|
OneupUploaderBundle
|
Added syntax hightlight indicator.
|
commit 4351643af4dce59605f57a3937f3afbf40da2670
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 13:09:52 2013 +0200
Added syntax hightlight indicator.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 05a27f0..47145c2 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -9,7 +9,7 @@ This bundle tested using Symfony2 versions 2.1+.
If you wish to use the default texts provided with this bundle, you have to make sure that you have translator
enabled in your configuration file.
-```
+```yaml
# app/config/config.yml
framework:
@@ -64,7 +64,7 @@ public function registerBundles()
This bundle was designed to just work out of the box. The only thing you have to configure in order to get this bundle up and running is a mapping.
-```
+```yaml
# app/config/config.yml
oneup_uploader:
@@ -77,7 +77,7 @@ As this is a server implementation for Fine Uploader, you have to include this l
_uploader_{mapping_key}
-```
+```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>
<script type="text/javascript">
| 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
|
e91f3a76464f340191cc3f3ccbecbe37d2f36971
|
1up-lab
|
OneupUploaderBundle
|
Marked some tests skipped if directories mismatch.
Strangly on my machine the function tempnam returns something
different than expected.
tempnam('/foo', 'bar');
returns a file located in /private/foo. The way this test works
does not allow this behaviour. This is why we test this condition
and mark the test skipped.
|
commit e91f3a76464f340191cc3f3ccbecbe37d2f36971
Author: Jim Schmid <[email protected]>
Date: Mon Oct 14 19:56:20 2013 +0200
Marked some tests skipped if directories mismatch.
Strangly on my machine the function tempnam returns something
different than expected.
tempnam('/foo', 'bar');
returns a file located in /private/foo. The way this test works
does not allow this behaviour. This is why we test this condition
and mark the test skipped.
diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
index bc3a671..418298c 100644
--- a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
+++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -28,6 +28,10 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
$this->tempDirectory = $this->realDirectory . '/' . $this->orphanageKey;
$this->payloads = array();
+ if (!$this->checkIfTempnameMatchesAfterCreation()) {
+ $this->markTestSkipped('Temporary directories do not match');
+ }
+
$filesystem = new \Symfony\Component\Filesystem\Filesystem();
$filesystem->mkdir($this->realDirectory);
$filesystem->mkdir($this->chunkDirectory);
@@ -107,4 +111,8 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
$this->assertCount($this->numberOfPayloads, $finder);
}
+ public function checkIfTempnameMatchesAfterCreation()
+ {
+ return strpos(tempnam($this->chunkDirectory, 'uploader'), $this->chunkDirectory) === 0;
+ }
}
| 0
|
4798b107492cfd8c6c483a4a95d86058761975dc
|
1up-lab
|
OneupUploaderBundle
|
Update chunked_uploads.md
|
commit 4798b107492cfd8c6c483a4a95d86058761975dc
Author: mitom <[email protected]>
Date: Fri Oct 11 10:37:31 2013 +0200
Update chunked_uploads.md
diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md
index 4f5c5e1..7b0dadc 100644
--- a/Resources/doc/chunked_uploads.md
+++ b/Resources/doc/chunked_uploads.md
@@ -31,11 +31,46 @@ 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/'
+```
+
+As you can see there are is a new option, ```prefix```. It represents the directory
+in *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.
| 0
|
5959952f2f6f9765122781110d7201ac2623f981
|
1up-lab
|
OneupUploaderBundle
|
CS fixes for the rest.
|
commit 5959952f2f6f9765122781110d7201ac2623f981
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 21:25:52 2013 +0200
CS fixes for the rest.
diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml
index 4593804..a964783 100644
--- a/Resources/config/templating.xml
+++ b/Resources/config/templating.xml
@@ -13,4 +13,4 @@
</services>
-</container>
\ No newline at end of file
+</container>
diff --git a/Resources/config/twig.xml b/Resources/config/twig.xml
index 95c0c2d..31f68e1 100644
--- a/Resources/config/twig.xml
+++ b/Resources/config/twig.xml
@@ -13,4 +13,4 @@
</services>
-</container>
\ No newline at end of file
+</container>
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 49de680..f6c93af 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -21,26 +21,26 @@
</parameters>
<services>
-
+
<!-- managers -->
<service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
</service>
-
+
<service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%">
<argument type="service" id="service_container" />
<argument>%oneup_uploader.orphanage%</argument>
</service>
-
+
<!-- namer -->
<service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" />
-
+
<!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
<argument>%oneup_uploader.controllers%</argument>
<tag name="routing.loader" />
</service>
-
+
</services>
-</container>
\ No newline at end of file
+</container>
diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml
index a47e6a9..8f435c5 100644
--- a/Resources/config/validators.xml
+++ b/Resources/config/validators.xml
@@ -15,11 +15,11 @@
<service id="oneup_uploader.validation_listener.disallowed_extension" class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
-
+
<service id="oneup_uploader.validation_listener.allowed_mimetype" class="Oneup\UploaderBundle\EventListener\AllowedMimetypeValidationListener">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
-
+
<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>
diff --git a/Resources/translations/OneupUploaderBundle.en.yml b/Resources/translations/OneupUploaderBundle.en.yml
index 4d5f620..6f38377 100644
--- a/Resources/translations/OneupUploaderBundle.en.yml
+++ b/Resources/translations/OneupUploaderBundle.en.yml
@@ -1,4 +1,4 @@
error:
maxsize: This file is too large.
whitelist: This file type is not allowed.
- blacklist: This file type is not allowed.
\ No newline at end of file
+ blacklist: This file type is not allowed.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 9145ff1..236f950 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -9,32 +9,31 @@ use Symfony\Component\Routing\RouteCollection;
class RouteLoader extends Loader
{
protected $controllers;
-
+
public function __construct(array $controllers)
{
$this->controllers = $controllers;
}
-
+
public function supports($resource, $type = null)
{
return $type === 'uploader';
}
-
+
public function load($resource, $type = null)
{
$routes = new RouteCollection();
-
- foreach($this->controllers as $type => $service)
- {
+
+ foreach ($this->controllers as $type => $service) {
$upload = new Route(
sprintf('/_uploader/%s/upload', $type),
array('_controller' => $service . ':upload', '_format' => 'json'),
array('_method' => 'POST')
);
-
+
$routes->add(sprintf('_uploader_%s', $type), $upload);
}
-
+
return $routes;
}
-}
\ No newline at end of file
+}
diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php
index b5c376a..1882766 100644
--- a/Templating/Helper/UploaderHelper.php
+++ b/Templating/Helper/UploaderHelper.php
@@ -8,19 +8,19 @@ use Symfony\Component\Templating\Helper\Helper;
class UploaderHelper extends Helper
{
protected $router;
-
+
public function __construct(RouterInterface $router)
{
$this->router = $router;
}
-
+
public function getName()
{
return 'oneup_uploader';
}
-
+
public function endpoint($key)
{
return $this->router->generate(sprintf('_uploader_%s', $key));
}
-}
\ No newline at end of file
+}
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index 910a0f9..8849b79 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -7,24 +7,24 @@ use Oneup\UploaderBundle\Templating\Helper\UploaderHelper;
class UploaderExtension extends \Twig_Extension
{
protected $helper;
-
+
public function __construct(UploaderHelper $helper)
{
$this->helper = $helper;
}
-
+
public function getName()
{
return 'oneup_uploader';
}
-
+
public function getFunctions()
{
return array('oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'));
}
-
+
public function endpoint($key)
{
return $this->helper->endpoint($key);
}
-}
\ No newline at end of file
+}
| 0
|
8d1b10eb56c2f9db969902518d5013935836f092
|
1up-lab
|
OneupUploaderBundle
|
Added a hint for the new Session upload progress implementation to the readme file.
|
commit 8d1b10eb56c2f9db969902518d5013935836f092
Author: Jim Schmid <[email protected]>
Date: Tue Jun 25 16:54:09 2013 +0200
Added a hint for the new Session upload progress implementation to the readme file.
diff --git a/README.md b/README.md
index 2592a61..f72f219 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,7 @@ Features included:
* Chunked uploads
* Supports [Gaufrette](https://github.com/KnpLabs/Gaufrette) and/or 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
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
| 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
|
f6804b958cc4d283cec0992943502df61e5f7e89
|
1up-lab
|
OneupUploaderBundle
|
Use the correct typehint for Iterators.
|
commit f6804b958cc4d283cec0992943502df61e5f7e89
Author: Jim Schmid <[email protected]>
Date: Mon Jun 24 14:13:15 2013 +0200
Use the correct typehint for Iterators.
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index f5bc733..18760b0 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -47,7 +47,7 @@ class ChunkManager implements ChunkManagerInterface
return $chunk->move($path, $name);
}
- public function assembleChunks(\Traversable $chunks)
+ public function assembleChunks(\IteratorAggregate $chunks)
{
$iterator = $chunks->getIterator()->getInnerIterator();
diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php
index 009bfed..3fad75a 100644
--- a/Uploader/Chunk/ChunkManagerInterface.php
+++ b/Uploader/Chunk/ChunkManagerInterface.php
@@ -8,7 +8,7 @@ interface ChunkManagerInterface
{
public function clear();
public function addChunk($uuid, $index, UploadedFile $chunk, $original);
- public function assembleChunks(\Traversable $chunks);
+ public function assembleChunks(\IteratorAggregate $chunks);
public function cleanup($path);
public function getChunks($uuid);
}
| 0
|
4c5be73f6b16810f7296382320c87d982df2d85c
|
1up-lab
|
OneupUploaderBundle
|
Tested max_size contraint.
|
commit 4c5be73f6b16810f7296382320c87d982df2d85c
Author: Jim Schmid <[email protected]>
Date: Sat Jun 22 16:51:10 2013 +0200
Tested max_size contraint.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index 96b50d3..77da381 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -31,6 +31,7 @@ oneup_uploader:
fineuploader_validation:
frontend: fineuploader
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
@@ -45,6 +46,7 @@ oneup_uploader:
fancyupload_validation:
frontend: fancyupload
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
@@ -59,6 +61,7 @@ oneup_uploader:
yui3_validation:
frontend: yui3
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
@@ -73,6 +76,7 @@ oneup_uploader:
plupload_validation:
frontend: plupload
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
@@ -87,6 +91,7 @@ oneup_uploader:
uploadify_validation:
frontend: uploadify
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
@@ -101,6 +106,7 @@ oneup_uploader:
blueimp_validation:
frontend: blueimp
+ max_size: 256
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
allowed_extensions: [ "ok" ]
diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php
index 6dfc7e4..e84dd20 100644
--- a/Tests/Controller/AbstractUploadTest.php
+++ b/Tests/Controller/AbstractUploadTest.php
@@ -49,13 +49,13 @@ abstract class AbstractUploadTest extends AbstractControllerTest
$me = $this;
$uploadCount = 0;
$preValidation = 1;
-
+
$dispatcher->addListener(UploadEvents::PRE_UPLOAD, function(PreUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) {
$preValidation -= 2;
$file = $event->getFile();
$request = $event->getRequest();
-
+
// add a new key to the attribute list
$request->attributes->set('grumpy', 'cat');
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index 73d66f9..d0e1e60 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -11,6 +11,21 @@ abstract class AbstractValidationTest extends AbstractControllerTest
abstract protected function getFileWithIncorrectExtension();
abstract protected function getFileWithCorrectMimeType();
abstract protected function getFileWithIncorrectMimeType();
+ abstract protected function getOversizedFile();
+
+ public function testAgainstMaxSize()
+ {
+ // assemble a request
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getOversizedFile()));
+ $response = $client->getResponse();
+
+ //$this->assertTrue($response->isNotSuccessful());
+ $this->assertEquals($response->headers->get('Content-Type'), 'application/json');
+ $this->assertCount(0, $this->getUploadedFiles());
+ }
public function testAgainstCorrectExtension()
{
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index bdc9493..e2cd6cd 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -17,6 +17,16 @@ class BlueimpValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return array(new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ ));
+ }
+
protected function getFileWithCorrectExtension()
{
return array(new UploadedFile(
diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php
index 11ef999..7e48964 100644
--- a/Tests/Controller/FancyUploadValidationTest.php
+++ b/Tests/Controller/FancyUploadValidationTest.php
@@ -17,6 +17,16 @@ class FancyUploadValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ );
+ }
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
diff --git a/Tests/Controller/FineUploaderValidationTest.php b/Tests/Controller/FineUploaderValidationTest.php
index 9d5f31c..d1961e4 100644
--- a/Tests/Controller/FineUploaderValidationTest.php
+++ b/Tests/Controller/FineUploaderValidationTest.php
@@ -17,6 +17,16 @@ class FineUploaderValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ );
+ }
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
diff --git a/Tests/Controller/PluploadValidationTest.php b/Tests/Controller/PluploadValidationTest.php
index ccd9848..61ffc55 100644
--- a/Tests/Controller/PluploadValidationTest.php
+++ b/Tests/Controller/PluploadValidationTest.php
@@ -17,6 +17,16 @@ class PluploadValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ );
+ }
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
diff --git a/Tests/Controller/UploadifyValidationTest.php b/Tests/Controller/UploadifyValidationTest.php
index b5851b2..0f10650 100644
--- a/Tests/Controller/UploadifyValidationTest.php
+++ b/Tests/Controller/UploadifyValidationTest.php
@@ -17,6 +17,16 @@ class UploadifyValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ );
+ }
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
diff --git a/Tests/Controller/YUI3ValidationTest.php b/Tests/Controller/YUI3ValidationTest.php
index 3d839f3..ca4919c 100644
--- a/Tests/Controller/YUI3ValidationTest.php
+++ b/Tests/Controller/YUI3ValidationTest.php
@@ -17,6 +17,16 @@ class YUI3ValidationTest extends AbstractValidationTest
return array();
}
+ protected function getOversizedFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(512),
+ 'cat.ok',
+ 'text/plain',
+ 512
+ );
+ }
+
protected function getFileWithCorrectExtension()
{
return new UploadedFile(
| 0
|
530858cbefb4bb3ea1b147b032514f779df7c814
|
1up-lab
|
OneupUploaderBundle
|
Fix .gitignore
|
commit 530858cbefb4bb3ea1b147b032514f779df7c814
Author: David Greminger <[email protected]>
Date: Fri Oct 23 11:36:41 2020 +0200
Fix .gitignore
diff --git a/.gitignore b/.gitignore
index 0204479..68a1a75 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,8 @@
+.idea
+.phpunit.result.cache
composer.lock
-phpunit.xml
vendor
-log
-var
tests/App/cache
tests/App/logs
+tests/App/var
tests/var
-
-.idea
-.phpunit.result.cache
| 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
|
ad5577f64f954377521b8724ce7de3f7b4682987
|
1up-lab
|
OneupUploaderBundle
|
gaufrette chunk storage
|
commit ad5577f64f954377521b8724ce7de3f7b4682987
Author: mitom <[email protected]>
Date: Wed Oct 9 21:48:18 2013 +0200
gaufrette chunk storage
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index 7f930d4..2678a66 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -74,8 +74,7 @@ abstract class AbstractChunkedController extends AbstractController
$path = $assembled->getPath();
// create a temporary uploaded file to meet the interface restrictions
- $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, $assembled->getSize(), null, true);
- $uploaded = $this->handleUpload($uploadedFile, $response, $request);
+ $this->handleUpload($assembled, $response, $request);
$chunkManager->cleanup($path);
}
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 04397d2..aea039e 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Controller;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -103,7 +104,7 @@ abstract class AbstractController
* @param response A response object.
* @param request The request object.
*/
- protected function handleUpload(UploadedFile $file, ResponseInterface $response, Request $request)
+ protected function handleUpload(FileInterface $file, ResponseInterface $response, Request $request)
{
$this->validate($file);
@@ -126,7 +127,7 @@ abstract class AbstractController
* @param response A response object.
* @param request The request object.
*/
- protected function dispatchPreUploadEvent(UploadedFile $uploaded, ResponseInterface $response, Request $request)
+ protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
@@ -161,7 +162,7 @@ abstract class AbstractController
}
}
- protected function validate(UploadedFile $file)
+ protected function validate(FileInterface $file)
{
$dispatcher = $this->container->get('event_dispatcher');
$event = new ValidationEvent($file, $this->container->get('request'), $this->config, $this->type);
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 97b1eef..ab37255 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -18,7 +18,18 @@ class Configuration implements ConfigurationInterface
->addDefaultsIfNotSet()
->children()
->scalarNode('maxage')->defaultValue(604800)->end()
- ->scalarNode('directory')->defaultNull()->end()
+ ->arrayNode('storage')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->enumNode('type')
+ ->values(array('filesystem', 'gaufrette'))
+ ->defaultValue('filesystem')
+ ->end()
+ ->scalarNode('filesystem')->defaultNull()->end()
+ ->scalarNode('directory')->defaultNull()->end()
+ ->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
+ ->end()
+ ->end()
->booleanNode('load_distribution')->defaultTrue()->end()
->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index fae9056..72445fa 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -13,11 +13,14 @@ use Symfony\Component\DependencyInjection\Loader;
class OneupUploaderExtension extends Extension
{
protected $storageServices = array();
+ protected $container;
+ protected $config;
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
- $config = $this->processConfiguration($configuration, $configs);
+ $this->config = $this->processConfiguration($configuration, $configs);
+ $this->container = $container;
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
@@ -25,88 +28,45 @@ class OneupUploaderExtension extends Extension
$loader->load('validators.xml');
$loader->load('errorhandler.xml');
- if ($config['twig']) {
+ if ($this->config['twig']) {
$loader->load('twig.xml');
}
- $config['chunks']['directory'] = is_null($config['chunks']['directory']) ?
- sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir')) :
- $this->normalizePath($config['chunks']['directory'])
- ;
+ if ($this->config['chunks']['storage']['type'] === 'filesystem' &&
+ !isset($this->config['chunks']['storage']['directory'])) {
+ $this->config['chunks']['storage']['directory'] = sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir'));
+ } elseif ($this->config['chunks']['storage']['type'] === 'gaufrette' ) {
+ // Force load distribution when using gaufrette chunk storage
+ $this->config['chunks']['load_distribution'] = true;
+ }
+
+ // register the service for the chunk storage
+ $this->createStorageService($this->config['chunks']['storage'], 'chunk');
- $config['orphanage']['directory'] = is_null($config['orphanage']['directory']) ?
+
+ $this->config['orphanage']['directory'] = is_null($this->config['orphanage']['directory']) ?
sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir')) :
- $this->normalizePath($config['orphanage']['directory'])
+ $this->normalizePath($this->config['orphanage']['directory'])
;
- $container->setParameter('oneup_uploader.chunks', $config['chunks']);
- $container->setParameter('oneup_uploader.orphanage', $config['orphanage']);
+ $container->setParameter('oneup_uploader.chunks', $this->config['chunks']);
+ $container->setParameter('oneup_uploader.orphanage', $this->config['orphanage']);
$controllers = array();
// handle mappings
- foreach ($config['mappings'] as $key => $mapping) {
+ foreach ($this->config['mappings'] as $key => $mapping) {
+ if ($key === 'chunk') {
+ throw new InvalidArgumentException('"chunk" is a protected mapping name, please use a different one.');
+ }
+
$mapping['max_size'] = $mapping['max_size'] < 0 ?
$this->getMaxUploadSize($mapping['max_size']) :
$mapping['max_size']
;
// create the storage service according to the configuration
- $storageService = null;
-
- // if a service is given, return a reference to this service
- // this allows a user to overwrite the storage layer if needed
- if (!is_null($mapping['storage']['service'])) {
- $storageService = new Reference($mapping['storage']['service']);
- } else {
- // no service was given, so we create one
- $storageName = sprintf('oneup_uploader.storage.%s', $key);
-
- if ($mapping['storage']['type'] == 'filesystem') {
- $mapping['storage']['directory'] = is_null($mapping['storage']['directory']) ?
- sprintf('%s/../web/uploads/%s', $container->getParameter('kernel.root_dir'), $key) :
- $this->normalizePath($mapping['storage']['directory'])
- ;
-
- $container
- ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $mapping['storage']['type']))
- ->addArgument($mapping['storage']['directory'])
- ;
- }
-
- 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.');
-
- if(strlen($mapping['storage']['filesystem']) <= 0)
- throw new ServiceNotFoundException('Empty service name');
-
- $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']))
- ;
- }
-
- $storageService = new Reference($storageName);
-
- if ($mapping['use_orphanage']) {
- $orphanageName = sprintf('oneup_uploader.orphanage.%s', $key);
-
- // this mapping wants to use the orphanage, so create
- // a masked filesystem for the controller
- $container
- ->register($orphanageName, '%oneup_uploader.orphanage.class%')
- ->addArgument($storageService)
- ->addArgument(new Reference('session'))
- ->addArgument($config['orphanage'])
- ->addArgument($key)
- ;
-
- // switch storage of mapping to orphanage
- $storageService = new Reference($orphanageName);
- }
- }
+ $storageService = $this->createStorageService($mapping['storage'], $key, isset($mapping['orphanage']) ? :null);
if ($mapping['frontend'] != 'custom') {
$controllerName = sprintf('oneup_uploader.controller.%s', $key);
@@ -154,6 +114,68 @@ class OneupUploaderExtension extends Extension
$container->setParameter('oneup_uploader.controllers', $controllers);
}
+ protected function createStorageService($storage, $key, $orphanage = null)
+ {
+ $storageService = null;
+
+ // if a service is given, return a reference to this service
+ // this allows a user to overwrite the storage layer if needed
+ if (isset($storage['service']) && !is_null($storage['service'])) {
+ $storageService = new Reference($storage['storage']['service']);
+ } else {
+ // no service was given, so we create one
+ $storageName = sprintf('oneup_uploader.storage.%s', $key);
+
+ if ($storage['type'] == 'filesystem') {
+ $storage['directory'] = is_null($storage['directory']) ?
+ sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $key) :
+ $this->normalizePath($storage['directory'])
+ ;
+
+ $this->container
+ ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $storage['type']))
+ ->addArgument($storage['directory'])
+ ;
+ }
+
+ if ($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.');
+
+ if(strlen($storage['filesystem']) <= 0)
+ throw new ServiceNotFoundException('Empty service name');
+
+ $this->container
+ ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $storage['type']))
+ ->addArgument(new Reference($storage['filesystem']))
+ ->addArgument($this->getValueInBytes($storage['sync_buffer_size']))
+ ;
+ }
+
+ $storageService = new Reference($storageName);
+
+ if ($orphanage) {
+ $orphanageName = sprintf('oneup_uploader.orphanage.%s', $key);
+
+ // this mapping wants to use the orphanage, so create
+ // a masked filesystem for the controller
+ $this->container
+ ->register($orphanageName, '%oneup_uploader.orphanage.class%')
+ ->addArgument($storageService)
+ ->addArgument(new Reference('session'))
+ ->addArgument($this->config['orphanage'])
+ ->addArgument($key)
+ ;
+
+ // switch storage of mapping to orphanage
+ $storageService = new Reference($orphanageName);
+ }
+ }
+
+ return $storageService;
+ }
+
+
protected function getMaxUploadSize($input)
{
$input = $this->getValueInBytes($input);
diff --git a/Event/ValidationEvent.php b/Event/ValidationEvent.php
index 8110b78..15e1c18 100644
--- a/Event/ValidationEvent.php
+++ b/Event/ValidationEvent.php
@@ -2,8 +2,8 @@
namespace Oneup\UploaderBundle\Event;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Symfony\Component\EventDispatcher\Event;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
class ValidationEvent extends Event
@@ -13,7 +13,7 @@ class ValidationEvent extends Event
protected $type;
protected $request;
- public function __construct(UploadedFile $file, Request $request, array $config, $type)
+ public function __construct(FileInterface $file, Request $request, array $config, $type)
{
$this->file = $file;
$this->config = $config;
diff --git a/EventListener/AllowedExtensionValidationListener.php b/EventListener/AllowedExtensionValidationListener.php
index 68c26e8..add50ca 100644
--- a/EventListener/AllowedExtensionValidationListener.php
+++ b/EventListener/AllowedExtensionValidationListener.php
@@ -12,7 +12,7 @@ class AllowedExtensionValidationListener
$config = $event->getConfig();
$file = $event->getFile();
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+ $extension = $file->getExtension();
if (count($config['allowed_extensions']) > 0 && !in_array($extension, $config['allowed_extensions'])) {
throw new ValidationException('error.whitelist');
diff --git a/EventListener/AllowedMimetypeValidationListener.php b/EventListener/AllowedMimetypeValidationListener.php
index 195f6bd..66aa7b9 100644
--- a/EventListener/AllowedMimetypeValidationListener.php
+++ b/EventListener/AllowedMimetypeValidationListener.php
@@ -16,8 +16,7 @@ class AllowedMimetypeValidationListener
return;
}
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
- $mimetype = finfo_file($finfo, $file->getRealpath());
+ $mimetype = $file->getMimeType();
if (!in_array($mimetype, $config['allowed_mimetypes'])) {
throw new ValidationException('error.whitelist');
diff --git a/EventListener/DisallowedExtensionValidationListener.php b/EventListener/DisallowedExtensionValidationListener.php
index 9cdac58..9f000de 100644
--- a/EventListener/DisallowedExtensionValidationListener.php
+++ b/EventListener/DisallowedExtensionValidationListener.php
@@ -12,7 +12,7 @@ class DisallowedExtensionValidationListener
$config = $event->getConfig();
$file = $event->getFile();
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+ $extension = $file->getExtension();
if (count($config['disallowed_extensions']) > 0 && in_array($extension, $config['disallowed_extensions'])) {
throw new ValidationException('error.blacklist');
diff --git a/EventListener/DisallowedMimetypeValidationListener.php b/EventListener/DisallowedMimetypeValidationListener.php
index 452eff6..c5ace44 100644
--- a/EventListener/DisallowedMimetypeValidationListener.php
+++ b/EventListener/DisallowedMimetypeValidationListener.php
@@ -16,8 +16,7 @@ class DisallowedMimetypeValidationListener
return;
}
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
- $mimetype = finfo_file($finfo, $file->getRealpath());
+ $mimetype = $file->getExtension();
if (in_array($mimetype, $config['disallowed_mimetypes'])) {
throw new ValidationException('error.blacklist');
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 39502ab..3c95386 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -26,6 +26,7 @@
<!-- managers -->
<service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%">
<argument>%oneup_uploader.chunks%</argument>
+ <argument type="service" id="oneup_uploader.storage.chunk" />
</service>
<service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%">
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 4f7733b..39bd2d2 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Chunk;
+use Oneup\UploaderBundle\Uploader\Storage\ChunkStorageInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Finder\Finder;
@@ -11,102 +12,38 @@ use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface;
class ChunkManager implements ChunkManagerInterface
{
- public function __construct($configuration)
+ protected $configuration;
+ protected $storage;
+
+ public function __construct($configuration, ChunkStorageInterface $storage)
{
$this->configuration = $configuration;
+ $this->storage = $storage;
}
public function clear()
{
- $system = new Filesystem();
- $finder = new Finder();
-
- try {
- $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds')->files();
- } catch (\InvalidArgumentException $e) {
- // the finder will throw an exception of type InvalidArgumentException
- // if the directory he should search in does not exist
- // in that case we don't have anything to clean
- return;
- }
-
- foreach ($finder as $file) {
- $system->remove($file);
- }
+ $this->storage->clear($this->configuration['maxage']);
}
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));
-
- return $chunk->move($path, $name);
+ return $this->storage->addChunk($uuid, $index, $chunk, $original);
}
- public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false)
+ public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false)
{
- $iterator = $chunks->getIterator()->getInnerIterator();
-
- $base = $iterator->current();
- $iterator->next();
-
- while ($iterator->valid()) {
-
- $file = $iterator->current();
-
- if (false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX)) {
- throw new \RuntimeException('Reassembling chunks failed.');
- }
-
- if ($removeChunk) {
- $filesystem = new Filesystem();
- $filesystem->remove($file->getPathname());
- }
-
- $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(), $name);
-
- return $assembled;
+ return $this->storage->assembleChunks($chunks, $removeChunk, $renameChunk);
}
public function cleanup($path)
{
- // cleanup
- $filesystem = new Filesystem();
- $filesystem->remove($path);
-
- return true;
+ return $this->storage->cleanup($path);
}
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;
+ return $this->storage->getChunks($uuid);
}
public function getLoadDistribution()
diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php
index 0991a3e..99ad60c 100644
--- a/Uploader/Chunk/ChunkManagerInterface.php
+++ b/Uploader/Chunk/ChunkManagerInterface.php
@@ -21,13 +21,13 @@ interface ChunkManagerInterface
/**
* Assembles the given chunks and return the resulting file.
*
- * @param \IteratorAggregate $chunks
+ * @param $chunks
* @param bool $removeChunk Remove the chunk file once its assembled.
* @param bool $renameChunk Rename the chunk file once its assembled.
*
* @return File
*/
- public function assembleChunks(\IteratorAggregate $chunks, $removeChunk = true, $renameChunk = false);
+ public function assembleChunks($chunks, $removeChunk = true, $renameChunk = false);
/**
* Get chunks associated with the given uuid.
diff --git a/Uploader/File/FileInterface.php b/Uploader/File/FileInterface.php
new file mode 100644
index 0000000..47e4266
--- /dev/null
+++ b/Uploader/File/FileInterface.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\File;
+
+/**
+ * Every function in this interface should be considered unsafe.
+ * They are only meant to abstract away some basic file functionality.
+ * For safe methods rely on the parent functions.
+ *
+ * Interface FileInterface
+ *
+ * @package Oneup\UploaderBundle\Uploader\File
+ */
+interface FileInterface
+{
+ /**
+ * Returns the size of the file
+ *
+ * @return int
+ */
+ public function getSize();
+
+ /**
+ * Returns the directory of the file without the filename
+ *
+ * @return string
+ */
+ public function getPath();
+
+ /**
+ * Returns the guessed mime type of the file
+ *
+ * @return string
+ */
+ public function getMimeType();
+
+ /**
+ * Returns the filename of the file
+ *
+ * @return string
+ */
+ public function getName();
+
+ /**
+ * Returns the guessed extension of the file
+ *
+ * @return mixed
+ */
+ public function getExtension();
+}
\ No newline at end of file
diff --git a/Uploader/File/FilesystemFile.php b/Uploader/File/FilesystemFile.php
new file mode 100644
index 0000000..eed8d67
--- /dev/null
+++ b/Uploader/File/FilesystemFile.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\File;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+class FilesystemFile extends UploadedFile implements FileInterface
+{
+ protected $file;
+ public function __construct(UploadedFile $file)
+ {
+ $this->file = $file;
+ parent::__construct($file->getPath(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
+ }
+}
\ No newline at end of file
diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php
new file mode 100644
index 0000000..7771c4a
--- /dev/null
+++ b/Uploader/File/GaufretteFile.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\File;
+
+use Gaufrette\File;
+use Gaufrette\Filesystem;
+
+class GaufretteFile extends File implements FileInterface
+{
+ protected $filesystem;
+
+ public function __construct(File $file, Filesystem $filesystem) {
+ parent::__construct($file->getKey(), $filesystem);
+ $this->filesystem = $filesystem;
+ }
+
+ /**
+ * Returns the size of the file
+ *
+ * !! WARNING !!
+ * Calling this loads the entire file into memory,
+ * in case of bigger files this could throw exceptions,
+ * and will have heavy performance footprint.
+ * !! ------- !!
+ *
+ * TODO mock/calculate the size if possible and use that instead?
+ */
+ public function getSize()
+ {
+ return parent::getSize();
+ }
+
+ public function getPath()
+ {
+ return pathinfo($this->getKey(), PATHINFO_DIRNAME);
+ }
+
+ public function getName()
+ {
+ return pathinfo($this->getKey(), PATHINFO_BASENAME);
+ }
+
+ /**
+ * @return string
+ */
+ public function getMimeType()
+ {
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ return finfo_file($finfo, $this->getKey());
+ }
+
+ public function getExtension()
+ {
+ return pathinfo($this->getKey(), PATHINFO_EXTENSION);
+ }
+
+ public function getFilesystem()
+ {
+ return $this->filesystem;
+ }
+
+}
\ No newline at end of file
diff --git a/Uploader/Naming/NamerInterface.php b/Uploader/Naming/NamerInterface.php
index d44b817..173e0b8 100644
--- a/Uploader/Naming/NamerInterface.php
+++ b/Uploader/Naming/NamerInterface.php
@@ -2,15 +2,16 @@
namespace Oneup\UploaderBundle\Uploader\Naming;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
interface NamerInterface
{
/**
* Name a given file and return the name
*
- * @param UploadedFile $file
+ * @param FileInterface $file
* @return string
*/
- public function name(UploadedFile $file);
+ public function name(FileInterface $file);
}
diff --git a/Uploader/Naming/UniqidNamer.php b/Uploader/Naming/UniqidNamer.php
index 4c16b98..80bc741 100644
--- a/Uploader/Naming/UniqidNamer.php
+++ b/Uploader/Naming/UniqidNamer.php
@@ -2,13 +2,13 @@
namespace Oneup\UploaderBundle\Uploader\Naming;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;
+
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
class UniqidNamer implements NamerInterface
{
- public function name(UploadedFile $file)
+ public function name(FileInterface $file)
{
- return sprintf('%s.%s', uniqid(), $file->guessExtension());
+ return sprintf('%s.%s', uniqid(), $file->getExtension());
}
}
diff --git a/Uploader/Storage/ChunkStorageInterface.php b/Uploader/Storage/ChunkStorageInterface.php
new file mode 100644
index 0000000..b9fa1f6
--- /dev/null
+++ b/Uploader/Storage/ChunkStorageInterface.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Storage;
+
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+
+interface ChunkStorageInterface
+{
+ public function clear($maxAge);
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original);
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk);
+
+ public function cleanup($path);
+
+ public function getChunks($uuid);
+}
\ No newline at end of file
diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php
index d6915e0..d443f3c 100644
--- a/Uploader/Storage/FilesystemStorage.php
+++ b/Uploader/Storage/FilesystemStorage.php
@@ -2,11 +2,15 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\File\File;
-use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
-class FilesystemStorage implements StorageInterface
+class FilesystemStorage implements StorageInterface,ChunkStorageInterface
{
protected $directory;
@@ -15,8 +19,12 @@ class FilesystemStorage implements StorageInterface
$this->directory = $directory;
}
- public function upload(File $file, $name, $path = null)
+ public function upload(FileInterface $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);
@@ -29,4 +37,107 @@ class FilesystemStorage implements StorageInterface
return $file;
}
+
+ public function clear($maxAge)
+ {
+ $system = new Filesystem();
+ $finder = new Finder();
+
+ try {
+ $finder->in($this->directory)->date('<=' . -1 * (int) $maxAge . 'seconds')->files();
+ } catch (\InvalidArgumentException $e) {
+ // the finder will throw an exception of type InvalidArgumentException
+ // if the directory he should search in does not exist
+ // in that case we don't have anything to clean
+ return;
+ }
+
+ foreach ($finder as $file) {
+ $system->remove($file);
+ }
+ }
+
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $filesystem = new Filesystem();
+ $path = sprintf('%s/%s', $this->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->directory, $uuid));
+
+ return $chunk->move($path, $name);
+ }
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk)
+ {
+ if (!($chunks instanceof \IteratorAggregate)) {
+ throw new \InvalidArgumentException('The first argument must implement \IteratorAggregate interface.');
+ }
+
+ $iterator = $chunks->getIterator()->getInnerIterator();
+
+ $base = $iterator->current();
+ $iterator->next();
+
+ while ($iterator->valid()) {
+
+ $file = $iterator->current();
+
+ if (false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX)) {
+ throw new \RuntimeException('Reassembling chunks failed.');
+ }
+
+ if ($removeChunk) {
+ $filesystem = new Filesystem();
+ $filesystem->remove($file->getPathname());
+ }
+
+ $iterator->next();
+ }
+
+ $name = $base->getBasename();
+
+ if ($renameChunk) {
+ // remove the prefix added by self::addChunk
+ $name = preg_replace('/^(\d+)_/', '', $base->getBasename());
+ }
+
+ $assembled = new File($base->getRealPath());
+ $assembled = $assembled->move($base->getPath(), $name);
+
+ // the file is only renamed before it is uploaded
+ if ($renameChunk) {
+ // create an file to meet interface restrictions
+ $assembled = new FilesystemFile(new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, $assembled->getSize(), null, true));
+ }
+
+ return $assembled;
+ }
+
+ public function cleanup($path)
+ {
+ // cleanup
+ $filesystem = new Filesystem();
+ $filesystem->remove($path);
+
+ return true;
+ }
+
+ public function getChunks($uuid)
+ {
+ $finder = new Finder();
+ $finder
+ ->in(sprintf('%s/%s', $this->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;
+ }
}
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index f2229d0..6c82693 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -2,18 +2,21 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
-use Symfony\Component\HttpFoundation\File\File;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
+use Oneup\UploaderBundle\Uploader\File\GaufretteFile;
use Gaufrette\Stream\Local as LocalStream;
use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
use Gaufrette\Adapter\MetadataSupporter;
-use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Symfony\Component\HttpFoundation\File\UploadedFile;
-class GaufretteStorage implements StorageInterface
+class GaufretteStorage implements StorageInterface, ChunkStorageInterface
{
protected $filesystem;
protected $bufferSize;
+ protected $unhandledChunk;
+ protected $chunkPrefix = 'chunks';
public function __construct(Filesystem $filesystem, $bufferSize)
{
@@ -21,25 +24,142 @@ class GaufretteStorage implements StorageInterface
$this->bufferSize = $bufferSize;
}
- public function upload(File $file, $name, $path = null)
+ public function upload(FileInterface $file, $name, $path = null)
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
+ if ($file instanceof GaufretteFile) {
+ if ($file->getFilesystem() == $this->filesystem) {
+ $file->getFilesystem()->rename($file->getKey(), $path);
+
+ return $this->filesystem->get($path);
+ }
+ }
+
+ $this->stream($file, $path, $name);
+
+ return $this->filesystem->get($path);
+ }
+
+ public function clear($maxAge)
+ {
+ $matches = $this->filesystem->listKeys($this->chunkPrefix);
+
+ $limit = time()+$maxAge;
+ $toDelete = array();
+
+ // Collect the directories that are old,
+ // this also means the files inside are old
+ // but after the files are deleted the dirs
+ // would remain
+ foreach ($matches['dirs'] as $key) {
+ if ($limit < $this->filesystem->mtime($key)) {
+ $toDelete[] = $key;
+ }
+ }
+ // The same directory is returned for every file it contains
+ array_unique($toDelete);
+ foreach ($matches['keys'] as $key) {
+ if ($limit < $this->filesystem->mtime($key)) {
+ $this->filesystem->delete($key);
+ }
+ }
+
+ foreach($toDelete as $key) {
+ // The filesystem will throw exceptions if
+ // a directory is not empty
+ try {
+ $this->filesystem->delete($key);
+ } catch (\Exception $e) {
+ //do nothing
+ }
+ }
+ }
+
+ /**
+ * Only saves the information about the chunk to avoid moving it
+ * forth-and-back to reassemble it. Load distribution is enforced
+ * for gaufrette based chunk storage therefore assembleChunks will
+ * be called in the same request.
+ *
+ * @param $uuid
+ * @param $index
+ * @param UploadedFile $chunk
+ * @param $original
+ */
+ public function addChunk($uuid, $index, UploadedFile $chunk, $original)
+ {
+ $this->unhandledChunk = array(
+ 'uuid' => $uuid,
+ 'index' => $index,
+ 'chunk' => $chunk,
+ 'original' => $original
+ );
+ return;
+ }
+
+ public function assembleChunks($chunks, $removeChunk, $renameChunk)
+ {
+ // the index is only added to be in sync with the filesystem storage
+ $path = $this->chunkPrefix.'/'.$this->unhandledChunk['uuid'].'/';
+ $filename = $this->unhandledChunk['index'].'_'.$this->unhandledChunk['original'];
+
+ if (empty($chunks)) {
+ $target = $filename;
+ } else {
+ /*
+ * The array only contains items with matching prefix until the filename
+ * therefore the order will be decided depending on the filename
+ * It is only case-insensitive to be overly-careful.
+ */
+ sort($chunks, SORT_STRING | SORT_FLAG_CASE);
+ $target = pathinfo($chunks[0], PATHINFO_BASENAME);
+ }
+
+ $this->stream($this->unhandledChunk['chunk'], $path, $target);
+
+ if ($renameChunk) {
+ $name = preg_replace('/^(\d+)_/', '', $target);
+ $this->filesystem->rename($path.$target, $path.$name);
+ $target = $name;
+ }
+ $uploaded = $this->filesystem->get($path.$target);
+
+ if (!$renameChunk) {
+ return $uploaded;
+ }
+
+ return new GaufretteFile($uploaded, $this->filesystem);
+ }
+
+ public function cleanup($path)
+ {
+ $this->filesystem->delete($path);
+ }
+
+ public function getChunks($uuid)
+ {
+ return $this->filesystem->listKeys($this->chunkPrefix.'/'.$uuid)['keys'];
+ }
+
+ protected function stream($file, $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);
-
+ $path = $path.$name;
// this is a somehow ugly workaround introduced
// because the stream-mode is not able to create
// subdirectories.
if(!$this->filesystem->has($path))
$this->filesystem->write($path, '', true);
+ $src = new LocalStream($file->getPathname());
+ $dst = $this->filesystem->createStream($path);
+
$src->open(new StreamMode('rb+'));
- $dst->open(new StreamMode('wb+'));
+ $dst->open(new StreamMode('ab+'));
while (!$src->eof()) {
$data = $src->read($this->bufferSize);
@@ -48,7 +168,6 @@ class GaufretteStorage implements StorageInterface
$dst->close();
$src->close();
-
- return $this->filesystem->get($path);
}
+
}
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index fcbbaf0..a50a3bd 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Finder\Finder;
@@ -27,7 +28,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte
$this->type = $type;
}
- public function upload(File $file, $name, $path = null)
+ 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.');
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 79fb3ae..a9e2332 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Uploader\Storage;
+use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
@@ -13,5 +14,5 @@ interface StorageInterface
* @param string $name
* @param string $path
*/
- public function upload(File $file, $name, $path = null);
+ public function upload(FileInterface $file, $name, $path = null);
}
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.