Inspekt\Inspekt::makeServerCage PHP Method

makeServerCage() public static method

This utilizes a singleton pattern to get around scoping issues
public static makeServerCage ( string $config_file = null, boolean $strict = true ) : Cage
$config_file string
$strict boolean whether or not to nullify the superglobal array
return Cage
    public static function makeServerCage($config_file = null, $strict = true)
    {
        /**
         * @staticvar $_instance
         */
        static $_instance;
        if (!isset($_instance)) {
            $_instance = Cage::factory($_SERVER, $config_file, '_SERVER', $strict);
        }
        $GLOBALS['HTTP_SERVER_VARS'] = null;
        return $_instance;
    }

Usage Example

<?php

/**
 * Demonstration of:
 * - helper "make*Cage()" methods to create input cage from superglobal
 * - cleanup of HTTP_*_VARS
 * - cage filter methods
 * - "Array Query" method of accessing deep keys in multidim arrays
 */
require_once dirname(__FILE__) . "/../vendor/autoload.php";
use Inspekt\Inspekt;
$serverCage = Inspekt::makeServerCage();
echo "<pre>";
var_dump($serverCage);
echo "</pre>\n";
echo 'Digits:' . $serverCage->getDigits('SERVER_SOFTWARE') . '<p/>';
echo 'Alpha:' . $serverCage->getAlpha('SERVER_SOFTWARE') . '<p/>';
echo 'Alnum:' . $serverCage->getAlnum('SERVER_SOFTWARE') . '<p/>';
echo 'Raw:' . $serverCage->getRaw('SERVER_SOFTWARE') . '<p/>';
echo '<pre>$_SERVER:';
var_dump($_SERVER);
echo "</pre>\n";
echo '<pre>HTTP_SERVER_VARS:';
var_dump($HTTP_SERVER_VARS);
echo "</pre>\n";
var_dump($serverCage->getAlnum('/argv/0'));
All Usage Examples Of Inspekt\Inspekt::makeServerCage