Completed
Pull Request — master (#1657)
by mark
04:09
created

AbstractSeed::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace Phinx\Seed;
9
10
use Phinx\Db\Adapter\AdapterInterface;
11
use Phinx\Db\Table;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * Abstract Seed Class.
17
 *
18
 * It is expected that the seeds you write extend from this class.
19
 *
20
 * This abstract class proxies the various database methods to your specified
21
 * adapter.
22
 *
23
 * @author Rob Morgan <[email protected]>
24
 */
25
abstract class AbstractSeed implements SeedInterface
26
{
27
    /**
28
     * @var \Phinx\Db\Adapter\AdapterInterface
29
     */
30
    protected $adapter;
31
32
    /**
33
     * @var \Symfony\Component\Console\Input\InputInterface
34
     */
35
    protected $input;
36
37
    /**
38
     * @var \Symfony\Component\Console\Output\OutputInterface
39
     */
40
    protected $output;
41
42
    /**
43
     * @param \Symfony\Component\Console\Input\InputInterface|null $input
44
     * @param \Symfony\Component\Console\Output\OutputInterface|null $output
45
     */
46
    final public function __construct(InputInterface $input = null, OutputInterface $output = null)
47
    {
48
        if ($input !== null) {
49
            $this->setInput($input);
50
        }
51
        if ($output !== null) {
52
            $this->setOutput($output);
53
        }
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function run()
60
    {
61
    }
62
63
    /**
64
     * Return seeds dependencies.
65
     *
66
     * @return array
67
     */
68
    public function getDependencies()
69 11
    {
70
        return [];
71 11
    }
72 11
73 11
    /**
74 11
     * @inheritDoc
75 11
     */
76 11
    public function setAdapter(AdapterInterface $adapter)
77
    {
78 11
        $this->adapter = $adapter;
79 11
80
        return $this;
81
    }
82
83
    /**
84
     * @inheritDoc
85
     */
86 11
    public function getAdapter()
87
    {
88 11
        return $this->adapter;
89
    }
90
91
    /**
92
     * @inheritDoc
93
     */
94
    public function setInput(InputInterface $input)
95
    {
96
        $this->input = $input;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @inheritDoc
103
     */
104
    public function getInput()
105
    {
106
        return $this->input;
107
    }
108
109
    /**
110
     * @inheritDoc
111
     */
112
    public function setOutput(OutputInterface $output)
113
    {
114
        $this->output = $output;
115
116
        return $this;
117 11
    }
118
119 11
    /**
120 11
     * @inheritDoc
121
     */
122
    public function getOutput()
123
    {
124
        return $this->output;
125
    }
126 1
127
    /**
128 1
     * @inheritDoc
129
     */
130
    public function getName()
131
    {
132
        return static::class;
133
    }
134 11
135
    /**
136 11
     * @inheritDoc
137 11
     */
138
    public function execute($sql)
139
    {
140
        return $this->getAdapter()->execute($sql);
141
    }
142
143 1
    /**
144
     * @inheritDoc
145 1
     */
146
    public function query($sql)
147
    {
148
        return $this->getAdapter()->query($sql);
149
    }
150
151 6
    /**
152
     * @inheritDoc
153 6
     */
154
    public function fetchRow($sql)
155
    {
156
        return $this->getAdapter()->fetchRow($sql);
157
    }
158
159
    /**
160
     * @inheritDoc
161
     */
162
    public function fetchAll($sql)
163
    {
164
        return $this->getAdapter()->fetchAll($sql);
165
    }
166
167
    /**
168
     * @inheritDoc
169
     */
170
    public function insert($table, $data)
171
    {
172
        // convert to table object
173
        if (is_string($table)) {
174
            $table = new Table($table, [], $this->getAdapter());
175
        }
176
        $table->insert($data)->save();
177
    }
178
179
    /**
180
     * @inheritDoc
181
     */
182
    public function hasTable($tableName)
183
    {
184
        return $this->getAdapter()->hasTable($tableName);
185
    }
186
187
    /**
188
     * @inheritDoc
189
     */
190
    public function table($tableName, $options = [])
191
    {
192
        return new Table($tableName, $options, $this->getAdapter());
193
    }
194
}
195