PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | database/DBSeeder.php +51 -1 1.3.20 → 1.6.5 View file →
@@ -2,9 +2,8 @@
2 2
3 3 namespace FluentCart\Database;
4 4
5 5 use FluentCart\App\App;
6 -use FluentCart\Database\Seeder\AttributeSeeder;
7 6 use FluentCart\Database\Seeder\CouponSeeder;
8 7 use FluentCart\Database\Seeder\CustomerAddressSeeder;
9 8 use FluentCart\Database\Seeder\OrderAddressSeeder;
10 9 use FluentCart\Database\Seeder\OrderOperationSeeder;
@@ -19,8 +18,10 @@
19 18 class DBSeeder
20 19 {
21 20 public static function run($count = 10, $entity = null, $checkDev = true, $assoc_args = [])
22 21 {
22 + static::ensureFakerAliases();
23 +
23 24 $seeders = [
24 25 'customer' => CustomerSeeder::class,
25 26 'customer_address' => CustomerAddressSeeder::class,
26 27 'coupon' => CouponSeeder::class,
@@ -54,6 +55,55 @@
54 55 $seeders[$entity]::seed($count, $assoc_args);
55 56 }
56 57 }
57 58
59 + }
60 +
61 + /**
62 + * Boot Faker and make the namespace the seeders import resolvable.
63 + *
64 + * Two things stand between the seeders and Faker in a normal install:
65 + *
66 + * 1. The generated Composer autoloader is classmap-authoritative and
67 + * composer.json excludes `/vendor/fakerphp/` from the classmap, so
68 + * `Faker\Factory` never autoloads. Faker ships its own PSR-0 autoloader,
69 + * so register that instead of touching the Composer config.
70 + * 2. Every seeder imports `FluentCart\Faker\Factory` (and ProductNameProvide
71 + * extends `FluentCart\Faker\Provider\Base`). That prefixed namespace only
72 + * exists once dev/ComposerScript rewrites the vendor autoloader, and
73 + * composer.json sets extra.wpfluent.excludes to ["*"], which skips generic
74 + * packages such as fakerphp/faker — so alias the upstream classes onto it.
75 + *
76 + * Without this, every seeder fatals with
77 + * "Class FluentCart\Faker\Factory not found".
78 + *
79 + * @return void
80 + */
81 + protected static function ensureFakerAliases()
82 + {
83 + if (class_exists('FluentCart\\Faker\\Factory')) {
84 + return;
85 + }
86 +
87 + if (!class_exists('Faker\\Factory')) {
88 + $fakerAutoload = FLUENTCART_PLUGIN_PATH . 'vendor/fakerphp/faker/src/autoload.php';
89 +
90 + if (!file_exists($fakerAutoload)) {
91 + return;
92 + }
93 +
94 + require_once $fakerAutoload;
95 + }
96 +
97 + $aliases = [
98 + 'Faker\\Factory' => 'FluentCart\\Faker\\Factory',
99 + 'Faker\\Generator' => 'FluentCart\\Faker\\Generator',
100 + 'Faker\\Provider\\Base' => 'FluentCart\\Faker\\Provider\\Base',
101 + ];
102 +
103 + foreach ($aliases as $original => $alias) {
104 + if (class_exists($original) && !class_exists($alias, false)) {
105 + class_alias($original, $alias);
106 + }
107 + }
58 108 }
59 109 }