mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Simplify flag checks
This commit is contained in:
parent
05cafa68d1
commit
581944b3cf
|
|
@ -25,7 +25,7 @@ Features this framework provides are:
|
|||
* Request/Response management
|
||||
* Math (e.g. matrix, forecasting, optimization, geometry, stochastics, etc.)
|
||||
* Module management
|
||||
* Uri
|
||||
* Uri
|
||||
* Utils (e.g. barcodes, comporession, unit converter, jobqueue, git, etc.)
|
||||
* Value validation
|
||||
* View management
|
||||
|
|
|
|||
|
|
@ -138,4 +138,20 @@ abstract class Enum
|
|||
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);
|
||||
|
||||
if (
|
||||
(($mode & ContentPutMode::APPEND) === ContentPutMode::APPEND && $exists)
|
||||
|| (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists)
|
||||
|| (($mode & ContentPutMode::REPLACE) === ContentPutMode::REPLACE && $exists)
|
||||
|| (!$exists && ($mode & ContentPutMode::CREATE) === ContentPutMode::CREATE)
|
||||
(ContentPutMode::hasFlag($mode, ContentPutMode::APPEND) && $exists)
|
||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists)
|
||||
|| (ContentPutMode::hasFlag($mode, ContentPutMode::REPLACE) && $exists)
|
||||
|| (!$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);
|
||||
} elseif (($mode & ContentPutMode::PREPEND) === ContentPutMode::PREPEND && $exists) {
|
||||
} elseif (ContentPutMode::hasFlag($mode, ContentPutMode::PREPEND) && $exists) {
|
||||
file_put_contents($path, $content . file_get_contents($path));
|
||||
} else {
|
||||
if (!Directory::exists(dirname($path))) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user