-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Seerus
authored and
Seerus
committed
Aug 20, 2015
1 parent
4579cd0
commit bf4e2a9
Showing
21 changed files
with
3,394 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Glavweb\UploaderBundle\Driver; | ||
|
||
use Doctrine\Common\Annotations\Reader as AnnotationReader; | ||
use Glavweb\UploaderBundle\Exception\ClassNotUploadableException; | ||
use Glavweb\UploaderBundle\Exception\ValueEmptyException; | ||
|
||
/** | ||
* Annotation driver | ||
* | ||
*/ | ||
class AnnotationDriver | ||
{ | ||
const UPLOADABLE_ANNOTATION = 'Glavweb\UploaderBundle\Mapping\Annotation\Uploadable'; | ||
const UPLOADABLE_FIELD_ANNOTATION = 'Glavweb\UploaderBundle\Mapping\Annotation\UploadableField'; | ||
|
||
protected $reader; | ||
|
||
public function __construct(AnnotationReader $reader) | ||
{ | ||
$this->reader = $reader; | ||
} | ||
|
||
public function loadDataForClass(\ReflectionClass $class) | ||
{ | ||
if (!$this->isUploadable($class)) { | ||
throw new ClassNotUploadableException(); | ||
} | ||
|
||
$data = array(); | ||
|
||
foreach ($class->getProperties() as $property) { | ||
$uploadableField = $this->reader->getPropertyAnnotation($property, self::UPLOADABLE_FIELD_ANNOTATION); | ||
if ($uploadableField === null) { | ||
continue; | ||
} | ||
|
||
$fieldData = array( | ||
'mapping' => $uploadableField->getMapping(), | ||
'nameAddFunction' => $uploadableField->getNameAddFunction(), | ||
'nameGetFunction' => $uploadableField->getNameGetFunction() | ||
); | ||
|
||
// $metadata->fields[$property->getName()] = $fieldData; | ||
$data[$property->getName()] = $fieldData; | ||
} | ||
|
||
// return $metadata; | ||
return $data; | ||
} | ||
|
||
protected function isUploadable(\ReflectionClass $class) | ||
{ | ||
return $this->reader->getClassAnnotation($class, self::UPLOADABLE_ANNOTATION) !== null; | ||
} | ||
|
||
public function getDataByFieldName(\ReflectionClass $class, $fieldName) | ||
{ | ||
if (!$this->isUploadable($class)) { | ||
throw new ClassNotUploadableException(); | ||
} | ||
|
||
if (!$fieldName) { | ||
throw new ValueEmptyException(); | ||
} | ||
|
||
$property = $class->getProperty($fieldName); | ||
|
||
if (!$property) { | ||
return false; | ||
} | ||
|
||
$uploadableField = $this->reader->getPropertyAnnotation($property, self::UPLOADABLE_FIELD_ANNOTATION); | ||
|
||
if (!$uploadableField) { | ||
return false; | ||
} | ||
|
||
return array( | ||
'mapping' => $uploadableField->getMapping(), | ||
'nameAddFunction' => $uploadableField->getNameAddFunction(), | ||
'nameGetFunction' => $uploadableField->getNameGetFunction() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Glavweb\UploaderBundle\EventListener; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Registry; | ||
use Glavweb\UploaderBundle\Event\ValidationEvent; | ||
use Glavweb\UploaderBundle\Exception\ValidationException; | ||
|
||
class MaxFilesValidationListener | ||
{ | ||
private $doctrine; | ||
|
||
/** | ||
* @param Registry $doctrine | ||
*/ | ||
public function __construct(Registry $doctrine) | ||
{ | ||
$this->doctrine = $doctrine; | ||
} | ||
|
||
public function onValidate(ValidationEvent $event) | ||
{ | ||
// $config = $event->getConfig(); | ||
// | ||
// if (!isset($config['max_files'])) { | ||
// return; | ||
// } | ||
// | ||
// $request = $event->getRequest(); | ||
// $requestId = $request->get('_glavweb_uploader_request_id'); | ||
// $qb = $this->doctrine->getEntityManager()->createQueryBuilder(); | ||
// $qb->select('COUNT(m.id)') | ||
// ->from('GlavwebUploaderBundle:Media', 'm') | ||
// ->where('m.requestId = :requestId') | ||
// ->setParameter('requestId', $requestId); | ||
// $result = $qb->getQuery()->getSingleScalarResult(); | ||
// | ||
// if ($result >= $config['max_files']) { | ||
// throw new ValidationException('error.maxfiles'); | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Glavweb\UploaderBundle\Exception\Exception; | ||
/** | ||
* Class Exception | ||
* @package Glavweb\UploaderBundle\Exception | ||
*/ | ||
class ClassNotUploadableException extends Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Glavweb\UploaderBundle\Exception\Exception; | ||
/** | ||
* Class Exception | ||
* @package Glavweb\UploaderBundle\Exception | ||
*/ | ||
class MappingNotSetException extends Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Glavweb\UploaderBundle\Exception\Exception; | ||
/** | ||
* Class Exception | ||
* @package Glavweb\UploaderBundle\Exception | ||
*/ | ||
class NotFoundPropertiesInAnnotationException extends Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Glavweb\UploaderBundle\Exception\Exception; | ||
/** | ||
* Class Exception | ||
* @package Glavweb\UploaderBundle\Exception | ||
*/ | ||
class RequestEmptyException extends Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
|
||
namespace Glavweb\UploaderBundle\Exception; | ||
|
||
use Glavweb\UploaderBundle\Exception\Exception; | ||
/** | ||
* Class Exception | ||
* @package Glavweb\UploaderBundle\Exception | ||
*/ | ||
class ValueEmptyException extends Exception | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.