@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'errors' => [ |
|
| 5 | - 'upload' => [ |
|
| 6 | - 'failed' => "The upload of file :name has failed.", |
|
| 7 | - 'access' => "Cannot get write access to upload directory.", |
|
| 8 | - 'type' => "Upload is not allowed for file of type :type.", |
|
| 9 | - 'extension' => "Upload is not allowed for file with extension :extension.", |
|
| 10 | - 'max-size' => "Upload is not allowed for file of size :size. Too big.", |
|
| 11 | - 'min-size' => "Upload is not allowed for file of size :size. Too small.", |
|
| 12 | - 'plugin' => "Upload plugin not found.", |
|
| 13 | - 'request' => "Upload data not available in the request.", |
|
| 14 | - 'invalid' => "Upload data are invalid.", |
|
| 15 | - ], |
|
| 16 | - ], |
|
| 4 | +'errors' => [ |
|
| 5 | +'upload' => [ |
|
| 6 | +'failed' => "The upload of file :name has failed.", |
|
| 7 | +'access' => "Cannot get write access to upload directory.", |
|
| 8 | +'type' => "Upload is not allowed for file of type :type.", |
|
| 9 | +'extension' => "Upload is not allowed for file with extension :extension.", |
|
| 10 | +'max-size' => "Upload is not allowed for file of size :size. Too big.", |
|
| 11 | +'min-size' => "Upload is not allowed for file of size :size. Too small.", |
|
| 12 | +'plugin' => "Upload plugin not found.", |
|
| 13 | +'request' => "Upload data not available in the request.", |
|
| 14 | +'invalid' => "Upload data are invalid.", |
|
| 15 | +], |
|
| 16 | +], |
|
| 17 | 17 | ]; |
@@ -1,17 +1,17 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'errors' => [ |
|
| 5 | - 'upload' => [ |
|
| 6 | - 'failed' => "L'upload du fichier :name a échoué.", |
|
| 7 | - 'access' => "Impossible d'accéder en écriture au répertoire d'upload.", |
|
| 8 | - 'type' => "L'upload n'est pas autorisé pour les fichiers de type :type.", |
|
| 9 | - 'extension' => "L'upload n'est pas autorisé pour les fichiers avec l'extension :extension.", |
|
| 10 | - 'max-size' => "L'upload n'est pas autorisé pour les fichiers de taille :size. Trop grand.", |
|
| 11 | - 'min-size' => "L'upload n'est pas autorisé pour les fichiers de taille :size. Trop petit.", |
|
| 12 | - 'plugin' => "Le plugin Upload est introuvable.", |
|
| 13 | - 'request' => "La requête ne contient pas de données d'upload.", |
|
| 14 | - 'invalid' => "Les données d'upload sont invalides.", |
|
| 15 | - ], |
|
| 16 | - ], |
|
| 4 | +'errors' => [ |
|
| 5 | +'upload' => [ |
|
| 6 | +'failed' => "L'upload du fichier :name a échoué.", |
|
| 7 | +'access' => "Impossible d'accéder en écriture au répertoire d'upload.", |
|
| 8 | +'type' => "L'upload n'est pas autorisé pour les fichiers de type :type.", |
|
| 9 | +'extension' => "L'upload n'est pas autorisé pour les fichiers avec l'extension :extension.", |
|
| 10 | +'max-size' => "L'upload n'est pas autorisé pour les fichiers de taille :size. Trop grand.", |
|
| 11 | +'min-size' => "L'upload n'est pas autorisé pour les fichiers de taille :size. Trop petit.", |
|
| 12 | +'plugin' => "Le plugin Upload est introuvable.", |
|
| 13 | +'request' => "La requête ne contient pas de données d'upload.", |
|
| 14 | +'invalid' => "Les données d'upload sont invalides.", |
|
| 15 | +], |
|
| 16 | +], |
|
| 17 | 17 | ]; |
@@ -22,56 +22,56 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | class File implements FileInterface |
| 24 | 24 | {
|
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The uploaded file type |
| 27 | 27 | * |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - protected $sType; |
|
| 30 | +protected $sType; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * The uploaded file name, without the extension and sanitized |
| 34 | 34 | * |
| 35 | 35 | * @var string |
| 36 | 36 | */ |
| 37 | - protected $sName; |
|
| 37 | +protected $sName; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * The uploaded file name, with the extension |
| 41 | 41 | * |
| 42 | 42 | * @var string |
| 43 | 43 | */ |
| 44 | - protected $sFilename; |
|
| 44 | +protected $sFilename; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * The uploaded file path |
| 48 | 48 | * |
| 49 | 49 | * @var string |
| 50 | 50 | */ |
| 51 | - protected $sPath; |
|
| 51 | +protected $sPath; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * The uploaded file size |
| 55 | 55 | * |
| 56 | 56 | * @var int |
| 57 | 57 | */ |
| 58 | - protected $nSize; |
|
| 58 | +protected $nSize; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * The uploaded file extension |
| 62 | 62 | * |
| 63 | 63 | * @var string |
| 64 | 64 | */ |
| 65 | - protected $sExtension; |
|
| 65 | +protected $sExtension; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * The filesystem where the file is stored |
| 69 | 69 | * |
| 70 | 70 | * @var Filesystem |
| 71 | 71 | */ |
| 72 | - protected $xFilesystem; |
|
| 72 | +protected $xFilesystem; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * Create an instance of this class using data from an uploaded file. |
| 76 | 76 | * |
| 77 | 77 | * @param Filesystem $xFilesystem |
@@ -81,87 +81,87 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return File |
| 83 | 83 | */ |
| 84 | - public static function fromHttpFile(Filesystem $xFilesystem, |
|
| 85 | - UploadedFile $xHttpFile, string $sUploadDir, string $sName): File |
|
| 86 | - {
|
|
| 87 | - $xFile = new File(); |
|
| 88 | - $xFile->xFilesystem = $xFilesystem; |
|
| 89 | - $xFile->sType = $xHttpFile->getClientMediaType(); |
|
| 90 | - $xFile->sName = $sName; |
|
| 91 | - $xFile->sFilename = $xHttpFile->getClientFilename(); |
|
| 92 | - $xFile->sExtension = pathinfo($xFile->sFilename, PATHINFO_EXTENSION); |
|
| 93 | - $xFile->nSize = $xHttpFile->getSize(); |
|
| 94 | - $xFile->sPath = $sUploadDir . $xFile->sName . '.' . $xFile->sExtension; |
|
| 95 | - return $xFile; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 84 | +public static function fromHttpFile(Filesystem $xFilesystem, |
|
| 85 | +UploadedFile $xHttpFile, string $sUploadDir, string $sName): File |
|
| 86 | +{
|
|
| 87 | +$xFile = new File(); |
|
| 88 | +$xFile->xFilesystem = $xFilesystem; |
|
| 89 | +$xFile->sType = $xHttpFile->getClientMediaType(); |
|
| 90 | +$xFile->sName = $sName; |
|
| 91 | +$xFile->sFilename = $xHttpFile->getClientFilename(); |
|
| 92 | +$xFile->sExtension = pathinfo($xFile->sFilename, PATHINFO_EXTENSION); |
|
| 93 | +$xFile->nSize = $xHttpFile->getSize(); |
|
| 94 | +$xFile->sPath = $sUploadDir . $xFile->sName . '.' . $xFile->sExtension; |
|
| 95 | +return $xFile; |
|
| 96 | +} |
|
| 97 | + |
|
| 98 | +/** |
|
| 99 | 99 | * Get the filesystem where the file is stored |
| 100 | 100 | * |
| 101 | 101 | * @return Filesystem |
| 102 | 102 | */ |
| 103 | - public function filesystem(): Filesystem |
|
| 104 | - {
|
|
| 105 | - return $this->xFilesystem; |
|
| 106 | - } |
|
| 103 | +public function filesystem(): Filesystem |
|
| 104 | +{
|
|
| 105 | +return $this->xFilesystem; |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Get the uploaded file type |
| 110 | 110 | * |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function type(): string |
|
| 114 | - {
|
|
| 115 | - return $this->sType; |
|
| 116 | - } |
|
| 113 | +public function type(): string |
|
| 114 | +{
|
|
| 115 | +return $this->sType; |
|
| 116 | +} |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | +/** |
|
| 119 | 119 | * Get the uploaded file name, without the extension and slugified |
| 120 | 120 | * |
| 121 | 121 | * @return string |
| 122 | 122 | */ |
| 123 | - public function name(): string |
|
| 124 | - {
|
|
| 125 | - return $this->sName; |
|
| 126 | - } |
|
| 123 | +public function name(): string |
|
| 124 | +{
|
|
| 125 | +return $this->sName; |
|
| 126 | +} |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Get the uploaded file name, with the extension |
| 130 | 130 | * |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - public function filename(): string |
|
| 134 | - {
|
|
| 135 | - return $this->sFilename; |
|
| 136 | - } |
|
| 133 | +public function filename(): string |
|
| 134 | +{
|
|
| 135 | +return $this->sFilename; |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * Get the uploaded file path |
| 140 | 140 | * |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public function path(): string |
|
| 144 | - {
|
|
| 145 | - return $this->sPath; |
|
| 146 | - } |
|
| 143 | +public function path(): string |
|
| 144 | +{
|
|
| 145 | +return $this->sPath; |
|
| 146 | +} |
|
| 147 | 147 | |
| 148 | - /** |
|
| 148 | +/** |
|
| 149 | 149 | * Get the uploaded file size |
| 150 | 150 | * |
| 151 | 151 | * @return int |
| 152 | 152 | */ |
| 153 | - public function size(): int |
|
| 154 | - {
|
|
| 155 | - return $this->nSize; |
|
| 156 | - } |
|
| 153 | +public function size(): int |
|
| 154 | +{
|
|
| 155 | +return $this->nSize; |
|
| 156 | +} |
|
| 157 | 157 | |
| 158 | - /** |
|
| 158 | +/** |
|
| 159 | 159 | * Get the uploaded file extension |
| 160 | 160 | * |
| 161 | 161 | * @return string |
| 162 | 162 | */ |
| 163 | - public function extension(): string |
|
| 164 | - {
|
|
| 165 | - return $this->sExtension; |
|
| 166 | - } |
|
| 163 | +public function extension(): string |
|
| 164 | +{
|
|
| 165 | +return $this->sExtension; |
|
| 166 | +} |
|
| 167 | 167 | } |
@@ -4,12 +4,12 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface FileNameInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 7 | +/** |
|
| 8 | 8 | * Generate a random name for a file or dir |
| 9 | 9 | * |
| 10 | 10 | * @param int $nLength |
| 11 | 11 | * |
| 12 | 12 | * @return string |
| 13 | 13 | */ |
| 14 | - public function random(int $nLength): string; |
|
| 14 | +public function random(int $nLength): string; |
|
| 15 | 15 | } |
@@ -25,58 +25,58 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | class UploadHandler implements UploadHandlerInterface |
| 27 | 27 | { |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * The uploaded files copied in the user dir |
| 30 | 30 | * |
| 31 | 31 | * @var array |
| 32 | 32 | */ |
| 33 | - private $aUserFiles = []; |
|
| 33 | +private $aUserFiles = []; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * The constructor |
| 37 | 37 | * |
| 38 | 38 | * @param FileStorage $xFileStorage |
| 39 | 39 | * @param UploadManager $xUploadManager |
| 40 | 40 | */ |
| 41 | - public function __construct(private FileStorage $xFileStorage, |
|
| 42 | - private UploadManager $xUploadManager) |
|
| 43 | - {} |
|
| 41 | +public function __construct(private FileStorage $xFileStorage, |
|
| 42 | +private UploadManager $xUploadManager) |
|
| 43 | +{} |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * Set the uploaded file name sanitizer |
| 47 | 47 | * |
| 48 | 48 | * @param Closure $cSanitizer The closure |
| 49 | 49 | * |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - public function sanitizer(Closure $cSanitizer): void |
|
| 53 | - { |
|
| 54 | - $this->xUploadManager->setNameSanitizer($cSanitizer); |
|
| 55 | - } |
|
| 52 | +public function sanitizer(Closure $cSanitizer): void |
|
| 53 | +{ |
|
| 54 | +$this->xUploadManager->setNameSanitizer($cSanitizer); |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * Get the uploaded files |
| 59 | 59 | * |
| 60 | 60 | * @return array |
| 61 | 61 | */ |
| 62 | - public function files(): array |
|
| 63 | - { |
|
| 64 | - return $this->aUserFiles; |
|
| 65 | - } |
|
| 62 | +public function files(): array |
|
| 63 | +{ |
|
| 64 | +return $this->aUserFiles; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * Check if the current request contains uploaded files |
| 69 | 69 | * |
| 70 | 70 | * @param ServerRequestInterface $xRequest |
| 71 | 71 | * |
| 72 | 72 | * @return bool |
| 73 | 73 | */ |
| 74 | - public function canProcessRequest(ServerRequestInterface $xRequest): bool |
|
| 75 | - { |
|
| 76 | - return count($xRequest->getUploadedFiles()) > 0; |
|
| 77 | - } |
|
| 74 | +public function canProcessRequest(ServerRequestInterface $xRequest): bool |
|
| 75 | +{ |
|
| 76 | +return count($xRequest->getUploadedFiles()) > 0; |
|
| 77 | +} |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * Process the uploaded files in the HTTP request |
| 81 | 81 | * |
| 82 | 82 | * @param ServerRequestInterface $xRequest |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | * @return bool |
| 85 | 85 | * @throws RequestException |
| 86 | 86 | */ |
| 87 | - public function processRequest(ServerRequestInterface $xRequest): bool |
|
| 88 | - { |
|
| 89 | - // Copy the uploaded files from the HTTP request. |
|
| 90 | - $this->aUserFiles = $this->xUploadManager->readFromHttpData($xRequest); |
|
| 91 | - return true; |
|
| 92 | - } |
|
| 87 | +public function processRequest(ServerRequestInterface $xRequest): bool |
|
| 88 | +{ |
|
| 89 | +// Copy the uploaded files from the HTTP request. |
|
| 90 | +$this->aUserFiles = $this->xUploadManager->readFromHttpData($xRequest); |
|
| 91 | +return true; |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * @param string $sStorage |
| 96 | 96 | * @param Closure $cFactory |
| 97 | 97 | * |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - public function registerStorageAdapter(string $sStorage, Closure $cFactory): void |
|
| 101 | - { |
|
| 102 | - $this->xFileStorage->registerAdapter($sStorage, $cFactory); |
|
| 103 | - } |
|
| 100 | +public function registerStorageAdapter(string $sStorage, Closure $cFactory): void |
|
| 101 | +{ |
|
| 102 | +$this->xFileStorage->registerAdapter($sStorage, $cFactory); |
|
| 103 | +} |
|
| 104 | 104 | } |
@@ -30,16 +30,16 @@ |
||
| 30 | 30 | |
| 31 | 31 | abstract class AbstractRequestPlugin extends AbstractPlugin implements CallableRegistryInterface, RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * @var Target |
| 35 | 35 | */ |
| 36 | - protected $xTarget = null; |
|
| 36 | +protected $xTarget = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public function getTarget(): ?Target |
|
| 42 | - { |
|
| 43 | - return $this->xTarget; |
|
| 44 | - } |
|
| 41 | +public function getTarget(): ?Target |
|
| 42 | +{ |
|
| 43 | +return $this->xTarget; |
|
| 44 | +} |
|
| 45 | 45 | } |
@@ -7,21 +7,21 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | interface RequestHandlerInterface |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * Get the target function or class and method |
| 12 | 12 | * |
| 13 | 13 | * @return Target|null |
| 14 | 14 | */ |
| 15 | - public function getTarget(): ?Target; |
|
| 15 | +public function getTarget(): ?Target; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * @param ServerRequestInterface $xRequest |
| 19 | 19 | * |
| 20 | 20 | * @return Target |
| 21 | 21 | */ |
| 22 | - public function setTarget(ServerRequestInterface $xRequest): Target; |
|
| 22 | +public function setTarget(ServerRequestInterface $xRequest): Target; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * Check if this plugin can process the current request |
| 26 | 26 | * |
| 27 | 27 | * Called by the <Jaxon\Plugin\RequestManager> when a request has been received to determine |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | - public static function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 34 | +public static function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Process the current request |
| 38 | 38 | * |
| 39 | 39 | * Called by the <Jaxon\Plugin\RequestManager> when a request is being processed. |
@@ -42,5 +42,5 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public function processRequest(): void; |
|
| 45 | +public function processRequest(): void; |
|
| 46 | 46 | } |
@@ -16,31 +16,31 @@ |
||
| 16 | 16 | |
| 17 | 17 | class JsCode |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * The main javascript code |
| 21 | 21 | * |
| 22 | 22 | * @var string |
| 23 | 23 | */ |
| 24 | - public $sJs = ''; |
|
| 24 | +public $sJs = ''; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The js files |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - public $aFiles = []; |
|
| 31 | +public $aFiles = []; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The javascript code to be inserted inline before the main code |
| 35 | 35 | * |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - public $sJsBefore = ''; |
|
| 38 | +public $sJsBefore = ''; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The javascript code to be inserted inline after the main code |
| 42 | 42 | * |
| 43 | 43 | * @var string |
| 44 | 44 | */ |
| 45 | - public $sJsAfter = ''; |
|
| 45 | +public $sJsAfter = ''; |
|
| 46 | 46 | } |
@@ -18,11 +18,11 @@ |
||
| 18 | 18 | |
| 19 | 19 | class ReadyScriptGenerator extends AbstractCodeGenerator |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * @inheritDoc |
| 23 | 23 | */ |
| 24 | - public function getScript(): string |
|
| 25 | - { |
|
| 26 | - return "jaxon.dom.ready(() => jaxon.processCustomAttrs());"; |
|
| 27 | - } |
|
| 24 | +public function getScript(): string |
|
| 25 | +{ |
|
| 26 | +return "jaxon.dom.ready(() => jaxon.processCustomAttrs());"; |
|
| 27 | +} |
|
| 28 | 28 | } |