Packages

  • Nette
    • Application
      • Application\Diagnostics
      • Application\Responses
      • Application\Routers
      • Application\UI
    • Caching
      • Caching\Storages
    • ComponentModel
    • Config
    • Database
      • Database\Diagnostics
      • Database\Drivers
      • Database\Reflection
      • Database\Table
    • DI
    • Diagnostics
    • Forms
      • Forms\Controls
      • Forms\Rendering
    • Http
    • Iterators
    • Latte
      • Latte\Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • Arrays
  • CriticalSection
  • Finder
  • Html
  • Json
  • LimitedScope
  • MimeTypeDetector
  • Neon
  • Paginator
  • Strings

Exceptions

  • JsonException
  • NeonException
  • RegexpException
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  * @package Nette\Utils
11:  */
12: 
13: 
14: 
15: /**
16:  * Limited scope for PHP code evaluation and script including.
17:  *
18:  * @author     David Grudl
19:  * @package Nette\Utils
20:  */
21: final class LimitedScope
22: {
23:     private static $vars;
24: 
25:     /**
26:      * Static class - cannot be instantiated.
27:      */
28:     final public function __construct()
29:     {
30:         throw new StaticClassException;
31:     }
32: 
33: 
34: 
35:     /**
36:      * Evaluates code in limited scope.
37:      * @param  string  PHP code
38:      * @param  array   local variables
39:      * @return mixed   the return value of the evaluated code
40:      */
41:     public static function evaluate(/*$code, array $vars = NULL*/)
42:     {
43:         if (func_num_args() > 1) {
44:             self::$vars = func_get_arg(1);
45:             extract(self::$vars);
46:         }
47:         $res = eval('?>' . func_get_arg(0));
48:         if ($res === FALSE && ($error = error_get_last()) && $error['type'] === E_PARSE) {
49:             throw new FatalErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'], NULL);
50:         }
51:         return $res;
52:     }
53: 
54: 
55: 
56:     /**
57:      * Includes script in a limited scope.
58:      * @param  string  file to include
59:      * @param  array   local variables
60:      * @return mixed   the return value of the included file
61:      */
62:     public static function load(/*$file, array $vars = NULL*/)
63:     {
64:         if (func_num_args() > 1) {
65:             self::$vars = func_get_arg(1);
66:             extract(self::$vars);
67:         }
68:         return include func_get_arg(0);
69:     }
70: 
71: }
72: 
Nette Framework 2.0beta1 (for PHP 5.2) API API documentation generated by ApiGen 2.3.0