diff --git a/hphp/system/php.txt b/hphp/system/php.txt index 76f675e7b..30e61fe6c 100644 --- a/hphp/system/php.txt +++ b/hphp/system/php.txt @@ -23,6 +23,13 @@ hphp/system/php/spl/iterators/DirectoryIterator.php hphp/system/php/spl/iterators/FilesystemIterator.php hphp/system/php/spl/iterators/RecursiveDirectoryIterator.php hphp/system/php/spl/file_handling/SplFileObject.php +hphp/system/php/spl/file_handling/SplTempFileObject.php + +hphp/system/php/lang/ArrayAccess.php +hphp/system/php/lang/Serializeable.php +hphp/system/php/spl/datastructures/SplDoublyLinkedList.php +hphp/system/php/spl/datastructures/SplQueue.php +hphp/system/php/spl/datastructures/SplStack.php hphp/system/php/spl/interfaces/OuterIterator.php hphp/system/php/spl/iterators/IteratorIterator.php @@ -45,13 +52,12 @@ hphp/system/php/collections/collections.php hphp/system/php/dom/DOMException.php hphp/system/php/file_system/Directory.php hphp/system/php/json/JsonSerializable.php -hphp/system/php/lang/ArrayAccess.php hphp/system/php/lang/ErrorException.php -hphp/system/php/lang/Serializeable.php hphp/system/php/pdo/PDOException.php hphp/system/php/reflection/reflection.php hphp/system/php/sessions/session_register_shutdown.php hphp/system/php/soap/SoapFault.php +hphp/system/php/spl/datastructures/SplFixedArray.php hphp/system/php/spl/datastructures/SplObjectStorage.php hphp/system/php/spl/datastructures/SplPriorityQueue.php hphp/system/php/spl/iterators/AppendIterator.php diff --git a/hphp/system/php/spl/datastructures/SplDoublyLinkedList.php b/hphp/system/php/spl/datastructures/SplDoublyLinkedList.php new file mode 100644 index 000000000..23858d0ce --- /dev/null +++ b/hphp/system/php/spl/datastructures/SplDoublyLinkedList.php @@ -0,0 +1,477 @@ +head === null) { + throw new RuntimeException("Can't shift from an empty datastructure"); + } + return $this->head->data; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.top.php ) + * + * + * @return mixed The value of the last node. + */ + public function top() { + if ($this->tail === null) { + throw new RuntimeException("Can't pop from an empty datastructure"); + } + return $this->tail->data; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.isempty.php + * ) + * + * + * @return mixed Returns whether the doubly linked list is empty. + */ + public function isEmpty() { + return !$this->count; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.push.php ) + * + * Pushes value at the end of the doubly linked list. + * + * @value mixed The value to push. + * + * @return mixed No value is returned. + */ + public function push($value) { + $node = new _SplDoublyLinkedListNode; + $node->data = $value; + + if ($this->isEmpty()) { + $this->head = $node; + } else { + $node->prev = $this->tail; + $this->tail->next = $node; + } + $this->tail = $node; + + ++$this->count; + return; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.pop.php ) + * + * + * @return mixed The value of the popped node. + */ + public function pop() { + $retval = $this->top(); + $this->tail = $this->tail->prev; + --$this->count; + return $retval; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.unshift.php + * ) + * + * Prepends value at the beginning of the doubly linked list. + * + * @value mixed The value to unshift. + * + * @return mixed No value is returned. + */ + public function unshift($value) { + $node = new _SplDoublyLinkedListNode; + $node->data = $value; + + if ($this->isEmpty()) { + $this->head = $this->tail = $node; + } else { + $node->next = $this->head; + $this->head->prev = $node; + $this->head = $node; + } + + ++$this->count; + return; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.shift.php ) + * + * + * @return mixed The value of the shifted node. + */ + public function shift() { + $retval = $this->bottom(); + $this->head = $this->head->next; + --$this->count; + return $retval; + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.current.php + * ) + * + * Get the current doubly linked list node. + * + * @return mixed The current node value. + */ + public function current() { + if (!$this->valid()) { + return null; + } + return $this->current->data; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.key.php ) + * + * This function returns the current node index + * + * @return mixed The current node index. + */ + public function key() { + return $this->key; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.next.php ) + * + * Move the iterator to the next node. + * + * @return mixed No value is returned. + */ + public function next() { + if ($this->mode & self::IT_MODE_DELETE) { + --$this->count; + if ($this->current->prev !== null) { + $this->current->prev->next = $this->current->next; + } + if ($this->current->next !== null) { + $this->current->next->prev = $this->current->prev; + } + } + + if ($this->mode & self::IT_MODE_LIFO) { + --$this->key; + $this->current = $this->current ? $this->current->prev : null; + } else { + if (!$this->mode & self::IT_MODE_DELETE) { + ++$this->key; + } + $this->current = $this->current ? $this->current->next : null; + } + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.prev.php ) + * + * Move the iterator to the previous node. + * + * @return mixed No value is returned. + */ + public function prev() { + if ($this->mode & self::IT_MODE_DELETE) { + --$this->count; + if ($this->current->prev !== null) { + $this->current->prev->next = $this->current->next; + } + if ($this->current->next !== null) { + $this->current->next->prev = $this->current->prev; + } + } + + if ($this->mode & self::IT_MODE_LIFO) { + if (!$this->mode & self::IT_MODE_DELETE) { + ++$this->key; + } + $this->current = $this->current ? $this->current->next : null; + } else { + --$this->key; + $this->current = $this->current ? $this->current->prev : null; + } + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.rewind.php ) + * + * This rewinds the iterator to the beginning. + * + * @return mixed No value is returned. + */ + public function rewind() { + if ($this->mode & self::IT_MODE_LIFO) { + $this->key = $this->count - 1; + $this->current = $this->tail; + } else { + $this->key = 0; + $this->current = $this->head; + } + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.valid.php ) + * + * Checks if the doubly linked list contains any more nodes. + * + * @return mixed Returns TRUE if the doubly linked list contains any + * more nodes, FALSE otherwise. + */ + public function valid() { + return $this->current !== null; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.getiteratormode.php ) + * + * + * @return mixed Returns the different modes and flags that affect + * the iteration. + */ + public function getIteratorMode() { + return $this->mode; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.setiteratormode.php ) + * + * + * @mode mixed There are two orthogonal sets of modes that can be + * set: The direction of the iteration (either one or + * the other): SplDoublyLinkedList::IT_MODE_LIFO (Stack + * style) SplDoublyLinkedList::IT_MODE_FIFO (Queue + * style) The behavior of the iterator (either one or + * the other): SplDoublyLinkedList::IT_MODE_DELETE + * (Elements are deleted by the iterator) + * SplDoublyLinkedList::IT_MODE_KEEP (Elements are + * traversed by the iterator) + * + * The default mode is: + * SplDoublyLinkedList::IT_MODE_FIFO | + * SplDoublyLinkedList::IT_MODE_KEEP + * + * @return mixed No value is returned. + */ + public function setIteratorMode($mode) { + $this->mode = $mode; + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.offsetexists.php ) + * + * + * @index mixed The index being checked. + * + * @return mixed TRUE if the requested index exists, otherwise FALSE + */ + public function offsetExists($index) { + return $index < $this->count; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.offsetget.php ) + * + * + * @index mixed The index with the value. + * + * @return mixed The value at the specified index. + */ + public function offsetGet($index) { + if (!is_int($index) && !is_numeric($index)) { + throw new OutOfRangeException("Offset invalid or out of range"); + } + $node = $this->head; + for ($i = 0; $i < $index && $node !== null; ++$i) { + $node = $node->next; + } + if (!$node) { + throw new OutOfRangeException("Offset invalid or out of range"); + } + return $node->data; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.offsetset.php ) + * + * Sets the value at the specified index to newval. + * + * @index mixed The index being set. + * @newval mixed The new value for the index. + * + * @return mixed No value is returned. + */ + public function offsetSet($index, $newval) { + if ($index === null) { + $index = $this->count; + } + if ($this->isEmpty()) { + $node = new _SplDoublyLinkedListNode; + $this->head = $node; + $this->tail = $node; + ++$this->count; + } + $node = $this->head; + for ($i = 0; $i < $index; ++$i) { + if ($node->next === null) { + ++$this->count; + $node->next = new _SplDoublyLinkedListNode; + $node->next->prev = $node; + } + $node = $node->next; + } + $node->data = $newval; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.offsetunset.php ) + * + * Unsets the value at the specified index. + * + * @index mixed The index being unset. + * + * @return mixed No value is returned. + */ + public function offsetUnset($index) { + if (!is_int($index) && !is_numeric($index)) { + throw new OutOfRangeException("Offset invalid or out of range"); + } + $node = $this->head; + for ($i = 0; $i < $index; ++$i) { + if (!$node) { + throw new OutOfRangeException("Offset out of range"); + } + $node = $node->next; + } + + if (!$node) { + throw new OutOfRangeException("Offset out of range"); + } + + --$this->count; + if ($node->prev) { + $node->prev->next = $node->next; + } else { + $this->head = $node->next; + } + + if ($node->next) { + $node->next->prev = $node->prev; + } else { + $this->tail = $node->prev; + } + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/spldoublylinkedlist.count.php ) + * + * + * @return mixed Returns the number of elements in the doubly linked + * list. + */ + public function count() { + return $this->count; + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.serialize.php ) + * + * Serializes the storage. WarningThis function is currently not + * documented; only its argument list is available. + * + * @return mixed The serialized string. + */ + public function serialize() { + $data = array(); + foreach ($this as $val) { + $data[] = $val; + } + return serialize(array($data, $this->mode)); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from + * http://php.net/manual/en/spldoublylinkedlist.unserialize.php ) + * + * Unserializes the storage, from SplDoublyLinkedList::serialize(). + * WarningThis function is currently not documented; only its argument list + * is available. + * + * @serialized mixed The serialized string. + * + * @return mixed No value is returned. + */ + public function unserialize($serialized) { + list($data, $this->mode) = unserialize($serialized); + foreach ($data as $elem) { + $this->push($elem); + } + } +} diff --git a/hphp/system/php/spl/datastructures/SplFixedArray.php b/hphp/system/php/spl/datastructures/SplFixedArray.php new file mode 100644 index 000000000..d37121c88 --- /dev/null +++ b/hphp/system/php/spl/datastructures/SplFixedArray.php @@ -0,0 +1,260 @@ +setSize($size); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.current.php ) + * + * Get the current array element. + * + * @return mixed The current element value. + */ + public function current() { + return current($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.key.php ) + * + * Returns the current array index. + * + * @return mixed The current array index. + */ + public function key() { + return key($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.next.php ) + * + * Move the iterator to the next array entry. + * + * @return mixed No value is returned. + */ + public function next() { + next($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.rewind.php ) + * + * Rewinds the iterator to the beginning. + * + * @return mixed No value is returned. + */ + public function rewind() { + reset($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.valid.php ) + * + * Checks if the array contains any more elements. + * + * @return mixed Returns TRUE if the array contains any more + * elements, FALSE otherwise. + */ + public function valid() { + return key($this->data) !== NULL; + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.offsetexists.php ) + * + * Checks whether the requested index index exists. + * + * @index mixed The index being checked. + * + * @return mixed TRUE if the requested index exists, otherwise FALSE + */ + public function offsetExists($index) { + if (!is_int($index) && !is_numeric($index)) { + throw new RuntimeException("Index invalid or out of range"); + } + return $index < count($this->data); + } + + private function validateIndex($index) { + if ($index >= count($this->data) || $index < 0 || + (!is_int($index) && !is_numeric($index))) { + throw new RuntimeException("Index invalid or out of range"); + } + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.offsetget.php ) + * + * Returns the value at the index index. + * + * @index mixed The index with the value. + * + * @return mixed The value at the specified index. + */ + public function offsetGet($index) { + $this->validateIndex($index); + return $this->data[$index]; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.offsetset.php ) + * + * Sets the value at the specified index to newval. + * + * @index mixed The index being set. + * @newval mixed The new value for the index. + * + * @return mixed No value is returned. + */ + public function offsetSet($index, $newval) { + $this->validateIndex($index); + $this->data[$index] = $newval; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.offsetunset.php ) + * + * Unsets the value at the specified index. + * + * @index mixed The index being unset. + * + * @return mixed No value is returned. + */ + public function offsetUnset($index) { + $this->offsetSet($index, null); + } + + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.count.php ) + * + * Returns the size of the array. + * + * @return mixed Returns the size of the array. + */ + public function count() { + return count($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.setsize.php ) + * + * Change the size of an array to the new size of size. If size is less + * than the current array size, any values after the new size will be + * discarded. If size is greater than the current array size, the array + * will be padded with NULL values. + * + * @size mixed The new array size. This should be a value between 0 + * and PHP_INT_MAX. + * + * @return mixed No value is returned. + */ + public function setSize($size) { + if (!is_int($size)) { + return; + } + if ($size < 0) { + throw new Exception('array size cannot be less than zero'); + } + if ($size < count($this->data)) { + $this->data = array_slice($this->data, 0, $size); + } else if ($size > count($this->data)) { + $this->data = array_pad($thid->data, $size, null); + } + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.getsize.php ) + * + * Gets the size of the array. + * + * @return mixed Returns the size of the array, as an integer. + */ + public function getSize() { + return count($this->data); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.toarray.php ) + * + * Returns a PHP array from the fixed array. + * + * @return mixed Returns a PHP array, similar to the fixed array. + */ + public function toArray() { + return $this->data; + } + + // This doc comment block generated by idl/sysdoc.php + /** + * ( excerpt from http://php.net/manual/en/splfixedarray.fromarray.php ) + * + * Import the PHP array array in a new SplFixedArray instance + * + * @array mixed The array to import. + * @save_indexes + * mixed Try to save the numeric indexes used in the original + * array. + * + * @return mixed Returns an instance of SplFixedArray containing the + * array content. + */ + public static function fromArray($array, $save_indexes = true) { + $fixed_array = new self; + if ($save_indexes) { + foreach ($array as $key => $value) { + if (!is_int($key) || $key < 0) { + throw new Exception('array must contain only positive integer keys'); + } + if ($key >= $fixed_array->count()) { + $fixed_array->setSize($key + 1); + } + $fixed_array[$key] = $value; + } + } else { + $fixed_array->data = array_values($array); + } + return $fixed_array; + } +} diff --git a/hphp/system/php/spl/datastructures/SplQueue.php b/hphp/system/php/spl/datastructures/SplQueue.php new file mode 100644 index 000000000..342df814e --- /dev/null +++ b/hphp/system/php/spl/datastructures/SplQueue.php @@ -0,0 +1,72 @@ +shift(); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * (excerpt from http://php.net/manual/en/splqueue.enqueue.php) + * + * Enqueues value at the end of the queue. + * + * SplQueue::enqueue() is an alias of SplDoublyLinkedList::push(). + * + * @value mixed The value to enqueue. + * + * @return mixed No value is returned. + */ + public function enqueue($value) { + $this->push($value); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * (excerpt from http://php.net/manual/en/splqueue.setiteratormode.php) + * + * + * @mode mixed There is only one iteration parameter you can + * modify. The behavior of the iterator (either one or + * the other): SplDoublyLinkedList::IT_MODE_DELETE + * (Elements are deleted by the iterator) + * SplDoublyLinkedList::IT_MODE_KEEP (Elements are + * traversed by the iterator) + * + * The default mode is: + * SplDoublyLinkedList::IT_MODE_FIFO | + * SplDoublyLinkedList::IT_MODE_KEEP Warning + * + * The direction of iteration can not be changed for + * SplQueues, it is always + * SplDoublyLinkedList::IT_MODE_FIFO. + * + * @return mixed No value is returned. + */ + public function setIteratorMode($mode) { + if ($mode & self::IT_MODE_LIFO) { + throw new RuntimeException('SplQueue can only be used in FIFO mode.'); + } + parent::setIteratorMode($mode); + } +} diff --git a/hphp/system/php/spl/datastructures/SplStack.php b/hphp/system/php/spl/datastructures/SplStack.php new file mode 100644 index 000000000..58f4c490d --- /dev/null +++ b/hphp/system/php/spl/datastructures/SplStack.php @@ -0,0 +1,57 @@ +setIteratorMode(self::IT_MODE_LIFO | self::IT_MODE_KEEP); + } + + // This doc comment block generated by idl/sysdoc.php + /** + * (excerpt from http://php.net/manual/en/splstack.setiteratormode.php) + * + * + * @mode mixed There is only one iteration parameter you can + * modify. The behavior of the iterator (either one or + * the other): SplDoublyLinkedList::IT_MODE_DELETE + * (Elements are deleted by the iterator) + * SplDoublyLinkedList::IT_MODE_KEEP (Elements are + * traversed by the iterator) + * + * The default mode is 0x2 : + * SplDoublyLinkedList::IT_MODE_LIFO | + * SplDoublyLinkedList::IT_MODE_KEEP Warning + * + * The direction of iteration can no longer be changed + * for SplStacks. Trying to do so will result in a + * RuntimeException being thrown. + * + * @return mixed No value is returned. + */ + public function setIteratorMode($mode) { + if ($mode & self::IT_MODE_FIFO) { + throw new RuntimeException('SplStack can only be used in LIFO mode.'); + } + parent::setIteratorMode($mode); + } +} diff --git a/hphp/system/php/spl/file_handling/SplTempFileObject.php b/hphp/system/php/spl/file_handling/SplTempFileObject.php new file mode 100644 index 000000000..bf045e221 --- /dev/null +++ b/hphp/system/php/spl/file_handling/SplTempFileObject.php @@ -0,0 +1,37 @@ +