query.class.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * The query class file of zin lib.
  4. *
  5. * @copyright Copyright 2024 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com)
  6. * @author Hao Sun <sunhao@easycorp.ltd>
  7. * @package zin
  8. * @version $Id
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once __DIR__ . DS . 'wg.class.php';
  13. require_once __DIR__ . DS . 'selector.func.php';
  14. require_once __DIR__ . DS . 'query.class.php';
  15. /**
  16. * The query class.
  17. */
  18. class query
  19. {
  20. /**
  21. * The selector object list.
  22. * @var mixed[]
  23. */
  24. public $selectors;
  25. /**
  26. * The command list.
  27. * @var mixed[]
  28. */
  29. public $commands = array();
  30. /**
  31. * Construct the query instance.
  32. *
  33. * @param object|string|array - $selectors
  34. * @access public
  35. */
  36. public function __construct($selectors)
  37. {
  38. $this->selectors = parseSelectors($selectors, true);
  39. context::current()->addQuery($this);
  40. }
  41. /**
  42. * Magic method for adding commands.
  43. *
  44. * @access public
  45. * @param string $name - Property name.
  46. * @param array $args - Property values.
  47. * @return query
  48. */
  49. public function __call($name, $args)
  50. {
  51. skipRenderInGlobal($args);
  52. $this->commands[] = array($name, $args);
  53. return $this;
  54. }
  55. /**
  56. * Debug info.
  57. *
  58. * @access public
  59. * @return array
  60. */
  61. public function __debugInfo()
  62. {
  63. return array
  64. (
  65. 'selectors' => $this->selectors,
  66. 'commands' => $this->commands
  67. );
  68. }
  69. public function isRoot()
  70. {
  71. return count($this->selectors) === 1 && $this->selectors[0]->tag === 'root';
  72. }
  73. }
  74. /**
  75. * Create a query object.
  76. *
  77. * @param object|string|array $selectors
  78. * @return query
  79. */
  80. function query($selectors)
  81. {
  82. return new query($selectors);
  83. }