Packages

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • NAutoLoader
  • NLimitedScope
  • NNetteLoader
  • NRobotLoader
  • Overview
  • Package
  • Class
  • Tree
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  *
 6:  * Copyright (c) 2004 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\Loaders
11:  */
12: 
13: 
14: 
15: /**
16:  * Limited scope for PHP code evaluation and script including.
17:  *
18:  * @author     David Grudl
19:  * @package Nette\Loaders
20:  */
21: final class NLimitedScope
22: {
23:     private static $vars;
24: 
25:     /**
26:      * Static class - cannot be instantiated.
27:      */
28:     final public function __construct()
29:     {
30:         throw new LogicException("Cannot instantiate static class " . get_class($this));
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:         return eval('?>' . func_get_arg(0));
48:     }
49: 
50: 
51: 
52:     /**
53:      * Includes script in a limited scope.
54:      * @param  string  file to include
55:      * @param  array   local variables or TRUE meaning include once
56:      * @return mixed   the return value of the included file
57:      */
58:     public static function load(/*$file, array $vars = NULL*/)
59:     {
60:         if (func_num_args() > 1) {
61:             self::$vars = func_get_arg(1);
62:             if (self::$vars === TRUE) {
63:                 return include_once func_get_arg(0);
64:             }
65:             extract(self::$vars);
66:         }
67:         return include func_get_arg(0);
68:     }
69: 
70: }
71: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0