/** * Constructor * * @throws \BLW\Model\InvalidArgumentException If <code>$Referer</code> is invalid. * * @param \BLW\Type\IURI $Referer * Value of Referer header */ public function __construct(IURI $Referer) { // Validate $Referer if (!$Referer->isValid()) { throw new InvalidArgumentException(0); } // 1. Header type $this->_Type = 'Referer'; // 2. Header value $this->_Value = @strval($Referer); }
/** * Constructor * * @throws \BLW\Model\InvalidArgumentException If <code>$Location</code> is invalid. * * @param \BLW\Type\IURI $Location * Value of Location header */ public function __construct(IURI $Location) { // 1. Header type $this->_Type = 'Location'; // 2. Header value // Validate $Location if ($Location->isValid() && $Location->isAbsolute()) { // Base $this->_Value = @strval($Location); // Invalid $Location } else { throw new InvalidArgumentException(0); } }
/** * Constructor * * @throws \BLW\Model\InvalidArgumentException If <code>$Base</code> is invalid. * * @param \BLW\Type\IURI $Base * Value of Content-Base header */ public function __construct(IURI $Base) { // 1. Header type $this->_Type = 'Content-Base'; // 2. Header value // Validate $Base if ($Base->isValid() && $Base->isAbsolute()) { // Base $this->_Value = @strval($Base); // Invalid $Base } else { throw new InvalidArgumentException(0); } }
/** * Sets the last / current URI of this response. * * @param \BLW\Type\IURI $URI * New request URI * @return integer Returns a <code>DataMapper</code> status code. */ public function setURI($URI) { // Validate $RequestURI if ($URI instanceof IURI) { if ($URI->isValid() && $URI->isAbsolute()) { // Update $_URI $this->_URI = $URI; // Done return IDataMapper::UPDATED; } } // Invalid return IDataMapper::INVALID; }
/** * Creates HTTP POST Requests. * * @param \BLW\Type\IURI $URI * Address of request. * @param \BLW\Type\IURI $BaseURI * Base URL of request used to resolve relative addresses. * @param array|\Traversable $Data * Post data to send with keys as field names and values as field values. * * <h4>Note</h4> * * <p>Field keys should be string values. (ie `foo` and not `0`)</p> * * <hr> * * @param array|\Traversable $Headers * Headers to add to request. * @return \BLW\Type\HTTP\IRequest Built request. */ public function createPOST(IURI $URI, IURI $BaseURI, $Data = null, $Headers = array()) { // Validate $Parameters if (!$URI->isValid()) { throw new InvalidArgumentException(0); // Invalid $Header } elseif (!is_array($Headers) && !$Headers instanceof \Traversable) { throw new InvalidArgumentException(3); } // Create request $Request = $this->_RequestClass; $Request = new $Request(IRequest::POST); // URI $Request->URI = new GenericURI(strval($URI), $BaseURI); $Request->Referer = $BaseURI; // Headers $this->_addHeaders($Request, $Headers); // Build Fields $Fields = array(); $isMultiPart = false; foreach ($Data as $Field => $Value) { if (is_string($Field)) { // File field if ($Value instanceof IFile) { // Add field $Fields[] = new FormFile($Field, $Value); // Switch body to multipart $isMultiPart = true; // Direct field } elseif ($Value instanceof FormField) { $Fields[] = $Value; } elseif ($Value instanceof FormFile) { $Fields[] = $Value; // Regular field? } elseif (is_scalar($Value) ?: is_callable(array($Value, '__toString'))) { $Value = is_callable('mb_convert_encoding') ? mb_convert_encoding($Value, 'UTF-8', mb_detect_order()) : strval($Value); // Add field $Fields[] = new FormField($Field, 'text/plain', $Value, 'UTF-8'); } } } // Multipart body if ($isMultiPart) { $this->_addMultipartFields($Request, $Fields); // Regular body } else { $this->_addUrlEncodedFields($Request, $Fields); } // Done return $Request; }
/** * Set the request referer. * * <h4>Note</h4> * * <p>Fails if:</p> * * <ul> * <li>$URI is invalid</li> * <li>$URI is not absolute</li> * </ul> * * <hr> * * @param \BLW\Type\IURI $Referer * Request referer URL. * @return integer Returns a <code>DataMapper</code> status code. */ public function setReferer($Referer) { // Validate $URI if ($Referer instanceof IURI) { if ($Referer->isValid() && $Referer->isAbsolute()) { // Update $_Referer $this->_Referer = $Referer; // Done return IDataMapper::UPDATED; } } // Invalid return IDataMapper::INVALID; }