Example #1
0
 public function postStaticServe(StaticServer $server)
 {
     $request_time = microtime(true) - COWL_START_TIME;
     $this->log("static_serve", sprintf("took %01.6f s. %s", $request_time, $server->getPath()));
     // Logging static file requests is optional since it floods the logs
     if (Current::$config->get('plugins.logging.log_static_files')) {
         $this->save();
     }
 }
Example #2
0
 public function __construct()
 {
     Cowl::timer('cowl init');
     @session_start();
     // I know that the @-notation is frowned upon, but adding it to session_start saves us unnecessary warnings
     Cache::setDir(COWL_CACHE_DIR);
     Current::initialize(COWL_DIR);
     if (COWL_CLI) {
         $this->parseCLIPath();
     } else {
         $this->parseRequestPath();
     }
     Cowl::timer('cowl set defaults');
     // Get and set all directories for various things.
     list($commands_dir, $model_dir, $validators_dir, $library_dir, $view_dir, $helpers_dir, $helpers_app_dir, $drivers_dir, $app_dir, $view_layout_dir, $validator_error_messages, $lang) = Current::$config->gets('paths.commands', 'paths.model', 'paths.validators', 'paths.library', 'paths.view', 'paths.helpers', 'paths.helpers_app', 'paths.drivers', 'paths.app', 'paths.layouts', 'paths.validator_messages', 'lang');
     Controller::setDir($commands_dir);
     DataMapper::setMappersDir($model_dir);
     DataMapper::setObjectsDir($model_dir);
     Validator::setPath($validators_dir);
     Validator::loadStrings($validator_error_messages, $lang);
     Templater::setBaseDir($view_dir);
     Templater::setLayoutDir($view_layout_dir);
     Library::setPath($library_dir);
     Helpers::setPath($helpers_dir);
     Helpers::setAppPath($helpers_app_dir);
     Database::setPath($drivers_dir);
     StaticServer::setDir($app_dir);
     Cowl::timerEnd('cowl set defaults');
     Cowl::timer('cowl plugins load');
     Current::$plugins = new Plugins();
     Cowl::timerEnd('cowl plugins load');
     // Load default helper
     Helpers::load('standard', 'form');
     Cowl::timerEnd('cowl init');
 }
Example #3
0
 public function prePathParse(Controller $controller, StaticServer $server)
 {
     try {
         $this->path = $controller->getPath();
         // Transform routes base on host preferences
         $host_routes = Current::$config->get('plugins.routing.host_routes');
         if (count($host_routes)) {
             $host = $_SERVER['HTTP_HOST'];
             foreach ($host_routes as $search => $replace) {
                 if (preg_match($search, $host)) {
                     $this->applyTransform($replace);
                 }
             }
         }
         // Transform normal routes
         $routes = Current::$config->get('plugins.routing.routes');
         if (count($routes)) {
             $this->applyTransform($routes);
         }
         $controller->setPath($this->path);
         $server->setPath($this->path);
     } catch (RegistryException $e) {
     }
 }
Example #4
0
 public function preStaticServe(StaticServer $server)
 {
     // If file was a package file, don't do anything
     if ($this->is_package) {
         return;
     }
     // If the type isn't css we don't touch it
     if ($server->getType() != 'css') {
         return;
     }
     $path = $server->getPath();
     $cache_path = $this->cache . '.' . preg_replace('#\\W#', '', $path);
     // Compile and cache CSS file.
     $cache = new FileCache($cache_path, $path);
     $cache->setExtension('css');
     if ($cache->isOutDated() || $this->force_update) {
         $contents = file_get_contents($path);
         $compiler = new CSSCompiler($contents);
         $updated = $compiler->compile();
         $cache->update($updated);
     }
     // Change the path to be the cached file instead
     $server->setPath($cache->getFile());
 }
Example #5
0
 public static function setDir($dir)
 {
     self::$files_dir = $dir;
 }
Example #6
0
 public function prePathParse(Controller $controller, StaticServer $server)
 {
     $path = strtolower($server->getPath());
     $url_path = COWL_BASE . $this->packaged_dir;
     // Path begins with release path, then we build it if need be
     if (strncmp($path, $url_path, strlen($url_path)) !== 0) {
         return;
     }
     // Get package name from request path
     $package = preg_replace('#\\.js$#', '', substr($path, strlen($url_path)));
     $filepath = $this->buildPackage($package);
     // No package here
     if (!$filepath) {
         return;
     }
     $server->setPath($filepath);
     $controller->setPath($filepath);
     $server->lockPath();
     $this->is_package = true;
 }