Compare commits
2 Commits
2f68acdfc1
...
306efa3769
Author | SHA1 | Date | |
---|---|---|---|
306efa3769 | |||
1c86051997 |
32
.git.template
Normal file
32
.git.template
Normal file
|
@ -0,0 +1,32 @@
|
|||
# If applied, this commit will ...
|
||||
|
||||
# Why was this change necessary? Improvements brought about by the
|
||||
# change.
|
||||
|
||||
# End
|
||||
|
||||
# Format
|
||||
# --------------------
|
||||
# (If applied, this commit will...) <subject> (Max 72 char)
|
||||
# |<---- Preferably using up to 50 chars --->|<------------------->|
|
||||
# Example:
|
||||
# Implement automated commit messages
|
||||
|
||||
# (Optional) Explain why this change is being made
|
||||
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
|
||||
|
||||
# (Optional) Provide links or keys to any relevant tickets, articles or other resources
|
||||
# Example: Github issue #23
|
||||
|
||||
# --- COMMIT END ---
|
||||
#
|
||||
# Remember to:
|
||||
# * Capitalize the subject line
|
||||
# * Use the imperative mood in the subject line
|
||||
# * Do not end the subject line with a period
|
||||
# * Separate subject from body with a blank line
|
||||
# * Use the body to explain what and why vs. how
|
||||
# * Can use multiple lines with "-" or "*" for bullet points in body
|
||||
# --------------------
|
||||
|
||||
# Continuous integration messages
|
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.php text eol=lf diff=php
|
||||
*.css text eol=lf diff=css
|
31
MD_STD.php
31
MD_STD.php
|
@ -378,4 +378,35 @@ final class MD_STD {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a file exists, with one of the expected mime types.
|
||||
*
|
||||
* @param string $filepath File path of the file that needs to exist.
|
||||
* @param string[] $accepted_mimetype Mime type the file should have.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function ensure_file(string $filepath, array $accepted_mimetype = []) {
|
||||
|
||||
if (!\file_exists($filepath)) {
|
||||
throw new MDFileDoesNotExist("File " . basename($filepath) . " does not exist");
|
||||
}
|
||||
|
||||
// Check for mime type follows. If no check is to be done, ignore this.
|
||||
if (empty($accepted_mimetype)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$finfo = \finfo_open(FILEINFO_MIME_TYPE);
|
||||
if (!($mime_type = finfo_file($finfo, $filepath))) {
|
||||
throw new MDWrongFileType("Cannot get mime type of file: " . basename($filepath));
|
||||
}
|
||||
\finfo_close($finfo);
|
||||
|
||||
if (!\in_array($mime_type, $accepted_mimetype)) {
|
||||
throw new MDWrongFileType("Incorrect mime type of file " . \basename($filepath) . ". Mime type is " . \mime_content_type($filepath) . ", accepted any of ['" . \implode("', '", $accepted_mimetype) . "']");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user