6
6
*/
7
7
namespace eZ \Publish \Core \FieldType \BinaryBase ;
8
8
9
+ use eZ \Publish \Core \Base \Exceptions \ContentFieldValidationException ;
10
+ use eZ \Publish \Core \FieldType \Validator \FileExtensionBlackListValidator ;
9
11
use eZ \Publish \Core \IO \IOServiceInterface ;
10
12
use eZ \Publish \SPI \FieldType \BinaryBase \PathGenerator ;
11
13
use eZ \Publish \SPI \FieldType \BinaryBase \RouteAwarePathGenerator ;
@@ -39,24 +41,21 @@ class BinaryBaseStorage extends GatewayBasedStorage
39
41
/** @var \eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway */
40
42
protected $ gateway ;
41
43
42
- /**
43
- * Construct from gateways.
44
- *
45
- * @param \eZ\Publish\SPI\FieldType\StorageGateway $gateway
46
- * @param \eZ\Publish\Core\IO\IOServiceInterface $ioService
47
- * @param \eZ\Publish\SPI\FieldType\BinaryBase\PathGenerator $pathGenerator
48
- * @param \eZ\Publish\SPI\IO\MimeTypeDetector $mimeTypeDetector
49
- */
44
+ /** @var \eZ\Publish\Core\FieldType\Validator\FileExtensionBlackListValidator */
45
+ protected $ fileExtensionBlackListValidator ;
46
+
50
47
public function __construct (
51
48
StorageGateway $ gateway ,
52
49
IOServiceInterface $ ioService ,
53
50
PathGenerator $ pathGenerator ,
54
- MimeTypeDetector $ mimeTypeDetector
51
+ MimeTypeDetector $ mimeTypeDetector ,
52
+ FileExtensionBlackListValidator $ fileExtensionBlackListValidator
55
53
) {
56
54
parent ::__construct ($ gateway );
57
55
$ this ->ioService = $ ioService ;
58
56
$ this ->pathGenerator = $ pathGenerator ;
59
57
$ this ->mimeTypeDetector = $ mimeTypeDetector ;
58
+ $ this ->fileExtensionBlackListValidator = $ fileExtensionBlackListValidator ;
60
59
}
61
60
62
61
/**
@@ -67,6 +66,10 @@ public function setDownloadUrlGenerator(PathGenerator $downloadUrlGenerator)
67
66
$ this ->downloadUrlGenerator = $ downloadUrlGenerator ;
68
67
}
69
68
69
+ /**
70
+ * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
71
+ * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException
72
+ */
70
73
public function storeFieldData (VersionInfo $ versionInfo , Field $ field , array $ context )
71
74
{
72
75
if ($ field ->value ->externalData === null ) {
@@ -76,6 +79,17 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co
76
79
}
77
80
78
81
if (isset ($ field ->value ->externalData ['inputUri ' ])) {
82
+ $ this ->fileExtensionBlackListValidator ->validateFileExtension ($ field ->value ->externalData ['fileName ' ]);
83
+ if (!empty ($ errors = $ this ->fileExtensionBlackListValidator ->getErrors ())) {
84
+ $ preparedErrors = [];
85
+ $ preparedErrors [$ field ->fieldDefinitionId ][$ field ->languageCode ] = $ errors ;
86
+
87
+ throw ContentFieldValidationException::createNewWithMultiline (
88
+ $ preparedErrors ,
89
+ $ versionInfo ->contentInfo ->name
90
+ );
91
+ }
92
+
79
93
$ field ->value ->externalData ['mimeType ' ] = $ this ->mimeTypeDetector ->getFromPath ($ field ->value ->externalData ['inputUri ' ]);
80
94
$ createStruct = $ this ->ioService ->newBinaryCreateStructFromLocalFile ($ field ->value ->externalData ['inputUri ' ]);
81
95
$ createStruct ->id = $ this ->pathGenerator ->getStoragePathForField ($ field , $ versionInfo );
0 commit comments