1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <https://github.com/baleen/migrations>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Migration\Factory; |
21
|
|
|
|
22
|
|
|
use Baleen\Migrations\Exception\InvalidArgumentException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritdoc |
26
|
|
|
*/ |
27
|
|
|
final class SimpleFactory implements FactoryInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @inheritdoc |
31
|
|
|
* |
32
|
|
|
* @throws InvalidArgumentException |
33
|
|
|
*/ |
34
|
9 |
|
public function create($class, $args = []) |
35
|
|
|
{ |
36
|
9 |
|
$class = (string) $class; |
37
|
|
|
|
38
|
9 |
|
if (empty($class)) { |
39
|
1 |
|
throw new InvalidArgumentException( |
40
|
|
|
'Cannot create a migration from an empty class name!' |
41
|
1 |
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
8 |
|
if (!is_array($args)) { |
45
|
1 |
|
throw new InvalidArgumentException( |
46
|
|
|
'Argument "params" must be an array of parameters.' |
47
|
1 |
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
7 |
|
if (!empty($args)) { |
51
|
1 |
|
$class = new \ReflectionClass($class); |
52
|
1 |
|
$instance = $class->newInstanceArgs($args); |
53
|
1 |
|
} else { |
54
|
6 |
|
$instance = new $class(); |
55
|
|
|
} |
56
|
|
|
|
57
|
7 |
|
return $instance; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|