Skip to content

Commit

Permalink
Merge pull request #57 from 1up-lab/release-1.0
Browse files Browse the repository at this point in the history
Release 1.0
  • Loading branch information
Jim Schmid committed Oct 23, 2013
2 parents 706cb28 + 8e21e81 commit 0a5c5d1
Show file tree
Hide file tree
Showing 75 changed files with 1,587 additions and 664 deletions.
9 changes: 8 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
tools:
php_code_sniffer: true
php_cs_fixer: true
php_mess_detector: true
php_mess_detector:
config:
code_size_rules:
too_many_fields: false
too_many_methods: false

design_rules:
coupling_between_objects: false
php_analyzer: true
sensiolabs_security_checker: true
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ php:
- 5.4

env:
- SYMFONY_VERSION=2.1.*
- SYMFONY_VERSION=2.2.*
- SYMFONY_VERSION=2.3.*

Expand Down
15 changes: 8 additions & 7 deletions Controller/AbstractChunkedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re
$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 (null !== $chunk) {
$this->dispatchChunkEvents($chunk, $response, $request, $last);
}

if ($chunkManager->getLoadDistribution()) {
$chunks = $chunkManager->getChunks($uuid);
$assembled = $chunkManager->assembleChunks($chunks, true, $last);

if (null === $chunk) {
$this->dispatchChunkEvents($assembled, $response, $request, $last);
}
}

// if all chunks collected and stored, proceed
Expand All @@ -73,9 +76,7 @@ protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $re

$path = $assembled->getPath();

// create a temporary uploaded file to meet the interface restrictions
$uploadedFile = new UploadedFile($assembled->getPathname(), $assembled->getBasename(), null, $assembled->getSize(), null, true);
$uploaded = $this->handleUpload($uploadedFile, $response, $request);
$this->handleUpload($assembled, $response, $request);

$chunkManager->cleanup($path);
}
Expand Down
19 changes: 13 additions & 6 deletions Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Oneup\UploaderBundle\Controller;

use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\File\FilesystemFile;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\FileBag;

Expand Down Expand Up @@ -99,12 +100,18 @@ protected function getFiles(FileBag $bag)
*
* Note: The return value differs when
*
* @param UploadedFile The file to upload
* @param The file to upload
* @param response A response object.
* @param request The request object.
*/
protected function handleUpload(UploadedFile $file, ResponseInterface $response, Request $request)
protected function handleUpload($file, ResponseInterface $response, Request $request)
{
// wrap the file if it is not done yet which can only happen
// if it wasn't a chunked upload, in which case it is definitely
// on the local filesystem.
if (!($file instanceof FileInterface)) {
$file = new FilesystemFile($file);
}
$this->validate($file);

$this->dispatchPreUploadEvent($file, $response, $request);
Expand All @@ -126,7 +133,7 @@ protected function handleUpload(UploadedFile $file, ResponseInterface $response,
* @param response A response object.
* @param request The request object.
*/
protected function dispatchPreUploadEvent(UploadedFile $uploaded, ResponseInterface $response, Request $request)
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request)
{
$dispatcher = $this->container->get('event_dispatcher');

Expand Down Expand Up @@ -161,10 +168,10 @@ protected function dispatchPostEvents($uploaded, ResponseInterface $response, Re
}
}

protected function validate(UploadedFile $file)
protected function validate(FileInterface $file)
{
$dispatcher = $this->container->get('event_dispatcher');
$event = new ValidationEvent($file, $this->config, $this->type, $this->container->get('request'));
$event = new ValidationEvent($file, $this->container->get('request'), $this->config, $this->type);

$dispatcher->dispatch(UploadEvents::VALIDATION, $event);
}
Expand Down
3 changes: 1 addition & 2 deletions Controller/BlueimpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function parseChunkedRequest(Request $request)
$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);
list(, $startByte, $endByte, $totalBytes) = preg_split('/[^0-9]+/', $headerRange);

// getting information about chunks
// note: We don't have a chance to get the last $total
Expand All @@ -73,7 +73,6 @@ protected function parseChunkedRequest(Request $request)
$size = ($endByte + 1 - $startByte);
$last = ($endByte + 1) == $totalBytes;
$index = $last ? \PHP_INT_MAX : floor($startByte / $size);
$total = ceil($totalBytes / $size);

// it is possible, that two clients send a file with the
// exact same filename, therefore we have to add the session
Expand Down
2 changes: 1 addition & 1 deletion Controller/DropzoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function upload()

foreach ($files as $file) {
try {
$uploaded = $this->handleUpload($file, $response, $request);
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
$this->errorHandler->addException($response, $e);
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/FancyUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function upload()

foreach ($files as $file) {
try {
$uploaded = $this->handleUpload($file, $response, $request);
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
$this->errorHandler->addException($response, $e);
}
Expand Down
3 changes: 0 additions & 3 deletions Controller/MooUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class MooUploadController extends AbstractChunkedController
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;

Expand Down
2 changes: 1 addition & 1 deletion Controller/UploadifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function upload()

foreach ($files as $file) {
try {
$uploaded = $this->handleUpload($file, $response, $request);
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
$this->errorHandler->addException($response, $e);
}
Expand Down
2 changes: 1 addition & 1 deletion Controller/YUI3Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function upload()

foreach ($files as $file) {
try {
$uploaded = $this->handleUpload($file, $response, $request);
$this->handleUpload($file, $response, $request);
} catch (UploadException $e) {
$this->errorHandler->addException($response, $e);
}
Expand Down
23 changes: 15 additions & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ public function getConfigTreeBuilder()
->addDefaultsIfNotSet()
->children()
->scalarNode('maxage')->defaultValue(604800)->end()
->scalarNode('directory')->defaultNull()->end()
->arrayNode('storage')
->addDefaultsIfNotSet()
->children()
->enumNode('type')
->values(array('filesystem', 'gaufrette'))
->defaultValue('filesystem')
->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
->scalarNode('stream_wrapper')->defaultNull()->end()
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->scalarNode('prefix')->defaultValue('chunks')->end()
->end()
->end()
->booleanNode('load_distribution')->defaultTrue()->end()
->end()
->end()
Expand All @@ -38,7 +51,6 @@ public function getConfigTreeBuilder()
->children()
->enumNode('frontend')
->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload', 'mooupload', 'plupload', 'dropzone', 'custom'))
->defaultValue('fineuploader')
->end()
->arrayNode('custom_frontend')
->addDefaultsIfNotSet()
Expand All @@ -57,15 +69,10 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('filesystem')->defaultNull()->end()
->scalarNode('directory')->defaultNull()->end()
->scalarNode('stream_wrapper')->defaultNull()->end()
->scalarNode('sync_buffer_size')->defaultValue('100K')->end()
->end()
->end()
->arrayNode('allowed_extensions')
->prototype('scalar')->end()
->end()
->arrayNode('disallowed_extensions')
->prototype('scalar')->end()
->end()
->arrayNode('allowed_mimetypes')
->prototype('scalar')->end()
->end()
Expand Down
Loading

0 comments on commit 0a5c5d1

Please sign in to comment.