pquery.array.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * pQuery plugin for executing common array functions.
  4. *
  5. * @package pQuery
  6. */
  7. /**
  8. * @todo Documentation
  9. */
  10. class pQueryArray extends pQuery implements pQueryExtension {
  11. function get($index) {
  12. return isset($this->variable[$index]) ? $this->variable[$index] : null;
  13. }
  14. function is_empty() {
  15. return !$this->count();
  16. }
  17. function reverse() {
  18. $this->variable = array_reverse($this->variable);
  19. return $this;
  20. }
  21. function __call($method, $args) {
  22. $function = 'array_'.$method;
  23. if( function_exists($function) ) {
  24. array_unshift($args, &$this->variable);
  25. return call_user_func_array($function, $args);
  26. }
  27. if( in_array($method, array('count')) )
  28. return $method($this->variable);
  29. if( in_array($method, array('shuffle')) ) {
  30. $method($this->variable);
  31. return $this;
  32. }
  33. return self::error('Plugin "%s" has no method "%s".', __CLASS__, $method);
  34. }
  35. }
  36. /**
  37. * Shortcut constructor for {@link pQueryArray}.
  38. *
  39. * @returns pQueryArray A new pQueryArray instance.
  40. */
  41. function _arr($array) {
  42. return pQuery::create('array', $array);
  43. }
  44. pQuery::extend('pQueryArray', 'array');
  45. ?>