| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * pQuery plugin for executing common array functions.
- *
- * @package pQuery
- */
- /**
- * @todo Documentation
- */
- class pQueryArray extends pQuery implements pQueryExtension {
- /**
- * Get the value of an array alement at the given index.
- *
- * @param int|string $index The index to get the element of.
- * @returns mixed The array value at the given index if it exists, or NULL otherwise.
- */
- function get($index) {
- return isset($this->variable[$index]) ? $this->variable[$index] : null;
- }
-
- /**
- * Check if the array is empty.
- *
- * @returns bool Whether the array is empty.
- */
- function is_empty() {
- return !$this->count();
- }
-
- /**
- * Reverse the array.
- *
- * @returns pQueryArray The current object.
- */
- function reverse() {
- $this->variable = array_reverse($this->variable);
-
- return $this;
- }
-
- /**
- * Execute an existing array function on the array.
- *
- * @var $method string A (part of the) function name to execute.
- * @var method $args Additional arguments to pass to the called function.
- * @returns mixed Either the current object, or the return value
- * of the called array function.
- */
- function __call($method, $args) {
- $function = 'array_'.$method;
-
- if( function_exists($function) ) {
- array_unshift($args, &$this->variable);
-
- return call_user_func_array($function, $args);
- }
-
- if( in_array($method, array('count')) )
- return $method($this->variable);
-
- if( in_array($method, array('shuffle')) ) {
- $method($this->variable);
- return $this;
- }
-
- return self::error('Plugin "%s" has no method "%s".', __CLASS__, $method);
- }
- }
- /**
- * Shortcut constructor for {@link pQueryArray}.
- *
- * @returns pQueryArray A new pQueryArray instance.
- */
- function _arr($array) {
- return pQuery::create('array', $array);
- }
- pQuery::extend('pQueryArray', 'array');
- ?>
|