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

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

/**
 * SetPasswordRequest
 * 
 * A requestor must send a <setPasswordRequest> to
 * a provider in order to (ask the provider to) change
 * to a specified value the password that is
 * associated an existing object
 * 
 * @package SimpleSPML
 * @author Alessandra Bozzo <hide@address.com>
 */
class SetPasswordRequest 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;
    
    /**
	 * Contain the current password value
	 * that is associated with the specified object
	 * 
	 * @access protected
	 * @var XsdString
	 */
    protected $currentPassword = null;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->setBaseElements("psoID");
        $this->setBaseElements("password");
        $this->setBaseElements("currentPassword");
        
        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;
    }
    
    /**
     * Return currentPassword value
     * @access public
     * @return XsdString
     */
    public function __getCurrentPassword()
    {
        return $this->currentPassword;
    }
    
    /**
     * Sets the value of psoID
     * @access public
     * @param Core::PSOIdentifier $psoID 
     */
    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");
        }        
    }
    
    /**
     * Sets the value of currentPassword
     * @access public
     * @param string $currentPassword 
     */
    public function __setCurrentPassword($currentPassword)
    {
        if($currentPassword)
        {
            try
            {
                $this->currentPassword = new XsdString($currentPassword);
            }
            
            catch(Exception $e)
            {
                throw new WrongTypeException(get_class($this) . "::currentPassword");
            }
        }
    }
    
    /**
     * 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);
        
        // currentPassword
        if($children->currentPassword)
        {
            $this->setElement("currentPassword", (string) $children->currentPassword);
            unset($children->currentPassword);
        }
        
        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 . '<setPasswordRequest xmlns="urn:oasis:names:tc:SPML:2:0"';
        
        // write setPasswordRequest attributes
        $spmlstr .= $this->writeAttributes();
                
        // write parent elements
        $spmlmidstr = parent::writeMessage($level + 1);
        
        // write setPasswordRequest elements
        $spmlmidstr .= $this->psoID->writeElement("psoID", $level + 1);
        
        $spmlmidstr .= $midind . '<password>' . $this->password->ToString() . '</password>
';
        
        if($this->currentPassword)
            $spmlmidstr .= $midind . '<currentPassword>' . $this->currentPassword->ToString() . '</currentPassword>
';
        
        return $this->tagCloser("setPasswordRequest", $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