Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor support for values in file properties #13

Merged
merged 1 commit into from Apr 15, 2020

Conversation

mcaskill
Copy link
Member

Improve support for multilingual/multiple values across various methods of FileProperty and its variants.

Validation will now (correctly) log a message if a value (i.e., a file) is missing, is unparsable, is a rejected MIME type, or exceeds a maximum file size.

Breaking Changes:

  • Removed deprecated accessor methods in favour of get-prefix variants
  • Refactored validation methods to focus on values (i.e., files) directly
  • Changed how default MIME types are defined to allow overriding in media-specific properties

Fixed:

  • Edge case where MIME type resolution returns "inode/x-empty" or empty string
  • Edge cases where a string is expected
  • Support for validating/handling multilingual/multiple values

Added:

  • Option fallbackFilename to customize generated filename (defaults to property label)
  • Method hasAcceptedMimetypes() to check if any custom or fallback MIME types are specified
  • Method getDefaultAcceptedMimetypes() to distinguish between custom and fallback MIME types in property variants like ImageProperty and AudioProperty
  • Method assertValidUploadPath() to ensure upload path exists (or creates it) and checks if writable
  • Methods isAcceptedMimeType() and isAcceptedFilesize()
  • Methods generateExtensionFromFile(), generateExtensionFromMimeType(), and resolveExtensionFromMimeType()
  • Method formatFilesize() to format bytes into a human-readable unit
  • Method pathFor() to make an absolute path to a directory or file
  • Method parseValAsFileList() to flatten value object to simplify validation and parsing of values

Changed:

  • Bump branch-alias to 0.11
  • Moved default MIME types from getAcceptedMimeTypes() to new getDefaultAcceptedMimetypes() for ImageProperty and AudioProperty
  • Fallback routine in method getMimetype() to retrieve the MIME type of the first value
  • Fallback routine in method getFilesize() to retrieve the MIME type of the first value
  • Renamed validation methods and internal routines to validate MIME type and size of available values (ignoring getMimetype() and getFilesize)
  • Unified methods dataUpload() and fileUpload() to throw exceptions
  • Unified methods saveDataUploads() and saveDataUploads() to catch exceptions and log errors
  • Replaced validation methods with new isAccepted*() methods inside dataUpload() and fileUpload()
  • Method dataUpload() to generate filename and extension before calling uploadTarget()
  • Method uploadTarget() to simplify making of filename
  • Method generateFilename() to use fallbackFilename and sanitize value

Removed:

  • Aliases filesize(), mimetype(), mimetypeFor() in favour of their get-prefixed methods

Improve support for multilingual/multiple values across various methods of FileProperty.

Validation will now (correctly) log a message if a value (a file) is missing, is unparsable, is a rejected MIME type, or exceeds a maximum file size.

Breaking Changes:
- Removed deprecated accessor methods in favour of get-prefix variants
- Refactored validation methods to focus on values (files) directly
- Moved default MIME types to allow overriding in media-specific properties

Added:
- Option "fallbackFilename" to customize generated filename (defaults to property label)
- Method `hasAcceptedMimetypes()` to check if any custom or fallback MIME types are specified
- Method `getDefaultAcceptedMimetypes()` to distinguish between custom and fallback MIME types in property variants like ImageProperty and AudioProperty
- Method `assertValidUploadPath()` to ensure upload path exists (or creates it) and checks if writable
- Methods `isAcceptedMimeType()` and `isAcceptedFilesize()`
- Methods `generateExtensionFromFile()`, `generateExtensionFromMimeType()`, and `resolveExtensionFromMimeType()`
- Method `formatFilesize()` to format bytes into a human-readable unit
- Method `pathFor()` to make an absolute path to a directory or file
- Method `parseValAsFileList()` to flatten value object to simplify validation and parsing of values

Removed:
- Aliases `filesize()`, `mimetype()`, `mimetypeFor()` in favour of their get-prefixed methods

Changed:
- Bump branch-alias to 0.11
- Moved default MIME types from `getAcceptedMimeTypes()` to new `getDefaultAcceptedMimetypes()` for ImageProperty and AudioProperty
- Fallback in method `getMimetype()` to retrieve the MIME type of the first value
- Fallback in method `getFilesize()` to retrieve the MIME type of the first value
- Renamed validation methods and internal routines to validate MIME type and size of available values (ignoring `getMimetype()` and `getFilesize`)
- Unified methods `dataUpload()` and `fileUpload()` to throw exceptions
- Unified methods `saveDataUploads()` and `saveDataUploads()` to catch exceptions and log errors
- Replaced validation methods with new `isAccepted*()` methods inside `dataUpload()` and `fileUpload()`
- Method `dataUpload()` to generate filename and extension before calling `uploadTarget()`
- Method `uploadTarget()` to simplify making of filename
- Method `generateFilename()` to use "fallbackFilename" and sanitize value

Fixed:
- Edge case where MIME type resolution returns "inode/x-empty" or empty string
- Edge cases where a string is expected
@mcaskill mcaskill force-pushed the mcaskill-patch-file-properties branch from 6c9ba0d to 9d3c98f Compare April 15, 2020 17:55
@mcaskill mcaskill merged commit 436d742 into master Apr 15, 2020
@mcaskill mcaskill deleted the mcaskill-patch-file-properties branch April 15, 2020 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants