Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Application_Model_User
- *
- * Contains the minimum requirements to identify a specific user to the system.
- *
- * @category Prozf
- * @package Application_Model
- *
- */
- class Application_Model_User
- {
- /**
- * @var int The ID of a user
- */
- protected $_id;
- /**
- * @var string The full name of a user
- */
- protected $_fullname;
- /**
- * @var string The email address of a user
- */
- protected $_email;
- /**
- * @var string The password of a user
- */
- protected $_password;
- /**
- * @var array List of filters used on the individual properties
- */
- protected $_filters;
- /**
- * @var array List of validators used on the individual properties
- */
- protected $_validators;
- /**
- * Constructor class for this User
- *
- * @param null|string|array $fullname
- * @param null|string $email
- * @param null|string $password
- */
- public function __construct($fullname = null, $email = null, $password = null)
- {
- $this->_filters = array (
- 'id' => new Zend_Filter_Int(),
- 'fullname' => array (
- new Zend_Filter_StringTrim(),
- new Zend_Filter_Alnum(true),
- new Zend_Filter_StripTags(),
- ),
- 'email' => array (
- new Zend_Filter_StringTrim(),
- new Zend_Filter_StringToLower(),
- new Zend_Filter_StripTags(),
- ),
- );
- $this->_validators = array (
- 'id' => array (
- new Zend_Validate_Int(),
- new Zend_Validate_GreaterThan(-1),
- ),
- 'fullname' => array (
- new Prozf_Validate_Mwop(),
- new Zend_Validate_StringLength(array ('min' => 4, 'max' => 50)),
- ),
- 'email' => array (
- 'EmailAddress',
- new Zend_Validate_StringLength(array ('min' => 4, 'max' => 50)),
- ),
- 'password' => array (
- new Prozf_Validate_PasswordStrength(
- Prozf_Validate_PasswordStrength::PASSWD_MEDIUM),
- new Zend_Validate_StringLength(array ('min' => 4)),
- ),
- );
- if (null !== $fullname && (is_array($fullname) || $fullname instanceof Zend_Db_Table_Row)) {
- $this->populate($fullname);
- }
- if (null !== $fullname && is_string($fullname)) {
- $this->setFullname($fullname);
- }
- if (null !== $fullname && is_string($email)) {
- $this->setEmail($email);
- }
- if (null !== $password && is_string($password)) {
- $this->setPassword($password);
- }
- }
- /**
- * Sets the sequence ID for a User
- *
- * @param int $id
- * @throws UnexpectedValueException
- * @return Application_Model_User
- */
- public function setId($id)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array ('id' => $id));
- if (!$input->isValid('id')) {
- throw new UnexpectedValueException('Wrong value for ID');
- }
- $this->_id = (int) $input->id;
- return $this;
- }
- /**
- * Retrieves the sequence ID from a User
- *
- * @return int
- */
- public function getId()
- {
- return $this->_id;
- }
- /**
- * Sets the full name for a User
- *
- * @param string $fullname
- * @throws UnexpectedValueException
- * @return Application_Model_User
- */
- public function setFullname($fullname)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array ('fullname' => $fullname));
- if (!$input->isValid('fullname')) {
- throw new UnexpectedValueException('Wrong value for full name');
- }
- $this->_fullname = $input->fullname;
- return $this;
- }
- /**
- * Retrieves the full name from a User
- *
- * @return string
- */
- public function getFullname()
- {
- return $this->_fullname;
- }
- /**
- * Sets the email address for a User
- *
- * @param string $email
- * @throws UnexpectedValueException
- * @return Application_Model_User
- */
- public function setEmail($email)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array ('email' => $email));
- if (!$input->isValid('email')) {
- throw new UnexpectedValueException('Wrong value for email');
- }
- $this->_email = $input->email;
- return $this;
- }
- /**
- * Retrieves the email address from a User
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->_email;
- }
- /**
- * Sets the password for a User
- *
- * @param string $password
- * @throws UnexpectedValueException
- * @return Application_Model_User
- */
- public function setPassword($password)
- {
- $input = new Zend_Filter_Input($this->_filters, $this->_validators);
- $input->setData(array ('password' => $password));
- if (!$input->isValid('password')) {
- throw new UnexpectedValueException('Wrong value for password');
- }
- $this->_password = $input->password;
- return $this;
- }
- /**
- * Retrieve the password from a User
- */
- public function getPassword()
- {
- return $this->_password;
- }
- /**
- * Populates this User profile with an array
- *
- * @param array $data
- * @return Application_Model_User
- */
- public function populate($data)
- {
- if (is_array($data)) {
- $data = new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS);
- }
- if (isset ($data->id)) $this->setId($data->id);
- if (isset ($data->fullname)) $this->setFullname($data->fullname);
- if (isset ($data->email)) $this->setEmail($data->email);
- if (isset ($data->password)) $this->setPassword($data->password);
- return $this;
- }
- /**
- * Converts this User data into an array
- *
- * @return array
- */
- public function toArray()
- {
- return array (
- 'id' => $this->getId(),
- 'fullname' => $this->getFullname(),
- 'email' => $this->getEmail(),
- 'password' => $this->getPassword(),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement