pquery.array.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 pQuerySql}.
  38. *
  39. * @returns pQuerySql A new pQuerySql instance.
  40. * @see pQuerySql::__construct
  41. */
  42. function _arr($array) {
  43. return pQuery::create('array', $array);
  44. }
  45. pQuery::extend('pQueryArray', 'array');
  46. ?>