1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\core; |
3
|
|
|
|
4
|
|
|
use EventEspresso\core\libraries\iframe_display\Iframe; |
5
|
|
|
|
6
|
|
|
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
7
|
|
|
exit( 'No direct script access allowed' ); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Factory |
14
|
|
|
* creates instantiations of classes |
15
|
|
|
* |
16
|
|
|
* @package Event Espresso |
17
|
|
|
* @subpackage core |
18
|
|
|
* @author Brent Christensen |
19
|
|
|
* @since 4.9.0 |
20
|
|
|
*/ |
21
|
|
|
class Factory { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $class_name |
25
|
|
|
* @param array $arguments |
26
|
|
|
* @return mixed|null |
27
|
|
|
* @throws \EE_Error |
28
|
|
|
*/ |
29
|
|
|
public static function create( $class_name, $arguments = array() ) { |
30
|
|
|
if ( empty( $class_name ) ) { |
31
|
|
|
throw new \EE_Error( |
32
|
|
|
__( 'You must provide a class name in order to instantiate it.', 'event_espresso' ) |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
// if ( ! class_exists( $class_name ) ) { |
36
|
|
|
// throw new \EE_Error( |
37
|
|
|
// sprintf( |
38
|
|
|
// __( 'The "%1$s" class was not found. Please include the correct file or set an autoloader for it', 'event_espresso' ), |
39
|
|
|
// $class_name |
40
|
|
|
// ) |
41
|
|
|
// ); |
42
|
|
|
// } |
43
|
|
|
$object = null; |
|
|
|
|
44
|
|
|
switch ( $class_name ) { |
45
|
|
|
|
46
|
|
|
case 'EE_Request' : |
47
|
|
|
$object = new \EE_Request( $_GET, $_POST, $_COOKIE ); |
48
|
|
|
break; |
49
|
|
|
|
50
|
|
|
case 'Iframe' : |
51
|
|
|
$title = isset( $arguments['title'] ) ? $arguments['title'] : null; |
52
|
|
|
$content = isset( $arguments['content'] ) ? $arguments['content'] : null; |
53
|
|
|
$object = new Iframe( $title, $content ); |
54
|
|
|
break; |
55
|
|
|
|
56
|
|
|
default : |
57
|
|
|
$object = new $class_name( $arguments ); |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// if ( ! $object instanceof $class_name ) { |
62
|
|
|
// throw new \EE_Error( |
63
|
|
|
// sprintf( |
64
|
|
|
// __( |
65
|
|
|
// 'An error occurred during class instantiation and the requested object could not be created. The result was: %1$s %2$s', |
66
|
|
|
// 'event_espresso' |
67
|
|
|
// ), |
68
|
|
|
// '<br />', |
69
|
|
|
// var_export( $object, true ) |
70
|
|
|
// ) |
71
|
|
|
// ); |
72
|
|
|
// } |
73
|
|
|
return $object; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
// End of file Factory.php |
78
|
|
|
// Location: /Factory.php |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.