本文整理汇总了PHP中Zend\Navigation\Page\AbstractPage::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractPage::factory方法的具体用法?PHP AbstractPage::factory怎么用?PHP AbstractPage::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Navigation\Page\AbstractPage
的用法示例。
在下文中一共展示了AbstractPage::factory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testShouldFailIfUnableToDetermineType
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');
}
示例2: indexAction
/**
* 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;
}
示例3: testAclFiltersAwayPagesFromPageProperty
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);
}
示例4: testGetChildrenShouldReturnTheCurrentPage
public function testGetChildrenShouldReturnTheCurrentPage()
{
$container = new Navigation\Navigation();
$page = Page\AbstractPage::factory(array('type' => 'uri'));
$container->addPage($page);
$this->assertEquals($page, $container->getChildren());
}
示例5: addPage
/**
* Adds a page to the container
*
* This method will inject the container as the given page's parent by
* calling {@link Page\AbstractPage::setParent()}.
*
* @param Page\AbstractPage|array|Traversable $page page to add
* @return self fluent interface, returns self
* @throws Exception\InvalidArgumentException if page is invalid
*/
public function addPage($page)
{
if ($page === $this) {
throw new Exception\InvalidArgumentException('A page cannot have itself as a parent');
}
if (!$page instanceof Page\AbstractPage) {
if (!is_array($page) && !$page instanceof Traversable) {
throw new Exception\InvalidArgumentException('Invalid argument: $page must be an instance of ' . 'Zend\\Navigation\\Page\\AbstractPage or Traversable, or an array');
}
$page = Page\AbstractPage::factory($page);
}
$hash = $page->hashCode();
if (array_key_exists($hash, $this->index)) {
// page is already in container
return $this;
}
// adds page to container and sets dirty flag
$this->pages[$hash] = $page;
$this->index[$hash] = $page->getOrder();
$this->dirtyIndex = true;
// inject self as page parent
$page->setParent($this);
return $this;
}
示例6: testToArrayMethod
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);
}
示例7: testToArrayMethod
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);
}
示例8: convertToPages
/**
* Converts a $mixed value to an array of pages
*
* @param mixed $mixed mixed value to get page(s) from
* @param bool $recursive whether $value should be looped
* if it is an array or a config
* @return AbstractPage|array|null
*/
protected function convertToPages($mixed, $recursive = true)
{
if ($mixed instanceof AbstractPage) {
// value is a page instance; return directly
return $mixed;
} elseif ($mixed instanceof AbstractContainer) {
// value is a container; return pages in it
$pages = array();
foreach ($mixed as $page) {
$pages[] = $page;
}
return $pages;
} elseif ($mixed instanceof Traversable) {
$mixed = ArrayUtils::iteratorToArray($mixed);
} elseif (is_string($mixed)) {
// value is a string; make an URI page
return AbstractPage::factory(array('type' => 'uri', 'uri' => $mixed));
}
if (is_array($mixed) && !empty($mixed)) {
if ($recursive && is_numeric(key($mixed))) {
// first key is numeric; assume several pages
$pages = array();
foreach ($mixed as $value) {
$value = $this->convertToPages($value, false);
if ($value) {
$pages[] = $value;
}
}
return $pages;
} else {
// pass array to factory directly
try {
$page = AbstractPage::factory($mixed);
return $page;
} catch (\Exception $e) {
}
}
}
// nothing found
return null;
}
示例9: testSetObjectPermission
public function testSetObjectPermission()
{
$page = AbstractPage::factory(array('type' => 'uri'));
$permission = new \stdClass();
$permission->name = 'my_permission';
$page->setPermission($permission);
$this->assertInstanceOf('stdClass', $page->getPermission());
$this->assertEquals('my_permission', $page->getPermission()->name);
}
示例10: testMenu
public function testMenu()
{
$this->_authService->method('hasIdentity')->willReturn(true);
$this->_authService->method('getIdentity')->willReturn('identity');
$this->_view->plugin('navigation')->menu()->setTranslator(null);
$menu = \Zend\Navigation\Page\AbstractPage::factory(array('type' => 'uri', 'pages' => array(array('label' => 'main', 'uri' => 'mainUri', 'active' => true, 'pages' => array(array('label' => 'sub', 'uri' => 'subUri', 'active' => true))))));
$html = $this->_view->render('layout', array('menu' => $menu));
$document = new \Zend\Dom\Document($html);
$this->assertCount(1, Query::execute('/html/body/div[@id="menu"]/ul[@class="navigation"]/li/a[@href="mainUri"]', $document));
$this->assertCount(1, Query::execute('/html/body/div[@id="menu"]/ul[@class="navigation navigation_sub"]/li/a[@href="subUri"]', $document));
$this->assertCount(1, Query::execute("/html/body/div[@id='menu']/div[@id='logout']/a[@href='/console/login/logout/'][text()='\nAbmelden\n']", $document));
}