PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.11
Timetics – Appointment Booking Calendar & Scheduling v1.0.11
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 1.0.23 1.0.24 All 62 releases
timetics / core / dummy-data / generator.php

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

99 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 /**
10 * Faker generator class
11 */
12 class Generator {
13 /**
14 * Store providers
15 *
16 * @var array
17 */
18 protected $providers = [];
19
20 /**
21 * Store formaters
22 *
23 * @var array
24 */
25 protected $formatters = [];
26
27 /**
28 * @param string $attribute
29 *
30 * @return mixex
31 */
32 public function __get( $attribute ) {
33 return $this->format( $attribute );
34 }
35
36 /**
37 * @param string $method_name
38 * @param array $arguments
39 *
40 * @return mixed
41 */
42 public function __call( $method_name, $attributes ) {
43 return $this->format( $method_name, $attributes );
44 }
45
46 /**
47 * Add provider to providers
48 *
49 * @param Object $provider
50 *
51 * @return void
52 */
53 public function add_provider( $provider ) {
54 array_unshift( $this->providers, $provider );
55 }
56
57 /**
58 * Get all providers
59 *
60 * @return array
61 */
62 public function get_provider() {
63 return $this->providers;
64 }
65
66 /**
67 * Format faker data
68 *
69 * @param string $formatter
70 * @param array $arguments
71 *
72 * @return mixed
73 */
74 public function format( $formatter, $arguments = [] ) {
75 return call_user_func_array( $this->get_formatter( $formatter ), $arguments );
76 }
77
78 /**
79 * @param string $formatter
80 *
81 * @return Callable
82 */
83 public function get_formatter( $formatter ) {
84 if ( isset( $this->formatters[$formatter] ) ) {
85 return $this->formatters[$formatter];
86 }
87
88 foreach ( $this->providers as $provider ) {
89 if ( method_exists( $provider, $formatter ) ) {
90 $this->formatters[$formatter] = [$provider, $formatter];
91
92 return $this->formatters[$formatter];
93 }
94 }
95
96 throw new \InvalidArgumentException( sprintf( 'Unknown formatter "%s"', $formatter ) );
97 }
98 }
99