123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- /**
- *
- * Cube Framework $Id$ jeKCHwmclBnGwr/r4M2EA4s5UIsukd1g879OggypTDc=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2014 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.0
- */
- namespace Cube\Navigation\Page;
- use Cube\Controller\Front;
- class Mvc extends AbstractPage
- {
- /**
- *
- * page module
- *
- * @var string
- */
- protected $_module;
- /**
- *
- * page controller
- *
- * @var string
- */
- protected $_controller;
- /**
- *
- * page action
- *
- * @var string
- */
- protected $_action;
- /**
- *
- * page params
- *
- * @var array
- */
- protected $_params = array();
- /**
- *
- * get page module
- *
- * @return string
- */
- public function getModule()
- {
- return $this->_module;
- }
- /**
- *
- * set page module
- *
- * @param string $module
- * @return \Cube\Navigation\Page\Mvc
- * @throws \InvalidArgumentException
- */
- public function setModule($module)
- {
- if (!is_string($module) && $module !== null) {
- throw new \InvalidArgumentException(sprintf(
- "'module' must be a string or null, %s given.", gettype($module)));
- }
- $this->_module = $module;
- return $this;
- }
- /**
- *
- * get page controller
- *
- * @return string
- */
- public function getController()
- {
- return $this->_controller;
- }
- /**
- *
- * set page controller
- *
- * @param string $controller
- * @return \Cube\Navigation\Page\Mvc
- * @throws \InvalidArgumentException
- */
- public function setController($controller)
- {
- if (!is_string($controller) && $controller !== null) {
- throw new \InvalidArgumentException(sprintf(
- "'controller' must be a string or null, %s given.", gettype($controller)));
- }
- $this->_controller = $controller;
- return $this;
- }
- /**
- *
- * get page action
- *
- * @return string
- */
- public function getAction()
- {
- return $this->_action;
- }
- /**
- *
- * set page action
- *
- * @param string $action
- * @return \Cube\Navigation\Page\Mvc
- * @throws \InvalidArgumentException
- */
- public function setAction($action)
- {
- if (!is_string($action) && $action !== null) {
- throw new \InvalidArgumentException(sprintf(
- "'action' must be a string or null, %s given.", gettype($action)));
- }
- $this->_action = $action;
- return $this;
- }
- /**
- *
- * get page params
- *
- * @return string
- */
- public function getParams()
- {
- $params = array(
- 'module' => $this->_module,
- 'controller' => $this->_controller,
- 'action' => $this->_action,
- );
- foreach ($this->_params as $key => $value) {
- $params[$key] = $value;
- }
- return $params;
- }
- /**
- *
- * set page params
- *
- * @param array $params
- * @return \Cube\Navigation\Page\Mvc
- */
- public function setParams(array $params = null)
- {
- $this->_params = (array) $params;
- return $this;
- }
- /**
- *
- * check if the page is active, based on the request uri
- *
- * @param bool $recursive check in subpages as well, and if a subpage is active, return the current page as active
- * @return bool returns active status
- */
- public function isActive($recursive = false)
- {
- if (!$this->_active) {
- $frontController = Front::getInstance();
- $request = $frontController->getRequest();
- $router = $frontController->getRouter();
- $mvcParams = array(
- 'module' => $this->_module,
- 'controller' => $this->_controller,
- 'action' => $this->_action,
- );
- $uri = $router->assemble(
- array_merge($mvcParams, $this->_params), null, false);
- if ($request->matchRequestUri($uri)) {
- $this->_active = true;
- return true;
- }
- }
- return parent::isActive($recursive);
- }
- }
|