PluginProbe
ElasticPress / 4.3.0
ElasticPress v4.3.0
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / includes / classes / Indexables.php

Indexables.php in ElasticPress 4.3.0, at includes/classes/Indexables.php

96 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles indexable registration and storage
4 *
5 * @since 3.0
6 * @package elasticpress
7 */
8
9 namespace ElasticPress;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Class for handling all Indexable instances
17 */
18 class Indexables {
19
20 /**
21 * Array of registered indexables
22 *
23 * @var array
24 * @since 3.0
25 */
26 private $registered_indexables = [];
27
28 /**
29 * Register an indexable instance
30 *
31 * @param Indexable $indexable Instance of Indexable.
32 * @since 3.0
33 */
34 public function register( Indexable $indexable ) {
35 $this->registered_indexables[ $indexable->slug ] = $indexable;
36 }
37
38 /**
39 * Get an indexable instance given a slug
40 *
41 * @param string $slug Indexable type slug.
42 * @since 3.0
43 * @return Indexable|boolean
44 */
45 public function get( $slug ) {
46 return ( ! empty( $this->registered_indexables[ $slug ] ) ) ? $this->registered_indexables[ $slug ] : false;
47 }
48
49 /**
50 * Get all indexable instances
51 *
52 * @param boolean $global If true or false, will only get Indexables with that global property.
53 * @param boolean $slug_only True returns an array of only string slugs.
54 * @since 3.0
55 * @return array
56 */
57 public function get_all( $global = null, $slug_only = false ) {
58 $indexables = [];
59
60 foreach ( $this->registered_indexables as $slug => $indexable ) {
61 if ( null === $global ) {
62 if ( $slug_only ) {
63 $indexables[] = $slug;
64 } else {
65 $indexables[] = $indexable;
66 }
67 } else {
68 if ( $global === $indexable->global ) {
69 if ( $slug_only ) {
70 $indexables[] = $slug;
71 } else {
72 $indexables[] = $indexable;
73 }
74 }
75 }
76 }
77
78 return $indexables;
79 }
80
81 /**
82 * Return singleton instance of class
83 *
84 * @return object
85 */
86 public static function factory() {
87 static $instance = false;
88
89 if ( ! $instance ) {
90 $instance = new self();
91 }
92
93 return $instance;
94 }
95 }
96