Source for file LimitedScope.php

Documentation is available at LimitedScope.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette\Loaders
  11. 11:  */
  12. 12:  
  13. 13:  
  14. 14:  
  15. 15: /**
  16. 16:  * Limited scope for PHP code evaluation and script including.
  17. 17:  *
  18. 18:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  19. 19:  * @package    Nette\Loaders
  20. 20:  */
  21. 21: final class LimitedScope
  22. 22: {
  23. 23:     private static $vars;
  24. 24:  
  25. 25:     /**
  26. 26:      * Static class - cannot be instantiated.
  27. 27:      */
  28. 28:     final public function __construct()
  29. 29:     {
  30. 30:         throw new LogicException("Cannot instantiate static class " get_class($this));
  31. 31:     }
  32. 32:  
  33. 33:  
  34. 34:  
  35. 35:     /**
  36. 36:      * Evaluates code in limited scope.
  37. 37:      * @param  string  PHP code
  38. 38:      * @param  array   local variables
  39. 39:      * @return mixed   the return value of the evaluated code
  40. 40:      */
  41. 41:     public static function evaluate(/*$code, array $vars = NULL*/)
  42. 42:     {
  43. 43:         if (func_num_args(1{
  44. 44:             extract(func_get_arg(1));
  45. 45:             
  46. 46:             
  47. 47:         }
  48. 48:         return eval('?>' func_get_arg(0));
  49. 49:     }
  50. 50:  
  51. 51:  
  52. 52:  
  53. 53:     /**
  54. 54:      * Includes script in a limited scope.
  55. 55:      * @param  string  file to include
  56. 56:      * @param  array   local variables
  57. 57:      * @return mixed   the return value of the included file
  58. 58:      */
  59. 59:     public static function load(/*$file, array $vars = NULL*/)
  60. 60:     {
  61. 61:         if (func_num_args(1{
  62. 62:             extract(func_get_arg(1));
  63. 63:             
  64. 64:             
  65. 65:         }
  66. 66:         return include func_get_arg(0);
  67. 67:     }
  68. 68:  
  69. 69: }