Location: PHPKode > projects > SimpleSPML > SimpleSPML/lib/msg/password/ValidatePasswordRequest.php
<?php
require_once "lib/core/Request.php";
require_once "lib/core/PSOIdentifier.php";

/*
<complexType name = "ValidatePasswordRequestType">
    <complexContent>
        <extension base = "spml:RequestType">
            <sequence>
                <element name = "psoID" type = "spml:PSOIdentifierType" />
                <element name = "password" type = "string" />
            </sequence>
        </extension>
    </complexContent>
</complexType>
*/

/**
 * ValidatePasswordRequest
 * 
 * A requestor must send a <validatePasswordRequest>
 * to a provider in order to (ask the provider to)
 * test whether a specified value would be valid as
 * the password that is associated with an existing object
 * 
 * @package SimpleSPML
 * @author Alessandra Bozzo <hide@address.com>
 */
class ValidatePasswordRequest extends Request
{
    /**
	 * Object identifier
	 * 
	 * @access protected
	 * @var Core::PSOIdentifier
	 */
    protected $psoID  = null;
    
    /**
	 * Contain the newly changed password value
	 * that is associated with the specified object
	 * 
	 * @access protected
	 * @var XsdString
	 */
    protected $password  = null;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->setBaseElements("psoID");
        $this->setBaseElements("password");
        
        parent::__construct();
    }
    
    /**
     * Return psoID value
     * @access public
     * @return Core::PSOIdentifier
     */
    public function __getPsoID()
    {
        return $this->psoID;
    }
    
    /**
     * Return password value
     * @access public
     * @return XsdString
     */
    public function __getPassword()
    {
        return $this->password;
    }
    
    /**
     * Sets the value of remainingLogins
     * @access public
     * @param int $remainingLogins 
     */
    public function __setPsoID($psoID)
    {
        if(!$psoID)
            throw new MissingParameterException(get_class($this) . "::psoID");
            
        if(!($psoID instanceof PSOIdentifier))
            throw new WrongTypeException(get_class($this) . "::psoID");
            
        $this->psoID = $psoID;
    }
    
    /**
     * Sets the value of password
     * @access public
     * @param string $password 
     */
    public function __setPassword($password)
    {
        if(!$password)
            throw new MissingParameterException(get_class($this) . "::password");
        
        try
        {
            $this->password = new XsdString($password);
        }
        
        catch(Exception $e)
        {
            throw new WrongTypeException(get_class($this) . "::password");
        }        
    }
    
    /**
     * Read the SPML message
     * @access public
     * @param SimpleXMLIterator $obj
     */
    public function readMessage($obj)
    {
        $this->checkNamespace($obj, "urn:oasis:names:tc:SPML:2:0");
        
        // Load elements
        $children = $obj->children();
        
        // psoID
        if(!$children->psoID)
			throw new MalformedMessageException(get_class($this) . "::psoID");
   		     	
        $psoID = new PSOIdentifier();
        $psoID->readMessage($children->psoID);
        $this->setElement("psoID", $psoID);
        unset($children->psoID);
        
        // password
        if(!$children->password)
            throw new MalformedMessageException(get_class($this) . "::password");
        
        $this->setElement("password", (string) $children->password);
        unset($children->password);
        
        parent::readMessage($obj);
        
        if(!$this->isValid())
            throw new InvalidMessageException(get_class($this));
    }
    
    /**
     * Write the SPML message
     * @access public
     * @param int $level
     * @return string
     */
    public function writeMessage($level = 0)
    {
        if(!$this->isValid())
            throw new InvalidObjectException(get_class($this));
        
        $ind = $this->indentation($level);
        
        $spmlstr = $ind . '<validatePasswordRequest xmlns="urn:oasis:names:tc:SPML:2:0"';
        
        // write validatePasswordRequest attributes
        $spmlstr .= $this->writeAttributes();
                
        // write parent elements
        $spmlmidstr = parent::writeMessage($level + 1);
        
        // write validatePasswordRequest elements
        $spmlmidstr .= $this->psoID->writeElement("psoID", $level + 1);
        
        $spmlmidstr .= $midind . '<password>' . $this->password->ToString() . '</password>
';
        return $this->tagCloser("validatePasswordRequest", $spmlstr, $spmlmidstr, $ind);
    }
    
    /**
     * Check if the object is valid
     * @access public
     * @return boolean
     */
    public function isValid()
    {
        return(($this->psoID != null) && ($this->password != null) && parent::isValid());
    }
}
?>
Return current item: SimpleSPML