View.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. *
  4. * Cube Framework $Id$ wjGj3bGJdRKfONM6h2P+182eI09uPFKTK7vg7mxxK9w=
  5. *
  6. * @link http://codecu.be/framework
  7. * @copyright Copyright (c) 2014 CodeCube SRL
  8. * @license http://codecu.be/framework/license Commercial License
  9. *
  10. * @version 1.0
  11. */
  12. /**
  13. * view resource management class
  14. */
  15. namespace Cube\Application\Resource;
  16. use Cube\View as ViewObject;
  17. class View extends AbstractResource
  18. {
  19. /**
  20. *
  21. * view object
  22. *
  23. * @var \Cube\View
  24. */
  25. protected $_view;
  26. /**
  27. *
  28. * get view object
  29. *
  30. * @return \Cube\View
  31. */
  32. public function getView()
  33. {
  34. return $this->_view;
  35. }
  36. /**
  37. *
  38. * set view object
  39. *
  40. * @param \Cube\View $view
  41. * @return \Cube\Application\Resource\View
  42. * @throws \InvalidArgumentException
  43. */
  44. public function setView($view)
  45. {
  46. if (!$view instanceof ViewObject) {
  47. throw new \InvalidArgumentException("\Cube\Application\Resource\View requires an object of type \Cube\View");
  48. }
  49. $this->_view = $view;
  50. return $this;
  51. }
  52. /**
  53. *
  54. * initialize view object based on resource settings
  55. *
  56. * @return \Cube\View
  57. */
  58. public function init()
  59. {
  60. if (!$this->_view instanceof ViewObject) {
  61. $view = new ViewObject();
  62. $view->setLayout($this->_options['view']['layout_file'])
  63. ->setLayoutsPath($this->_options['view']['layouts_path'])
  64. ->setViewsPath($this->_options['view']['views_path']);
  65. $this->setView($view);
  66. }
  67. return $this->getView();
  68. }
  69. }