private static function doInstantiate($className) { if (!ClassCache::exists($className)) { throw new SingletonException("Cannot create singleton for class {$className}: class does not exist."); } $name = new $className(); self::$instances[$className] = $name; }
public static function get($className) { if (!ClassCache::exists($className)) { throw new NoSuchBeanException($className); } if (self::isRequestBean($className)) { return self::getOrCreateRequestBean($className); } if (self::isSessionBean($className)) { return self::getOrCreateSessionBean($className); } if (self::isApplicationBean($className)) { return self::getOrCreateApplicationBean($className); } throw new NoSuchBeanException($className); }
private function parseNode(XmlElement $node) { $className = ucfirst($node->getName()); if (!ClassCache::exists($className)) { $instance = new HtmlComponent($node->getName(), $node->getText(), $node->getAttributes()); } else { if (!ClassUtil::isSubclassOf($className, "Component")) { throw new ComponentNotExistsException($className); } $instance = new $className(); foreach ($node->getAttributes() as $attrName => $attrValue) { $setterName = "set" . ucfirst($attrName); $setter = new ReflectionMethod($instance, $setterName); $setter->invoke($instance, (string) $attrValue); } } foreach ($node->getChildren() as $child) { $instance->addChild($this->parseNode($child)); } return $instance; }
public static function init($classes) { self::$classes = $classes; }
<?php ini_set("display_errors", 1); ini_set("error_reporting", E_ALL); $root = dirname(__FILE__); $directories = array(".", $root); $classes = array(); buildDirectoryList($root, ".", $directories, $classes); ini_set("include_path", implode(PATH_SEPARATOR, $directories)); ClassCache::init($classes); function __autoload($className) { if (in_array(lcfirst($className), array("div", "p", "span", "ul", "ol", "li", "h1", "h2", "h3", "h4", "h5", "h6"))) { require_once "HtmlComponent.php"; } else { $found = stream_resolve_include_path("{$className}.php"); if ($found === false) { $className = strtolower($className); $found = stream_resolve_include_path("{$className}.php"); } if ($found !== false) { include_once "{$className}.php"; } } } function buildDirectoryList($absRoot, $root, &$paths, &$classes) { $dirs = scandir($root); foreach ($dirs as $dir) { $absDir = $root == "." ? $dir : $root . "/" . $dir; $endOfClassName = strpos($dir, ".php");