/** * Finds the module that would contain a class and loads it. * * @param string $className The full class name. This doesn't deal with * namespaces. */ public function loadClass($className) { $parts = explode('_', $className); if ($parts[0] !== $this->baseModule) { return; } for ($i = count($parts); $i > 0; $i--) { $module = $i === 1 ? $parts[0] : implode('_', array_slice($parts, 0, $i)); if (array_key_exists($module, $this->overrides)) { $filename = $this->overrides[$module]; } else { if ($i > 1) { $filename = $this->baseDir . ($i === 2 ? $parts[1] : implode('/', array_slice($parts, 1, $i - 1))) . '.php'; } else { // We don't try to load the base module unless they set an // override. break; } } if (is_file($filename)) { if ($module === 'Tuffy') { // a bit of special casing to avoid circular requires require $filename; return; } Tuffy::debug("Loading Class", "{$className} from {$filename}", 0, 3); require $filename; $this->postLoad($module); return; } } }
/** * Executes the statement. * * @param array $params Parameters to bind before executing the statement. * You can use this to simplify running several sequential inserts. */ public function execute($params = NULL) { $debug = Tuffy::setting('debug'); if ($params) { $this->bind($params); } if ($debug) { ob_start(); $this->debugDumpParams(); $idx = Tuffy::debug("Query", ob_get_clean()); } parent::execute(); if ($debug) { Tuffy_Debug::completeEvent($idx); } }
/** * Sends email using the PHP standard mail() function. (This assumes your * system administrator has configured it properly.) * * @param string $from The email address to send the message from. * @param string $to The email address(es) to send the message to. * @param string $replyTo The email address to which replies should be * delivered. * @param string $subject The subject of the message. * @param string $body The content of the message. */ public static function mail($from, $to, $replyTo, $subject, $body) { $headers = "From: {$from}\r\nReply-To: {$replyTo}"; $sendmailParams = "-f" . $from; Tuffy::debug("Mail", "To: {$to}\r\n" . "From: {$from}\r\n" . "Reply-To: {$replyTo}\r\n" . "Subject: {$subject}\r\n\r\n" . $body); mail($to, $subject, $body, $headers, $sendmailParams); }
Tuffy::configure($GLOBALS['tuffySettings']); } if (!Tuffy::setting('appName')) { die("You must define the appName setting."); } // 6. Configure the environment. $tuffyTimezone = Tuffy::setting('timezone'); if ($tuffyTimezone !== NULL) { date_default_timezone_set(Tuffy::setting('timezone')); } unset($tuffyTimezone); if (Tuffy::setting('useSessions')) { session_start(); if (Tuffy::setting('debug')) { Tuffy_Debug::restoreLogFromSession(); Tuffy::debug("Session " . session_id(), $_SESSION); } } if ($libraryPath = Tuffy::setting('libraryPath')) { $tuffyAppLoader = new Tuffy_Loader(Tuffy::setting('appName'), Tuffy_Util::interpretPath($libraryPath)); $tuffyAppLoader->register(); } unset($libraryPath); foreach (Tuffy::setting('initializers', array()) as $init) { call_user_func($init); } // 7. Here are a couple of completely non-namespaced utility functions // that are just too useful not to have. /** * If the $key exists in $array, returns the value stored therein. Otherwise, * returns $default.