Пример #1
0
 /**
  * Configure the output handler. This will find the most suitable output
  * handler based on the request, and set the object's handler accordingly.
  * If none are found, defaults are used.
  *
  * @param string $param  The output handler parameter
  * @param string $default  The default output handler
  * @param array $request_params  Pointer to request parameters array
  * @return bool
  */
 public function configure_handler($param, $default, array &$request_params)
 {
     $index = \veneer\util::header_to_index($param);
     if (array_key_exists($index, $_SERVER)) {
         $class = sprintf('\\veneer\\output\\handler\\%s', $_SERVER[$index]);
         $this->set_output_handler($_SERVER[$index]);
     }
     if (is_null($this->get_output_handler())) {
         foreach ($request_params as $name => $value) {
             if ($name == $param) {
                 $this->set_output_handler($value);
                 unset($request_params[$name]);
             }
         }
     }
     if (is_null($this->get_output_handler())) {
         $this->set_output_handler($default);
     }
 }
Пример #2
0
 /**
  * Includes the socket listener class and instantiates it, creating an HTTP
  * server instance that can serve requests to the run() method.
  *
  * @param string $bind_addr  The inet address to bind to
  * @param integer $bind_port  The TCP port to bind on
  * @return bool
  */
 public static function listen($bind_addr = '0.0.0.0', $bind_port = '8080')
 {
     require_once \veneer\util::path_join('http', 'server.php');
     require_once \veneer\util::path_join('http', 'request.php');
     new \veneer\http\server($bind_addr, $bind_port);
 }
Пример #3
0
 /**
  * Parse through the request and evaluate raw HTTP header data. This function
  * will populate the PHP server environment the way one would normally expect
  * it to be via mod_php or FastCGI.
  *
  * @param string $request  An associative array containing request data
  * @return bool
  */
 public function set_environment($request)
 {
     if ($request['method'] == 'GET') {
         global $_GET;
         $_GET = $request['params'];
     } else {
         if ($request['method'] == 'PUT' || $request['method'] == 'POST') {
             global $_POST;
             $_POST = $request['params'];
         }
     }
     global $_SERVER;
     $_SERVER['REQUEST_METHOD'] = $request['method'];
     $_SERVER['REQUEST_URI'] = $request['uri'];
     $_SERVER['SERVER_PROTOCOL'] = $request['protocol'];
     $_SERVER['HTTP_HOST'] = $request['http_host'] . ':' . $request['server_port'];
     $_SERVER['SERVER_PORT'] = $request['server_port'];
     $_SERVER['REMOTE_ADDR'] = $request['remote_addr'];
     $_SERVER['REMOTE_PORT'] = $request['remote_port'];
     foreach ($request['headers'] as $key => $val) {
         $index = \veneer\util::header_to_index($key);
         $_SERVER[$index] = $val;
     }
     return true;
 }
Пример #4
0
 public function test_version_munger()
 {
     $this->assertEquals('v5.9', \veneer\util::version('number', 'v5_9'));
     $this->assertEquals('v5_9', \veneer\util::version('class', 'v5.9'));
     $this->assertFalse(\veneer\util::version('oogabooga', 'v5.9'));
 }
Пример #5
0
<?php

/**
 * veneer - An Experimental API Framework for PHP
 *
 * @author     Ryan Uber <*****@*****.**>
 * @copyright  Ryan Uber <*****@*****.**>
 * @link       https://github.com/ryanuber/veneer
 * @license    http://opensource.org/licenses/MIT
 * @package    veneer
 * @category   api
 */
namespace veneer;

/**
 * Require various framework components in the proper order. These calls
 * will only load in classes, and won't actually execute anything. This
 * is intended to make using the framework simple for a developer - simply
 * include this file, then begin using veneer.
 */
require_once 'util.php';
\veneer\util::include_dir('exception');
require_once 'output.php';
\veneer\util::include_dir('output');
\veneer\util::include_dir(\veneer\util::path_join('output', 'handler'));
require_once \veneer\util::path_join('http', 'response.php');
require_once 'call.php';
require_once 'app.php';
require_once 'router.php';