diff --git a/class-Queried.php b/class-Queried.php index 0a83511..58469c7 100644 --- a/class-Queried.php +++ b/class-Queried.php @@ -1,185 +1,185 @@ . /** * This class handles a database table result * * Very often this database table has an ID and an UID. */ class Queried { /** * Maximum UID length */ const MAXLEN_UID = 256; /** * Empty constructor */ public function __construct() {} /** * Obtain a property that can be null (but can't be undefined). * * @param string $property * @return mixed */ public function get( $property ) { if( property_exists( $this, $property ) ) { return $this->$property; } throw new SucklessException( sprintf( 'cannot obtain %s->%s', get_class( $this ), $property ) ); } /** * Check if a property is not NULL * * @param string $property * @return bool */ public function has( $property ) { return null !== $this->get( $property ); } /** * Obtain a property that can't be null (and can't be undefined). * * @param string $property * @return mixed */ public function nonnull($property) { if( isset( $this->$property ) ) { return $this->$property; } throw new SucklessException( sprintf( 'cannot obtain %s->%s', get_class( $this ), $property ) ); } function integers() { foreach( func_get_args() as $p) { isset( $this->$p ) and $this->$p = (int) $this->$p; } return $this; } function booleans() { foreach( func_get_args() as $p) { isset( $this->$p ) and $this->$p = (bool) (int) $this->$p; } return $this; } function dates() { foreach( func_get_args() as $p) { isset( $this->$p ) and $this->$p = DateTime::createFromFormat('Y-m-d', $this->$p); } } function datetimes() { foreach( func_get_args() as $p) { isset( $this->$p ) and $this->$p = DateTime::createFromFormat('Y-m-d H:i:s', $this->$p); } return $this; } function floats() { foreach( func_get_args() as $p) { isset( $this->$p ) and $this->$p = (float) $this->$p; } } /** * Query factory * * The class constant 'T' is expected as table name * * @return Query */ public static function factory() { return Query::factory( static::class ) ->from( static::T ); } /** * Factory from an ID column * * The class constant 'ID' is expected * * @param $ID int * @return Queried */ public static function factoryFromID( $ID ) { $field = defined( static::class . '::ID' ) ? static::ID : static::T . '_ID'; $field = static::T . DOT . $field; - return self::factory() + return static::factory() ->whereInt( $field, $ID ); } /** * Factory from an UID column * * The class constant 'UID' is expected * * @param $uid string * @return Queried */ public static function factoryFromUID( $uid ) { $field = defined( static::class . '::UID' ) ? static::UID : static::T . '_uid'; $uid = static::sanitizeUID( $uid ); - return self::factory() + return static::factory() ->whereStr( $field, $uid ); } /** * Sanitize the UID * * @return string * @use luser_input() */ public static function sanitizeUID( $uid ) { return luser_input( $uid, static::MAXLEN_UID ); } /** * Alias of self::factoryFromID() * * @deprecated */ public static function factoryByID( $ID ) { return self::factoryFromID( $ID ); } /** * Alias of self::factoryFromUID() * * @deprecated */ public static function factoryByUID( $uid ) { return self::factoryFromUID( $uid ); } }