function amslib_autoload_exception($c) { if ($c == __CLASS__) { return false; } $result = false; if (strpos($c, '\\') === false) { $e = new Exception(); $t = $e->getTrace(); if (isset($t[1]) && isset($t[1]["file"])) { $result = Amslib::requireFile(dirname($t[1]["file"]) . "/{$c}.php"); if ($result && !Amslib::autoloaderStatus("exception")) { Amslib_Debug::log("EXCEPTION AUTOLOADER: we loaded the class '{$c}' this is not efficient"); Amslib_Debug::log("EXCEPTION AUTOLOADER: call Amslib::autoloader_exception(true,true) to remove this warning"); } } } return $result; }
/** * method: createObject * * todo: write documentation */ protected function createObject(&$object, $singleton = false, $dieOnError = false) { // invalid requests get returned false if (!$object || empty($object)) { return false; } // existing objects just get returned from their cache if (isset($object["cache"])) { return $object["cache"]; } // otherwise, we go through the process of loading them, first of all, make sure the object file is in the system if (isset($object["file"])) { Amslib::requireFile($object["file"], array("require_once" => true)); } // Create the generic string for all the errors $error = "FATAL ERROR(" . __METHOD__ . ") Could not __ERROR__ for plugin '{$this->name}'<br/>"; // false by default to signal an error in creation $cache = false; if (isset($object["value"]) && class_exists($object["value"])) { if ($singleton) { if (method_exists($object["value"], "getInstance")) { $cache = call_user_func(array($object["value"], "getInstance")); } else { // your object was not a compatible singleton, we need to find the getInstance method $message = str_replace("__ERROR__", "find the getInstance method in the API object '{$object["value"]}'", $error); Amslib_Debug::log($message); die($message); } } else { // yay! we have a proper object $cache = new $object["value"](); } } else { if ($dieOnError) { // The class was not found, we cannot continue // NOTE: I am not sure why we cannot continue here, it might not be something // critical and yet we're stopping everything // NOTE: It's hard to die here because perhaps there is a better way of not dying everytime an object // which is requested that doesn't exist won't load, we immediately kill everything // perhaps a nicer way would be to notify the system of the error, but build better code // so that if an object doesnt exist, we could use a dummy object with a __call interface // and register all the methods as returning false, therefore hiding the missing object // but not killing the process, but handling all the failures which happen and properly written code // which respects the methods that return false, will keep functioning but failing to operating, // although they will not crash $error = str_replace("__ERROR__", "find class using configuration " . Amslib_Debug::dump($object) . "'", $error); Amslib_Debug::log("stack_trace", $error, $object); die($error); } } if ($cache) { $object["cache"] = $cache; } return $cache; }
/** * method: renderView * * todo: write documentation */ public function renderView($view, $params = NULL) { if (!is_string($view) || !isset($this->view[$view])) { Amslib_Debug::log("stack_trace", "Unable to find view in structure", $this->getName(), $view, $this->view); return ""; } if ($params == "inherit") { $params = $this->getViewParam(); } if (!is_array($params)) { $params = array(); } $global = $this->getViewParam(NULL, NULL, true); if (!empty($global)) { $params = array_merge($global, $params); } // Set the parameters that were used for rendering this view, // useful when wanting to pass along to various child views. if (!empty($params)) { $this->setViewParam($params); } if (Amslib_Array::hasKeys($params, array("api", "wt", "ct"))) { Amslib_Debug::log("ERROR: A reserved key was detected in this array,\n\t\t\t\t\tthis might result in subtle errors, please remove 'api', 'wt' or 'ct',\n\t\t\t\t\tthey are used by the framework to provide access to the api object, and the translators"); } $params["api"] = $this; // FIXME: what if multiple translators of the same type are defined? they would start to clash $params["wt"] = $this->getTranslator("website"); $params["ct"] = $this->getTranslator("content"); return Amslib::requireFile($this->view[$view], $params, true); }