public function __construct($url = NULL, $query = NULL) { if ($query) { $url = $url . '?' . Tuffy_Util::buildQuery($query); } $this->ch = curl_init($url); }
/** * Expands a URL. Absolute URLs, and URLs with a leading slash, * are returned as is, but relative URLs are treated as relative to * REQUEST_PREFIX instead of the current directory. * * @param string $target The URL to redirect to. * @param array $params GET parameters to include in the built URL's * query string. * @param boolean $forceHTTPS If this is TRUE, the generated URL will * always begin with https://. Otherwise, it will be the same as the * current request's scheme. */ public static function url($target, $params = NULL, $forceHTTPS = FALSE) { $scheme = $forceHTTPS ? 'https://' : REQUEST_SCHEME; if ($target === 'index') { $base = $scheme . REQUEST_HOST . REQUEST_PREFIX; } else { if (parse_url($target, PHP_URL_SCHEME) !== NULL) { $base = $target; } else { if ($target[0] === '/') { $base = $scheme . REQUEST_HOST . $target; } else { $base = $scheme . REQUEST_HOST . REQUEST_PREFIX . $target; } } } return $params === NULL ? $base : $base . '?' . Tuffy_Util::buildQuery($params, TRUE); }
} // 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. * * @param array $array The array to check. * @param mixed $key The key to search for. * @param mixed $default The value to return if the key does not exist.
/** * Creates the default template loader. It will load templates from the * directory indicated by the `template.path` setting if defined, * otherwise it will use `TUFFY_APP_PATH/templates`. */ public static function getDefaultLoader() { $templatePath = Tuffy_Util::interpretPath(Tuffy::setting('template.path', 'templates')); return new Twig_Loader_Filesystem($templatePath); }