PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.62
Timetics – Appointment Booking Calendar & Scheduling v1.0.62
1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 All 64 releases
timetics / core / dummy-data / generator.php

generator.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.62, at core/dummy-data/generator.php

101 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Faker Generator
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Core\DummyData;
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Faker generator class
13 */
14 class Generator {
15 /**
16 * Store providers
17 *
18 * @var array
19 */
20 protected $providers = [];
21
22 /**
23 * Store formaters
24 *
25 * @var array
26 */
27 protected $formatters = [];
28
29 /**
30 * @param string $attribute
31 *
32 * @return mixex
33 */
34 public function __get( $attribute ) {
35 return $this->format( $attribute );
36 }
37
38 /**
39 * @param string $method_name
40 * @param array $arguments
41 *
42 * @return mixed
43 */
44 public function __call( $method_name, $attributes ) {
45 return $this->format( $method_name, $attributes );
46 }
47
48 /**
49 * Add provider to providers
50 *
51 * @param Object $provider
52 *
53 * @return void
54 */
55 public function add_provider( $provider ) {
56 array_unshift( $this->providers, $provider );
57 }
58
59 /**
60 * Get all providers
61 *
62 * @return array
63 */
64 public function get_provider() {
65 return $this->providers;
66 }
67
68 /**
69 * Format faker data
70 *
71 * @param string $formatter
72 * @param array $arguments
73 *
74 * @return mixed
75 */
76 public function format( $formatter, $arguments = [] ) {
77 return call_user_func_array( $this->get_formatter( $formatter ), $arguments );
78 }
79
80 /**
81 * @param string $formatter
82 *
83 * @return Callable
84 */
85 public function get_formatter( $formatter ) {
86 if ( isset( $this->formatters[$formatter] ) ) {
87 return $this->formatters[$formatter];
88 }
89
90 foreach ( $this->providers as $provider ) {
91 if ( method_exists( $provider, $formatter ) ) {
92 $this->formatters[$formatter] = [$provider, $formatter];
93
94 return $this->formatters[$formatter];
95 }
96 }
97
98 throw new \InvalidArgumentException( sprintf( 'Unknown formatter "%s"', wp_kses( $formatter, 'post' ) ) );
99 }
100 }
101