PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/View/Helper/Navigation/HelperAbstract.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 855 lines | 327 code | 80 blank | 448 comment | 58 complexity | d57656d29b8e2f7e29428e6bea38ccb8 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: HelperAbstract.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_View_Helper_Navigation_Helper
  24. */
  25. require_once 'Zend/View/Helper/Navigation/Helper.php';
  26. /**
  27. * @see Zend_View_Helper_HtmlElement
  28. */
  29. require_once 'Zend/View/Helper/HtmlElement.php';
  30. /**
  31. * Base class for navigational helpers
  32. *
  33. * @category Zend
  34. * @package Zend_View
  35. * @subpackage Helper
  36. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. abstract class Zend_View_Helper_Navigation_HelperAbstract
  40. extends Zend_View_Helper_HtmlElement
  41. implements Zend_View_Helper_Navigation_Helper
  42. {
  43. /**
  44. * Container to operate on by default
  45. *
  46. * @var Zend_Navigation_Container
  47. */
  48. protected $_container;
  49. /**
  50. * The minimum depth a page must have to be included when rendering
  51. *
  52. * @var int
  53. */
  54. protected $_minDepth;
  55. /**
  56. * The maximum depth a page can have to be included when rendering
  57. *
  58. * @var int
  59. */
  60. protected $_maxDepth;
  61. /**
  62. * Indentation string
  63. *
  64. * @var string
  65. */
  66. protected $_indent = '';
  67. /**
  68. * Translator
  69. *
  70. * @var Zend_Translate_Adapter
  71. */
  72. protected $_translator;
  73. /**
  74. * ACL to use when iterating pages
  75. *
  76. * @var Zend_Acl
  77. */
  78. protected $_acl;
  79. /**
  80. * Wheter invisible items should be rendered by this helper
  81. *
  82. * @var bool
  83. */
  84. protected $_renderInvisible = false;
  85. /**
  86. * ACL role to use when iterating pages
  87. *
  88. * @var string|Zend_Acl_Role_Interface
  89. */
  90. protected $_role;
  91. /**
  92. * Whether translator should be used for page labels and titles
  93. *
  94. * @var bool
  95. */
  96. protected $_useTranslator = true;
  97. /**
  98. * Whether ACL should be used for filtering out pages
  99. *
  100. * @var bool
  101. */
  102. protected $_useAcl = true;
  103. /**
  104. * Default ACL to use when iterating pages if not explicitly set in the
  105. * instance by calling {@link setAcl()}
  106. *
  107. * @var Zend_Acl
  108. */
  109. protected static $_defaultAcl;
  110. /**
  111. * Default ACL role to use when iterating pages if not explicitly set in the
  112. * instance by calling {@link setRole()}
  113. *
  114. * @var string|Zend_Acl_Role_Interface
  115. */
  116. protected static $_defaultRole;
  117. // Accessors:
  118. /**
  119. * Sets navigation container the helper operates on by default
  120. *
  121. * Implements {@link Zend_View_Helper_Navigation_Interface::setContainer()}.
  122. *
  123. * @param Zend_Navigation_Container $container [optional] container
  124. * to operate on.
  125. * Default is null,
  126. * meaning container
  127. * will be reset.
  128. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  129. * returns self
  130. */
  131. public function setContainer(Zend_Navigation_Container $container = null)
  132. {
  133. $this->_container = $container;
  134. return $this;
  135. }
  136. /**
  137. * Returns the navigation container helper operates on by default
  138. *
  139. * Implements {@link Zend_View_Helper_Navigation_Interface::getContainer()}.
  140. *
  141. * If a helper is not explicitly set in this helper instance by calling
  142. * {@link setContainer()} or by passing it through the helper entry point,
  143. * this method will look in {@link Zend_Registry} for a container by using
  144. * the key 'Zend_Navigation'.
  145. *
  146. * If no container is set, and nothing is found in Zend_Registry, a new
  147. * container will be instantiated and stored in the helper.
  148. *
  149. * @return Zend_Navigation_Container navigation container
  150. */
  151. public function getContainer()
  152. {
  153. if (null === $this->_container) {
  154. // try to fetch from registry first
  155. require_once 'Zend/Registry.php';
  156. if (Zend_Registry::isRegistered('Zend_Navigation')) {
  157. $nav = Zend_Registry::get('Zend_Navigation');
  158. if ($nav instanceof Zend_Navigation_Container) {
  159. return $this->_container = $nav;
  160. }
  161. }
  162. // nothing found in registry, create new container
  163. require_once 'Zend/Navigation.php';
  164. $this->_container = new Zend_Navigation();
  165. }
  166. return $this->_container;
  167. }
  168. /**
  169. * Sets the minimum depth a page must have to be included when rendering
  170. *
  171. * @param int $minDepth [optional] minimum
  172. * depth. Default is
  173. * null, which sets
  174. * no minimum depth.
  175. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  176. * returns self
  177. */
  178. public function setMinDepth($minDepth = null)
  179. {
  180. if (null === $minDepth || is_int($minDepth)) {
  181. $this->_minDepth = $minDepth;
  182. } else {
  183. $this->_minDepth = (int) $minDepth;
  184. }
  185. return $this;
  186. }
  187. /**
  188. * Returns minimum depth a page must have to be included when rendering
  189. *
  190. * @return int|null minimum depth or null
  191. */
  192. public function getMinDepth()
  193. {
  194. if (!is_int($this->_minDepth) || $this->_minDepth < 0) {
  195. return 0;
  196. }
  197. return $this->_minDepth;
  198. }
  199. /**
  200. * Sets the maximum depth a page can have to be included when rendering
  201. *
  202. * @param int $maxDepth [optional] maximum
  203. * depth. Default is
  204. * null, which sets no
  205. * maximum depth.
  206. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  207. * returns self
  208. */
  209. public function setMaxDepth($maxDepth = null)
  210. {
  211. if (null === $maxDepth || is_int($maxDepth)) {
  212. $this->_maxDepth = $maxDepth;
  213. } else {
  214. $this->_maxDepth = (int) $maxDepth;
  215. }
  216. return $this;
  217. }
  218. /**
  219. * Returns maximum depth a page can have to be included when rendering
  220. *
  221. * @return int|null maximum depth or null
  222. */
  223. public function getMaxDepth()
  224. {
  225. return $this->_maxDepth;
  226. }
  227. /**
  228. * Set the indentation string for using in {@link render()}, optionally a
  229. * number of spaces to indent with
  230. *
  231. * @param string|int $indent indentation string or
  232. * number of spaces
  233. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  234. * returns self
  235. */
  236. public function setIndent($indent)
  237. {
  238. $this->_indent = $this->_getWhitespace($indent);
  239. return $this;
  240. }
  241. /**
  242. * Returns indentation
  243. *
  244. * @return string
  245. */
  246. public function getIndent()
  247. {
  248. return $this->_indent;
  249. }
  250. /**
  251. * Sets translator to use in helper
  252. *
  253. * Implements {@link Zend_View_Helper_Navigation_Helper::setTranslator()}.
  254. *
  255. * @param mixed $translator [optional] translator.
  256. * Expects an object of
  257. * type
  258. * {@link Zend_Translate_Adapter}
  259. * or {@link Zend_Translate},
  260. * or null. Default is
  261. * null, which sets no
  262. * translator.
  263. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  264. * returns self
  265. */
  266. public function setTranslator($translator = null)
  267. {
  268. if (null == $translator ||
  269. $translator instanceof Zend_Translate_Adapter) {
  270. $this->_translator = $translator;
  271. } elseif ($translator instanceof Zend_Translate) {
  272. $this->_translator = $translator->getAdapter();
  273. }
  274. return $this;
  275. }
  276. /**
  277. * Returns translator used in helper
  278. *
  279. * Implements {@link Zend_View_Helper_Navigation_Helper::getTranslator()}.
  280. *
  281. * @return Zend_Translate_Adapter|null translator or null
  282. */
  283. public function getTranslator()
  284. {
  285. if (null === $this->_translator) {
  286. require_once 'Zend/Registry.php';
  287. if (Zend_Registry::isRegistered('Zend_Translate')) {
  288. $this->setTranslator(Zend_Registry::get('Zend_Translate'));
  289. }
  290. }
  291. return $this->_translator;
  292. }
  293. /**
  294. * Sets ACL to use when iterating pages
  295. *
  296. * Implements {@link Zend_View_Helper_Navigation_Helper::setAcl()}.
  297. *
  298. * @param Zend_Acl $acl [optional] ACL object.
  299. * Default is null.
  300. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  301. * returns self
  302. */
  303. public function setAcl(Zend_Acl $acl = null)
  304. {
  305. $this->_acl = $acl;
  306. return $this;
  307. }
  308. /**
  309. * Returns ACL or null if it isn't set using {@link setAcl()} or
  310. * {@link setDefaultAcl()}
  311. *
  312. * Implements {@link Zend_View_Helper_Navigation_Helper::getAcl()}.
  313. *
  314. * @return Zend_Acl|null ACL object or null
  315. */
  316. public function getAcl()
  317. {
  318. if ($this->_acl === null && self::$_defaultAcl !== null) {
  319. return self::$_defaultAcl;
  320. }
  321. return $this->_acl;
  322. }
  323. /**
  324. * Sets ACL role(s) to use when iterating pages
  325. *
  326. * Implements {@link Zend_View_Helper_Navigation_Helper::setRole()}.
  327. *
  328. * @param mixed $role [optional] role to
  329. * set. Expects a string,
  330. * an instance of type
  331. * {@link Zend_Acl_Role_Interface},
  332. * or null. Default is
  333. * null, which will set
  334. * no role.
  335. * @throws Zend_View_Exception if $role is invalid
  336. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  337. * returns self
  338. */
  339. public function setRole($role = null)
  340. {
  341. if (null === $role || is_string($role) ||
  342. $role instanceof Zend_Acl_Role_Interface) {
  343. $this->_role = $role;
  344. } else {
  345. require_once 'Zend/View/Exception.php';
  346. $e = new Zend_View_Exception(sprintf(
  347. '$role must be a string, null, or an instance of '
  348. . 'Zend_Acl_Role_Interface; %s given',
  349. gettype($role)
  350. ));
  351. $e->setView($this->view);
  352. throw $e;
  353. }
  354. return $this;
  355. }
  356. /**
  357. * Returns ACL role to use when iterating pages, or null if it isn't set
  358. * using {@link setRole()} or {@link setDefaultRole()}
  359. *
  360. * Implements {@link Zend_View_Helper_Navigation_Helper::getRole()}.
  361. *
  362. * @return string|Zend_Acl_Role_Interface|null role or null
  363. */
  364. public function getRole()
  365. {
  366. if ($this->_role === null && self::$_defaultRole !== null) {
  367. return self::$_defaultRole;
  368. }
  369. return $this->_role;
  370. }
  371. /**
  372. * Sets whether ACL should be used
  373. *
  374. * Implements {@link Zend_View_Helper_Navigation_Helper::setUseAcl()}.
  375. *
  376. * @param bool $useAcl [optional] whether ACL
  377. * should be used.
  378. * Default is true.
  379. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  380. * returns self
  381. */
  382. public function setUseAcl($useAcl = true)
  383. {
  384. $this->_useAcl = (bool) $useAcl;
  385. return $this;
  386. }
  387. /**
  388. * Returns whether ACL should be used
  389. *
  390. * Implements {@link Zend_View_Helper_Navigation_Helper::getUseAcl()}.
  391. *
  392. * @return bool whether ACL should be used
  393. */
  394. public function getUseAcl()
  395. {
  396. return $this->_useAcl;
  397. }
  398. /**
  399. * Return renderInvisible flag
  400. *
  401. * @return bool
  402. */
  403. public function getRenderInvisible()
  404. {
  405. return $this->_renderInvisible;
  406. }
  407. /**
  408. * Render invisible items?
  409. *
  410. * @param bool $renderInvisible [optional] boolean flag
  411. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface
  412. * returns self
  413. */
  414. public function setRenderInvisible($renderInvisible = true)
  415. {
  416. $this->_renderInvisible = (bool) $renderInvisible;
  417. return $this;
  418. }
  419. /**
  420. * Sets whether translator should be used
  421. *
  422. * Implements {@link Zend_View_Helper_Navigation_Helper::setUseTranslator()}.
  423. *
  424. * @param bool $useTranslator [optional] whether
  425. * translator should be
  426. * used. Default is true.
  427. * @return Zend_View_Helper_Navigation_HelperAbstract fluent interface,
  428. * returns self
  429. */
  430. public function setUseTranslator($useTranslator = true)
  431. {
  432. $this->_useTranslator = (bool) $useTranslator;
  433. return $this;
  434. }
  435. /**
  436. * Returns whether translator should be used
  437. *
  438. * Implements {@link Zend_View_Helper_Navigation_Helper::getUseTranslator()}.
  439. *
  440. * @return bool whether translator should be used
  441. */
  442. public function getUseTranslator()
  443. {
  444. return $this->_useTranslator;
  445. }
  446. // Magic overloads:
  447. /**
  448. * Magic overload: Proxy calls to the navigation container
  449. *
  450. * @param string $method method name in container
  451. * @param array $arguments [optional] arguments to pass
  452. * @return mixed returns what the container returns
  453. * @throws Zend_Navigation_Exception if method does not exist in container
  454. */
  455. public function __call($method, array $arguments = array())
  456. {
  457. return call_user_func_array(
  458. array($this->getContainer(), $method),
  459. $arguments);
  460. }
  461. /**
  462. * Magic overload: Proxy to {@link render()}.
  463. *
  464. * This method will trigger an E_USER_ERROR if rendering the helper causes
  465. * an exception to be thrown.
  466. *
  467. * Implements {@link Zend_View_Helper_Navigation_Helper::__toString()}.
  468. *
  469. * @return string
  470. */
  471. public function __toString()
  472. {
  473. try {
  474. return $this->render();
  475. } catch (Exception $e) {
  476. $msg = get_class($e) . ': ' . $e->getMessage();
  477. trigger_error($msg, E_USER_ERROR);
  478. return '';
  479. }
  480. }
  481. // Public methods:
  482. /**
  483. * Finds the deepest active page in the given container
  484. *
  485. * @param Zend_Navigation_Container $container container to search
  486. * @param int|null $minDepth [optional] minimum depth
  487. * required for page to be
  488. * valid. Default is to use
  489. * {@link getMinDepth()}. A
  490. * null value means no minimum
  491. * depth required.
  492. * @param int|null $minDepth [optional] maximum depth
  493. * a page can have to be
  494. * valid. Default is to use
  495. * {@link getMaxDepth()}. A
  496. * null value means no maximum
  497. * depth required.
  498. * @return array an associative array with
  499. * the values 'depth' and
  500. * 'page', or an empty array
  501. * if not found
  502. */
  503. public function findActive(Zend_Navigation_Container $container,
  504. $minDepth = null,
  505. $maxDepth = -1)
  506. {
  507. if (!is_int($minDepth)) {
  508. $minDepth = $this->getMinDepth();
  509. }
  510. if ((!is_int($maxDepth) || $maxDepth < 0) && null !== $maxDepth) {
  511. $maxDepth = $this->getMaxDepth();
  512. }
  513. $found = null;
  514. $foundDepth = -1;
  515. $iterator = new RecursiveIteratorIterator($container,
  516. RecursiveIteratorIterator::CHILD_FIRST);
  517. foreach ($iterator as $page) {
  518. $currDepth = $iterator->getDepth();
  519. if ($currDepth < $minDepth || !$this->accept($page)) {
  520. // page is not accepted
  521. continue;
  522. }
  523. if ($page->isActive(false) && $currDepth > $foundDepth) {
  524. // found an active page at a deeper level than before
  525. $found = $page;
  526. $foundDepth = $currDepth;
  527. }
  528. }
  529. if (is_int($maxDepth) && $foundDepth > $maxDepth) {
  530. while ($foundDepth > $maxDepth) {
  531. if (--$foundDepth < $minDepth) {
  532. $found = null;
  533. break;
  534. }
  535. $found = $found->getParent();
  536. if (!$found instanceof Zend_Navigation_Page) {
  537. $found = null;
  538. break;
  539. }
  540. }
  541. }
  542. if ($found) {
  543. return array('page' => $found, 'depth' => $foundDepth);
  544. } else {
  545. return array();
  546. }
  547. }
  548. /**
  549. * Checks if the helper has a container
  550. *
  551. * Implements {@link Zend_View_Helper_Navigation_Helper::hasContainer()}.
  552. *
  553. * @return bool whether the helper has a container or not
  554. */
  555. public function hasContainer()
  556. {
  557. return null !== $this->_container;
  558. }
  559. /**
  560. * Checks if the helper has an ACL instance
  561. *
  562. * Implements {@link Zend_View_Helper_Navigation_Helper::hasAcl()}.
  563. *
  564. * @return bool whether the helper has a an ACL instance or not
  565. */
  566. public function hasAcl()
  567. {
  568. return null !== $this->_acl;
  569. }
  570. /**
  571. * Checks if the helper has an ACL role
  572. *
  573. * Implements {@link Zend_View_Helper_Navigation_Helper::hasRole()}.
  574. *
  575. * @return bool whether the helper has a an ACL role or not
  576. */
  577. public function hasRole()
  578. {
  579. return null !== $this->_role;
  580. }
  581. /**
  582. * Checks if the helper has a translator
  583. *
  584. * Implements {@link Zend_View_Helper_Navigation_Helper::hasTranslator()}.
  585. *
  586. * @return bool whether the helper has a translator or not
  587. */
  588. public function hasTranslator()
  589. {
  590. return null !== $this->_translator;
  591. }
  592. /**
  593. * Returns an HTML string containing an 'a' element for the given page
  594. *
  595. * @param Zend_Navigation_Page $page page to generate HTML for
  596. * @return string HTML string for the given page
  597. */
  598. public function htmlify(Zend_Navigation_Page $page)
  599. {
  600. // get label and title for translating
  601. $label = $page->getLabel();
  602. $title = $page->getTitle();
  603. if ($this->getUseTranslator() && $t = $this->getTranslator()) {
  604. if (is_string($label) && !empty($label)) {
  605. $label = $t->translate($label);
  606. }
  607. if (is_string($title) && !empty($title)) {
  608. $title = $t->translate($title);
  609. }
  610. }
  611. // get attribs for anchor element
  612. $attribs = array(
  613. 'id' => $page->getId(),
  614. 'title' => $title,
  615. 'class' => $page->getClass(),
  616. 'href' => $page->getHref(),
  617. 'target' => $page->getTarget()
  618. );
  619. return '<a' . $this->_htmlAttribs($attribs) . '>'
  620. . $this->view->escape($label)
  621. . '</a>';
  622. }
  623. // Iterator filter methods:
  624. /**
  625. * Determines whether a page should be accepted when iterating
  626. *
  627. * Rules:
  628. * - If a page is not visible it is not accepted, unless RenderInvisible has
  629. * been set to true.
  630. * - If helper has no ACL, page is accepted
  631. * - If helper has ACL, but no role, page is not accepted
  632. * - If helper has ACL and role:
  633. * - Page is accepted if it has no resource or privilege
  634. * - Page is accepted if ACL allows page's resource or privilege
  635. * - If page is accepted by the rules above and $recursive is true, the page
  636. * will not be accepted if it is the descendant of a non-accepted page.
  637. *
  638. * @param Zend_Navigation_Page $page page to check
  639. * @param bool $recursive [optional] if true, page will not
  640. * be accepted if it is the
  641. * descendant of a page that is not
  642. * accepted. Default is true.
  643. * @return bool whether page should be accepted
  644. */
  645. public function accept(Zend_Navigation_Page $page, $recursive = true)
  646. {
  647. // accept by default
  648. $accept = true;
  649. if (!$page->isVisible(false) && !$this->getRenderInvisible()) {
  650. // don't accept invisible pages
  651. $accept = false;
  652. } elseif ($this->getUseAcl() && !$this->_acceptAcl($page)) {
  653. // acl is not amused
  654. $accept = false;
  655. }
  656. if ($accept && $recursive) {
  657. $parent = $page->getParent();
  658. if ($parent instanceof Zend_Navigation_Page) {
  659. $accept = $this->accept($parent, true);
  660. }
  661. }
  662. return $accept;
  663. }
  664. /**
  665. * Determines whether a page should be accepted by ACL when iterating
  666. *
  667. * Rules:
  668. * - If helper has no ACL, page is accepted
  669. * - If page has a resource or privilege defined, page is accepted
  670. * if the ACL allows access to it using the helper's role
  671. * - If page has no resource or privilege, page is accepted
  672. *
  673. * @param Zend_Navigation_Page $page page to check
  674. * @return bool whether page is accepted by ACL
  675. */
  676. protected function _acceptAcl(Zend_Navigation_Page $page)
  677. {
  678. if (!$acl = $this->getAcl()) {
  679. // no acl registered means don't use acl
  680. return true;
  681. }
  682. $role = $this->getRole();
  683. $resource = $page->getResource();
  684. $privilege = $page->getPrivilege();
  685. if ($resource || $privilege) {
  686. // determine using helper role and page resource/privilege
  687. return $acl->isAllowed($role, $resource, $privilege);
  688. }
  689. return true;
  690. }
  691. // Util methods:
  692. /**
  693. * Retrieve whitespace representation of $indent
  694. *
  695. * @param int|string $indent
  696. * @return string
  697. */
  698. protected function _getWhitespace($indent)
  699. {
  700. if (is_int($indent)) {
  701. $indent = str_repeat(' ', $indent);
  702. }
  703. return (string) $indent;
  704. }
  705. /**
  706. * Converts an associative array to a string of tag attributes.
  707. *
  708. * Overloads {@link Zend_View_Helper_HtmlElement::_htmlAttribs()}.
  709. *
  710. * @param array $attribs an array where each key-value pair is converted
  711. * to an attribute name and value
  712. * @return string an attribute string
  713. */
  714. protected function _htmlAttribs($attribs)
  715. {
  716. // filter out null values and empty string values
  717. foreach ($attribs as $key => $value) {
  718. if ($value === null || (is_string($value) && !strlen($value))) {
  719. unset($attribs[$key]);
  720. }
  721. }
  722. return parent::_htmlAttribs($attribs);
  723. }
  724. /**
  725. * Normalize an ID
  726. *
  727. * Overrides {@link Zend_View_Helper_HtmlElement::_normalizeId()}.
  728. *
  729. * @param string $value
  730. * @return string
  731. */
  732. protected function _normalizeId($value)
  733. {
  734. $prefix = get_class($this);
  735. $prefix = strtolower(trim(substr($prefix, strrpos($prefix, '_')), '_'));
  736. return $prefix . '-' . $value;
  737. }
  738. // Static methods:
  739. /**
  740. * Sets default ACL to use if another ACL is not explicitly set
  741. *
  742. * @param Zend_Acl $acl [optional] ACL object. Default is null, which
  743. * sets no ACL object.
  744. * @return void
  745. */
  746. public static function setDefaultAcl(Zend_Acl $acl = null)
  747. {
  748. self::$_defaultAcl = $acl;
  749. }
  750. /**
  751. * Sets default ACL role(s) to use when iterating pages if not explicitly
  752. * set later with {@link setRole()}
  753. *
  754. * @param midex $role [optional] role to set. Expects null,
  755. * string, or an instance of
  756. * {@link Zend_Acl_Role_Interface}.
  757. * Default is null, which sets no default
  758. * role.
  759. * @throws Zend_View_Exception if role is invalid
  760. * @return void
  761. */
  762. public static function setDefaultRole($role = null)
  763. {
  764. if (null === $role ||
  765. is_string($role) ||
  766. $role instanceof Zend_Acl_Role_Interface) {
  767. self::$_defaultRole = $role;
  768. } else {
  769. require_once 'Zend/View/Exception.php';
  770. throw new Zend_View_Exception(
  771. '$role must be null|string|Zend_Acl_Role_Interface'
  772. );
  773. }
  774. }
  775. }