PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 134 releases
jetformbuilder / modules / framework / blocks-style-manager / style-cache.php

style-cache.php in JetFormBuilder — Dynamic Blocks Form Builder 3.6.6, at modules/framework/blocks-style-manager/style-cache.php

100 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CSS caching class
4 */
5 namespace Crocoblock\Blocks_Style;
6
7 class Style_Cache {
8
9 /**
10 * Class instance
11 *
12 * @var Style_Cache
13 */
14 private static $instance = null;
15
16 /**
17 * Cached styles by classes
18 *
19 * @var array
20 */
21 protected $generated_css = array();
22
23 /**
24 * List of already printed CSS classes
25 *
26 * @var array
27 */
28 protected $printed_css = array();
29
30 /**
31 * Check if the class is already printed
32 *
33 * @param string $class_name
34 * @return boolean
35 */
36 public function is_printed( $class_name ) {
37
38 if ( ! is_string( $class_name ) || empty( $class_name ) ) {
39 return false;
40 }
41
42 return in_array( $class_name, $this->printed_css, true );
43 }
44
45 /**
46 * Get cached or generated styles.
47 *
48 * @param Style_Engine $style_engine
49 * @return void
50 */
51 public function get_cached( $style_engine ) {
52
53 if ( ! $style_engine instanceof Style_Engine ) {
54 return array();
55 }
56
57 $class_name = $style_engine->get_class_name();
58
59 if ( isset( $this->generated_css[ $class_name ] ) ) {
60 return $this->generated_css[ $class_name ];
61 }
62
63 $styles_data = $style_engine->get_styles();
64
65 if ( ! empty( $styles_data ) ) {
66 $this->generated_css[ $class_name ] = $styles_data;
67 }
68
69 return $styles_data;
70 }
71
72 /**
73 * Add a class to the printed CSS classes list
74 *
75 * @param string $class_name
76 */
77 public function add_printed( $class_name ) {
78
79 if ( ! is_string( $class_name ) || empty( $class_name ) ) {
80 return;
81 }
82 if ( ! in_array( $class_name, $this->printed_css, true ) ) {
83 $this->printed_css[] = $class_name;
84 }
85 }
86
87 /**
88 * Get the instance of the Style_Cache class
89 *
90 * @return Style_Cache
91 */
92 public static function get_instance() {
93
94 if ( null === self::$instance ) {
95 self::$instance = new self();
96 }
97
98 return self::$instance;
99 }
100 }