mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 13:28:39 +00:00
Simplify flag checks
This commit is contained in:
parent
05cafa68d1
commit
581944b3cf
|
|
@ -138,4 +138,20 @@ abstract class Enum
|
||||||
return count(self::getConstants());
|
return count(self::getConstants());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if flag is set
|
||||||
|
*
|
||||||
|
* This only works for binary flags.
|
||||||
|
*
|
||||||
|
* @param int $flags Set flags
|
||||||
|
* @param int $checkForFlag Check if this flag is part of the set flags
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function hasFlag(int $flags, int $checkForFlag) : bool
|
||||||
|
{
|
||||||
|
return ($flags & $checkForFlag) === $checkForFlag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,14 @@ class File extends FileAbstract implements FileInterface
|
||||||
$exists = file_exists($path);
|
$exists = file_exists($path);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists)
|
(ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|
||||||
|| (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists)
|
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|
||||||
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)
|
||||||
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
|
|| (!$exists && ContentPutMode::hasFlag($mode, ContentPutMode::CREATE))
|
||||||
) {
|
) {
|
||||||
if (($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists) {
|
if (ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists) {
|
||||||
file_put_contents($path, file_get_contents($path) . $content);
|
file_put_contents($path, file_get_contents($path) . $content);
|
||||||
} elseif (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) {
|
} elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) {
|
||||||
file_put_contents($path, $content . file_get_contents($path));
|
file_put_contents($path, $content . file_get_contents($path));
|
||||||
} else {
|
} else {
|
||||||
if (!Directory::exists(dirname($path))) {
|
if (!Directory::exists(dirname($path))) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user