2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * This class is responsible for creating Node objects
6 * @package PhpMyAdmin-navigation
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/navigation/Nodes/Node.class.php';
15 * Node factory - instantiates Node objects or objects derived from the Node class
17 * @package PhpMyAdmin-Navigation
22 * @var string $_path A template for generating paths to files
23 * that contain various Node classes
26 private static $_path = 'libraries/navigation/Nodes/%s.class.php';
28 * Sanitizes the name of a Node class
30 * @param string $class The class name to be sanitized
34 private static function _sanitizeClass($class)
36 if ($class !== 'Node' && ! preg_match('@^Node_\w+(_\w+)?$@', $class)) {
40 /* l10n: The word "Node" must not be translated here */
41 __('Invalid class name "%1$s", using default of "Node"'),
47 return self
::_checkFile($class);
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
58 private static function _checkFile($class)
60 $path = sprintf(self
::$_path, $class);
61 if (! is_readable($path)) {
65 __('Could not include class "%1$s", file "%2$s" not found'),
67 'Nodes/' . $class . '.class.php'
75 * Instantiates a Node object
77 * @param string $class The name of the class to instantiate
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
85 public static function getInstance(
91 $class = self
::_sanitizeClass($class);
92 include_once sprintf(self
::$_path, $class);
93 return new $class($name, $type, $is_group);