Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Release 1.0 #57

Merged
merged 54 commits into from
Oct 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8a2fc86
Removed default value 'fineuploader' for frontend key in Configuration.
sheeep Oct 8, 2013
d64ade8
Removed a notice which was stating that there is a default value for …
sheeep Oct 8, 2013
73e39c5
Made request passing in ValidationEvent mandatory.
sheeep Oct 8, 2013
3cee34e
Fixed "unused code" labels in Scrutinizer report.
sheeep Oct 8, 2013
4b7e0aa
Added Next Steps section to frontend documentations.
sheeep Oct 8, 2013
ad5577f
gaufrette chunk storage
mitom Oct 9, 2013
130bef2
separated storages both in definition and configuration
mitom Oct 10, 2013
f795b14
moved the metadatasupporter check
mitom Oct 10, 2013
f1f84bc
better file size calculation for gaufrette files
mitom Oct 10, 2013
4769708
fix non-chunked uploads and improve extension handling
mitom Oct 10, 2013
39c94c5
fixed messy type hinting for more comprehensible structure
mitom Oct 10, 2013
fc1bd5e
made scrutiziner happier
mitom Oct 10, 2013
bd400e8
broke configuration up even more fro scrutinizer
mitom Oct 10, 2013
85dd84a
had to lower interface requirements for the controllers
mitom Oct 10, 2013
7884373
fixed existing tests and some mistakes revealed by them
mitom Oct 10, 2013
c5a87ee
don't test for sf2.1
mitom Oct 10, 2013
db91777
Update configuration_reference.md
mitom Oct 11, 2013
4798b10
Update chunked_uploads.md
mitom Oct 11, 2013
a47326e
Update gaufrette_storage.md
mitom Oct 11, 2013
7bb3f2a
Update chunked_uploads.md
mitom Oct 11, 2013
160c9a1
Update custom_namer.md
mitom Oct 11, 2013
082f119
orphanage for gaufrette chunk storage
mitom Oct 11, 2013
948d850
Merge branch 'release-1.0' of https://github.com/mitom/OneupUploaderB…
mitom Oct 11, 2013
94d6d30
typo
mitom Oct 11, 2013
0223eea
Update orphanage.md
mitom Oct 11, 2013
155aca3
gaufrette orphanage fixes and tests
mitom Oct 11, 2013
71acfbe
added missing files
mitom Oct 11, 2013
98f2a90
fix for php5.3
mitom Oct 11, 2013
052148a
gaufette chunk storage test
mitom Oct 11, 2013
529b01c
file tests
mitom Oct 11, 2013
71d6118
another php5.3 fix
mitom Oct 11, 2013
48b19bc
Removed extension validators.
sheeep Oct 11, 2013
e7cb8dc
Fixed some typos in documentation.
sheeep Oct 11, 2013
207d2f1
Added a documentation topic: How to use Chunked Uploads behind Load B…
sheeep Oct 11, 2013
80ba434
Merge pull request #1 from sheeep/release-1.0
mitom Oct 11, 2013
50d14cc
Raised requirement of symfony/framework-bundle to >=2.2.
sheeep Oct 11, 2013
9a7ce28
Merge pull request #2 from sheeep/release-1.0
mitom Oct 11, 2013
47c9e32
remove file from gaufrette chunk storage after upload
mitom Oct 14, 2013
01e3347
avoid post-chunk upload events to fire with empty files
mitom Oct 14, 2013
e91f3a7
Marked some tests skipped if directories mismatch.
sheeep Oct 14, 2013
15a4590
Normalize stream wrapper path.
sheeep Oct 14, 2013
988082e
Extended documentation about chunked uploads and Gaufrette.
sheeep Oct 14, 2013
efaa424
Merge pull request #3 from sheeep/release-1.0
mitom Oct 14, 2013
5e789d8
made docs a bit nicer with a check
mitom Oct 14, 2013
147388f
Revert "made docs a bit nicer with a check"
mitom Oct 14, 2013
d0cdf7a
Merge branch 'release-1.0' of github.com:mitom/OneupUploaderBundle in…
sheeep Oct 14, 2013
341c880
Test against null to avoid object to boolean conversion.
sheeep Oct 14, 2013
0095863
fixed event firing check
mitom Oct 14, 2013
c9c64c9
Merge branch 'release-1.0' of github.com:mitom/OneupUploaderBundle in…
sheeep Oct 14, 2013
b17bee4
Fix configuration for storage service creation
Paulmolin Oct 15, 2013
bfc3e81
Merge pull request #63 from Paulmolin/release-1.0
Oct 15, 2013
996a784
Fixes scrutinizer-ci warnings.
sheeep Oct 23, 2013
d265291
Use 1.0 version of this bundle.
Oct 23, 2013
8e21e81
Added Upgrade Note about version 1.0.
Oct 23, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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