Esempio n. 1
0
 public static function getCodeLocation($stack_offset = 2, $exception = NULL)
 {
     $stack = $exception ? self::getStackTrace("exception", $exception) : self::getStackTrace();
     //	eliminate this function from the stack
     $location = array_slice($stack, $stack_offset);
     $line = array_shift($location);
     $location = count($location) == 0 ? ltrim(Amslib_Website::web($line["file"]), "/") : array_shift($location);
     $line = isset($line["line"]) ? "@{$line["line"]}" : "";
     $location = is_array($location) && Amslib_Array::hasKeys($location, array("class", "type", "function")) ? $location["class"] . $location["type"] . $location["function"] : $location;
     $location = is_array($location) && Amslib_Array::hasKeys($location, array("file", "function")) ? basename($location["file"]) . "({$location["function"]})" : $location;
     $location = is_array($location) && Amslib_Array::hasKeys($location, "function") ? "{$location["function"]}()" : $location;
     if (is_array($location)) {
         error_log("Debugging error, location of error not available: " . Amslib_Debug::vdump($location));
     }
     $location = is_array($location) ? "__ERROR_unknown_location" : $location;
     return $location . $line;
 }
Esempio n. 2
0
 public function configExtension($name, $array, $object)
 {
     if (!array_key_exists("child", $array)) {
         return;
     }
     $data = $array["attr"];
     if (!isset($data["type"]) || !in_array($data["type"], array("scan", "load"))) {
         $data["type"] = "load";
     }
     foreach (Amslib_Array::valid($array["child"]) as $c) {
         $data[$c["tag"]] = $c["value"];
     }
     //	We require the selector so we know what to search for
     if (!isset($data["selector"])) {
         Amslib_Debug::log("INVALID SELECTOR", $data);
         return false;
     }
     Amslib_Debug::log("extension keys = ", array_keys($data));
     if (Amslib_Array::hasKeys($data, array("plugin", "method"))) {
         //  Just in case an object is included as well
         $data["callback"] = array_key_exists("object", $data) ? array($data['plugin'], $data["object"], $data["method"]) : array($data['plugin'], $data["method"]);
         $data["callback"] = self::getCallback($data["callback"], $this);
     } else {
         if (Amslib_Array::hasKeys($data, array("callback"))) {
             $data["callback"] = self::getCallback($data["callback"], $this);
         } else {
             Amslib_Debug::log("INVALID PLUGIN/METHOD/CALLBACK", $data);
             return false;
         }
     }
     $callback = array("scan" => "addScanSelector", "load" => "addLoadSelector");
     $method = array(get_class($this->source), $callback[$data["type"]]);
     call_user_func($method, $data["selector"], $data["callback"]);
 }
Esempio n. 3
0
 /**
  * 	method:	connect
  *
  * 	Connect to the MYSQL database using various details
  *
  * 	todo:
  * 		-	Need to move the database details to somewhere more
  * 			secure (like inside the database!! ROFL!! joke, don't do that!!!!)
  */
 public function connect($details = false)
 {
     list($details, $password) = Amslib_Array::valid($this->setConnectionDetails($details)) + array(NULL, NULL);
     $this->disconnect();
     $valid = Amslib_Array::hasKeys($details, array("server", "username", "database", "encoding")) && strlen($password);
     if ($valid) {
         try {
             $dsn = "mysql:dbname={$details["database"]};host={$details["server"]};charset={$details["encoding"]}";
             $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_STATEMENT_CLASS => array('Amslib_Database_Statement', array($this)));
             $this->connection = new PDO($dsn, $details["username"], $password, $options);
             $this->setEncoding($details["encoding"]);
             return $this->isConnected(true);
         } catch (PDOException $e) {
             $this->debug("DATABASE", array("exception" => $e->getMessage(), "data" => $details));
             throw $e;
         }
     } else {
         $this->debug("DATABASE", "connection details were not valid", $details);
     }
     $this->disconnect();
     return false;
 }
Esempio n. 4
0
 /**
  * 	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);
 }