/wp-content/plugins/the-events-calendar/common/src/Tribe/Repository/Decorator.php

https://github.com/livinglab/openlab · PHP · 688 lines · 283 code · 111 blank · 294 comment · 0 complexity · e78c17179c797d769092c69725ac6e81 MD5 · raw file

  1. <?php
  2. /**
  3. * Class Tribe__Repository__Decorator
  4. *
  5. * This is the base repository decorator class to ease the decoration
  6. * of repositories.
  7. *
  8. * @since 4.7.19
  9. */
  10. abstract class Tribe__Repository__Decorator implements Tribe__Repository__Interface {
  11. /**
  12. * @var Tribe__Repository__Interface|Tribe__Repository__Read_Interface|Tribe__Repository__Update_Interface
  13. */
  14. protected $decorated;
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function get_default_args() {
  19. return $this->decorated->get_default_args();
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function set_default_args( array $default_args ) {
  25. return $this->decorated->set_default_args( $default_args );
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function filter_name( $filter_name ) {
  31. $this->decorated->filter_name( $filter_name );
  32. return $this;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function by_args( array $args ) {
  38. $this->decorated->by_args( $args );
  39. return $this;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function by( $key, $value = null ) {
  45. $call_args = func_get_args();
  46. call_user_func_array( [ $this->decorated, 'by' ], $call_args );
  47. return $this;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function where( $key, $value = null ) {
  53. $call_args = func_get_args();
  54. call_user_func_array( [ $this->decorated, 'where' ], $call_args );
  55. return $this;
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function page( $page ) {
  61. $this->decorated->page( $page );
  62. return $this;
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function per_page( $per_page ) {
  68. $this->decorated->per_page( $per_page );
  69. return $this;
  70. }
  71. /**
  72. * {@inheritdoc}
  73. */
  74. public function found() {
  75. return $this->decorated->found();
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function all() {
  81. return $this->decorated->all();
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function offset( $offset, $increment = false ) {
  87. $this->decorated->offset( $offset );
  88. return $this;
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function order( $order = 'ASC' ) {
  94. $this->decorated->order( $order );
  95. return $this;
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function order_by( $order_by, $order = 'DESC' ) {
  101. $this->decorated->order_by( $order_by, $order );
  102. return $this;
  103. }
  104. /**
  105. * {@inheritdoc}
  106. */
  107. public function fields( $fields ) {
  108. $this->decorated->fields( $fields );
  109. return $this;
  110. }
  111. /**
  112. * {@inheritdoc}
  113. */
  114. public function permission( $permission ) {
  115. $this->decorated->permission( $permission );
  116. return $this;
  117. }
  118. /**
  119. * {@inheritdoc}
  120. */
  121. public function in( $post_ids ) {
  122. $this->decorated->in( $post_ids );
  123. return $this;
  124. }
  125. /**
  126. * {@inheritdoc}
  127. */
  128. public function not_in( $post_ids ) {
  129. $this->decorated->not_in( $post_ids );
  130. return $this;
  131. }
  132. /**
  133. * {@inheritdoc}
  134. */
  135. public function parent( $post_id ) {
  136. $this->decorated->parent( $post_id );
  137. return $this;
  138. }
  139. /**
  140. * {@inheritdoc}
  141. */
  142. public function parent_in( $post_ids ) {
  143. $this->decorated->parent_in( $post_ids );
  144. return $this;
  145. }
  146. /**
  147. * {@inheritdoc}
  148. */
  149. public function parent_not_in( $post_ids ) {
  150. $this->decorated->parent_not_in( $post_ids );
  151. return $this;
  152. }
  153. /**
  154. * {@inheritdoc}
  155. */
  156. public function search( $search ) {
  157. $this->decorated->search( $search );
  158. return $this;
  159. }
  160. /**
  161. * {@inheritdoc}
  162. */
  163. public function count() {
  164. return $this->decorated->count();
  165. }
  166. /**
  167. * {@inheritdoc}
  168. */
  169. public function first() {
  170. return $this->decorated->first();
  171. }
  172. /**
  173. * {@inheritdoc}
  174. */
  175. public function last() {
  176. return $this->decorated->last();
  177. }
  178. /**
  179. * {@inheritdoc}
  180. */
  181. public function nth( $n ) {
  182. return $this->decorated->nth( $n );
  183. }
  184. /**
  185. * {@inheritdoc}
  186. */
  187. public function take( $n ) {
  188. return $this->decorated->take( $n );
  189. }
  190. /**
  191. * {@inheritdoc}
  192. */
  193. public function by_primary_key( $primary_key ) {
  194. return $this->decorated->by_primary_key( $primary_key );
  195. }
  196. /**
  197. * {@inheritdoc}
  198. */
  199. public function set( $key, $value ) {
  200. $this->decorated->set( $key, $value );
  201. return $this;
  202. }
  203. /**
  204. * {@inheritdoc}
  205. */
  206. public function get_query() {
  207. return $this->decorated->get_query();
  208. }
  209. /**
  210. * {@inheritdoc}
  211. */
  212. public function set_args( array $update_map ) {
  213. $this->decorated->set_args( $update_map );
  214. return $this;
  215. }
  216. /**
  217. * {@inheritdoc}
  218. */
  219. public function save( $return_promise = true ) {
  220. $this->decorated->save( $return_promise );
  221. }
  222. /**
  223. * {@inheritdoc}
  224. */
  225. public function set_formatter( Tribe__Repository__Formatter_Interface $formatter ) {
  226. $this->decorated->set_formatter( $formatter );
  227. }
  228. /**
  229. * {@inheritdoc}
  230. */
  231. public function join_clause( $join ) {
  232. $this->decorated->join_clause( $join );
  233. }
  234. /**
  235. * {@inheritdoc}
  236. */
  237. public function where_clause( $where ) {
  238. $this->decorated->where_clause( $where );
  239. }
  240. /**
  241. * {@inheritdoc}
  242. */
  243. public function set_query_builder( $query_builder ) {
  244. $this->decorated->set_query_builder( $query_builder );
  245. }
  246. /**
  247. * Sets the repository to be decorated.
  248. *
  249. * @since 4.7.19
  250. *
  251. * @param Tribe__Repository__Interface $decorated
  252. */
  253. protected function set_decorated_repository( Tribe__Repository__Interface $decorated ) {
  254. $this->decorated = $decorated;
  255. }
  256. /**
  257. * {@inheritdoc}
  258. */
  259. public function build_query( $use_query_builder = true ) {
  260. return $this->decorated->build_query( $use_query_builder );
  261. }
  262. /**
  263. * {@inheritdoc}
  264. */
  265. public function where_or( $callbacks ) {
  266. $call_args = func_get_args();
  267. call_user_func_array( [ $this->decorated, 'where_or' ], $call_args );
  268. return $this;
  269. }
  270. /**
  271. * {@inheritdoc}
  272. */
  273. public function by_related_to_min( $by_meta_keys, $min, $keys = null, $values = null ) {
  274. $this->decorated->by_related_to_min( $by_meta_keys, $min, $keys, $values );
  275. return $this;
  276. }
  277. /**
  278. * {@inheritdoc}
  279. */
  280. public function by_related_to_max( $by_meta_keys, $max, $keys = null, $values = null ) {
  281. $this->decorated->by_related_to_max( $by_meta_keys, $max, $keys, $values );
  282. return $this;
  283. }
  284. /**
  285. * {@inheritdoc}
  286. */
  287. public function by_related_to_between( $by_meta_keys, $min, $max, $keys = null, $values = null ) {
  288. $this->decorated->by_related_to_between( $by_meta_keys, $min, $max, $keys, $values );
  289. return $this;
  290. }
  291. /**
  292. * {@inheritdoc}
  293. */
  294. public function has_filter( $key, $value = null ) {
  295. return $this->decorated->has_filter( $key, $value );
  296. }
  297. /**
  298. * {@inheritdoc}
  299. */
  300. public function get_current_filter() {
  301. return $this->decorated->get_current_filter();
  302. }
  303. /**
  304. * {@inheritdoc}
  305. */
  306. public function get_ids() {
  307. return $this->decorated->get_ids();
  308. }
  309. /**
  310. * {@inheritdoc}
  311. */
  312. public function add_schema_entry( $key, $callback ) {
  313. $this->decorated->add_schema_entry( $key, $callback );
  314. }
  315. /**
  316. * {@inheritdoc}
  317. */
  318. public function prepare_interval( $values, $format = '%s' ) {
  319. return $this->decorated->prepare_interval( $values, $format );
  320. }
  321. /**
  322. * {@inheritdoc}
  323. */
  324. public function delete( $return_promise = false ) {
  325. return $this->decorated->delete( $return_promise );
  326. }
  327. /**
  328. * {@inheritdoc}
  329. */
  330. public function async_delete( array $to_delete, $return_promise = true ) {
  331. return $this->decorated->async_delete( $to_delete, $return_promise );
  332. }
  333. /**
  334. * {@inheritdoc}
  335. */
  336. public function add_update_field_alias( $alias, $field_name ) {
  337. $this->decorated->add_update_field_alias( $alias, $field_name );
  338. }
  339. /**
  340. * {@inheritdoc}
  341. */
  342. public function async_update( array $to_update, $return_promise = true ) {
  343. return $this->decorated->async_update( $to_update, $return_promise );
  344. }
  345. /**
  346. * {@inheritdoc}
  347. */
  348. public function get_update_fields_aliases() {
  349. return $this->decorated->get_update_fields_aliases();
  350. }
  351. /**
  352. * {@inheritdoc}
  353. */
  354. public function set_update_fields_aliases( array $update_fields_aliases ) {
  355. $this->decorated->set_update_fields_aliases( $update_fields_aliases );
  356. }
  357. /**
  358. * {@inheritdoc}
  359. */
  360. public function get_filter_name() {
  361. return $this->decorated->get_filter_name();
  362. }
  363. /**
  364. * {@inheritdoc}
  365. */
  366. public function filter_postarr_for_update( array $postarr, $post_id ) {
  367. return $this->decorated->filter_postarr_for_update( $postarr, $post_id );
  368. }
  369. /**
  370. * {@inheritdoc}
  371. */
  372. public function build_postarr( $id = null ) {
  373. return $this->decorated->build_postarr();
  374. }
  375. /**
  376. * {@inheritdoc}
  377. */
  378. public function create() {
  379. return $this->decorated->create();
  380. }
  381. /**
  382. * {@inheritdoc}
  383. */
  384. public function filter_postarr_for_create( array $postarr ) {
  385. return $this->decorated->filter_postarr_for_create( $postarr, $post_id );
  386. }
  387. /**
  388. * {@inheritdoc}
  389. */
  390. public function set_create_args( array $create_args ) {
  391. $this->decorated->set_create_args( $create_args );
  392. }
  393. /**
  394. * {@inheritdoc}
  395. */
  396. public function get_create_args() {
  397. return $this->decorated->get_create_args();
  398. }
  399. /**
  400. * {@inheritdoc}
  401. */
  402. public function set_display_context( $context = 'default' ) {
  403. $this->decorated->set_display_context( $context );
  404. return $this;
  405. }
  406. /**
  407. * {@inheritdoc}
  408. */
  409. public function set_render_context( $context = 'default' ) {
  410. $this->decorated->set_render_context( $context );
  411. return $this;
  412. }
  413. /**
  414. * {@inheritdoc}
  415. */
  416. public function get_query_for_posts( array $posts ) {
  417. return $this->decorated->get_query_for_posts( $posts );
  418. }
  419. /**
  420. * Whether the decorator is decorating an instance of a specific repository class or not.
  421. *
  422. * The check is made recursively for decorators to get to the first repository implementation.
  423. *
  424. * @since 4.9.5
  425. *
  426. * @param string $class The class to check for.
  427. *
  428. * @return bool Whether the decorator is decorating an instance of a specific repository class or not.
  429. */
  430. public function decorates_an_instance_of( $class ) {
  431. return $this->decorated instanceof Tribe__Repository__Decorator
  432. ? $this->decorated->decorates_an_instance_of( $class )
  433. : $this->decorated instanceof $class;
  434. }
  435. /**
  436. * Returns the concrete repository implementation that's "hidden" under the decorator(s).
  437. *
  438. * @since 4.9.5
  439. *
  440. * @return \Tribe__Repository__Interface The concrete repository instance.
  441. */
  442. public function get_decorated_repository() {
  443. return $this->decorated instanceof Tribe__Repository__Decorator
  444. ? $this->decorated->get_decorated_repository()
  445. : $this->decorated;
  446. }
  447. /**
  448. * {@inheritdoc}
  449. */
  450. public function pluck( $field ) {
  451. return $this->decorated->pluck( $field );
  452. }
  453. /**
  454. * {@inheritdoc}
  455. */
  456. public function filter( $orderby = [], $order = 'ASC', $preserve_keys = false ) {
  457. return $this->decorated->filter( $orderby, $order, $preserve_keys );
  458. }
  459. /**
  460. * {@inheritdoc}
  461. */
  462. public function sort( $orderby = [], $order = 'ASC', $preserve_keys = false ) {
  463. return $this->decorated->sort( $orderby, $order, $preserve_keys );
  464. }
  465. /**
  466. * {@inheritdoc}
  467. */
  468. public function collect() {
  469. return $this->decorated->collect();
  470. }
  471. /**
  472. * {@inheritdoc}
  473. */
  474. public function hash( array $settings = [], WP_Query $query = null ) {
  475. return $this->decorated->hash( $settings );
  476. }
  477. /**
  478. * {@inheritDoc}
  479. */
  480. public function get_hash_data( array $settings, WP_Query $query = null ) {
  481. return $this->decorated->get_hash_data( $settings, $query );
  482. }
  483. /**
  484. * {@inheritDoc}
  485. */
  486. public function get_last_built_query() {
  487. return $this->decorated->last_built_query;
  488. }
  489. /**
  490. * {@inheritDoc}
  491. */
  492. public function where_multi( array $fields, $compare, $value, $where_relation = 'OR', $value_relation = 'OR' ) {
  493. $this->decorated->where_multi( $fields, $compare, $value, $where_relation, $value_relation );
  494. return $this;
  495. }
  496. /**
  497. * Handle getting additional property from decorated object.
  498. *
  499. * @since 4.9.6.1
  500. *
  501. * @param string $name Property name.
  502. *
  503. * @return mixed
  504. */
  505. public function __get( $name ) {
  506. return $this->decorated->{$name};
  507. }
  508. /**
  509. * Handle setting additional property on decorated object.
  510. *
  511. * @since 4.9.6.1
  512. *
  513. * @param string $name Property name.
  514. * @param mixed $value Property value.
  515. */
  516. public function __set( $name, $value ) {
  517. $this->decorated->{$name} = $value;
  518. }
  519. /**
  520. * Check if additional property on decorated object exists.
  521. *
  522. * @since 4.9.6.1
  523. *
  524. * @param string $name Property name.
  525. *
  526. * @return bool
  527. */
  528. public function __isset( $name ) {
  529. return isset( $this->decorated->{$name} );
  530. }
  531. /**
  532. * Call methods on decorated object.
  533. *
  534. * @since 4.9.6.1
  535. *
  536. * @param string $name Method name.
  537. * @param array $arguments Method arguments.
  538. *
  539. * @return mixed
  540. */
  541. public function __call( $name, $arguments ) {
  542. return call_user_func_array( [ $this->decorated, $name ], $arguments );
  543. }
  544. /**
  545. * {@inheritDoc}
  546. */
  547. public function set_query( WP_Query $query ) {
  548. $this->decorated->set_query( $query );
  549. return $this;
  550. }
  551. /**
  552. * {@inheritDoc}
  553. */
  554. public function next() {
  555. return $this->decorated->next();
  556. }
  557. /**
  558. * {@inheritDoc}
  559. */
  560. public function prev() {
  561. return $this->decorated->prev();
  562. }
  563. /**
  564. * {@inheritDoc}
  565. */
  566. public function set_found_rows( $found_rows ) {
  567. $this->decorated->set_found_rows( $found_rows );
  568. return $this;
  569. }
  570. /**
  571. * {@inheritDoc}
  572. */
  573. public function void_query( $void_query = true ) {
  574. $this->decorated->void_query( $void_query );
  575. return $this;
  576. }
  577. }