1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Database;
|
4 |
|
|
|
5 |
|
|
use Illuminate\Console\Command;
|
6 |
|
|
use Illuminate\Container\Container;
|
7 |
|
|
|
8 |
|
|
abstract class Seeder
|
9 |
|
|
{
|
10 |
|
|
/**
|
11 |
|
|
* The container instance.
|
12 |
|
|
*
|
13 |
|
|
* @var \Illuminate\Container\Container
|
14 |
|
|
*/
|
15 |
|
|
protected $container;
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* The console command instance.
|
19 |
|
|
*
|
20 |
|
|
* @var \Illuminate\Console\Command
|
21 |
|
|
*/
|
22 |
|
|
protected $command;
|
23 |
|
|
|
24 |
|
|
/**
|
25 |
|
|
* Run the database seeds.
|
26 |
|
|
*
|
27 |
|
|
* @return void
|
28 |
|
|
*/
|
29 |
|
|
abstract public function run();
|
30 |
|
|
|
31 |
|
|
/**
|
32 |
|
|
* Seed the given connection from the given path.
|
33 |
|
|
*
|
34 |
|
|
* @param string $class
|
35 |
|
|
* @return void
|
36 |
|
|
*/
|
37 |
|
|
public function call($class)
|
38 |
|
|
{
|
39 |
|
|
$this->resolve($class)->run();
|
40 |
|
|
|
41 |
|
|
if (isset($this->command)) {
|
42 |
|
|
$this->command->getOutput()->writeln("<info>Seeded:</info> $class");
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Resolve an instance of the given seeder class.
|
48 |
|
|
*
|
49 |
|
|
* @param string $class
|
50 |
|
|
* @return \Illuminate\Database\Seeder
|
51 |
|
|
*/
|
52 |
|
|
protected function resolve($class)
|
53 |
|
|
{
|
54 |
|
|
if (isset($this->container)) {
|
55 |
|
|
$instance = $this->container->make($class);
|
56 |
|
|
|
57 |
|
|
$instance->setContainer($this->container);
|
58 |
|
|
} else {
|
59 |
|
|
$instance = new $class;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
if (isset($this->command)) {
|
63 |
|
|
$instance->setCommand($this->command);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
return $instance;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Set the IoC container instance.
|
71 |
|
|
*
|
72 |
|
|
* @param \Illuminate\Container\Container $container
|
73 |
|
|
* @return $this
|
74 |
|
|
*/
|
75 |
|
|
public function setContainer(Container $container)
|
76 |
|
|
{
|
77 |
|
|
$this->container = $container;
|
78 |
|
|
|
79 |
|
|
return $this;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
/**
|
83 |
|
|
* Set the console command instance.
|
84 |
|
|
*
|
85 |
|
|
* @param \Illuminate\Console\Command $command
|
86 |
|
|
* @return $this
|
87 |
|
|
*/
|
88 |
|
|
public function setCommand(Command $command)
|
89 |
|
|
{
|
90 |
|
|
$this->command = $command;
|
91 |
|
|
|
92 |
|
|
return $this;
|
93 |
|
|
}
|
94 |
|
|
}
|