Namespaces

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

Classes

  • AutoLoader
  • LimitedScope
  • NetteLoader
  • RobotLoader
  • Overview
  • Namespace
  • 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:  */
11: 
12: namespace Nette\Loaders;
13: 
14: use Nette;
15: 
16: 
17: 
18: /**
19:  * Limited scope for PHP code evaluation and script including.
20:  *
21:  * @author     David Grudl
22:  */
23: final class LimitedScope
24: {
25:     private static $vars;
26: 
27:     /**
28:      * Static class - cannot be instantiated.
29:      */
30:     final public function __construct()
31:     {
32:         throw new \LogicException("Cannot instantiate static class " . get_class($this));
33:     }
34: 
35: 
36: 
37:     /**
38:      * Evaluates code in limited scope.
39:      * @param  string  PHP code
40:      * @param  array   local variables
41:      * @return mixed   the return value of the evaluated code
42:      */
43:     public static function evaluate(/*$code, array $vars = NULL*/)
44:     {
45:         if (func_num_args() > 1) {
46:             self::$vars = func_get_arg(1);
47:             extract(self::$vars);
48:         }
49:         return eval('?>' . func_get_arg(0));
50:     }
51: 
52: 
53: 
54:     /**
55:      * Includes script in a limited scope.
56:      * @param  string  file to include
57:      * @param  array   local variables or TRUE meaning include once
58:      * @return mixed   the return value of the included file
59:      */
60:     public static function load(/*$file, array $vars = NULL*/)
61:     {
62:         if (func_num_args() > 1) {
63:             self::$vars = func_get_arg(1);
64:             if (self::$vars === TRUE) {
65:                 return include_once func_get_arg(0);
66:             }
67:             extract(self::$vars);
68:         }
69:         return include func_get_arg(0);
70:     }
71: 
72: }
73: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0