Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / navigation / NodeFactory.class.php
blob7d8106af988c7ea65949f495ca8d4b26c793c004
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * This class is responsible for creating Node objects
6 * @package PhpMyAdmin-navigation
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/navigation/Nodes/Node.class.php';
14 /**
15 * Node factory - instanciates Node objects or objects derived from the Node class
17 * @package PhpMyAdmin-Navigation
19 class PMA_NodeFactory
21 /**
22 * @var string $_path A template for generating paths to files
23 * that contain various Node classes
24 * @access private
26 private static $_path = 'libraries/navigation/Nodes/%s.class.php';
27 /**
28 * Sanitizes the name of a Node class
30 * @param string $class The class name to be sanitized
32 * @return string
34 private static function _sanitizeClass($class)
36 if ($class !== 'Node' && ! preg_match('@^Node_\w+(_\w+)?$@', $class)) {
37 $class = 'Node';
38 trigger_error(
39 sprintf(
40 /* l10n: The word "Node" must not be translated here */
41 __('Invalid class name "%1$s", using default of "Node"'),
42 $class
44 E_USER_ERROR
47 return self::_checkFile($class);
49 /**
50 * Checks if a file exists for a given class name
51 * Will return the default class name back if the
52 * file for some subclass is not available
54 * @param string $class The class name to check
56 * @return string
58 private static function _checkFile($class)
60 $path = sprintf(self::$_path, $class);
61 if (! is_readable($path)) {
62 $class = 'Node';
63 trigger_error(
64 sprintf(
65 __('Could not include class "%1$s", file "%2$s" not found'),
66 $class,
67 'Nodes/' . $class . '.class.php'
69 E_USER_ERROR
72 return $class;
74 /**
75 * Instanciates a Node object
77 * @param string $class The name of the class to instanciate
78 * @param string $name An identifier for the new node
79 * @param int $type Type of node, may be one of CONTAINER or OBJECT
80 * @param bool $is_group Whether this object has been created
81 * while grouping nodes
83 * @return string
85 public static function getInstance(
86 $class = 'Node',
87 $name = 'default',
88 $type = Node::OBJECT,
89 $is_group = false
90 ) {
91 $class = self::_sanitizeClass($class);
92 include_once sprintf(self::$_path, $class);
93 return new $class($name, $type, $is_group);