Vendor::getVendor()   B
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.439
c 0
b 0
f 0
cc 6
eloc 15
nc 5
nop 3
1
<?php
2
3
/**
4
 * Vendor manage in factory
5
 *
6
 * @category  	lib
7
 * @author    	Judicaël Paquet <[email protected]>
8
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
9
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
10
 * @version   	Release: 2.0.0
11
 * @filesource	https://github.com/las93/venus2
12
 * @link      	https://github.com/las93
13
 * @since     	2.0.0
14
 */
15
namespace Venus\lib;
16
17
use \Venus\core\Config as Config;
18
19
/**
20
 * This class manage the vendor class
21
 *
22
 * @category  	lib
23
 * @author    	Judicaël Paquet <[email protected]>
24
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
25
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
26
 * @version   	Release: 2.0.0
27
 * @filesource	https://github.com/las93/venus2
28
 * @link      	https://github.com/las93
29
 * @since     	2.0.0
30
 */
31
class Vendor
32
{
33
    /**
34
     * cache of the vendor available
35
     * 
36
     * @access private
37
     * @var    array
38
     */
39
    private static $_aCache = null;
0 ignored issues
show
Unused Code introduced by
The property $_aCache is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
    
41
	/**
42
	 * constructor - factory
43
	 * To call a specific vendor, you have to call this class like this :
44
	 * new \Venus\lib\Vendor('Apollina\Template');
45
	 * new \Venus\lib\Vendor('Attila\Orm');
46
	 * new \Venus\lib\Vendor('Mobile_Detect');
47
	 *
48
	 * @access public
49
	 * @param  string $sVendorName
50
	 * @param  mixed $mParam
51
	 * @param  mixed $mParam2
52
	 * @return bool|object
53
	 */
54
55
	public static function getVendor(string $sVendorName, $mParam = null, $mParam2 = null)
56
	{
57
	    if ($sVendorName === 'Apollina\Template') { 
58
59
	        $oApollina = new $sVendorName($mParam, str_replace('lib', '', __DIR__), 
60
	            str_replace('bundles'.DIRECTORY_SEPARATOR.'lib', CACHE_DIR, __DIR__), $mParam2);
61
62
	        return $oApollina->addFunctionPath(__DIR__.DIRECTORY_SEPARATOR.'Functions', '\Venus\lib\Functions\\');
63
	    }
64
	    else if ($sVendorName === 'Attila\Orm') {
65
66
	        $oDbConfig = Config::get('Db')->configuration;
67
68
	        return new $sVendorName($oDbConfig->db, $oDbConfig->type, $oDbConfig->host, $oDbConfig->user, $oDbConfig->password, 
69
	            $oDbConfig->db);
70
	    }
71
	    else if (isset($mParam) && isset($mParam2)) { 
72
	        
73
	        return new $sVendorName($mParam, $mParam2);
74
	    }
75
	    else if (isset($mParam)) { 
76
	        
77
	        return new $sVendorName($mParam);
78
	    }
79
	    else { 
80
	        
81
	        return new $sVendorName;
82
	    }
83
	}
84
}
85