|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- if (!defined('DEDEINC')) exit('dedebiz');
- class Condition
- {
- /**
- * Simple equals
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function equal($value, $comparable)
- {
- return $value == $comparable;
- }
- /**
- * Strict equals
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function strictEqual($value, $comparable)
- {
- return $value === $comparable;
- }
- /**
- * Simple not equal
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function notEqual($value, $comparable)
- {
- return $value != $comparable;
- }
- /**
- * Strict not equal
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function strictNotEqual($value, $comparable)
- {
- return $value !== $comparable;
- }
- /**
- * Strict greater than
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function greaterThan($value, $comparable)
- {
- return $value > $comparable;
- }
- /**
- * Strict less than
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function lessThan($value, $comparable)
- {
- return $value < $comparable;
- }
- /**
- * Greater or equal
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function greaterThanOrEqual($value, $comparable)
- {
- return $value >= $comparable;
- }
- /**
- * Less or equal
- *
- * @param mixed $value
- * @param mixed $comparable
- *
- * @return bool
- */
- public static function lessThanOrEqual($value, $comparable)
- {
- return $value <= $comparable;
- }
- /**
- * In array
- *
- * @param mixed $value
- * @param array $comparable
- *
- * @return bool
- */
- public static function in($value, $comparable)
- {
- return (is_array($comparable) && in_array($value, $comparable));
- }
- /**
- * Not in array
- *
- * @param mixed $value
- * @param array $comparable
- *
- * @return bool
- */
- public static function notIn($value, $comparable)
- {
- return (is_array($comparable) && !in_array($value, $comparable));
- }
- /**
- * Is null equal
- *
- * @param mixed $value
- *
- * @return bool
- */
- public static function isNull($value, $comparable)
- {
- return is_null($value);
- }
- /**
- * Is not null equal
- *
- * @param mixed $value
- *
- * @return bool
- */
- public static function isNotNull($value, $comparable)
- {
- return !is_null($value);
- }
- /**
- * Start With
- *
- * @param mixed $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function startWith($value, $comparable)
- {
- if (is_array($comparable) || is_array($value) || is_object($comparable) || is_object($value)) {
- return false;
- }
- if (preg_match("/^$comparable/", $value)) {
- return true;
- }
- return false;
- }
- /**
- * End with
- *
- * @param mixed $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function endWith($value, $comparable)
- {
- if (is_array($comparable) || is_array($value) || is_object($comparable) || is_object($value)) {
- return false;
- }
- if (preg_match("/$comparable$/", $value)) {
- return true;
- }
- return false;
- }
- /**
- * Match with pattern
- *
- * @param mixed $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function match($value, $comparable)
- {
- if (is_array($comparable) || is_array($value) || is_object($comparable) || is_object($value)) {
- return false;
- }
- $comparable = trim($comparable);
- if (preg_match("/^$comparable$/", $value)) {
- return true;
- }
- return false;
- }
- /**
- * Contains substring in string
- *
- * @param string $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function contains($value, $comparable)
- {
- return (strpos($value, $comparable) !== false);
- }
- /**
- * Dates equal
- *
- * @param string $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function dateEqual($value, $comparable, $format = 'Y-m-d')
- {
- $date = date($format, strtotime($value));
- return $date == $comparable;
- }
- /**
- * Months equal
- *
- * @param string $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function monthEqual($value, $comparable)
- {
- $month = date('m', strtotime($value));
- return $month == $comparable;
- }
- /**
- * Years equal
- *
- * @param string $value
- * @param string $comparable
- *
- * @return bool
- */
- public static function yearEqual($value, $comparable)
- {
- $year = date('Y', strtotime($value));
- return $year == $comparable;
- }
- }
- ?>
|