/** * Sets the byte range(s) of interest in the requested entity. * * @param array $byteRangeOrRanges The byte range(s) of interest. This is either an array with two integer values * specifying the byte range to be retrieved or, for HTTP requests only, an array of such arrays specifying * multiple byte ranges. The second value in a pair is allowed to be `null`, in which case the range is considered * to be open-ended and the server is expected to respond with data starting from the byte indicated by the first * value in the pair and up to the very last byte available. * * @return void */ public function setRequestedByteRange($byteRangeOrRanges) { assert('is_carray($byteRangeOrRanges) && !CArray::isEmpty($byteRangeOrRanges)', vs(isset($this), get_defined_vars())); if (!is_carray(CArray::first($byteRangeOrRanges))) { assert('CArray::length($byteRangeOrRanges) == 2', vs(isset($this), get_defined_vars())); $rangeBPosLow = $byteRangeOrRanges[0]; $rangeBPosHigh = $byteRangeOrRanges[1]; assert('is_int($rangeBPosLow) && (is_null($rangeBPosHigh) || is_int($rangeBPosHigh))', vs(isset($this), get_defined_vars())); assert('$rangeBPosLow >= 0 && (is_null($rangeBPosHigh) || $rangeBPosHigh >= 0)', vs(isset($this), get_defined_vars())); assert('is_null($rangeBPosHigh) || $rangeBPosHigh >= $rangeBPosLow', vs(isset($this), get_defined_vars())); $this->m_requestedByteRange = !is_null($rangeBPosHigh) ? "{$rangeBPosLow}-{$rangeBPosHigh}" : "{$rangeBPosLow}-"; } else { assert('$this->isHttp()', vs(isset($this), get_defined_vars())); $preOutString = CArray::make(); $len = CArray::length($byteRangeOrRanges); $lenMinusOne = $len - 1; for ($i = 0; $i < $len; $i++) { $range = $byteRangeOrRanges[$i]; assert('is_carray($range)', vs(isset($this), get_defined_vars())); assert('CArray::length($range) == 2', vs(isset($this), get_defined_vars())); $rangeBPosLow = $range[0]; $rangeBPosHigh = $range[1]; if (CDebug::isDebugModeOn()) { // The high byte position can be specified as `null` for the last range only. if ($i != $lenMinusOne) { assert('is_int($rangeBPosLow) && is_int($rangeBPosHigh)', vs(isset($this), get_defined_vars())); assert('$rangeBPosLow >= 0 && $rangeBPosHigh >= 0', vs(isset($this), get_defined_vars())); assert('$rangeBPosHigh >= $rangeBPosLow', vs(isset($this), get_defined_vars())); } else { assert('is_int($rangeBPosLow) && (is_null($rangeBPosHigh) || is_int($rangeBPosHigh))', vs(isset($this), get_defined_vars())); assert('$rangeBPosLow >= 0 && (is_null($rangeBPosHigh) || $rangeBPosHigh >= 0)', vs(isset($this), get_defined_vars())); assert('is_null($rangeBPosHigh) || $rangeBPosHigh >= $rangeBPosLow', vs(isset($this), get_defined_vars())); } } $rbr = !is_null($rangeBPosHigh) ? "{$rangeBPosLow}-{$rangeBPosHigh}" : "{$rangeBPosLow}-"; CArray::push($preOutString, $rbr); } $this->m_requestedByteRange = CArray::join($preOutString, ","); } }
public function testFirst() { $array = CArray::fromElements("a", "b", "c"); $this->assertTrue(CArray::first($array) === "a"); }
/** * Returns the first element from an array. * * @return mixed The first element in the array. */ public function first() { return CArray::first($this->m_splArray); }