1 | <?php |
||
11 | class Seeder |
||
|
|||
12 | { |
||
13 | private $CI; |
||
14 | protected $db; |
||
15 | protected $dbforge; |
||
16 | protected $seedPath; |
||
17 | protected $depends = []; |
||
18 | |||
19 | public function __construct() |
||
27 | |||
28 | /** |
||
29 | * Run another seeder |
||
30 | * |
||
31 | * @param string $seeder Seeder classname |
||
32 | * @param bool $callDependencies |
||
33 | */ |
||
34 | public function call($seeder, $callDependencies = true) |
||
35 | { |
||
36 | if ($this->seedPath === null) |
||
37 | { |
||
38 | $this->seedPath = APPPATH . 'database/seeds/'; |
||
39 | } |
||
40 | |||
41 | $obj = $this->loadSeeder($seeder); |
||
42 | if ($callDependencies === true && $obj instanceof Seeder) { |
||
43 | $obj->callDependencies($this->seedPath); |
||
44 | } |
||
45 | $obj->run(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Get Seeder instance |
||
50 | * |
||
51 | * @param string $seeder |
||
52 | * @return Seeder |
||
53 | */ |
||
54 | protected function loadSeeder($seeder) |
||
61 | |||
62 | /** |
||
63 | * Call dependency seeders |
||
64 | * |
||
65 | * @param string $seedPath |
||
66 | */ |
||
67 | public function callDependencies($seedPath) |
||
68 | { |
||
69 | foreach ($this->depends as $path => $seeders) { |
||
70 | $this->seedPath = $seedPath; |
||
71 | if (is_string($path)) { |
||
72 | $this->setPath($path); |
||
73 | } |
||
74 | |||
75 | $this->callDependency($seeders); |
||
76 | } |
||
77 | $this->setPath($seedPath); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Call dependency seeder |
||
82 | * |
||
83 | * @param string|array $seederName |
||
84 | */ |
||
85 | protected function callDependency($seederName) |
||
86 | { |
||
87 | if (is_array($seederName)) { |
||
88 | array_map([$this, 'callDependency'], $seederName); |
||
89 | return; |
||
90 | } |
||
91 | |||
92 | $seeder = $this->loadSeeder($seederName); |
||
93 | if (is_string($this->seedPath)) { |
||
94 | $seeder->setPath($this->seedPath); |
||
95 | } |
||
96 | |||
97 | $seeder->call($seederName, true); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Set path for seeder files |
||
102 | * |
||
103 | * @param string $path |
||
104 | */ |
||
105 | public function setPath($path) |
||
109 | |||
110 | public function __get($property) |
||
114 | } |
||
115 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.