php Zend-Navigation-Page-AbstractPage类(方法)实例源码

下面列出了php Zend-Navigation-Page-AbstractPage 类(方法)源码代码实例,从而了解它的用法。

作者:suitedJ    项目:ZfcTwitterBootstra   
/**
  * Returns an HTML string containing an 'a' element for the given page
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @param  boolean      $hasParent if the breadcrumb has a parent
  * @return string
  */
 public function htmlify(AbstractPage $page, $hasParent = false)
 {
     $html = '<li';
     if (!$hasParent) {
         $html .= ' class="active"';
     }
     $html .= '>';
     $label = $page->getLabel();
     if (null !== ($translator = $this->getTranslator())) {
         $label = $translator->translate($label, $this->getTranslatorTextDomain());
     }
     $escaper = $this->view->plugin('escapeHtml');
     $label = $escaper($label);
     if ($page->getHref() && ($hasParent || !$hasParent && $this->getLinkLast())) {
         $anchorAttribs = $this->htmlAttribs(array('href' => $page->getHref()));
         $html .= '<a' . $anchorAttribs . '>' . $label . '</a>';
     } else {
         $html .= $label;
     }
     if ($hasParent) {
         $html .= '<span class="divider">' . $this->getSeparator() . '</span>';
     }
     $html .= '</li>';
     return $html;
 }

作者:gstearmi    项目:EshopVegeTabl   
protected function decorateDropdown($content, \Zend\Navigation\Page\AbstractPage $page, $renderIcons = true, $activeIconInverse = true, array $options = array())
 {
     //Get attribs
     $liAttribs = array('id' => $page->getId(), 'class' => 'dropdown' . ($page->isActive(true) ? ' active' : ''));
     $html = "\n" . '<li' . $this->htmlAttribs($liAttribs) . '>' . "\n" . $content . "\n</li>";
     return $html;
 }

作者:siad00    项目:ctrlli   
/**
  * Determines whether a page should be accepted by ACL when iterating
  *
  * Rules:
  * - If helper has no ACL, page is accepted
  * - If page has a resource or privilege defined, page is accepted
  *   if the ACL allows access to it using the helper's role
  * - If page has no resource or privilege, page is accepted
  *
  * @param  AbstractPage $page  page to check
  * @return bool                whether page is accepted by ACL
  */
 protected function acceptAcl(AbstractPage $page)
 {
     if (!($acl = $this->getAcl())) {
         // no acl registered means don't use acl
         return true;
     }
     $role = $this->getRole();
     $roles = $this->getRoles();
     $resource = $page->getResource();
     if ($resource === NULL) {
         return true;
     }
     $resource = $this->acl->hasResourceOrParent($resource);
     if ($resource === false || $resource === NULL) {
         return false;
     }
     if (!$roles) {
         $roles = array($role);
     }
     if ($resource) {
         foreach ($roles as $r) {
             /**
              * TODO: for now this has been set to allow an item if its resource is not found
              */
             if (!$acl->hasResource($resource) || $acl->isAllowed($r, $resource)) {
                 return true;
             }
         }
         return false;
     }
     return true;
 }

作者:andreas-serl    项目:athene   
protected function isActive(AbstractPage $page, $recursive = true)
 {
     if ($page->get('identifier') != $this->identifier && $recursive) {
         foreach ($page->getPages() as $subPage) {
             if ($this->isActive($subPage, $recursive)) {
                 return true;
             }
         }
         return false;
     }
     return $page->get('identifier') == $this->identifier;
 }

作者:kashandaras    项目:blog-exampl   
public function htmlifyLabel(AbstractPage $page)
 {
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     /** @var \Zend\View\Helper\EscapeHtml $escaper */
     $escaper = $this->view->plugin('escapeHtml');
     $label = $escaper($label);
     if (isset($page->icon)) {
         $attribs = array('class' => 'fa fa-' . $page->icon);
         $label = '<i ' . $this->htmlAttribs($attribs) . '></i> ' . $label;
     }
     return $label;
 }

作者:kashandaras    项目:blog-exampl   
/**
  * Get list item class.
  *
  * @param AbstractPage $page
  *
  * @return string
  */
 public function getLiClass(AbstractPage $page)
 {
     /* @var $escaper \Zend\View\Helper\EscapeHtmlAttr */
     $escaper = $this->getView()->plugin('escapeHtmlAttr');
     $liClasses = array($this->liClass);
     if ($this->getAddClassToListItem()) {
         $liClasses[] = $page->getClass();
     }
     if ($page->hasPages()) {
         $liClasses[] = $this->getLiHasMenuClass();
     }
     if ($page->isActive(true)) {
         $liClasses[] = $this->getLiActiveClass();
     }
     return $escaper(implode(' ', $liClasses));
 }

作者:jochum-mediaservice    项目:contentinum5.   
/**
  * Returns an HTML string containing an 'a' element for the given page if
  * the page's href is not empty, and a 'span' element if it is empty
  *
  * Overrides {@link AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page               page to generate HTML for
  * @param  bool         $escapeLabel        Whether or not to escape the label
  * @param  bool         $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $page->getTitle());
     if ($addClassToListItem === false) {
         $attribs['class'] = $page->getClass();
     }
     // does page have a href?
     $href = $page->getHref();
     if ('#' !== $href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     $label = $page->getLabel();
     //$this->translate(, $page->getTextDomain());
     if ($escapeLabel === true) {
         /** @var \Zend\View\Helper\EscapeHtml $escaper */
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }

作者:ninahuanc    项目:zf   
public function testShouldFailIfUnableToDetermineType()
 {
     try {
         $page = AbstractPage::factory(array('label' => 'My Invalid Page'));
     } catch (Navigation\Exception\InvalidArgumentException $e) {
         return;
     }
     $this->fail('An exception has not been thrown for invalid page type');
 }

作者:CPDeutschlan    项目:zf2-api-clien   
/**
  * Get the feed list and the posts of the feed we are looking at now
  *
  * @return void
  */
 public function indexAction()
 {
     $viewData = array();
     $flashMessenger = $this->flashMessenger();
     $username = $this->params()->fromRoute('username');
     $currentFeedId = $this->params()->fromRoute('feed_id');
     $userData = ApiClient::getUser($username);
     if ($userData !== FALSE) {
         $hydrator = new ClassMethods();
         $user = $hydrator->hydrate($userData, new User());
     } else {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $subscribeForm = new SubscribeForm();
     $unsubscribeForm = new UnsubscribeForm();
     $subscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-subscribe', array('username' => $username)));
     $unsubscribeForm->setAttribute('action', $this->url()->fromRoute('feeds-unsubscribe', array('username' => $username)));
     $hydrator = new ClassMethods();
     $response = ApiClient::getFeeds($username);
     $feeds = array();
     foreach ($response as $r) {
         $feeds[$r['id']] = $hydrator->hydrate($r, new Feed());
     }
     if ($currentFeedId === null && !empty($feeds)) {
         $currentFeedId = reset($feeds)->getId();
     }
     $feedsMenu = new Navigation();
     $router = $this->getEvent()->getRouter();
     $routeMatch = $this->getEvent()->getRouteMatch()->setParam('feed_id', $currentFeedId);
     foreach ($feeds as $f) {
         $feedsMenu->addPage(AbstractPage::factory(array('title' => $f->getTitle(), 'icon' => $f->getIcon(), 'route' => 'feeds', 'routeMatch' => $routeMatch, 'router' => $router, 'params' => array('username' => $username, 'feed_id' => $f->getId()))));
     }
     $currentFeed = $currentFeedId != null ? $feeds[$currentFeedId] : null;
     if ($currentFeed != null) {
         $paginator = new Paginator(new ArrayAdapter($currentFeed->getArticles()));
         $paginator->setItemCountPerPage(5);
         $paginator->setCurrentPageNumber($this->params()->fromRoute('page'));
         $viewData['paginator'] = $paginator;
         $viewData['feedId'] = $currentFeedId;
     }
     $unsubscribeForm->get('feed_id')->setValue($currentFeedId);
     $viewData['subscribeForm'] = $subscribeForm;
     $viewData['unsubscribeForm'] = $unsubscribeForm;
     $viewData['username'] = $username;
     $viewData['feedsMenu'] = $feedsMenu;
     $viewData['user'] = $user;
     $viewData['paginator'] = $paginator;
     $viewData['feedId'] = $currentFeedId;
     $viewData['feed'] = $currentFeed;
     $this->layout()->username = $username;
     if ($flashMessenger->hasMessages()) {
         $viewData['flashMessages'] = $flashMessenger->getMessages();
     }
     return $viewData;
 }

作者:houzoum    项目:fm   
/**
  * @override htmlify from the parent/base/super class
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // !!! This method will be executed in the namespace of the class
     // !!! But the methods of the super/base class will be executed in its own namespace
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $title);
     $attribs['class'] = '';
     if ($addClassToListItem === false) {
         $attribs['class'] = $page->getClass();
     }
     // Stoyan
     $attribs['class'] .= $attribs['class'] ? ' ' : '';
     $attribs['class'] .= $page->getAnchorClass();
     //		echo 'Menu<pre>';
     //		echo 'Class: ' . $page->getClass();
     //		echo 'Anchor Class: ' . $page->getAnchorClass();
     //		print_r($attribs);
     //		echo '</pre>';
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }

作者:siad00    项目:ctrlli   
/**
  * Determines whether a page should be accepted by ACL when iterating
  *
  * Rules:
  * - If helper has no ACL, page is accepted
  * - If page has a resource or privilege defined, page is accepted
  *   if the ACL allows access to it using the helper's role
  * - If page has no resource or privilege, page is accepted
  *
  * @param  AbstractPage $page  page to check
  * @return bool                whether page is accepted by ACL
  */
 protected function acceptAcl(AbstractPage $page)
 {
     if (!($acl = $this->getAcl())) {
         // no acl registered means don't use acl
         return true;
     }
     $role = $this->getRole();
     $roles = $this->getRoles();
     $resource = $page->getResource();
     $privilege = $page->getPrivilege();
     if (!$roles) {
         $roles = array($roles);
     }
     if ($resource || $privilege) {
         foreach ($roles as $r) {
             // determine using helper role and page resource/privilege
             return $acl->hasResource($resource) && $acl->isAllowed($r, $resource);
         }
         return false;
     }
     return true;
 }

作者:rajanlami    项目:IntTes   
public function testGetChildrenShouldReturnTheCurrentPage()
 {
     $container = new Navigation\Navigation();
     $page = Page\AbstractPage::factory(array('type' => 'uri'));
     $container->addPage($page);
     $this->assertEquals($page, $container->getChildren());
 }

作者:Baf    项目:Zend-For   
/**
  * Returns an HTML string containing an 'a' element for the given page if
  * the page's href is not empty, and a 'span' element if it is empty
  *
  * Overrides {@link AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page   page to generate HTML for
  * @param bool $escapeLabel     Whether or not to escape the label
  * @return string               HTML string for the given page
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass());
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     $html .= '</' . $element . '>';
     return $html;
 }

作者:eltonoliveir    项目:jenkin   
/**
  * Checks if the container has the given page
  *
  * @param  Page\AbstractPage $page page to look for
  * @param  bool $recursive [optional] whether to search recursively.
  *                         Default is false.
  * @return bool whether page is in container
  */
 public function hasPage(Page\AbstractPage $page, $recursive = false)
 {
     if (array_key_exists($page->hashCode(), $this->index)) {
         return true;
     } elseif ($recursive) {
         foreach ($this->pages as $childPage) {
             if ($childPage->hasPage($page, true)) {
                 return true;
             }
         }
     }
     return false;
 }

作者:eltonoliveir    项目:jenkin   
/**
  * Returns an HTML string containing an 'a' element for the given page
  *
  * @param  AbstractPage $page  page to generate HTML for
  * @return string
  */
 public function htmlify(AbstractPage $page)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $title = $page->getTitle();
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for anchor element
     $attribs = array('id' => $page->getId(), 'title' => $title, 'class' => $page->getClass(), 'href' => $page->getHref(), 'target' => $page->getTarget());
     $escaper = $this->view->plugin('escapeHtml');
     return '<a' . $this->htmlAttribs($attribs) . '>' . $escaper($label) . '</a>';
 }

作者:pnaq5    项目:zf2dem   
public function testAclFiltersAwayPagesFromPageProperty()
 {
     $acl = new Acl\Acl();
     $acl->addRole(new Role\GenericRole('member'));
     $acl->addRole(new Role\GenericRole('admin'));
     $acl->addResource(new Resource\GenericResource('protected'));
     $acl->allow('admin', 'protected');
     $this->_helper->setAcl($acl);
     $this->_helper->setRole($acl->getRole('member'));
     $samplePage = AbstractPage::factory(array('label' => 'An example page', 'uri' => 'http://www.example.com/', 'resource' => 'protected'));
     $active = $this->_helper->findOneByLabel('Home');
     $expected = array('alternate' => false, 'stylesheet' => false, 'start' => false, 'next' => 'Page 1', 'prev' => false, 'contents' => false, 'index' => false, 'glossary' => false, 'copyright' => false, 'chapter' => 'array(4)', 'section' => false, 'subsection' => false, 'appendix' => false, 'help' => false, 'bookmark' => false);
     $actual = array();
     foreach ($expected as $type => $discard) {
         $active->addRel($type, $samplePage);
         $found = $this->_helper->findRelation($active, 'rel', $type);
         if (null === $found) {
             $actual[$type] = false;
         } elseif (is_array($found)) {
             $actual[$type] = 'array(' . count($found) . ')';
         } else {
             $actual[$type] = $found->getLabel();
         }
     }
     $this->assertEquals($expected, $actual);
 }

作者:kashandaras    项目:blog-exampl   
/**
  * Returns an HTML string of page label with icon support.
  *
  * @param  AbstractPage $page page to generate HTML for
  * @param  bool $escapeLabel Whether or not to escape the label
  * @return string
  */
 public function htmlifyLabel(AbstractPage $page, $escapeLabel = true, $isTreeView = false)
 {
     $label = $this->translate($page->getLabel(), $page->getTextDomain());
     if ($escapeLabel) {
         /** @var \Zend\View\Helper\EscapeHtml $escaper */
         $escaper = $this->view->plugin('escapeHtml');
         $label = $escaper($label);
     }
     $label = '<span>' . $label . '</span>';
     if (isset($page->icon)) {
         $attribs = array('class' => 'fa fa-' . $page->icon);
         $label = '<i ' . $this->htmlAttribs($attribs) . '></i> ' . $label;
     }
     if ($isTreeView) {
         $label .= '<i class="fa fa-angle-left pull-right"></i>';
     }
     return $label;
 }

作者:bradley-hol    项目:zf   
public function testToArrayMethod()
 {
     $options = array('label' => 'foo', 'uri' => 'http://www.example.com/foo.html', 'fragment' => 'bar', 'id' => 'my-id', 'class' => 'my-class', 'title' => 'my-title', 'target' => 'my-target', 'rel' => array(), 'rev' => array(), 'order' => 100, 'active' => true, 'visible' => false, 'resource' => 'joker', 'privilege' => null, 'foo' => 'bar', 'meaning' => 42, 'pages' => array(array('label' => 'foo.bar', 'uri' => 'http://www.example.com/foo.html'), array('label' => 'foo.baz', 'uri' => 'http://www.example.com/foo.html')));
     $page = AbstractPage::factory($options);
     $toArray = $page->toArray();
     // tweak options to what we expect toArray() to contain
     $options['type'] = 'Zend\\Navigation\\Page\\Uri';
     // calculate diff between toArray() and $options
     $diff = array_diff_assoc($toArray, $options);
     // should be no diff
     $this->assertEquals(array(), $diff);
     // $toArray should have 2 sub pages
     $this->assertEquals(2, count($toArray['pages']));
     // tweak options to what we expect sub page 1 to be
     $options['label'] = 'foo.bar';
     $options['fragment'] = null;
     $options['order'] = null;
     $options['id'] = null;
     $options['class'] = null;
     $options['title'] = null;
     $options['target'] = null;
     $options['resource'] = null;
     $options['active'] = false;
     $options['visible'] = true;
     unset($options['foo']);
     unset($options['meaning']);
     // assert that there is no diff from what we expect
     $subPageOneDiff = array_diff_assoc($toArray['pages'][0], $options);
     $this->assertEquals(array(), $subPageOneDiff);
     // tweak options to what we expect sub page 2 to be
     $options['label'] = 'foo.baz';
     // assert that there is no diff from what we expect
     $subPageTwoDiff = array_diff_assoc($toArray['pages'][1], $options);
     $this->assertEquals(array(), $subPageTwoDiff);
 }

作者:zetta-cod    项目:tss-bootstra   
/**
  * Returns an HTML string containing an 'a' element for the given page if
  * the page's href is not empty, and a 'span' element if it is empty
  *
  * Overrides {@link AbstractHelper::htmlify()}.
  *
  * @param  AbstractPage $page page to generate HTML for
  * @param  bool $escapeLabel Whether or not to escape the label
  * @param  bool $addClassToListItem Whether or not to add the page class to the list item
  * @return string
  */
 public function htmlify(AbstractPage $page, $escapeLabel = true, $addClassToListItem = false)
 {
     // get label and title for translating
     $label = $page->getLabel();
     $addonLeft = $page->get('addon-left');
     $addonRight = $page->get('addon-right');
     $title = $page->getTitle();
     // translate label and title?
     if (null !== ($translator = $this->getTranslator())) {
         $textDomain = $this->getTranslatorTextDomain();
         if (is_string($label) && !empty($label)) {
             $label = $translator->translate($label, $textDomain);
         }
         if (is_string($title) && !empty($title)) {
             $title = $translator->translate($title, $textDomain);
         }
     }
     // get attribs for element
     $attribs = ['id' => $page->getId(), 'title' => $title];
     // add additional attributes
     $attr = $page->get('attribs');
     if (is_array($attr)) {
         $attribs = $attribs + $attr;
     }
     //if ($addClassToListItem === false) {
     $attribs['class'] = $page->getClass();
     //}
     // does page have a href?
     $href = $page->getHref();
     if ($href) {
         $element = 'a';
         $attribs['href'] = $href;
         $attribs['target'] = $page->getTarget();
     } else {
         $element = 'span';
     }
     $html = '<' . $element . $this->htmlAttribs($attribs) . '>';
     if ($addonLeft) {
         $html .= $addonLeft;
     }
     if ($escapeLabel === true) {
         $escaper = $this->view->plugin('escapeHtml');
         $html .= $escaper($label);
     } else {
         $html .= $label;
     }
     if ($addonRight) {
         $html .= $addonRight;
     }
     $html .= '</' . $element . '>';
     return $html;
 }

作者:haoyanfe    项目:zf   
public function testToArrayMethod()
 {
     $options = array('label' => 'foo', 'uri' => 'http://www.example.com/foo.html', 'fragment' => 'bar', 'id' => 'my-id', 'class' => 'my-class', 'title' => 'my-title', 'target' => 'my-target', 'rel' => array(), 'rev' => array(), 'order' => 100, 'active' => true, 'visible' => false, 'resource' => 'joker', 'privilege' => null, 'foo' => 'bar', 'meaning' => 42, 'pages' => array(array('type' => 'Zend\\Navigation\\Page\\Uri', 'label' => 'foo.bar', 'fragment' => null, 'id' => null, 'class' => null, 'title' => null, 'target' => null, 'rel' => array(), 'rev' => array(), 'order' => null, 'resource' => null, 'privilege' => null, 'active' => null, 'visible' => 1, 'pages' => array(), 'uri' => 'http://www.example.com/foo.html'), array('label' => 'foo.baz', 'type' => 'Zend\\Navigation\\Page\\Uri', 'label' => 'foo.bar', 'fragment' => null, 'id' => null, 'class' => null, 'title' => null, 'target' => null, 'rel' => array(), 'rev' => array(), 'order' => null, 'resource' => null, 'privilege' => null, 'active' => null, 'visible' => 1, 'pages' => array(), 'uri' => 'http://www.example.com/foo.html')));
     $page = AbstractPage::factory($options);
     $toArray = $page->toArray();
     // tweak options to what we expect toArray() to contain
     $options['type'] = 'Zend\\Navigation\\Page\\Uri';
     ksort($options);
     ksort($toArray);
     $this->assertEquals($options, $toArray);
 }


问题


面经


文章

微信
公众号

扫码关注公众号