FOF30\Utils\Buffer::canRegisterWrapper PHP Method

canRegisterWrapper() public static method

Should I register the fof:// stream wrapper
public static canRegisterWrapper ( ) : boolean
return boolean True if the stream wrapper can be registered
    public static function canRegisterWrapper()
    {
        if (is_null(static::$canRegisterWrapper)) {
            static::$canRegisterWrapper = false;
            // Check for Suhosin
            $hasSuhosin = false;
            if (function_exists('extension_loaded')) {
                $hasSuhosin = extension_loaded('suhosin');
            } else {
                $hasSuhosin = -1;
                // Can't detect
            }
            if ($hasSuhosin !== true) {
                $hasSuhosin = defined('SUHOSIN_PATCH') ? true : -1;
            }
            if ($hasSuhosin === -1) {
                if (function_exists('ini_get')) {
                    $hasSuhosin = false;
                    $maxIdLength = ini_get('suhosin.session.max_id_length');
                    if ($maxIdLength !== false) {
                        $hasSuhosin = ini_get('suhosin.session.max_id_length') !== '';
                    }
                }
            }
            // If we can't detect whether Suhosin is installed we won't proceed to prevent a White Screen of Death
            if ($hasSuhosin === -1) {
                return false;
            }
            // If Suhosin is installed but ini_get is not available we won't proceed to prevent a WSoD
            if ($hasSuhosin && !function_exists('ini_get')) {
                return false;
            }
            // If Suhosin is installed check if fof:// is whitelisted
            if ($hasSuhosin) {
                $whiteList = ini_get('suhosin.executor.include.whitelist');
                // Nothing in the whitelist? I can't go on, sorry.
                if (empty($whiteList)) {
                    return false;
                }
                $whiteList = explode(',', $whiteList);
                $whiteList = array_map(function ($x) {
                    return trim($x);
                }, $whiteList);
                if (!in_array('fof://', $whiteList)) {
                    return false;
                }
            }
            static::$canRegisterWrapper = true;
        }
        return static::$canRegisterWrapper;
    }

Usage Example

Beispiel #1
0
 /**
  * Get the evaluated contents of the view template.
  *
  * @param   string  $path         The path to the view template
  * @param   array   $forceParams  Any additional information to pass to the view template engine
  *
  * @return  array  Content evaluation information
  */
 public function get($path, array $forceParams = array())
 {
     // If it's cached return the path to the cached file's path
     if ($this->isCached($path)) {
         return array('type' => 'path', 'content' => $this->getCachePath($path));
     }
     // Not cached or caching not really allowed. Compile it and cache it.
     $content = $this->compile($path, $forceParams);
     $cachePath = $this->putToCache($path, $content);
     // If we could cache it, return the cached file's path
     if ($cachePath !== false) {
         return array('type' => 'path', 'content' => $cachePath);
     }
     // We could not write to the cache. Hm, can I use a stream wrapper?
     $canUseStreams = Buffer::canRegisterWrapper();
     if ($canUseStreams) {
         $id = $this->getIdentifier($path);
         $streamPath = 'fof://' . $this->view->getContainer()->componentName . '/compiled_templates/' . $id . '.php';
         return array('type' => 'path', 'content' => $streamPath);
     }
     // I couldn't use a stream wrapper. I have to give up.
     throw new PossiblySuhosin();
 }