mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 10:34:34 +00:00
cleanup some methods in databox_status as only 32bit ints used.
This commit is contained in:
@@ -151,10 +151,6 @@ class databox_status
|
|||||||
|
|
||||||
public static function operation_and(Application $app, $stat1, $stat2)
|
public static function operation_and(Application $app, $stat1, $stat2)
|
||||||
{
|
{
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
|
||||||
|
|
||||||
$status = '0';
|
|
||||||
|
|
||||||
if (substr($stat1, 0, 2) === '0x') {
|
if (substr($stat1, 0, 2) === '0x') {
|
||||||
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
||||||
}
|
}
|
||||||
@@ -162,18 +158,7 @@ class databox_status
|
|||||||
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'select bin(0b' . trim($stat1) . ' & 0b' . trim($stat2) . ') as result';
|
return dechex(hexdec($stat1) & hexdec($stat2));
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,42 +169,20 @@ class databox_status
|
|||||||
* @param $stat1 a binary mask "010x1xx0.." STRING
|
* @param $stat1 a binary mask "010x1xx0.." STRING
|
||||||
* @param $stat2 a binary mask "x100x1..." STRING
|
* @param $stat2 a binary mask "x100x1..." STRING
|
||||||
*
|
*
|
||||||
* @return binary string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function operation_mask(Application $app, $stat1, $stat2)
|
public static function operation_mask(Application $app, $stat1, $stat2)
|
||||||
{
|
{
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
$stat1_or = bindec(trim(str_replace("x", "0", $stat1)));
|
||||||
|
$stat1_and = bindec(trim(str_replace("x", "1", $stat1)));
|
||||||
|
$stat2_or = bindec(trim(str_replace("x", "0", $stat2)));
|
||||||
|
$stat2_and = bindec(trim(str_replace("x", "1", $stat2)));
|
||||||
|
|
||||||
$status = '0';
|
return decbin((((0 | $stat1_or) & $stat1_and) | $stat2_or) & $stat2_and);
|
||||||
$stat1_or = '0b' . trim(str_replace("x", "0", $stat1));
|
|
||||||
$stat1_and = '0b' . trim(str_replace("x", "1", $stat1));
|
|
||||||
$stat2_or = '0b' . trim(str_replace("x", "0", $stat2));
|
|
||||||
$stat2_and = '0b' . trim(str_replace("x", "1", $stat2));
|
|
||||||
|
|
||||||
// $sql = "SELECT BIN(((((0 | :o1) & :a1)) | :o2) & :a2) AS result";
|
|
||||||
// $stmt = $conn->prepare($sql);
|
|
||||||
// $stmt->execute(array(':o1'=>$stat1_or, ':a1'=>$stat1_and, ':o2'=>$stat2_or, ':a2'=>$stat2_and));
|
|
||||||
|
|
||||||
$sql = "SELECT BIN(((((0 | $stat1_or) & $stat1_and)) | $stat2_or) & $stat2_and) AS result";
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
|
|
||||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function operation_and_not(Application $app, $stat1, $stat2)
|
public static function operation_and_not(Application $app, $stat1, $stat2)
|
||||||
{
|
{
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
|
||||||
|
|
||||||
$status = '0';
|
|
||||||
|
|
||||||
if (substr($stat1, 0, 2) === '0x') {
|
if (substr($stat1, 0, 2) === '0x') {
|
||||||
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
||||||
}
|
}
|
||||||
@@ -227,26 +190,11 @@ class databox_status
|
|||||||
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'select bin(0b' . trim($stat1) . ' & ~0b' . trim($stat2) . ') as result';
|
return decbin(bindec($stat1) & ~bindec($stat2));
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function operation_or(Application $app, $stat1, $stat2)
|
public static function operation_or(Application $app, $stat1, $stat2)
|
||||||
{
|
{
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
|
||||||
|
|
||||||
$status = '0';
|
|
||||||
|
|
||||||
if (substr($stat1, 0, 2) === '0x') {
|
if (substr($stat1, 0, 2) === '0x') {
|
||||||
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
$stat1 = self::hex2bin($app, substr($stat1, 2));
|
||||||
}
|
}
|
||||||
@@ -254,18 +202,7 @@ class databox_status
|
|||||||
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
$stat2 = self::hex2bin($app, substr($stat2, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'select bin(0b' . trim($stat1) . ' | 0b' . trim($stat2) . ') as result';
|
return decbin(hexdec($stat1) | hexdec($stat2));
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dec2bin(Application $app, $status)
|
public static function dec2bin(Application $app, $status)
|
||||||
@@ -276,22 +213,7 @@ class databox_status
|
|||||||
throw new \Exception(sprintf('`%s`is non-decimal value', $status));
|
throw new \Exception(sprintf('`%s`is non-decimal value', $status));
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
return decbin($status);
|
||||||
|
|
||||||
$sql = 'select bin(' . $status . ') as result';
|
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$status = '0';
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function hex2bin(Application $app, $status)
|
public static function hex2bin(Application $app, $status)
|
||||||
@@ -305,22 +227,7 @@ class databox_status
|
|||||||
throw new \Exception('Non-hexadecimal value');
|
throw new \Exception('Non-hexadecimal value');
|
||||||
}
|
}
|
||||||
|
|
||||||
$conn = $app['phraseanet.appbox']->get_connection();
|
return hex2bin($status);
|
||||||
|
|
||||||
$sql = 'select BIN( CAST( 0x' . trim($status) . ' AS UNSIGNED ) ) as result';
|
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql);
|
|
||||||
$stmt->execute();
|
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
||||||
$stmt->closeCursor();
|
|
||||||
|
|
||||||
$status = '0';
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$status = $row['result'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function bitIsSet($bitValue, $nthBit)
|
public static function bitIsSet($bitValue, $nthBit)
|
||||||
|
Reference in New Issue
Block a user