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
|
|---|---|---|---|---|---|
209b593525545ca8e792529a49aa92809f362391
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit 209b593525545ca8e792529a49aa92809f362391
Merge: 5e82365 dad8de6
Author: Jim Schmid <[email protected]>
Date: Wed Dec 4 11:16:19 2013 +0100
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
| 0
|
7288cecd805802baf5f8660bea7d894cf75084e8
|
1up-lab
|
OneupUploaderBundle
|
Fixes ChunkManager class declaration.
|
commit 7288cecd805802baf5f8660bea7d894cf75084e8
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 13:39:52 2013 +0100
Fixes ChunkManager class declaration.
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index f10809d..72d08e6 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunks\ChunkManager</parameter>
+ <parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
</parameters>
<services>
| 0
|
1fd15f74248a7f11481be3bb1c66315d68e7a1be
|
1up-lab
|
OneupUploaderBundle
|
Add Errorhandling to Dropzone
|
commit 1fd15f74248a7f11481be3bb1c66315d68e7a1be
Author: Gladhon <[email protected]>
Date: Fri Feb 20 17:23:38 2015 +0100
Add Errorhandling to Dropzone
diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php
index 0c8a5b0..2121f32 100644
--- a/Controller/DropzoneController.php
+++ b/Controller/DropzoneController.php
@@ -20,6 +20,11 @@ class DropzoneController extends AbstractController
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
$this->errorHandler->addException($response, $e);
+ $translator = $this->container->get('translator');
+ $message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle');
+ $response = $this->createSupportedJsonResponse(array('error'=>$message ));
+ $response->setStatusCode(400);
+ return $response;
}
}
| 0
|
95740749e0550dc63f7b4f28b2e0129ef5fc33be
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #258 from mediafigaro/patch-2
Update custom_namer.md
|
commit 95740749e0550dc63f7b4f28b2e0129ef5fc33be
Merge: 2a6daa7 e5b8427
Author: David Greminger <[email protected]>
Date: Tue Jun 28 09:50:14 2016 +0200
Merge pull request #258 from mediafigaro/patch-2
Update custom_namer.md
| 0
|
3745b3af2e19c7c8be02d6552bd2708b7f86d51d
|
1up-lab
|
OneupUploaderBundle
|
Update composer.json
|
commit 3745b3af2e19c7c8be02d6552bd2708b7f86d51d
Author: Flavian <[email protected]>
Date: Sun Apr 14 12:53:55 2013 +0300
Update composer.json
diff --git a/composer.json b/composer.json
index 8124134..a59d0c0 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
- "description": "Handle multi file uploads. Features included: Chunked upload, Orphans management, Gaufrette support.",
+ "description": "Handles multi file uploads in Symonfy2. Features included: Chunked upload, Orphans management, Gaufrette support.",
"keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload"],
"homepage": "http://1up.io",
"license": "MIT",
@@ -30,4 +30,4 @@
},
"target-dir": "Oneup/UploaderBundle"
-}
\ No newline at end of file
+}
| 0
|
e1b1b618cfbbdb48f80547e44f9889e362374997
|
1up-lab
|
OneupUploaderBundle
|
Thank you
|
commit e1b1b618cfbbdb48f80547e44f9889e362374997
Author: David Greminger <[email protected]>
Date: Fri Dec 1 17:02:35 2017 +0100
Thank you
diff --git a/README.md b/README.md
index c76f765..2a54218 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
-* Version **2.0.0** supports now Symfony 4! Symfony 2.x support was dropped. You can also configure now a file extension validation whitelist (PR [#289](https://github.com/1up-lab/OneupUploaderBundle/pull/289))
+* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure now a file extension validation whitelist (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262))
* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway).
* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
* 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).
| 0
|
712bff50293aabc60d2c9f34c02abc5dcb977e29
|
1up-lab
|
OneupUploaderBundle
|
Registered a new EventListener on POST_UPLOAD. This one is for the session storage after upload.
|
commit 712bff50293aabc60d2c9f34c02abc5dcb977e29
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 10:11:27 2013 +0100
Registered a new EventListener on POST_UPLOAD. This one is for the session storage after upload.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 6d29961..0d18043 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -4,7 +4,8 @@ namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
-use Oneup\UploaderBundle\StoreEvents;
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
@@ -38,9 +39,9 @@ class UploaderController implements UploadControllerInterface
$name = $this->namer->name($file, $this->config['directory_prefix']);
$uploaded = $this->storage->upload($file, $name);
- // dispatch POST_UPLOAD event
- $event = new PostUploadEvent($uploaded, $request);
- $this->dispatcher->dispatch(StoreEvents::POST_UPLOAD, $event);
+ // dispatch post upload event
+ $event = new PostUploadEvent($uploaded, $this->request);
+ $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $event);
}
return new JsonResponse(array('success' => true));
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 8d26404..5f8cd6d 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -94,7 +94,7 @@ class OneupUploaderExtension extends Extension
->addArgument($mapping)
// we need the EventDispatcher for post upload events
- ->addArgument(new Reference('event.dispatcher'))
+ ->addArgument(new Reference('event_dispatcher'))
->addTag('oneup_uploader.routable', array('type' => $type))
->setScope('request')
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
index a24af56..132e71e 100644
--- a/Event/PostUploadEvent.php
+++ b/Event/PostUploadEvent.php
@@ -2,7 +2,6 @@
namespace Oneup\UploaderBundle\Event;
-use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Request;
diff --git a/EventListener/SessionStoreListener.php b/EventListener/SessionStoreListener.php
new file mode 100644
index 0000000..a8f25c5
--- /dev/null
+++ b/EventListener/SessionStoreListener.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+
+use Oneup\UploaderBundle\Event\PostUploadEvent;
+use Oneup\UploaderBundle\UploadEvents;
+
+class SessionStoreListener implements EventSubscriberInterface
+{
+ public function __construct(SessionInterface $session)
+ {
+ $this->session = $session;
+ }
+
+ public function addToSession(PostUploadEvent $event)
+ {
+ $request = $event->getRequest();
+ $file = $event->getFile();
+ }
+
+ public static function getSubscribedEvents()
+ {
+ return array(
+ UploadEvents::POST_UPLOAD => 'addToSession',
+ );
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index b0e8de6..d22de7e 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -10,6 +10,7 @@
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
<parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
+ <parameter key="oneup_uploader.listener.session.class">Oneup\UploaderBundle\EventListener\SessionStoreListener</parameter>
</parameters>
<services>
@@ -29,6 +30,13 @@
<tag name="routing.loader" />
</service>
+ <!-- events -->
+ <service id="oneup_uploader.listener.session" class="%oneup_uploader.listener.session.class%">
+ <argument type="service" id="session" />
+
+ <tag name="kernel.event_subscriber" />
+ </service>
+
</services>
</container>
\ No newline at end of file
| 0
|
b915fe5bb57e427f9cadf73454d835350b3529b6
|
1up-lab
|
OneupUploaderBundle
|
fixed uploads not being retryable if there was an error
|
commit b915fe5bb57e427f9cadf73454d835350b3529b6
Author: mitom <[email protected]>
Date: Mon Dec 16 14:27:53 2013 +0100
fixed uploads not being retryable if there was an error
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 5c641d0..dec76ce 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -120,7 +120,6 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
$this->openStream($dst, 'a');
}
-
// Meet the interface requirements
$uploadedFile = new FilesystemFile($this->unhandledChunk['chunk']);
@@ -128,6 +127,16 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
if ($renameChunk) {
$name = preg_replace('/^(\d+)_/', '', $target);
+ /* The name can only match if the same user in the same session is
+ * trying to upload a file under the same name AND the previous upload failed,
+ * somewhere between this function, and the cleanup call. If that happened
+ * the previous file is unaccessible by the user, but if it is not removed
+ * it will block the user from trying to re-upload it.
+ */
+ if ($this->filesystem->has($path.$name)) {
+ $this->filesystem->delete($path.$name);
+ }
+
$this->filesystem->rename($path.$target, $path.$name);
$target = $name;
}
@@ -149,7 +158,11 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
{
$results = $this->filesystem->listKeys($this->prefix.'/'.$uuid);
- return $results['keys'];
+ /* exclude files without an index, so if there is a completed file which
+ * failed to upload it will not get mixed together with new one's chunks.
+ */
+
+ return preg_grep('/^.+\/(\d+)_/', $results['keys']);
}
public function getFilesystem()
| 0
|
d64d4f36b11f1fc3cd78a772fa5609ff2157f15f
|
1up-lab
|
OneupUploaderBundle
|
Renamed test.
|
commit d64d4f36b11f1fc3cd78a772fa5609ff2157f15f
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:49:49 2013 +0200
Renamed test.
diff --git a/Tests/Routing/RoutingTest.php b/Tests/Routing/RouteLoaderTest.php
similarity index 100%
rename from Tests/Routing/RoutingTest.php
rename to Tests/Routing/RouteLoaderTest.php
| 0
|
ce5f1f555380460a00c1da2276cb0662a6be05cc
|
1up-lab
|
OneupUploaderBundle
|
CS fixes for Controller
|
commit ce5f1f555380460a00c1da2276cb0662a6be05cc
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 21:24:23 2013 +0200
CS fixes for Controller
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index b167aa6..4d797d1 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -29,7 +29,7 @@ abstract class AbstractChunkedController extends AbstractController
* @return array
*/
abstract protected function parseChunkedRequest(Request $request);
-
+
/**
* This function will be called in order to upload and save an
* uploaded chunk.
@@ -47,35 +47,35 @@ abstract class AbstractChunkedController extends AbstractController
// get basic container stuff
$request = $this->container->get('request');
$chunkManager = $this->container->get('oneup_uploader.chunk_manager');
-
+
// reset uploaded to always have a return value
$uploaded = null;
-
+
// get information about this chunked request
list($last, $uuid, $index, $orig) = $this->parseChunkedRequest($request);
-
+
$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) {
// we'll take the first chunk and append the others to it
// this way we don't need another file in temporary space for assembling
$chunks = $chunkManager->getChunks($uuid);
-
+
// assemble parts
$assembled = $chunkManager->assembleChunks($chunks);
$path = $assembled->getPath();
-
+
// create a temporary uploaded file to meet the interface restrictions
$uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true);
-
+
// validate this entity and upload on success
$this->validate($uploadedFile);
$uploaded = $this->handleUpload($uploadedFile, $response, $request);
-
+
$chunkManager->cleanup($path);
}
}
@@ -91,10 +91,10 @@ abstract class AbstractChunkedController extends AbstractController
protected function dispatchChunkEvents($uploaded, ResponseInterface $response, Request $request, $isLast)
{
$dispatcher = $this->container->get('event_dispatcher');
-
+
// 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 b5c91a1..1f6b0dd 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -5,7 +5,6 @@ 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;
@@ -13,7 +12,6 @@ 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;
use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
@@ -23,7 +21,7 @@ abstract class AbstractController
protected $storage;
protected $config;
protected $type;
-
+
public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
{
$this->container = $container;
@@ -31,7 +29,7 @@ abstract class AbstractController
$this->config = $config;
$this->type = $type;
}
-
+
abstract public function upload();
/**
@@ -50,17 +48,17 @@ abstract class AbstractController
protected function handleUpload(UploadedFile $file, ResponseInterface $response, Request $request)
{
$this->validate($file);
-
+
// no error happend, proceed
$namer = $this->container->get($this->config['namer']);
$name = $namer->name($file);
-
+
// perform the real upload
$uploaded = $this->storage->upload($file, $name);
-
+
$this->dispatchEvents($uploaded, $response, $request);
}
-
+
/**
* This function is a helper function which dispatches post upload
* and post persist events.
@@ -72,13 +70,13 @@ abstract class AbstractController
protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');
-
+
// 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);
-
- 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);
@@ -90,10 +88,10 @@ abstract class AbstractController
{
$dispatcher = $this->container->get('event_dispatcher');
$event = new ValidationEvent($file, $this->config, $this->type);
-
+
try {
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
- } catch(ValidationException $exception) {
+ } catch (ValidationException $exception) {
// pass the exception one level up
throw new UploadException($exception->getMessage());
}
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index e62ed31..41736a2 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -16,36 +16,35 @@ class BlueimpController extends AbstractChunkedController
$request = $this->container->get('request');
$response = new EmptyResponse();
$files = $request->files;
-
+
$chunked = !is_null($request->headers->get('content-range'));
-
- foreach($files as $file)
- {
+
+ foreach ($files as $file) {
$file = $file[0];
-
+
try {
$chunked ?
$this->handleChunkedUpload($file, $response, $request) :
$this->handleUpload($file, $response, $request)
;
- } catch(UploadException $e) {
+ } catch (UploadException $e) {
// return nothing
return new JsonResponse(array());
}
}
-
+
return new JsonResponse($response->assemble());
}
-
+
protected function parseChunkedRequest(Request $request)
{
$session = $this->container->get('session');
$headerRange = $request->headers->get('content-range');
$attachmentName = rawurldecode(preg_replace('/(^[^"]+")|("$)/', '', $request->headers->get('content-disposition')));
-
+
// split the header string to the appropriate parts
list($tmp, $startByte, $endByte, $totalBytes) = preg_split('/[^0-9]+/', $headerRange);
-
+
// getting information about chunks
// note: We don't have a chance to get the last $total
// correct. This is due to the fact that the $size variable
@@ -57,13 +56,13 @@ class BlueimpController extends AbstractChunkedController
$last = ($endByte + 1) == $totalBytes;
$index = $last ? \PHP_INT_MAX : floor($startByte / $size);
$total = ceil($totalBytes / $size);
-
+
// it is possible, that two clients send a file with the
// exact same filename, therefore we have to add the session
// to the uuid otherwise we will get a mess
$uuid = md5(sprintf('%s.%s', $attachmentName, $session->getId()));
$orig = $attachmentName;
-
+
return array($last, $uuid, $index, $orig);
}
-}
\ No newline at end of file
+}
diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php
index b9244fe..c26f040 100644
--- a/Controller/FancyUploadController.php
+++ b/Controller/FancyUploadController.php
@@ -15,20 +15,16 @@ class FancyUploadController extends AbstractController
$request = $this->container->get('request');
$response = new EmptyResponse();
$files = $request->files;
-
- foreach($files as $file)
- {
- try
- {
+
+ foreach ($files as $file) {
+ try {
$uploaded = $this->handleUpload($file, $response, $request);
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
// return nothing
return new JsonResponse(array());
}
}
-
+
return new JsonResponse($response->assemble());
}
-}
\ No newline at end of file
+}
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index c295234..2fcfe00 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -15,34 +15,30 @@ class FineUploaderController extends AbstractChunkedController
{
$request = $this->container->get('request');
$translator = $this->container->get('translator');
-
+
$response = new FineUploaderResponse();
$totalParts = $request->get('qqtotalparts', 1);
$files = $request->files;
$chunked = $totalParts > 1;
-
- foreach($files as $file)
- {
- try
- {
+
+ foreach ($files as $file) {
+ try {
$chunked ?
$this->handleChunkedUpload($file, $response, $request) :
$this->handleUpload($file, $response, $request)
;
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
$response->setSuccess(false);
$response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'));
-
+
// an error happended, return this error message.
return new JsonResponse($response->assemble());
}
}
-
+
return new JsonResponse($response->assemble());
}
-
+
protected function parseChunkedRequest(Request $request)
{
$index = $request->get('qqpartindex');
@@ -50,7 +46,7 @@ class FineUploaderController extends AbstractChunkedController
$uuid = $request->get('qquuid');
$orig = $request->get('qqfilename');
$last = ($total - 1) == $index;
-
+
return array($last, $uuid, $index, $orig);
}
-}
\ No newline at end of file
+}
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index 1b2ec9b..dbc75f6 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -13,29 +13,28 @@ use Oneup\UploaderBundle\Uploader\Response\MooUploadResponse;
class MooUploadController extends AbstractChunkedController
{
protected $response;
-
+
public function upload()
{
$request = $this->container->get('request');
$dispatcher = $this->container->get('event_dispatcher');
$translator = $this->container->get('translator');
-
+
$response = new MooUploadResponse();
$headers = $request->headers;
-
+
list($file, $uploadFileName) = $this->getUploadedFile($request);
-
+
// we have to get access to this object in another method
$this->response = $response;
-
+
// check if uploaded by chunks
$chunked = $headers->get('content-length') < $headers->get('x-file-size');
-
- try
- {
+
+ try {
// fill response object
$response = $this->response;
-
+
$response->setId($headers->get('x-file-id'));
$response->setSize($headers->get('content-length'));
$response->setName($headers->get('x-file-name'));
@@ -45,86 +44,79 @@ class MooUploadController extends AbstractChunkedController
$this->handleChunkedUpload($file, $response, $request) :
$this->handleUpload($file, $response, $request)
;
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
$response = $this->response;
-
+
$response->setFinish(true);
$response->setError(-1);
-
+
// return nothing
return new JsonResponse($response->assemble());
}
-
+
return new JsonResponse($response->assemble());
}
-
+
protected function parseChunkedRequest(Request $request)
{
$chunkManager = $this->container->get('oneup_uploader.chunk_manager');
$headers = $request->headers;
$parameters = array_keys($request->query->all());
-
+
$uuid = $headers->get('x-file-id');
$index = $this->createIndex($parameters[0]);
$orig = $headers->get('x-file-name');
$size = 0;
-
- try
- {
+
+ try {
// loop through every file that has been uploaded before
- foreach($chunkManager->getChunks($uuid) as $file)
- {
+ foreach ($chunkManager->getChunks($uuid) as $file) {
$size += $file->getSize();
}
- }
- catch(\InvalidArgumentException $e)
- {
+ } catch (\InvalidArgumentException $e) {
// do nothing: this exception will be thrown
// if the directory does not yet exist. this
// means we don't have a chunk and the actual
// size is 0
}
-
+
$last = $headers->get('x-file-size') == ($size + $headers->get('content-length'));
-
+
// store also to response object
$this->response->setFinish($last);
-
+
return array($last, $uuid, $index, $orig);
}
-
+
protected function createIndex($id)
{
$ints = 0;
-
+
// loop through every char and convert it to an integer
// we need this for sorting
- foreach(str_split($id) as $char)
- {
+ foreach (str_split($id) as $char) {
$ints += ord($char);
}
-
+
return $ints;
}
-
+
protected function getUploadedFile(Request $request)
{
$headers = $request->headers;
-
+
// create temporary file in systems temp dir
$tempFile = tempnam(sys_get_temp_dir(), 'uploader');
$contents = file_get_contents('php://input');
-
+
// put data from php://input to temp file
file_put_contents($tempFile, $contents);
-
+
$uploadFileName = sprintf('%s_%s', $headers->get('x-file-id'), $headers->get('x-file-name'));
-
+
// create an uploaded file to upload
$file = new UploadedFile($tempFile, $uploadFileName, null, null, null, true);
-
+
return array($file, $uploadFileName);
}
-}
\ No newline at end of file
+}
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
index 60501e9..162f6a8 100644
--- a/Controller/PluploadController.php
+++ b/Controller/PluploadController.php
@@ -16,41 +16,37 @@ class PluploadController extends AbstractChunkedController
$request = $this->container->get('request');
$response = new EmptyResponse();
$files = $request->files;
-
+
$chunked = !is_null($request->get('chunks'));
-
- foreach($files as $file)
- {
- try
- {
+
+ foreach ($files as $file) {
+ try {
$chunked ?
$this->handleChunkedUpload($file, $response, $request) :
$this->handleUpload($file, $response, $request)
;
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
// return nothing
return new JsonResponse(array());
}
}
-
+
return new JsonResponse($response->assemble());
}
-
+
protected function parseChunkedRequest(Request $request)
{
$session = $this->container->get('session');
-
+
$orig = $request->get('name');
$index = $request->get('chunk');
$last = $request->get('chunks') - 1 == $request->get('chunk');
-
+
// it is possible, that two clients send a file with the
// exact same filename, therefore we have to add the session
// to the uuid otherwise we will get a mess
$uuid = md5(sprintf('%s.%s', $orig, $session->getId()));
-
+
return array($last, $uuid, $index, $orig);
}
-}
\ No newline at end of file
+}
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index cc42c74..fe57183 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -15,20 +15,16 @@ class UploadifyController extends AbstractController
$request = $this->container->get('request');
$response = new EmptyResponse();
$files = $request->files;
-
- foreach($files as $file)
- {
- try
- {
+
+ foreach ($files as $file) {
+ try {
$uploaded = $this->handleUpload($file, $response, $request);
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
// return nothing
return new JsonResponse(array());
}
}
-
+
return new JsonResponse($response->assemble());
}
-}
\ No newline at end of file
+}
diff --git a/Controller/YUI3Controller.php b/Controller/YUI3Controller.php
index d5c87de..5b1e98f 100644
--- a/Controller/YUI3Controller.php
+++ b/Controller/YUI3Controller.php
@@ -15,20 +15,16 @@ class YUI3Controller extends AbstractController
$request = $this->container->get('request');
$response = new EmptyResponse();
$files = $request->files;
-
- foreach($files as $file)
- {
- try
- {
+
+ foreach ($files as $file) {
+ try {
$uploaded = $this->handleUpload($file, $response, $request);
- }
- catch(UploadException $e)
- {
+ } catch (UploadException $e) {
// return nothing
return new JsonResponse(array());
}
}
-
+
return new JsonResponse($response->assemble());
}
-}
\ No newline at end of file
+}
| 0
|
1db282127c8f43c664e714a51b4d7fe8ddaec453
|
1up-lab
|
OneupUploaderBundle
|
Update AbstractController.php
|
commit 1db282127c8f43c664e714a51b4d7fe8ddaec453
Author: DomoJonux <[email protected]>
Date: Thu Jan 7 09:14:44 2016 +0100
Update AbstractController.php
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 01ae713..75d3518 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -175,6 +175,7 @@ abstract class AbstractController
$event = new ValidationEvent($file, $this->getRequest(), $this->config, $this->type);
$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
+ $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::VALIDATION, $this->type), $event);
}
/**
| 0
|
d60f1ae8960853385ad3f803bb3fcd3a5651c2c6
|
1up-lab
|
OneupUploaderBundle
|
Allow PUT and PATCH verbs for upload
|
commit d60f1ae8960853385ad3f803bb3fcd3a5651c2c6
Author: Giorgio Premi <[email protected]>
Date: Mon Mar 2 12:45:23 2015 +0100
Allow PUT and PATCH verbs for upload
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 4e8df11..cd8c070 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -36,7 +36,7 @@ class RouteLoader extends Loader
array(),
'',
array(),
- array('POST')
+ array('POST', 'PUT', 'PATCH')
);
if ($options['enable_progress'] === true) {
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
index b5460ef..2b0abf7 100644
--- a/Tests/Controller/AbstractControllerTest.php
+++ b/Tests/Controller/AbstractControllerTest.php
@@ -51,14 +51,16 @@ abstract class AbstractControllerTest extends WebTestCase
$this->implTestCallBy('DELETE');
}
+ public function testCallByPatch()
+ {
+ $this->implTestCallBy('PATCH');
+ }
+
public function testCallByPost()
{
$this->implTestCallBy('POST');
}
- /**
- * @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
- */
public function testCallByPut()
{
$this->implTestCallBy('PUT');
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index a09385e..95b35ab 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -34,7 +34,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertEquals('json', $route->getDefault('_format'));
- $this->assertEquals(array('POST'), $route->getMethods());
+ $this->assertContains('POST', $route->getMethods());
}
}
@@ -56,7 +56,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
foreach ($routes as $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$this->assertEquals('json', $route->getDefault('_format'));
- $this->assertEquals(array('POST'), $route->getMethods());
+ $this->assertContains('POST', $route->getMethods());
$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
| 0
|
4c51d95f8b59b8373d351a26373cae0bcd69d650
|
1up-lab
|
OneupUploaderBundle
|
Add warning to custom namer doc
|
commit 4c51d95f8b59b8373d351a26373cae0bcd69d650
Author: JHGitty <[email protected]>
Date: Sun Feb 7 19:46:38 2016 +0100
Add warning to custom namer doc
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index c83002d..0d9dc17 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -24,7 +24,7 @@ class CatNamer implements NamerInterface
}
```
-To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful.
+To match the `NamerInterface` you have to implement the function `name()` which expects an `FileInterface` and should return a string representing the name of the given file. The example above would name every file _grumpycat.jpg_ and is therefore not very useful. The namer should return an unique name to avoid issues if the file already exists.
Next, register your created namer as a service in your `services.xml`
| 0
|
564839351006a86888743e49cd984c8abd985138
|
1up-lab
|
OneupUploaderBundle
|
Changed generated route name as we now only have one method per mapping.
|
commit 564839351006a86888743e49cd984c8abd985138
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:29:59 2013 +0200
Changed generated route name as we now only have one method per mapping.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 3ccc0a0..016fb2b 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -38,7 +38,7 @@ class RouteLoader extends Loader
array('_method' => 'POST')
);
- $routes->add(sprintf('_uploader_%s_upload', $type), $upload);
+ $routes->add(sprintf('_uploader_%s', $type), $upload);
}
return $routes;
| 0
|
4cf73508bf6676454fcaed4b1d63f59817317153
|
1up-lab
|
OneupUploaderBundle
|
Minor improvements
* Updated Dropzone's url
* Added style to make dropzone visible immediately
|
commit 4cf73508bf6676454fcaed4b1d63f59817317153
Author: Thomas Landauer <[email protected]>
Date: Sun Oct 25 19:53:32 2015 +0100
Minor improvements
* Updated Dropzone's url
* Added style to make dropzone visible immediately
diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md
index 66fc318..875fb3d 100644
--- a/Resources/doc/frontend_dropzone.md
+++ b/Resources/doc/frontend_dropzone.md
@@ -4,9 +4,9 @@ Use Dropzone in your Symfony2 application
Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`.
```html
-<script type="text/javascript" src="https://rawgithub.com/enyo/dropzone/master/downloads/dropzone.js"></script>
+<script type="text/javascript" src="https://raw.github.com/enyo/dropzone/master/dist/dropzone.js"></script>
-<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone">
+<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black">
</form>
```
| 0
|
222e4d52c9c042f9dbc17f331daaf6d13fbed80f
|
1up-lab
|
OneupUploaderBundle
|
Adapted the FineUploaderController to the new abstract structure.
|
commit 222e4d52c9c042f9dbc17f331daaf6d13fbed80f
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 23:46:50 2013 +0200
Adapted the FineUploaderController to the new abstract structure.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 60800cf..c53e574 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -11,12 +11,11 @@ use Symfony\Component\HttpFoundation\Request;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use Oneup\UploaderBundle\Event\PostUploadEvent;
-use Oneup\UploaderBundle\Controller\UploadControllerInterface;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
use Oneup\UploaderBundle\Uploader\Response\ResponseInterface;
-abstract class AbstractController implements UploadControllerInterface
+abstract class AbstractController
{
protected $container;
protected $storage;
@@ -30,6 +29,8 @@ abstract class AbstractController implements UploadControllerInterface
$this->config = $config;
$this->type = $type;
}
+
+ abstract public function upload();
protected function handleUpload(UploadedFile $file)
{
@@ -45,9 +46,9 @@ abstract class AbstractController implements UploadControllerInterface
return $uploaded;
}
- protected function dispatchEvents($uploaded, ResponseInterface $response)
+ protected function dispatchEvents($uploaded, ResponseInterface $response, Request $request)
{
- $request = $this->container->get('request');
+ $dispatcher = $this->container->get('event_dispatcher');
$postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
$dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index a4f4d56..e2c6026 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -37,7 +37,7 @@ class BlueimpController extends AbstractChunkedController
$uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
// dispatch POST_PERSIST AND POST_UPLOAD events
- $this->dispatchEvents($uploaded, $response);
+ $this->dispatchEvents($uploaded, $response, $request);
}
catch(UploadException $e)
{
diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php
index 178378e..7fcbace 100644
--- a/Controller/FineUploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -6,33 +6,20 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\Exception\UploadException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
use Oneup\UploaderBundle\UploadEvents;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use Oneup\UploaderBundle\Event\PostUploadEvent;
-use Oneup\UploaderBundle\Controller\UploadControllerInterface;
+use Oneup\UploaderBundle\Controller\AbstractChunkedController;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
-class FineUploaderController implements UploadControllerInterface
+class FineUploaderController extends AbstractChunkedController
{
- protected $container;
- protected $storage;
- protected $config;
- protected $type;
-
- public function __construct(ContainerInterface $container, StorageInterface $storage, array $config, $type)
- {
- $this->container = $container;
- $this->storage = $storage;
- $this->config = $config;
- $this->type = $type;
- }
-
public function upload()
{
$request = $this->container->get('request');
- $dispatcher = $this->container->get('event_dispatcher');
$translator = $this->container->get('translator');
$response = new FineUploaderResponse();
@@ -45,16 +32,9 @@ class FineUploaderController implements UploadControllerInterface
try
{
$uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
-
- $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config);
- $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
-
- if(!$this->config['use_orphanage'])
- {
- // dispatch post upload event
- $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config);
- $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent);
- }
+
+ // dispatch POST_PERSIST AND POST_UPLOAD events
+ $this->dispatchEvents($uploaded, $response, $request);
}
catch(UploadException $e)
{
@@ -69,76 +49,14 @@ class FineUploaderController implements UploadControllerInterface
return new JsonResponse($response->assemble());
}
- protected function handleUpload(UploadedFile $file)
- {
- $this->validate($file);
-
- // no error happend, proceed
- $namer = $this->container->get($this->config['namer']);
- $name = $namer->name($file);
-
- // perform the real upload
- $uploaded = $this->storage->upload($file, $name);
-
- return $uploaded;
- }
-
- protected function handleChunkedUpload(UploadedFile $file)
+ protected function parseChunkedRequest(Request $request)
{
- $request = $this->container->get('request');
- $chunkManager = $this->container->get('oneup_uploader.chunk_manager');
- $uploaded = null;
-
- // getting information about chunks
$index = $request->get('qqpartindex');
$total = $request->get('qqtotalparts');
$uuid = $request->get('qquuid');
$orig = $request->get('qqfilename');
-
- $chunkManager->addChunk($uuid, $index, $file, $orig);
-
- // if all chunks collected and stored, proceed
- // with reassembling the parts
- if(($total - 1) == $index)
- {
- // we'll take the first chunk and append the others to it
- // this way we don't need another file in temporary space for assembling
- $chunks = $chunkManager->getChunks($uuid);
-
- // assemble parts
- $assembled = $chunkManager->assembleChunks($chunks);
- $path = $assembled->getPath();
-
- // create a temporary uploaded file to meet the interface restrictions
- $uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, null, null, true);
-
- // validate this entity and upload on success
- $this->validate($uploadedFile);
- $uploaded = $this->handleUpload($uploadedFile);
-
- $chunkManager->cleanup($path);
- }
-
- return $uploaded;
- }
-
- protected function validate(UploadedFile $file)
- {
- // check if the file size submited by the client is over the max size in our config
- if($file->getClientSize() > $this->config['max_size'])
- throw new UploadException('error.maxsize');
-
- $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
-
- // if this mapping defines at least one type of an allowed extension,
- // test if the current is in this array
- if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions']))
- throw new UploadException('error.whitelist');
-
- // check if the current extension is mentioned in the disallowed types
- // and if so, throw an exception
- if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions']))
- throw new UploadException('error.blacklist');
+ $last = ($total - 1) == $index;
+ return array($last, $uuid, $index, $orig);
}
}
\ No newline at end of file
diff --git a/Controller/UploadControllerInterface.php b/Controller/UploadControllerInterface.php
deleted file mode 100644
index 977375e..0000000
--- a/Controller/UploadControllerInterface.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Controller;
-
-interface UploadControllerInterface
-{
- public function upload();
-}
\ No newline at end of file
| 0
|
52865bd21f1b8921bec55ed499be41b8a6e78377
|
1up-lab
|
OneupUploaderBundle
|
Readded the codeblock for the assembling of chunks if load distribution is false.
|
commit 52865bd21f1b8921bec55ed499be41b8a6e78377
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:47:33 2013 +0200
Readded the codeblock for the assembling of chunks if load distribution is false.
diff --git a/Controller/AbstractChunkedController.php b/Controller/AbstractChunkedController.php
index c197ec1..d7b0365 100644
--- a/Controller/AbstractChunkedController.php
+++ b/Controller/AbstractChunkedController.php
@@ -66,6 +66,11 @@ abstract class AbstractChunkedController extends AbstractController
// if all chunks collected and stored, proceed
// with reassembling the parts
if ($last) {
+ if (!$chunkManager->getLoadDistribution()) {
+ $chunks = $chunkManager->getChunks($uuid);
+ $assembled = $chunkManager->assembleChunks($chunks, true, true);
+ }
+
$path = $assembled->getPath();
// create a temporary uploaded file to meet the interface restrictions
| 0
|
bafaa89108f01ad790c750c9155836a658e1ecc1
|
1up-lab
|
OneupUploaderBundle
|
Removed unused die()
|
commit bafaa89108f01ad790c750c9155836a658e1ecc1
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 22:51:06 2013 +0200
Removed unused die()
diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php
index c9b6286..438bd08 100644
--- a/Controller/BlueimpController.php
+++ b/Controller/BlueimpController.php
@@ -141,8 +141,6 @@ class BlueimpController implements UploadControllerInterface
}
return $uploaded;
-
- die();
}
protected function validate(UploadedFile $file)
| 0
|
86efe3662c06ca6decbf997d9528bcae3e8c9fd0
|
1up-lab
|
OneupUploaderBundle
|
Blacklist test against a files mime type.
|
commit 86efe3662c06ca6decbf997d9528bcae3e8c9fd0
Author: Jim Schmid <[email protected]>
Date: Tue Apr 23 21:16:02 2013 +0200
Blacklist test against a files mime type.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 5c713c0..c22b3d1 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -67,6 +67,9 @@ class Configuration implements ConfigurationInterface
->arrayNode('allowed_mimetypes')
->prototype('scalar')->end()
->end()
+ ->arrayNode('disallowed_mimetypes')
+ ->prototype('scalar')->end()
+ ->end()
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
diff --git a/EventListener/DisallowedMimetypeValidationListener.php b/EventListener/DisallowedMimetypeValidationListener.php
new file mode 100644
index 0000000..3981298
--- /dev/null
+++ b/EventListener/DisallowedMimetypeValidationListener.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class DisallowedMimetypeValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ if(count($config['disallowed_mimetypes']) == 0) {
+ return;
+ }
+
+ $finfo = finfo_open(FILEINFO_MIME_TYPE);
+ $mimetype = finfo_file($finfo, $file->getRealpath());
+
+ if(in_array($mimetype, $config['disallowed_mimetypes'])) {
+ throw new ValidationException('error.blacklist');
+ }
+ }
+}
diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml
index 51b1449..a47e6a9 100644
--- a/Resources/config/validators.xml
+++ b/Resources/config/validators.xml
@@ -19,6 +19,10 @@
<service id="oneup_uploader.validation_listener.allowed_mimetype" class="Oneup\UploaderBundle\EventListener\AllowedMimetypeValidationListener">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
+
+ <service id="oneup_uploader.validation_listener.disallowed_mimetype" class="Oneup\UploaderBundle\EventListener\DisallowedMimetypeValidationListener">
+ <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
+ </service>
</services>
</container>
| 0
|
bf82ebc63684d3698ec020d2c9a96163815288db
|
1up-lab
|
OneupUploaderBundle
|
Whoopsi.
|
commit bf82ebc63684d3698ec020d2c9a96163815288db
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 12:07:34 2013 +0100
Whoopsi.
diff --git a/Uploader/Orphanage/OrphanageInterface.php b/Uploader/Orphanage/OrphanageInterface.php
index 07b5558..8e75e4e 100644
--- a/Uploader/Orphanage/OrphanageInterface.php
+++ b/Uploader/Orphanage/OrphanageInterface.php
@@ -6,5 +6,5 @@ use Symfony\Component\HttpFoundation\File\File;
interface OrphanageInterface
{
- public function add(File $file, $name);
+ public function addFile(File $file, $name);
}
| 0
|
34d22041d40ff45f87de56cd617a580d48cbdd8c
|
1up-lab
|
OneupUploaderBundle
|
Fix #422 PHP 8.1 compatibility / deprecation warnings (#427)
|
commit 34d22041d40ff45f87de56cd617a580d48cbdd8c
Author: Martin Mandl <[email protected]>
Date: Mon Jul 25 09:48:07 2022 +0200
Fix #422 PHP 8.1 compatibility / deprecation warnings (#427)
diff --git a/src/Uploader/Response/AbstractResponse.php b/src/Uploader/Response/AbstractResponse.php
index 8223619..e2507e0 100644
--- a/src/Uploader/Response/AbstractResponse.php
+++ b/src/Uploader/Response/AbstractResponse.php
@@ -46,6 +46,7 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface
*
* @return mixed|null
*/
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->data[$offset] ?? null;
| 0
|
0abea705145a0943144f0eebf99ebcc6373d3da9
|
1up-lab
|
OneupUploaderBundle
|
Added Travis CI integration.
|
commit 0abea705145a0943144f0eebf99ebcc6373d3da9
Author: Jim Schmid <[email protected]>
Date: Fri Mar 8 18:56:55 2013 +0100
Added Travis CI integration.
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..bec17da
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
\ No newline at end of file
| 0
|
249977688334962d0f8d7714ff50f59b349d840e
|
1up-lab
|
OneupUploaderBundle
|
Removed unused property.
|
commit 249977688334962d0f8d7714ff50f59b349d840e
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:49:10 2013 +0200
Removed unused property.
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 016fb2b..c7dfb91 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -8,7 +8,6 @@ use Symfony\Component\Routing\RouteCollection;
class RouteLoader extends Loader
{
- protected $name;
protected $controllers;
public function __construct()
| 0
|
bd400e893294d1f6fca31fb2de252c7eb94d7da4
|
1up-lab
|
OneupUploaderBundle
|
broke configuration up even more fro scrutinizer
|
commit bd400e893294d1f6fca31fb2de252c7eb94d7da4
Author: mitom <[email protected]>
Date: Thu Oct 10 16:11:07 2013 +0200
broke configuration up even more fro scrutinizer
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index b5e2ab5..a86036f 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -42,7 +42,7 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach ($this->config['mappings'] as $key => $mapping) {
- $this->processMapping($key, $mapping);
+ $controllers[$key] = $this->processMapping($key, $mapping);
}
$container->setParameter('oneup_uploader.controllers', $controllers);
@@ -62,15 +62,26 @@ class OneupUploaderExtension extends Extension
$this->getMaxUploadSize($mapping['max_size']) :
$mapping['max_size']
;
+ $controllerName = $this->createController($key, $mapping);
+ $this->verifyPhpVersion($mapping);
+
+ return array($controllerName, array(
+ 'enable_progress' => $mapping['enable_progress'],
+ 'enable_cancelation' => $mapping['enable_cancelation']
+ ));
+ }
+
+ protected function createController($key, $config)
+ {
// create the storage service according to the configuration
- $storageService = $this->createStorageService($mapping['storage'], $key, isset($mapping['orphanage']) ? :null);
+ $storageService = $this->createStorageService($config['storage'], $key, isset($config['orphanage']) ? :null);
- if ($mapping['frontend'] != 'custom') {
+ if ($config['frontend'] != 'custom') {
$controllerName = sprintf('oneup_uploader.controller.%s', $key);
- $controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $mapping['frontend']);
+ $controllerType = sprintf('%%oneup_uploader.controller.%s.class%%', $config['frontend']);
} else {
- $customFrontend = $mapping['custom_frontend'];
+ $customFrontend = $config['custom_frontend'];
$controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']);
$controllerType = $customFrontend['class'];
@@ -79,9 +90,7 @@ class OneupUploaderExtension extends Extension
throw new ServiceNotFoundException('Empty controller class or name. If you really want to use a custom frontend implementation, be sure to provide a class and a name.');
}
- $errorHandler = is_null($mapping['error_handler']) ?
- new Reference('oneup_uploader.error_handler.'.$mapping['frontend']) :
- new Reference($mapping['error_handler']);
+ $errorHandler = $this->createErrorHandler($config);
// create controllers based on mapping
$this->container
@@ -90,23 +99,30 @@ class OneupUploaderExtension extends Extension
->addArgument(new Reference('service_container'))
->addArgument($storageService)
->addArgument($errorHandler)
- ->addArgument($mapping)
+ ->addArgument($config)
->addArgument($key)
->addTag('oneup_uploader.routable', array('type' => $key))
->setScope('request')
;
- if ($mapping['enable_progress'] || $mapping['enable_cancelation']) {
+ return $controllerName;
+ }
+
+ protected function createErrorHandler($config)
+ {
+ return is_null($config['error_handler']) ?
+ new Reference('oneup_uploader.error_handler.'.$config['frontend']) :
+ new Reference($config['error_handler']);
+ }
+
+ protected function verifyPhpVersion($config)
+ {
+ if ($config['enable_progress'] || $config['enable_cancelation']) {
if (strnatcmp(phpversion(), '5.4.0') < 0) {
throw new InvalidArgumentException('You need to run PHP version 5.4.0 or above to use the progress/cancelation feature.');
}
}
-
- $controllers[$key] = array($controllerName, array(
- 'enable_progress' => $mapping['enable_progress'],
- 'enable_cancelation' => $mapping['enable_cancelation']
- ));
}
protected function createChunkStorageService()
| 0
|
9f1dd1249fc77ad24618c9816d8e936bdbadaa0b
|
1up-lab
|
OneupUploaderBundle
|
Fixed RouteLoader test according to the new controller loading mechanism.
|
commit 9f1dd1249fc77ad24618c9816d8e936bdbadaa0b
Author: Jim Schmid <[email protected]>
Date: Mon Apr 8 10:28:03 2013 +0200
Fixed RouteLoader test according to the new controller loading mechanism.
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index 4bd7ca9..4145b86 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -8,19 +8,18 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testRouteLoader()
{
- $routeLoader = new RouteLoader();
-
- // for code coverage
- $this->assertTrue($routeLoader->supports('grumpy', 'uploader'));
-
$cat = 'GrumpyCatController';
$dog = 'HelloThisIsDogController';
+
+ $routeLoader = new RouteLoader(array(
+ 'cat' => $cat,
+ 'dog' => $dog
+ ));
- // add a new controller and check if the route will be added
- $routeLoader->addController('cat', $cat);
- $routeLoader->addController('dog', $dog);
$routes = $routeLoader->load(null);
-
+
+ // for code coverage
+ $this->assertTrue($routeLoader->supports('grumpy', 'uploader'));
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes);
$this->assertCount(2, $routes);
| 0
|
72671ee9b9ca21bfe16741048caf5155ba16084f
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #8 from 1up-lab/frontend_agnostic
Make the Bundle frontend agnostic
|
commit 72671ee9b9ca21bfe16741048caf5155ba16084f
Merge: baede53 dccc513
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 16:09:39 2013 -0700
Merge pull request #8 from 1up-lab/frontend_agnostic
Make the Bundle frontend agnostic
| 0
|
9a001b8806b83cf46e5ed84bd44db023e331103d
|
1up-lab
|
OneupUploaderBundle
|
Added missing methods to OrphanageInterface.
|
commit 9a001b8806b83cf46e5ed84bd44db023e331103d
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 17:18:18 2013 +0100
Added missing methods to OrphanageInterface.
diff --git a/Uploader/Orphanage/OrphanageInterface.php b/Uploader/Orphanage/OrphanageInterface.php
index 8e75e4e..00b584a 100644
--- a/Uploader/Orphanage/OrphanageInterface.php
+++ b/Uploader/Orphanage/OrphanageInterface.php
@@ -7,4 +7,5 @@ use Symfony\Component\HttpFoundation\File\File;
interface OrphanageInterface
{
public function addFile(File $file, $name);
+ public function uploadFiles($keep = false);
}
| 0
|
8172cea52f0daf23cf30be17fc657cae9cd99914
|
1up-lab
|
OneupUploaderBundle
|
Moved UploaderController to specific FineUploaderController
|
commit 8172cea52f0daf23cf30be17fc657cae9cd99914
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 20:57:50 2013 +0200
Moved UploaderController to specific FineUploaderController
diff --git a/Controller/UploaderController.php b/Controller/FineUploaderController.php
similarity index 98%
rename from Controller/UploaderController.php
rename to Controller/FineUploaderController.php
index 3bf61a5..35996c0 100644
--- a/Controller/UploaderController.php
+++ b/Controller/FineUploaderController.php
@@ -14,7 +14,7 @@ use Oneup\UploaderBundle\Controller\UploadControllerInterface;
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
-class UploaderController implements UploadControllerInterface
+class FineUploaderController implements UploadControllerInterface
{
protected $container;
protected $storage;
| 0
|
d6d75255d3cf6334c286b440ec53c736ec76ca7d
|
1up-lab
|
OneupUploaderBundle
|
Added check for max_size: -1 (#329)
|
commit d6d75255d3cf6334c286b440ec53c736ec76ca7d
Author: Nikita Pimoshenko <[email protected]>
Date: Tue Jun 5 10:34:16 2018 +0200
Added check for max_size: -1 (#329)
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 6371cd8..4ed42dd 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -291,6 +291,10 @@ class OneupUploaderExtension extends Extension
$maxPost = $this->getValueInBytes(ini_get('upload_max_filesize'));
$maxFile = $this->getValueInBytes(ini_get('post_max_size'));
+ if ($input < 0) {
+ return min($maxPost, $maxFile);
+ }
+
return min(min($input, $maxPost), $maxFile);
}
| 0
|
ac864c6d7b3e127970d4ced1b83ca99c80c176fe
|
1up-lab
|
OneupUploaderBundle
|
Tested FancyUpload controller.
|
commit ac864c6d7b3e127970d4ced1b83ca99c80c176fe
Author: Jim Schmid <[email protected]>
Date: Mon May 6 22:55:34 2013 +0200
Tested FancyUpload controller.
diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml
index de85d76..7e78b16 100644
--- a/Tests/App/config/config.yml
+++ b/Tests/App/config/config.yml
@@ -29,6 +29,11 @@ oneup_uploader:
storage:
directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+ fancyupload:
+ frontend: fancyupload
+ storage:
+ directory: %kernel.root_dir%/cache/%kernel.environment%/upload
+
blueimp:
frontend: blueimp
storage:
diff --git a/Tests/Controller/FancyUploadTest.php b/Tests/Controller/FancyUploadTest.php
new file mode 100644
index 0000000..e3069c5
--- /dev/null
+++ b/Tests/Controller/FancyUploadTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Controller;
+
+use Symfony\Component\HttpFoundation\File\UploadedFile;
+use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+
+class FancyUploadTest extends AbstractControllerTest
+{
+ protected function getConfigKey()
+ {
+ return 'fancyupload';
+ }
+
+ protected function getRequestParameters()
+ {
+ return array();
+ }
+
+ protected function getRequestFile()
+ {
+ return new UploadedFile(
+ $this->createTempFile(128),
+ 'cat.txt',
+ 'text/plain',
+ 128
+ );
+ }
+}
| 0
|
ffbdf2fd02a8e2957b719fd3ae82a3d9f2fa1daa
|
1up-lab
|
OneupUploaderBundle
|
Further documented the changed events.
|
commit ffbdf2fd02a8e2957b719fd3ae82a3d9f2fa1daa
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 19:59:21 2013 +0200
Further documented the changed events.
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index dcb0343..e3cda00 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -77,5 +77,17 @@ The Event object provides the following methods.
* `getFile`: Get the uploaded file. Is either an instance of `Gaufrette\File` or `Symfony\Component\HttpFoundation\File\File`.
* `getRequest`: Get the current request including custom variables.
+* `getResponse`: Get the response object to add custom return data.
* `getType`: Get the name of the mapping of the current upload. Useful if you have multiple mappings and EventListeners.
-* `getConfig`: Get the config of the mapping.
\ No newline at end of file
+* `getConfig`: Get the config of the mapping.
+
+## Using chunked uploads
+If you are using chunked uploads and hook into the `oneup_uploader.post_chunk_upload` event, you will get `PostChunkUploadEvent` in your listeners. This Event type differs from the previously introduced ones. You'll have the following methods.
+
+
+* `getChunk`: Get the chunk file. Is an instance of `Symfony\Component\HttpFoundation\File\File`.
+* `getRequest`: Get the current request including custom variables.
+* `getResponse`: Get the response object to add custom return data.
+* `getType`: Get the name of the mapping of the current upload. Useful if you have multiple mappings and EventListeners.
+* `getConfig`: Get the config of the mapping.
+* `isLast`: Returns `true` if this is the last chunk to be uploaded, `false` otherwise.
diff --git a/Resources/doc/events.md b/Resources/doc/events.md
index a7a5ff5..a789691 100644
--- a/Resources/doc/events.md
+++ b/Resources/doc/events.md
@@ -8,7 +8,7 @@ For a list of general Events, you can always have a look at the `UploadEvents.ph
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)
+* `oneup_uploader.post_chunk_upload` Will be dispatched after a chunk has been uploaded. The Event itself has a property `isLast` which shows if this is the last chunk for the uploaded file.
Moreover this bundles also dispatches some special kind of generic events you can listen to.
| 0
|
f28f251a6c8c5501db38af2a2b6e1a8337e079f5
|
1up-lab
|
OneupUploaderBundle
|
Fix link
|
commit f28f251a6c8c5501db38af2a2b6e1a8337e079f5
Author: David Greminger <[email protected]>
Date: Tue Sep 22 15:30:54 2015 +0200
Fix link
diff --git a/Resources/doc/frontend_plupload.md b/Resources/doc/frontend_plupload.md
index deb1ce0..0c2e01d 100644
--- a/Resources/doc/frontend_plupload.md
+++ b/Resources/doc/frontend_plupload.md
@@ -1,7 +1,7 @@
Use Plupload in your Symfony2 application
=========================================
-Download [Plupload](http://http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`.
+Download [Plupload](http://www.plupload.com/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}`.
```html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
| 0
|
6b5a2b6aa5d833ed6460e67daa5615504c74b0f4
|
1up-lab
|
OneupUploaderBundle
|
Added a dispatched POST_UPLOAD event. Will be used for session storage or custom logic (for example orm-bindings..)
|
commit 6b5a2b6aa5d833ed6460e67daa5615504c74b0f4
Author: Jim Schmid <[email protected]>
Date: Wed Mar 13 09:29:02 2013 +0100
Added a dispatched POST_UPLOAD event. Will be used for session storage or custom logic (for example orm-bindings..)
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 7314147..6d29961 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -3,6 +3,8 @@
namespace Oneup\UploaderBundle\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
+
+use Oneup\UploaderBundle\StoreEvents;
use Oneup\UploaderBundle\Controller\UploadControllerInterface;
class UploaderController implements UploadControllerInterface
@@ -10,12 +12,13 @@ class UploaderController implements UploadControllerInterface
protected $namer;
protected $storage;
- public function __construct($request, $namer, $storage, $config)
+ public function __construct($request, $namer, $storage, $config, $dispatcher)
{
$this->request = $request;
$this->namer = $namer;
$this->storage = $storage;
$this->config = $config;
+ $this->dispatcher = $dispatcher;
}
public function upload()
@@ -33,7 +36,11 @@ class UploaderController implements UploadControllerInterface
foreach($files as $file)
{
$name = $this->namer->name($file, $this->config['directory_prefix']);
- $this->storage->upload($file, $name);
+ $uploaded = $this->storage->upload($file, $name);
+
+ // dispatch POST_UPLOAD event
+ $event = new PostUploadEvent($uploaded, $request);
+ $this->dispatcher->dispatch(StoreEvents::POST_UPLOAD, $event);
}
return new JsonResponse(array('success' => true));
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 2640c61..8d26404 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -93,6 +93,9 @@ class OneupUploaderExtension extends Extension
// after all, add the config as argument
->addArgument($mapping)
+ // we need the EventDispatcher for post upload events
+ ->addArgument(new Reference('event.dispatcher'))
+
->addTag('oneup_uploader.routable', array('type' => $type))
->setScope('request')
;
diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php
new file mode 100644
index 0000000..a24af56
--- /dev/null
+++ b/Event/PostUploadEvent.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Oneup\UploaderBundle\Event;
+
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\HttpFoundation\Request;
+
+use Gaufrette\File;
+
+class PostUploadEvent extends Event
+{
+ protected $file;
+ protected $request;
+
+ public function __construct(File $file, Request $request)
+ {
+ $this->file = $file;
+ $this->request = $request;
+ }
+
+ public function getFile()
+ {
+ return $this->file;
+ }
+
+ public function getRequest()
+ {
+ return $this->request;
+ }
+}
\ No newline at end of file
diff --git a/UploadEvents.php b/UploadEvents.php
new file mode 100644
index 0000000..39adf0b
--- /dev/null
+++ b/UploadEvents.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Oneup\UploaderBundle;
+
+final class UploadEvents
+{
+ const POST_UPLOAD = 'oneup.uploader.post.upload';
+}
\ No newline at end of file
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index b6918c6..4268814 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -42,7 +42,7 @@ class GaufretteStorage implements StorageInterface
$dst->close();
$src->close();
- return true;
+ return $this->filesystem->get($name);
}
public function remove(File $file)
| 0
|
052148a91278b16bc592ce65ed9b1dddb5105ad6
|
1up-lab
|
OneupUploaderBundle
|
gaufette chunk storage test
|
commit 052148a91278b16bc592ce65ed9b1dddb5105ad6
Author: mitom <[email protected]>
Date: Fri Oct 11 16:01:43 2013 +0200
gaufette chunk storage test
diff --git a/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php
new file mode 100644
index 0000000..af1f32f
--- /dev/null
+++ b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
+
+use Symfony\Component\Filesystem\Filesystem;
+use Symfony\Component\Finder\Finder;
+
+abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase
+{
+ protected $tmpDir;
+ protected $storage;
+
+ 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;
+ $numberOfFiles = 10;
+
+ $finder = new Finder();
+ $finder->in($this->tmpDir);
+
+ $this->fillDirectory($numberOfFiles);
+ $this->assertCount($numberOfFiles, $finder);
+
+ $this->storage->clear($maxage);
+
+ $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));
+ }
+ }
+
+ public function testClearIfDirectoryDoesNotExist()
+ {
+ $filesystem = new Filesystem();
+ $filesystem->remove($this->tmpDir);
+
+ $this->storage->clear(10);
+
+ // yey, no exception
+ $this->assertTrue(true);
+ }
+
+ protected function fillDirectory($number)
+ {
+ $system = new Filesystem();
+
+ for ($i = 0; $i < $number; $i ++) {
+ $system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
+ }
+ }
+}
diff --git a/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php b/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php
index 1df65ea..8e54cc4 100644
--- a/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php
+++ b/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php
@@ -2,11 +2,10 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
-use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage;
-class FilesystemStorageTest extends \PHPUnit_Framework_TestCase
+class FilesystemStorageTest extends ChunkStorageTest
{
protected $tmpDir;
@@ -19,81 +18,14 @@ class FilesystemStorageTest extends \PHPUnit_Framework_TestCase
$system->mkdir($tmpDir);
$this->tmpDir = $tmpDir;
- }
-
- public function tearDown()
- {
- $system = new Filesystem();
- $system->remove($this->tmpDir);
- }
-
- public function testExistanceOfTmpDir()
- {
- $this->assertTrue(is_dir($this->tmpDir));
- $this->assertTrue(is_writeable($this->tmpDir));
- }
-
- public function testFillOfTmpDir()
- {
- $finder = new Finder();
- $finder->in($this->tmpDir);
-
- $numberOfFiles = 10;
-
- $this->fillDirectory($numberOfFiles);
- $this->assertCount($numberOfFiles, $finder);
- }
-
- public function testChunkCleanup()
- {
- // get a manager configured with a max-age of 5 minutes
- $maxage = 5 * 60;
- $manager = $this->getStorage();
- $numberOfFiles = 10;
-
- $finder = new Finder();
- $finder->in($this->tmpDir);
-
- $this->fillDirectory($numberOfFiles);
- $this->assertCount(10, $finder);
-
- $manager->clear($maxage);
-
- $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));
- }
- }
-
- public function testClearIfDirectoryDoesNotExist()
- {
- $filesystem = new Filesystem();
- $filesystem->remove($this->tmpDir);
-
- $manager = $this->getStorage();
- $manager->clear(10);
-
- // yey, no exception
- $this->assertTrue(true);
- }
-
- protected function getStorage()
- {
- return new FilesystemStorage(array(
+ $this->storage = new FilesystemStorage(array(
'directory' => $this->tmpDir
));
}
- protected function fillDirectory($number)
+ public function tearDown()
{
$system = new Filesystem();
-
- for ($i = 0; $i < $number; $i ++) {
- $system->touch(sprintf('%s/%s', $this->tmpDir, uniqid()), time() - $i * 60);
- }
+ $system->remove($this->tmpDir);
}
}
diff --git a/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php b/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php
new file mode 100644
index 0000000..375d450
--- /dev/null
+++ b/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
+
+use Oneup\UploaderBundle\Uploader\Chunk\Storage\GaufretteStorage;
+use Symfony\Component\Filesystem\Filesystem;
+use Gaufrette\Adapter\Local as Adapter;
+use Gaufrette\Filesystem as GaufretteFilesystem;
+
+class GaufretteStorageTest extends ChunkStorageTest
+{
+ protected $parentDir;
+ protected $chunkKey = 'chunks';
+ protected $chunkDir;
+
+ public function setUp()
+ {
+ // create a cache dir
+ $parentDir = sprintf('/tmp/%s', uniqid());
+
+ $system = new Filesystem();
+ $system->mkdir($parentDir);
+
+ $this->parentDir = $parentDir;
+
+ $adapter = new Adapter($this->parentDir, true);
+
+ $filesystem = new GaufretteFilesystem($adapter);
+
+ $this->storage = new GaufretteStorage($filesystem, 100000, null, $this->chunkKey);
+ $this->tmpDir = $this->parentDir.'/'.$this->chunkKey;
+
+ $system->mkdir($this->tmpDir);
+
+ }
+
+ public function tearDown()
+ {
+ $system = new Filesystem();
+ $system->remove($this->parentDir);
+ }
+
+}
diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php
index 6c4cd04..5c641d0 100644
--- a/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -40,7 +40,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
$prefix = $prefix ? :$this->prefix;
$matches = $this->filesystem->listKeys($prefix);
- $limit = time()+$maxAge;
+ $now = time();
$toDelete = array();
// Collect the directories that are old,
@@ -48,14 +48,14 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
// but after the files are deleted the dirs
// would remain
foreach ($matches['dirs'] as $key) {
- if ($limit < $this->filesystem->mtime($key)) {
+ if ($maxAge <= $now-$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)) {
+ if ($maxAge <= $now-$this->filesystem->mtime($key)) {
$this->filesystem->delete($key);
}
}
| 0
|
6d945acde6d375b2077f0874e7a2a9757dd9874e
|
1up-lab
|
OneupUploaderBundle
|
replace the deprecated "Twig_Function_Method"
replace it with the recommended "Twig_SimpleFunction" as per Twig docs
|
commit 6d945acde6d375b2077f0874e7a2a9757dd9874e
Author: Ahmad Tawila <[email protected]>
Date: Sun Oct 25 05:54:29 2015 +0200
replace the deprecated "Twig_Function_Method"
replace it with the recommended "Twig_SimpleFunction" as per Twig docs
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index c042e56..ab76375 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -21,11 +21,11 @@ class UploaderExtension extends \Twig_Extension
public function getFunctions()
{
return array(
- 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'),
- 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'),
- 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'),
- 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey'),
- 'oneup_uploader_maxsize' => new \Twig_Function_Method($this, 'maxSize'),
+ 'oneup_uploader_endpoint' => new \Twig_SimpleFunction('endpoint', array($this, 'endpoint')),
+ 'oneup_uploader_progress' => new \Twig_SimpleFunction('progress', array($this, 'progress')),
+ 'oneup_uploader_cancel' => new \Twig_SimpleFunction('cancel', array($this, 'cancel')),
+ 'oneup_uploader_upload_key' => new \Twig_SimpleFunction('uploadKey', array($this, 'uploadKey')),
+ 'oneup_uploader_maxsize' => new \Twig_SimpleFunction('maxSize', array($this, 'maxSize')),
);
}
| 0
|
be7cdc76ebf067f9fcc733050be4eeab9b0b6195
|
1up-lab
|
OneupUploaderBundle
|
Moved knp-gaufrette-bundle to the 'suggest' section of the composer.json
|
commit be7cdc76ebf067f9fcc733050be4eeab9b0b6195
Author: Jim Schmid <[email protected]>
Date: Fri Apr 5 19:38:55 2013 +0200
Moved knp-gaufrette-bundle to the 'suggest' section of the composer.json
diff --git a/composer.json b/composer.json
index 9b70844..ac64ad5 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,10 @@
"require": {
"symfony/finder": ">=2.0.16,<2.3-dev",
"symfony/filesystem": ">=2.0.16,<2.3-dev",
- "symfony/event-dispatcher": ">=2.0.16,<2.3-dev",
+ "symfony/event-dispatcher": ">=2.0.16,<2.3-dev"
+ },
+
+ "suggest": {
"knplabs/knp-gaufrette-bundle": "0.1.*"
},
| 0
|
ced5635c00f4bb9db4f76804b9e5d3345f54c948
|
1up-lab
|
OneupUploaderBundle
|
Added validator to validate allowed extensions.
|
commit ced5635c00f4bb9db4f76804b9e5d3345f54c948
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 19:22:43 2013 +0200
Added validator to validate allowed extensions.
diff --git a/EventListener/AllowedExtensionValidationListener.php b/EventListener/AllowedExtensionValidationListener.php
new file mode 100644
index 0000000..69ab16a
--- /dev/null
+++ b/EventListener/AllowedExtensionValidationListener.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Oneup\UploaderBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\ValidationEvent;
+use Oneup\UploaderBundle\Uploader\Exception\ValidationException;
+
+class AllowedExtensionValidationListener
+{
+ public function onValidate(ValidationEvent $event)
+ {
+ $config = $event->getConfig();
+ $file = $event->getFile();
+
+ $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
+
+ if(count($config['allowed_extensions']) > 0 && !in_array($extension, $config['allowed_extensions'])) {
+ throw new ValidationException('error.whitelist');
+ }
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/validation.xml b/Resources/config/validation.xml
index ac5322b..a272a48 100644
--- a/Resources/config/validation.xml
+++ b/Resources/config/validation.xml
@@ -6,7 +6,11 @@
<services>
- <service id="oneup_uploader.validation.max_size_listener" 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">
<tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" />
</service>
| 0
|
254d5cdb0d6f17475afe5a2c8739f7387496ace1
|
1up-lab
|
OneupUploaderBundle
|
Added a template helper and a twig function to get to the endpoint route of a mapping.
|
commit 254d5cdb0d6f17475afe5a2c8739f7387496ace1
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 18:11:56 2013 +0200
Added a template helper and a twig function to get to the endpoint route of a mapping.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index da81832..89051cd 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('directory')->defaultNull()->end()
->end()
->end()
+ ->scalarNode('twig')->defaultTrue()->end()
->arrayNode('mappings')
->useAttributeAsKey('id')
->isRequired()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index f643686..bf0121f 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -21,6 +21,12 @@ class OneupUploaderExtension extends Extension
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
+ $loader->load('templating.xml');
+
+ if($config['twig'])
+ {
+ $loader->load('twig.xml');
+ }
$config['chunks']['directory'] = is_null($config['chunks']['directory']) ?
sprintf('%s/uploader/chunks', $container->getParameter('kernel.cache_dir')) :
diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml
new file mode 100644
index 0000000..4593804
--- /dev/null
+++ b/Resources/config/templating.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">
+
+ <services>
+
+ <service id="oneup_uploader.templating.uploader_helper" class="Oneup\UploaderBundle\Templating\Helper\UploaderHelper">
+ <argument type="service" id="router" />
+ <tag name="templating.helper" alias="oneup_uploader" />
+ </service>
+
+ </services>
+
+</container>
\ No newline at end of file
diff --git a/Resources/config/twig.xml b/Resources/config/twig.xml
new file mode 100644
index 0000000..95c0c2d
--- /dev/null
+++ b/Resources/config/twig.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">
+
+ <services>
+
+ <service id="oneup_uploader.twig.extension.uploader" class="Oneup\UploaderBundle\Twig\Extension\UploaderExtension" public="true">
+ <argument type="service" id="oneup_uploader.templating.uploader_helper" />
+ <tag name="twig.extension" />
+ </service>
+
+ </services>
+
+</container>
\ No newline at end of file
diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php
new file mode 100644
index 0000000..b5c376a
--- /dev/null
+++ b/Templating/Helper/UploaderHelper.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Oneup\UploaderBundle\Templating\Helper;
+
+use Symfony\Component\Routing\RouterInterface;
+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
new file mode 100644
index 0000000..910a0f9
--- /dev/null
+++ b/Twig/Extension/UploaderExtension.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Oneup\UploaderBundle\Twig\Extension;
+
+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
|
2138609ee5cebdc2b151669b0eae2e104ecb6816
|
1up-lab
|
OneupUploaderBundle
|
Fix: README.md Symfony 2.8.2
Error without the fix :
UploadListener::__construct() must be an instance of
Doctrine\Common\Persistence\ObjectManager, none given
|
commit 2138609ee5cebdc2b151669b0eae2e104ecb6816
Author: p1rox <[email protected]>
Date: Sat Feb 13 11:54:34 2016 +0100
Fix: README.md Symfony 2.8.2
Error without the fix :
UploadListener::__construct() must be an instance of
Doctrine\Common\Persistence\ObjectManager, none given
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 6fea373..1aa1cfd 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -50,7 +50,7 @@ And register it in your `services.xml`.
services:
acme_hello.upload_listener:
class: AppBundle\EventListener\UploadListener
- argument: ["@doctrine.orm.entity_manager"]
+ arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload }
```
| 0
|
49bb6feea7542bb373f12de48020425f7a1bdd73
|
1up-lab
|
OneupUploaderBundle
|
Fix codestyle (#439)
|
commit 49bb6feea7542bb373f12de48020425f7a1bdd73
Author: David Greminger <[email protected]>
Date: Mon Feb 5 13:07:57 2024 +0100
Fix codestyle (#439)
diff --git a/src/Controller/AbstractChunkedController.php b/src/Controller/AbstractChunkedController.php
index c169915..3f78149 100644
--- a/src/Controller/AbstractChunkedController.php
+++ b/src/Controller/AbstractChunkedController.php
@@ -39,7 +39,7 @@ abstract class AbstractChunkedController extends AbstractController
* returned array to reassemble the uploaded chunks.
*
* @param UploadedFile $file - The uploaded chunk
- * @param responseInterface $response - A response object
+ * @param ResponseInterface $response - A response object
* @param Request $request - The request object
*/
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request): void
@@ -84,7 +84,7 @@ abstract class AbstractChunkedController extends AbstractController
* This function is a helper function which dispatches post chunk upload event.
*
* @param mixed $uploaded - The uploaded chunk
- * @param responseInterface $response - A response object
+ * @param ResponseInterface $response - A response object
* @param Request $request - The request object
* @param bool $isLast - True if this is the last chunk, false otherwise
*/
diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php
index 76ba042..7dbd5b6 100644
--- a/src/Controller/AbstractController.php
+++ b/src/Controller/AbstractController.php
@@ -164,7 +164,7 @@ abstract class AbstractController
}
}
- protected function validate(FileInterface $file, Request $request, ResponseInterface $response = null): void
+ protected function validate(FileInterface $file, Request $request, ?ResponseInterface $response = null): void
{
$event = new ValidationEvent($file, $request, $this->config, $this->type, $response);
@@ -204,7 +204,7 @@ abstract class AbstractController
/**
* Event dispatch proxy that avoids using deprecated interfaces.
*/
- protected function dispatchEvent(Event $event, string $eventName = null): void
+ protected function dispatchEvent(Event $event, ?string $eventName = null): void
{
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = $this->container->get('event_dispatcher');
diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php
index af23747..d2e4942 100644
--- a/src/DependencyInjection/OneupUploaderExtension.php
+++ b/src/DependencyInjection/OneupUploaderExtension.php
@@ -256,7 +256,7 @@ class OneupUploaderExtension extends Extension
return $storageService;
}
- protected function registerFilesystem(string $type, string $key, string $class, string $filesystem, string $buffer, string $streamWrapper = null, string $prefix = ''): void
+ protected function registerFilesystem(string $type, string $key, string $class, string $filesystem, string $buffer, ?string $streamWrapper = null, string $prefix = ''): void
{
switch ($type) {
case 'gaufrette':
diff --git a/src/Routing/RouteLoader.php b/src/Routing/RouteLoader.php
index 39279c0..cd7658b 100644
--- a/src/Routing/RouteLoader.php
+++ b/src/Routing/RouteLoader.php
@@ -15,12 +15,12 @@ class RouteLoader extends Loader
parent::__construct();
}
- public function supports(mixed $resource, string $type = null): bool
+ public function supports(mixed $resource, ?string $type = null): bool
{
return 'uploader' === $type;
}
- public function load(mixed $resource, string $type = null): RouteCollection
+ public function load(mixed $resource, ?string $type = null): RouteCollection
{
$routes = new RouteCollection();
$separator = '::';
diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php
index f28bd0c..5f75d47 100644
--- a/src/Uploader/Chunk/Storage/FlysystemStorage.php
+++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -37,7 +37,7 @@ class FlysystemStorage implements ChunkStorageInterface
/**
* @throws FilesystemException
*/
- public function clear(int $maxAge, string $prefix = null): void
+ public function clear(int $maxAge, ?string $prefix = null): void
{
$prefix = $prefix ?: $this->prefix;
$matches = $this->filesystem->listContents($prefix, true);
diff --git a/src/Uploader/Chunk/Storage/GaufretteStorage.php b/src/Uploader/Chunk/Storage/GaufretteStorage.php
index 345f028..12bee41 100644
--- a/src/Uploader/Chunk/Storage/GaufretteStorage.php
+++ b/src/Uploader/Chunk/Storage/GaufretteStorage.php
@@ -42,7 +42,7 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface
* $prefix must be passable so it can clean the orphanage too
* as it is forced to be the same filesystem.
*/
- public function clear(int $maxAge, string $prefix = null): void
+ public function clear(int $maxAge, ?string $prefix = null): void
{
$prefix = $prefix ?: $this->prefix;
$matches = $this->filesystem->listKeys($prefix);
diff --git a/src/Uploader/Response/FineUploaderResponse.php b/src/Uploader/Response/FineUploaderResponse.php
index b37b310..34eb0bc 100644
--- a/src/Uploader/Response/FineUploaderResponse.php
+++ b/src/Uploader/Response/FineUploaderResponse.php
@@ -42,7 +42,7 @@ class FineUploaderResponse extends AbstractResponse
return $this->success;
}
- public function setError(string $msg = null): self
+ public function setError(?string $msg = null): self
{
$this->error = $msg;
diff --git a/src/Uploader/Response/MooUploadResponse.php b/src/Uploader/Response/MooUploadResponse.php
index 3a5cad9..c273aa9 100644
--- a/src/Uploader/Response/MooUploadResponse.php
+++ b/src/Uploader/Response/MooUploadResponse.php
@@ -42,7 +42,7 @@ class MooUploadResponse extends AbstractResponse
return $this->id;
}
- public function setName(string $name = null): self
+ public function setName(?string $name = null): self
{
$this->name = $name;
diff --git a/src/Uploader/Storage/FilesystemOrphanageStorage.php b/src/Uploader/Storage/FilesystemOrphanageStorage.php
index 83cfaa1..8dfce6a 100644
--- a/src/Uploader/Storage/FilesystemOrphanageStorage.php
+++ b/src/Uploader/Storage/FilesystemOrphanageStorage.php
@@ -34,7 +34,7 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS
*
* @return FileInterface|File
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
if (!$this->session instanceof SessionInterface || !$this->session->isStarted()) {
throw new \RuntimeException('You need a running session in order to run the Orphanage.');
@@ -43,7 +43,7 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS
return parent::upload($file, $name, $this->getPath());
}
- public function uploadFiles(array $files = null): array
+ public function uploadFiles(?array $files = null): array
{
try {
if (null === $files) {
diff --git a/src/Uploader/Storage/FilesystemStorage.php b/src/Uploader/Storage/FilesystemStorage.php
index a67f7a2..d7cc420 100644
--- a/src/Uploader/Storage/FilesystemStorage.php
+++ b/src/Uploader/Storage/FilesystemStorage.php
@@ -19,7 +19,7 @@ class FilesystemStorage implements StorageInterface
*
* @return FileInterface|File
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
$path = null === $path ? $name : sprintf('%s/%s', $path, $name);
$path = sprintf('%s/%s', $this->directory, $path);
diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php
index 9f51f63..2d771c4 100644
--- a/src/Uploader/Storage/FlysystemOrphanageStorage.php
+++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -41,7 +41,7 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
*
* @return FileInterface|SymfonyFile
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
if (!$this->session instanceof SessionInterface || !$this->session->isStarted()) {
throw new \RuntimeException('You need a running session in order to run the Orphanage.');
@@ -53,7 +53,7 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
/**
* @throws FilesystemException
*/
- public function uploadFiles(array $files = null): array
+ public function uploadFiles(?array $files = null): array
{
try {
if (null === $files) {
diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php
index c689587..4187b4f 100644
--- a/src/Uploader/Storage/FlysystemStorage.php
+++ b/src/Uploader/Storage/FlysystemStorage.php
@@ -25,7 +25,7 @@ class FlysystemStorage implements StorageInterface
*
* @return FileInterface|SymfonyFile
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
$path = null === $path ? $name : sprintf('%s/%s', $path, $name);
diff --git a/src/Uploader/Storage/GaufretteOrphanageStorage.php b/src/Uploader/Storage/GaufretteOrphanageStorage.php
index bac1a92..2f4a2e7 100644
--- a/src/Uploader/Storage/GaufretteOrphanageStorage.php
+++ b/src/Uploader/Storage/GaufretteOrphanageStorage.php
@@ -37,7 +37,7 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto
*
* @return FileInterface|GaufretteFile
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
if (!$this->session instanceof SessionInterface || !$this->session->isStarted()) {
throw new \RuntimeException('You need a running session in order to run the Orphanage.');
@@ -46,7 +46,7 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto
return parent::upload($file, $name, $this->getPath());
}
- public function uploadFiles(array $files = null): array
+ public function uploadFiles(?array $files = null): array
{
try {
if (null === $files) {
diff --git a/src/Uploader/Storage/GaufretteStorage.php b/src/Uploader/Storage/GaufretteStorage.php
index ea2cd83..aea8128 100644
--- a/src/Uploader/Storage/GaufretteStorage.php
+++ b/src/Uploader/Storage/GaufretteStorage.php
@@ -33,7 +33,7 @@ class GaufretteStorage extends StreamManager implements StorageInterface
*
* @return FileInterface|GaufretteFile
*/
- public function upload($file, string $name, string $path = null)
+ public function upload($file, string $name, ?string $path = null)
{
$path = null === $path ? $name : sprintf('%s/%s', $path, $name);
diff --git a/src/Uploader/Storage/OrphanageStorageInterface.php b/src/Uploader/Storage/OrphanageStorageInterface.php
index 21c6c8d..b10b26a 100644
--- a/src/Uploader/Storage/OrphanageStorageInterface.php
+++ b/src/Uploader/Storage/OrphanageStorageInterface.php
@@ -6,5 +6,5 @@ namespace Oneup\UploaderBundle\Uploader\Storage;
interface OrphanageStorageInterface extends StorageInterface
{
- public function uploadFiles(array $files = null): array;
+ public function uploadFiles(?array $files = null): array;
}
diff --git a/src/Uploader/Storage/StorageInterface.php b/src/Uploader/Storage/StorageInterface.php
index 0259db7..2c75db1 100644
--- a/src/Uploader/Storage/StorageInterface.php
+++ b/src/Uploader/Storage/StorageInterface.php
@@ -16,5 +16,5 @@ interface StorageInterface
*
* @return FileInterface|File
*/
- public function upload($file, string $name, string $path = null);
+ public function upload($file, string $name, ?string $path = null);
}
diff --git a/tests/Uploader/File/GaufretteFileTest.php b/tests/Uploader/File/GaufretteFileTest.php
index 1febc13..a8fa2e0 100644
--- a/tests/Uploader/File/GaufretteFileTest.php
+++ b/tests/Uploader/File/GaufretteFileTest.php
@@ -16,7 +16,7 @@ class GaufretteFileTest extends FileTest
protected function setUp(): void
{
$adapter = new Adapter(sys_get_temp_dir(), true);
- $filesystem = new GaufretteFilesystem($adapter);
+ $filesystem = new GaufretteFileSystem($adapter);
$map = StreamWrapper::getFilesystemMap();
$map->set('oneup', $filesystem);
| 0
|
f95413e20d9b28ae8cd5856f3e458b882f2c1d61
|
1up-lab
|
OneupUploaderBundle
|
Documentation: Process uploaded files using custom logic.
|
commit f95413e20d9b28ae8cd5856f3e458b882f2c1d61
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 10:44:57 2013 +0200
Documentation: Process uploaded files using custom logic.
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
new file mode 100644
index 0000000..4d66237
--- /dev/null
+++ b/Resources/doc/custom_logic.md
@@ -0,0 +1,41 @@
+Process uploaded files using custom logic
+=========================================
+
+In almost every use case you need to further process uploaded files. For example if you want to add them to a Doctrine Entity or the like. To cover this, the OneupUploaderBundle provides some useful Events you can listen to.
+
+* `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.
+
+To listen to one of these events you need to create an `EventListener`.
+
+```php
+namespace Acme\HelloBundle\EventListener;
+
+use Oneup\UploaderBundle\Event\PostPersistEvent;
+
+class UploadListener
+{
+ public function __construct($doctrine)
+ {
+ $this->doctrine = $doctrine;
+ }
+
+ public function onUpload(PostPersistEvent $event)
+ {
+ //...
+ }
+}
+```
+
+And register it in your `services.xml`.
+
+```xml
+<services>
+ <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener">
+ <argument type="service" id="doctrine" />
+ <tag name="kernel.event_listener" event="oneup.uploader.post.persist" method="onUpload" />
+ </service>
+</services>
+```
+
+You can now implement you custom logic in the `onUpload` method of your EventListener.
\ No newline at end of file
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 1d44c18..5688e52 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -113,6 +113,7 @@ This is of course a very minimal setup. Be sure to include stylesheets for Fine
After installing and setting up the basic functionality of this bundle you can move on and integrate
some more advanced features.
+* [Process uploaded files using custom logic](custom_logic.md)
* [Return custom data to frontend](response.md)
* [Enable chunked uploads](chunked_uploads.md)
* [Using the Orphanage](orphanage.md)
| 0
|
a5824f08728386589bdde272653fb9dd45145a4a
|
1up-lab
|
OneupUploaderBundle
|
Fixed MooUploadController so that chunked uploads work for now.
|
commit a5824f08728386589bdde272653fb9dd45145a4a
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 14:15:47 2013 +0200
Fixed MooUploadController so that chunked uploads work for now.
diff --git a/Controller/MooUploadController.php b/Controller/MooUploadController.php
index fcd2435..949663d 100644
--- a/Controller/MooUploadController.php
+++ b/Controller/MooUploadController.php
@@ -50,7 +50,7 @@ class MooUploadController extends AbstractChunkedController
$response = $this->response;
$response->setId($headers->get('x-file-id'));
- $response->setSize($headers->get('x-file-size'));
+ $response->setSize($headers->get('content-length'));
$response->setName($headers->get('x-file-name'));
$response->setUploadedName($uploadFileName);
@@ -108,13 +108,13 @@ class MooUploadController extends AbstractChunkedController
protected function createIndex($id)
{
- $ints = '';
+ $ints = 0;
// loop through every char and convert it to an integer
// we need this for sorting
foreach(str_split($id) as $char)
{
- $ints .= ord($char);
+ $ints += ord($char);
}
return $ints;
| 0
|
07e294cb11a6287ece278887400af2f1547fa511
|
1up-lab
|
OneupUploaderBundle
|
Removed max version constraint for symfony/finder.
|
commit 07e294cb11a6287ece278887400af2f1547fa511
Author: Jim Schmid <[email protected]>
Date: Mon Oct 7 12:28:30 2013 +0200
Removed max version constraint for symfony/finder.
diff --git a/composer.json b/composer.json
index 37e7667..b4a4d15 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,7 @@
"require": {
"symfony/framework-bundle": "2.*",
- "symfony/finder": ">=2.2.0,<2.4-dev"
+ "symfony/finder": ">=2.2.0"
},
"require-dev": {
| 0
|
131ad19813cd2be8ee6a8e81391c984da90b74aa
|
1up-lab
|
OneupUploaderBundle
|
XML services translated to yml
|
commit 131ad19813cd2be8ee6a8e81391c984da90b74aa
Author: Martin Aarhof <[email protected]>
Date: Thu Dec 17 18:52:36 2015 +0100
XML services translated to yml
diff --git a/Resources/doc/custom_error_handler.md b/Resources/doc/custom_error_handler.md
index 4110836..69bedfa 100644
--- a/Resources/doc/custom_error_handler.md
+++ b/Resources/doc/custom_error_handler.md
@@ -33,6 +33,12 @@ Define a service for your class.
</services>
```
+```yml
+services:
+ acme_demo.custom_error_handler:
+ class: Acme\DemoBundle\ErrorHandler\CustomErrorHandler
+```
+
And configure the mapping to use your shiny new service.
```yml
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index 88c6d71..b91091e 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -40,6 +40,15 @@ And register it in your `services.xml`.
</services>
```
+```yml
+services:
+ acme_hello.upload_listener:
+ class: Acme\HelloBundle\EventListener\UploadListener
+ argument: ["@doctrine"]
+ tags:
+ - { name: kernel.event_listener, event: oneup_uploader.post_persist, method: onUpload }
+```
+
You can now implement you custom logic in the `onUpload` method of your EventListener.
## Use custom input data
diff --git a/Resources/doc/custom_namer.md b/Resources/doc/custom_namer.md
index 9b59e58..ffc7a03 100644
--- a/Resources/doc/custom_namer.md
+++ b/Resources/doc/custom_namer.md
@@ -34,13 +34,19 @@ Next, register your created namer as a service in your `services.xml`
</services>
```
+```yml
+acme_demo.custom_namer:
+ class: Acme\DemoBundle\CatNamer
+```
+
Now you can use your custom service by adding it to your configuration:
```yml
-oneup_uploader:
- mappings:
- gallery:
- namer: acme_demo.custom_namer
+services:
+ oneup_uploader:
+ mappings:
+ gallery:
+ namer: acme_demo.custom_namer
```
Every file uploaded through the `Controller` of this mapping will be named with your custom namer.
diff --git a/Resources/doc/custom_validator.md b/Resources/doc/custom_validator.md
index 1f0ef03..2d5b5f0 100644
--- a/Resources/doc/custom_validator.md
+++ b/Resources/doc/custom_validator.md
@@ -45,3 +45,11 @@ After that register your new `EventListener` in the `services.xml` of your appli
</services>
</container>
```
+
+```yml
+services:
+ acme_demo.always_false_listener:
+ class: Acme\DemoBundle\EventListener\AlwaysFalseValidationListener
+ tags:
+ - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate }
+```
| 0
|
a1b15da3b36f478e66463c498382793dfc8c9b82
|
1up-lab
|
OneupUploaderBundle
|
Fixed a typo.
|
commit a1b15da3b36f478e66463c498382793dfc8c9b82
Author: Jim Schmid <[email protected]>
Date: Thu Apr 11 21:48:50 2013 +0200
Fixed a typo.
diff --git a/Resources/doc/frontend_uploadify.md b/Resources/doc/frontend_uploadify.md
index 78a3dbe..e84c7d5 100644
--- a/Resources/doc/frontend_uploadify.md
+++ b/Resources/doc/frontend_uploadify.md
@@ -3,7 +3,7 @@ Use Uploadify
Download [Uploadify](http://www.uploadify.com/download/) and include it in your template. Connect the `uploader` property to the dynamic route `_uploader_{mapping_name}` and include the FlashUploader file.
-> If you are using UploadiFive, please drop me a note. I'd like to know if this bundle also works works for the HTML5-Version of this frontend library.
+> If you are using UploadiFive, please drop me a note. I'd like to know if this bundle also works for the HTML5-Version of this frontend library.
```html
| 0
|
3d711a21d4a983443797b83bd763557067e72b85
|
1up-lab
|
OneupUploaderBundle
|
Swap order of condition (#402)
|
commit 3d711a21d4a983443797b83bd763557067e72b85
Author: David Greminger <[email protected]>
Date: Thu Feb 11 12:45:51 2021 +0100
Swap order of condition (#402)
diff --git a/src/DependencyInjection/OneupUploaderExtension.php b/src/DependencyInjection/OneupUploaderExtension.php
index b688707..ab33a88 100644
--- a/src/DependencyInjection/OneupUploaderExtension.php
+++ b/src/DependencyInjection/OneupUploaderExtension.php
@@ -342,13 +342,6 @@ class OneupUploaderExtension extends Extension
{
$projectDir = '';
- 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');
@@ -356,6 +349,13 @@ class OneupUploaderExtension extends Extension
$projectDir = sprintf('%s/..', $kernelRootDir);
}
+ if ($this->container->hasParameter('kernel.project_dir')) {
+ /** @var string $kernelProjectDir */
+ $kernelProjectDir = $this->container->getParameter('kernel.project_dir');
+
+ $projectDir = $kernelProjectDir;
+ }
+
$publicDir = sprintf('%s/public', $projectDir);
if (!is_dir($publicDir)) {
| 0
|
4e173b4f3863b5aca6f5d021fbc538c6bc5b5e69
|
1up-lab
|
OneupUploaderBundle
|
Added a test to assure you can pass values through the event listeners via the request object.
|
commit 4e173b4f3863b5aca6f5d021fbc538c6bc5b5e69
Author: Jim Schmid <[email protected]>
Date: Fri Jun 21 23:29:29 2013 +0200
Added a test to assure you can pass values through the event listeners via the request object.
diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php
index 1024613..6dfc7e4 100644
--- a/Tests/Controller/AbstractUploadTest.php
+++ b/Tests/Controller/AbstractUploadTest.php
@@ -54,6 +54,10 @@ abstract class AbstractUploadTest extends AbstractControllerTest
$preValidation -= 2;
$file = $event->getFile();
+ $request = $event->getRequest();
+
+ // add a new key to the attribute list
+ $request->attributes->set('grumpy', 'cat');
$me->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $file);
});
@@ -63,9 +67,11 @@ abstract class AbstractUploadTest extends AbstractControllerTest
$preValidation *= -1;
$file = $event->getFile();
+ $request = $event->getRequest();
$me->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $file);
$me->assertEquals(128, $file->getSize());
+ $me->assertEquals('cat', $request->get('grumpy'));
});
$client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getRequestFile()));
| 0
|
50b8167a6845d5774b170733a7b6e774f2fdf96a
|
1up-lab
|
OneupUploaderBundle
|
Added .scrutinizer.yml file.
|
commit 50b8167a6845d5774b170733a7b6e774f2fdf96a
Author: Jim Schmid <[email protected]>
Date: Sun Apr 14 15:28:12 2013 +0200
Added .scrutinizer.yml file.
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
new file mode 100644
index 0000000..764db5d
--- /dev/null
+++ b/.scrutinizer.yml
@@ -0,0 +1,6 @@
+tools:
+ php_code_sniffer: true
+ php_cs_fixer: true
+ php_mess_detector: true
+ php_analyzer: true
+ sensiolabs_security_checker: true
\ No newline at end of file
| 0
|
ea2804ca78e8a139fcaf3f847997e9ff2a49b1a5
|
1up-lab
|
OneupUploaderBundle
|
Doc changes
|
commit ea2804ca78e8a139fcaf3f847997e9ff2a49b1a5
Author: David Greminger <[email protected]>
Date: Mon Jan 4 12:03:05 2016 +0100
Doc changes
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index 5850164..4178e9e 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -5,7 +5,9 @@ The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2
## Prerequisites
-This bundle is tested using Symfony 2.4+.
+This bundle is tested using Symfony 2.4+.
+
+**With Symfony 2.3**
If you want to use the bundle with Symfony 2.3, head over to the documentation for [1.3.x](https://github.com/1up-lab/OneupUploaderBundle/blob/release-1.3.x/Resources/doc/index.md).
### Translations
| 0
|
f795b14669b1cb3e7855b7326aee646f1aae7570
|
1up-lab
|
OneupUploaderBundle
|
moved the metadatasupporter check
|
commit f795b14669b1cb3e7855b7326aee646f1aae7570
Author: mitom <[email protected]>
Date: Thu Oct 10 12:32:55 2013 +0200
moved the metadatasupporter check
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 35d46b7..c69e3b2 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -21,6 +21,10 @@ class GaufretteStorage extends StreamManager implements StorageInterface
{
$path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
+ if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
+ $this->filesystem->getAdapter()->setMetadata($name, array('contentType' => $file->getMimeType()));
+ }
+
if ($file instanceof GaufretteFile) {
if ($file->getFilesystem() == $this->filesystem) {
$file->getFilesystem()->rename($file->getKey(), $path);
@@ -29,9 +33,6 @@ class GaufretteStorage extends StreamManager implements StorageInterface
}
}
- if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
- $this->filesystem->getAdapter()->setMetadata($name, array('contentType' => $file->getMimeType()));
- }
$this->ensureRemotePathExists($path.$name);
$dst = $this->filesystem->createStream($path);
| 0
|
e0b21208c623676bd54445a3bc1f2efcd896b7a2
|
1up-lab
|
OneupUploaderBundle
|
Fix doc (see #337)
|
commit e0b21208c623676bd54445a3bc1f2efcd896b7a2
Author: stoccc <[email protected]>
Date: Tue Jun 5 10:30:32 2018 +0200
Fix doc (see #337)
diff --git a/Resources/doc/progress.md b/Resources/doc/progress.md
index f3a6833..3086b72 100644
--- a/Resources/doc/progress.md
+++ b/Resources/doc/progress.md
@@ -31,7 +31,7 @@ $('#fileupload').bind('fileuploadsend', function (e, data) {
data.formData.push(progressObj);
data.context.data('interval', setInterval(function () {
- $.get('{{ oneup_uploader_progress("gallery") }}', $.param([progressObj]), function (result) {
+ $.post('{{ oneup_uploader_progress("gallery") }}', $.param([progressObj]), function (result) {
e = $.Event( 'progress', {bubbles: false, cancelable: true});
$.extend(e, result);
($('#fileupload').data('blueimp-fileupload') ||
| 0
|
75a380fa651ca456726fba944fd60ff5d20b7edb
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #18 from UseAllFive/GaufretteStorageWriteNotAppend
Fix RuntimeException: Could not read key content bug
|
commit 75a380fa651ca456726fba944fd60ff5d20b7edb
Merge: 09141db bf58310
Author: Jim Schmid <[email protected]>
Date: Tue Jun 11 23:54:30 2013 -0700
Merge pull request #18 from UseAllFive/GaufretteStorageWriteNotAppend
Fix RuntimeException: Could not read key content bug
| 0
|
50c5ddae3219937270b793fe647a0e29f4e2b128
|
1up-lab
|
OneupUploaderBundle
|
Added a license file.
|
commit 50c5ddae3219937270b793fe647a0e29f4e2b128
Author: Jim Schmid <[email protected]>
Date: Sat Mar 9 11:46:09 2013 +0100
Added a license file.
diff --git a/Resources/meta/LICENSE b/Resources/meta/LICENSE
new file mode 100644
index 0000000..44d421f
--- /dev/null
+++ b/Resources/meta/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2013 1up GmbH
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
\ No newline at end of file
| 0
|
9c9a403eba5b8e4fa73a76ab5c33fd63d4297d9b
|
1up-lab
|
OneupUploaderBundle
|
Translate the error message if upload fails.
|
commit 9c9a403eba5b8e4fa73a76ab5c33fd63d4297d9b
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 23:19:22 2013 +0200
Translate the error message if upload fails.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 21cf3d9..f7880cb 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -33,6 +33,7 @@ class UploaderController implements UploadControllerInterface
{
$request = $this->container->get('request');
$dispatcher = $this->container->get('event_dispatcher');
+ $translator = $this->container->get('translator');
$response = new UploaderResponse();
$totalParts = $request->get('qqtotalparts', 1);
@@ -58,6 +59,7 @@ class UploaderController implements UploadControllerInterface
catch(UploadException $e)
{
$response->setSuccess(false);
+ $response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'));
// an error happended, return this error message.
return new JsonResponse($response->assemble());
diff --git a/Tests/Controller/UploaderControllerTest.php b/Tests/Controller/UploaderControllerTest.php
index 967ca51..e9bd236 100644
--- a/Tests/Controller/UploaderControllerTest.php
+++ b/Tests/Controller/UploaderControllerTest.php
@@ -98,6 +98,9 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
if($inp == 'namer')
return new UniqidNamer();
+
+ if($inp == 'translator')
+ return $this->getTranslatorMock();
}
protected function getEventDispatcherMock()
@@ -129,6 +132,18 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase
return $mock;
}
+ protected function getTranslatorMock()
+ {
+ $mock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
+ $mock
+ ->expects($this->any())
+ ->method('trans')
+ ->will($this->returnValue('A translated error.'))
+ ;
+
+ return $mock;
+ }
+
protected function getUploadedFile()
{
return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
| 0
|
35aa95b0e3a0f0bcc044de7374a110f61ddb0d9d
|
1up-lab
|
OneupUploaderBundle
|
Documented custom_uploaders
|
commit 35aa95b0e3a0f0bcc044de7374a110f61ddb0d9d
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 17:13:18 2013 +0200
Documented custom_uploaders
diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md
index 43dbd6f..786e7a6 100644
--- a/Resources/doc/custom_uploader.md
+++ b/Resources/doc/custom_uploader.md
@@ -3,4 +3,126 @@ Support a custom Uploader
If you have written your own Uploader or you want to use an implementation that is currently not supported by the OneupUploaderBundle follow these steps to integrate it to your Symfony2 application.
-##
\ No newline at end of file
+## Configuration
+
+Configure your custom uploader according to the following example.
+
+```yml
+oneup_uploader:
+ mappings:
+ gallery:
+ frontend: custom
+ custom_frontend:
+ class: Acme\DemoBundle\Controller\CustomController
+ name: MyFancyCustomUploader
+```
+
+This will automatically create everything you need later.
+The next step is to include the logic of your custom Uploader to your provided Controller. For having a consistent interface consider extending one of the following classes:
+
+* `Oneup\UploaderBundle\Controller\AbstractController`: For any implementation that don't support chunked uploads.
+* `Oneup\UploaderBundle\Controller\AbstractChunkedController`: For any implementation that should support chunked uploads.
+
+## The Controller part
+
+If you decided to extend the AbstractController, do the following
+
+```php
+namespace Acme\DemoBundle\Controller;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Oneup\UploaderBundle\Controller\UploaderController;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class CustomUploader extends UploaderController
+{
+ public function upload()
+ {
+ // get some basic stuff together
+ $request = $this->container->get('request');
+ $response = new EmptyResponse();
+
+ // get file from request (your own logic)
+ $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 assembled response
+ return new JsonResponse($response->assemble());
+ }
+}
+```
+
+## Implement chunked upload
+If you want to additionaly support chunked upload, you have to overwrite the `AbstractChunkedController` and implement the `parseChunkedRequest` method. This method should return an array containing the following values:
+
+* `$last`: Is this the last chunk of a file (`true`/`false`)
+* `$uuid`: A truly unique id which will become the directory name for the `ChunkManager` to use.
+* `$index`: Which part (chunk) is it? Its not important that you provide exact numbers, but they must be higher for a subsequent chunk!
+* `$orig`: The original filename.
+
+Take any chunked upload implementation in `Oneup\UploaderBundle\Controller` as an example.
+
+After that, you manually have to check if you have to do a chunked upload or not. This differs from implementation to implementation, so heres an example of the jQuery File Uploader:
+
+```php
+$chunked = !is_null($request->headers->get('content-range'));
+$uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file);
+```
+
+## Using a custom Response class
+If your frontend implementation relies on specific data returned, it is highly recommended to create your own `Response` class. Here is an example for FineUploader, I guess you'll get the point:
+
+```php
+namespace Oneup\UploaderBundle\Uploader\Response;
+
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class FineUploaderResponse extends AbstractResponse
+{
+ protected $success;
+ protected $error;
+
+ public function __construct()
+ {
+ $this->success = true;
+ $this->error = null;
+
+ parent::__construct();
+ }
+
+ 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;
+ }
+
+ // ... snip, setters/getters
+}
+
+## Notes
+
+It is highly recommended to use the internal and inherited methods `handleUpload` and `handleChunkedUpload` as these will mind your configuration file. Nonetheless; it is possible to overwrite the behaviour completely in your Controller class.
\ No newline at end of file
| 0
|
d519bab7f4029f22a812409bbd84936170d85261
|
1up-lab
|
OneupUploaderBundle
|
Removed old controller tests.
|
commit d519bab7f4029f22a812409bbd84936170d85261
Author: Jim Schmid <[email protected]>
Date: Sat May 4 13:59:53 2013 +0200
Removed old controller tests.
diff --git a/Tests/Controller/AbstractControllerChunkedTest.php b/Tests/Controller/AbstractControllerChunkedTest.php
deleted file mode 100644
index 771282f..0000000
--- a/Tests/Controller/AbstractControllerChunkedTest.php
+++ /dev/null
@@ -1,147 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-
-use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager;
-use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
-use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-
-abstract class AbstractControllerChunkedTest extends \PHPUnit_Framework_TestCase
-{
- protected $tempChunks;
- protected $currentChunk;
- protected $chunkUuid;
- protected $numberOfChunks;
-
- abstract public function getControllerString();
- abstract protected function getRequestMock();
-
- public function setUp()
- {
- $this->numberOfChunks = 10;
-
- // create 10 chunks
- for($i = 0; $i < $this->numberOfChunks; $i++)
- {
- // create temporary file
- $chunk = tempnam(sys_get_temp_dir(), 'uploader');
-
- $pointer = fopen($chunk, 'w+');
- fwrite($pointer, str_repeat('A', 1024), 1024);
- fclose($pointer);
-
- $this->tempChunks[] = $chunk;
- }
-
- $this->currentChunk = 0;
- $this->chunkUuid = uniqid();
- }
-
- public function testUpload()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 2048,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
-
- $responses = array();
- $str = $this->getControllerString();
- $controller = new $str($container, $storage, $config, 'cat');
-
- // mock as much requests as there are parts to assemble
- for($i = 0; $i < $this->numberOfChunks; $i ++)
- {
- $responses[] = $controller->upload();
-
- // will be used internaly
- $this->currentChunk++;
- }
-
- for($i = 0; $i < $this->numberOfChunks; $i ++)
- {
- // check if original file has been moved
- $this->assertFalse(file_exists($this->tempChunks[$i]));
-
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $responses[$i]);
- $this->assertEquals(200, $responses[$i]->getStatusCode());
- }
-
- // check if assembled file is here
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/uploader')->files();
- $this->assertCount(1, $finder);
-
- // and check if chunks are gone
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/chunks')->files();
- $this->assertCount(0, $finder);
- }
-
- protected function getContainerMock()
- {
- $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'containerGetCb')))
- ;
-
- return $mock;
- }
-
- public function containerGetCb($inp)
- {
- if($inp == 'request')
- return $this->getRequestMock();
-
- if($inp == 'event_dispatcher')
- return $this->getEventDispatcherMock();
-
- if($inp == 'namer')
- return new UniqidNamer();
-
- if($inp == 'oneup_uploader.chunk_manager')
- return $this->getChunkManager();
- }
-
- protected function getEventDispatcherMock()
- {
- $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $mock
- ->expects($this->any())
- ->method('dispatch')
- ->will($this->returnValue(true))
- ;
-
- return $mock;
- }
-
- protected function getUploadedFile()
- {
- return new UploadedFile($this->tempChunks[$this->currentChunk], 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
- }
-
- protected function getChunkManager()
- {
- return new ChunkManager(array(
- 'directory' => sys_get_temp_dir() . '/chunks'
- ));
- }
-
- public function tearDown()
- {
- // remove all files in tmp folder
- $filesystem = new Filesystem();
- $filesystem->remove(sys_get_temp_dir() . '/uploader');
- $filesystem->remove(sys_get_temp_dir() . '/chunks');
- }
-}
\ No newline at end of file
diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php
deleted file mode 100644
index 80176e9..0000000
--- a/Tests/Controller/AbstractControllerTest.php
+++ /dev/null
@@ -1,144 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Symfony\Component\Finder\Finder;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\HttpFoundation\File\UploadedFile;
-
-use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer;
-use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage;
-
-abstract class AbstractControllerTest extends \PHPUnit_Framework_TestCase
-{
- protected $tempFile;
-
- abstract public function getControllerString();
- abstract protected function getRequestMock();
-
- public function setUp()
- {
- // create temporary file
- $this->tempFile = tempnam(sys_get_temp_dir(), 'uploader');
-
- $pointer = fopen($this->tempFile, 'w+');
- fwrite($pointer, str_repeat('A', 1024), 1024);
- fclose($pointer);
- }
-
- public function testUpload()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 2048,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
-
- $str = $this->getControllerString();
- $controller = new $str($container, $storage, $config, 'cat');
- $response = $controller->upload();
-
- // check if original file has been moved
- $this->assertFalse(file_exists($this->tempFile));
-
- // testing response
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
- $this->assertEquals(200, $response->getStatusCode());
-
- // check if file is present
- $finder = new Finder();
- $finder->in(sys_get_temp_dir() . '/uploader')->files();
-
- $this->assertCount(1, $finder);
- }
-
- public function testUploadWhichFails()
- {
- $container = $this->getContainerMock();
- $storage = new FilesystemStorage(sys_get_temp_dir() . '/uploader');
- $config = array(
- 'use_orphanage' => false,
- 'namer' => 'namer',
- 'max_size' => 1,
- 'allowed_extensions' => array(),
- 'disallowed_extensions' => array()
- );
-
- $str = $this->getControllerString();
- $controller = new $str($container, $storage, $config, 'cat');
- $response = $controller->upload();
-
- $json = json_decode($response->getContent());
-
- // testing response
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\JsonResponse', $response);
- $this->assertEquals(200, $response->getStatusCode());
- }
-
- protected function getContainerMock()
- {
- $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'containerGetCb')))
- ;
-
- return $mock;
- }
-
- public function containerGetCb($inp)
- {
- if($inp == 'request')
- return $this->getRequestMock();
-
- if($inp == 'event_dispatcher')
- return $this->getEventDispatcherMock();
-
- if($inp == 'namer')
- return new UniqidNamer();
-
- if($inp == 'translator')
- return $this->getTranslatorMock();
- }
-
- protected function getEventDispatcherMock()
- {
- $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
- $mock
- ->expects($this->any())
- ->method('dispatch')
- ->will($this->returnValue(true))
- ;
-
- return $mock;
- }
-
- protected function getTranslatorMock()
- {
- $mock = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
- $mock
- ->expects($this->any())
- ->method('trans')
- ->will($this->returnValue('A translated error.'))
- ;
-
- return $mock;
- }
-
- protected function getUploadedFile()
- {
- return new UploadedFile($this->tempFile, 'grumpy-cat.jpeg', 'image/jpeg', 1024, null, true);
- }
-
- public function tearDown()
- {
- // remove all files in tmp folder
- $filesystem = new Filesystem();
- $filesystem->remove(sys_get_temp_dir() . '/uploader');
- }
-}
\ No newline at end of file
diff --git a/Tests/Controller/BlueimpControllerChunkedTest.php b/Tests/Controller/BlueimpControllerChunkedTest.php
deleted file mode 100644
index 9b95ca5..0000000
--- a/Tests/Controller/BlueimpControllerChunkedTest.php
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
-
-class BlueimpControllerChunkedTest extends AbstractControllerChunkedTest
-{
- public function getControllerString()
- {
- return 'Oneup\UploaderBundle\Controller\BlueimpController';
- }
-
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
-
- $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
- $headers
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'headersGetCb')))
- ;
-
- $mock->headers = $headers;
-
- $mock->files = array(
- array($this->getUploadedFile())
- );
-
- return $mock;
- }
-
- public function containerGetCb($inp)
- {
- if($inp == 'session')
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Session\Session');
- $mock
- ->expects($this->any())
- ->method('getId')
- ->will($this->returnValue('fixed-id'))
- ;
-
- return $mock;
- }
-
- return parent::containerGetCb($inp);
- }
-
- public function headersGetCb($inp)
- {
- if($inp == 'content-disposition')
- return 'grumpy-cat.jpeg';
-
- if($inp == 'content-range')
- {
- if($this->currentChunk == ($this->numberOfChunks - 1))
- {
- return sprintf('- 9218, 10240/10241');
- }
- else
- {
- $size = 1024;
- $ret = sprintf('- %d, %d/%d', $this->currentChunk * $size, $this->currentChunk * $size + $size, 10240);
-
- return $ret;
- }
- }
- }
-}
diff --git a/Tests/Controller/BlueimpControllerTest.php b/Tests/Controller/BlueimpControllerTest.php
deleted file mode 100644
index 19ffefa..0000000
--- a/Tests/Controller/BlueimpControllerTest.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
-
-class BlueimpControllerTest extends AbstractControllerTest
-{
- public function getControllerString()
- {
- return 'Oneup\UploaderBundle\Controller\BlueimpController';
- }
-
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
- $headers
- ->expects($this->any())
- ->method('get')
- ->will($this->returnValue(null))
- ;
-
- $mock->headers = $headers;
-
- $mock->files = array(
- array($this->getUploadedFile())
- );
-
- return $mock;
- }
-}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerChunkedTest.php b/Tests/Controller/FineUploaderControllerChunkedTest.php
deleted file mode 100644
index 9d9adb1..0000000
--- a/Tests/Controller/FineUploaderControllerChunkedTest.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Oneup\UploaderBundle\Tests\Controller\AbstractControllerChunkedTest;
-
-class FineUploaderControllerChunkedTest extends AbstractControllerChunkedTest
-{
- public function getControllerString()
- {
- return 'Oneup\UploaderBundle\Controller\FineUploaderController';
- }
-
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $mock
- ->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(array($this, 'requestGetCb')))
- ;
-
- $mock->files = array(
- $this->getUploadedFile()
- );
-
- return $mock;
- }
-
- public function requestGetCb($inp)
- {
- if($inp == 'qqtotalparts')
- return $this->numberOfChunks;
-
- if($inp == 'qqpartindex')
- return $this->currentChunk;
-
- if($inp == 'qquuid')
- return $this->chunkUuid;
-
- if($inp == 'qqfilename')
- return 'grumpy-cat.jpeg';
- }
-}
\ No newline at end of file
diff --git a/Tests/Controller/FineUploaderControllerTest.php b/Tests/Controller/FineUploaderControllerTest.php
deleted file mode 100644
index 5fafc14..0000000
--- a/Tests/Controller/FineUploaderControllerTest.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\Tests\Controller;
-
-use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
-
-class FineUploaderControllerTest extends AbstractControllerTest
-{
- public function getControllerString()
- {
- return 'Oneup\UploaderBundle\Controller\FineUploaderController';
- }
-
- protected function getRequestMock()
- {
- $mock = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $mock
- ->expects($this->any())
- ->method('get')
- ->with('qqtotalparts')
- ->will($this->returnValue(1))
- ;
-
- $mock->files = array(
- $this->getUploadedFile()
- );
-
- return $mock;
- }
-}
\ No newline at end of file
| 0
|
63beecbc814d3047feb9448a7e383703930d01ac
|
1up-lab
|
OneupUploaderBundle
|
Reduced amount of copied code in ValidationTest.
|
commit 63beecbc814d3047feb9448a7e383703930d01ac
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 14:51:54 2013 +0200
Reduced amount of copied code in ValidationTest.
diff --git a/Tests/Controller/ControllerValidationTest.php b/Tests/Controller/ControllerValidationTest.php
index e33c096..fd4c2d0 100644
--- a/Tests/Controller/ControllerValidationTest.php
+++ b/Tests/Controller/ControllerValidationTest.php
@@ -17,15 +17,7 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array();
$config['disallowed_extensions'] = array();
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new UploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
+ $this->performConfigTest($config);
}
public function testMaxSizeValidationPasses()
@@ -36,18 +28,7 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array();
$config['disallowed_extensions'] = array();
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new UploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
-
- // yey, no exception thrown
- $this->assertTrue(true);
+ $this->performConfigTest($config);
}
/**
@@ -61,18 +42,7 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array('txt', 'pdf');
$config['disallowed_extensions'] = array();
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new UploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
-
- // yey, no exception thrown
- $this->assertTrue(true);
+ $this->performConfigTest($config);
}
public function testAllowedExtensionValidationPasses()
@@ -83,18 +53,7 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array('png', 'jpg', 'jpeg', 'gif');
$config['disallowed_extensions'] = array();
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new UploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
-
- // yey, no exception thrown
- $this->assertTrue(true);
+ $this->performConfigTest($config);
}
/**
@@ -108,18 +67,7 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array();
$config['disallowed_extensions'] = array('jpeg');
- // prepare mock
- $file = $this->getUploadedFileMock();
- $method = $this->getValidationMethod();
-
- $container = $this->getContainerMock();
- $storage = $this->getStorageMock();
-
- $controller = new UploaderController($container, $storage, $config, 'cat');
- $method->invoke($controller, $file);
-
- // yey, no exception thrown
- $this->assertTrue(true);
+ $this->performConfigTest($config);
}
public function testDisallowedExtensionValidationPasses()
@@ -130,6 +78,11 @@ class ControllerValidationTest extends \PHPUnit_Framework_TestCase
$config['allowed_extensions'] = array();
$config['disallowed_extensions'] = array('exe', 'bat');
+ $this->performConfigTest($config);
+ }
+
+ protected function performConfigTest($config)
+ {
// prepare mock
$file = $this->getUploadedFileMock();
$method = $this->getValidationMethod();
| 0
|
7c0f4bb6c13c6f73bfe62b55d3c564f8e526a517
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #227 from p1rox/master
Fixed typo in documentation
|
commit 7c0f4bb6c13c6f73bfe62b55d3c564f8e526a517
Merge: 9fa868f 2138609
Author: David Greminger <[email protected]>
Date: Sun Feb 14 15:11:32 2016 +0100
Merge pull request #227 from p1rox/master
Fixed typo in documentation
| 0
|
fdebca99c4c4b55ce2cfa71f89942b2e5c343cbf
|
1up-lab
|
OneupUploaderBundle
|
Update testing.md
Added a note about how to enable the new AWS test which came along with pr #18.
|
commit fdebca99c4c4b55ce2cfa71f89942b2e5c343cbf
Author: Jim Schmid <[email protected]>
Date: Wed Jun 12 09:42:41 2013 +0200
Update testing.md
Added a note about how to enable the new AWS test which came along with pr #18.
diff --git a/Resources/doc/testing.md b/Resources/doc/testing.md
index 7da4cb2..91a37a6 100644
--- a/Resources/doc/testing.md
+++ b/Resources/doc/testing.md
@@ -14,6 +14,17 @@ You can run the unit tests by simply performing the follwowing command.
$> phpunit
+If you are using the Gaufrette storage to upload files to an Amazon S3 instance be sure to add your AWS credentials by exporting them as environment variables.
+It will enable an otherwise skipped test.
+
+```bash
+export AWS_ACCESS_KEY_ID="your-id-here"
+export AWS_SECRET_ACCESS_KEY="your-key-here"
+export AWS_BUCKET="your-bucket-name-here"
+```
+
+Details can be found in the corresponding [pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/18).
+
## Testing Code Coverage
PHPUnit comes bundles with a handy feature to test the code coverage of a project. I recommend using the following configuration to enable the creation of code coverage reports in the `log` directory in the root of this bundle. This directory is gitignored by default.
@@ -57,4 +68,4 @@ The directories `Command`, `DependencyInjection` and `Event` are excluded from t
Run the test suite and generate reports by running:
- $> phpunit
\ No newline at end of file
+ $> phpunit
| 0
|
44fbde3a6aaec6a7364362386b5b63907ce6688d
|
1up-lab
|
OneupUploaderBundle
|
Fixed error when running tests in PHP5.3
|
commit 44fbde3a6aaec6a7364362386b5b63907ce6688d
Author: Jim Schmid <[email protected]>
Date: Sat Sep 14 16:51:44 2013 +0200
Fixed error when running tests in PHP5.3
diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php
index 5461c6b..01b0a6d 100644
--- a/Tests/Controller/AbstractValidationTest.php
+++ b/Tests/Controller/AbstractValidationTest.php
@@ -73,9 +73,10 @@ abstract class AbstractValidationTest extends AbstractControllerTest
// event data
$validationCount = 0;
+ $me = $this;
- $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) {
- $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $event->getRequest());
+ $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount, &$me) {
+ $me->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $event->getRequest());
// to be sure this listener is called
++ $validationCount;
| 0
|
15f3614144d72b166d82a3e1586c2e66a357c0d1
|
1up-lab
|
OneupUploaderBundle
|
Test against php71
|
commit 15f3614144d72b166d82a3e1586c2e66a357c0d1
Author: David Greminger <[email protected]>
Date: Thu Dec 15 12:25:03 2016 +0100
Test against php71
diff --git a/.travis.yml b/.travis.yml
index 7884714..0e69924 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ php:
- 5.5
- 5.6
- 7.0
+ - 7.1
- hhvm
env:
| 0
|
b9aef6ac357e09061a6051a3cca7ffee07f8a473
|
1up-lab
|
OneupUploaderBundle
|
Updated description in composer.json
|
commit b9aef6ac357e09061a6051a3cca7ffee07f8a473
Author: David Greminger <[email protected]>
Date: Fri Mar 27 17:05:15 2020 +0100
Updated description in composer.json
diff --git a/composer.json b/composer.json
index f53221a..278b963 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
{
"name": "oneup/uploader-bundle",
"type": "symfony-bundle",
- "description": "Handles multi file uploads in Symfony2. Features included: Chunked upload, Orphans management, Gaufrette support.",
+ "description": "This Symfony bundle provides a server implementation for handling single and multiple file uploads using either FineUploader, jQuery File Uploader, YUI3 Uploader, Uploadify, FancyUpload, MooUpload, Plupload or Dropzone. Features include chunked uploads, orphanages, Gaufrette and Flysystem support.",
"keywords": ["fileupload", "upload", "FineUploader", "blueimp", "jQuery File Uploader", "YUI3 Uploader", "Uploadify", "FancyUpload", "MooUpload", "Plupload", "Dropzone"],
"homepage": "https://1up.io",
"license": "MIT",
| 0
|
5da645b523edb24f79a0b9360b43bfa196c3276d
|
1up-lab
|
OneupUploaderBundle
|
First version of Plupload implementation.
|
commit 5da645b523edb24f79a0b9360b43bfa196c3276d
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 15:40:28 2013 +0200
First version of Plupload implementation.
diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php
new file mode 100644
index 0000000..ede7a8d
--- /dev/null
+++ b/Controller/PluploadController.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+use Symfony\Component\HttpFoundation\File\Exception\UploadException;
+use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
+
+use Oneup\UploaderBundle\Controller\AbstractChunkedController;
+use Oneup\UploaderBundle\Uploader\Response\EmptyResponse;
+
+class PluploadController extends AbstractChunkedController
+{
+ public function upload()
+ {
+ $request = $this->container->get('request');
+ $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());
+ }
+
+ protected function parseChunkedRequest(Request $request)
+ {
+ die("foobar");
+ }
+}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index b00f847..e33d623 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', 'yui3', 'fancyupload', 'mooupload'))
+ ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload'))
->defaultValue('fineuploader')
->end()
->arrayNode('storage')
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 8b1cc48..49de680 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -17,6 +17,7 @@
<parameter key="oneup_uploader.controller.yui3.class">Oneup\UploaderBundle\Controller\YUI3Controller</parameter>
<parameter key="oneup_uploader.controller.fancyupload.class">Oneup\UploaderBundle\Controller\FancyUploadController</parameter>
<parameter key="oneup_uploader.controller.mooupload.class">Oneup\UploaderBundle\Controller\MooUploadController</parameter>
+ <parameter key="oneup_uploader.controller.plupload.class">Oneup\UploaderBundle\Controller\PluploadController</parameter>
</parameters>
<services>
| 0
|
b1fd72a35532b4317bc2537cfc6ac4931ab5422d
|
1up-lab
|
OneupUploaderBundle
|
Support for flysystem v2 (#412)
|
commit b1fd72a35532b4317bc2537cfc6ac4931ab5422d
Author: Martin Mandl <[email protected]>
Date: Wed Jul 20 14:20:27 2022 +0200
Support for flysystem v2 (#412)
diff --git a/README.md b/README.md
index eaa78ab..daa56ae 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `docs/index.md`
Upgrade Notes
-------------
+* Version **4.0.0* supports now [Flysystem 2 & 3](https://github.com/1up-lab/OneupFlysystemBundle) (kudos to @[m2mtech](https://github.com/m2mtech)), see [#412](https://github.com/1up-lab/OneupUploaderBundle/pull/412)! Flysystem 1 and OneupFlysystemBundle < 4.0 support was dropped.
* Version **3.2.0** supports now Symfony 6 (kudos to @[pich](https://github.com/pich)), see [#421](https://github.com/1up-lab/OneupUploaderBundle/pull/421)! PHP 7.2/7.3 support was dropped.
* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter](https://github.com/steveWinter), @[gubler](https://github.com/gubler), @[patrickbussmann](https://github.com/patrickbussmann), @[ErnadoO](https://github.com/ErnadoO) and @[enumag](https://github.com/enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
diff --git a/composer.json b/composer.json
index 000d258..f170b07 100644
--- a/composer.json
+++ b/composer.json
@@ -50,10 +50,11 @@
"doctrine/doctrine-bundle": "^2.4",
"friendsofphp/php-cs-fixer": "^2.16",
"knplabs/gaufrette": "^0.9",
- "oneup/flysystem-bundle": "^1.2 || ^2.0 || ^3.0",
+ "oneup/flysystem-bundle": "^4.1",
"phpstan/phpstan": "^0.12.10",
"phpunit/phpunit": "^9.5",
"sensio/framework-extra-bundle": "^5.0 || ^6.0",
+ "m2mtech/flysystem-stream-wrapper": "^1.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4",
"symfony/security-bundle": "^4.4 || ^5.4 || ^6.0",
@@ -63,7 +64,7 @@
"suggest": {
"knplabs/knp-gaufrette-bundle": "0.1.*",
"oneup/flysystem-bundle": "^3.0",
- "twistor/flysystem-stream-wrapper": "^1.0 (Required when using Flysystem)"
+ "m2mtech/flysystem-stream-wrapper": "^1.0 (Required when using Flysystem)"
},
"config": {
"sort-packages": true
diff --git a/src/Uploader/Chunk/Storage/FlysystemStorage.php b/src/Uploader/Chunk/Storage/FlysystemStorage.php
index 50d2d8b..9b3a642 100644
--- a/src/Uploader/Chunk/Storage/FlysystemStorage.php
+++ b/src/Uploader/Chunk/Storage/FlysystemStorage.php
@@ -4,9 +4,10 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\Chunk\Storage;
-use League\Flysystem\FileNotFoundException;
use League\Flysystem\Filesystem;
-use League\Flysystem\FilesystemInterface;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\FilesystemOperator;
+use League\Flysystem\StorageAttributes;
use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@@ -33,7 +34,7 @@ class FlysystemStorage implements ChunkStorageInterface
protected $streamWrapperPrefix;
/**
- * @var Filesystem
+ * @var FilesystemOperator
*/
private $filesystem;
@@ -58,6 +59,9 @@ class FlysystemStorage implements ChunkStorageInterface
];
}
+ /**
+ * @throws FilesystemException
+ */
public function clear(int $maxAge, string $prefix = null): void
{
$prefix = $prefix ?: $this->prefix;
@@ -70,9 +74,10 @@ class FlysystemStorage implements ChunkStorageInterface
// this also means the files inside are old
// but after the files are deleted the dirs
// would remain
+ /** @var StorageAttributes $key */
foreach ($matches as $key) {
- $path = $key['path'];
- $timestamp = $key['timestamp'] ?? $this->filesystem->getTimestamp($path);
+ $path = $key->path();
+ $timestamp = $key->lastModified();
if ($maxAge <= $now - $timestamp) {
$toDelete[] = $path;
@@ -92,6 +97,8 @@ class FlysystemStorage implements ChunkStorageInterface
/**
* @param array $chunks
+ *
+ * @throws FilesystemException
*/
public function assembleChunks($chunks, bool $removeChunk, bool $renameChunk): FlysystemFile
{
@@ -132,42 +139,48 @@ class FlysystemStorage implements ChunkStorageInterface
* the previous file is unaccessible by the user, but if it is not removed
* it will block the user from trying to re-upload it.
*/
- if ($this->filesystem->has($path . $name)) {
+ if ($this->filesystem->fileExists($path . $name)) {
$this->filesystem->delete($path . $name);
}
- $this->filesystem->rename($path . $target, $path . $name);
+ $this->filesystem->move($path . $target, $path . $name);
$target = $name;
}
- /** @var FlysystemFile $uploaded */
- $uploaded = $this->filesystem->get($path . $target);
-
- if (!$renameChunk) {
- return $uploaded;
- }
-
- return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
+ return new FlysystemFile($path . $target, $this->filesystem);
}
public function cleanup(string $path): void
{
try {
$this->filesystem->delete($path);
- } catch (FileNotFoundException $e) {
+ } catch (FilesystemException $e) {
// File already gone.
}
}
+ /**
+ * @throws FilesystemException
+ */
public function getChunks(string $uuid): array
{
// Prevent path traversal attacks
$uuid = basename($uuid);
- return $this->filesystem->listFiles($this->prefix . '/' . $uuid);
+ return $this->filesystem->listContents($this->prefix . '/' . $uuid)
+ ->filter(function (StorageAttributes $attributes) { return $attributes->isFile(); })
+ ->sortByPath()
+ ->map(function (StorageAttributes $attributes) {
+ return [
+ 'path' => $attributes->path(),
+ 'type' => $attributes->type(),
+ 'timestamp' => $attributes->lastModified(),
+ 'size' => $this->filesystem->fileSize($attributes->path()),
+ ];
+ })->toArray();
}
- public function getFilesystem(): FilesystemInterface
+ public function getFilesystem(): FilesystemOperator
{
return $this->filesystem;
}
diff --git a/src/Uploader/File/FlysystemFile.php b/src/Uploader/File/FlysystemFile.php
index 1324347..ab179a9 100644
--- a/src/Uploader/File/FlysystemFile.php
+++ b/src/Uploader/File/FlysystemFile.php
@@ -4,44 +4,60 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\File;
-use League\Flysystem\File;
-use League\Flysystem\FilesystemInterface;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\FilesystemOperator;
-class FlysystemFile extends File implements FileInterface
+class FlysystemFile implements FileInterface
{
- /**
- * @var string|null
- */
- protected $streamWrapperPrefix;
+ /** @var string */
+ private $pathname;
+
+ /** @var FilesystemOperator */
+ private $filesystem;
+
+ public function __construct(string $pathname, FilesystemOperator $filesystem)
+ {
+ $this->pathname = $pathname;
+ $this->filesystem = $filesystem;
+ }
/**
- * @var string
+ * @throws FilesystemException
*/
- protected $mimeType;
+ public function getSize(): int
+ {
+ return $this->filesystem->fileSize($this->pathname);
+ }
- public function __construct(File $file, FilesystemInterface $filesystem, string $streamWrapperPrefix = null)
+ public function getPathname(): string
{
- parent::__construct($filesystem, $file->getPath());
+ return $this->pathname;
+ }
- $this->streamWrapperPrefix = $streamWrapperPrefix;
+ public function getPath(): string
+ {
+ return pathinfo($this->pathname, \PATHINFO_DIRNAME);
}
- public function getPathname(): string
+ /**
+ * @throws FilesystemException
+ */
+ public function getMimeType(): string
{
- return $this->getPath();
+ return $this->filesystem->mimeType($this->pathname);
}
public function getBasename(): string
{
- return pathinfo($this->getPath(), \PATHINFO_BASENAME);
+ return basename($this->pathname);
}
public function getExtension(): string
{
- return pathinfo($this->getPath(), \PATHINFO_EXTENSION);
+ return pathinfo($this->pathname, \PATHINFO_EXTENSION);
}
- public function getFilesystem(): FilesystemInterface
+ public function getFilesystem(): FilesystemOperator
{
return $this->filesystem;
}
diff --git a/src/Uploader/Storage/FlysystemOrphanageStorage.php b/src/Uploader/Storage/FlysystemOrphanageStorage.php
index aedc716..49307c8 100644
--- a/src/Uploader/Storage/FlysystemOrphanageStorage.php
+++ b/src/Uploader/Storage/FlysystemOrphanageStorage.php
@@ -4,7 +4,8 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\Storage;
-use League\Flysystem\File;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\StorageAttributes;
use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
@@ -61,6 +62,8 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
/**
* @param FileInterface|SymfonyFile $file
*
+ * @throws FilesystemException
+ *
* @return FileInterface|SymfonyFile
*/
public function upload($file, string $name, string $path = null)
@@ -72,6 +75,9 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
return parent::upload($file, $name, $this->getPath());
}
+ /**
+ * @throws FilesystemException
+ */
public function uploadFiles(array $files = null): array
{
try {
@@ -95,6 +101,9 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
}
}
+ /**
+ * @throws FilesystemException
+ */
public function getFiles(): array
{
$fileList = $this->chunkStorage
@@ -102,13 +111,11 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto
->listContents($this->getPath());
$files = [];
+ /** @var StorageAttributes $fileDetail */
foreach ($fileList as $fileDetail) {
- $key = $fileDetail['path'];
- if ('file' === $fileDetail['type']) {
- $files[$key] = new FlysystemFile(
- new File($this->chunkStorage->getFilesystem(), $key),
- $this->chunkStorage->getFilesystem()
- );
+ $key = $fileDetail->path();
+ if ($fileDetail->isFile()) {
+ $files[$key] = new FlysystemFile($key, $this->chunkStorage->getFilesystem());
}
}
diff --git a/src/Uploader/Storage/FlysystemStorage.php b/src/Uploader/Storage/FlysystemStorage.php
index 8b0040e..854757d 100644
--- a/src/Uploader/Storage/FlysystemStorage.php
+++ b/src/Uploader/Storage/FlysystemStorage.php
@@ -4,13 +4,12 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Uploader\Storage;
-use League\Flysystem\File;
-use League\Flysystem\FilesystemInterface;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\FilesystemOperator;
use League\Flysystem\MountManager;
use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
-use Symfony\Component\Filesystem\Filesystem as LocalFilesystem;
use Symfony\Component\HttpFoundation\File\File as SymfonyFile;
class FlysystemStorage implements StorageInterface
@@ -26,11 +25,11 @@ class FlysystemStorage implements StorageInterface
protected $bufferSize;
/**
- * @var FilesystemInterface
+ * @var FilesystemOperator
*/
private $filesystem;
- public function __construct(FilesystemInterface $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null)
+ public function __construct(FilesystemOperator $filesystem, int $bufferSize, ?string $streamWrapperPrefix = null)
{
$this->filesystem = $filesystem;
$this->bufferSize = $bufferSize;
@@ -40,6 +39,8 @@ class FlysystemStorage implements StorageInterface
/**
* @param FileInterface|SymfonyFile $file
*
+ * @throws FilesystemException
+ *
* @return FileInterface|SymfonyFile
*/
public function upload($file, string $name, string $path = null)
@@ -50,7 +51,7 @@ class FlysystemStorage implements StorageInterface
/** @var resource $stream */
$stream = fopen($file->getPathname(), 'r+');
- $this->filesystem->putStream($path, $stream, [
+ $this->filesystem->writeStream($path, $stream, [
'mimetype' => $file->getMimeType(),
]);
@@ -58,22 +59,17 @@ class FlysystemStorage implements StorageInterface
fclose($stream);
}
- $filesystem = new LocalFilesystem();
- $filesystem->remove($file->getPathname());
+ $resultFile = new FlysystemFile($path, $this->filesystem);
- /** @var File $file */
- $file = $this->filesystem->get($path);
+ unlink($file->getPathname());
- return new FlysystemFile($file, $this->filesystem, $this->streamWrapperPrefix);
+ return $resultFile;
}
if ($file instanceof FlysystemFile && $file->getFilesystem() === $this->filesystem) {
- $file->getFilesystem()->rename($file->getPath(), $path);
-
- /** @var File $file */
- $file = $this->filesystem->get($path);
+ $file->getFilesystem()->move($file->getPathname(), $path);
- return new FlysystemFile($file, $this->filesystem, $this->streamWrapperPrefix);
+ return new FlysystemFile($path, $this->filesystem);
}
if ($file instanceof FileInterface) {
@@ -82,12 +78,9 @@ class FlysystemStorage implements StorageInterface
'dest' => $this->filesystem,
]);
- $manager->move(sprintf('chunks://%s', $file->getPathname()), sprintf('dest://%s', $path));
+ $manager->move('chunks://' . $file->getPathname(), 'dest://' . $path);
}
- /** @var File $file */
- $file = $this->filesystem->get($path);
-
- return new FlysystemFile($file, $this->filesystem, $this->streamWrapperPrefix);
+ return new FlysystemFile($path, $this->filesystem);
}
}
diff --git a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
index c96f558..a3ba11c 100644
--- a/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
+++ b/tests/Uploader/Chunk/Storage/FlysystemStorageTest.php
@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage;
-use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Filesystem as LeagueFilesystem;
-use League\Flysystem\Plugin\ListFiles;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\Local\LocalFilesystemAdapter as Adapter;
+use M2MTech\FlysystemStreamWrapper\FlysystemStreamWrapper;
use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage;
use Symfony\Component\Filesystem\Filesystem;
-use Twistor\FlysystemStreamWrapper;
class FlysystemStorageTest extends ChunkStorageTest
{
@@ -41,7 +41,6 @@ class FlysystemStorageTest extends ChunkStorageTest
$adapter = new Adapter($this->parentDir);
$filesystem = new LeagueFilesystem($adapter);
- $filesystem->addPlugin(new ListFiles());
FlysystemStreamWrapper::register('tests', $filesystem);
@@ -58,4 +57,30 @@ class FlysystemStorageTest extends ChunkStorageTest
FlysystemStreamWrapper::unregister('tests');
}
+
+ /**
+ * @throws FilesystemException
+ */
+ public function testGetChunks(): void
+ {
+ $uuid = uniqid('', true);
+ $dir = $this->tmpDir . '/' . $uuid;
+ $system = new Filesystem();
+ $system->mkdir($dir);
+ $timeFrom = time();
+ $system->mkdir($dir . '/shouldNotBeListed');
+ $system->dumpFile($dir . '/chunk1', 'test');
+ $system->dumpFile($dir . '/chunk2', 'test');
+ $system->dumpFile($dir . '/chunk3', 'test');
+ $timeTo = time();
+
+ $files = $this->storage->getChunks($uuid);
+ $this->assertCount(3, $files);
+ $file = $files[0];
+ $this->assertSame($this->chunkKey . '/' . $uuid . '/chunk1', $file['path']);
+ $this->assertSame('file', $file['type']);
+ $this->assertGreaterThanOrEqual($timeFrom, $file['timestamp']);
+ $this->assertLessThanOrEqual($timeTo, $file['timestamp']);
+ $this->assertSame(4, $file['size']);
+ }
}
diff --git a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
index f8ed31d..764d943 100644
--- a/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
+++ b/tests/Uploader/Storage/FlysystemOrphanageStorageTest.php
@@ -4,9 +4,10 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
-use League\Flysystem\Adapter\Local as Adapter;
-use League\Flysystem\File;
use League\Flysystem\Filesystem as FSAdapter;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\Local\LocalFilesystemAdapter as Adapter;
+use M2MTech\FlysystemStreamWrapper\FlysystemStreamWrapper;
use Oneup\UploaderBundle\Uploader\Chunk\Storage\FlysystemStorage as ChunkStorage;
use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage;
@@ -17,7 +18,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
-use Twistor\FlysystemStreamWrapper;
class FlysystemOrphanageStorageTest extends OrphanageTest
{
@@ -85,7 +85,7 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
// It seems that tempnam on OS X prepends 'private' to chunkDirectory, so strip that off as well
$fileKey = str_replace([$this->realDirectory, '/private'], '', $file);
- $this->payloads[] = new FlysystemFile(new File($filesystem, $fileKey), $filesystem);
+ $this->payloads[] = new FlysystemFile($fileKey, $filesystem);
}
}
@@ -96,6 +96,9 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
FlysystemStreamWrapper::unregister('tests');
}
+ /**
+ * @throws FilesystemException
+ */
public function testUpload(): void
{
for ($i = 0; $i < $this->numberOfPayloads; ++$i) {
@@ -112,6 +115,9 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
$this->assertCount(0, $finder);
}
+ /**
+ * @throws FilesystemException
+ */
public function testUploadAndFetching(): void
{
for ($i = 0; $i < $this->numberOfPayloads; ++$i) {
@@ -139,4 +145,25 @@ class FlysystemOrphanageStorageTest extends OrphanageTest
$finder->in($this->realDirectory)->files();
$this->assertCount($this->numberOfPayloads, $finder);
}
+
+ /**
+ * @throws FilesystemException
+ */
+ public function testGetFiles(): void
+ {
+ for ($i = 0; $i < $this->numberOfPayloads; ++$i) {
+ $this->orphanage->upload($this->payloads[$i], $i . 'notsogrumpyanymore.jpeg');
+ }
+
+ if (!$this->orphanage instanceof FlysystemOrphanageStorage) {
+ $this->fail();
+ }
+ $files = $this->orphanage->getFiles();
+ $this->assertCount(5, $files);
+
+ $key = key($files);
+ $file = $files[$key];
+ $this->assertSame($key, $file->getPathname());
+ $this->assertSame(1024, $file->getSize());
+ }
}
diff --git a/tests/Uploader/Storage/FlysystemStorageTest.php b/tests/Uploader/Storage/FlysystemStorageTest.php
index 42e6b1f..4205ea4 100644
--- a/tests/Uploader/Storage/FlysystemStorageTest.php
+++ b/tests/Uploader/Storage/FlysystemStorageTest.php
@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Oneup\UploaderBundle\Tests\Uploader\Storage;
-use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Filesystem as FSAdapter;
+use League\Flysystem\FilesystemException;
+use League\Flysystem\Local\LocalFilesystemAdapter as Adapter;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
+use Oneup\UploaderBundle\Uploader\File\FlysystemFile;
use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
@@ -30,6 +32,9 @@ class FlysystemStorageTest extends TestCase
*/
protected $file;
+ /** @var FSAdapter */
+ protected $filesystem;
+
protected function setUp(): void
{
$this->directory = sys_get_temp_dir() . '/storage';
@@ -44,9 +49,9 @@ class FlysystemStorageTest extends TestCase
fclose($pointer);
$adapter = new Adapter($this->directory);
- $filesystem = new FSAdapter($adapter);
+ $this->filesystem = new FSAdapter($adapter);
- $this->storage = new Storage($filesystem, 100000);
+ $this->storage = new Storage($this->filesystem, 100000);
}
protected function tearDown(): void
@@ -55,12 +60,18 @@ class FlysystemStorageTest extends TestCase
$filesystem->remove($this->directory);
}
+ /**
+ * @throws FilesystemException
+ */
public function testUpload(): void
{
$uploadedFile = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, true);
$payload = new FilesystemFile($uploadedFile);
- $this->storage->upload($payload, 'notsogrumpyanymore.jpeg');
+ $file = $this->storage->upload($payload, 'notsogrumpyanymore.jpeg');
+ $this->assertInstanceOf(FlysystemFile::class, $file);
+ $this->assertSame('notsogrumpyanymore.jpeg', $file->getPathname());
+ $this->assertSame(1024, $file->getSize());
$finder = new Finder();
$finder->in($this->directory)->files();
@@ -73,12 +84,18 @@ class FlysystemStorageTest extends TestCase
}
}
+ /**
+ * @throws FilesystemException
+ */
public function testUploadWithPath(): void
{
$uploadedFile = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, true);
$payload = new FilesystemFile($uploadedFile);
- $this->storage->upload($payload, 'notsogrumpyanymore.jpeg', 'cat');
+ $file = $this->storage->upload($payload, 'notsogrumpyanymore.jpeg', 'cat');
+ $this->assertInstanceOf(FlysystemFile::class, $file);
+ $this->assertSame('cat/notsogrumpyanymore.jpeg', $file->getPathname());
+ $this->assertSame(1024, $file->getSize());
$finder = new Finder();
$finder->in($this->directory)->files();
@@ -86,8 +103,42 @@ class FlysystemStorageTest extends TestCase
$this->assertCount(1, $finder);
foreach ($finder as $file) {
+ $this->assertStringEndsWith('cat', $file->getPath());
$this->assertSame($file->getFilename(), 'notsogrumpyanymore.jpeg');
$this->assertSame($file->getSize(), 1024);
}
}
+
+ public function testUploadFlysystemFile(): void
+ {
+ $tempFileName = basename($this->file);
+ $localPath = $this->directory . '/' . $tempFileName;
+ $flysystemFile = new FlysystemFile($tempFileName, $this->filesystem);
+ copy($this->file, $localPath);
+ $this->assertFileExists($localPath);
+
+ $file = $this->storage->upload($flysystemFile, 'final.jpg');
+ $this->assertInstanceOf(FlysystemFile::class, $file);
+ $this->assertSame('final.jpg', $file->getPathname());
+ $this->assertSame(1024, $file->getSize());
+
+ $this->assertFileDoesNotExist($localPath);
+ $this->assertFileExists($this->directory . '/final.jpg');
+ }
+
+ public function testUploadFlysystemFileFromDifferentFilesystem(): void
+ {
+ $adapter = new Adapter(sys_get_temp_dir());
+ $filesystem = new FSAdapter($adapter);
+
+ $flysystemFile = new FlysystemFile(basename($this->file), $filesystem);
+
+ $file = $this->storage->upload($flysystemFile, 'final.jpg');
+ $this->assertInstanceOf(FlysystemFile::class, $file);
+ $this->assertSame('final.jpg', $file->getPathname());
+ $this->assertSame(1024, $file->getSize());
+
+ $this->assertFileDoesNotExist($this->file);
+ $this->assertFileExists($this->directory . '/final.jpg');
+ }
}
| 0
|
e2b21d4245bf70ccd5aa7cf4f38ab7884f490c79
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'Lctrs-fix/flysystem-chunk-storage'
|
commit e2b21d4245bf70ccd5aa7cf4f38ab7884f490c79
Merge: d5a149b 42e611f
Author: David Greminger <[email protected]>
Date: Tue Oct 10 10:09:38 2017 +0200
Merge branch 'Lctrs-fix/flysystem-chunk-storage'
| 0
|
913046018e89163c3c04756baa48b3eed12454b1
|
1up-lab
|
OneupUploaderBundle
|
Updated cs fixer
|
commit 913046018e89163c3c04756baa48b3eed12454b1
Author: David Greminger <[email protected]>
Date: Fri Oct 23 11:47:27 2020 +0200
Updated cs fixer
diff --git a/.php_cs.dist b/.php_cs.dist
index 3f15c9a..428e683 100644
--- a/.php_cs.dist
+++ b/.php_cs.dist
@@ -7,11 +7,13 @@ $finder = PhpCsFixer\Finder::create()
return PhpCsFixer\Config::create()
->setRules([
+ '@DoctrineAnnotation' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
+ '@PHPUnit75Migration:risky' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => [
diff --git a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
index 53f2071..3a5e734 100644
--- a/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
+++ b/tests/Uploader/Storage/GaufretteOrphanageStorageTest.php
@@ -113,7 +113,7 @@ class GaufretteOrphanageStorageTest extends OrphanageTest
$files = $this->orphanage->uploadFiles();
- $this->assertInternalType('array', $files);
+ $this->assertIsArray($files);
$this->assertCount($this->numberOfPayloads, $files);
$finder = new Finder();
| 0
|
147388f69ed1b5d5fa8b91e2c039fb7e8deb0093
|
1up-lab
|
OneupUploaderBundle
|
Revert "made docs a bit nicer with a check"
This reverts commit 5e789d8b759d1977643a5ac99b3291fd30d866f5.
|
commit 147388f69ed1b5d5fa8b91e2c039fb7e8deb0093
Author: mitom <[email protected]>
Date: Mon Oct 14 21:09:25 2013 +0200
Revert "made docs a bit nicer with a check"
This reverts commit 5e789d8b759d1977643a5ac99b3291fd30d866f5.
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index a3f55dc..c017bdc 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -63,12 +63,6 @@ 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 2f53fb7..fd6d87a 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: If you use a gaufrette filesystem as chunk storage, you may only use gaufrette filesystems in your mappings too!
+> :exclamation: Do not use a Gaufrette filesystem for the chunk storage and a local filesystem for the mapping. This is not possible to check during container setup and will throw unexpected errors at runtime!
You can achieve the biggest improvement if you use the same filesystem as your storage. If you do so, the assembled
file only has to be moved out of the chunk directory, which takes no time on a local filesystem.
| 0
|
91e11e6f62978a420e8ccceb2bae0f2e6993416b
|
1up-lab
|
OneupUploaderBundle
|
Create PluploadErrorHandler.php
|
commit 91e11e6f62978a420e8ccceb2bae0f2e6993416b
Author: MJBGO <[email protected]>
Date: Sun Nov 16 00:01:36 2014 +0100
Create PluploadErrorHandler.php
diff --git a/Uploader/ErrorHandler/PluploadErrorHandler.php b/Uploader/ErrorHandler/PluploadErrorHandler.php
new file mode 100644
index 0000000..6716c87
--- /dev/null
+++ b/Uploader/ErrorHandler/PluploadErrorHandler.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
+
+use Exception;
+use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
+use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+
+class PluploadErrorHandler implements ErrorHandlerInterface
+{
+ public function addException(AbstractResponse $response, Exception $exception)
+ {
+ /* Plupload only needs an error message so it can be handled client side */
+ $message = $exception->getMessage();
+ $response['error'] = $message;
+ }
+}
+
+?>
| 0
|
568dfb13740c22de13205a702eb4b510cab0159f
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #194 from a-tawila/master
replace the deprecated "Twig_Function_Method"
|
commit 568dfb13740c22de13205a702eb4b510cab0159f
Merge: db6423b 0f30d96
Author: David Greminger <[email protected]>
Date: Wed Oct 28 09:11:12 2015 +0100
Merge pull request #194 from a-tawila/master
replace the deprecated "Twig_Function_Method"
| 0
|
172b38ae024c6ecfebb0ffa7b7537eea027a849f
|
1up-lab
|
OneupUploaderBundle
|
Renamed class file.
|
commit 172b38ae024c6ecfebb0ffa7b7537eea027a849f
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 21:54:50 2013 +0200
Renamed class file.
diff --git a/Uploader/Response/BlueimpResponse.php b/Uploader/Response/BlueimpResponse.php
index 8842b6b..a7e6c26 100644
--- a/Uploader/Response/BlueimpResponse.php
+++ b/Uploader/Response/BlueimpResponse.php
@@ -4,8 +4,12 @@ namespace Oneup\UploaderBundle\Uploader\Response;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
-class FineUploaderResponse extends AbstractResponse
+class BlueimpResponse extends AbstractResponse
{
+ /**
+ * This is an array containing elements of the following type
+ * array(url, thumbnail_url, type, size, delete_url, delete_type)
+ */
protected $files;
public function __construct()
| 0
|
f61d2d1a0ea6ce33d9582d80f7489bb81f4cf38c
|
1up-lab
|
OneupUploaderBundle
|
Fixed path madness introduced due to reimplementation of Orphanage.
|
commit f61d2d1a0ea6ce33d9582d80f7489bb81f4cf38c
Author: Jim Schmid <[email protected]>
Date: Thu Mar 28 16:11:36 2013 +0100
Fixed path madness introduced due to reimplementation of Orphanage.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 465b264..a0072cc 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -115,7 +115,7 @@ class UploaderController implements UploadControllerInterface
// validate this entity and upload on success
$this->validate($uploadedFile);
- $uploaded = $this->handleUpload();
+ $uploaded = $this->handleUpload($uploadedFile);
$this->chunkManager->cleanup($path);
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9987fb7..a19fb50 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -28,6 +28,7 @@ class Configuration implements ConfigurationInterface
->booleanNode('enabled')->defaultFalse()->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('maxage')->defaultValue(604800)->end()
+ ->scalarNode('directory')->defaultValue('orphanage')->end()
->end()
->end()
->arrayNode('mappings')
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 1ca00ec..b1768df 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -27,15 +27,7 @@ class OneupUploaderExtension extends Extension
}
$container->setParameter('oneup_uploader.chunks', $config['chunks']);
-
- // handling orphanage configuration
- if(!array_key_exists('directory', $config['orphanage']))
- {
- $config['orphanage']['directory'] = sprintf('%s/uploader/orphanage', $container->getParameter('kernel.cache_dir'));
- }
-
$container->setParameter('oneup_uploader.orphanage', $config['orphanage']);
- //$config['orphanage']['storage'] = $this->registerStorageService($container, $config['orphanage']);
// handle mappings
foreach($config['mappings'] as $key => $mapping)
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index 66b074f..7f3978e 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -18,19 +18,19 @@ class GaufretteStorage implements StorageInterface
$this->filesystem = $filesystem;
}
- public function upload(File $file, $name = null)
+ public function upload(File $file, $name = null, $path = null)
{
- $path = $file->getPathname();
$name = is_null($name) ? $file->getRelativePathname() : $name;
+ $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name);
- $src = new LocalStream($path);
- $dst = $this->filesystem->createStream($name);
+ $src = new LocalStream($file->getPathname());
+ $dst = $this->filesystem->createStream($path);
// this is a somehow ugly workaround introduced
// because the stream-mode is not able to create
// subdirectories.
- if(!$this->filesystem->has($name))
- $this->filesystem->write($name, '', true);
+ if(!$this->filesystem->has($path))
+ $this->filesystem->write($path, '', true);
$src->open(new StreamMode('rb+'));
$dst->open(new StreamMode('ab+'));
@@ -44,6 +44,6 @@ class GaufretteStorage implements StorageInterface
$dst->close();
$src->close();
- return $this->filesystem->get($name);
+ return $this->filesystem->get($path);
}
}
\ No newline at end of file
diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php
index 27f83ec..096af12 100644
--- a/Uploader/Storage/OrphanageStorage.php
+++ b/Uploader/Storage/OrphanageStorage.php
@@ -28,12 +28,15 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter
$this->type = $type;
}
- public function upload(File $file, $name = null)
+ public function upload(File $file, $name = null, $path = null)
{
if(!$this->session->isStarted())
throw new \RuntimeException('You need a running session in order to run the Orphanage.');
- return parent::upload($file, $name);
+ // generate a path based on session id
+ $path = $this->getPath();
+
+ return parent::upload($file, $name, $path);
}
public function uploadFiles($keep = false)
@@ -47,7 +50,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter
if(!$system->exists($this->getPath()))
return array();
- $finder->in($this->getPathRelativeToSession())->files();
+ $finder->in($this->getPath())->files();
$uploaded = array();
foreach($finder as $file)
@@ -64,14 +67,6 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter
}
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/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 74a63df..3684604 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);
+ public function upload(File $file, $name = null, $path = null);
}
\ No newline at end of file
| 0
|
76bfb5d660c7c2c2162afa877c1c8993319bb7b5
|
1up-lab
|
OneupUploaderBundle
|
Integrated the correct link to the index.md of documentation in readme.
|
commit 76bfb5d660c7c2c2162afa877c1c8993319bb7b5
Author: Jim Schmid <[email protected]>
Date: Sun Apr 7 13:05:49 2013 +0200
Integrated the correct link to the index.md of documentation in readme.
diff --git a/README.md b/README.md
index d674be8..79d7905 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ Documentation
The entry point of the documentation can be found in the file `Resources/docs/index.md`
-[Read the documentation for master](...)
+[Read the documentation for master](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md)
License
-------
diff --git a/Resources/docs/index.md b/Resources/doc/index.md
similarity index 100%
rename from Resources/docs/index.md
rename to Resources/doc/index.md
| 0
|
a90b2001d447f348a9e35862e72727ea75e07a5d
|
1up-lab
|
OneupUploaderBundle
|
Added KnpGaufretteBundle to the list of dependencies.
|
commit a90b2001d447f348a9e35862e72727ea75e07a5d
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 15:26:47 2013 +0100
Added KnpGaufretteBundle to the list of dependencies.
diff --git a/composer.json b/composer.json
index 51ece7f..d82d5c8 100644
--- a/composer.json
+++ b/composer.json
@@ -28,9 +28,10 @@
},
"require": {
- "symfony/finder": ">=2.0.16,<2.3-dev",
- "symfony/filesystem": ">=2.0.16,<2.3-dev",
- "valums/file-uploader": "3.3.*"
+ "symfony/finder": ">=2.0.16,<2.3-dev",
+ "symfony/filesystem": ">=2.0.16,<2.3-dev",
+ "knplabs/knp-gaufrette-bundle": "0.1.*",
+ "valums/file-uploader": "3.3.*"
},
"autoload": {
| 0
|
d7a2376b3367c4ca3841d1c70acdac267da43ca6
|
1up-lab
|
OneupUploaderBundle
|
Refactored Route loading as addMethodCall won't be called if Bundle is loaded through composer.
|
commit d7a2376b3367c4ca3841d1c70acdac267da43ca6
Author: Jim Schmid <[email protected]>
Date: Mon Apr 8 10:26:03 2013 +0200
Refactored Route loading as addMethodCall won't be called if Bundle is loaded through composer.
diff --git a/DependencyInjection/Compiler/ControllerCompilerPass.php b/DependencyInjection/Compiler/ControllerCompilerPass.php
deleted file mode 100644
index a56ea90..0000000
--- a/DependencyInjection/Compiler/ControllerCompilerPass.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-
-namespace Oneup\UploaderBundle\DependencyInjection\Compiler;
-
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Reference;
-
-class ControllerCompilerPass implements CompilerPassInterface
-{
- public function process(ContainerBuilder $container)
- {
- $tags = $container->findTaggedServiceIds('oneup_uploader.routable');
-
- if(count($tags) > 0 && $container->hasDefinition('oneup_uploader.routing.loader'))
- {
- $loader = $container->getDefinition('oneup_uploader.routing.loader');
-
- foreach($tags as $id => $tag)
- {
- $loader->addMethodCall('addController', array($tag[0]['type'], $id));
- }
- }
- }
-}
\ No newline at end of file
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index c828879..04eb240 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -35,6 +35,8 @@ class OneupUploaderExtension extends Extension
$container->setParameter('oneup_uploader.chunks', $config['chunks']);
$container->setParameter('oneup_uploader.orphanage', $config['orphanage']);
+ $controllers = array();
+
// handle mappings
foreach($config['mappings'] as $key => $mapping)
{
@@ -102,9 +104,11 @@ class OneupUploaderExtension extends Extension
}
}
+ $controllerName = sprintf('oneup_uploader.controller.%s', $key);
+
// create controllers based on mapping
$container
- ->register(sprintf('oneup_uploader.controller.%s', $key), $container->getParameter('oneup_uploader.controller.class'))
+ ->register($controllerName, $container->getParameter('oneup_uploader.controller.class'))
->addArgument(new Reference('service_container'))
->addArgument($storageService)
@@ -114,7 +118,11 @@ class OneupUploaderExtension extends Extension
->addTag('oneup_uploader.routable', array('type' => $key))
->setScope('request')
;
+
+ $controllers[$key] = $controllerName;
}
+
+ $container->setParameter('oneup_uploader.controllers', $controllers);
}
protected function getMaxUploadSize($input)
diff --git a/OneupUploaderBundle.php b/OneupUploaderBundle.php
index f359549..693f273 100644
--- a/OneupUploaderBundle.php
+++ b/OneupUploaderBundle.php
@@ -9,10 +9,4 @@ use Oneup\UploaderBundle\DependencyInjection\Compiler\ControllerCompilerPass;
class OneupUploaderBundle extends Bundle
{
- public function build(ContainerBuilder $container)
- {
- parent::build($container);
-
- $container->addCompilerPass(new ControllerCompilerPass);
- }
}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 0f9d511..13baac6 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -31,6 +31,7 @@
<!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
+ <argument>%oneup_uploader.controllers%</argument>
<tag name="routing.loader" />
</service>
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index c7dfb91..9145ff1 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -10,14 +10,9 @@ class RouteLoader extends Loader
{
protected $controllers;
- public function __construct()
+ public function __construct(array $controllers)
{
- $this->controllers = array();
- }
-
- public function addController($type, $controller)
- {
- $this->controllers[$type] = $controller;
+ $this->controllers = $controllers;
}
public function supports($resource, $type = null)
| 0
|
ff25449a5b050eeaecd43c231f34d4d94d940694
|
1up-lab
|
OneupUploaderBundle
|
Fixed tests
|
commit ff25449a5b050eeaecd43c231f34d4d94d940694
Author: Jim Schmid <[email protected]>
Date: Tue Apr 9 21:46:04 2013 +0200
Fixed tests
diff --git a/Tests/Uploader/Response/UploaderResponseTest.php b/Tests/Uploader/Response/FineUploaderResponseTest.php
similarity index 84%
rename from Tests/Uploader/Response/UploaderResponseTest.php
rename to Tests/Uploader/Response/FineUploaderResponseTest.php
index 37728a0..05f3d0a 100644
--- a/Tests/Uploader/Response/UploaderResponseTest.php
+++ b/Tests/Uploader/Response/FineUploaderResponseTest.php
@@ -2,13 +2,13 @@
namespace Oneup\UploaderBundle\Tests\Uploader\Response;
-use Oneup\UploaderBundle\Uploader\Response\UploaderResponse;
+use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse;
-class TestUploaderResponse extends \PHPUnit_Framework_TestCase
+class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase
{
public function testCreationOfResponse()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$this->assertTrue($response->getSuccess());
$this->assertNull($response->getError());
@@ -16,7 +16,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testFillOfResponse()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$cat = 'is grumpy';
$dog = 'has no idea';
@@ -46,7 +46,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testError()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$response->setError('This response is grumpy');
$this->assertEquals($response->getError(), 'This response is grumpy');
@@ -54,7 +54,7 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase
public function testOverwriteOfInternals()
{
- $response = new UploaderResponse();
+ $response = new FineUploaderResponse();
$response['success'] = false;
$response['error'] = 42;
| 0
|
efaa424cd58b6b2b391b93316e7e69fb264e309e
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #3 from sheeep/release-1.0
Documentation / Test / Little Improvement
|
commit efaa424cd58b6b2b391b93316e7e69fb264e309e
Merge: 01e3347 988082e
Author: mitom <[email protected]>
Date: Mon Oct 14 11:48:55 2013 -0700
Merge pull request #3 from sheeep/release-1.0
Documentation / Test / Little Improvement
| 0
|
e6550e82a7c64a9c952f03364fafb5c27049d88d
|
1up-lab
|
OneupUploaderBundle
|
Messed up the links. Sorry.
|
commit e6550e82a7c64a9c952f03364fafb5c27049d88d
Author: Jim Schmid <[email protected]>
Date: Thu Apr 18 19:04:12 2013 +0200
Messed up the links. Sorry.
diff --git a/Resources/doc/events.md b/Resources/doc/events.md
index 30244f2..4edba13 100644
--- a/Resources/doc/events.md
+++ b/Resources/doc/events.md
@@ -14,4 +14,4 @@ Moreover this bundles also dispatches some special kind of generic events you ca
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
+See the [custom logic section](custom_logic.md) of this documentation for specific examples on how to use these Events.
\ No newline at end of file
| 0
|
70d745fed42b4744e70a50c4dfb2dd3a70ea712c
|
1up-lab
|
OneupUploaderBundle
|
Use the EventDispatcher in AbstractControllerValidationTest.
|
commit 70d745fed42b4744e70a50c4dfb2dd3a70ea712c
Author: Jim Schmid <[email protected]>
Date: Mon Apr 22 18:50:31 2013 +0200
Use the EventDispatcher in AbstractControllerValidationTest.
diff --git a/Tests/Controller/AbstractControllerValidationTest.php b/Tests/Controller/AbstractControllerValidationTest.php
index b066e3b..348c7a2 100644
--- a/Tests/Controller/AbstractControllerValidationTest.php
+++ b/Tests/Controller/AbstractControllerValidationTest.php
@@ -122,7 +122,32 @@ abstract class AbstractControllerValidationTest extends \PHPUnit_Framework_TestC
protected function getContainerMock()
{
- return $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+ $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 == 'event_dispatcher')
+ return $this->getEventDispatcherMock();
+ }
+
+ protected function getEventDispatcherMock()
+ {
+ $mock = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $mock
+ ->expects($this->any())
+ ->method('dispatch')
+ ->will($this->returnValue(true))
+ ;
+
+ return $mock;
}
protected function getStorageMock()
| 0
|
38cf65177d5d36cdfbd0f0ec6ecfa437b8335ae6
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
|
commit 38cf65177d5d36cdfbd0f0ec6ecfa437b8335ae6
Merge: cf5b24b a2b58ac
Author: Jim Schmid <[email protected]>
Date: Thu Jul 25 17:46:13 2013 +0200
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
| 0
|
f64018fc329f570fe47652066b15edce79f86021
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #100 from ribeiropaulor/bugfix_aws3_adapter
bugfix: when using AwsS3 adapter the mimeType was not being set.
|
commit f64018fc329f570fe47652066b15edce79f86021
Merge: 9f7f3fb 5904a41
Author: Jim Schmid <[email protected]>
Date: Tue Apr 8 10:15:36 2014 +0200
Merge pull request #100 from ribeiropaulor/bugfix_aws3_adapter
bugfix: when using AwsS3 adapter the mimeType was not being set.
| 0
|
d84b721e428a44bf3a3e888898689b46ae1675a1
|
1up-lab
|
OneupUploaderBundle
|
Added a FAQ entry.
|
commit d84b721e428a44bf3a3e888898689b46ae1675a1
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 17:15:14 2013 +0200
Added a FAQ entry.
diff --git a/Resources/doc/index.md b/Resources/doc/index.md
index db17308..cb24aa1 100644
--- a/Resources/doc/index.md
+++ b/Resources/doc/index.md
@@ -117,6 +117,10 @@ some more advanced features.
## FAQ
+> I want to use a frontend library you don't yet support
+
+This is absolutely no problem, just follow the instructions given in the corresponding [documentation file](custom_uploader.md). If you think that others could profit of your code, please consider making a pull request. I'm always happy for any kind of contribution.
+
> Why didn't you implement the _delete_ feature provided by Fine Uploader?
FineUploaders _delete Feature_ is using generated unique names we would have to store in order to track down which file to delete. But both the storage and the deletetion of files are tight-coupled with the logic of your very own implementation. This means we leave the _delete Feature_ open for you to implement. Information on how the route must be crafted can be found on the [official documentation](https://github.com/Widen/fine-uploader/blob/master/docs/options-fineuploaderbasic.md#deletefile-option-properties) and on [the blog](http://blog.fineuploader.com/2013/01/delete-uploaded-file-in-33.html) of Fine Uploader.
| 0
|
222e93cd91d3407120e9eaf9c790671d42031d60
|
1up-lab
|
OneupUploaderBundle
|
A bunch of stuff related to a new feature: Delete uploads.
|
commit 222e93cd91d3407120e9eaf9c790671d42031d60
Author: Jim Schmid <[email protected]>
Date: Thu Mar 14 20:01:17 2013 +0100
A bunch of stuff related to a new feature: Delete uploads.
diff --git a/Controller/UploadControllerInterface.php b/Controller/UploadControllerInterface.php
index 977375e..c2631a7 100644
--- a/Controller/UploadControllerInterface.php
+++ b/Controller/UploadControllerInterface.php
@@ -5,4 +5,5 @@ namespace Oneup\UploaderBundle\Controller;
interface UploadControllerInterface
{
public function upload();
+ public function delete($uuid = null);
}
\ No newline at end of file
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 0047a7d..a59fe54 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -5,6 +5,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\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Finder\Finder;
@@ -61,6 +62,16 @@ class UploaderController implements UploadControllerInterface
new JsonResponse(array('error' => 'An unknown error occured.'))
;
}
+
+ public function delete($uuid = null)
+ {
+ if(is_null($uuid))
+ return new HttpException(400, 'You must provide a file uuid.');
+
+ return $this->storage->remove($this->type, $uuid) ?
+ new JsonResponse(array('success' => true)):
+ new JsonResponse(array('error' => 'An unknown error occured.'));
+ }
protected function handleUpload(UploadedFile $file)
{
@@ -85,6 +96,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'],
));
$this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 658f48f..c3f4575 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -44,6 +44,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
->scalarNode('directory_prefix')->defaultNull()->end()
->booleanNode('use_orphanage')->defaultFalse()->end()
+ ->booleanNode('deletable')->defaultFalse()->end()
->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end()
->end()
->end()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 91e4520..3a0d2f2 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -71,6 +71,8 @@ class OneupUploaderExtension extends Extension
// inject the actual gaufrette filesystem
->addArgument(new Reference($storage))
+
+ ->addArgument(new Reference('oneup_uploader.deletable_manager'))
;
self::$storageServices[] = $name;
diff --git a/Event/PostDeleteEvent.php b/Event/PostDeleteEvent.php
new file mode 100644
index 0000000..00f9a93
--- /dev/null
+++ b/Event/PostDeleteEvent.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Oneup\UploaderBundle\Event;
+
+use Symfony\Component\EventDispatcher\Event;
+use Symfony\Component\HttpFoundation\Request;
+
+use Symfony\Component\HttpFoundation\File\File;
+
+class PostDeleteEvent extends Event
+{
+ protected $file;
+ protected $request;
+ protected $type;
+ protected $options;
+
+ public function __construct(File $file, Request $request, $type, array $options = array())
+ {
+ $this->file = $file;
+ $this->request = $request;
+ $this->type = $type;
+ $this->options = $options;
+ }
+
+ public function getFile()
+ {
+ return $this->file;
+ }
+
+ public function getRequest()
+ {
+ return $this->request;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function getOptions()
+ {
+ return $this->options;
+ }
+}
\ No newline at end of file
diff --git a/EventListener/DeletableListener.php b/EventListener/DeletableListener.php
new file mode 100644
index 0000000..38c752b
--- /dev/null
+++ b/EventListener/DeletableListener.php
@@ -0,0 +1,45 @@
+<?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',
+ );
+ }
+}
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 83369bf..fad0080 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -4,6 +4,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
+ <parameter key="oneup_uploader.deletable.manager.class">Oneup\UploaderBundle\Uploader\Deletable\DeletableManager</parameter>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.orphanage.manager.class">Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager</parameter>
<parameter key="oneup_uploader.orphanage.class">Oneup\UploaderBundle\Uploader\Orphanage\Orphanage</parameter>
@@ -11,7 +12,8 @@
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
<parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
<parameter key="oneup_uploader.storage.class">Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage</parameter>
- <parameter key="oneup_uploader.listener.session.class">Oneup\UploaderBundle\EventListener\OrphanageListener</parameter>
+ <parameter key="oneup_uploader.listener.orphanage.class">Oneup\UploaderBundle\EventListener\OrphanageListener</parameter>
+ <parameter key="oneup_uploader.listener.deletable.class">Oneup\UploaderBundle\EventListener\DeletableListener</parameter>
</parameters>
<services>
@@ -28,18 +30,29 @@
<!-- namer -->
<service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" />
+ <!-- deletable -->
+ <service id="oneup_uploader.deletable_manager" class="%oneup_uploader.deletable.manager.class%">
+ <argument type="service" id="session" />
+ </service>
+
<!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
<tag name="routing.loader" />
</service>
<!-- events -->
- <service id="oneup_uploader.listener.orphanage" class="%oneup_uploader.listener.session.class%">
+ <service id="oneup_uploader.listener.orphanage" class="%oneup_uploader.listener.orphanage.class%">
<argument type="service" id="oneup_uploader.orphanage_manager" />
<tag name="kernel.event_subscriber" />
</service>
+ <service id="oneup_uploader.listener.deletable" class="%oneup_uploader.listener.deletable.class%">
+ <argument type="service" id="oneup_uploader.deletable_manager" />
+
+ <tag name="kernel.event_subscriber" />
+ </service>
+
</services>
</container>
\ No newline at end of file
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 572f522..726e84d 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -32,13 +32,27 @@ class RouteLoader extends Loader
foreach($this->controllers as $type => $service)
{
- $route = new Route(
- sprintf('/_uploader/%s', $type),
+ $upload = new Route(
+ sprintf('/_uploader/%s/upload', $type),
array('_controller' => $service . ':upload', '_format' => 'json'),
array('_method' => 'POST')
);
- $routes->add(sprintf('_uploader_%s', $type), $route);
+ $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/Uploader/Deletable/DeletableManager.php b/Uploader/Deletable/DeletableManager.php
new file mode 100644
index 0000000..69ba85c
--- /dev/null
+++ b/Uploader/Deletable/DeletableManager.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Deletable;
+
+use Symfony\Component\HttpFoundation\File\File;
+use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
+use Symfony\Component\HttpFoundation\Session\SessionInterface;
+
+use Oneup\UploaderBundle\Uploader\Deletable\DeletableManagerInterface;
+
+class DeletableManager implements DeletableManagerInterface
+{
+ protected $session;
+
+ public function __construct(SessionInterface $session)
+ {
+ $this->session = $session;
+ }
+
+ public function addFile($type, $uuid, $name)
+ {
+ $session = $this->session;
+ $key = sprintf('oneup_uploader.deletable.%s', $type);
+
+ // get bag
+ $arr = $session->get($key, array());
+
+ $arr[$uuid] = $name;
+
+ // and reattach it to session
+ $session->set($key, $arr);
+
+ return true;
+ }
+
+ public function getFile($type, $uuid)
+ {
+ $session = $this->session;
+ $key = sprintf('oneup_uploader.deletable.%s', $type);
+
+ // get bag
+ $arr = $session->get($key, array());
+
+ if(!array_key_exists($uuid, $arr))
+ throw new \InvalidArgumentException(sprintf('No file with the uuid "%s" found', $uuid));
+
+ return $arr[$uuid];
+ }
+
+ public function removeFile($type, $uuid)
+ {
+ $session = $this->session;
+ $key = sprintf('oneup_uploader.deletable.%s', $type);
+
+ // get bag
+ $arr = $session->get($key, array());
+
+ if(!array_key_exists($uuid, $arr))
+ throw new \InvalidArgumentException(sprintf('No file with the uuid "%s" found', $uuid));
+
+ unset($arr[$uuid]);
+
+ $session->set($key, $arr);
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/Uploader/Deletable/DeletableManagerInterface.php b/Uploader/Deletable/DeletableManagerInterface.php
new file mode 100644
index 0000000..02afdf1
--- /dev/null
+++ b/Uploader/Deletable/DeletableManagerInterface.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Oneup\UploaderBundle\Uploader\Deletable;
+
+interface DeletableManagerInterface
+{
+}
\ No newline at end of file
diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php
index cfc5d35..f0a7430 100644
--- a/Uploader/Storage/GaufretteStorage.php
+++ b/Uploader/Storage/GaufretteStorage.php
@@ -6,15 +6,19 @@ use Symfony\Component\HttpFoundation\File\File;
use Gaufrette\Stream\Local as LocalStream;
use Gaufrette\StreamMode;
use Gaufrette\Filesystem;
+
use Oneup\UploaderBundle\Uploader\Storage\StorageInterface;
+use Oneup\UploaderBundle\Uploader\Deletable\DeletableManagerInterface;
class GaufretteStorage implements StorageInterface
{
protected $filesystem;
+ protected $deletableManager;
- public function __construct(Filesystem $filesystem)
+ public function __construct(Filesystem $filesystem, DeletableManagerInterface $deletableManager)
{
$this->filesystem = $filesystem;
+ $this->deletableManager = $deletableManager;
}
public function upload(File $file, $name = null)
@@ -46,8 +50,28 @@ class GaufretteStorage implements StorageInterface
return $this->filesystem->get($name);
}
- public function remove(File $file)
+ public function remove($type, $uuid)
{
+ try
+ {
+ // get associated file path
+ $name = $this->deletableManager->getFile($type, $uuid);
+
+ if($this->filesystem->has($name))
+ {
+ $this->filesystem->delete($name);
+ }
+
+ // delete this reference anyway
+ $this->deletableManager->removeFile($type, $uuid);
+ }
+ catch(\Exception $e)
+ {
+ // whoopsi, something went terribly wrong
+ // better leave this method now and never look back
+ return false;
+ }
+ return true;
}
}
\ No newline at end of file
diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php
index 1e4a287..38eb9c8 100644
--- a/Uploader/Storage/StorageInterface.php
+++ b/Uploader/Storage/StorageInterface.php
@@ -7,5 +7,5 @@ use Symfony\Component\HttpFoundation\File\File;
interface StorageInterface
{
public function upload(File $file, $name);
- public function remove(File $file);
+ public function remove($type, $uuid);
}
\ No newline at end of file
| 0
|
9fa868f0f92759d421787dea82c53274e83063b1
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #225 from SrgSteak/patch-1
Upload large files with flysystem
|
commit 9fa868f0f92759d421787dea82c53274e83063b1
Merge: 0abd706 394a7ab
Author: Jim Schmid <[email protected]>
Date: Thu Feb 11 10:03:43 2016 +0100
Merge pull request #225 from SrgSteak/patch-1
Upload large files with flysystem
| 0
|
beaadefeb00acf0230f3f96cdbc02c6c21f7220e
|
1up-lab
|
OneupUploaderBundle
|
Added chunk configuration.
|
commit beaadefeb00acf0230f3f96cdbc02c6c21f7220e
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 10:08:24 2013 +0100
Added chunk configuration.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 2c20ba1..902be76 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -11,6 +11,17 @@ class Configuration implements ConfigurationInterface
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('oneup_uploader');
+
+ $rootNode
+ ->children()
+ ->arrayNode('chunks')
+ ->addDefaultsIfNotSet()
+ ->children()
+ ->scalarNode('directory')->end()
+ ->scalarNode('maxage')->defaultValue(604800)->end()
+ ->end()
+ ->end()
+ ;
return $treeBuilder;
}
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 3a77172..29cd7e9 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -16,5 +16,13 @@ class OneupUploaderExtension extends Extension
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
+
+ // handling chunk configuration
+ if(!array_key_exists('directory', $config['chunks']))
+ {
+ $config['chunks']['directory'] = sprintf('%s/chunks', $container->getParameter('kernel.cache_dir'));
+ }
+
+ $container->setParameter('oneup_uploader.chunks', $config['chunks']);
}
}
\ No newline at end of file
| 0
|
3ecd0b845d996916abc37d1e5052902756965ba5
|
1up-lab
|
OneupUploaderBundle
|
Fix for blueimp uploading not translating error messages
|
commit 3ecd0b845d996916abc37d1e5052902756965ba5
Author: Jason Playne <[email protected]>
Date: Tue Mar 14 11:13:35 2017 +0800
Fix for blueimp uploading not translating error messages
diff --git a/Resources/config/errorhandler.xml b/Resources/config/errorhandler.xml
index bf580bf..1f51fb2 100644
--- a/Resources/config/errorhandler.xml
+++ b/Resources/config/errorhandler.xml
@@ -12,7 +12,9 @@
<services>
<service id="oneup_uploader.error_handler.noop" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.fineuploader" class="%oneup_uploader.error_handler.noop.class%" public="false" />
- <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false" />
+ <service id="oneup_uploader.error_handler.blueimp" class="%oneup_uploader.error_handler.blueimp.class%" public="false">
+ <argument type="service" id="translator"/>
+ </service>
<service id="oneup_uploader.error_handler.uploadify" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.yui3" class="%oneup_uploader.error_handler.noop.class%" public="false" />
<service id="oneup_uploader.error_handler.fancyupload" class="%oneup_uploader.error_handler.noop.class%" public="false" />
diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php
index 7ba1307..871e687 100644
--- a/Tests/Controller/BlueimpValidationTest.php
+++ b/Tests/Controller/BlueimpValidationTest.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\Tests\Controller;
+use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest;
use Oneup\UploaderBundle\UploadEvents;
@@ -11,6 +12,7 @@ class BlueimpValidationTest extends AbstractValidationTest
public function testAgainstMaxSize()
{
// assemble a request
+ /** @var Client $client */
$client = $this->client;
$endpoint = $this->helper->endpoint($this->getConfigKey());
@@ -20,6 +22,7 @@ class BlueimpValidationTest extends AbstractValidationTest
//$this->assertTrue($response->isNotSuccessful());
$this->assertEquals($response->headers->get('Content-Type'), 'application/json');
$this->assertCount(0, $this->getUploadedFiles());
+ $this->assertFalse(strpos($response->getContent(), 'error.maxsize'), "Failed to translate error id into lang");
}
public function testEvents()
diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php
index c8839b7..be5e088 100644
--- a/Uploader/ErrorHandler/BlueimpErrorHandler.php
+++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php
@@ -5,12 +5,23 @@ namespace Oneup\UploaderBundle\Uploader\ErrorHandler;
use Exception;
use Oneup\UploaderBundle\Uploader\ErrorHandler\ErrorHandlerInterface;
use Oneup\UploaderBundle\Uploader\Response\AbstractResponse;
+use Symfony\Component\Translation\TranslatorInterface;
class BlueimpErrorHandler implements ErrorHandlerInterface
{
+ /**
+ * @var TranslatorInterface
+ */
+ private $translator;
+
+ public function __construct(TranslatorInterface $translator)
+ {
+ $this->translator = $translator;
+ }
+
public function addException(AbstractResponse $response, Exception $exception)
{
- $message = $exception->getMessage();
+ $message = $this->translator->trans($exception->getMessage(), array(), 'OneupUploaderBundle');
$response->addToOffset(array('error' => $message), array('files'));
}
}
| 0
|
68e1534803d4c9f0338e007224e0bfe390079c39
|
1up-lab
|
OneupUploaderBundle
|
Refactored dynamic controllers.
|
commit 68e1534803d4c9f0338e007224e0bfe390079c39
Author: Jim Schmid <[email protected]>
Date: Tue Mar 12 16:03:35 2013 +0100
Refactored dynamic controllers.
diff --git a/Controller/UploadControllerInterface.php b/Controller/UploadControllerInterface.php
new file mode 100644
index 0000000..977375e
--- /dev/null
+++ b/Controller/UploadControllerInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+interface UploadControllerInterface
+{
+ public function upload();
+}
\ No newline at end of file
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 0209311..f5e0b84 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -2,25 +2,44 @@
namespace Oneup\UploaderBundle\Controller;
-class UploaderController
+use Oneup\UploaderBundle\Controller\UploadControllerInterface;
+
+class UploaderController implements UploadControllerInterface
{
- protected $mappings;
- protected $container;
+ protected $namer;
+ protected $storage;
- public function __construct($mappings, $container)
+ public function __construct($namer, $storage)
{
- $this->mappings = $mappings;
- $this->container = $container;
+ $this->namer = $namer;
+ $this->storage = $storage;
}
- public function upload($mapping)
+ public function upload()
{
+ /*
$container = $this->container;
$config = $this->mappings[$mapping];
+ $request = $container->get('request');
+ $files = $request->files;
if(!$container->has($config['storage']))
throw new \InvalidArgumentException(sprintf('The storage service "%s" must be defined.'));
+
+ if(!$container->has($config['namer']))
+ throw new \InvalidArgumentException(sprintf('The namer service "%s" must be defined.'));
$storage = $container->get($config['storage']);
+ $namer = $container->get($config['namer']);
+
+ var_dump($request);
+
+ die();
+ foreach($files as $file)
+ {
+ var_dump($namer->name($file, $config));
+ }
+ */
+ die();
}
}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index afbd956..f5ece9d 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -14,13 +14,6 @@ class Configuration implements ConfigurationInterface
$rootNode
->children()
- ->arrayNode('routing')
- ->addDefaultsIfNotSet()
- ->children()
- ->scalarNode('name')->defaultValue('/_uploader')->end()
- ->scalarNode('action')->defaultValue('oneup_uploader.controller:upload')->end()
- ->end()
- ->end()
->arrayNode('chunks')
->addDefaultsIfNotSet()
->children()
diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php
index 01ca0b3..8f8011b 100644
--- a/DependencyInjection/OneupUploaderExtension.php
+++ b/DependencyInjection/OneupUploaderExtension.php
@@ -2,6 +2,7 @@
namespace Oneup\UploaderBundle\DependencyInjection;
+use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -17,12 +18,6 @@ class OneupUploaderExtension extends Extension
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('uploader.xml');
- // handle routing configuration
- foreach($config['routing'] as $key => $value)
- {
- $container->setParameter(sprintf('oneup_uploader.routing.%s', $key), $value);
- }
-
// handling chunk configuration
if(!array_key_exists('directory', $config['chunks']))
{
@@ -42,9 +37,23 @@ class OneupUploaderExtension extends Extension
// handle mappings
foreach($config['mappings'] as $key => $mapping)
{
- $container->setParameter(sprintf('oneup_uploader.mapping.%s', $key), $value);
+ $this->registerServicesPerMap($container, $key, $mapping);
}
-
- $container->setParameter('oneup_uploader.mappings', $config['mappings']);
+ }
+
+ public function registerServicesPerMap(ContainerBuilder $container, $type, $mapping)
+ {
+ // create controllers based on mapping
+ $container
+ ->register(sprintf('oneup_uploader.controller.%s', $type), $container->getParameter('oneup_uploader.controller.class'))
+
+ // add the correct namer as argument
+ ->addArgument(new Reference($mapping['namer']))
+
+ // add the correspoding storage service as argument
+ ->addArgument(new Reference($mapping['storage']))
+
+ ->addTag('oneup_uploader.routable', array('type' => $type))
+ ;
}
}
\ No newline at end of file
diff --git a/OneupUploaderBundle.php b/OneupUploaderBundle.php
index 22c1af9..f359549 100644
--- a/OneupUploaderBundle.php
+++ b/OneupUploaderBundle.php
@@ -3,7 +3,16 @@
namespace Oneup\UploaderBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+
+use Oneup\UploaderBundle\DependencyInjection\Compiler\ControllerCompilerPass;
class OneupUploaderBundle extends Bundle
{
+ public function build(ContainerBuilder $container)
+ {
+ parent::build($container);
+
+ $container->addCompilerPass(new ControllerCompilerPass);
+ }
}
\ No newline at end of file
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 11344b6..3816e43 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -23,18 +23,8 @@
<!-- namer -->
<service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" />
- <!-- controller -->
- <service id="oneup_uploader.controller" class="%oneup_uploader.controller.class%">
- <argument>%oneup_uploader.mappings%</argument>
- <argument type="service" id="service_container" />
- </service>
-
<!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
- <argument>%oneup_uploader.routing.action%</argument>
- <argument>%oneup_uploader.routing.name%</argument>
- <argument>%oneup_uploader.mappings%</argument>
-
<tag name="routing.loader" />
</service>
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 881e0d9..771fb01 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -8,15 +8,17 @@ use Symfony\Component\Routing\RouteCollection;
class RouteLoader extends Loader
{
- protected $action;
- protected $prefix;
- protected $mappings;
+ protected $name;
+ protected $controllers;
- public function __construct($action, $name, array $mappings)
+ public function __construct()
{
- $this->name = $name;
- $this->action = $action;
- $this->mappings = $mappings;
+ $this->controllers = array();
+ }
+
+ public function addController($type, $controller)
+ {
+ $this->controllers[$type] = $controller;
}
public function supports($resource, $type = null)
@@ -26,22 +28,17 @@ class RouteLoader extends Loader
public function load($resource, $type = null)
{
- $requirements = array('_method' => 'POST', 'mapping' => '[A-z0-9_\-]*');
$routes = new RouteCollection();
- foreach($this->mappings as $key => $mapping)
+ foreach($this->controllers as $type => $service)
{
- $defaults = array(
- '_controller' => is_null($mapping['action']) ? $this->action : $mapping['action'],
- 'mapping' => $key
+ $route = new Route(
+ sprintf('/_uploader/%s', $type),
+ array('_controller' => $service . ':upload'),
+ array('_method' => 'POST')
);
- $routes->add(sprintf('_uploader_%s', $key), new Route(
- sprintf('%s/{mapping}', $this->name),
- $defaults,
- $requirements,
- array()
- ));
+ $routes->add(sprintf('_uploader_%s', $type), $route);
}
return $routes;
| 0
|
8a2fc86ac9d83457193c40cbc006f5799495e2b0
|
1up-lab
|
OneupUploaderBundle
|
Removed default value 'fineuploader' for frontend key in Configuration.
This was a legacy decision which will be changed in 1.0.0.
The first version of this Bundle only supported Fineuploader which
would have been a BC break if 'fineuploader' was not the default value.
|
commit 8a2fc86ac9d83457193c40cbc006f5799495e2b0
Author: Jim Schmid <[email protected]>
Date: Tue Oct 8 20:31:29 2013 +0200
Removed default value 'fineuploader' for frontend key in Configuration.
This was a legacy decision which will be changed in 1.0.0.
The first version of this Bundle only supported Fineuploader which
would have been a BC break if 'fineuploader' was not the default value.
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index e18268a..97b1eef 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -38,7 +38,6 @@ class Configuration implements ConfigurationInterface
->children()
->enumNode('frontend')
->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom'))
- ->defaultValue('fineuploader')
->end()
->arrayNode('custom_frontend')
->addDefaultsIfNotSet()
| 0
|
f3d5507675fa0b56410bbaf219678087170fa7ea
|
1up-lab
|
OneupUploaderBundle
|
Added a Controller, registered it as a Service and made it configurable through configuration.
|
commit f3d5507675fa0b56410bbaf219678087170fa7ea
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 18:54:04 2013 +0100
Added a Controller, registered it as a Service and made it configurable through configuration.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
new file mode 100644
index 0000000..c33e281
--- /dev/null
+++ b/Controller/UploaderController.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Oneup\UploaderBundle\Controller;
+
+class UploaderController
+{
+ protected $mappings;
+
+ public function __construct($mappings)
+ {
+ $this->mappings = $mappings;
+ }
+
+ public function upload($mapping)
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9cbdc10..7900b4e 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -17,8 +17,8 @@ class Configuration implements ConfigurationInterface
->arrayNode('routing')
->addDefaultsIfNotSet()
->children()
- ->scalarNode('prefix')->defaultValue('/oneup/uploader')->end()
- ->scalarNode('action')->defaultValue('OneupUploaderBundle:Uploader:upload')->end()
+ ->scalarNode('name')->defaultValue('/_uploader')->end()
+ ->scalarNode('action')->defaultValue('oneup_uploader.controller:upload')->end()
->end()
->end()
->arrayNode('chunks')
@@ -34,8 +34,9 @@ class Configuration implements ConfigurationInterface
->requiresAtLeastOneElement()
->prototype('array')
->children()
- ->scalarNode('namer')->defaultNull()->end()
->scalarNode('storage')->isRequired()->end()
+ ->scalarNode('action')->defaultNull()->end()
+ ->scalarNode('namer')->defaultNull()->end()
->end()
->end()
->end()
diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml
index 727e452..e440170 100644
--- a/Resources/config/uploader.xml
+++ b/Resources/config/uploader.xml
@@ -6,6 +6,7 @@
<parameters>
<parameter key="oneup_uploader.chunks.manager.class">Oneup\UploaderBundle\Uploader\Chunk\ChunkManager</parameter>
<parameter key="oneup_uploader.routing.loader.class">Oneup\UploaderBundle\Routing\RouteLoader</parameter>
+ <parameter key="oneup_uploader.controller.class">Oneup\UploaderBundle\Controller\UploaderController</parameter>
</parameters>
<services>
@@ -13,9 +14,15 @@
<argument>%oneup_uploader.chunks%</argument>
</service>
+ <!-- controller -->
+ <service id="oneup_uploader.controller" class="%oneup_uploader.controller.class%">
+ <argument>%oneup_uploader.mappings%</argument>
+ </service>
+
+ <!-- routing -->
<service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%">
<argument>%oneup_uploader.routing.action%</argument>
- <argument>%oneup_uploader.routing.prefix%</argument>
+ <argument>%oneup_uploader.routing.name%</argument>
<argument>%oneup_uploader.mappings%</argument>
<tag name="routing.loader" />
diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php
index 7c6ef11..881e0d9 100644
--- a/Routing/RouteLoader.php
+++ b/Routing/RouteLoader.php
@@ -12,10 +12,10 @@ class RouteLoader extends Loader
protected $prefix;
protected $mappings;
- public function __construct($action, $prefix, array $mappings)
+ public function __construct($action, $name, array $mappings)
{
+ $this->name = $name;
$this->action = $action;
- $this->prefix = $prefix;
$this->mappings = $mappings;
}
@@ -27,16 +27,17 @@ class RouteLoader extends Loader
public function load($resource, $type = null)
{
$requirements = array('_method' => 'POST', 'mapping' => '[A-z0-9_\-]*');
- $defaults = array('_controller' => $this->action);
-
$routes = new RouteCollection();
foreach($this->mappings as $key => $mapping)
{
- $defaults += array('mapping' => $key);
+ $defaults = array(
+ '_controller' => is_null($mapping['action']) ? $this->action : $mapping['action'],
+ 'mapping' => $key
+ );
$routes->add(sprintf('_uploader_%s', $key), new Route(
- sprintf('%s/{mapping}', $this->prefix),
+ sprintf('%s/{mapping}', $this->name),
$defaults,
$requirements,
array()
| 0
|
ab115fc37d8fabb1347a3d476482c1bbeee33e55
|
1up-lab
|
OneupUploaderBundle
|
Renamed (dis)allowed_types to (dis)allowed_extensions.
|
commit ab115fc37d8fabb1347a3d476482c1bbeee33e55
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 14:43:41 2013 +0200
Renamed (dis)allowed_types to (dis)allowed_extensions.
diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php
index 3e63f8b..21cf3d9 100644
--- a/Controller/UploaderController.php
+++ b/Controller/UploaderController.php
@@ -130,12 +130,12 @@ class UploaderController implements UploadControllerInterface
// 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']))
+ if(count($this->config['allowed_extensions']) > 0 && !in_array($extension, $this->config['allowed_extensions']))
throw new UploadException('This extension is not allowed.');
// check if the current extension is mentioned in the disallowed types
// and if so, throw an exception
- if(count($this->config['disallowed_types']) > 0 && in_array($extension, $this->config['disallowed_types']))
+ if(count($this->config['disallowed_extensions']) > 0 && in_array($extension, $this->config['disallowed_extensions']))
throw new UploadException('This extension is not allowed.');
}
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 4deb776..5f061b0 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -46,10 +46,10 @@ class Configuration implements ConfigurationInterface
->scalarNode('directory')->defaultNull()->end()
->end()
->end()
- ->arrayNode('allowed_types')
+ ->arrayNode('allowed_extensions')
->prototype('scalar')->end()
->end()
- ->arrayNode('disallowed_types')
+ ->arrayNode('disallowed_extensions')
->prototype('scalar')->end()
->end()
->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end()
| 0
|
a488f6f8f32f51e49c5ee02695e24cff40ee6b02
|
1up-lab
|
OneupUploaderBundle
|
Fix links
|
commit a488f6f8f32f51e49c5ee02695e24cff40ee6b02
Author: David Greminger <[email protected]>
Date: Fri Mar 27 16:53:48 2020 +0100
Fix links
diff --git a/README.md b/README.md
index cd057cb..f9b252e 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in
Upgrade Notes
-------------
-* Version **3.0.0** supports now Symfony 5 (kudos to @steveWinter, @gubler, @patrickbussmann, @ErnadoO and @enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
+* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter], @[gubler], @[patrickbussmann], @[ErnadoO] and @[enumag]), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped.
* Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)).
* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway).
* Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
| 0
|
dad8de6070dd9d4fb54e00da12aa23d2e38c613b
|
1up-lab
|
OneupUploaderBundle
|
New depending.in image source.
|
commit dad8de6070dd9d4fb54e00da12aa23d2e38c613b
Author: Jim Schmid <[email protected]>
Date: Mon Nov 18 10:50:13 2013 +0100
New depending.in image source.
diff --git a/README.md b/README.md
index 0abe5c1..7ddeab2 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ Features included:
* Fully unit tested
[](https://travis-ci.org/1up-lab/OneupUploaderBundle)
-[](http://depending.in/1up-lab/OneupUploaderBundle)
+[](http://depending.in/1up-lab/OneupUploaderBundle)
[](https://packagist.org/packages/oneup/uploader-bundle)
Documentation
| 0
|
9dce81dd52fef5195e16113de8443c62531e9234
|
1up-lab
|
OneupUploaderBundle
|
Merge pull request #120 from umpirsky/patch-1
Filesystem is already in parent class
|
commit 9dce81dd52fef5195e16113de8443c62531e9234
Merge: 4967f7c 32a4efa
Author: Jim Schmid <[email protected]>
Date: Fri Jul 18 15:07:48 2014 +0200
Merge pull request #120 from umpirsky/patch-1
Filesystem is already in parent class
| 0
|
0127666ebd0a6aa0c69a768f7276a79fdc8f14ee
|
1up-lab
|
OneupUploaderBundle
|
Replaced deprecated global Twig functions (#366)
|
commit 0127666ebd0a6aa0c69a768f7276a79fdc8f14ee
Author: Koen van Wijnen <[email protected]>
Date: Wed Feb 5 07:25:08 2020 +0100
Replaced deprecated global Twig functions (#366)
diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php
index a8664b1..a5a7c44 100644
--- a/Twig/Extension/UploaderExtension.php
+++ b/Twig/Extension/UploaderExtension.php
@@ -3,8 +3,10 @@
namespace Oneup\UploaderBundle\Twig\Extension;
use Oneup\UploaderBundle\Templating\Helper\UploaderHelper;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
-class UploaderExtension extends \Twig_Extension
+class UploaderExtension extends AbstractExtension
{
protected $helper;
@@ -21,11 +23,11 @@ class UploaderExtension extends \Twig_Extension
public function getFunctions()
{
return [
- new \Twig_SimpleFunction('oneup_uploader_endpoint', [$this, 'endpoint']),
- new \Twig_SimpleFunction('oneup_uploader_progress', [$this, 'progress']),
- new \Twig_SimpleFunction('oneup_uploader_cancel', [$this, 'cancel']),
- new \Twig_SimpleFunction('oneup_uploader_upload_key', [$this, 'uploadKey']),
- new \Twig_SimpleFunction('oneup_uploader_maxsize', [$this, 'maxSize']),
+ new TwigFunction('oneup_uploader_endpoint', [$this, 'endpoint']),
+ new TwigFunction('oneup_uploader_progress', [$this, 'progress']),
+ new TwigFunction('oneup_uploader_cancel', [$this, 'cancel']),
+ new TwigFunction('oneup_uploader_upload_key', [$this, 'uploadKey']),
+ new TwigFunction('oneup_uploader_maxsize', [$this, 'maxSize']),
];
}
diff --git a/composer.json b/composer.json
index 6da9463..3a90d01 100644
--- a/composer.json
+++ b/composer.json
@@ -28,7 +28,8 @@
"symfony/http-foundation": "^3.0|^4.0",
"symfony/templating": "^3.0|^4.0",
"symfony/translation": "^3.0|^4.0",
- "symfony/yaml": "^3.0|^4.0"
+ "symfony/yaml": "^3.0|^4.0",
+ "twig/twig": "^1.41|^2.10|^3.0"
},
"require-dev": {
| 0
|
06bbbe2a98e10dbab2cb487c78487bb7937f7a9b
|
1up-lab
|
OneupUploaderBundle
|
Fixes wrong class name in RouteLoaderTest.
|
commit 06bbbe2a98e10dbab2cb487c78487bb7937f7a9b
Author: Jim Schmid <[email protected]>
Date: Sat Apr 6 16:50:19 2013 +0200
Fixes wrong class name in RouteLoaderTest.
diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php
index c1e6edd..4bd7ca9 100644
--- a/Tests/Routing/RouteLoaderTest.php
+++ b/Tests/Routing/RouteLoaderTest.php
@@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Tests\Routing;
use Oneup\UploaderBundle\Routing\RouteLoader;
-class RoutingTest extends \PHPUnit_Framework_TestCase
+class RouteLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testRouteLoader()
{
| 0
|
5be2e5b52db91466ee14cf700d048255b8f8df4f
|
1up-lab
|
OneupUploaderBundle
|
Test event dispatching of post update event.
|
commit 5be2e5b52db91466ee14cf700d048255b8f8df4f
Author: Jim Schmid <[email protected]>
Date: Thu Jun 20 20:19:29 2013 +0200
Test event dispatching of post update event.
diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md
index e3cda00..a42926c 100644
--- a/Resources/doc/custom_logic.md
+++ b/Resources/doc/custom_logic.md
@@ -84,7 +84,6 @@ The Event object provides the following methods.
## Using chunked uploads
If you are using chunked uploads and hook into the `oneup_uploader.post_chunk_upload` event, you will get `PostChunkUploadEvent` in your listeners. This Event type differs from the previously introduced ones. You'll have the following methods.
-
* `getChunk`: Get the chunk file. Is an instance of `Symfony\Component\HttpFoundation\File\File`.
* `getRequest`: Get the current request including custom variables.
* `getResponse`: Get the response object to add custom return data.
diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php
index 8603bd2..754bb8d 100644
--- a/Tests/Controller/AbstractUploadTest.php
+++ b/Tests/Controller/AbstractUploadTest.php
@@ -3,6 +3,8 @@
namespace Oneup\UploaderBundle\Tests\Controller;
use Oneup\UploaderBundle\Tests\Controller\AbstractControllerTest;
+use Oneup\UploaderBundle\UploadEvents;
+use Oneup\UploaderBundle\Event\PostUploadEvent;
abstract class AbstractUploadTest extends AbstractControllerTest
{
@@ -35,4 +37,29 @@ abstract class AbstractUploadTest extends AbstractControllerTest
$this->assertEquals(128, $file->getSize());
}
}
+
+ public function testEvents()
+ {
+ $client = $this->client;
+ $endpoint = $this->helper->endpoint($this->getConfigKey());
+ $dispatcher = $client->getContainer()->get('event_dispatcher');
+
+ // event data
+ $me = $this;
+ $uploadCount = 0;
+
+ $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(PostUploadEvent $event) use (&$uploadCount, &$me) {
+ ++ $uploadCount;
+
+ $file = $event->getFile();
+
+ $me->assertInstanceOf('Symfony\Component\HttpFoundation\File\File', $file);
+ $me->assertEquals(128, $file->getSize());
+ });
+
+ $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getRequestFile()));
+
+ $this->assertCount(1, $this->getUploadedFiles());
+ $this->assertEquals($uploadCount, count($this->getUploadedFiles()));
+ }
}
| 0
|
bbf9ab86d226a8a1dac92f744949835d932f1f38
|
1up-lab
|
OneupUploaderBundle
|
Fix typo in composer constraint (see #306)
|
commit bbf9ab86d226a8a1dac92f744949835d932f1f38
Author: Nikola Kuzmanović <[email protected]>
Date: Thu Dec 14 14:06:09 2017 +0100
Fix typo in composer constraint (see #306)
diff --git a/composer.json b/composer.json
index 25b7e00..dc5b01b 100644
--- a/composer.json
+++ b/composer.json
@@ -19,7 +19,7 @@
"paragonie/random_compat": "^1.1|^2.0",
"symfony/asset": "^3.0|^4.0",
"symfony/finder": "^3.0|^4.0",
- "symfony/framework-bundle": "^3.0|4.0",
+ "symfony/framework-bundle": "^3.0|^4.0",
"symfony/templating": "^3.0|^4.0",
"symfony/translation": "^3.0|^4.0",
"symfony/yaml": "^3.0|^4.0"
| 0
|
2c4b17dbc589c2c716e4008a7b27633d3d3864da
|
1up-lab
|
OneupUploaderBundle
|
Darn, forgot to delete some debug stuff in AbstractController.
|
commit 2c4b17dbc589c2c716e4008a7b27633d3d3864da
Author: Jim Schmid <[email protected]>
Date: Thu Apr 18 19:08:49 2013 +0200
Darn, forgot to delete some debug stuff in AbstractController.
diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php
index 75e1cc8..ac8a1f0 100644
--- a/Controller/AbstractController.php
+++ b/Controller/AbstractController.php
@@ -55,8 +55,6 @@ abstract class AbstractController
$dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent);
$dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent);
- var_dump(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type));
-
if(!$this->config['use_orphanage'])
{
// dispatch post persist event (both the specific and the general)
| 0
|
c7d022d74a1de408dd8ad06d5083ac11a7a547df
|
1up-lab
|
OneupUploaderBundle
|
Removed unused variables on UploadifyController.
|
commit c7d022d74a1de408dd8ad06d5083ac11a7a547df
Author: Jim Schmid <[email protected]>
Date: Fri Apr 12 11:25:18 2013 +0200
Removed unused variables on UploadifyController.
diff --git a/Controller/UploadifyController.php b/Controller/UploadifyController.php
index 7c94966..ea18f52 100644
--- a/Controller/UploadifyController.php
+++ b/Controller/UploadifyController.php
@@ -13,9 +13,6 @@ class UploadifyController extends AbstractController
public function upload()
{
$request = $this->container->get('request');
- $dispatcher = $this->container->get('event_dispatcher');
- $translator = $this->container->get('translator');
-
$response = new EmptyResponse();
$files = $request->files;
| 0
|
69d0819038a736e02bb5cbb420b06e502efc22e8
|
1up-lab
|
OneupUploaderBundle
|
Merge branch 'dropzone-chunk' of git://github.com/tompiard/OneupUploaderBundle into tompiard-dropzone-chunk
|
commit 69d0819038a736e02bb5cbb420b06e502efc22e8
Merge: e1e139a bf10b7b
Author: David Greminger <[email protected]>
Date: Tue Nov 21 17:19:30 2017 +0100
Merge branch 'dropzone-chunk' of git://github.com/tompiard/OneupUploaderBundle into tompiard-dropzone-chunk
| 0
|
a6c0d14eda9a30197178da8a9ba3cc81339bb90f
|
1up-lab
|
OneupUploaderBundle
|
Catch incoming InvalidArgumentExceptions which Finder will throw if the chunk-directory does not exist.
|
commit a6c0d14eda9a30197178da8a9ba3cc81339bb90f
Author: Jim Schmid <[email protected]>
Date: Mon Mar 11 13:39:15 2013 +0100
Catch incoming InvalidArgumentExceptions which Finder will throw if the chunk-directory does not exist.
diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php
index 1b184f5..4d1077d 100644
--- a/Uploader/Chunk/ChunkManager.php
+++ b/Uploader/Chunk/ChunkManager.php
@@ -25,7 +25,18 @@ class ChunkManager implements ChunkManagerInterface
$system = new Filesystem();
$finder = new Finder();
- $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
+ try
+ {
+ $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds');
+ }
+ catch(\InvalidArgumentException $e)
+ {
+ // the finder will throw an exception of type InvalidArgumentException
+ // if the directory he should search in does not exist
+ // in that case we don't have anything to clean
+ return;
+ }
+
foreach($finder as $file)
{
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.