HelperAbstract.php 26 KB

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