Completed
Push — master ( b74889...e4b807 )
by Kenji
02:40
created

Seeder::call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.4285
1
<?php
2
/**
3
 * Part of ci-phpunit-test
4
 *
5
 * @author     Kenji Suzuki <https://github.com/kenjis>
6
 * @license    MIT License
7
 * @copyright  2015 Kenji Suzuki
8
 * @link       https://github.com/kenjis/ci-phpunit-test
9
 */
10
11
class Seeder
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
	private $CI;
14
	protected $db;
15
	protected $dbforge;
16
	protected $seedPath;
17
18
	public function __construct()
19
	{
20
		$this->CI =& get_instance();
21
		$this->CI->load->database();
22
		$this->CI->load->dbforge();
23
		$this->db = $this->CI->db;
24
		$this->dbforge = $this->CI->dbforge;
25
	}
26
27
	/**
28
	 * Run another seeder
29
	 * 
30
	 * @param string $seeder Seeder classname
31
	 */
32
	public function call($seeder)
33
	{
34
		if ($this->seedPath === null)
35
		{
36
			$this->seedPath = APPPATH . 'database/seeds/';
37
		}
38
39
		$file = $this->seedPath . $seeder . '.php';
40
		require_once $file;
41
42
		$obj = new $seeder;
43
		$obj->run();
44
	}
45
46
	/**
47
	 * Set path for seeder files
48
	 * 
49
	 * @param string $path
50
	 */
51
	public function setPath($path)
52
	{
53
		$this->seedPath = rtrim($path, '/').'/';
54
	}
55
56
	public function __get($property)
57
	{
58
		return $this->CI->$property;
59
	}
60
}
61