/** * Configures the in-built session. * * A value of 'private' for the cache limiter prevents 'page has expired' * warnings and enables client caching of session pages. However, it should * not be used with POST forms or other content that should not be cached * by the client. The default is to disallow all caching. * * @see http://shiflett.org/articles/how-to-avoid-page-has-expired-warnings * @param string $name session name * @param string $dir directory to save session files in * @param bool $https_only maintain session for https requests only * @param T_Url $url root url for session (if on shared host) * @param string $cache_limiter caching type ('nocache' by default) * @param int $cache_expire cache expiry (mins) */ function __construct($name = 'sid', $dir = null, $https_only = false, T_Url $url = null, $cache_limiter = 'nocache', $cache_expire = 30) { // use cookies only ini_set('session.use_only_cookies', 1); ini_set('session.cookie_httponly', 1); // set session name session_name($name); // setup cookie parameters if ($url) { $path = '/'; if (count($url->getPath()) > 0) { $path .= implode('/', $url->getPath()) . '/'; } $domain = $url->getHost(); // remove any 'www.' prefix subdomain as not relevant, and take off // any port information. if (strncasecmp('www.', $domain, 4) === 0) { $domain = substr($domain, 4); } if (($pos = strpos($domain, ':')) !== false) { $domain = substr($domain, 0, $pos); } if (strpos($domain, '.') === false) { $domain = null; // HTTP protocol doesn't allow setting top level domains like // 'localhost' for security reasons } else { $domain = '.' . $domain; // prefix domain with dot to make sure it is // available on all sub-domains } } else { $path = '/'; $domain = null; } session_set_cookie_params(null, $path, $domain, $https_only); // set save path if ($dir) { session_save_path($dir); } else { $default = new T_File_Dir(T_CACHE_DIR . 'session'); session_save_path($default->__toString()); // it is not safe on shared hosts to store session files in shared // temporary dirs. Therefore by default store session files in // cache directory. } // configure caching session_cache_limiter($cache_limiter); session_cache_expire($cache_expire); }
function testCanRenderGifAsString() { $dir = new T_File_Dir(T_CACHE_DIR . 'test'); $im = new T_Image_Gd(100, 200); $path = $im->convertTo(T_Mime::GIF); /* save to file to get expected */ $im->toFile($dir->__toString(), 'image'); $expect = file_get_contents($dir->__toString() . 'image.gif'); /* get string */ $this->assertSame($expect, $im->__toString()); }
/** * Compiles a template file using a filter. * * @param mixed filter * @return string compiled template filename */ function _compileUsingFilter($filter) { $dir = new T_File_Dir(T_CACHE_DIR . 'template'); $cache = new T_File_Path($dir->__toString(), md5($this->_tpl), 'php'); if (!$cache->exists() || $cache->exists() && $cache->getLastModified() < filemtime($this->_tpl)) { $data = @file_get_contents($this->_tpl); if ($data === false) { $msg = "Error reading template file {$this->_tpl}"; throw new RuntimeException(); } $data = _transform($data, $filter); $swap = new T_File_Swap($cache, 'wb'); $swap->write($data); $swap->close(); } return $cache->__toString(); }