PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Database / Seeder.php
kirki / libraries / framework / Database Last commit date
Concerns 1 week ago Connection 1 week ago Constants 1 month ago Contracts 1 week ago Migrations 1 month ago Query 1 week ago Schema 1 week ago Seeder.php 1 week ago
Seeder.php
99 lines
1 <?php
2
3 /**
4 * Base class for database seeders with call tracking to prevent duplicate execution.
5 * Resolves seeder classes from the container and runs them within optional transactions.
6 * Coordinates ordered seeding through the static call API.
7 *
8 * @package Framework
9 * @subpackage Database
10 * @since 1.0.0
11 */
12 namespace Kirki\Framework\Database;
13
14 \defined('ABSPATH') || exit;
15 use Kirki\Framework\Supports\Arr;
16 use Throwable;
17 use function Kirki\Framework\app;
18 class Seeder
19 {
20 /**
21 * Store the called seeder classes
22 *
23 * @var string[]
24 *
25 * @since 1.0.0
26 */
27 protected static $called = [];
28 /**
29 * Track the already resolved seeders so that it doesn't run again
30 *
31 * @var string[]
32 *
33 * @since 1.0.0
34 */
35 protected static $resolved = [];
36 /**
37 * Call the seeders
38 *
39 * @param mixed $class The class.
40 *
41 * @return Seeder
42 *
43 * @since 1.0.0
44 */
45 public function call($class)
46 {
47 $classes = Arr::wrap($class);
48 foreach ($classes as $class) {
49 if (!\in_array($class, static::$called, \true) && empty(static::$resolved[$class])) {
50 static::$called[] = $class;
51 }
52 }
53 return $this;
54 }
55 /**
56 * Resolve the seeder
57 *
58 * @param mixed $class The class.
59 *
60 * @return Seeder
61 *
62 * @since 1.0.0
63 */
64 protected function resolve($class)
65 {
66 return app()->make($class);
67 }
68 /**
69 * Run the seeder
70 *
71 * @return void
72 *
73 * @since 1.0.0
74 */
75 public function run()
76 {
77 //
78 }
79 /**
80 * Run the seeders
81 *
82 * @return void
83 *
84 * @since 1.0.0
85 */
86 public function __invoke()
87 {
88 try {
89 while (!empty(static::$called)) {
90 $seeder = \array_shift(static::$called);
91 $this->resolve($seeder)->run();
92 static::$resolved[$seeder] = \true;
93 }
94 } catch (Throwable $exception) {
95 throw $exception;
96 }
97 }
98 }
99