Context.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /** @package verysimple::HTTP */
  3. /**
  4. * Context Persistance Storage
  5. *
  6. * The context provides an object that can be uses globally for
  7. * dependency injection when passing information that should be
  8. * available to an entire application
  9. *
  10. * @package verysimple::HTTP
  11. * @author VerySimple Inc.
  12. * @copyright 1997-2007 VerySimple, Inc. http://www.verysimple.com
  13. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  14. * @version 1.0
  15. */
  16. class Context
  17. {
  18. public $GUID;
  19. /**
  20. * Constructor initializes the session
  21. */
  22. public function __construct()
  23. {
  24. if (session_id() == '')
  25. {
  26. @session_start();
  27. }
  28. }
  29. /**
  30. * Returns a persisted object or value
  31. *
  32. * @param var
  33. * @param default value (default = null)
  34. * @return value of var (or default)
  35. */
  36. public function Get($var,$default = null)
  37. {
  38. return (isset($_SESSION[$this->GUID . "_" . $var])) ? unserialize($_SESSION[$this->GUID . "_" . $var]) : null;
  39. }
  40. /**
  41. * Persists an object or value
  42. *
  43. * @access public
  44. * @param var
  45. * @param value
  46. * @return object || null
  47. */
  48. public function Set($var,$val)
  49. {
  50. $_SESSION[$this->GUID . "_" . $var] = serialize($val);
  51. }
  52. }
  53. ?>