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
625ff285d43eeaf3ccac45dc4fae1bf7587b17f9
1up-lab
OneupUploaderBundle
Added missing methods to ChunkManager.
commit 625ff285d43eeaf3ccac45dc4fae1bf7587b17f9 Author: Jim Schmid <[email protected]> Date: Thu Mar 14 17:17:34 2013 +0100 Added missing methods to ChunkManager. diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php index 3e58f00..6d4b489 100644 --- a/Uploader/Chunk/ChunkManager.php +++ b/Uploader/Chunk/ChunkManager.php @@ -58,7 +58,7 @@ class ChunkManager implements ChunkManagerInterface $chunk->move($path, $name); } - public function assembleChunks($chunks) + public function assembleChunks(array $chunks) { // I don't really get it why getIterator()->current() always // gives me a null-value, due to that I've to implement this diff --git a/Uploader/Chunk/ChunkManagerInterface.php b/Uploader/Chunk/ChunkManagerInterface.php index 12574c9..4d0068d 100644 --- a/Uploader/Chunk/ChunkManagerInterface.php +++ b/Uploader/Chunk/ChunkManagerInterface.php @@ -2,8 +2,14 @@ namespace Oneup\UploaderBundle\Uploader\Chunk; +use Symfony\Component\HttpFoundation\File\UploadedFile; + interface ChunkManagerInterface { public function warmup(); public function clear(); + public function addChunk($uuid, $index, UploadedFile $chunk, $original); + public function assembleChunks(array $chunks); + public function cleanup($path); + public function getChunks($uuid); } \ No newline at end of file
0
786efca3939d9d38c78625e6e56cc047daf5e242
1up-lab
OneupUploaderBundle
Merge pull request #47 from 1up-lab/feature-dropzone-uploader Dropzone uploader
commit 786efca3939d9d38c78625e6e56cc047daf5e242 Merge: 44fbde3 f7b509f Author: Jim Schmid <[email protected]> Date: Wed Sep 18 03:42:15 2013 -0700 Merge pull request #47 from 1up-lab/feature-dropzone-uploader Dropzone uploader
0
f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be
1up-lab
OneupUploaderBundle
Changed the value string of the events. (BC-Break)
commit f5d5fe4b6f7b9a04ce633acbc9c94a2dd0e0d6be Author: Jim Schmid <[email protected]> Date: Sat Apr 13 12:34:19 2013 +0200 Changed the value string of the events. (BC-Break) diff --git a/Resources/doc/custom_logic.md b/Resources/doc/custom_logic.md index 84af61e..1163dee 100644 --- a/Resources/doc/custom_logic.md +++ b/Resources/doc/custom_logic.md @@ -33,7 +33,7 @@ And register it in your `services.xml`. <services> <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener"> <argument type="service" id="doctrine" /> - <tag name="kernel.event_listener" event="oneup.uploader.post.persist" method="onUpload" /> + <tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" /> </service> </services> ``` @@ -41,11 +41,12 @@ And register it in your `services.xml`. You can now implement you custom logic in the `onUpload` method of your EventListener. ## Use custom input data -FineUploader supports passing custom data through the request as the following examples states. For example you can pass the id of an entity you wish to paste the images to. +Many of the supported frontends support passing custom data through the request. Here's an example for [FineUploader](frontend_fineuploader.md) sending an id of an Entity along the normal request. ```html <script type="text/javascript"> -var uploader = new qq.FineUploader({ +var uploader = new qq.FineUploader( +{ element: document.getElementById('fine-uploader'), request: { endpoint: "{{ oneup_uploader_endpoint('gallery') }}", @@ -57,7 +58,7 @@ var uploader = new qq.FineUploader({ </script> ``` -As you can see, we extended the `request` part of the Fine Uploader by adding a `params` section. These variables are accessible through the request object in the EventHander. +As you can see, we extended the `request` part of the FineUploader by adding a `params` section. These variables are accessible through the request object in the EventHander. ```php public function onUpload(PostPersistEvent $event) diff --git a/UploadEvents.php b/UploadEvents.php index 6a9967b..34e287c 100644 --- a/UploadEvents.php +++ b/UploadEvents.php @@ -4,6 +4,6 @@ namespace Oneup\UploaderBundle; final class UploadEvents { - const POST_PERSIST = 'oneup.uploader.post.persist'; - const POST_UPLOAD = 'oneup.uploader.post.upload'; + const POST_PERSIST = 'oneup_uploader.post_persist'; + const POST_UPLOAD = 'oneup_uploader.post_upload'; } \ No newline at end of file
0
334a88dc634812fa36697255f7c0bebf9ce37c7e
1up-lab
OneupUploaderBundle
Change dropzone.js path in the example (#313)
commit 334a88dc634812fa36697255f7c0bebf9ce37c7e Author: Łukasz Chruściel <[email protected]> Date: Mon Jan 29 14:12:25 2018 +0100 Change dropzone.js path in the example (#313) diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md index 875fb3d..c6b2c64 100644 --- a/Resources/doc/frontend_dropzone.md +++ b/Resources/doc/frontend_dropzone.md @@ -4,7 +4,7 @@ Use Dropzone in your Symfony2 application Download [Dropzone](http://www.dropzonejs.com/) and include it in your template. Connect the `action` property of the form to the dynamic route `_uploader_{mapping_name}`. ```html -<script type="text/javascript" src="https://raw.github.com/enyo/dropzone/master/dist/dropzone.js"></script> +<script type="text/javascript" src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script> <form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black"> </form>
0
19ba4bf48b3a80581f242eda313149508599c2a5
1up-lab
OneupUploaderBundle
Add Symfony 6.0 support (#421) Co-authored-by: David Greminger <[email protected]>
commit 19ba4bf48b3a80581f242eda313149508599c2a5 Author: Michał Piszczek <[email protected]> Date: Mon Mar 21 14:26:11 2022 +0100 Add Symfony 6.0 support (#421) Co-authored-by: David Greminger <[email protected]> diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6002249..b04960f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,8 +36,12 @@ jobs: strategy: fail-fast: false matrix: - php: [7.2, 7.3, 7.4, 8.0] - symfony: [4.4, 5.0] + php: [7.4, 8.0] + symfony: [4.4, 5.4, 6.0] + exclude: + # Symfony 6.0 does not supports php <8.0 + - php: 7.4 + symfony: 6.0 steps: - name: Setup PHP uses: shivammathur/[email protected] @@ -63,7 +67,7 @@ jobs: - name: Setup PHP uses: shivammathur/[email protected] with: - php-version: 7.2 + php-version: 7.4 extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, pcre, pdo_mysql, zlib coverage: none diff --git a/composer.json b/composer.json index ef6d10f..000d258 100644 --- a/composer.json +++ b/composer.json @@ -32,16 +32,16 @@ } ], "require": { - "php": "^7.2.5 || ^8.0", - "symfony/asset": "^4.4 || ^5.0", - "symfony/event-dispatcher-contracts": "^1.0 || ^2.0", - "symfony/finder": "^4.4 || ^5.0", - "symfony/framework-bundle": "^4.4 || ^5.0", - "symfony/mime": "^4.4 || ^5.0", - "symfony/templating": "^4.4 || ^5.0", - "symfony/translation": "^4.4 || ^5.0", - "symfony/translation-contracts": "^1.0 || ^2.0", - "symfony/yaml": "^4.4 || ^5.0", + "php": "^7.4 || ^8.0", + "symfony/asset": "^4.4 || ^5.4 || ^6.0", + "symfony/event-dispatcher-contracts": "^1.0 || ^2.0 || ^3.0", + "symfony/finder": "^4.4 || ^5.4 || ^6.0", + "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/mime": "^4.4 || ^5.4 || ^6.0", + "symfony/templating": "^4.4 || ^5.4 || ^6.0", + "symfony/translation": "^4.4 || ^5.4 || ^6.0", + "symfony/translation-contracts": "^1.0 || ^2.0 || ^3.0", + "symfony/yaml": "^4.4 || ^5.4 || ^6.0", "twig/twig": "^2.4 || ^3.0" }, "require-dev": { @@ -52,12 +52,12 @@ "knplabs/gaufrette": "^0.9", "oneup/flysystem-bundle": "^1.2 || ^2.0 || ^3.0", "phpstan/phpstan": "^0.12.10", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": "^9.5", "sensio/framework-extra-bundle": "^5.0 || ^6.0", - "symfony/browser-kit": "^4.4 || ^5.0", - "symfony/phpunit-bridge": "^5.0", - "symfony/security-bundle": "^4.4 || ^5.0", - "symfony/var-dumper": "^4.4 || ^5.0", + "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", + "symfony/phpunit-bridge": "^5.4", + "symfony/security-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/var-dumper": "^4.4 || ^5.4 || ^6.0", "twistor/flysystem-stream-wrapper": "^1.0" }, "suggest": { diff --git a/tests/App/Kernel.php b/tests/App/Kernel.php index 3b72826..1a15234 100644 --- a/tests/App/Kernel.php +++ b/tests/App/Kernel.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel; class Kernel extends BaseKernel { - public function registerBundles() + public function registerBundles(): iterable { $bundles = [ new FrameworkBundle(), @@ -30,7 +30,7 @@ class Kernel extends BaseKernel $loader->load($this->getProjectDir() . '/config/config.yml'); } - public function getProjectDir() + public function getProjectDir(): string { return __DIR__; } diff --git a/tests/App/config/config.yml b/tests/App/config/config.yml index ac4945d..3eda25a 100644 --- a/tests/App/config/config.yml +++ b/tests/App/config/config.yml @@ -10,7 +10,6 @@ framework: # engines: ['php'] default_locale: en session: - storage_id: session.storage.native handler_id: ~ test: true @@ -21,8 +20,6 @@ security: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false - main: - anonymous: ~ oneup_uploader: mappings: diff --git a/tests/Controller/AbstractControllerTest.php b/tests/Controller/AbstractControllerTest.php index 0748c6b..6a56de1 100644 --- a/tests/Controller/AbstractControllerTest.php +++ b/tests/Controller/AbstractControllerTest.php @@ -41,6 +41,8 @@ abstract class AbstractControllerTest extends WebTestCase protected function setUp(): void { + self::ensureKernelShutdown(); + $this->client = static::createClient(['debug' => false]); $this->client->catchExceptions(false); $this->client->disableReboot(); @@ -49,12 +51,13 @@ abstract class AbstractControllerTest extends WebTestCase $container = $this->client->getContainer(); /** @var UploaderHelper $helper */ - $helper = self::$container->get('oneup_uploader.templating.uploader_helper'); + $helper = $container->get('oneup_uploader.templating.uploader_helper'); /** @var RouterInterface $router */ - $router = self::$container->get('router'); + $router = $container->get('router'); self::$container = $container; + $this->helper = $helper; $this->createdFiles = []; $this->requestHeaders = [ diff --git a/tests/Templating/TemplateHelperTest.php b/tests/Templating/TemplateHelperTest.php index 72d2ffb..a0abf71 100644 --- a/tests/Templating/TemplateHelperTest.php +++ b/tests/Templating/TemplateHelperTest.php @@ -12,6 +12,8 @@ class TemplateHelperTest extends WebTestCase { public function testName(): void { + self::ensureKernelShutdown(); + /** @var KernelBrowser $client */ $client = static::createClient(); @@ -28,6 +30,8 @@ class TemplateHelperTest extends WebTestCase { $this->expectException('\InvalidArgumentException'); + self::ensureKernelShutdown(); + /** @var KernelBrowser $client */ $client = static::createClient(); diff --git a/tests/Uploader/Naming/UniqidNamerTest.php b/tests/Uploader/Naming/UniqidNamerTest.php index 2b027a4..047b812 100644 --- a/tests/Uploader/Naming/UniqidNamerTest.php +++ b/tests/Uploader/Naming/UniqidNamerTest.php @@ -13,7 +13,6 @@ class UniqidNamerTest extends TestCase { public function testNamerReturnsName(): void { - /** @var FilesystemFile&MockObject $file */ $file = $this->createMock(FilesystemFile::class); $file @@ -22,7 +21,7 @@ class UniqidNamerTest extends TestCase ; $namer = new UniqidNamer(); - $this->assertRegExp('/[a-z0-9]{13}.jpeg/', $namer->name($file)); + $this->assertMatchesRegularExpression('/[a-z0-9]{13}.jpeg/', $namer->name($file)); } public function testNamerReturnsUniqueName(): void diff --git a/tests/Uploader/Orphanage/OrphanageManagerTest.php b/tests/Uploader/Orphanage/OrphanageManagerTest.php index e75977a..c2685d9 100644 --- a/tests/Uploader/Orphanage/OrphanageManagerTest.php +++ b/tests/Uploader/Orphanage/OrphanageManagerTest.php @@ -65,7 +65,7 @@ class OrphanageManagerTest extends TestCase $manager = new OrphanageManager($this->mockContainer, $this->mockConfig); $service = $manager->get('grumpycat'); - $this->assertTrue($service); + $this->assertInstanceOf(\stdClass::class, $service); } public function testClearAllInPast(): void @@ -119,12 +119,12 @@ class OrphanageManagerTest extends TestCase protected function getContainerMock() { /** @var MockObject&ContainerInterface $mock */ - $mock = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $mock = $this->createMock(ContainerInterface::class); $mock ->expects($this->any()) ->method('get') ->with('oneup_uploader.orphanage.grumpycat') - ->willReturn(true) + ->willReturn(new \stdClass()) ; return $mock;
0
a658021322e2ed9360f63a4e219d48551c444a21
1up-lab
OneupUploaderBundle
Fix typo
commit a658021322e2ed9360f63a4e219d48551c444a21 Author: David Greminger <[email protected]> Date: Wed Jul 20 14:22:01 2022 +0200 Fix typo diff --git a/README.md b/README.md index daa56ae..c59bc59 100644 --- a/README.md +++ b/README.md @@ -34,7 +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 **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)).
0
c07642908590218c4a01b4fea7d325beb11cbc48
1up-lab
OneupUploaderBundle
Something has fallen through the net.
commit c07642908590218c4a01b4fea7d325beb11cbc48 Author: Jim Schmid <[email protected]> Date: Mon Jul 15 12:26:22 2013 +0200 Something has fallen through the net. diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php index fb5cc27..e9b1c30 100644 --- a/Uploader/Response/AbstractResponse.php +++ b/Uploader/Response/AbstractResponse.php @@ -58,6 +58,6 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface $element =& $element[$offset]; } } - $element = $value; + $element[] = $value; } }
0
6287770f9450be2662739bdc360ff910cdff8126
1up-lab
OneupUploaderBundle
Fix link
commit 6287770f9450be2662739bdc360ff910cdff8126 Author: David Greminger <[email protected]> Date: Thu May 14 13:44:46 2020 +0200 Fix link diff --git a/README.md b/README.md index 8ef49c0..b717f2b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ OneupUploaderBundle =================== -![CI](https://github.com/1up-lab/OneupUploaderBundle/workflows/CI/badge.svg) +[![CI](https://github.com/1up-lab/OneupUploaderBundle/workflows/CI/badge.svg)](https://github.com/1up-lab/OneupUploaderBundle/actions) [![Total Downloads](https://poser.pugx.org/oneup/uploader-bundle/d/total.png)](https://packagist.org/packages/oneup/uploader-bundle) The OneupUploaderBundle for Symfony adds support for handling file uploads using one of the following JavaScript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md).
0
210707fefc9f9fe9d14e5aefe361ad7e6c346ef7
1up-lab
OneupUploaderBundle
Merge branch 'lsv-xml-to-yml' into release-1.4.0
commit 210707fefc9f9fe9d14e5aefe361ad7e6c346ef7 Merge: 5962166 91b5ecc Author: David Greminger <[email protected]> Date: Mon Jan 4 10:08:50 2016 +0100 Merge branch 'lsv-xml-to-yml' into release-1.4.0
0
5ec3508c5a8ddcbd9a4d96b77e5b415a15599806
1up-lab
OneupUploaderBundle
Merge pull request #268 from bronek89/master Remove metric suffix from input before multiplication (PHP 7.1 notice)
commit 5ec3508c5a8ddcbd9a4d96b77e5b415a15599806 Merge: a8c1e53 cb9e36c Author: David Greminger <[email protected]> Date: Sat Oct 8 16:29:52 2016 +0200 Merge pull request #268 from bronek89/master Remove metric suffix from input before multiplication (PHP 7.1 notice)
0
2397664cf1ce3fd87fde6628713193eb32f2de3f
1up-lab
OneupUploaderBundle
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
commit 2397664cf1ce3fd87fde6628713193eb32f2de3f Merge: c0d9cce b1973d8 Author: Jim Schmid <[email protected]> Date: Tue Aug 13 13:07:45 2013 +0200 Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
0
fc9d5c10e27136dad7865807c584db6471cfb658
1up-lab
OneupUploaderBundle
Fix PHP 7.1 Notice: A non well formed numeric value Notice: A non well formed numeric value encountered in /var/www/symfony/vendor/oneup/uploader-bundle/Oneup/UploaderBundle/DependencyInjection/OneupUploaderExtension.php on line 297
commit fc9d5c10e27136dad7865807c584db6471cfb658 Author: Martin Hlaváč <[email protected]> Date: Thu Dec 15 09:22:48 2016 +0100 Fix PHP 7.1 Notice: A non well formed numeric value Notice: A non well formed numeric value encountered in /var/www/symfony/vendor/oneup/uploader-bundle/Oneup/UploaderBundle/DependencyInjection/OneupUploaderExtension.php on line 297 diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 0d472ff..86fd9f6 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -292,7 +292,7 @@ class OneupUploaderExtension extends Extension protected function getValueInBytes($input) { // see: http://www.php.net/manual/en/function.ini-get.php - $input = trim($input); + $input = (float) trim($input); $last = strtolower($input[strlen($input) - 1]); $numericInput = substr($input, 0, -1);
0
b69175b94f3aff3dcc82cc9f9e228693434b6ef8
1up-lab
OneupUploaderBundle
Added tests for Dropzone uploader.
commit b69175b94f3aff3dcc82cc9f9e228693434b6ef8 Author: Jim Schmid <[email protected]> Date: Wed Sep 18 12:22:28 2013 +0200 Added tests for Dropzone uploader. diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 43d37c3..619cebc 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -43,6 +43,21 @@ oneup_uploader: allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] + dropzone: + frontend: dropzone + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + + dropzone_validation: + frontend: dropzone + max_size: 256 + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + allowed_extensions: [ "ok" ] + disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] + disallowed_mimetypes: [ "image/gif" ] + yui3: frontend: yui3 storage: diff --git a/Tests/Controller/DropzoneTest.php b/Tests/Controller/DropzoneTest.php new file mode 100644 index 0000000..a5aa7d0 --- /dev/null +++ b/Tests/Controller/DropzoneTest.php @@ -0,0 +1,29 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest; + +class DropzoneTest extends AbstractUploadTest +{ + protected function getConfigKey() + { + return 'dropzone'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getRequestFile() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.txt', + 'text/plain', + 128 + ); + } +} diff --git a/Tests/Controller/DropzoneValidationTest.php b/Tests/Controller/DropzoneValidationTest.php new file mode 100644 index 0000000..73cb5ff --- /dev/null +++ b/Tests/Controller/DropzoneValidationTest.php @@ -0,0 +1,69 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; + +class DropzoneValidationTest extends AbstractValidationTest +{ + protected function getConfigKey() + { + return 'dropzone_validation'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getOversizedFile() + { + return new UploadedFile( + $this->createTempFile(512), + 'cat.ok', + 'text/plain', + 512 + ); + } + + protected function getFileWithCorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'text/plain', + 128 + ); + } + + protected function getFileWithIncorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.fail', + 'text/plain', + 128 + ); + } + + protected function getFileWithCorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/jpg', + 128 + ); + } + + protected function getFileWithIncorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/gif', + 128 + ); + } +}
0
dfc20db7f208af02bb98f97eedb786c26b2a2117
1up-lab
OneupUploaderBundle
Initial directory structure and bundle initialization files.
commit dfc20db7f208af02bb98f97eedb786c26b2a2117 Author: Jim Schmid <[email protected]> Date: Fri Mar 8 17:48:52 2013 +0100 Initial directory structure and bundle initialization files. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php new file mode 100644 index 0000000..2c20ba1 --- /dev/null +++ b/DependencyInjection/Configuration.php @@ -0,0 +1,17 @@ +<?php + +namespace Oneup\UploaderBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +class Configuration implements ConfigurationInterface +{ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('oneup_uploader'); + + return $treeBuilder; + } +} \ No newline at end of file diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php new file mode 100644 index 0000000..3a77172 --- /dev/null +++ b/DependencyInjection/OneupUploaderExtension.php @@ -0,0 +1,20 @@ +<?php + +namespace Oneup\UploaderBundle\DependencyInjection; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader; + +class OneupUploaderExtension extends Extension +{ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $config = $this->processConfiguration($configuration, $configs); + + $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('uploader.xml'); + } +} \ No newline at end of file diff --git a/OneupUploaderBundle.php b/OneupUploaderBundle.php new file mode 100644 index 0000000..22c1af9 --- /dev/null +++ b/OneupUploaderBundle.php @@ -0,0 +1,9 @@ +<?php + +namespace Oneup\UploaderBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class OneupUploaderBundle extends Bundle +{ +} \ No newline at end of file diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml new file mode 100644 index 0000000..f32be1c --- /dev/null +++ b/Resources/config/uploader.xml @@ -0,0 +1,6 @@ +<?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"> + +</container> \ No newline at end of file
0
03d5a6fea4e2f20504e27fb50adc1c649bbaeac2
1up-lab
OneupUploaderBundle
Added notes for 1.3.x
commit 03d5a6fea4e2f20504e27fb50adc1c649bbaeac2 Author: David Greminger <[email protected]> Date: Mon Jan 4 11:58:06 2016 +0100 Added notes for 1.3.x diff --git a/Resources/doc/index.md b/Resources/doc/index.md index f5d2e21..5850164 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -1,11 +1,12 @@ Getting started =============== -The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.1+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself. +The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.4+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself. ## Prerequisites -This bundle is tested using Symfony2 versions 2.4+. +This bundle is tested using Symfony 2.4+. +If you want to use the bundle with Symfony 2.3, head over to the documentation for [1.3.x](https://github.com/1up-lab/OneupUploaderBundle/blob/release-1.3.x/Resources/doc/index.md). ### Translations If you wish to use the default texts provided with this bundle, you have to make sure that you have translator
0
9f7f3fbe988d3df5e0f6fc68b82b34cf1445a406
1up-lab
OneupUploaderBundle
Expose configuration of this bundle via container parameters. This can be useful to extend file upload/deletion logic, for an example head to #96. Close #96.
commit 9f7f3fbe988d3df5e0f6fc68b82b34cf1445a406 Author: Jim Schmid <[email protected]> Date: Wed Mar 26 12:00:10 2014 +0100 Expose configuration of this bundle via container parameters. This can be useful to extend file upload/deletion logic, for an example head to #96. Close #96. diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 480d8ec..34e707d 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -45,8 +45,11 @@ class OneupUploaderExtension extends Extension foreach ($this->config['mappings'] as $key => $mapping) { $controllers[$key] = $this->processMapping($key, $mapping); $maxsize[$key] = $this->getMaxUploadSize($mapping['max_size']); + + $container->setParameter(sprintf('oneup_uploader.config.%s', $key), $mapping); } + $container->setParameter('oneup_uploader.config', $this->config); $container->setParameter('oneup_uploader.controllers', $controllers); $container->setParameter('oneup_uploader.maxsize', $maxsize); }
0
d4355f62565163f25e4637860a431ce5e721f898
1up-lab
OneupUploaderBundle
Added doc blocks for StorageInterface.
commit d4355f62565163f25e4637860a431ce5e721f898 Author: Jim Schmid <[email protected]> Date: Tue Aug 13 16:03:50 2013 +0200 Added doc blocks for StorageInterface. diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php index 090db1a..79fb3ae 100644 --- a/Uploader/Storage/StorageInterface.php +++ b/Uploader/Storage/StorageInterface.php @@ -6,5 +6,12 @@ use Symfony\Component\HttpFoundation\File\File; interface StorageInterface { + /** + * Uploads a File instance to the configured storage. + * + * @param File $file + * @param string $name + * @param string $path + */ public function upload(File $file, $name, $path = null); }
0
06f3d9906381bccadf8cc06081632eeb51788cf8
1up-lab
OneupUploaderBundle
Documentation updates
commit 06f3d9906381bccadf8cc06081632eeb51788cf8 Author: David Greminger <[email protected]> Date: Fri Dec 1 17:00:18 2017 +0100 Documentation updates diff --git a/README.md b/README.md index 377fb9d..c76f765 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- +* Version **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 **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). diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 2e5f82e..bc3858f 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -5,11 +5,14 @@ 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 3.3+. **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). +**With Symfony 2.4.x - 2.8.x** +If you want to use the bundle with Symfony 2.4.x - 2.8.x, head over to the documentation for [1.9.x](https://github.com/1up-lab/OneupUploaderBundle/blob/release/1.9.x/Resources/doc/index.md). + ### Translations If you wish to use the default texts provided with this bundle, you have to make sure that you have translator enabled in your configuration file.
0
8c884df291a903202824f60e19971fe86dbd11b2
1up-lab
OneupUploaderBundle
Added a ResponseInterface because every frontend has to use its own.
commit 8c884df291a903202824f60e19971fe86dbd11b2 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 21:44:53 2013 +0200 Added a ResponseInterface because every frontend has to use its own. diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php index 9c9cf30..cc02d77 100644 --- a/Controller/BlueimpController.php +++ b/Controller/BlueimpController.php @@ -31,6 +31,75 @@ class BlueimpController implements UploadControllerInterface public function upload() { + $request = $this->container->get('request'); + $dispatcher = $this->container->get('event_dispatcher'); + $translator = $this->container->get('translator'); + + $response = new UploaderResponse(); + $files = $request->files; + + foreach($files as $file) + { + $file = $file[0]; + + try + { + $uploaded = $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); + } + } + catch(UploadException $e) + { + $response->setSuccess(false); + $response->setError($translator->trans($e->getMessage(), array(), 'OneupUploaderBundle')); + + // an error happended, return this error message. + return new JsonResponse(array()); + } + } + + return new JsonResponse(array('files' => array())); + } + + 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 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'); } } \ No newline at end of file diff --git a/Controller/FineUploaderController.php b/Controller/FineUploaderController.php index 35996c0..178378e 100644 --- a/Controller/FineUploaderController.php +++ b/Controller/FineUploaderController.php @@ -12,7 +12,7 @@ use Oneup\UploaderBundle\Event\PostPersistEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; -use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; +use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse; class FineUploaderController implements UploadControllerInterface { @@ -35,7 +35,7 @@ class FineUploaderController implements UploadControllerInterface $dispatcher = $this->container->get('event_dispatcher'); $translator = $this->container->get('translator'); - $response = new UploaderResponse(); + $response = new FineUploaderResponse(); $totalParts = $request->get('qqtotalparts', 1); $files = $request->files; $chunked = $totalParts > 1; diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php index 6fed87f..a25dc19 100644 --- a/Event/PostPersistEvent.php +++ b/Event/PostPersistEvent.php @@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Event; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpFoundation\Request; -use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; +use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; class PostPersistEvent extends Event { @@ -14,7 +14,7 @@ class PostPersistEvent extends Event protected $response; protected $config; - public function __construct($file, UploaderResponse $response, Request $request, $type, array $config) + public function __construct($file, ResponseInterface $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php index 9dfd6ce..872a131 100644 --- a/Event/PostUploadEvent.php +++ b/Event/PostUploadEvent.php @@ -4,7 +4,7 @@ namespace Oneup\UploaderBundle\Event; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpFoundation\Request; -use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; +use Oneup\UploaderBundle\Uploader\Response\ResponseInterface; class PostUploadEvent extends Event { @@ -14,7 +14,7 @@ class PostUploadEvent extends Event protected $response; protected $config; - public function __construct($file, UploaderResponse $response, Request $request, $type, array $config) + public function __construct($file, ResponseInterface $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; diff --git a/Uploader/Response/ResponseInterface.php b/Uploader/Response/ResponseInterface.php new file mode 100644 index 0000000..b1e835e --- /dev/null +++ b/Uploader/Response/ResponseInterface.php @@ -0,0 +1,8 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Response; + +interface ResponseInterface extends \ArrayAccess +{ + public function assemble(); +} \ No newline at end of file diff --git a/Uploader/Response/UploaderResponse.php b/Uploader/Response/UploaderResponse.php deleted file mode 100644 index 090df34..0000000 --- a/Uploader/Response/UploaderResponse.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Oneup\UploaderBundle\Uploader\Response; - -class UploaderResponse implements \ArrayAccess -{ - protected $success; - protected $error; - protected $data; - - public function __construct() - { - $this->success = true; - $this->error = null; - $this->data = array(); - } - - public function assemble() - { - // explicitly overwrite success and error key - // as these keys are used internaly by the - // frontend uploader - $data = $this->data; - $data['success'] = $this->success; - - if($this->success) - unset($data['error']); - - if(!$this->success) - $data['error'] = $this->error; - - return $data; - } - - public function offsetSet($offset, $value) - { - is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value; - } - public function offsetExists($offset) - { - return isset($this->data[$offset]); - } - public function offsetUnset($offset) - { - unset($this->data[$offset]); - } - - public function offsetGet($offset) - { - return isset($this->data[$offset]) ? $this->data[$offset] : null; - } - - public function setSuccess($success) - { - $this->success = (bool) $success; - - return $this; - } - - public function getSuccess() - { - return $this->success; - } - - public function setError($msg) - { - $this->error = $msg; - - return $this; - } - - public function getError() - { - return $this->error; - } -} \ No newline at end of file
0
baac8e0db1250efaab681237e1f9cc48269e7270
1up-lab
OneupUploaderBundle
personalize upload path
commit baac8e0db1250efaab681237e1f9cc48269e7270 Author: MEDIA.figaro <[email protected]> Date: Wed Jun 22 18:03:44 2016 +0200 personalize upload path diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 0c18f92..5af1774 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -92,6 +92,19 @@ oneup_uploader: > It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. > You can improve the directory structure checking the "[Change the directory structure](custom_namer.md#change-the-directory-structure)". +If you want to use your own path, for example /data/uploads : + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + frontend: dropzone + storage: + directory: "%kernel.root_dir%/../data/uploads/" +``` + ### Step 4: Prepare your frontend No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows:
0
7727ba12af35030d1ac8c54caa6d0264829c0da1
1up-lab
OneupUploaderBundle
Changed tests according to new class names.
commit 7727ba12af35030d1ac8c54caa6d0264829c0da1 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 21:01:59 2013 +0200 Changed tests according to new class names. diff --git a/Tests/Controller/UploaderControllerChunkedTest.php b/Tests/Controller/FineUploaderControllerChunkedTest.php similarity index 95% rename from Tests/Controller/UploaderControllerChunkedTest.php rename to Tests/Controller/FineUploaderControllerChunkedTest.php index 1291823..f82f41b 100644 --- a/Tests/Controller/UploaderControllerChunkedTest.php +++ b/Tests/Controller/FineUploaderControllerChunkedTest.php @@ -9,9 +9,9 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager; use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer; use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage; -use Oneup\UploaderBundle\Controller\UploaderController; +use Oneup\UploaderBundle\Controller\FineUploaderController; -class UploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase +class FineUploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase { protected $tempChunks; protected $currentChunk; @@ -52,7 +52,7 @@ class UploaderControllerChunkedTest extends \PHPUnit_Framework_TestCase ); $responses = array(); - $controller = new UploaderController($container, $storage, $config, 'cat'); + $controller = new FineUploaderController($container, $storage, $config, 'cat'); // mock as much requests as there are parts to assemble for($i = 0; $i < $this->numberOfChunks; $i ++) diff --git a/Tests/Controller/UploaderControllerTest.php b/Tests/Controller/FineUploaderControllerTest.php similarity index 93% rename from Tests/Controller/UploaderControllerTest.php rename to Tests/Controller/FineUploaderControllerTest.php index e9bd236..84f0db4 100644 --- a/Tests/Controller/UploaderControllerTest.php +++ b/Tests/Controller/FineUploaderControllerTest.php @@ -8,9 +8,9 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer; use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage; -use Oneup\UploaderBundle\Controller\UploaderController; +use Oneup\UploaderBundle\Controller\FineUploaderController; -class UploaderControllerTest extends \PHPUnit_Framework_TestCase +class FineUploaderControllerTest extends \PHPUnit_Framework_TestCase { protected $tempFile; @@ -36,7 +36,7 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase 'disallowed_extensions' => array() ); - $controller = new UploaderController($container, $storage, $config, 'cat'); + $controller = new FineUploaderController($container, $storage, $config, 'cat'); $response = $controller->upload(); // check if original file has been moved @@ -65,7 +65,7 @@ class UploaderControllerTest extends \PHPUnit_Framework_TestCase 'disallowed_extensions' => array() ); - $controller = new UploaderController($container, $storage, $config, 'cat'); + $controller = new FineUploaderController($container, $storage, $config, 'cat'); $response = $controller->upload(); $json = json_decode($response->getContent()); diff --git a/Tests/Controller/UploaderControllerValidationTest.php b/Tests/Controller/FineUploaderControllerValidationTest.php similarity index 93% rename from Tests/Controller/UploaderControllerValidationTest.php rename to Tests/Controller/FineUploaderControllerValidationTest.php index 2e06720..f38e951 100644 --- a/Tests/Controller/UploaderControllerValidationTest.php +++ b/Tests/Controller/FineUploaderControllerValidationTest.php @@ -2,9 +2,9 @@ namespace Oneup\UploaderBundle\Tests\Controller; -use Oneup\UploaderBundle\Controller\UploaderController; +use Oneup\UploaderBundle\Controller\FineUploaderController; -class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase +class FineUploaderControllerValidationTest extends \PHPUnit_Framework_TestCase { /** * @expectedException Symfony\Component\HttpFoundation\File\Exception\UploadException @@ -90,7 +90,7 @@ class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase $container = $this->getContainerMock(); $storage = $this->getStorageMock(); - $controller = new UploaderController($container, $storage, $config, 'cat'); + $controller = new FineUploaderController($container, $storage, $config, 'cat'); $method->invoke($controller, $file); // yey, no exception thrown @@ -132,7 +132,7 @@ class UploaderControllerValidationTest extends \PHPUnit_Framework_TestCase protected function getValidationMethod() { // create a public version of the validate method - $class = new \ReflectionClass('Oneup\\UploaderBundle\\Controller\\UploaderController'); + $class = new \ReflectionClass('Oneup\\UploaderBundle\\Controller\\FineUploaderController'); $method = $class->getMethod('validate'); $method->setAccessible(true);
0
1f6fa09ab087d125bbb62204d0ccc00da5369f5d
1up-lab
OneupUploaderBundle
Merge pull request #286 from Lctrs/composer-constraints Allow versions >=2.0 of paragonie/random_compat
commit 1f6fa09ab087d125bbb62204d0ccc00da5369f5d Merge: bdef0e2 79faf20 Author: David Greminger <[email protected]> Date: Mon Sep 18 15:31:47 2017 +0200 Merge pull request #286 from Lctrs/composer-constraints Allow versions >=2.0 of paragonie/random_compat
0
a23bcbf0b9583cadbed778e3b57761d68a1b22b9
1up-lab
OneupUploaderBundle
addToOffset is now using arrays instead of variable argument list.
commit a23bcbf0b9583cadbed778e3b57761d68a1b22b9 Author: Jim Schmid <[email protected]> Date: Mon Jul 15 11:17:01 2013 +0200 addToOffset is now using arrays instead of variable argument list. diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php index 299dae1..d9adf89 100644 --- a/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -16,6 +16,6 @@ class BlueimpErrorHandler implements ErrorHandlerInterface $message = $exception->getMessage(); } - $response->addToOffset(array('error' => $message), 'files'); + $response->addToOffset(array('error' => $message), array('files')); } } diff --git a/Uploader/Response/AbstractResponse.php b/Uploader/Response/AbstractResponse.php index 3745f62..fb5cc27 100644 --- a/Uploader/Response/AbstractResponse.php +++ b/Uploader/Response/AbstractResponse.php @@ -38,29 +38,26 @@ abstract class AbstractResponse implements \ArrayAccess, ResponseInterface * This function will take a path of arrays and add a new element to it, creating the path if needed. * * @param mixed $value - * @param mixed $offset,... + * @param array $offsets + * + * @throws \InvalidArgumentException if the path contains non-array items. * - * @throws \InvalidArgumentException if the path contains non-array or unset items. */ - public function addToOffset($value, $offset) + public function addToOffset($value, array $offsets) { - $args = func_get_args(); - array_shift($args); - $element =& $this->data; - - foreach ($args as $offset) { + foreach ($offsets as $offset) { if (isset($element[$offset])) { if (is_array($element[$offset])) { $element =& $element[$offset]; } else { - throw new \InvalidArgumentException('The specified offset is set but is not an array at ' . $offset); + throw new \InvalidArgumentException("The specified offset is set but is not an array at" . $offset); } } else { $element[$offset] = array(); $element =& $element[$offset]; } } - $element[] = $value; + $element = $value; } }
0
bf10b7b1a6a831cc5eabe4a84b68378482cf9f5e
1up-lab
OneupUploaderBundle
enable dropzone chunked upload
commit bf10b7b1a6a831cc5eabe4a84b68378482cf9f5e Author: Thomas Piard <[email protected]> Date: Tue Nov 21 15:18:09 2017 +0100 enable dropzone chunked upload diff --git a/Controller/DropzoneController.php b/Controller/DropzoneController.php index b4fdc99..feab508 100644 --- a/Controller/DropzoneController.php +++ b/Controller/DropzoneController.php @@ -2,11 +2,12 @@ namespace Oneup\UploaderBundle\Controller; -use Symfony\Component\HttpFoundation\File\Exception\UploadException; - use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\File\Exception\UploadException; -class DropzoneController extends AbstractController +class DropzoneController extends AbstractChunkedController { public function upload() { @@ -14,9 +15,15 @@ class DropzoneController extends AbstractController $response = new EmptyResponse(); $files = $this->getFiles($request->files); $statusCode = 200; + + $chunked = !is_null($request->request->get('dzchunkindex')); + foreach ($files as $file) { try { - $this->handleUpload($file, $response, $request); + $chunked ? + $this->handleChunkedUpload($file, $response, $request) : + $this->handleUpload($file, $response, $request) + ; } catch (UploadException $e) { $statusCode = 500; //Dropzone displays error if HTTP response is 40x or 50x $this->errorHandler->addException($response, $e); @@ -24,10 +31,26 @@ class DropzoneController extends AbstractController $message = $translator->trans($e->getMessage(), array(), 'OneupUploaderBundle'); $response = $this->createSupportedJsonResponse(array('error'=>$message )); $response->setStatusCode(400); - return $response; + return $response; } } return $this->createSupportedJsonResponse($response->assemble(), $statusCode); } + + protected function parseChunkedRequest(Request $request) + { + $totalChunkCount = $request->get('dztotalchunkcount'); + $index = $request->get('dzchunkindex'); + $last = ($index + 1) === (int) $totalChunkCount; + $uuid = $request->get('dzuuid'); + + /** + * @var UploadedFile $file + */ + $file = $request->files->get('file')->getClientOriginalName(); + $orig = $file; + + return [$last, $uuid, $index, $orig]; + } }
0
dc7a0e41b92a256a61627385ac7e621f819a383c
1up-lab
OneupUploaderBundle
Merge branch 'mhlavac-patch-1'
commit dc7a0e41b92a256a61627385ac7e621f819a383c Merge: 5ec3508 fc9d5c1 Author: David Greminger <[email protected]> Date: Thu Dec 15 09:28:57 2016 +0100 Merge branch 'mhlavac-patch-1'
0
0abd7065d1e36193147ba5cbaf53f3e5576389ae
1up-lab
OneupUploaderBundle
Update custom_validator.md Cc https://github.com/1up-lab/OneupUploaderBundle/pull/211
commit 0abd7065d1e36193147ba5cbaf53f3e5576389ae Author: Jim Schmid <[email protected]> Date: Mon Feb 8 08:48:06 2016 +0100 Update custom_validator.md Cc https://github.com/1up-lab/OneupUploaderBundle/pull/211 diff --git a/Resources/doc/custom_validator.md b/Resources/doc/custom_validator.md index 2d5b5f0..1a4d77d 100644 --- a/Resources/doc/custom_validator.md +++ b/Resources/doc/custom_validator.md @@ -53,3 +53,5 @@ services: tags: - { name: kernel.event_listener, event: oneup_uploader.validation, method: onValidate } ``` + +Since version 1.6 you can listen to an event thrown for every uploader specifically. The name for the event is `oneup_uploader.validation.{type}` where `{type}` represents the config key of the uploader you want to target.
0
c965c77eb68b7146ccd274d30a2e2fabf07a394e
1up-lab
OneupUploaderBundle
Register POST_DELETE Event (whops) and dispatch the correct one.
commit c965c77eb68b7146ccd274d30a2e2fabf07a394e Author: Jim Schmid <[email protected]> Date: Thu Mar 14 20:16:20 2013 +0100 Register POST_DELETE Event (whops) and dispatch the correct one. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index ddd87ea..0d103a5 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -13,6 +13,7 @@ use Symfony\Component\Finder\Finder; use Oneup\UploaderBundle\UploadEvents; use Oneup\UploaderBundle\Event\PostPersistEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; +use Oneup\UploaderBundle\Event\PostDeleteEvent; use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; @@ -72,10 +73,10 @@ class UploaderController implements UploadControllerInterface if($result) { - $postUploadEvent = new PostUploadEvent($this->request, $uuid, $this->type); - $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); + $postUploadEvent = new PostDeleteEvent($this->request, $uuid, $this->type); + $this->dispatcher->dispatch(UploadEvents::POST_DELETE, $postUploadEvent); - return new JsonResponse(array('success' => true)): + return new JsonResponse(array('success' => true)); } return new JsonResponse(array('error' => 'An unknown error occured.')); diff --git a/UploadEvents.php b/UploadEvents.php index 6a9967b..f272c9d 100644 --- a/UploadEvents.php +++ b/UploadEvents.php @@ -6,4 +6,5 @@ final class UploadEvents { const POST_PERSIST = 'oneup.uploader.post.persist'; const POST_UPLOAD = 'oneup.uploader.post.upload'; + const POST_DELETE = 'oneup.uploader.post.delete'; } \ No newline at end of file
0
48b19bc18fb944fe8b05a70173bff94074b8f83b
1up-lab
OneupUploaderBundle
Removed extension validators.
commit 48b19bc18fb944fe8b05a70173bff94074b8f83b Author: Jim Schmid <[email protected]> Date: Fri Oct 11 18:15:47 2013 +0200 Removed extension validators. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 97b1eef..3ebfbec 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -59,12 +59,6 @@ class Configuration implements ConfigurationInterface ->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() diff --git a/EventListener/AllowedExtensionValidationListener.php b/EventListener/AllowedExtensionValidationListener.php deleted file mode 100644 index 68c26e8..0000000 --- a/EventListener/AllowedExtensionValidationListener.php +++ /dev/null @@ -1,21 +0,0 @@ -<?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'); - } - } -} diff --git a/EventListener/DisallowedExtensionValidationListener.php b/EventListener/DisallowedExtensionValidationListener.php deleted file mode 100644 index 9cdac58..0000000 --- a/EventListener/DisallowedExtensionValidationListener.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -namespace Oneup\UploaderBundle\EventListener; - -use Oneup\UploaderBundle\Event\ValidationEvent; -use Oneup\UploaderBundle\Uploader\Exception\ValidationException; - -class DisallowedExtensionValidationListener -{ - public function onValidate(ValidationEvent $event) - { - $config = $event->getConfig(); - $file = $event->getFile(); - - $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION); - - if (count($config['disallowed_extensions']) > 0 && in_array($extension, $config['disallowed_extensions'])) { - throw new ValidationException('error.blacklist'); - } - } -} diff --git a/Resources/config/validators.xml b/Resources/config/validators.xml index 5b2ffe0..4c3fc73 100644 --- a/Resources/config/validators.xml +++ b/Resources/config/validators.xml @@ -8,14 +8,6 @@ <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> - - <service id="oneup_uploader.validation_listener.disallowed_extension" class="Oneup\UploaderBundle\EventListener\DisallowedExtensionValidationListener"> - <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> - </service> - <service id="oneup_uploader.validation_listener.allowed_mimetype" class="Oneup\UploaderBundle\EventListener\AllowedMimetypeValidationListener"> <tag name="kernel.event_listener" event="oneup_uploader.validation" method="onValidate" /> </service> diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index b75fee4..07c420b 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -27,8 +27,6 @@ oneup_uploader: filesystem: ~ directory: ~ sync_buffer_size: 100K - allowed_extensions: [] - disallowed_extensions: [] allowed_mimetypes: [] disallowed_mimetypes: [] error_handler: oneup_uploader.error_handler.noop diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 619cebc..a350ddb 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -23,8 +23,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -38,8 +37,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -53,8 +51,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -68,8 +65,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -83,8 +79,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -98,8 +93,7 @@ oneup_uploader: max_size: 256 storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] @@ -115,8 +109,7 @@ oneup_uploader: storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload error_handler: oneup_uploader.error_handler.blueimp - allowed_extensions: [ "ok" ] - disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] disallowed_mimetypes: [ "image/gif" ] diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php index 01b0a6d..8b56bfb 100644 --- a/Tests/Controller/AbstractValidationTest.php +++ b/Tests/Controller/AbstractValidationTest.php @@ -7,8 +7,6 @@ use Oneup\UploaderBundle\UploadEvents; abstract class AbstractValidationTest extends AbstractControllerTest { - abstract protected function getFileWithCorrectExtension(); - abstract protected function getFileWithIncorrectExtension(); abstract protected function getFileWithCorrectMimeType(); abstract protected function getFileWithIncorrectMimeType(); abstract protected function getOversizedFile(); @@ -27,26 +25,6 @@ abstract class AbstractValidationTest extends AbstractControllerTest $this->assertCount(0, $this->getUploadedFiles()); } - public function testAgainstCorrectExtension() - { - // assemble a request - $client = $this->client; - $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension())); - $response = $client->getResponse(); - - $this->assertTrue($response->isSuccessful()); - $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); - $this->assertCount(1, $this->getUploadedFiles()); - - foreach ($this->getUploadedFiles() as $file) { - $this->assertTrue($file->isFile()); - $this->assertTrue($file->isReadable()); - $this->assertEquals(128, $file->getSize()); - } - } - public function testEvents() { $client = $this->client; @@ -60,7 +38,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest ++ $validationCount; }); - $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension())); + $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectMimeType())); $this->assertEquals(1, $validationCount); } @@ -82,25 +60,11 @@ abstract class AbstractValidationTest extends AbstractControllerTest ++ $validationCount; }); - $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectExtension())); + $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithCorrectMimeType())); $this->assertEquals(1, $validationCount); } - public function testAgainstIncorrectExtension() - { - // assemble a request - $client = $this->client; - $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), array($this->getFileWithIncorrectExtension())); - $response = $client->getResponse(); - - //$this->assertTrue($response->isNotSuccessful()); - $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); - $this->assertCount(0, $this->getUploadedFiles()); - } - public function testAgainstCorrectMimeType() { // assemble a request diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index 4bbfa1c..c5b8af6 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -23,26 +23,6 @@ class BlueimpValidationTest extends AbstractValidationTest $this->assertCount(0, $this->getUploadedFiles()); } - public function testAgainstCorrectExtension() - { - // assemble a request - $client = $this->client; - $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension(), array('HTTP_ACCEPT' => 'application/json')); - $response = $client->getResponse(); - - $this->assertTrue($response->isSuccessful()); - $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); - $this->assertCount(1, $this->getUploadedFiles()); - - foreach ($this->getUploadedFiles() as $file) { - $this->assertTrue($file->isFile()); - $this->assertTrue($file->isReadable()); - $this->assertEquals(128, $file->getSize()); - } - } - public function testEvents() { $client = $this->client; @@ -56,25 +36,11 @@ class BlueimpValidationTest extends AbstractValidationTest ++ $validationCount; }); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType()); $this->assertEquals(1, $validationCount); } - public function testAgainstIncorrectExtension() - { - // assemble a request - $client = $this->client; - $endpoint = $this->helper->endpoint($this->getConfigKey()); - - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectExtension(), array('HTTP_ACCEPT' => 'application/json')); - $response = $client->getResponse(); - - //$this->assertTrue($response->isNotSuccessful()); - $this->assertEquals($response->headers->get('Content-Type'), 'application/json'); - $this->assertCount(0, $this->getUploadedFiles()); - } - public function testAgainstCorrectMimeType() { // assemble a request @@ -131,26 +97,6 @@ class BlueimpValidationTest extends AbstractValidationTest ))); } - protected function getFileWithCorrectExtension() - { - return array('files' => array(new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ))); - } - - protected function getFileWithIncorrectExtension() - { - return array('files' => array(new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ))); - } - protected function getFileWithCorrectMimeType() { return array('files' => array(new UploadedFile( diff --git a/Tests/Controller/DropzoneValidationTest.php b/Tests/Controller/DropzoneValidationTest.php index 73cb5ff..abe7f06 100644 --- a/Tests/Controller/DropzoneValidationTest.php +++ b/Tests/Controller/DropzoneValidationTest.php @@ -27,26 +27,6 @@ class DropzoneValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile( diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php index 7e48964..1f78228 100644 --- a/Tests/Controller/FancyUploadValidationTest.php +++ b/Tests/Controller/FancyUploadValidationTest.php @@ -27,26 +27,6 @@ class FancyUploadValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile( diff --git a/Tests/Controller/FineUploaderValidationTest.php b/Tests/Controller/FineUploaderValidationTest.php index d1961e4..a3b1a7e 100644 --- a/Tests/Controller/FineUploaderValidationTest.php +++ b/Tests/Controller/FineUploaderValidationTest.php @@ -27,26 +27,6 @@ class FineUploaderValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile( diff --git a/Tests/Controller/PluploadValidationTest.php b/Tests/Controller/PluploadValidationTest.php index 61ffc55..c9e9be9 100644 --- a/Tests/Controller/PluploadValidationTest.php +++ b/Tests/Controller/PluploadValidationTest.php @@ -27,26 +27,6 @@ class PluploadValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile( diff --git a/Tests/Controller/UploadifyValidationTest.php b/Tests/Controller/UploadifyValidationTest.php index 0f10650..086267f 100644 --- a/Tests/Controller/UploadifyValidationTest.php +++ b/Tests/Controller/UploadifyValidationTest.php @@ -27,26 +27,6 @@ class UploadifyValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile( diff --git a/Tests/Controller/YUI3ValidationTest.php b/Tests/Controller/YUI3ValidationTest.php index ca4919c..2325c61 100644 --- a/Tests/Controller/YUI3ValidationTest.php +++ b/Tests/Controller/YUI3ValidationTest.php @@ -27,26 +27,6 @@ class YUI3ValidationTest extends AbstractValidationTest ); } - protected function getFileWithCorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.ok', - 'text/plain', - 128 - ); - } - - protected function getFileWithIncorrectExtension() - { - return new UploadedFile( - $this->createTempFile(128), - 'cat.fail', - 'text/plain', - 128 - ); - } - protected function getFileWithCorrectMimeType() { return new UploadedFile(
0
cbb87b59746d2b035a4981e5ce945b6d0239d19e
1up-lab
OneupUploaderBundle
Merge pull request #22 from 1up-lab/upload-progress Upload progress
commit cbb87b59746d2b035a4981e5ce945b6d0239d19e Merge: 5364f98 434a8ed Author: Jim Schmid <[email protected]> Date: Tue Jun 25 09:02:16 2013 -0700 Merge pull request #22 from 1up-lab/upload-progress Upload progress
0
de814a130556372d7468d4983ff1e4b427ce7690
1up-lab
OneupUploaderBundle
Use the native createFile instead of an empty write to create the file in the first place.
commit de814a130556372d7468d4983ff1e4b427ce7690 Author: Jim Schmid <[email protected]> Date: Wed Mar 13 09:07:05 2013 +0100 Use the native createFile instead of an empty write to create the file in the first place. diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index a5fb5d8..b6918c6 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -26,9 +26,9 @@ class GaufretteStorage implements StorageInterface // this is a somehow ugly workaround introduced // because the stream-mode is not able to create - // subdirectories, while "write" does. + // subdirectories. if(!$this->filesystem->has($name)) - $this->filesystem->write($name, '', true); + $this->filesystem->createFile($name); $src->open(new StreamMode('rb+')); $dst->open(new StreamMode('ab+'));
0
051829418cbc6a8d22ca00e439762476259d8e38
1up-lab
OneupUploaderBundle
Fix code coverage in Response object test.
commit 051829418cbc6a8d22ca00e439762476259d8e38 Author: Jim Schmid <[email protected]> Date: Sat Apr 6 16:21:50 2013 +0200 Fix code coverage in Response object test. diff --git a/Tests/Uploader/Response/UploaderResponseTest.php b/Tests/Uploader/Response/UploaderResponseTest.php index a232436..37728a0 100644 --- a/Tests/Uploader/Response/UploaderResponseTest.php +++ b/Tests/Uploader/Response/UploaderResponseTest.php @@ -20,10 +20,18 @@ class TestUploaderResponse extends \PHPUnit_Framework_TestCase $cat = 'is grumpy'; $dog = 'has no idea'; + $del = 'nothing here'; $response['cat'] = $cat; $response['dog'] = $dog; + $response['del'] = $del; $response->setSuccess(false); + + // the next three lines are from code coverage + $this->assertTrue(isset($response['cat'])); + $this->assertEquals($response['cat'], $cat); + + unset($response['del']); $assembled = $response->assemble();
0
cdc567739906d0e7f42dbc06a005774589ec03af
1up-lab
OneupUploaderBundle
Merge branch 'm47730-patch-1'
commit cdc567739906d0e7f42dbc06a005774589ec03af Merge: e2b21d4 74453d4 Author: David Greminger <[email protected]> Date: Mon Oct 23 17:47:06 2017 +0200 Merge branch 'm47730-patch-1'
0
44c64391b5901555d66b508f64802731cefee7b7
1up-lab
OneupUploaderBundle
Implemented FancyUpload.
commit 44c64391b5901555d66b508f64802731cefee7b7 Author: Jim Schmid <[email protected]> Date: Thu Apr 11 22:31:15 2013 +0200 Implemented FancyUpload. diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php new file mode 100644 index 0000000..ee69af0 --- /dev/null +++ b/Controller/FancyUploadController.php @@ -0,0 +1,40 @@ +<?php + +namespace Oneup\UploaderBundle\Controller; + +use Symfony\Component\HttpFoundation\File\Exception\UploadException; +use Symfony\Component\HttpFoundation\JsonResponse; + +use Oneup\UploaderBundle\Controller\AbstractController; +use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; + +class FancyUploadController extends AbstractController +{ + public function upload() + { + $request = $this->container->get('request'); + $dispatcher = $this->container->get('event_dispatcher'); + $translator = $this->container->get('translator'); + + $response = new EmptyResponse(); + $files = $request->files; + + foreach($files as $file) + { + try + { + $uploaded = $this->handleUpload($file); + + // dispatch POST_PERSIST AND POST_UPLOAD events + $this->dispatchEvents($uploaded, $response, $request); + } + catch(UploadException $e) + { + // return nothing + return new JsonResponse(array()); + } + } + + return new JsonResponse($response->assemble()); + } +} \ No newline at end of file diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7298bec..b97806e 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')) + ->values(array('fineuploader', 'blueimp', 'uploadify', 'yui3', 'fancyupload')) ->defaultValue('fineuploader') ->end() ->arrayNode('storage') diff --git a/Resources/config/frontend_fancyupload.md b/Resources/config/frontend_fancyupload.md new file mode 100644 index 0000000..bad221a --- /dev/null +++ b/Resources/config/frontend_fancyupload.md @@ -0,0 +1,106 @@ +Use FancyUpload +============= + +Download [FancyUpload](http://digitarald.de/project/fancyupload/) and include it in your template. Connect the `url` property to the dynamic route `_uploader_{mapping_name}` and include the FlashUploader file (`path`). + +```html + +<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools.js"></script> +<script type="text/javascript" src="{{ asset('bundles/acmedemo/js/Swiff.Uploader.js') }}"></script> +<script type="text/javascript" src="{{ asset('bundles/acmedemo/js/Fx.ProgressBar.js') }}"></script> +<script type="text/javascript" src="{{ asset('bundles/acmedemo/js/FancyUpload2.js') }}"></script> + +<script type="text/javascript"> +window.addEvent('domready', function() +{ + var uploader = new FancyUpload2($('demo-status'), $('demo-list'), + { + url: $('form-demo').action, + fieldName: 'photoupload', + path: "{{ asset('bundles/acmedemo/js/Swiff.Uploader.swf') }}", + limitSize: 2 * 1024 * 1024, + onLoad: function() { + $('demo-status').removeClass('hide'); + $('demo-fallback').destroy(); + }, + debug: true, + target: 'demo-browse' + }); + + $('demo-browse').addEvent('click', function() + { + swiffy.browse(); + return false; + }); + + $('demo-select-images').addEvent('change', function() + { + var filter = null; + if (this.checked) { + filter = {'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'}; + } + uploader.options.typeFilter = filter; + }); + + $('demo-clear').addEvent('click', function() + { + uploader.removeFile(); + return false; + }); + + $('demo-upload').addEvent('click', function() + { + uploader.upload(); + return false; + }); +}); +</script> + + +<form action="{{ path('_uploader_gallery') }}" method="post" enctype="multipart/form-data" id="form-demo"> + <fieldset id="demo-fallback"> + <legend>File Upload</legend> + <p> + Selected your photo to upload.<br /> + <strong>This form is just an example fallback for the unobtrusive behaviour of FancyUpload.</strong> + </p> + <label for="demo-photoupload"> + Upload Photos: + <input type="file" name="photoupload" id="demo-photoupload" /> + </label> + </fieldset> + + <div id="demo-status" class="hide"> + <p> + <a href="#" id="demo-browse">Browse Files</a> | + <input type="checkbox" id="demo-select-images" /> Images Only | + <a href="#" id="demo-clear">Clear List</a> | + <a href="#" id="demo-upload">Upload</a> + </p> + <div> + <strong class="overall-title">Overall progress</strong><br /> + <img src="{{ asset('bundles/acmedemo/images/progress-bar/bar.gif') }}" class="progress overall-progress" /> + </div> + <div> + <strong class="current-title">File Progress</strong><br /> + <img src="{{ asset('bundles/acmedemo/images/progress-bar/bar.gif') }}" class="progress current-progress" /> + </div> + <div class="current-text"></div> + </div> + <ul id="demo-list"></ul> +</form> + +``` + +Configure the OneupUploaderBundle to use the correct controller: + +```yaml +# app/config/config.yml + +oneup_uploader: + mappings: + gallery: + frontend: fancyupload +``` + +Be sure to check out the [official manual](http://digitarald.de/project/fancyupload/) for details on the configuration. \ No newline at end of file diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 6933114..1a1108d 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -15,6 +15,7 @@ <parameter key="oneup_uploader.controller.blueimp.class">Oneup\UploaderBundle\Controller\BlueimpController</parameter> <parameter key="oneup_uploader.controller.uploadify.class">Oneup\UploaderBundle\Controller\UploadifyController</parameter> <parameter key="oneup_uploader.controller.yui3.class">Oneup\UploaderBundle\Controller\YUI3Controller</parameter> + <parameter key="oneup_uploader.controller.fancyupload.class">Oneup\UploaderBundle\Controller\FancyUploadController</parameter> </parameters> <services>
0
4b7e0aab49b5cfe268d47f760ead43a5b71fe251
1up-lab
OneupUploaderBundle
Added Next Steps section to frontend documentations.
commit 4b7e0aab49b5cfe268d47f760ead43a5b71fe251 Author: Jim Schmid <[email protected]> Date: Tue Oct 8 22:46:59 2013 +0200 Added Next Steps section to frontend documentations. diff --git a/Resources/doc/frontend_blueimp.md b/Resources/doc/frontend_blueimp.md index f6935c2..db30fdf 100644 --- a/Resources/doc/frontend_blueimp.md +++ b/Resources/doc/frontend_blueimp.md @@ -41,4 +41,14 @@ security: main: pattern: ^/ anonymous: true -``` \ No newline at end of file +``` + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_dropzone.md b/Resources/doc/frontend_dropzone.md index 0be52b3..66fc318 100644 --- a/Resources/doc/frontend_dropzone.md +++ b/Resources/doc/frontend_dropzone.md @@ -21,4 +21,14 @@ oneup_uploader: frontend: dropzone ``` -Be sure to check out the [official manual](http://www.dropzonejs.com/) for details on the configuration. \ No newline at end of file +Be sure to check out the [official manual](http://www.dropzonejs.com/) for details on the configuration. + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_fancyupload.md b/Resources/doc/frontend_fancyupload.md index 02bef21..09896f0 100644 --- a/Resources/doc/frontend_fancyupload.md +++ b/Resources/doc/frontend_fancyupload.md @@ -28,13 +28,13 @@ window.addEvent('domready', function() debug: true, target: 'demo-browse' }); - + $('demo-browse').addEvent('click', function() { swiffy.browse(); return false; }); - + $('demo-select-images').addEvent('change', function() { var filter = null; @@ -71,7 +71,7 @@ window.addEvent('domready', function() <input type="file" name="photoupload" id="demo-photoupload" /> </label> </fieldset> - + <div id="demo-status" class="hide"> <p> <a href="#" id="demo-browse">Browse Files</a> | @@ -106,3 +106,13 @@ oneup_uploader: ``` Be sure to check out the [official manual](http://digitarald.de/project/fancyupload/) for details on the configuration. + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md index 50ea10d..cd8a019 100644 --- a/Resources/doc/frontend_fineuploader.md +++ b/Resources/doc/frontend_fineuploader.md @@ -33,3 +33,13 @@ oneup_uploader: ``` Be sure to check out the [official manual](https://github.com/Widen/fine-uploader/blob/master/readme.md) for details on the configuration. + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_mooupload.md b/Resources/doc/frontend_mooupload.md index 5c31868..6a1db2c 100644 --- a/Resources/doc/frontend_mooupload.md +++ b/Resources/doc/frontend_mooupload.md @@ -32,4 +32,14 @@ oneup_uploader: frontend: mooupload ``` -Be sure to check out the [official manual](https://github.com/juanparati/MooUpload) for details on the configuration. \ No newline at end of file +Be sure to check out the [official manual](https://github.com/juanparati/MooUpload) for details on the configuration. + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_plupload.md b/Resources/doc/frontend_plupload.md index 34c1dc5..deb1ce0 100644 --- a/Resources/doc/frontend_plupload.md +++ b/Resources/doc/frontend_plupload.md @@ -47,4 +47,14 @@ security: main: pattern: ^/ anonymous: true -``` \ No newline at end of file +``` + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md) diff --git a/Resources/doc/frontend_uploadify.md b/Resources/doc/frontend_uploadify.md index 072f22c..ec7bcc9 100644 --- a/Resources/doc/frontend_uploadify.md +++ b/Resources/doc/frontend_uploadify.md @@ -16,7 +16,7 @@ $(document).ready(function() swf: "{{ asset('bundles/acmedemo/js/uploadify.swf') }}", uploader: "{{ oneup_uploader_endpoint('gallery') }}" }); - + }); </script> @@ -34,4 +34,14 @@ oneup_uploader: frontend: uploadify ``` -Be sure to check out the [official manual](http://www.uploadify.com/documentation/) for details on the configuration. \ No newline at end of file +Be sure to check out the [official manual](http://www.uploadify.com/documentation/) for details on the configuration. + +Next steps +---------- + +After this setup, you can move on and implement some of the more advanced features. A full list is available [here](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md#next-steps). + +* [Process uploaded files using custom logic](custom_logic.md) +* [Return custom data to frontend](response.md) +* [Include your own Namer](custom_namer.md) +* [Configuration Reference](configuration_reference.md)
0
3361b73c806eb3d952a17b0e6d50e77eee9e8d26
1up-lab
OneupUploaderBundle
Merge pull request #27 from 1up-lab/error-handler Proper error handling.
commit 3361b73c806eb3d952a17b0e6d50e77eee9e8d26 Merge: 9dbd905 1e91e1e Author: Jim Schmid <[email protected]> Date: Mon Jul 15 03:00:36 2013 -0700 Merge pull request #27 from 1up-lab/error-handler Proper error handling.
0
68023c5268696390c86aa2c172497606c03d79e1
1up-lab
OneupUploaderBundle
Remove cache before executing tests
commit 68023c5268696390c86aa2c172497606c03d79e1 Author: Jim Schmid <[email protected]> Date: Thu Jul 18 10:10:41 2013 +0200 Remove cache before executing tests diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index f04fc53..a1756af 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -10,6 +10,7 @@ EOT ); } +passthru(sprintf('rm -rf %s/App/cache', __DIR__)); spl_autoload_register(function($class) { if (0 === strpos($class, 'Oneup\\UploaderBundle\\')) { $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
0
52205e6275347a3f1bfe3f607687a2921cef4487
1up-lab
OneupUploaderBundle
Update travis test matrix
commit 52205e6275347a3f1bfe3f607687a2921cef4487 Author: Jérémy M <[email protected]> Date: Fri Aug 21 15:45:54 2015 +0200 Update travis test matrix diff --git a/.travis.yml b/.travis.yml index 5a3affa..0af42e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,22 +5,29 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 - hhvm env: - - SYMFONY_VERSION=2.3.* + - SYMFONY_VERSION=2.7.* matrix: + include: + - php: 5.6 + env: SYMFONY_VERSION=2.3.* + - php: 5.6 + env: SYMFONY_VERSION=2.6.* + - php: 5.6 + env: SYMFONY_VERSION=2.7.* + - php: 5.6 + env: SYMFONY_VERSION=2.8.*@dev + - php: 5.6 + env: SYMFONY_VERSION="3.0.x-dev as 2.8" allow_failures: - - env: SYMFONY_VERSION=dev-master + - php: 7.0 - php: hhvm - include: - - php: 5.5 - env: SYMFONY_VERSION=2.4.* - - php: 5.5 - env: SYMFONY_VERSION=2.5.* - - php: 5.5 - env: SYMFONY_VERSION=dev-master + - env: SYMFONY_VERSION=2.8.*@dev + - env: SYMFONY_VERSION="3.0.x-dev as 2.8" before_script: - composer selfupdate
0
db6423ba0afb99615c265112ef4075ef75164faa
1up-lab
OneupUploaderBundle
Merge pull request #192 from u-voelkel/fix-iterator fix iterator access. fixes #190.
commit db6423ba0afb99615c265112ef4075ef75164faa Merge: f28f251 1ffd96c Author: David Greminger <[email protected]> Date: Tue Sep 29 16:41:35 2015 +0200 Merge pull request #192 from u-voelkel/fix-iterator fix iterator access. fixes #190.
0
243f21631411b06669f57e90243d7154e798b4f9
1up-lab
OneupUploaderBundle
use the stream wrapper prefix when available
commit 243f21631411b06669f57e90243d7154e798b4f9 Author: mitom <[email protected]> Date: Fri Feb 21 17:11:20 2014 +0100 use the stream wrapper prefix when available diff --git a/Uploader/Chunk/Storage/GaufretteStorage.php b/Uploader/Chunk/Storage/GaufretteStorage.php index dec76ce..9d22fd6 100644 --- a/Uploader/Chunk/Storage/GaufretteStorage.php +++ b/Uploader/Chunk/Storage/GaufretteStorage.php @@ -169,4 +169,9 @@ class GaufretteStorage extends StreamManager implements ChunkStorageInterface { return $this->filesystem; } + + public function getStreamWrapperPrefix() + { + return $this->streamWrapperPrefix; + } } diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php index ea5379f..d5a9489 100644 --- a/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/Uploader/Storage/GaufretteOrphanageStorage.php @@ -26,9 +26,11 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto */ public function __construct(StorageInterface $storage, SessionInterface $session, GaufretteChunkStorage $chunkStorage, $config, $type) { - // initiate the storage on the chunk storage's filesystem - // the prefix and stream wrapper are unnecessary. - parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, null, null); + /* + * initiate the storage on the chunk storage's filesystem + * the stream wrapper is useful for metadata. + */ + parent::__construct($chunkStorage->getFilesystem(), $chunkStorage->bufferSize, $chunkStorage->getStreamWrapperPrefix()); $this->storage = $storage; $this->chunkStorage = $chunkStorage;
0
a2b58acd47ee19bed944e45cb4488e338c97b3fe
1up-lab
OneupUploaderBundle
Added warning to readme. ping #21
commit a2b58acd47ee19bed944e45cb4488e338c97b3fe Author: Jim Schmid <[email protected]> Date: Thu Jul 25 17:28:23 2013 +0200 Added warning to readme. ping #21 diff --git a/README.md b/README.md index 17de8d8..cfdfbdb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,16 @@ +*** + +**Warning**: There is currently a pretty serious issue reported. Until further notice, +consider chunked uploads as *not-working*. It is highly recommended to switch from chunked +uploads to non-chunked uploads until this issue is fixed again. You can find more +information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21). + +*** + + OneupUploaderBundle =================== + The OneupUploaderBundle for Symfony2 adds support for handling file uploads using one of the following Javascript libraries, or [your own implementation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_uploader.md). * [FineUploader](http://fineuploader.com/)
0
70b5f5e04f1834e547fafdebb5ce35dba2c796d7
1up-lab
OneupUploaderBundle
process max size when string
commit 70b5f5e04f1834e547fafdebb5ce35dba2c796d7 Author: jbouzekri <[email protected]> Date: Fri Jan 30 21:49:37 2015 +0100 process max size when string diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 34e707d..aec580d 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -69,7 +69,7 @@ class OneupUploaderExtension extends Extension protected function processMapping($key, &$mapping) { - $mapping['max_size'] = $mapping['max_size'] < 0 ? + $mapping['max_size'] = $mapping['max_size'] < 0 || is_string($mapping['max_size']) ? $this->getMaxUploadSize($mapping['max_size']) : $mapping['max_size'] ;
0
1589bd69468c1734bb20337bfbdb00c455b8d868
1up-lab
OneupUploaderBundle
Run phpstan on max level
commit 1589bd69468c1734bb20337bfbdb00c455b8d868 Author: David Greminger <[email protected]> Date: Fri Oct 23 11:58:17 2020 +0200 Run phpstan on max level diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26eb666..7605e04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: - name: Check the coding style run: vendor/bin/php-cs-fixer fix --diff --dry-run - name: Analyze the code - run: vendor/bin/phpstan analyze src/ tests/ --level=6 + run: vendor/bin/phpstan analyze src/ tests/ --level=max tests: name: PHP ${{ matrix.php }} / SF ^${{ matrix.symfony }} diff --git a/phpstan.neon b/phpstan.neon index bb9931f..b945375 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: - bootstrap: %rootDir%/../../../vendor/autoload.php + bootstrapFiles: + - %rootDir%/../../../vendor/autoload.php excludes_analyse: - src/DependencyInjection/Configuration.php diff --git a/tests/Controller/AbstractControllerTest.php b/tests/Controller/AbstractControllerTest.php index 194ec28..90f84db 100644 --- a/tests/Controller/AbstractControllerTest.php +++ b/tests/Controller/AbstractControllerTest.php @@ -140,7 +140,7 @@ abstract class AbstractControllerTest extends WebTestCase $response = $client->getResponse(); $this->assertSame($expectedStatusCode, $response->getStatusCode()); - $this->assertStringContainsStringIgnoringCase($expectedContentType, $response->headers->get('Content-Type')); + $this->assertStringContainsStringIgnoringCase($expectedContentType, (string) $response->headers->get('Content-Type')); } protected function createTempFile(int $size = 128): string
0
3df0636d3dfa53aa4e961f6d9dcee06d21d90f90
1up-lab
OneupUploaderBundle
Register commands to avoid deprecations in Symfony >= 3.4 (#336)
commit 3df0636d3dfa53aa4e961f6d9dcee06d21d90f90 Author: enekochan <[email protected]> Date: Tue May 22 19:05:56 2018 +0200 Register commands to avoid deprecations in Symfony >= 3.4 (#336) diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php index 89660b7..b72bd93 100644 --- a/Command/ClearChunkCommand.php +++ b/Command/ClearChunkCommand.php @@ -8,10 +8,12 @@ use Symfony\Component\Console\Output\OutputInterface; class ClearChunkCommand extends ContainerAwareCommand { + protected static $defaultName = 'oneup:uploader:clear-chunks'; // Make command lazy load + protected function configure() { $this - ->setName('oneup:uploader:clear-chunks') + ->setName(self::$defaultName) // BC with 2.7 ->setDescription('Clear chunks according to the max-age you defined in your configuration.') ; } diff --git a/Command/ClearOrphansCommand.php b/Command/ClearOrphansCommand.php index 9a1b913..a2d44e7 100644 --- a/Command/ClearOrphansCommand.php +++ b/Command/ClearOrphansCommand.php @@ -8,10 +8,12 @@ use Symfony\Component\Console\Output\OutputInterface; class ClearOrphansCommand extends ContainerAwareCommand { + protected static $defaultName = 'oneup:uploader:clear-orphans'; // Make command lazy load + protected function configure() { $this - ->setName('oneup:uploader:clear-orphans') + ->setName(self::$defaultName) // BC with 2.7 ->setDescription('Clear orphaned uploads according to the max-age you defined in your configuration.') ; } diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 1ab7116..29b3993 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -24,6 +24,8 @@ <parameter key="oneup_uploader.controller.mooupload.class">Oneup\UploaderBundle\Controller\MooUploadController</parameter> <parameter key="oneup_uploader.controller.plupload.class">Oneup\UploaderBundle\Controller\PluploadController</parameter> <parameter key="oneup_uploader.controller.dropzone.class">Oneup\UploaderBundle\Controller\DropzoneController</parameter> + <parameter key="oneup_uploader.command.clear_chunks.class">Oneup\UploaderBundle\Command\ClearChunkCommand</parameter> + <parameter key="oneup_uploader.command.clear_orphans.class">Oneup\UploaderBundle\Command\ClearOrphansCommand</parameter> </parameters> <services> @@ -40,7 +42,7 @@ </service> <!-- namer --> - <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" public="true"/> + <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" public="true" /> <service id="oneup_uploader.namer.urlsafe" class="%oneup_uploader.namer.urlsafename.class%" /> <!-- routing --> @@ -49,6 +51,14 @@ <tag name="routing.loader" /> </service> + <!-- commands --> + <service id="oneup_uploader.command.clear_chunks" class="%oneup_uploader.command.clear_chunks.class%"> + <tag name="console.command" command="oneup:uploader:clear-chunks" /> + </service> + <service id="oneup_uploader.command.clear_orphans" class="%oneup_uploader.command.clear_orphans.class%"> + <tag name="console.command" command="oneup:uploader:clear-orphans" /> + </service> + </services> </container>
0
c97fd9837d1cf4496465efa9d171458df44e33a9
1up-lab
OneupUploaderBundle
Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
commit c97fd9837d1cf4496465efa9d171458df44e33a9 Merge: c9c4c19 e7b6326 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 11:26:16 2013 +0200 Merge branch 'master' of github.com:1up-lab/OneupUploaderBundle
0
2fa822b7b9c097d26317ffc163fd9d0d584ca6a1
1up-lab
OneupUploaderBundle
Fix tests
commit 2fa822b7b9c097d26317ffc163fd9d0d584ca6a1 Author: David Greminger <[email protected]> Date: Tue Feb 4 14:03:24 2020 +0100 Fix tests diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index e72f144..81772b6 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -27,6 +27,8 @@ abstract class AbstractControllerTest extends WebTestCase public function setUp() { $this->client = static::createClient(); + $this->client->catchExceptions(false); + self::$container = $this->client->getContainer(); $this->helper = self::$container->get('oneup_uploader.templating.uploader_helper'); $this->createdFiles = []; diff --git a/composer.json b/composer.json index 9405e60..c0c4941 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,11 @@ "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", "oneup/flysystem-bundle": "^1.2|^2.0|^3.0", - "phpunit/phpunit": "^6.5", + "phpunit/phpunit": "^7.5", "sensio/framework-extra-bundle": "^5.0", "symfony/browser-kit": "^3.0|^4.0", "symfony/class-loader": "^3.0|^4.0", + "symfony/phpunit-bridge": "^5.0", "symfony/security-bundle": "^3.0|^4.0", "symfony/var-dumper": "^3.0|^4.0", "twistor/flysystem-stream-wrapper": "^1.0" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6f2e1c0..2e0c235 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,6 +5,10 @@ <server name="KERNEL_DIR" value="Tests/App" /> <server name="KERNEL_CLASS" value="AppKernel" /> </php> + + <listeners> + <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/> + </listeners> <testsuites> <testsuite name="OneupUploaderBundle test suite">
0
207d2f19d89f37ca61831ff1a79e2557aa9464f1
1up-lab
OneupUploaderBundle
Added a documentation topic: How to use Chunked Uploads behind Load Balancers. This is WIP.
commit 207d2f19d89f37ca61831ff1a79e2557aa9464f1 Author: Jim Schmid <[email protected]> Date: Fri Oct 11 19:19:16 2013 +0200 Added a documentation topic: How to use Chunked Uploads behind Load Balancers. This is WIP. diff --git a/Resources/doc/index.md b/Resources/doc/index.md index fe69b15..430fc08 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -124,6 +124,7 @@ some more advanced features. * [Validate your uploads](custom_validator.md) * [General/Generic Events](events.md) * [Enable Session upload progress / upload cancelation](progress.md) +* [Use Chunked Uploads behind Load Balancers](load_balancers.md) * [Configuration Reference](configuration_reference.md) * [Testing this bundle](testing.md) diff --git a/Resources/doc/load_balancers.md b/Resources/doc/load_balancers.md new file mode 100644 index 0000000..0667b94 --- /dev/null +++ b/Resources/doc/load_balancers.md @@ -0,0 +1,6 @@ +Use Chunked Uploads behind Load Balancers +========================================= + +If you want to use Chunked Uploads behind load balancers that is not configured to use sticky sessions you'll eventually end up with a bunch of chunks on every instance and the bundle is not able to reassemble the file on the server. + +You can avoid this problem by using Gaufrette as an abstract filesystem. \ No newline at end of file
0
f9fb64baadbfbad5d0a533b279251a4947507de7
1up-lab
OneupUploaderBundle
Let blueimp return a text/plain response to old browsers
commit f9fb64baadbfbad5d0a533b279251a4947507de7 Author: Erik Ammerlaan <[email protected]> Date: Wed Oct 2 12:36:50 2013 +0200 Let blueimp return a text/plain response to old browsers diff --git a/Controller/BlueimpController.php b/Controller/BlueimpController.php index 3e1578b..f10f776 100644 --- a/Controller/BlueimpController.php +++ b/Controller/BlueimpController.php @@ -30,7 +30,7 @@ class BlueimpController extends AbstractChunkedController } } - return new JsonResponse($response->assemble()); + return $this->createSupportedJsonResponse($response->assemble()); } public function progress() @@ -51,7 +51,7 @@ class BlueimpController extends AbstractChunkedController 'total' => $value['content_length'] ); - return new JsonResponse($progress); + return $this->createSupportedJsonResponse($progress); } protected function parseChunkedRequest(Request $request) @@ -83,4 +83,26 @@ class BlueimpController extends AbstractChunkedController return array($last, $uuid, $index, $orig); } + + /** + * Creates and returns a JsonResponse with the given data. + * + * On top of that, if the client does not support the application/json type, + * then the content type of the response will be set to text/plain instead. + * + * @param mixed $data + * + * @return JsonResponse + */ + private function createSupportedJsonResponse($data) + { + $request = $this->container->get('request'); + $response = new JsonResponse($data); + $response->headers->set('Vary', 'Accept'); + if (!in_array('application/json', $request->getAcceptableContentTypes())) { + $response->headers->set('Content-type', 'text/plain'); + } + + return $response; + } } diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index 351f173..8909345 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -63,7 +63,7 @@ abstract class AbstractControllerTest extends WebTestCase $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint); + $client->request('POST', $endpoint, array(), array(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); diff --git a/Tests/Controller/BlueimpTest.php b/Tests/Controller/BlueimpTest.php index 44e07bd..c06c8d1 100644 --- a/Tests/Controller/BlueimpTest.php +++ b/Tests/Controller/BlueimpTest.php @@ -16,7 +16,7 @@ class BlueimpTest extends AbstractUploadTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getRequestFile()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getRequestFile(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); @@ -30,6 +30,20 @@ class BlueimpTest extends AbstractUploadTest } } + public function testResponseForOldBrowsers() + { + $client = $this->client; + $endpoint = $this->helper->endpoint($this->getConfigKey()); + + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getRequestFile()); + $response = $client->getResponse(); + + $this->assertTrue($response->isSuccessful()); + $this->assertEquals($response->headers->get('Content-Type'), 'text/plain; charset=UTF-8'); + $this->assertCount(1, $this->getUploadedFiles()); + + } + public function testEvents() { $client = $this->client; diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index dc90c38..4bbfa1c 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -15,7 +15,7 @@ class BlueimpValidationTest extends AbstractValidationTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getOversizedFile()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getOversizedFile(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); //$this->assertTrue($response->isNotSuccessful()); @@ -29,7 +29,7 @@ class BlueimpValidationTest extends AbstractValidationTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectExtension(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); @@ -67,7 +67,7 @@ class BlueimpValidationTest extends AbstractValidationTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectExtension()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectExtension(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); //$this->assertTrue($response->isNotSuccessful()); @@ -81,7 +81,7 @@ class BlueimpValidationTest extends AbstractValidationTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithCorrectMimeType(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); @@ -103,7 +103,7 @@ class BlueimpValidationTest extends AbstractValidationTest $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectMimeType()); + $client->request('POST', $endpoint, $this->getRequestParameters(), $this->getFileWithIncorrectMimeType(), array('HTTP_ACCEPT' => 'application/json')); $response = $client->getResponse(); //$this->assertTrue($response->isNotSuccessful());
0
968548264758fa5bce66659730f57ca6582c7f3e
1up-lab
OneupUploaderBundle
Typo
commit 968548264758fa5bce66659730f57ca6582c7f3e Author: David Greminger <[email protected]> Date: Mon Dec 4 09:51:45 2017 +0100 Typo diff --git a/README.md b/README.md index 2a54218..c5c5b05 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 (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 **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). * 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
790a534de46dba1db1ed331c2416cac450267774
1up-lab
OneupUploaderBundle
Merge branch 'error-handling-doc' of https://github.com/lsv/OneupUploaderBundle into lsv-error-handling-doc
commit 790a534de46dba1db1ed331c2416cac450267774 Merge: 210707f 68af022 Author: David Greminger <[email protected]> Date: Mon Jan 4 10:09:46 2016 +0100 Merge branch 'error-handling-doc' of https://github.com/lsv/OneupUploaderBundle into lsv-error-handling-doc
0
cb9e36c8873f69ad207a28516d239c8b511e2f16
1up-lab
OneupUploaderBundle
Remove metric suffix from input Eliminates notice on php 7.1 caused by invalid string in arithmetic
commit cb9e36c8873f69ad207a28516d239c8b511e2f16 Author: Bronisław Białek <[email protected]> Date: Sat Oct 8 13:42:36 2016 +0200 Remove metric suffix from input Eliminates notice on php 7.1 caused by invalid string in arithmetic diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 5ffbe09..0d472ff 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -294,11 +294,14 @@ class OneupUploaderExtension extends Extension // see: http://www.php.net/manual/en/function.ini-get.php $input = trim($input); $last = strtolower($input[strlen($input) - 1]); + $numericInput = substr($input, 0, -1); switch ($last) { - case 'g': $input *= 1024; - case 'm': $input *= 1024; - case 'k': $input *= 1024; + case 'g': $numericInput *= 1024; + case 'm': $numericInput *= 1024; + case 'k': $numericInput *= 1024; + + return $numericInput; } return $input;
0
331f14afaa12ac997505d93160d6bff043200541
1up-lab
OneupUploaderBundle
Removed manual install of framework-bundle on travis
commit 331f14afaa12ac997505d93160d6bff043200541 Author: David Greminger <[email protected]> Date: Mon Jan 4 11:14:42 2016 +0100 Removed manual install of framework-bundle on travis diff --git a/.travis.yml b/.travis.yml index f81a416..1564c0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,5 +42,4 @@ matrix: before_script: - composer selfupdate - composer require symfony/http-kernel:${SYMFONY_VERSION} --prefer-source - - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source - composer install --dev --prefer-source
0
b06cf28f671cdb33c3ffdddd3a0df9884d1a5449
1up-lab
OneupUploaderBundle
Fixed a bug where not the correct request value was taken to access the session.
commit b06cf28f671cdb33c3ffdddd3a0df9884d1a5449 Author: Jim Schmid <[email protected]> Date: Tue Jun 25 11:06:10 2013 +0200 Fixed a bug where not the correct request value was taken to access the session. diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 68fa7b4..4b8bf48 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -44,7 +44,7 @@ abstract class AbstractController // assemble session key // ref: http://php.net/manual/en/session.upload-progress.php - $key = sprintf('%s.%s', $prefix, $name); + $key = sprintf('%s.%s', $prefix, $request->get($name)); $value = $session->get($key); return new JsonResponse($value);
0
13dee605501659d1bdcd738f3a9c4e7be97094a0
1up-lab
OneupUploaderBundle
Only Gaufrette is used to test the bundle, not the GaufretteBundle.
commit 13dee605501659d1bdcd738f3a9c4e7be97094a0 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 12:29:54 2013 +0200 Only Gaufrette is used to test the bundle, not the GaufretteBundle. diff --git a/composer.json b/composer.json index 9b93984..d59371e 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { - "knplabs/knp-gaufrette-bundle": "0.1.*" + "knplabs/gaufrette": "0.2.*@dev" }, "suggest": {
0
e6a0773c36ca172feae24e7117aebf6e4ff22c73
1up-lab
OneupUploaderBundle
Removed unused variables on FancyUploadController.
commit e6a0773c36ca172feae24e7117aebf6e4ff22c73 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 11:24:17 2013 +0200 Removed unused variables on FancyUploadController. diff --git a/Controller/FancyUploadController.php b/Controller/FancyUploadController.php index ee69af0..c2e32bd 100644 --- a/Controller/FancyUploadController.php +++ b/Controller/FancyUploadController.php @@ -13,9 +13,6 @@ class FancyUploadController 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
41ac1d8ce5e72f2d12e935400b1d066e06e71402
1up-lab
OneupUploaderBundle
DI: replace direct params usage with %param.name% After that, finally we can override 'oneup_uploader.orphanage.class' for example in parameters.yml as described in http://symfony.com/doc/current/cookbook/bundles/override.html
commit 41ac1d8ce5e72f2d12e935400b1d066e06e71402 Author: Veniamin Albaev <[email protected]> Date: Thu Jul 18 14:52:40 2013 +0400 DI: replace direct params usage with %param.name% After that, finally we can override 'oneup_uploader.orphanage.class' for example in parameters.yml as described in http://symfony.com/doc/current/cookbook/bundles/override.html diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 108394c..a7cdbba 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -66,7 +66,7 @@ class OneupUploaderExtension extends Extension ; $container - ->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type']))) + ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $mapping['storage']['type'])) ->addArgument($mapping['storage']['directory']) ; } @@ -79,7 +79,7 @@ class OneupUploaderExtension extends Extension throw new ServiceNotFoundException('Empty service name'); $container - ->register($storageName, $container->getParameter(sprintf('oneup_uploader.storage.%s.class', $mapping['storage']['type']))) + ->register($storageName, sprintf('%%oneup_uploader.storage.%s.class%%', $mapping['storage']['type'])) ->addArgument(new Reference($mapping['storage']['filesystem'])) ; } @@ -92,7 +92,7 @@ class OneupUploaderExtension extends Extension // this mapping wants to use the orphanage, so create // a masked filesystem for the controller $container - ->register($orphanageName, $container->getParameter('oneup_uploader.orphanage.class')) + ->register($orphanageName, '%oneup_uploader.orphanage.class%') ->addArgument($storageService) ->addArgument(new Reference('session')) ->addArgument($config['orphanage'])
0
a2f48b71a5cd3c4e4b75bff364dfb588660ab8f9
1up-lab
OneupUploaderBundle
Update FineUploader official manual link (#319)
commit a2f48b71a5cd3c4e4b75bff364dfb588660ab8f9 Author: Léo <[email protected]> Date: Fri Feb 16 16:26:03 2018 +0100 Update FineUploader official manual link (#319) diff --git a/Resources/doc/frontend_fineuploader.md b/Resources/doc/frontend_fineuploader.md index 22fbb16..8519f97 100644 --- a/Resources/doc/frontend_fineuploader.md +++ b/Resources/doc/frontend_fineuploader.md @@ -33,7 +33,7 @@ oneup_uploader: frontend: fineuploader ``` -Be sure to check out the [official manual](https://github.com/Widen/fine-uploader/blob/master/readme.md) for details on the configuration. +Be sure to check out the [official manual](https://github.com/FineUploader/fine-uploader/blob/master/README.md) for details on the configuration. Next steps ----------
0
a0996504bacb1130d780c3b346098c9962ac51c2
1up-lab
OneupUploaderBundle
Set correct link
commit a0996504bacb1130d780c3b346098c9962ac51c2 Author: David Greminger <[email protected]> Date: Thu Jan 28 16:04:15 2016 +0100 Set correct link diff --git a/README.md b/README.md index 12ae19a..8e23bc0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- -* Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @lsv! PR is [here](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 **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR is [here](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57). * If you're using chunked uploads consider upgrading from **v0.9.6** to **v0.9.7**. A critical issue was reported regarding the assembly of chunks. More information in ticket [#21](https://github.com/1up-lab/OneupUploaderBundle/issues/21#issuecomment-21560320). * Error management [changed](https://github.com/1up-lab/OneupUploaderBundle/pull/25) in Version **0.9.6**. You can now register an `ErrorHandler` per configured frontend. This comes bundled with some adjustments to the `blueimp` controller. More information is available in [the documentation](https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/custom_error_handler.md).
0
6e27f44a53a1653c74cf4ab8d4d0c1e5e8fa909c
1up-lab
OneupUploaderBundle
Adjusted version constraints for Symfony3.0.*
commit 6e27f44a53a1653c74cf4ab8d4d0c1e5e8fa909c Author: David Greminger <[email protected]> Date: Thu Dec 10 14:22:26 2015 +0100 Adjusted version constraints for Symfony3.0.* diff --git a/composer.json b/composer.json index 7f745ad..3d765c4 100644 --- a/composer.json +++ b/composer.json @@ -15,18 +15,18 @@ ], "require": { - "symfony/framework-bundle": "^2.3.0|~3.0", - "symfony/http-kernel": "^2.3.0|~3.0", - "symfony/finder": ">=2.2.0|~3.0" + "symfony/framework-bundle": "2.4.*", + "symfony/http-kernel": "^2.4.0|~3.0", + "symfony/finder": "^2.4.0|~3.0" }, "require-dev": { "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", - "symfony/class-loader": "2.*", - "symfony/security-bundle": "2.*", - "sensio/framework-extra-bundle": "2.*", - "symfony/browser-kit": "2.*", + "symfony/class-loader": "2.*|~3.0", + "symfony/security-bundle": "2.*|~3.0", + "sensio/framework-extra-bundle": "2.*|~3.0", + "symfony/browser-kit": "2.*|~3.0", "phpunit/phpunit": "~4.4" },
0
460b24323e1ef5f7dd7ef8088a7bcb5e76959b52
1up-lab
OneupUploaderBundle
Removed die(). Whoopsi.
commit 460b24323e1ef5f7dd7ef8088a7bcb5e76959b52 Author: Jim Schmid <[email protected]> Date: Sat Apr 6 10:25:11 2013 +0200 Removed die(). Whoopsi. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index dc1e83c..3e63f8b 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -102,7 +102,7 @@ class UploaderController implements UploadControllerInterface // 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); - die(); + // assemble parts $assembled = $chunkManager->assembleChunks($chunks); $path = $assembled->getPath();
0
7884373aed3344919d6aee3f95251307bbf24808
1up-lab
OneupUploaderBundle
fixed existing tests and some mistakes revealed by them
commit 7884373aed3344919d6aee3f95251307bbf24808 Author: mitom <[email protected]> Date: Thu Oct 10 19:59:30 2013 +0200 fixed existing tests and some mistakes revealed by them diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php index 01b0a6d..1a3c4b7 100644 --- a/Tests/Controller/AbstractValidationTest.php +++ b/Tests/Controller/AbstractValidationTest.php @@ -56,7 +56,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest // event data $validationCount = 0; - $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) { + $dispatcher->addListener(UploadEvents::VALIDATION, function() use (&$validationCount) { ++ $validationCount; }); diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index 4bbfa1c..19fea99 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -52,7 +52,7 @@ class BlueimpValidationTest extends AbstractValidationTest // event data $validationCount = 0; - $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) { + $dispatcher->addListener(UploadEvents::VALIDATION, function() use (&$validationCount) { ++ $validationCount; }); diff --git a/Tests/Uploader/Chunk/ChunkManagerTest.php b/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php similarity index 80% rename from Tests/Uploader/Chunk/ChunkManagerTest.php rename to Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php index 4ce9c4a..1df65ea 100644 --- a/Tests/Uploader/Chunk/ChunkManagerTest.php +++ b/Tests/Uploader/Chunk/Storage/FilesystemStorageTest.php @@ -1,13 +1,12 @@ <?php -namespace Oneup\UploaderBundle\Tests\Uploader\Chunk; +namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; +use Oneup\UploaderBundle\Uploader\Chunk\Storage\FilesystemStorage; -use Oneup\UploaderBundle\Uploader\Chunk\ChunkManager; - -class ChunkManagerTest extends \PHPUnit_Framework_TestCase +class FilesystemStorageTest extends \PHPUnit_Framework_TestCase { protected $tmpDir; @@ -49,7 +48,7 @@ class ChunkManagerTest extends \PHPUnit_Framework_TestCase { // get a manager configured with a max-age of 5 minutes $maxage = 5 * 60; - $manager = $this->getManager($maxage); + $manager = $this->getStorage(); $numberOfFiles = 10; $finder = new Finder(); @@ -58,7 +57,7 @@ class ChunkManagerTest extends \PHPUnit_Framework_TestCase $this->fillDirectory($numberOfFiles); $this->assertCount(10, $finder); - $manager->clear(); + $manager->clear($maxage); $this->assertTrue(is_dir($this->tmpDir)); $this->assertTrue(is_writeable($this->tmpDir)); @@ -75,18 +74,17 @@ class ChunkManagerTest extends \PHPUnit_Framework_TestCase $filesystem = new Filesystem(); $filesystem->remove($this->tmpDir); - $manager = $this->getManager(10); - $manager->clear(); + $manager = $this->getStorage(); + $manager->clear(10); // yey, no exception $this->assertTrue(true); } - protected function getManager($maxage) + protected function getStorage() { - return new ChunkManager(array( - 'directory' => $this->tmpDir, - 'maxage' => $maxage + return new FilesystemStorage(array( + 'directory' => $this->tmpDir )); } diff --git a/Tests/Uploader/Naming/UniqidNamerTest.php b/Tests/Uploader/Naming/UniqidNamerTest.php index 2ff1631..d20df0a 100644 --- a/Tests/Uploader/Naming/UniqidNamerTest.php +++ b/Tests/Uploader/Naming/UniqidNamerTest.php @@ -8,14 +8,14 @@ class UniqidNamerTest extends \PHPUnit_Framework_TestCase { public function testNamerReturnsName() { - $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') + $file = $this->getMockBuilder('Oneup\UploaderBundle\Uploader\File\FilesystemFile') ->disableOriginalConstructor() ->getMock() ; $file ->expects($this->any()) - ->method('guessExtension') + ->method('getExtension') ->will($this->returnValue('jpeg')) ; @@ -25,14 +25,14 @@ class UniqidNamerTest extends \PHPUnit_Framework_TestCase public function testNamerReturnsUniqueName() { - $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') + $file = $this->getMockBuilder('Oneup\UploaderBundle\Uploader\File\FilesystemFile') ->disableOriginalConstructor() ->getMock() ; $file ->expects($this->any()) - ->method('guessExtension') + ->method('getExtension') ->will($this->returnValue('jpeg')) ; diff --git a/Tests/Uploader/Storage/FilesystemStorageTest.php b/Tests/Uploader/Storage/FilesystemStorageTest.php index 6f3e011..1ae9964 100644 --- a/Tests/Uploader/Storage/FilesystemStorageTest.php +++ b/Tests/Uploader/Storage/FilesystemStorageTest.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -26,7 +27,7 @@ class FilesystemStorageTest extends \PHPUnit_Framework_TestCase public function testUpload() { - $payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true); + $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true)); $storage = new FilesystemStorage($this->directory); $storage->upload($payload, 'notsogrumpyanymore.jpeg'); diff --git a/Tests/Uploader/Storage/GaufretteStorageTest.php b/Tests/Uploader/Storage/GaufretteStorageTest.php index f9ecfe6..008e618 100644 --- a/Tests/Uploader/Storage/GaufretteStorageTest.php +++ b/Tests/Uploader/Storage/GaufretteStorageTest.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -33,7 +34,7 @@ class GaufretteStorageTest extends \PHPUnit_Framework_TestCase public function testUpload() { - $payload = new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true); + $payload = new FilesystemFile(new UploadedFile($this->file, 'grumpycat.jpeg', null, null, null, true)); $this->storage->upload($payload, 'notsogrumpyanymore.jpeg'); $finder = new Finder(); diff --git a/Tests/Uploader/Storage/OrphanageStorageTest.php b/Tests/Uploader/Storage/OrphanageStorageTest.php index bcaf525..b2eed0a 100644 --- a/Tests/Uploader/Storage/OrphanageStorageTest.php +++ b/Tests/Uploader/Storage/OrphanageStorageTest.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -39,7 +40,7 @@ class OrphanageStorageTest extends \PHPUnit_Framework_TestCase fwrite($pointer, str_repeat('A', 1024), 1024); fclose($pointer); - $this->payloads[] = new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true); + $this->payloads[] = new FilesystemFile(new UploadedFile($file, $i . 'grumpycat.jpeg', null, null, null, true)); } // create underlying storage diff --git a/Uploader/File/FilesystemFile.php b/Uploader/File/FilesystemFile.php index c24ba28..539df73 100644 --- a/Uploader/File/FilesystemFile.php +++ b/Uploader/File/FilesystemFile.php @@ -2,21 +2,23 @@ namespace Oneup\UploaderBundle\Uploader\File; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; class FilesystemFile extends UploadedFile implements FileInterface { - public function __construct(UploadedFile $file) + public function __construct(File $file) { - parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true); + if ($file instanceof UploadedFile) { + parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true); + } else { + parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true); + } } public function getExtension() { - // If the file is in tmp, it has no extension, but the wrapper object - // will have the original extension, otherwise it is better to rely - // on the actual extension - return parent::getExtension() ? :$this->getClientOriginalExtension(); + return $this->getClientOriginalExtension(); } } diff --git a/Uploader/Storage/FilesystemStorage.php b/Uploader/Storage/FilesystemStorage.php index f2613bf..ce62631 100644 --- a/Uploader/Storage/FilesystemStorage.php +++ b/Uploader/Storage/FilesystemStorage.php @@ -2,7 +2,7 @@ namespace Oneup\UploaderBundle\Uploader\Storage; -use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use Oneup\UploaderBundle\Uploader\File\FileInterface; class FilesystemStorage implements StorageInterface { @@ -13,7 +13,7 @@ class FilesystemStorage implements StorageInterface $this->directory = $directory; } - public function upload($file, $name, $path = null) + public function upload(FileInterface $file, $name, $path = null) { $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name); $path = sprintf('%s/%s', $this->directory, $path); diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index 1c0bc9c..f1ae5bd 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -12,14 +12,14 @@ class GaufretteStorage extends StreamManager implements StorageInterface { protected $streamWrapperPrefix; - public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix) + public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix = null) { $this->filesystem = $filesystem; $this->bufferSize = $bufferSize; $this->streamWrapperPrefix = $streamWrapperPrefix; } - public function upload($file, $name, $path = null) + public function upload(FileInterface $file, $name, $path = null) { $path = is_null($path) ? $name : sprintf('%s/%s', $path, $name); diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index ffdd2ae..22656aa 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -29,7 +29,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte $this->type = $type; } - public function upload($file, $name, $path = null) + public function upload(FileInterface $file, $name, $path = null) { if(!$this->session->isStarted()) throw new \RuntimeException('You need a running session in order to run the Orphanage.'); @@ -44,7 +44,7 @@ class OrphanageStorage extends FilesystemStorage implements OrphanageStorageInte $return = array(); foreach ($files as $file) { - $return[] = $this->storage->upload(new File($file->getPathname()), str_replace($this->getFindPath(), '', $file)); + $return[] = $this->storage->upload(new FilesystemFile(new File($file->getPathname())), str_replace($this->getFindPath(), '', $file)); } return $return; diff --git a/Uploader/Storage/StorageInterface.php b/Uploader/Storage/StorageInterface.php index 0c7e4b5..31665d8 100644 --- a/Uploader/Storage/StorageInterface.php +++ b/Uploader/Storage/StorageInterface.php @@ -9,9 +9,9 @@ interface StorageInterface /** * Uploads a File instance to the configured storage. * - * @param $file - * @param string $name - * @param string $path + * @param $file + * @param string $name + * @param string $path */ - public function upload($file, $name, $path = null); + public function upload(FileInterface $file, $name, $path = null); }
0
796f27f46fa2fd69583d46e2b1f6386d7566b023
1up-lab
OneupUploaderBundle
Merge pull request #34 from dirkluijk/patch-1 Renamed chunk_manager to chunks
commit 796f27f46fa2fd69583d46e2b1f6386d7566b023 Merge: c4b7367 b0e8666 Author: Jim Schmid <[email protected]> Date: Wed Jul 24 07:20:52 2013 -0700 Merge pull request #34 from dirkluijk/patch-1 Renamed chunk_manager to chunks
0
f3871241d648434f39310e95fcf1e442b28280a7
1up-lab
OneupUploaderBundle
Fixed the two bundled commands for clearing chunks and orphans.
commit f3871241d648434f39310e95fcf1e442b28280a7 Author: Jim Schmid <[email protected]> Date: Fri Apr 5 19:26:06 2013 +0200 Fixed the two bundled commands for clearing chunks and orphans. diff --git a/Command/ClearChunkCommand.php b/Command/ClearChunkCommand.php index 50bca9f..f1df091 100644 --- a/Command/ClearChunkCommand.php +++ b/Command/ClearChunkCommand.php @@ -18,7 +18,7 @@ class ClearChunkCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { - $manager = $this->getContainer()->get('oneup_uploader.chunks.manager'); + $manager = $this->getContainer()->get('oneup_uploader.chunk_manager'); $manager->clear(); } } \ No newline at end of file diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index 50b11cf..dc1e83c 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -102,7 +102,7 @@ class UploaderController implements UploadControllerInterface // 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); - + die(); // assemble parts $assembled = $chunkManager->assembleChunks($chunks); $path = $assembled->getPath(); diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index c252a84..0f9d511 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -23,6 +23,7 @@ <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%"> <argument type="service" id="service_container" /> + <argument>%oneup_uploader.orphanage%</argument> </service> <!-- namer --> diff --git a/Uploader/Chunk/ChunkManager.php b/Uploader/Chunk/ChunkManager.php index 90c48ef..b35f5f9 100644 --- a/Uploader/Chunk/ChunkManager.php +++ b/Uploader/Chunk/ChunkManager.php @@ -29,7 +29,7 @@ class ChunkManager implements ChunkManagerInterface try { - $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds'); + $finder->in($this->configuration['directory'])->date('<=' . -1 * (int) $this->configuration['maxage'] . 'seconds')->files(); } catch(\InvalidArgumentException $e) { diff --git a/Uploader/Orphanage/OrphanageManager.php b/Uploader/Orphanage/OrphanageManager.php index 9381aa6..053200f 100644 --- a/Uploader/Orphanage/OrphanageManager.php +++ b/Uploader/Orphanage/OrphanageManager.php @@ -2,17 +2,46 @@ namespace Oneup\UploaderBundle\Uploader\Orphanage; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\DependencyInjection\ContainerInterface; class OrphanageManager { - public function __construct(ContainerInterface $container) + protected $config; + protected $container; + + public function __construct(ContainerInterface $container, array $config) { $this->container = $container; + $this->config = $config; } public function get($key) { return $this->container->get(sprintf('oneup_uploader.orphanage.%s', $key)); } + + public function clear() + { + $system = new Filesystem(); + $finder = new Finder(); + + try + { + $finder->in($this->config['directory'])->date('<=' . -1 * (int) $this->config['maxage'] . 'seconds')->files(); + } + catch(\InvalidArgumentException $e) + { + // the finder will throw an exception of type InvalidArgumentException + // if the directory he should search in does not exist + // in that case we don't have anything to clean + return; + } + + foreach($finder as $file) + { + $system->remove($file); + } + } } \ No newline at end of file
0
676ef153a7ed0607e1ca777cf8bd67e76aa1ee7b
1up-lab
OneupUploaderBundle
Added configuration reference file and link from index.md
commit 676ef153a7ed0607e1ca777cf8bd67e76aa1ee7b Author: Jim Schmid <[email protected]> Date: Sun Apr 7 13:07:56 2013 +0200 Added configuration reference file and link from index.md diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md new file mode 100644 index 0000000..e69de29 diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 0fec11f..05a27f0 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -95,4 +95,11 @@ $(document).ready(function() <div id="uploader"></div> ``` -This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them. \ No newline at end of file +This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them. + +## Next steps + +After installing and setting up the basic functionality of this bundle you can move on and integrate +some more advanced features. + +* [Configuration Reference](configuration_reference.md) \ No newline at end of file
0
499cd9e4d3c86cd0db30a46b69628552fdd954ba
1up-lab
OneupUploaderBundle
Allow EventDispatcher component to have version >=2.0.16,<2.3-dev
commit 499cd9e4d3c86cd0db30a46b69628552fdd954ba Author: Jim Schmid <[email protected]> Date: Thu Mar 14 16:57:35 2013 +0100 Allow EventDispatcher component to have version >=2.0.16,<2.3-dev diff --git a/composer.json b/composer.json index 6d97b50..f9fa6d5 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require": { "symfony/finder": ">=2.0.16,<2.3-dev", "symfony/filesystem": ">=2.0.16,<2.3-dev", - "symfony/event-dispatcher": "2.2.*", + "symfony/event-dispatcher": ">=2.0.16,<2.3-dev", "knplabs/knp-gaufrette-bundle": "0.1.*", "valums/file-uploader": "3.3.*" },
0
f812b78d203429f133eebb8bf3188cebf6628097
1up-lab
OneupUploaderBundle
Added configure and clean-up sections to chunked_uploads documentation.
commit f812b78d203429f133eebb8bf3188cebf6628097 Author: Jim Schmid <[email protected]> Date: Sun Apr 7 19:45:58 2013 +0200 Added configure and clean-up sections to chunked_uploads documentation. diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index c4b7861..bd1238b 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -1,6 +1,8 @@ Using Chunked Uploads ===================== +## Enable + Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. ```js @@ -21,4 +23,25 @@ $(document).ready(function() The `partSize` property defines the maximum size of a blob, in this case 10MB. -> Be sure to select a partSize that fits your requirement. If it is too small, the speed of the overall upload drops significantly. \ No newline at end of file +> Be sure to select a partSize that fits your requirement. If it is too small, the speed of the overall upload drops significantly. + +## Configure + +You can configure the `ChunkManager` by using the following configuration parameters. + +``` +oneup_uploader: + chunk_manager: + maxage: 86400 + directory: %kernel.cache_dir%/uploader/chunks +``` + +You can choose a custom directory to save the chunks temporarily while uploading by changing the parameter `directory`. + +## Clean up + +The ChunkManager can be forced to clean up old and orphanaged chunks by using the command provided by the OneupUploaderBundle. + + $> php app/console oneup:uploader:clean-chunks + +This parameter will clean all chunk files older than the `maxage` value in your configuration.
0
83371099464ab15eb9988a82b5012bec2341dade
1up-lab
OneupUploaderBundle
Refactored controller test environment.
commit 83371099464ab15eb9988a82b5012bec2341dade Author: Jim Schmid <[email protected]> Date: Sat May 4 10:20:14 2013 +0200 Refactored controller test environment. diff --git a/.gitignore b/.gitignore index 820d851..7c766c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ composer.lock phpunit.xml vendor log +Tests/App/cache +Tests/App/logs \ No newline at end of file diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php new file mode 100644 index 0000000..2e39ab8 --- /dev/null +++ b/Tests/App/AppKernel.php @@ -0,0 +1,28 @@ +<?php + +use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Config\Loader\LoaderInterface; + +class AppKernel extends Kernel +{ + public function registerBundles() + { + $bundles = array( + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\MonologBundle\MonologBundle(), + new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new JMS\SerializerBundle\JMSSerializerBundle($this), + + // bundle to test + new Oneup\UploaderBundle\OneupUploaderBundle(), + ); + + return $bundles; + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(__DIR__.'/config/config.yml'); + } +} diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml new file mode 100644 index 0000000..d61f898 --- /dev/null +++ b/Tests/App/config/config.yml @@ -0,0 +1,33 @@ +framework: + #esi: ~ + translator: { fallback: en } + secret: secret + router: + resource: "%kernel.root_dir%/config/routing.yml" + strict_requirements: %kernel.debug% + form: ~ + csrf_protection: ~ + validation: { enable_annotations: true } + templating: + engines: ['php'] + #assets_version: SomeVersionScheme + default_locale: en + trusted_proxies: ~ + session: ~ + fragments: ~ + test: ~ + +monolog: + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + nested: + type: stream + path: %kernel.logs_dir%/%kernel.environment%.log + level: debug + +oneup_uploader: + mappings: + gallery: ~ \ No newline at end of file diff --git a/Tests/App/config/routing.yml b/Tests/App/config/routing.yml new file mode 100644 index 0000000..71cd825 --- /dev/null +++ b/Tests/App/config/routing.yml @@ -0,0 +1,3 @@ +oneup_uploader: + resource: . + type: uploader \ No newline at end of file diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 1f4f67c..5b67409 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,8 +1,22 @@ <?php -$file = __DIR__.'/../vendor/autoload.php'; -if (!file_exists($file)) { - throw new RuntimeException('Install dependencies to run test suite.'); +$loader = @include __DIR__ . '/../vendor/autoload.php'; +if (!$loader) { + die(<<<'EOT' +You must set up the project dependencies, run the following commands: +wget http://getcomposer.org/composer.phar +php composer.phar install +EOT + ); } -$autoload = require_once $file; \ No newline at end of file +spl_autoload_register(function($class) { + if (0 === strpos($class, 'Oneup\\UploaderBundle\\')) { + $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php'; + if (!stream_resolve_include_path($path)) { + return false; + } + require_once $path; + return true; + } +}); diff --git a/composer.json b/composer.json index b312ae5..6142788 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,16 @@ }, "require-dev": { - "knplabs/gaufrette": "0.2.*@dev" + "knplabs/gaufrette": "0.2.*@dev", + "symfony/class-loader": "dev-master", + "symfony/security-bundle": "dev-master", + "symfony/monolog-bundle": "dev-master", + "sensio/framework-extra-bundle": "dev-master", + "jms/serializer-bundle": "dev-master", + "symfony/yaml": "dev-master", + "symfony/form": "2.*", + "symfony/twig-bundle": "dev-master", + "symfony/browser-kit": "dev-master" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f3c7e3e..07c869d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <phpunit bootstrap="./Tests/bootstrap.php" colors="true"> - + <php> + <server name="KERNEL_DIR" value="Tests/App" /> + </php> + <testsuites> <testsuite name="OneupUploaderBundle test suite"> <directory suffix="Test.php">./Tests</directory>
0
18a7f3194bfd8a451e194410bc24a0620bae3acd
1up-lab
OneupUploaderBundle
Merge pull request #220 from JHGitty/patch-5 Fix typo
commit 18a7f3194bfd8a451e194410bc24a0620bae3acd Merge: f5acda9 fbaf18e Author: David Greminger <[email protected]> Date: Mon Feb 8 08:26:50 2016 +0100 Merge pull request #220 from JHGitty/patch-5 Fix typo
0
18507cfb909f0d0a37b8a49cd0b06c6caa8fe1e6
1up-lab
OneupUploaderBundle
Clear recommendation to test with Dropzone first Please explain the following sentence: "To enable the dynamic routes, add the following to your routing configuration file." Is having dynamic routes mandatory or optional? What are dynamic routes at all?
commit 18507cfb909f0d0a37b8a49cd0b06c6caa8fe1e6 Author: Thomas Landauer <[email protected]> Date: Mon Oct 26 16:00:14 2015 +0100 Clear recommendation to test with Dropzone first Please explain the following sentence: "To enable the dynamic routes, add the following to your routing configuration file." Is having dynamic routes mandatory or optional? What are dynamic routes at all? diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 2e90a51..ac381bc 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -72,7 +72,7 @@ This bundle was designed to just work out of the box. The only thing you have to oneup_uploader: mappings: gallery: - frontend: blueimp # or any uploader you use in the frontend + frontend: dropzone # or any uploader you use in the frontend ``` To enable the dynamic routes, add the following to your routing configuration file. @@ -85,13 +85,19 @@ oneup_uploader: type: uploader ``` -The default directory that is used to upload files to is `web/uploads/{mapping_name}`. +The default directory that is used to upload files to is `web/uploads/{mapping_name}`, where `{mapping_name}` is the value for `mappings` in your `config.yml` (namely `gallery` in the above example). -> It was reported that in some cases this directory was not created automatically. Please double check its existance if the upload does not work for you. +### Step 4: Check if the bundle is working correctly -### Step 4: Prepare your frontend +No matter which JavaScript library you are going to use ultimately, we recommend to test the bundle with Dropzone first, since this one features the easiest setup process: -No matter what library you choose, be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows: +1. [Install Dropzone](frontend_dropzone.md) +1. Drag a file onto the dashed rectangle. The upload should start immediately. However, you won't get any visual feedback yet. +1. Check your `web/uploads/gallery` directory: If you see the file there, the OneupUploaderBundle is working correctly. If you don't have that folder, create it manually and try again. + +### Step 5: Prepare your real frontend + +Now it's up to you to decide for a JavaScript library or write your own. Be sure to connect the corresponding endpoint property to the dynamic route created from your mapping. To get a url for a specific mapping you can use the `oneup_uploader.templating.uploader_helper` service as follows: ```php $helper = $this->container->get('oneup_uploader.templating.uploader_helper');
0
1e91e1e47f1a5e591e0adff95751df44843f9f85
1up-lab
OneupUploaderBundle
Moved the check for a custom error message entirely to the ValidationException.
commit 1e91e1e47f1a5e591e0adff95751df44843f9f85 Author: Jim Schmid <[email protected]> Date: Mon Jul 15 12:00:02 2013 +0200 Moved the check for a custom error message entirely to the ValidationException. diff --git a/Resources/doc/response.md b/Resources/doc/response.md index 60807e6..bfef2ca 100644 --- a/Resources/doc/response.md +++ b/Resources/doc/response.md @@ -32,3 +32,5 @@ $response->setError($msg); ``` > Do not use the keys `success` and `error` if you provide custom data, they will be overwritten by the internal properties of `UploaderResponse`. + +Due to limitations of the `\ArrayAccess` regarding multi-dimensional array access, there is a method `addToOffset` which can be used to attach values to specific pathes in the array. \ No newline at end of file diff --git a/Uploader/ErrorHandler/BlueimpErrorHandler.php b/Uploader/ErrorHandler/BlueimpErrorHandler.php index d9adf89..600d933 100644 --- a/Uploader/ErrorHandler/BlueimpErrorHandler.php +++ b/Uploader/ErrorHandler/BlueimpErrorHandler.php @@ -10,12 +10,7 @@ class BlueimpErrorHandler implements ErrorHandlerInterface { public function addException(ResponseInterface $response, UploadException $exception) { - if ($exception instanceof ValidationException) { - $message = $exception->getErrorMessage(); - } else { - $message = $exception->getMessage(); - } - + $message = $exception->getErrorMessage(); $response->addToOffset(array('error' => $message), array('files')); } }
0
1b544a0d5e188540d578eb783584ecc8bcdda9b7
1up-lab
OneupUploaderBundle
Added Validation test for FancyUpload.
commit 1b544a0d5e188540d578eb783584ecc8bcdda9b7 Author: Jim Schmid <[email protected]> Date: Sat May 18 16:56:04 2013 +0200 Added Validation test for FancyUpload. diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index a7d02f4..fcb884e 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -33,6 +33,15 @@ oneup_uploader: frontend: fancyupload storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload + + fancyupload_validation: + frontend: fancyupload + storage: + directory: %kernel.root_dir%/cache/%kernel.environment%/upload + allowed_extensions: [ "ok" ] + disallowed_extensions: [ "fail" ] + allowed_mimetypes: [ "image/jpg", "text/plain" ] + disallowed_mimetypes: [ "image/gif" ] yui3: frontend: yui3 diff --git a/Tests/Controller/FancyUploadValidationTest.php b/Tests/Controller/FancyUploadValidationTest.php new file mode 100644 index 0000000..1ca342d --- /dev/null +++ b/Tests/Controller/FancyUploadValidationTest.php @@ -0,0 +1,59 @@ +<?php + +namespace Oneup\UploaderBundle\Tests\Controller; + +use Symfony\Component\HttpFoundation\File\UploadedFile; +use Oneup\UploaderBundle\Tests\Controller\AbstractValidationTest; + +class FancyUploadValidationTest extends AbstractValidationTest +{ + protected function getConfigKey() + { + return 'fancyupload_validation'; + } + + protected function getRequestParameters() + { + return array(); + } + + protected function getFileWithCorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'text/plain', + 128 + ); + } + + protected function getFileWithIncorrectExtension() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.fail', + 'text/plain', + 128 + ); + } + + protected function getFileWithCorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/jpg', + 128 + ); + } + + protected function getFileWithIncorrectMimeType() + { + return new UploadedFile( + $this->createTempFile(128), + 'cat.ok', + 'image/gif', + 128 + ); + } +}
0
794f71ee56642fa3f09312cfb86977aa5ff7bd53
1up-lab
OneupUploaderBundle
Symfony4 support (#300) * Symfony 4 support * Add KERNEL_CLASS env in phpunit.xml.dist * Upgrade flysystem-bundle to 3.0 * Require phpunit ^6.5 * Fixed constraints * Also allow phpunit ^4.4 * Removed support for Symfony 2.x, adaptions for Symfony 4
commit 794f71ee56642fa3f09312cfb86977aa5ff7bd53 Author: David Greminger <[email protected]> Date: Mon Dec 4 09:43:43 2017 +0100 Symfony4 support (#300) * Symfony 4 support * Add KERNEL_CLASS env in phpunit.xml.dist * Upgrade flysystem-bundle to 3.0 * Require phpunit ^6.5 * Fixed constraints * Also allow phpunit ^4.4 * Removed support for Symfony 2.x, adaptions for Symfony 4 diff --git a/.travis.yml b/.travis.yml index 15534ea..8a47f8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,8 @@ php: - 7.1 env: - - SYMFONY_VERSION=2.7.* - - SYMFONY_VERSION=2.8.* - - SYMFONY_VERSION=3.3.* + - SYMFONY_VERSION=^3.3 + - SYMFONY_VERSION=^4.0 - SYMFONY_VERSION=dev-master cache: @@ -17,9 +16,14 @@ cache: matrix: allow_failures: - env: SYMFONY_VERSION=dev-master + exclude: + - php: 7.0 + env: SYMFONY_VERSION=^4.0 + - php: 7.0 + env: SYMFONY_VERSION=dev-master before_install: - - composer selfupdate + - travis_retry composer selfupdate before_script: - travis_wait composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 487a972..d8a6e1c 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -209,12 +209,10 @@ abstract class AbstractController */ protected function getRequest() { - if (version_compare(Kernel::VERSION, '2.4', '<=')) { return $this->container->get('request'); } return $this->container->get('request_stack')->getMasterRequest(); } - } diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index 61dc35f..af8af94 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -2,6 +2,7 @@ namespace Oneup\UploaderBundle\DependencyInjection; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -103,15 +104,16 @@ class OneupUploaderExtension extends Extension $controllerName = sprintf('oneup_uploader.controller.%s', $customFrontend['name']); $controllerType = $customFrontend['class']; - if(empty($controllerName) || empty($controllerType)) + if (empty($controllerName) || empty($controllerType)) { throw new ServiceNotFoundException('Empty controller class or name. If you really want to use a custom frontend implementation, be sure to provide a class and a name.'); + } } $errorHandler = $this->createErrorHandler($config); // create controllers based on mapping $this->container - ->register($controllerName, $controllerType) + ->setDefinition($controllerName, (new Definition($controllerType))->setPublic(true)) ->addArgument(new Reference('service_container')) ->addArgument($storageService) @@ -147,7 +149,7 @@ class OneupUploaderExtension extends Extension $storageClass = sprintf('%%oneup_uploader.chunks_storage.%s.class%%', $config['type']); - switch($config['type']) { + switch ($config['type']) { case 'filesystem': $config['directory'] = is_null($config['directory']) ? sprintf('%s/uploader/chunks', $this->container->getParameter('kernel.cache_dir')) : @@ -164,7 +166,8 @@ class OneupUploaderExtension extends Extension $this->registerFilesystem( $config['type'], 'oneup_uploader.chunks_storage', - $storageClass, $config['filesystem'], + $storageClass, + $config['filesystem'], $config['sync_buffer_size'], $config['stream_wrapper'], $config['prefix'] @@ -183,7 +186,6 @@ class OneupUploaderExtension extends Extension throw new \InvalidArgumentException(sprintf('Filesystem "%s" is invalid', $config['type'])); break; } - } protected function createStorageService(&$config, $key, $orphanage = false) @@ -268,8 +270,9 @@ class OneupUploaderExtension extends Extension break; } - if (strlen($filesystem) <= 0) + if (strlen($filesystem) <= 0) { throw new ServiceNotFoundException('Empty service name'); + } $streamWrapper = $this->normalizeStreamWrapper($streamWrapper); @@ -299,7 +302,9 @@ class OneupUploaderExtension extends Extension switch ($last) { case 'g': $numericInput *= 1024; + // no break case 'm': $numericInput *= 1024; + // no break case 'k': $numericInput *= 1024; return $numericInput; diff --git a/Resources/config/templating.xml b/Resources/config/templating.xml index a53e1f8..8a80df7 100644 --- a/Resources/config/templating.xml +++ b/Resources/config/templating.xml @@ -6,7 +6,7 @@ <services> - <service id="oneup_uploader.templating.uploader_helper" class="Oneup\UploaderBundle\Templating\Helper\UploaderHelper"> + <service id="oneup_uploader.templating.uploader_helper" class="Oneup\UploaderBundle\Templating\Helper\UploaderHelper" public="true"> <argument type="service" id="router" /> <argument>%oneup_uploader.maxsize%</argument> <tag name="templating.helper" alias="oneup_uploader" /> diff --git a/Resources/config/uploader.xml b/Resources/config/uploader.xml index 4389640..1ab7116 100644 --- a/Resources/config/uploader.xml +++ b/Resources/config/uploader.xml @@ -29,22 +29,22 @@ <services> <!-- managers --> - <service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%"> + <service id="oneup_uploader.chunk_manager" class="%oneup_uploader.chunks.manager.class%" public="true"> <argument>%oneup_uploader.chunks%</argument> <argument type="service" id="oneup_uploader.chunks_storage" /> </service> - <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%"> + <service id="oneup_uploader.orphanage_manager" class="%oneup_uploader.orphanage.manager.class%" public="true"> <argument type="service" id="service_container" /> <argument>%oneup_uploader.orphanage%</argument> </service> <!-- namer --> - <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" /> + <service id="oneup_uploader.namer.uniqid" class="%oneup_uploader.namer.uniqid.class%" public="true"/> <service id="oneup_uploader.namer.urlsafe" class="%oneup_uploader.namer.urlsafename.class%" /> <!-- routing --> - <service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%"> + <service id="oneup_uploader.routing.loader" class="%oneup_uploader.routing.loader.class%" public="true"> <argument>%oneup_uploader.controllers%</argument> <tag name="routing.loader" /> </service> diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index 6dbdc4a..9e076cb 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -25,7 +25,6 @@ class RouteLoader extends Loader $routes = new RouteCollection(); foreach ($this->controllers as $type => $controllerArray) { - $service = $controllerArray[0]; $options = $controllerArray[1]; diff --git a/Tests/App/AppKernel.php b/Tests/App/AppKernel.php index f1aa6f0..4b82ab1 100644 --- a/Tests/App/AppKernel.php +++ b/Tests/App/AppKernel.php @@ -1,5 +1,9 @@ <?php +use Oneup\UploaderBundle\OneupUploaderBundle; +use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\SecurityBundle\SecurityBundle; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; @@ -8,12 +12,12 @@ class AppKernel extends Kernel public function registerBundles() { $bundles = array( - new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new Symfony\Bundle\SecurityBundle\SecurityBundle(), - new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new FrameworkBundle(), + new SecurityBundle(), + new SensioFrameworkExtraBundle(), // bundle to test - new Oneup\UploaderBundle\OneupUploaderBundle(), + new OneupUploaderBundle(), ); return $bundles; diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 382b566..1db4696 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -3,7 +3,7 @@ framework: secret: secret router: resource: "%kernel.root_dir%/config/routing.yml" - strict_requirements: %kernel.debug% + strict_requirements: "%kernel.debug%" templating: engines: ['php'] default_locale: en @@ -16,13 +16,13 @@ oneup_uploader: fineuploader: frontend: fineuploader storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" fineuploader_validation: frontend: fineuploader max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -33,13 +33,13 @@ oneup_uploader: fancyupload: frontend: fancyupload storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" fancyupload_validation: frontend: fancyupload max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -49,13 +49,13 @@ oneup_uploader: dropzone: frontend: dropzone storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" dropzone_validation: frontend: dropzone max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -65,13 +65,13 @@ oneup_uploader: yui3: frontend: yui3 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" yui3_validation: frontend: yui3 max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -81,13 +81,13 @@ oneup_uploader: plupload: frontend: plupload storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" plupload_validation: frontend: plupload max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -97,13 +97,13 @@ oneup_uploader: uploadify: frontend: uploadify storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" uploadify_validation: frontend: uploadify max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" allowed_mimetypes: image/jpeg : ['jpg', 'jpeg', 'jpe'] @@ -113,14 +113,14 @@ oneup_uploader: blueimp: frontend: blueimp storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" error_handler: oneup_uploader.error_handler.blueimp blueimp_validation: frontend: blueimp max_size: 256 storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" error_handler: oneup_uploader.error_handler.blueimp allowed_mimetypes: @@ -131,4 +131,4 @@ oneup_uploader: mooupload: frontend: mooupload storage: - directory: %kernel.root_dir%/cache/%kernel.environment%/upload + directory: "%kernel.root_dir%/cache/%kernel.environment%/upload" diff --git a/Tests/Controller/AbstractChunkedUploadTest.php b/Tests/Controller/AbstractChunkedUploadTest.php index e3566d6..7409acb 100644 --- a/Tests/Controller/AbstractChunkedUploadTest.php +++ b/Tests/Controller/AbstractChunkedUploadTest.php @@ -34,7 +34,7 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest $client = static::createClient(); $dispatcher = $client->getContainer()->get('event_dispatcher'); - $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function(PreUploadEvent $event) use (&$me, $basename) { + $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function (PreUploadEvent $event) use (&$me, $basename) { $file = $event->getFile(); $me->assertNotNull($file->getClientSize()); @@ -42,7 +42,7 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest $me->assertEquals($file->getBasename(), $basename); }); - $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount) { + $dispatcher->addListener(UploadEvents::VALIDATION, function (ValidationEvent $event) use (&$validationCount) { ++ $validationCount; }); @@ -77,7 +77,7 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest $client = static::createClient(); $dispatcher = $client->getContainer()->get('event_dispatcher'); - $dispatcher->addListener(UploadEvents::POST_CHUNK_UPLOAD, function(PostChunkUploadEvent $event) use (&$chunkCount, $chunkSize, &$me) { + $dispatcher->addListener(UploadEvents::POST_CHUNK_UPLOAD, function (PostChunkUploadEvent $event) use (&$chunkCount, $chunkSize, &$me) { ++ $chunkCount; $chunk = $event->getChunk(); @@ -85,7 +85,7 @@ abstract class AbstractChunkedUploadTest extends AbstractUploadTest $me->assertEquals($chunkSize, $chunk->getSize()); }); - $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(Event $event) use (&$uploadCount) { + $dispatcher->addListener(UploadEvents::POST_UPLOAD, function (Event $event) use (&$uploadCount) { ++ $uploadCount; }); diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index 2b0abf7..654642f 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -2,16 +2,27 @@ namespace Oneup\UploaderBundle\Tests\Controller; +use Oneup\UploaderBundle\Templating\Helper\UploaderHelper; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Component\Finder\Finder; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; abstract class AbstractControllerTest extends WebTestCase { protected $createdFiles; + + /** + * @var Client + */ protected $client; protected $container; protected $requestHeaders; + /** + * @var UploaderHelper + */ + protected $helper; + public function setUp() { $this->client = static::createClient(); diff --git a/Tests/Controller/AbstractUploadTest.php b/Tests/Controller/AbstractUploadTest.php index dd98b5e..4908c34 100644 --- a/Tests/Controller/AbstractUploadTest.php +++ b/Tests/Controller/AbstractUploadTest.php @@ -50,7 +50,7 @@ abstract class AbstractUploadTest extends AbstractControllerTest $uploadCount = 0; $preValidation = 1; - $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function(PreUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { + $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function (PreUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { $preValidation -= 2; $file = $event->getFile(); @@ -62,7 +62,7 @@ abstract class AbstractUploadTest extends AbstractControllerTest $me->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $file); }); - $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(PostUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { + $dispatcher->addListener(UploadEvents::POST_UPLOAD, function (PostUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { ++ $uploadCount; $preValidation *= -1; diff --git a/Tests/Controller/AbstractValidationTest.php b/Tests/Controller/AbstractValidationTest.php index fee2f35..58b7bc7 100644 --- a/Tests/Controller/AbstractValidationTest.php +++ b/Tests/Controller/AbstractValidationTest.php @@ -35,7 +35,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest // event data $validationCount = 0; - $dispatcher->addListener(UploadEvents::VALIDATION, function() use (&$validationCount) { + $dispatcher->addListener(UploadEvents::VALIDATION, function () use (&$validationCount) { ++ $validationCount; }); @@ -54,7 +54,7 @@ abstract class AbstractValidationTest extends AbstractControllerTest $validationCount = 0; $me = $this; - $dispatcher->addListener(UploadEvents::VALIDATION, function(ValidationEvent $event) use (&$validationCount, &$me) { + $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 diff --git a/Tests/Controller/BlueimpTest.php b/Tests/Controller/BlueimpTest.php index b9c3f82..9573836 100644 --- a/Tests/Controller/BlueimpTest.php +++ b/Tests/Controller/BlueimpTest.php @@ -3,7 +3,6 @@ namespace Oneup\UploaderBundle\Tests\Controller; use Symfony\Component\HttpFoundation\File\UploadedFile; -use Oneup\UploaderBundle\Tests\Controller\AbstractUploadTest; use Oneup\UploaderBundle\UploadEvents; use Oneup\UploaderBundle\Event\PreUploadEvent; use Oneup\UploaderBundle\Event\PostUploadEvent; @@ -54,7 +53,7 @@ class BlueimpTest extends AbstractUploadTest $uploadCount = 0; $preValidation = 1; - $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function(PreUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { + $dispatcher->addListener(UploadEvents::PRE_UPLOAD, function (PreUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { $preValidation -= 2; $file = $event->getFile(); @@ -66,7 +65,7 @@ class BlueimpTest extends AbstractUploadTest $me->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $file); }); - $dispatcher->addListener(UploadEvents::POST_UPLOAD, function(PostUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { + $dispatcher->addListener(UploadEvents::POST_UPLOAD, function (PostUploadEvent $event) use (&$uploadCount, &$me, &$preValidation) { ++ $uploadCount; $preValidation *= -1; diff --git a/Tests/Controller/BlueimpValidationTest.php b/Tests/Controller/BlueimpValidationTest.php index ca8c8bd..c2e95eb 100644 --- a/Tests/Controller/BlueimpValidationTest.php +++ b/Tests/Controller/BlueimpValidationTest.php @@ -34,7 +34,7 @@ class BlueimpValidationTest extends AbstractValidationTest // event data $validationCount = 0; - $dispatcher->addListener(UploadEvents::VALIDATION, function() use (&$validationCount) { + $dispatcher->addListener(UploadEvents::VALIDATION, function () use (&$validationCount) { ++ $validationCount; }); diff --git a/Tests/Controller/FileBagExtractorTest.php b/Tests/Controller/FileBagExtractorTest.php index e757ebb..b50f16e 100644 --- a/Tests/Controller/FileBagExtractorTest.php +++ b/Tests/Controller/FileBagExtractorTest.php @@ -2,10 +2,11 @@ namespace Oneup\UploaderBundle\Tests\Controller; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\FileBag; -class FileBagExtractorText extends \PHPUnit_Framework_TestCase +class FileBagExtractorText extends TestCase { protected $method; protected $mock; diff --git a/Tests/DependencyInjection/OneupUploaderExtensionTest.php b/Tests/DependencyInjection/OneupUploaderExtensionTest.php index 85ac094..a7f8a1d 100644 --- a/Tests/DependencyInjection/OneupUploaderExtensionTest.php +++ b/Tests/DependencyInjection/OneupUploaderExtensionTest.php @@ -2,7 +2,9 @@ namespace Oneup\UploaderBundle\Tests\DependencyInjection; -class OneupUploaderExtensionTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +class OneupUploaderExtensionTest extends TestCase { public function testValueToByteTransformer() { diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php index d462101..115334a 100644 --- a/Tests/Routing/RouteLoaderTest.php +++ b/Tests/Routing/RouteLoaderTest.php @@ -3,8 +3,9 @@ namespace Oneup\UploaderBundle\Tests\Routing; use Oneup\UploaderBundle\Routing\RouteLoader; +use PHPUnit\Framework\TestCase; -class RouteLoaderTest extends \PHPUnit_Framework_TestCase +class RouteLoaderTest extends TestCase { public function testRouteLoader() { diff --git a/Tests/Templating/TemplateHelperTest.php b/Tests/Templating/TemplateHelperTest.php index eda82e9..9ec74b1 100644 --- a/Tests/Templating/TemplateHelperTest.php +++ b/Tests/Templating/TemplateHelperTest.php @@ -19,7 +19,7 @@ class TemplateHelperTest extends WebTestCase public function testNonExistentMappingForMaxSize() { - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException('\InvalidArgumentException'); $client = static::createClient(); $container = $client->getContainer(); diff --git a/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php index ca14e11..23d8b2d 100644 --- a/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php +++ b/Tests/Uploader/Chunk/Storage/ChunkStorageTest.php @@ -3,10 +3,11 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Chunk\Storage; use Oneup\UploaderBundle\Uploader\Chunk\Storage\ChunkStorageInterface; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; -abstract class ChunkStorageTest extends \PHPUnit_Framework_TestCase +abstract class ChunkStorageTest extends TestCase { protected $tmpDir; /** diff --git a/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php b/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php index 375d450..6ade0b7 100644 --- a/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php +++ b/Tests/Uploader/Chunk/Storage/GaufretteStorageTest.php @@ -31,7 +31,6 @@ class GaufretteStorageTest extends ChunkStorageTest $this->tmpDir = $this->parentDir.'/'.$this->chunkKey; $system->mkdir($this->tmpDir); - } public function tearDown() @@ -39,5 +38,4 @@ class GaufretteStorageTest extends ChunkStorageTest $system = new Filesystem(); $system->remove($this->parentDir); } - } diff --git a/Tests/Uploader/File/FileTest.php b/Tests/Uploader/File/FileTest.php index 2753089..bb7f573 100644 --- a/Tests/Uploader/File/FileTest.php +++ b/Tests/Uploader/File/FileTest.php @@ -1,7 +1,9 @@ <?php namespace Oneup\UploaderBundle\Tests\Uploader\File; -abstract class FileTest extends \PHPUnit_Framework_TestCase +use PHPUnit\Framework\TestCase; + +abstract class FileTest extends TestCase { protected $file; protected $pathname; diff --git a/Tests/Uploader/Naming/UniqidNamerTest.php b/Tests/Uploader/Naming/UniqidNamerTest.php index 38c9b75..a389b2d 100644 --- a/Tests/Uploader/Naming/UniqidNamerTest.php +++ b/Tests/Uploader/Naming/UniqidNamerTest.php @@ -3,8 +3,9 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Naming; use Oneup\UploaderBundle\Uploader\Naming\UniqidNamer; +use PHPUnit\Framework\TestCase; -class UniqidNamerTest extends \PHPUnit_Framework_TestCase +class UniqidNamerTest extends TestCase { public function testNamerReturnsName() { diff --git a/Tests/Uploader/Naming/UrlSafeNamerTest.php b/Tests/Uploader/Naming/UrlSafeNamerTest.php index 1707940..fa7aa89 100644 --- a/Tests/Uploader/Naming/UrlSafeNamerTest.php +++ b/Tests/Uploader/Naming/UrlSafeNamerTest.php @@ -8,7 +8,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; class UrlSafeNamerTest extends FileTest { - public function setUp() { $this->path = sys_get_temp_dir(). '/oneup_namer_test'; @@ -36,12 +35,11 @@ class UrlSafeNamerTest extends FileTest { $namer = new UrlSafeNamer(); // Trying 200 times just to be sure - for($i = 0; $i < 200; $i++) { + for ($i = 0; $i < 200; $i++) { $name1 = $namer->name($this->file); $name2 = $namer->name($this->file); $this->assertNotEquals($name1, $name2); } - } public function tearDown() @@ -49,5 +47,4 @@ class UrlSafeNamerTest extends FileTest unlink($this->pathname); rmdir($this->path); } - } diff --git a/Tests/Uploader/Orphanage/OrphanageManagerTest.php b/Tests/Uploader/Orphanage/OrphanageManagerTest.php index c81cb88..6ed9c97 100644 --- a/Tests/Uploader/Orphanage/OrphanageManagerTest.php +++ b/Tests/Uploader/Orphanage/OrphanageManagerTest.php @@ -2,11 +2,12 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Orphanage; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageManager; -class OrphanageManagerTest extends \PHPUnit_Framework_TestCase +class OrphanageManagerTest extends TestCase { protected $numberOfOrphans; protected $orphanagePath; @@ -89,7 +90,7 @@ class OrphanageManagerTest extends \PHPUnit_Framework_TestCase protected function getContainerMock() { - $mock = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $mock = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); $mock ->expects($this->any()) ->method('get') diff --git a/Tests/Uploader/Response/EmptyResponseTest.php b/Tests/Uploader/Response/EmptyResponseTest.php index 6bbef6f..be2c959 100644 --- a/Tests/Uploader/Response/EmptyResponseTest.php +++ b/Tests/Uploader/Response/EmptyResponseTest.php @@ -3,8 +3,9 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Response; use Oneup\UploaderBundle\Uploader\Response\EmptyResponse; +use PHPUnit\Framework\TestCase; -class TestEmptyResponse extends \PHPUnit_Framework_TestCase +class TestEmptyResponse extends TestCase { public function testEmpty() { diff --git a/Tests/Uploader/Response/FineUploaderResponseTest.php b/Tests/Uploader/Response/FineUploaderResponseTest.php index 1190669..463bf44 100644 --- a/Tests/Uploader/Response/FineUploaderResponseTest.php +++ b/Tests/Uploader/Response/FineUploaderResponseTest.php @@ -3,8 +3,9 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Response; use Oneup\UploaderBundle\Uploader\Response\FineUploaderResponse; +use PHPUnit\Framework\TestCase; -class TestFineUploaderResponse extends \PHPUnit_Framework_TestCase +class TestFineUploaderResponse extends TestCase { public function testCreationOfResponse() { diff --git a/Tests/Uploader/Response/MooUploadResponseTest.php b/Tests/Uploader/Response/MooUploadResponseTest.php index 41295bb..059991f 100644 --- a/Tests/Uploader/Response/MooUploadResponseTest.php +++ b/Tests/Uploader/Response/MooUploadResponseTest.php @@ -3,8 +3,9 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Response; use Oneup\UploaderBundle\Uploader\Response\MooUploadResponse; +use PHPUnit\Framework\TestCase; -class MooUploadResponseTest extends \PHPUnit_Framework_TestCase +class MooUploadResponseTest extends TestCase { public function testCreationOfResponse() { @@ -61,7 +62,6 @@ class MooUploadResponseTest extends \PHPUnit_Framework_TestCase public function testAssemble() { - $response = new MooUploadResponse(); $response->setId(3); $response->setName('grumpy_cat.jpg'); diff --git a/Tests/Uploader/Storage/FilesystemStorageTest.php b/Tests/Uploader/Storage/FilesystemStorageTest.php index 1ae9964..82ec674 100644 --- a/Tests/Uploader/Storage/FilesystemStorageTest.php +++ b/Tests/Uploader/Storage/FilesystemStorageTest.php @@ -3,12 +3,13 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; use Oneup\UploaderBundle\Uploader\Storage\FilesystemStorage; -class FilesystemStorageTest extends \PHPUnit_Framework_TestCase +class FilesystemStorageTest extends TestCase { protected $directory; protected $file; diff --git a/Tests/Uploader/Storage/FlysystemStorageTest.php b/Tests/Uploader/Storage/FlysystemStorageTest.php index 121a7ec..0105dbf 100644 --- a/Tests/Uploader/Storage/FlysystemStorageTest.php +++ b/Tests/Uploader/Storage/FlysystemStorageTest.php @@ -6,11 +6,12 @@ use League\Flysystem\Adapter\Local as Adapter; use League\Flysystem\Filesystem as FSAdapter; use Oneup\UploaderBundle\Uploader\File\FilesystemFile; use Oneup\UploaderBundle\Uploader\Storage\FlysystemStorage as Storage; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; -class FlysystemStorageTest extends \PHPUnit_Framework_TestCase +class FlysystemStorageTest extends TestCase { protected $directory; diff --git a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php index e915501..e1b970d 100644 --- a/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php +++ b/Tests/Uploader/Storage/GaufretteAmazonS3StorageTest.php @@ -3,20 +3,21 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; use \AmazonS3 as AmazonClient; +use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; use Gaufrette\Filesystem as GaufretteFilesystem; use Gaufrette\Adapter\AmazonS3 as S3Adapter; use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage; -class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase +class GaufretteAmazonS3StorageTest extends TestCase { protected $directory; protected $storage; public function setUp() { - if( + if ( "" == getenv('AWS_ACCESS_KEY_ID') || "" == getenv('AWS_SECRET_ACCESS_KEY') || "" == getenv('AWS_BUCKET') @@ -58,12 +59,12 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase $this->assertCount(2, $files['keys']); foreach ($files['keys'] as $filename) { - if ($filename === $this->prefix) { - // ignore the prefix directory - continue; - } - $this->assertEquals($this->prefix. '/notsogrumpyanymore.jpeg', $filename); - $this->assertEquals(1024, strlen($this->filesystem->read($filename))); + if ($filename === $this->prefix) { + // ignore the prefix directory + continue; + } + $this->assertEquals($this->prefix. '/notsogrumpyanymore.jpeg', $filename); + $this->assertEquals(1024, strlen($this->filesystem->read($filename))); } } @@ -71,9 +72,9 @@ class GaufretteAmazonS3StorageTest extends \PHPUnit_Framework_TestCase { $files = $this->filesystem->listKeys($this->prefix); foreach ($files['keys'] as $filename) { - if ($this->filesystem->has($filename)) { - $this->filesystem->delete($filename); - } + if ($this->filesystem->has($filename)) { + $this->filesystem->delete($filename); + } } } } diff --git a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php index a9e55cb..92e2d70 100644 --- a/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php +++ b/Tests/Uploader/Storage/GaufretteOrphanageStorageTest.php @@ -1,6 +1,7 @@ <?php namespace Oneup\UploaderBundle\Tests\Uploader\Storage; + use Gaufrette\File; use Gaufrette\Filesystem as GaufretteFilesystem; diff --git a/Tests/Uploader/Storage/GaufretteStorageTest.php b/Tests/Uploader/Storage/GaufretteStorageTest.php index 008e618..742f5c5 100644 --- a/Tests/Uploader/Storage/GaufretteStorageTest.php +++ b/Tests/Uploader/Storage/GaufretteStorageTest.php @@ -3,6 +3,7 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\File\UploadedFile; @@ -10,7 +11,7 @@ use Gaufrette\Filesystem as GaufretteFilesystem; use Gaufrette\Adapter\Local as Adapter; use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage; -class GaufretteStorageTest extends \PHPUnit_Framework_TestCase +class GaufretteStorageTest extends TestCase { protected $directory; protected $storage; diff --git a/Tests/Uploader/Storage/OrphanageTest.php b/Tests/Uploader/Storage/OrphanageTest.php index c539e7f..adfe7f8 100644 --- a/Tests/Uploader/Storage/OrphanageTest.php +++ b/Tests/Uploader/Storage/OrphanageTest.php @@ -3,10 +3,11 @@ namespace Oneup\UploaderBundle\Tests\Uploader\Storage; use Oneup\UploaderBundle\Uploader\Storage\FlysystemOrphanageStorage; +use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; use Symfony\Component\Filesystem\Filesystem; -abstract class OrphanageTest extends \PHPUnit_Framework_TestCase +abstract class OrphanageTest extends TestCase { protected $tempDirectory; protected $realDirectory; diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index a1756af..d00c03f 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,24 +1,13 @@ <?php -$loader = @include __DIR__ . '/../vendor/autoload.php'; -if (!$loader) { - die(<<<'EOT' -You must set up the project dependencies, run the following commands: -wget http://getcomposer.org/composer.phar -php composer.phar install -EOT - ); +if (!($loader = @include __DIR__.'/../vendor/autoload.php')) { + echo <<<'EOT' +You need to install the project dependencies using Composer: +$ wget http://getcomposer.org/composer.phar +OR +$ curl -s https://getcomposer.org/installer | php +$ php composer.phar install --dev +$ phpunit +EOT; + exit(1); } - -passthru(sprintf('rm -rf %s/App/cache', __DIR__)); -spl_autoload_register(function($class) { - if (0 === strpos($class, 'Oneup\\UploaderBundle\\')) { - $path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php'; - if (!stream_resolve_include_path($path)) { - return false; - } - require_once $path; - - return true; - } -}); diff --git a/Uploader/Chunk/Storage/FilesystemStorage.php b/Uploader/Chunk/Storage/FilesystemStorage.php index acc98d7..e91e258 100644 --- a/Uploader/Chunk/Storage/FilesystemStorage.php +++ b/Uploader/Chunk/Storage/FilesystemStorage.php @@ -44,8 +44,9 @@ class FilesystemStorage implements ChunkStorageInterface $name = sprintf('%s_%s', $index, $original); // create directory if it does not yet exist - if(!$filesystem->exists($path)) + if (!$filesystem->exists($path)) { $filesystem->mkdir(sprintf('%s/%s', $this->directory, $uuid)); + } return $chunk->move($path, $name); } @@ -62,7 +63,6 @@ class FilesystemStorage implements ChunkStorageInterface $iterator->next(); while ($iterator->valid()) { - $file = $iterator->current(); if (false === file_put_contents($base->getPathname(), file_get_contents($file->getPathname()), \FILE_APPEND | \LOCK_EX)) { @@ -109,7 +109,7 @@ class FilesystemStorage implements ChunkStorageInterface { $finder = new Finder(); $finder - ->in(sprintf('%s/%s', $this->directory, $uuid))->files()->sort(function(\SplFileInfo $a, \SplFileInfo $b) { + ->in(sprintf('%s/%s', $this->directory, $uuid))->files()->sort(function (\SplFileInfo $a, \SplFileInfo $b) { $t = explode('_', $a->getBasename()); $s = explode('_', $b->getBasename()); $t = (int) $t[0]; diff --git a/Uploader/ErrorHandler/DropzoneErrorHandler.php b/Uploader/ErrorHandler/DropzoneErrorHandler.php index 5b0ad44..e07ddc3 100755 --- a/Uploader/ErrorHandler/DropzoneErrorHandler.php +++ b/Uploader/ErrorHandler/DropzoneErrorHandler.php @@ -8,12 +8,12 @@ use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; class DropzoneErrorHandler implements ErrorHandlerInterface { - public function addException(AbstractResponse $response, Exception $exception) - { - $errors[] = $exception; - $message = $exception->getMessage(); - // Dropzone wants JSON with error message put into 'error' field. - // This overwrites the previous error message, so we're only displaying the last one. - $response['error'] = $message; - } + public function addException(AbstractResponse $response, Exception $exception) + { + $errors[] = $exception; + $message = $exception->getMessage(); + // Dropzone wants JSON with error message put into 'error' field. + // This overwrites the previous error message, so we're only displaying the last one. + $response['error'] = $message; + } } diff --git a/Uploader/File/FilesystemFile.php b/Uploader/File/FilesystemFile.php index 539df73..3d6d21e 100644 --- a/Uploader/File/FilesystemFile.php +++ b/Uploader/File/FilesystemFile.php @@ -14,7 +14,6 @@ class FilesystemFile extends UploadedFile implements FileInterface } else { parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true); } - } public function getExtension() diff --git a/Uploader/File/FlysystemFile.php b/Uploader/File/FlysystemFile.php index dc36e69..0b287d8 100644 --- a/Uploader/File/FlysystemFile.php +++ b/Uploader/File/FlysystemFile.php @@ -6,7 +6,6 @@ use League\Flysystem\Filesystem; class FlysystemFile extends File implements FileInterface { - protected $streamWrapperPrefix; protected $mimeType; diff --git a/Uploader/File/GaufretteFile.php b/Uploader/File/GaufretteFile.php index 1d38ab8..0965be2 100644 --- a/Uploader/File/GaufretteFile.php +++ b/Uploader/File/GaufretteFile.php @@ -118,5 +118,4 @@ class GaufretteFile extends File implements FileInterface { return $this->filesystem; } - } diff --git a/Uploader/Gaufrette/StreamManager.php b/Uploader/Gaufrette/StreamManager.php index e745eef..073c6f1 100644 --- a/Uploader/Gaufrette/StreamManager.php +++ b/Uploader/Gaufrette/StreamManager.php @@ -25,7 +25,7 @@ class StreamManager protected function ensureRemotePathExists($path) { - if(!$this->filesystem->has($path)) { + if (!$this->filesystem->has($path)) { $this->filesystem->write($path, '', true); } } @@ -53,5 +53,4 @@ class StreamManager $dst->close(); $src->close(); } - } diff --git a/Uploader/Response/FineUploaderResponse.php b/Uploader/Response/FineUploaderResponse.php index 52c8570..df29edf 100644 --- a/Uploader/Response/FineUploaderResponse.php +++ b/Uploader/Response/FineUploaderResponse.php @@ -25,11 +25,13 @@ class FineUploaderResponse extends AbstractResponse $data = $this->data; $data['success'] = $this->success; - if($this->success) + if ($this->success) { unset($data['error']); + } - if(!$this->success) + if (!$this->success) { $data['error'] = $this->error; + } return $data; } diff --git a/Uploader/Storage/FilesystemOrphanageStorage.php b/Uploader/Storage/FilesystemOrphanageStorage.php index 8888e16..7290869 100644 --- a/Uploader/Storage/FilesystemOrphanageStorage.php +++ b/Uploader/Storage/FilesystemOrphanageStorage.php @@ -33,8 +33,9 @@ class FilesystemOrphanageStorage extends FilesystemStorage implements OrphanageS public function upload(FileInterface $file, $name, $path = null) { - if(!$this->session->isStarted()) + if (!$this->session->isStarted()) { throw new \RuntimeException('You need a running session in order to run the Orphanage.'); + } return parent::upload($file, $name, $this->getPath()); } diff --git a/Uploader/Storage/FlysystemOrphanageStorage.php b/Uploader/Storage/FlysystemOrphanageStorage.php index 6cc00ab..021a1f6 100644 --- a/Uploader/Storage/FlysystemOrphanageStorage.php +++ b/Uploader/Storage/FlysystemOrphanageStorage.php @@ -96,5 +96,4 @@ class FlysystemOrphanageStorage extends FlysystemStorage implements OrphanageSto // should be relative. return sprintf('%s/%s/%s', $this->config['directory'], $this->session->getId(), $this->type); } - } diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php index b003236..aea9922 100644 --- a/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/Uploader/Storage/GaufretteOrphanageStorage.php @@ -40,8 +40,9 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto public function upload(FileInterface $file, $name, $path = null) { - if(!$this->session->isStarted()) + if (!$this->session->isStarted()) { throw new \RuntimeException('You need a running session in order to run the Orphanage.'); + } return parent::upload($file, $name, $this->getPath()); } @@ -89,5 +90,4 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto // should be relative. return sprintf('%s/%s/%s', $this->config['directory'], $this->session->getId(), $this->type); } - } diff --git a/Uploader/Storage/GaufretteStorage.php b/Uploader/Storage/GaufretteStorage.php index d83687e..84c5602 100644 --- a/Uploader/Storage/GaufretteStorage.php +++ b/Uploader/Storage/GaufretteStorage.php @@ -65,5 +65,4 @@ class GaufretteStorage extends StreamManager implements StorageInterface return new GaufretteFile($this->filesystem->get($path), $this->filesystem, $this->streamWrapperPrefix); } - } diff --git a/composer.json b/composer.json index d68b779..25b7e00 100644 --- a/composer.json +++ b/composer.json @@ -15,36 +15,41 @@ ], "require": { - "php":">=5.4", - "symfony/framework-bundle": "^2.4|^3.0", - "symfony/finder": "^2.4|^3.0", - "symfony/translation": "^2.4|^3.0", - "symfony/asset": "^2.4|^3.0", - "symfony/templating": "^2.4|^3.0", - "paragonie/random_compat": "^1.1|^2.0" + "php": ">=5.4", + "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/templating": "^3.0|^4.0", + "symfony/translation": "^3.0|^4.0", + "symfony/yaml": "^3.0|^4.0" }, "require-dev": { "amazonwebservices/aws-sdk-for-php": "1.5.*", "knplabs/gaufrette": "0.2.*@dev", - "oneup/flysystem-bundle": "^1.2", - "phpunit/phpunit": "^4.4", - "sensio/framework-extra-bundle": "2.*|^3.0", - "symfony/browser-kit": "2.*|^3.0", - "symfony/class-loader": "2.*|^3.0", - "symfony/security-bundle": "2.*|^3.0", + "oneup/flysystem-bundle": "^1.2|^2.0|^3.0", + "phpunit/phpunit": "^6.5", + "sensio/framework-extra-bundle": "^5.0", + "symfony/browser-kit": "^3.0|^4.0", + "symfony/class-loader": "^3.0|^4.0", + "symfony/security-bundle": "^3.0|^4.0", + "symfony/var-dumper": "^3.0|^4.0", "twistor/flysystem-stream-wrapper": "^1.0" }, - + "config": { + "sort-packages": true + }, "suggest": { "knplabs/knp-gaufrette-bundle": "0.1.*", - "oneup/flysystem-bundle": "^1.2", + "oneup/flysystem-bundle": "^3.0", "twistor/flysystem-stream-wrapper": "^1.0 (Required when using Flysystem)" }, "autoload": { - "psr-0": { "Oneup\\UploaderBundle": "" } - }, - - "target-dir": "Oneup/UploaderBundle" + "psr-4": { + "Oneup\\UploaderBundle\\": "" + }, + "classmap": [ "Tests/App/AppKernel.php"] + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7caffb4..6f2e1c0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,6 +3,7 @@ <phpunit bootstrap="./Tests/bootstrap.php" colors="true"> <php> <server name="KERNEL_DIR" value="Tests/App" /> + <server name="KERNEL_CLASS" value="AppKernel" /> </php> <testsuites>
0
d84e960953588ca47ce2984f6dd7da69942d5cee
1up-lab
OneupUploaderBundle
Removed first title in chunked_uploads.md
commit d84e960953588ca47ce2984f6dd7da69942d5cee Author: Jim Schmid <[email protected]> Date: Tue Apr 9 09:14:01 2013 +0200 Removed first title in chunked_uploads.md diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md index bd1238b..af3b780 100644 --- a/Resources/doc/chunked_uploads.md +++ b/Resources/doc/chunked_uploads.md @@ -1,8 +1,6 @@ Using Chunked Uploads ===================== -## Enable - Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. ```js
0
bcde9b99fc62015b4e93abf68dfc9fb51a146c22
1up-lab
OneupUploaderBundle
Merge pull request #105 from Schyzophrenic/master [Doc] Add Exception about the ValidationEvent
commit bcde9b99fc62015b4e93abf68dfc9fb51a146c22 Merge: 3e763f0 8a40040 Author: Jim Schmid <[email protected]> Date: Sat May 10 21:10:55 2014 +0200 Merge pull request #105 from Schyzophrenic/master [Doc] Add Exception about the ValidationEvent
0
d0157cb77b57d088bc5c6a5ca77e092e42065098
1up-lab
OneupUploaderBundle
Added installation and configuration docs.
commit d0157cb77b57d088bc5c6a5ca77e092e42065098 Author: Jim Schmid <[email protected]> Date: Sun Apr 7 13:02:06 2013 +0200 Added installation and configuration docs. diff --git a/Resources/docs/index.md b/Resources/docs/index.md new file mode 100644 index 0000000..0fec11f --- /dev/null +++ b/Resources/docs/index.md @@ -0,0 +1,98 @@ +Getting started +=============== + +## Prerequisites + +This bundle tested using Symfony2 versions 2.1+. + +### Translations +If you wish to use the default texts provided with this bundle, you have to make sure that you have translator +enabled in your configuration file. + +``` +# app/config/config.yml + +framework: + translator: ~ +``` + +## Installation + +Perform the following step to install and use the basic functionality of the OneupUploaderBundle: + +* Download OnueupUploaderBundle using Composer +* Enable the bundle +* Configure the bundle +* Prepare your frontend + +### Step 1: Download the OneupUploaderBundle + +Add OneupUploaderBundle to your composer.json using the following construct: + +```js +{ + "require": { + "oneup/uploader-bundle": "*" + } +} +``` + +Now tell composer to download the bundle by running the following command: + + $> php composer.phar update oneup/uploader-bundle + +Composer will now fetch and install this bundle in the vendor directory ```vendor/oneup``` + +### Step 2: Enable the bundle + +Enable the bundle in the kernel: + +``` php +<?php +// app/AppKernel.php + +public function registerBundles() +{ + $bundles = array( + // ... + new Oneup\UploaderBundle\OneupUploaderBundle(), + ); +} +``` + +### Step 3: Configure the bundle + +This bundle was designed to just work out of the box. The only thing you have to configure in order to get this bundle up and running is a mapping. + +``` +# app/config/config.yml + +oneup_uploader: + gallery: ~ +``` + +### Step 4: Prepare your frontend + +As this is a server implementation for Fine Uploader, you have to include this library in order to upload files through this bundle. You can find them on the [official page](http://fineuploader.com) of Fine Uploader. Be sure to connect the endpoint property to the dynamic route created from your mapping. It has the following form: + + _uploader_{mapping_key} + +``` +<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script> +<script type="text/javascript" src="js/jquery.fineuploader-3.4.1.js"></script> +<script type="text/javascript"> +$(document).ready(function() +{ + var uploader = new qq.FineUploader({ + element: $('#uploader'), + request: { + endpoint: "{{ path('_uploader_gallery') }}" + } + }); +}); +</script> + +<div id="uploader"></div> +``` + +This is of course a very minimal setup. Be sure to include stylesheets for Fine Uploader if you want to use them. \ No newline at end of file
0
1903a267fd643201b0664cfe24e599ae848e795b
1up-lab
OneupUploaderBundle
Fixed a bug in RouteLoader and created frontend helpers.
commit 1903a267fd643201b0664cfe24e599ae848e795b Author: Jim Schmid <[email protected]> Date: Mon Jun 24 21:07:08 2013 +0200 Fixed a bug in RouteLoader and created frontend helpers. diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index 7771274..62c3cab 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -41,9 +41,11 @@ class RouteLoader extends Loader array('_controller' => $service . ':progress', '_format' => 'json'), array('_method' => 'POST') ); + + $routes->add(sprintf('_uploader_progress_%s', $type), $progress); } - $routes->add(sprintf('_uploader_%s', $type), $upload); + $routes->add(sprintf('_uploader_upload_%s', $type), $upload); } return $routes; diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php index 1882766..ffdfd91 100644 --- a/Templating/Helper/UploaderHelper.php +++ b/Templating/Helper/UploaderHelper.php @@ -21,6 +21,11 @@ class UploaderHelper extends Helper public function endpoint($key) { - return $this->router->generate(sprintf('_uploader_%s', $key)); + return $this->router->generate(sprintf('_uploader_upload_%s', $key)); + } + + public function progress($key) + { + return $this->router->generate(sprintf('_uploader_progress_%s', $key)); } } diff --git a/Tests/App/config/config.yml b/Tests/App/config/config.yml index 77da381..2299750 100644 --- a/Tests/App/config/config.yml +++ b/Tests/App/config/config.yml @@ -26,6 +26,7 @@ oneup_uploader: fineuploader: frontend: fineuploader + use_upload_progress: true storage: directory: %kernel.root_dir%/cache/%kernel.environment%/upload diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index 8849b79..3e7d5da 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -20,11 +20,19 @@ class UploaderExtension extends \Twig_Extension public function getFunctions() { - return array('oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint')); + return array( + 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint') + 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress') + ); } public function endpoint($key) { return $this->helper->endpoint($key); } + + public function progress($key) + { + return $this->helper->progress($key); + } }
0
0f30d964784e6bc4a7fd7214af105a5e8f02816e
1up-lab
OneupUploaderBundle
Fix the refactoring as per documentation. use the Twig_SimpleFunction the way as mentioned in the docs http://twig.sensiolabs.org/doc/advanced.html#id2
commit 0f30d964784e6bc4a7fd7214af105a5e8f02816e Author: Ahmad Tawila <[email protected]> Date: Mon Oct 26 18:18:14 2015 +0200 Fix the refactoring as per documentation. use the Twig_SimpleFunction the way as mentioned in the docs http://twig.sensiolabs.org/doc/advanced.html#id2 diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index ab76375..3cac14d 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -21,11 +21,11 @@ class UploaderExtension extends \Twig_Extension public function getFunctions() { return array( - 'oneup_uploader_endpoint' => new \Twig_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')), + new \Twig_SimpleFunction('oneup_uploader_endpoint', array($this, 'endpoint')), + new \Twig_SimpleFunction('oneup_uploader_progress', array($this, 'progress')), + new \Twig_SimpleFunction('oneup_uploader_cancel', array($this, 'cancel')), + new \Twig_SimpleFunction('oneup_uploader_upload_key', array($this, 'uploadKey')), + new \Twig_SimpleFunction('oneup_uploader_maxsize', array($this, 'maxSize')), ); }
0
8ec27f83672c465ce032961e5c3eb684b767db68
1up-lab
OneupUploaderBundle
Added the session id to the uuid, as it is possible that two users upload the same filename at the same time.
commit 8ec27f83672c465ce032961e5c3eb684b767db68 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 15:52:37 2013 +0200 Added the session id to the uuid, as it is possible that two users upload the same filename at the same time. diff --git a/Controller/PluploadController.php b/Controller/PluploadController.php index 6b0cfe3..c445174 100644 --- a/Controller/PluploadController.php +++ b/Controller/PluploadController.php @@ -40,11 +40,17 @@ class PluploadController extends AbstractChunkedController protected function parseChunkedRequest(Request $request) { + $session = $this->container->get('session'); + $orig = $request->get('name'); - $uuid = $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
0
6db9e56ab3996511a8cf9e1dda844fa89a92e525
1up-lab
OneupUploaderBundle
Merge pull request #16 from 1up-lab/improved-tests Improved tests
commit 6db9e56ab3996511a8cf9e1dda844fa89a92e525 Merge: c57af49 2227d8b Author: Jim Schmid <[email protected]> Date: Mon May 6 13:34:59 2013 -0700 Merge pull request #16 from 1up-lab/improved-tests Improved tests
0
470b11eeee82946fbf93d5944c63749bcdf65f6f
1up-lab
OneupUploaderBundle
Widen typehint (#445)
commit 470b11eeee82946fbf93d5944c63749bcdf65f6f Author: David Greminger <[email protected]> Date: Thu Apr 4 08:57:10 2024 +0200 Widen typehint (#445) diff --git a/src/Controller/AbstractController.php b/src/Controller/AbstractController.php index 7dbd5b6..1e1a867 100644 --- a/src/Controller/AbstractController.php +++ b/src/Controller/AbstractController.php @@ -100,10 +100,8 @@ abstract class AbstractController * function in the implemented Controller. * * Note: The return value differs when - * - * @param File $file The file to upload */ - protected function handleUpload(File $file, ResponseInterface $response, Request $request): void + protected function handleUpload(FileInterface|File $file, ResponseInterface $response, Request $request): void { // wrap the file if it is not done yet which can only happen // if it wasn't a chunked upload, in which case it is definitely @@ -130,12 +128,8 @@ abstract class AbstractController /** * This function is a helper function which dispatches pre upload event. - * - * @param FileInterface $uploaded the uploaded file - * @param ResponseInterface $response a response object - * @param Request $request the request object */ - protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request): void + protected function dispatchPreUploadEvent(FileInterface|File $uploaded, ResponseInterface $response, Request $request): void { // dispatch pre upload event (both the specific and the general) $preUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config); @@ -146,10 +140,8 @@ abstract class AbstractController /** * This function is a helper function which dispatches post upload * and post persist events. - * - * @param File $uploaded the uploaded file */ - protected function dispatchPostEvents(File $uploaded, ResponseInterface $response, Request $request): void + protected function dispatchPostEvents(FileInterface|File $uploaded, ResponseInterface $response, Request $request): void { // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); @@ -164,7 +156,7 @@ abstract class AbstractController } } - protected function validate(FileInterface $file, Request $request, ?ResponseInterface $response = null): void + protected function validate(FileInterface|File $file, Request $request, ?ResponseInterface $response = null): void { $event = new ValidationEvent($file, $request, $this->config, $this->type, $response);
0
70fdfdbdf72642d382ce62d966d2079cc3a39061
1up-lab
OneupUploaderBundle
Merge pull request #245 from deviprsd21/master Fix #238 (typo, ®equested a non-existent service)
commit 70fdfdbdf72642d382ce62d966d2079cc3a39061 Merge: bde473d 4b188af Author: David Greminger <[email protected]> Date: Wed May 4 11:09:49 2016 +0200 Merge pull request #245 from deviprsd21/master Fix #238 (typo, ®equested a non-existent service)
0
8cd497ebb4a9e00b6b9babf5286e494b1ed06782
1up-lab
OneupUploaderBundle
Added php7.0 to allowed failures, updated composer version constraints to use symfony3.0
commit 8cd497ebb4a9e00b6b9babf5286e494b1ed06782 Author: David Greminger <[email protected]> Date: Thu Dec 10 11:37:06 2015 +0100 Added php7.0 to allowed failures, updated composer version constraints to use symfony3.0 diff --git a/.travis.yml b/.travis.yml index 26b3eb4..1734c3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ cache: matrix: allow_failures: - php: hhvm + - php: 7.0 - env: SYMFONY_VERSION=dev-master include: diff --git a/composer.json b/composer.json index 3d9a755..7f745ad 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ ], "require": { - "symfony/framework-bundle": "^2.3.0", - "symfony/http-kernel": "^2.3.0", - "symfony/finder": ">=2.2.0" + "symfony/framework-bundle": "^2.3.0|~3.0", + "symfony/http-kernel": "^2.3.0|~3.0", + "symfony/finder": ">=2.2.0|~3.0" }, "require-dev": { @@ -27,7 +27,7 @@ "symfony/security-bundle": "2.*", "sensio/framework-extra-bundle": "2.*", "symfony/browser-kit": "2.*", - "phpunit/phpunit": "~4.1" + "phpunit/phpunit": "~4.4" }, "suggest": {
0
0ccb23e3049c161b01fcc4c9c02939e4c8b011e4
1up-lab
OneupUploaderBundle
Fixed a markdown bug.
commit 0ccb23e3049c161b01fcc4c9c02939e4c8b011e4 Author: Jim Schmid <[email protected]> Date: Fri Apr 12 17:18:28 2013 +0200 Fixed a markdown bug. diff --git a/Resources/doc/custom_uploader.md b/Resources/doc/custom_uploader.md index 786e7a6..6c4a845 100644 --- a/Resources/doc/custom_uploader.md +++ b/Resources/doc/custom_uploader.md @@ -122,6 +122,7 @@ class FineUploaderResponse extends AbstractResponse // ... snip, setters/getters } +``` ## Notes
0
e36a629ed6584866ce8ddd22aa9f511056920af5
1up-lab
OneupUploaderBundle
Rename namer.md to custom_namer.md
commit e36a629ed6584866ce8ddd22aa9f511056920af5 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 09:40:25 2013 +0300 Rename namer.md to custom_namer.md diff --git a/Resources/doc/namer.md b/Resources/doc/custom_namer.md similarity index 97% rename from Resources/doc/namer.md rename to Resources/doc/custom_namer.md index 65fe084..4aaeabc 100644 --- a/Resources/doc/namer.md +++ b/Resources/doc/custom_namer.md @@ -43,4 +43,4 @@ oneup_uploader: namer: acme_demo.custom_namer ``` -Every file uploaded through the `Controller` of this mapping will be named with your custom namer. \ No newline at end of file +Every file uploaded through the `Controller` of this mapping will be named with your custom namer.
0
9a3189ec012fb0c240bd83dfed0c8447794322ce
1up-lab
OneupUploaderBundle
Code highlighter bricks on GitHub, give it another try.
commit 9a3189ec012fb0c240bd83dfed0c8447794322ce Author: Jim Schmid <[email protected]> Date: Tue Apr 9 10:15:24 2013 +0200 Code highlighter bricks on GitHub, give it another try. diff --git a/Resources/doc/response.md b/Resources/doc/response.md index a438956..6cb75f4 100644 --- a/Resources/doc/response.md +++ b/Resources/doc/response.md @@ -4,3 +4,31 @@ Return custom data to the Frontend There are some use cases where you need custom data to be returned to the frontend. For example the id of a generated Doctrine Entity or the like. To cover this, you can use `UploaderResponse` passed through all `Events`. ```php +namespace Acme\HelloBundle\EventListener; + +use Oneup\UploaderBundle\Event\PostPersistEvent; + +class UploadListener +{ + public function onUpload(PostPersistEvent $event) + { + $response = $event->getResponse(); + } +} +``` + +The `UploaderResponse` class implements the `ArrayAccess` interface, so you can just add data using it like an array: + +´´´php +$response['id'] = $uploadedImage->getId(); +$response['url'] = $uploadedImage->getUrl(); +``` + +If you like to indicate an error, be sure to set the `success` property to `false` and provide an error message: + +```php +$response->setSuccess(false); +$response->setError($msg); +``` + +> Do not use the keys `success` and `error` if you provide custom data, they will be overwritten by the internal properties of `UploaderResponse`. \ No newline at end of file
0
ab23ea0a9ba1450e42c188bd17c01f6b9e0cfdc5
1up-lab
OneupUploaderBundle
Added PHP 5.6 and HHVM to travis.yml
commit ab23ea0a9ba1450e42c188bd17c01f6b9e0cfdc5 Author: Tobias Nyholm <[email protected]> Date: Thu Jul 17 07:23:24 2014 +0200 Added PHP 5.6 and HHVM to travis.yml diff --git a/.travis.yml b/.travis.yml index bd24695..1d74818 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,27 @@ language: php php: - - 5.3 - - 5.4 - - 5.5 + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm env: - SYMFONY_VERSION=2.3.* - - SYMFONY_VERSION=2.4.* - - SYMFONY_VERSION=2.5.* + +matrix: + allow_failures: + - env: SYMFONY_VERSION=dev-master + - php: hhvm + include: + - php: 5.5 + env: SYMFONY_VERSION=2.4.* + - php: 5.5 + env: SYMFONY_VERSION=2.5.* + - php: 5.5 + env: SYMFONY_VERSION=dev-master before_script: - composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source - - composer install --dev --prefer-source \ No newline at end of file + - composer install --dev --prefer-source
0
529b01cac232a81430772f8c5d9ae09f0c1a8d74
1up-lab
OneupUploaderBundle
file tests
commit 529b01cac232a81430772f8c5d9ae09f0c1a8d74 Author: mitom <[email protected]> Date: Fri Oct 11 16:51:37 2013 +0200 file tests diff --git a/Tests/Uploader/File/FileTest.php b/Tests/Uploader/File/FileTest.php new file mode 100644 index 0000000..2753089 --- /dev/null +++ b/Tests/Uploader/File/FileTest.php @@ -0,0 +1,43 @@ +<?php +namespace Oneup\UploaderBundle\Tests\Uploader\File; + +abstract class FileTest extends \PHPUnit_Framework_TestCase +{ + protected $file; + protected $pathname; + protected $path; + protected $basename; + protected $extension; + protected $size; + protected $mimeType; + + public function testGetPathName() + { + $this->assertEquals($this->pathname, $this->file->getPathname()); + } + + public function testGetPath() + { + $this->assertEquals($this->path, $this->file->getPath()); + } + + public function testGetBasename() + { + $this->assertEquals($this->basename, $this->file->getBasename()); + } + + public function testGetExtension() + { + $this->assertEquals($this->extension, $this->file->getExtension()); + } + + public function testGetSize() + { + $this->assertEquals($this->size, $this->file->getSize()); + } + + public function testGetMimeType() + { + $this->assertEquals($this->mimeType, $this->file->getMimeType()); + } +} diff --git a/Tests/Uploader/File/FilesystemFileTest.php b/Tests/Uploader/File/FilesystemFileTest.php new file mode 100644 index 0000000..0868cb9 --- /dev/null +++ b/Tests/Uploader/File/FilesystemFileTest.php @@ -0,0 +1,30 @@ +<?php +namespace Oneup\UploaderBundle\Tests\Uploader\File; + +use Oneup\UploaderBundle\Uploader\File\FilesystemFile; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class FilesystemFileTest extends FileTest +{ + public function setUp() + { + $this->path = sys_get_temp_dir(). '/oneup_test_tmp'; + mkdir($this->path); + + $this->basename = 'test_file.txt'; + $this->pathname = $this->path .'/'. $this->basename; + $this->extension = 'txt'; + $this->size = 9; //something = 9 bytes + $this->mimeType = 'text/plain'; + + file_put_contents($this->pathname, 'something'); + + $this->file = new FilesystemFile(new UploadedFile($this->pathname, 'test_file.txt', null, null, null, true)); + } + + public function tearDown() + { + unlink($this->pathname); + rmdir($this->path); + } +} diff --git a/Tests/Uploader/File/GaufretteFileTest.php b/Tests/Uploader/File/GaufretteFileTest.php new file mode 100644 index 0000000..fc7e2f7 --- /dev/null +++ b/Tests/Uploader/File/GaufretteFileTest.php @@ -0,0 +1,44 @@ +<?php +namespace Oneup\UploaderBundle\Tests\Uploader\File; + +use Gaufrette\File; +use Gaufrette\StreamWrapper; +use Oneup\UploaderBundle\Uploader\File\GaufretteFile; +use Gaufrette\Adapter\Local as Adapter; +use Gaufrette\Filesystem as GaufretteFileSystem; +use Oneup\UploaderBundle\Uploader\Storage\GaufretteStorage; + +class GaufretteFileTest extends FileTest +{ + public function setUp() + { + $adapter = new Adapter(sys_get_temp_dir(), true); + $filesystem = new GaufretteFilesystem($adapter); + + $map = StreamWrapper::getFilesystemMap(); + $map->set('oneup', $filesystem); + + StreamWrapper::register(); + + $this->storage = new GaufretteStorage($filesystem, 100000); + + $this->path = 'oneup_test_tmp'; + mkdir(sys_get_temp_dir().'/'.$this->path); + + $this->basename = 'test_file.txt'; + $this->pathname = $this->path .'/'. $this->basename; + $this->extension = 'txt'; + $this->size = 9; //something = 9 bytes + $this->mimeType = 'text/plain'; + + file_put_contents(sys_get_temp_dir() .'/' . $this->pathname, 'something'); + + $this->file = new GaufretteFile(new File($this->pathname, $filesystem), $filesystem, 'gaufrette://oneup/'); + } + + public function tearDown() + { + unlink(sys_get_temp_dir().'/'.$this->pathname); + rmdir(sys_get_temp_dir().'/'.$this->path); + } +}
0
5ff6a2e7bc9c7361fc719321f2fe3d620d9c7f8a
1up-lab
OneupUploaderBundle
Merge branch 'snarktooth-flysystem-path-fix'
commit 5ff6a2e7bc9c7361fc719321f2fe3d620d9c7f8a Merge: 1f6fa09 8a922f6 Author: David Greminger <[email protected]> Date: Tue Sep 19 11:38:39 2017 +0200 Merge branch 'snarktooth-flysystem-path-fix'
0
1f9dbbc3ca57fc5a890e98bd9c55560463198547
1up-lab
OneupUploaderBundle
Added cancel helper functions incl. Twig extension.
commit 1f9dbbc3ca57fc5a890e98bd9c55560463198547 Author: Jim Schmid <[email protected]> Date: Tue Jun 25 11:28:41 2013 +0200 Added cancel helper functions incl. Twig extension. diff --git a/Templating/Helper/UploaderHelper.php b/Templating/Helper/UploaderHelper.php index f4a3490..c433675 100644 --- a/Templating/Helper/UploaderHelper.php +++ b/Templating/Helper/UploaderHelper.php @@ -29,6 +29,11 @@ class UploaderHelper extends Helper return $this->router->generate(sprintf('_uploader_progress_%s', $key)); } + public function cancel($key) + { + return $this->router->generate(sprintf('_uploader_cancel_%s', $key)); + } + public function uploadKey() { return ini_get('session.upload_progress.name'); diff --git a/Twig/Extension/UploaderExtension.php b/Twig/Extension/UploaderExtension.php index e33b9b4..2665a89 100644 --- a/Twig/Extension/UploaderExtension.php +++ b/Twig/Extension/UploaderExtension.php @@ -23,6 +23,7 @@ class UploaderExtension extends \Twig_Extension return array( 'oneup_uploader_endpoint' => new \Twig_Function_Method($this, 'endpoint'), 'oneup_uploader_progress' => new \Twig_Function_Method($this, 'progress'), + 'oneup_uploader_cancel' => new \Twig_Function_Method($this, 'cancel'), 'oneup_uploader_upload_key' => new \Twig_Function_Method($this, 'uploadKey') ); } @@ -37,6 +38,11 @@ class UploaderExtension extends \Twig_Extension return $this->helper->progress($key); } + public function cancel($key) + { + return $this->helper->cancel($key); + } + public function uploadKey() { return $this->helper->uploadKey();
0
996a7849633a5aeb2b35665b346e7c4ca28bccb4
1up-lab
OneupUploaderBundle
Fixes scrutinizer-ci warnings. Do not test against: too_many_methods too_many_fields coupling_between_objects As this bundle provides a base Controller that is dependant on many coupled objects/interfaces, the coupling does not really make sense to test.
commit 996a7849633a5aeb2b35665b346e7c4ca28bccb4 Author: Jim Schmid <[email protected]> Date: Wed Oct 23 15:03:40 2013 +0200 Fixes scrutinizer-ci warnings. Do not test against: too_many_methods too_many_fields coupling_between_objects As this bundle provides a base Controller that is dependant on many coupled objects/interfaces, the coupling does not really make sense to test. diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 764db5d..dc9dd29 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -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 \ No newline at end of file
0
b9c8d4868b0b5e3bf1be21a081e36a2573fe6d0f
1up-lab
OneupUploaderBundle
Enable cancelation flag for configuration.
commit b9c8d4868b0b5e3bf1be21a081e36a2573fe6d0f Author: Jim Schmid <[email protected]> Date: Tue Jun 25 11:26:14 2013 +0200 Enable cancelation flag for configuration. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index aa704c3..e51b8b0 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -71,8 +71,9 @@ class Configuration implements ConfigurationInterface ->prototype('scalar')->end() ->end() ->scalarNode('max_size')->defaultValue(\PHP_INT_MAX)->end() - ->booleanNode('use_upload_progress')->defaultValue(false)->end() ->booleanNode('use_orphanage')->defaultFalse()->end() + ->booleanNode('use_upload_progress')->defaultValue(false)->end() + ->booleanNode('enable_cancelation')->defaultFalse()->end() ->scalarNode('namer')->defaultValue('oneup_uploader.namer.uniqid')->end() ->end() ->end() diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index b5d7c58..ede54fb 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -130,7 +130,8 @@ class OneupUploaderExtension extends Extension ; $controllers[$key] = array($controllerName, array( - 'use_upload_progress' => $mapping['use_upload_progress'] + 'use_upload_progress' => $mapping['use_upload_progress'], + 'enable_cancelation' => $mapping['enable_cancelation'] )); } diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index 62c3cab..1e2f8ca 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -45,6 +45,16 @@ class RouteLoader extends Loader $routes->add(sprintf('_uploader_progress_%s', $type), $progress); } + if ($options['enable_cancelation'] === true) { + $progress = new Route( + sprintf('/_uploader/%s/cancel', $type), + array('_controller' => $service . ':cancel', '_format' => 'json'), + array('_method' => 'POST') + ); + + $routes->add(sprintf('_uploader_cancel_%s', $type), $progress); + } + $routes->add(sprintf('_uploader_upload_%s', $type), $upload); } diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php index 9a362f5..db6b86d 100644 --- a/Tests/Routing/RouteLoaderTest.php +++ b/Tests/Routing/RouteLoaderTest.php @@ -12,8 +12,14 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase $dog = 'HelloThisIsDogController'; $routeLoader = new RouteLoader(array( - 'cat' => array($cat, array('use_upload_progress' => false)), - 'dog' => array($dog, array('use_upload_progress' => true)), + 'cat' => array($cat, array( + 'use_upload_progress' => false, + 'enable_cancelation' => false + )), + 'dog' => array($dog, array( + 'use_upload_progress' => true, + 'enable_cancelation' => true + )), )); $routes = $routeLoader->load(null); @@ -21,7 +27,7 @@ class RouteLoaderTest extends \PHPUnit_Framework_TestCase // for code coverage $this->assertTrue($routeLoader->supports('grumpy', 'uploader')); $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $routes); - $this->assertCount(3, $routes); + $this->assertCount(4, $routes); foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
0
4c954cd2baf5531b91317bbe72f00f904d47e51d
1up-lab
OneupUploaderBundle
Fix links
commit 4c954cd2baf5531b91317bbe72f00f904d47e51d Author: David Greminger <[email protected]> Date: Fri Mar 27 16:56:10 2020 +0100 Fix links diff --git a/README.md b/README.md index f9b252e..c404bb7 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The entry point of the documentation can be found in the file `Resources/docs/in Upgrade Notes ------------- -* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter], @[gubler], @[patrickbussmann], @[ErnadoO] and @[enumag]), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped. +* Version **3.0.0** supports now Symfony 5 (kudos to @[steveWinter](https://github.com/steveWinter), @[gubler](https://github.com/gubler), @[patrickbussmann](https://github.com/patrickbussmann), @[ErnadoO](https://github.com/ErnadoO) and @[enumag](https://github.com/enumag), see [#373](https://github.com/1up-lab/OneupUploaderBundle/pull/373)! Symfony 3.x support was dropped. * Version **2.0.0** supports now Symfony 4 (Thank you @[istvancsabakis](https://github.com/istvancsabakis), see [#295](https://github.com/1up-lab/OneupUploaderBundle/pull/295))! Symfony 2.x support was dropped. You can also configure a file extension validation whitelist now (PR [#262](https://github.com/1up-lab/OneupUploaderBundle/pull/262)). * Version **1.5.0** supports now [Flysystem](https://github.com/1up-lab/OneupFlysystemBundle) (Thank you @[lsv](https://github.com/lsv)! PR [#213](https://github.com/1up-lab/OneupUploaderBundle/pull/213)) and is no longer compatible with PHP 5.3 (it's [EOL](http://php.net/eol.php) since August 2014 anyway). * Version **v1.0.0** introduced some backward compatibility breaks. For a full list of changes, head to the [dedicated pull request](https://github.com/1up-lab/OneupUploaderBundle/pull/57).
0
8f243bf6f64a78decbd533ab1a57bc09a7a608a2
1up-lab
OneupUploaderBundle
Integrated BlueimpResponse.
commit 8f243bf6f64a78decbd533ab1a57bc09a7a608a2 Author: Jim Schmid <[email protected]> Date: Tue Apr 9 21:51:57 2013 +0200 Integrated BlueimpResponse. diff --git a/Uploader/Response/BlueimpResponse.php b/Uploader/Response/BlueimpResponse.php index a4abe2d..8842b6b 100644 --- a/Uploader/Response/BlueimpResponse.php +++ b/Uploader/Response/BlueimpResponse.php @@ -1,2 +1,42 @@ <?php +namespace Oneup\UploaderBundle\Uploader\Response; + +use Oneup\UploaderBundle\Uploader\Response\AbstractResponse; + +class FineUploaderResponse extends AbstractResponse +{ + protected $files; + + public function __construct() + { + $this->success = array(); + + 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['files'] = $this->files; + + return $data; + } + + public function addFile($file) + { + $this->files[] = $file; + + return $this; + } + + public function setFiles(array $files) + { + $this->files = $files; + + return $this; + } +} \ No newline at end of file
0
908cbc408517203a7124c6f9eb45a104b8da9afe
1up-lab
OneupUploaderBundle
Improved compatibility with Symfony 4 (#335)
commit 908cbc408517203a7124c6f9eb45a104b8da9afe Author: okorneliuk <[email protected]> Date: Tue May 22 19:51:22 2018 +0300 Improved compatibility with Symfony 4 (#335) diff --git a/DependencyInjection/OneupUploaderExtension.php b/DependencyInjection/OneupUploaderExtension.php index d63804f..6371cd8 100644 --- a/DependencyInjection/OneupUploaderExtension.php +++ b/DependencyInjection/OneupUploaderExtension.php @@ -206,8 +206,8 @@ class OneupUploaderExtension extends Extension // root_folder is true, remove the mapping name folder from path $folder = $this->config['mappings'][$key]['root_folder'] ? '' : $key; - $config['directory'] = null === $config['directory'] ? - sprintf('%s/../web/uploads/%s', $this->container->getParameter('kernel.root_dir'), $folder) : + $config['directory'] = null === $config['directory'] ? + \sprintf('%s/uploads/%s', $this->getTargetDir(), $folder) : $this->normalizePath($config['directory']) ; @@ -327,4 +327,18 @@ class OneupUploaderExtension extends Extension return rtrim($input, '/').'/'; } + + protected function getTargetDir() + { + $projectDir = $this->container->hasParameter('kernel.project_dir') ? + $this->container->getParameter('kernel.project_dir') : + $this->container->getParameter('kernel.root_dir').'/..'; + $publicDir = \sprintf('%s/public', $projectDir); + + if (!is_dir($publicDir)) { + $publicDir = \sprintf('%s/web', $projectDir); + } + + return $publicDir; + } } diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index bdde803..d68d658 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -59,16 +59,12 @@ abstract class AbstractControllerTest extends WebTestCase public function testCallByGet() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException::class); - - $this->implTestCallBy('GET'); + $this->implTestCallBy('GET', 405, 'text/html'); } public function testCallByDelete() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException::class); - - $this->implTestCallBy('DELETE'); + $this->implTestCallBy('DELETE', 405, 'text/html'); } public function testCallByPatch() @@ -101,7 +97,7 @@ abstract class AbstractControllerTest extends WebTestCase abstract protected function getConfigKey(); - protected function implTestCallBy($method) + protected function implTestCallBy($method, $expectedStatusCode = 200, $expectedContentType='application/json') { $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); @@ -109,8 +105,8 @@ abstract class AbstractControllerTest extends WebTestCase $client->request($method, $endpoint, [], [], $this->requestHeaders); $response = $client->getResponse(); - $this->assertTrue($response->isSuccessful()); - $this->assertSame($response->headers->get('Content-Type'), 'application/json'); + $this->assertEquals($expectedStatusCode, $response->getStatusCode()); + $this->assertContains($expectedContentType, $response->headers->get('Content-Type')); } protected function createTempFile($size = 128)
0
f5ce6e41df95b28d827c51fc69de071349dd7d53
1up-lab
OneupUploaderBundle
Introducing an orphanage for uploads.
commit f5ce6e41df95b28d827c51fc69de071349dd7d53 Author: Jim Schmid <[email protected]> Date: Tue Mar 12 11:17:03 2013 +0100 Introducing an orphanage for uploads. diff --git a/Uploader/Orphanage/Orphanage.php b/Uploader/Orphanage/Orphanage.php new file mode 100644 index 0000000..7239042 --- /dev/null +++ b/Uploader/Orphanage/Orphanage.php @@ -0,0 +1,45 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Orphanage; + +use Symfony\Component\Finder\Finder; +use Symfony\Component\Filesystem\Filesystem; + +use Oneup\UploaderBundle\Uploader\Orphanage\OrphanageInterface; + +class Orphanage implements OrphanageInterface +{ + public function __construct($configuration) + { + $this->configuration = $configuration; + } + + public function warmup() + { + $fileSystem = new FileSystem(); + $fileSystem->mkdir($this->configuration['directory']); + } + + public function clear() + { + $system = new Filesystem(); + $finder = new Finder(); + + 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) + { + $system->remove($file); + } + } +} \ No newline at end of file diff --git a/Uploader/Orphanage/OrphanageInterface.php b/Uploader/Orphanage/OrphanageInterface.php new file mode 100644 index 0000000..6d66c0f --- /dev/null +++ b/Uploader/Orphanage/OrphanageInterface.php @@ -0,0 +1,9 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Orphanage; + +interface OrphanageInterface +{ + public function warmup(); + public function clear(); +} \ No newline at end of file
0
d22c230f85f036f5c68f038eb25f577da0b60ee0
1up-lab
OneupUploaderBundle
Introduced UploaderResponse. You are now able to add custom data to the output, even from EventListener.
commit d22c230f85f036f5c68f038eb25f577da0b60ee0 Author: Jim Schmid <[email protected]> Date: Thu Mar 28 15:05:35 2013 +0100 Introduced UploaderResponse. You are now able to add custom data to the output, even from EventListener. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index f29fff7..465b264 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -17,6 +17,7 @@ use Oneup\UploaderBundle\Controller\UploadControllerInterface; use Oneup\UploaderBundle\Uploader\Naming\NamerInterface; use Oneup\UploaderBundle\Uploader\Storage\StorageInterface; use Oneup\UploaderBundle\Uploader\Chunk\ChunkManagerInterface; +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; class UploaderController implements UploadControllerInterface { @@ -41,6 +42,7 @@ class UploaderController implements UploadControllerInterface public function upload() { + $response = new UploaderResponse(); $totalParts = $this->request->get('qqtotalparts', 1); $files = $this->request->files; $chunked = $totalParts > 1; @@ -49,16 +51,28 @@ class UploaderController implements UploadControllerInterface { try { - $name = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); + $uploaded = $chunked ? $this->handleChunkedUpload($file) : $this->handleUpload($file); + + $postUploadEvent = new PostUploadEvent($uploaded, $response, $this->request, $this->type, $this->config); + $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); + + if(!$this->config['use_orphanage']) + { + // dispatch post upload event + $postPersistEvent = new PostPersistEvent($uploaded, $response, $this->request, $this->type, $this->config); + $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); + } } catch(UploadException $e) { + $response->setSuccess(false); + // an error happended, return this error message. - return new JsonResponse(array('error' => $e->getMessage())); + return new JsonResponse($response->assemble()); } } - return new JsonResponse(array('success' => true, 'name' => $name)); + return new JsonResponse($response->assemble()); } protected function handleUpload(UploadedFile $file) @@ -68,25 +82,13 @@ class UploaderController implements UploadControllerInterface $name = $this->namer->name($file, $this->config['directory_prefix']); $uploaded = $this->storage->upload($file, $name); - $postUploadEvent = new PostUploadEvent($file, $this->request, $this->type, array( - 'use_orphanage' => $this->config['use_orphanage'], - 'file_name' => $name - )); - $this->dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); - - if(!$this->config['use_orphanage']) - { - // dispatch post upload event - $postPersistEvent = new PostPersistEvent($uploaded, $this->request, $this->type); - $this->dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); - } - - return $name; + return $uploaded; } protected function handleChunkedUpload(UploadedFile $file) { - $request = $this->request; + $request = $this->request; + $uploaded = null; // getting information about chunks $index = $request->get('qqpartindex'); @@ -113,12 +115,12 @@ class UploaderController implements UploadControllerInterface // validate this entity and upload on success $this->validate($uploadedFile); - $ret = $this->handleUpload(); + $uploaded = $this->handleUpload(); $this->chunkManager->cleanup($path); } - return $name; + return $uploaded; } protected function validate(UploadedFile $file) diff --git a/Event/PostPersistEvent.php b/Event/PostPersistEvent.php index dac4fc9..60fb8f7 100644 --- a/Event/PostPersistEvent.php +++ b/Event/PostPersistEvent.php @@ -7,17 +7,23 @@ use Symfony\Component\HttpFoundation\Request; use Gaufrette\File; +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; + class PostPersistEvent extends Event { protected $file; protected $request; protected $type; + protected $response; + protected $config; - public function __construct(File $file, Request $request, $type) + public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; + $this->response = $response; $this->type = $type; + $this->config = $config; } public function getFile() @@ -34,4 +40,14 @@ class PostPersistEvent extends Event { return $this->type; } + + public function getResponse() + { + return $this->response; + } + + public function getConfig() + { + return $this->config; + } } \ No newline at end of file diff --git a/Event/PostUploadEvent.php b/Event/PostUploadEvent.php index eb88843..216e58d 100644 --- a/Event/PostUploadEvent.php +++ b/Event/PostUploadEvent.php @@ -5,21 +5,25 @@ namespace Oneup\UploaderBundle\Event; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\File\File; +use Gaufrette\File; + +use Oneup\UploaderBundle\Uploader\Response\UploaderResponse; class PostUploadEvent extends Event { protected $file; protected $request; protected $type; - protected $options; + protected $response; + protected $config; - public function __construct(File $file, Request $request, $type, array $options = array()) + public function __construct(File $file, UploaderResponse $response, Request $request, $type, array $config) { $this->file = $file; $this->request = $request; + $this->response = $response; $this->type = $type; - $this->options = $options; + $this->config = $config; } public function getFile() @@ -37,8 +41,13 @@ class PostUploadEvent extends Event return $this->type; } - public function getOptions() + public function getResponse() + { + return $this->response; + } + + public function getConfig() { - return $this->options; + return $this->config; } } \ No newline at end of file diff --git a/Uploader/Response/UploaderResponse.php b/Uploader/Response/UploaderResponse.php new file mode 100644 index 0000000..4a0511e --- /dev/null +++ b/Uploader/Response/UploaderResponse.php @@ -0,0 +1,73 @@ +<?php + +namespace Oneup\UploaderBundle\Uploader\Response; + +class UploaderResponse implements \ArrayAccess +{ + protected $success; + protected $error; + protected $data; + + public function __construct() + { + $this->success = true; + $this->error = null; + $this->data = array(); + } + + public function assemble() + { + // explicitly overwrite success and error key + // as these keys are used internaly by the + // frontend uploader + $data = $this->data; + $data['success'] = $this->success; + + if(!$this->success) + $data['error'] = $this->error; + + return $data; + } + + public function offsetSet($offset, $value) + { + is_null($offset) ? $this->data[] = $value : $this->data[$offset] = $value; + } + public function offsetExists($offset) + { + return isset($this->data[$offset]); + } + public function offsetUnset($offset) + { + unset($this->data[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->data[$offset]) ? $this->container[$offset] : null; + } + + public function setSuccess($success) + { + $this->success = (bool) $success; + + return $this; + } + + public function getSuccess() + { + return $this->success; + } + + public function setError($msg) + { + $this->error = $msg; + + return $this; + } + + public function getError() + { + return $this->error; + } +} \ No newline at end of file diff --git a/Uploader/Storage/OrphanageStorage.php b/Uploader/Storage/OrphanageStorage.php index f7f7aad..27f83ec 100644 --- a/Uploader/Storage/OrphanageStorage.php +++ b/Uploader/Storage/OrphanageStorage.php @@ -33,7 +33,7 @@ class OrphanageStorage extends GaufretteStorage implements OrphanageStorageInter if(!$this->session->isStarted()) throw new \RuntimeException('You need a running session in order to run the Orphanage.'); - parent::upload($file, $name); + return parent::upload($file, $name); } public function uploadFiles($keep = false)
0
eb7d4d7bea320130d786e075b1f58d4c61da061b
1up-lab
OneupUploaderBundle
Retrieve Storage from injected container.
commit eb7d4d7bea320130d786e075b1f58d4c61da061b Author: Jim Schmid <[email protected]> Date: Tue Mar 12 11:06:50 2013 +0100 Retrieve Storage from injected container. diff --git a/Controller/UploaderController.php b/Controller/UploaderController.php index a511e00..0209311 100644 --- a/Controller/UploaderController.php +++ b/Controller/UploaderController.php @@ -20,5 +20,7 @@ class UploaderController if(!$container->has($config['storage'])) throw new \InvalidArgumentException(sprintf('The storage service "%s" must be defined.')); + + $storage = $container->get($config['storage']); } } \ No newline at end of file
0
71d6118a7598701727b72b2d712ad231184a8778
1up-lab
OneupUploaderBundle
another php5.3 fix
commit 71d6118a7598701727b72b2d712ad231184a8778 Author: mitom <[email protected]> Date: Fri Oct 11 17:14:24 2013 +0200 another php5.3 fix diff --git a/Uploader/Storage/GaufretteOrphanageStorage.php b/Uploader/Storage/GaufretteOrphanageStorage.php index e087c1b..ea5379f 100644 --- a/Uploader/Storage/GaufretteOrphanageStorage.php +++ b/Uploader/Storage/GaufretteOrphanageStorage.php @@ -68,7 +68,8 @@ class GaufretteOrphanageStorage extends GaufretteStorage implements OrphanageSto public function getFiles() { - $keys = $this->chunkStorage->getFilesystem()->listKeys($this->getPath())['keys']; + $keys = $this->chunkStorage->getFilesystem()->listKeys($this->getPath()); + $keys = $keys['keys']; $files = array(); foreach ($keys as $key) {
0
fa48674308ca34c2c035d165ea113a3a8f1f9f7b
1up-lab
OneupUploaderBundle
Improved documentation.
commit fa48674308ca34c2c035d165ea113a3a8f1f9f7b Author: Jim Schmid <[email protected]> Date: Fri Apr 12 14:58:10 2013 +0200 Improved documentation. diff --git a/README.md b/README.md index 558ff06..48eb51b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ OneupUploaderBundle =================== -The OneupUploaderBundle adds support for handling file uploads using one of the following Javascript libraries: +The OneupUploaderBundle adds support for handling file uploads using one of the following Javascript libraries to your Symfony2 application: * [FineUploader](http://fineuploader.com/) * [jQuery File Uploader](http://blueimp.github.io/jQuery-File-Upload/) diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 357df8f..0aae9be 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -1,6 +1,8 @@ Getting started =============== +The OneupUploaderBundle is a Symfony2 bundle developed and tested for versions 2.1+. This bundle does only provide a solid backend for the supported types of Javascript libraries. It does however not provide the assets itself. So in order to use any uploader, you first have to download and integrate it by yourself. + ## Prerequisites This bundle is tested using Symfony2 versions 2.1+. @@ -117,4 +119,8 @@ some more advanced features. > Why didn't you implement the _delete_ feature provided by Fine Uploader? -Fine Uploaders _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. \ No newline at end of file +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. + +> Why didn't you implement the _delete_ feature provided by another library? + +See the answer to the previous question and replace _FineUploader_ by the library you have chosen. \ No newline at end of file
0
515132a404c312ee0beb9dd86263c15ce0933788
1up-lab
OneupUploaderBundle
Added a switch to globally enable and disable chunks. This is necesseray to determine if a developer should provide a storage service.
commit 515132a404c312ee0beb9dd86263c15ce0933788 Author: Jim Schmid <[email protected]> Date: Fri Mar 15 16:36:45 2013 +0100 Added a switch to globally enable and disable chunks. This is necesseray to determine if a developer should provide a storage service. diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index c3f4575..9d98300 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -17,7 +17,8 @@ class Configuration implements ConfigurationInterface ->arrayNode('chunks') ->addDefaultsIfNotSet() ->children() - ->scalarNode('directory')->end() + ->booleanNode('enabled')->defaultFalse()->end() + ->scalarNode('storage')->defaultNull()->end() ->scalarNode('maxage')->defaultValue(604800)->end() ->end() ->end()
0
fd081007887586f13ab15c35c2f7007c05bdacc3
1up-lab
OneupUploaderBundle
Documented chunked uploads.
commit fd081007887586f13ab15c35c2f7007c05bdacc3 Author: Jim Schmid <[email protected]> Date: Sun Apr 7 13:25:56 2013 +0200 Documented chunked uploads. diff --git a/Resources/doc/chunked_uploads.md b/Resources/doc/chunked_uploads.md new file mode 100644 index 0000000..c4b7861 --- /dev/null +++ b/Resources/doc/chunked_uploads.md @@ -0,0 +1,24 @@ +Using Chunked Uploads +===================== + +Fine Uploader comes bundled with the possibility to use so called chunked uploads. If enabed, an uploaded file will be split into equal sized blobs which are sequentially uploaded afterwards. In order to use this feature, be sure to enable it in the frontend. + +```js +$(document).ready(function() +{ + var uploader = new qq.FineUploader({ + element: document.getElementById('uploader'), + request: { + endpoint: "{{ path('_uploader_gallery') }}" + }, + chunking: { + enabled: true, + partSize: 10000000 + } + }); +}); +``` + +The `partSize` property defines the maximum size of a blob, in this case 10MB. + +> Be sure to select a partSize that fits your requirement. If it is too small, the speed of the overall upload drops significantly. \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 85994bd..574d337 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -102,7 +102,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. -* Enable chunked uploads +* [Enable chunked uploads](chunked_uploads.md) * Using the Orphanage * Use Gaufrette as storage layer * Include your own Namer
0