public function getPage($path = '') { $pageTree = $this->getBranch()->getCommit()->getTree(); $pageObj = $pageTree->resolvePath($path); $name = $path === '' ? '' : $path; $page = $page = new Page($this, $name); if ($pageObj instanceof Tree) { $page->setHasSubpages(true)->setTree($pageObj)->setPath($path)->setBlob($pageObj->resolvePath('index.md')); } else { $page->setBlob($pageObj)->setPath($path); } return $page; }
/** * @Route("/{wiki}/new/{path}", name="page_create", requirements={ * "path": "[\d\w-_\/\.+@*]*" * })) * @ParamConverter("wiki", class="AppBundle\Model\Wiki") * @Method("POST") */ public function createAction(Wiki $wiki, $path = '', Request $request) { $this->denyAccessUnlessGranted('edit', $wiki->getSlug()); $name = $request->request->get('page'); $content = $request->request->get('content'); $message = $request->request->get('message'); $user = $this->getUser(); $page = new Page($wiki, $name); $pagePath = $path; $pagePath .= strlen($pagePath) === 0 ? '' : '/'; $pagePath .= $name; if (preg_match('/\\.md$/', $name) === 0) { $pagePath .= '/index.md'; } $page->setPath($pagePath)->setContent($content); $page->save($user, $message); return $this->redirectToRoute('page_show', array('slug' => $slug, 'path' => $path)); }
public function getPages() { $pages = array(); if ($this->getTree() instanceof Tree) { foreach ($this->getTree()->getEntries() as $name => $pageObj) { $page = new Page($this->getWiki(), $name); if ($name === 'index.md') { continue; } if ($pageObj[1] instanceof Tree) { $path = $this->getPath(); $path .= strlen($path) > 0 ? '/' : ''; $path .= $name; $page->setHasSubpages(true)->setTree($pageObj[1])->setPath($path)->setBlob($pageObj[1]->resolvePath('index.md')); } else { $page->setBlob($pageObj[1])->setPath($this->getPath() . '/' . $name); } array_push($pages, $page); } } return $pages; }