예제 #1
0
<?php

require_once PSU_EXTERNAL_DIR . '/klein/klein.php';
respond(function ($request, $response, $app) {
    $app->config = PSU\Config\Factory::get_config();
    if (false == $app->config->get('cdn', 'enabled', true)) {
        define('PSU_CDN', false);
    }
    $response->psu_lazyload = function ($ids) use($request, $response, $app) {
        if (!is_array($ids)) {
            $ids = array($ids);
        }
        $qs = http_build_query(array('id' => $ids));
        try {
            $json = \PSU::api('backend')->get("user/?{$qs}");
            $people = $json;
        } catch (Exception $e) {
            // nothing...?
            throw $e;
        }
        $response->header('Content-Type', 'application/json');
        $response->json($people);
    };
});
// Load routes for this hostname
$webapp->host()->routes();
respond('404', function ($request, $response, $app) {
    $response->code(404);
    $response->header('Content-Type', 'text/plain');
    echo '404 Not Found';
    error_log(sprintf("404 %s%s", $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']), E_USER_NOTICE);
예제 #2
0
 /**
  * Returns true if we are working on a development server, determined by server's
  * hostname. Will generate an error if run on an unknown host.
  */
 public static function isdev()
 {
     static $isdev = null;
     // don't run function body more than once
     if (null !== $isdev) {
         return $isdev;
     }
     // prefer HOSTNAME in the environment, which will be set in Apache.
     // use `uname -n' as a backup.
     if (isset($_ENV['HOSTNAME'])) {
         $hostname = $_ENV['HOSTNAME'];
     } else {
         $hostname = php_uname("n");
     }
     switch ($hostname) {
         case 'connect.plymouth.edu':
         case 'www.plymouth.edu':
         case 'capricorn.plymouth.edu':
         case 'cursa.plymouth.edu':
         case 'cetus.plymouth.edu':
         case 'chow.plymouth.edu':
         case 'chow':
         case 'choo.plymouth.edu':
         case 'choo':
         case 'perseus.plymouth.edu':
         case 'titan.plymouth.edu':
         case 'titan':
         case 'rigel.plymouth.edu':
             $isdev = false;
             break;
         case 'www.dev.plymouth.edu':
         case 'connect.dev.plymouth.edu':
         case 'setebos':
         case 'setebos.dev.plymouth.edu':
         case 'pollux.plymouth.edu':
         case 'lupus.plymouth.edu':
         case 'titan-vm':
         case 'titan-vm.plymouth.edu':
         case 'uranus':
         case 'uranus.dev.plymouth.edu':
         case 'uranus.plymouth.edu':
             $isdev = true;
             break;
     }
     // Fallback to a value set in config.ini
     if (null === $isdev) {
         $config = PSU\Config\Factory::get_config();
         $isdev = $config->get('environment', 'dev');
         if (null !== $isdev) {
             $isdev = (bool) $isdev;
         }
     }
     // Cannot identify by hostname or config.ini; that's a paddlin'
     if (null === $isdev) {
         trigger_error('HOSTNAME is set to an unknown value: ' . $hostname, E_USER_ERROR);
     }
     return $isdev;
 }