11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Netgen \Bundle \EnhancedBinaryFileBundle \FieldHandler ;
46
7+ use DOMDocument ;
58use eZ \Publish \API \Repository \Values \ContentType \FieldDefinition ;
69use eZ \Publish \Core \FieldType \Value ;
7- use Netgen \Bundle \EnhancedBinaryFileBundle \Core \FieldType \EnhancedBinaryFile \Value as EnhancedBinaryFileValue ;
810use eZ \Publish \Core \IO \IOServiceInterface ;
11+ use Netgen \Bundle \EnhancedBinaryFileBundle \Core \FieldType \EnhancedBinaryFile \Value as EnhancedBinaryFileValue ;
912use Netgen \Bundle \InformationCollectionBundle \FieldHandler \Custom \CustomLegacyFieldHandlerInterface ;
1013use Netgen \Bundle \InformationCollectionBundle \Value \LegacyData ;
11- use DOMDocument ;
1214
1315class EnhancedBinaryFileHandler implements CustomLegacyFieldHandlerInterface
1416{
@@ -28,23 +30,23 @@ public function __construct(IOServiceInterface $IOService)
2830 }
2931
3032 /**
31- * @inheritDoc
33+ * {@inheritdoc}
3234 */
3335 public function supports (Value $ value )
3436 {
3537 return $ value instanceof EnhancedBinaryFileValue;
3638 }
3739
3840 /**
39- * @inheritDoc
41+ * {@inheritdoc}
4042 */
4143 public function toString (Value $ value , FieldDefinition $ fieldDefinition )
4244 {
43- return (string )$ value ;
45+ return (string ) $ value ;
4446 }
4547
4648 /**
47- * @inheritDoc
49+ * {@inheritdoc}
4850 */
4951 public function getLegacyValue (Value $ value , FieldDefinition $ fieldDefinition )
5052 {
@@ -58,7 +60,7 @@ public function getLegacyValue(Value $value, FieldDefinition $fieldDefinition)
5860
5961 /**
6062 * Create XML doc string
61- * and save file to filesystem
63+ * and save file to filesystem.
6264 *
6365 * @param EnhancedBinaryFileValue $value
6466 * @param FieldDefinition $fieldDefinition
@@ -69,19 +71,19 @@ protected function store(EnhancedBinaryFileValue $value, FieldDefinition $fieldD
6971 {
7072 $ binaryFile = $ this ->storeBinaryFileToPath ($ value );
7173
72- $ doc = new DOMDocument ( '1.0 ' , 'utf-8 ' );
73- $ root = $ doc ->createElement ( 'binaryfile-info ' );
74- $ binaryFileList = $ doc ->createElement ( 'binaryfile-attributes ' );
74+ $ doc = new DOMDocument ('1.0 ' , 'utf-8 ' );
75+ $ root = $ doc ->createElement ('binaryfile-info ' );
76+ $ binaryFileList = $ doc ->createElement ('binaryfile-attributes ' );
7577
7678 $ fileInfo = [
7779 'Filename ' => htmlentities ($ binaryFile ->uri ),
7880 'OriginalFilename ' => htmlentities ($ value ->fileName ),
7981 'Size ' => $ value ->fileSize ,
8082 ];
8183
82- foreach ($ fileInfo as $ key => $ binaryFileItem ) {
84+ foreach ($ fileInfo as $ key => $ binaryFileItem ) {
8385 $ binaryFileElement = $ doc ->createElement ($ key , $ binaryFileItem );
84- $ binaryFileList ->appendChild ( $ binaryFileElement );
86+ $ binaryFileList ->appendChild ($ binaryFileElement );
8587 }
8688
8789 $ root ->appendChild ($ binaryFileList );
@@ -91,7 +93,7 @@ protected function store(EnhancedBinaryFileValue $value, FieldDefinition $fieldD
9193 }
9294
9395 /**
94- * Stores file to filesystem
96+ * Stores file to filesystem.
9597 *
9698 * @param EnhancedBinaryFileValue $value
9799 * @param string $storagePrefix
@@ -102,12 +104,12 @@ protected function storeBinaryFileToPath(EnhancedBinaryFileValue $value, $storag
102104 {
103105 $ binaryCreateStruct = $ this ->IOService
104106 ->newBinaryCreateStructFromLocalFile ($ value ->inputUri );
105- $ binaryCreateStruct ->id = $ storagePrefix . $ value ->fileName ;
107+
108+ $ encodedFilename = uniqid ();
109+ $ binaryCreateStruct ->id = $ storagePrefix . $ encodedFilename ;
106110
107111 $ binaryFile = $ this ->IOService ->createBinaryFile ($ binaryCreateStruct );
108112
109113 return $ binaryFile ;
110114 }
111115}
112-
113-
0 commit comments