Skip to content

Commit

Permalink
Moved throws to correct location for accurate stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
NinoFloris committed Aug 19, 2016
1 parent 6791bdb commit 5dac507
Show file tree
Hide file tree
Showing 49 changed files with 371 additions and 285 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/CompilerPass/ProcessorCompilerPass.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
5 changes: 3 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

namespace SRIO\RestUploadBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/Factory/StorageFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\DependencyInjection\Factory;

use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -10,12 +11,11 @@ class StorageFactory
{
/**
* Create the storage service.
*
*/
public function create(ContainerBuilder $container, $id, array $config)
{
$adapterId = $config['filesystem'] . '.adapter';
$adapterId = $config['filesystem'].'.adapter';

if ($config['type'] === 'gaufrette') {
$adapterDefinition = new DefinitionDecorator('srio_rest_upload.storage.gaufrette_adapter');
$adapterDefinition->setPublic(false);
Expand All @@ -26,7 +26,7 @@ public function create(ContainerBuilder $container, $id, array $config)
$adapterDefinition = new DefinitionDecorator('srio_rest_upload.storage.flysystem_adapter');
$adapterDefinition->setPublic(false);
$adapterDefinition->replaceArgument(0, new Reference($config['filesystem']));

$container->setDefinition($adapterId, $adapterDefinition);
}

Expand Down
13 changes: 7 additions & 6 deletions DependencyInjection/SRIORestUploadExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -7,18 +8,17 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

use SRIO\RestUploadBundle\DependencyInjection\Factory\StorageFactory;

/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class SRIORestUploadExtension extends Extension
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand Down Expand Up @@ -60,10 +60,11 @@ private function createStorageServices(ContainerBuilder $container, array $stora
/**
* Create a single storage service.
*
* @param StorageFactory $factory
* @param ContainerBuilder $containerBuilder
* @param StorageFactory $factory
* @param ContainerBuilder $containerBuilder
* @param $name
* @param array $config
* @param array $config
*
* @return string
*/
private function createStorage(StorageFactory $factory, ContainerBuilder $containerBuilder, $name, array $config)
Expand Down
4 changes: 2 additions & 2 deletions Entity/ResumableUploadSession.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SRIO\RestUploadBundle\Entity;

/**
* This model represent a resumable upload session. It is used to store
* a session ID and the related file path.
*
*/
class ResumableUploadSession
{
Expand Down Expand Up @@ -46,7 +46,7 @@ class ResumableUploadSession
/**
* Content length.
*
* @var integer
* @var int
*/
protected $contentLength;

Expand Down
4 changes: 2 additions & 2 deletions Exception/FileExistsException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace SRIO\RestUploadBundle\Exception;

class FileExistsException extends \Exception
{

}
}
4 changes: 2 additions & 2 deletions Exception/FileNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace SRIO\RestUploadBundle\Exception;

class FileNotFoundException extends \Exception
{

}
}
1 change: 1 addition & 0 deletions Exception/InternalUploadProcessorException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\Exception;

class InternalUploadProcessorException extends UploadProcessorException
Expand Down
1 change: 1 addition & 0 deletions Exception/UploadException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\Exception;

class UploadException extends \Exception
Expand Down
1 change: 1 addition & 0 deletions Exception/UploadProcessorException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace SRIO\RestUploadBundle\Exception;

class UploadProcessorException extends UploadException
Expand Down
2 changes: 1 addition & 1 deletion Model/UploadableFileInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace SRIO\RestUploadBundle\Model;

use SRIO\RestUploadBundle\Storage\UploadedFile;

/**
* A file object that will be uploaded with RestUploadBundle must implements
* this interface.
*
*/
interface UploadableFileInterface
{
Expand Down
32 changes: 20 additions & 12 deletions Processor/AbstractUploadProcessor.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace SRIO\RestUploadBundle\Processor;

use SRIO\RestUploadBundle\Exception\UploadException;
use SRIO\RestUploadBundle\Exception\UploadProcessorException;
use SRIO\RestUploadBundle\Model\UploadableFileInterface;
use SRIO\RestUploadBundle\Request\RequestContentHandler;
use SRIO\RestUploadBundle\Request\RequestContentHandlerInterface;

use SRIO\RestUploadBundle\Upload\StorageHandler;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
Expand Down Expand Up @@ -47,10 +47,11 @@ public function __construct(StorageHandler $storageHandler)
/**
* Constructor.
*
* @param Request $request
* @param FormInterface $form
* @param array $config
* @return boolean
* @param Request $request
* @param FormInterface $form
* @param array $config
*
* @return bool
*/
public function handleUpload(Request $request, FormInterface $form = null, array $config = array())
{
Expand All @@ -66,7 +67,8 @@ public function handleUpload(Request $request, FormInterface $form = null, array
* This method return a Response object that will be sent back
* to the client or will be caught by controller.
*
* @param Request $request
* @param Request $request
*
* @return \SRIO\RestUploadBundle\Upload\UploadResult
*/
abstract public function handleRequest(Request $request);
Expand All @@ -77,7 +79,8 @@ abstract public function handleRequest(Request $request);
* It walk one the form and make an intersection between its keys and
* provided data.
*
* @param array $data
* @param array $data
*
* @return array
*/
protected function createFormData(array $data)
Expand All @@ -90,7 +93,8 @@ protected function createFormData(array $data)
/**
* Get keys of the form.
*
* @param FormInterface $form
* @param FormInterface $form
*
* @return array
*/
protected function getFormKeys(FormInterface $form)
Expand All @@ -106,7 +110,8 @@ protected function getFormKeys(FormInterface $form)
/**
* Get a request content handler.
*
* @param Request $request
* @param Request $request
*
* @return RequestContentHandlerInterface
*/
protected function getRequestContentHandler(Request $request)
Expand All @@ -121,8 +126,9 @@ protected function getRequestContentHandler(Request $request)
/**
* Check that needed headers are here.
*
* @param Request $request the request
* @param array $headers the headers to check
* @param Request $request the request
* @param array $headers the headers to check
*
* @throws \SRIO\RestUploadBundle\Exception\UploadException
*/
protected function checkHeaders(Request $request, array $headers)
Expand All @@ -140,8 +146,10 @@ protected function checkHeaders(Request $request, array $headers)
/**
* Set the uploaded file on the form data.
*
* @param UploadedFile $file
* @param UploadedFile $file
*
* @throws \SRIO\RestUploadBundle\Exception\UploadProcessorException
*
* @deprecated
*/
protected function setUploadedFile(UploadedFile $file)
Expand Down
14 changes: 8 additions & 6 deletions Processor/FormDataUploadProcessor.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SRIO\RestUploadBundle\Processor;

use SRIO\RestUploadBundle\Storage\FileStorage;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;

use SRIO\RestUploadBundle\Exception\UploadException;
use SRIO\RestUploadBundle\Upload\UploadResult;

Expand All @@ -14,21 +14,23 @@ class FormDataUploadProcessor extends SimpleUploadProcessor
const KEY_FIELD_FORM = 'key_form';

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function handleUpload(Request $request, FormInterface $form = null, array $config = array())
{
$config = array_merge(array(
self::KEY_FIELD_FILE => 'file',
self::KEY_FIELD_FORM => 'form'
self::KEY_FIELD_FORM => 'form',
), $config);

return parent::handleUpload($request, $form, $config);
}

/**
* @param Request $request
* @param Request $request
*
* @return \SRIO\RestUploadBundle\Upload\UploadResult
*
* @throws \Exception|\SRIO\RestUploadBundle\Exception\UploadException
*/
public function handleRequest(Request $request)
Expand Down Expand Up @@ -77,8 +79,8 @@ public function handleRequest(Request $request)
$contents = file_get_contents($uploadedFile->getPathname());
$file = $this->storageHandler->store($response, $contents, array(
'metadata' => array(
FileStorage::METADATA_CONTENT_TYPE => $uploadedFile->getMimeType()
)
FileStorage::METADATA_CONTENT_TYPE => $uploadedFile->getMimeType(),
),
));

$response->setFile($file);
Expand Down
Loading

0 comments on commit 5dac507

Please sign in to comment.