PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.1
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.1
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 3 weeks ago Connection 3 weeks ago Constants 3 weeks ago Contracts 3 weeks ago Migrations 3 weeks ago Query 1 week ago Schema 3 weeks ago Seeder.php 3 weeks ago
Seeder.php
101 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 Kirki\Framework\Supports\Facades\DB;
17 use Kirki\Framework\Supports\Facades\Log;
18 use Throwable;
19 use function Kirki\Framework\app;
20 class Seeder
21 {
22 /**
23 * Store the called seeder classes
24 *
25 * @var string[]
26 *
27 * @since 1.0.0
28 */
29 protected static $called = [];
30 /**
31 * Track the already resolved seeders so that it doesn't run again
32 *
33 * @var string[]
34 *
35 * @since 1.0.0
36 */
37 protected static $resolved = [];
38 /**
39 * Call the seeders
40 *
41 * @param mixed $class The class.
42 *
43 * @return Seeder
44 *
45 * @since 1.0.0
46 */
47 public function call($class)
48 {
49 $classes = Arr::wrap($class);
50 foreach ($classes as $class) {
51 if (!\in_array($class, static::$called, \true) && empty(static::$resolved[$class])) {
52 static::$called[] = $class;
53 }
54 }
55 return $this;
56 }
57 /**
58 * Resolve the seeder
59 *
60 * @param mixed $class The class.
61 *
62 * @return Seeder
63 *
64 * @since 1.0.0
65 */
66 protected function resolve($class)
67 {
68 return app()->make($class);
69 }
70 /**
71 * Run the seeder
72 *
73 * @return void
74 *
75 * @since 1.0.0
76 */
77 public function run()
78 {
79 //
80 }
81 /**
82 * Run the seeders
83 *
84 * @return void
85 *
86 * @since 1.0.0
87 */
88 public function __invoke()
89 {
90 try {
91 while (!empty(static::$called)) {
92 $seeder = \array_shift(static::$called);
93 $this->resolve($seeder)->run();
94 static::$resolved[$seeder] = \true;
95 }
96 } catch (Throwable $exception) {
97 throw $exception;
98 }
99 }
100 }
101