protected function deepCopyPageWithoutChildren(Page $page, Page $parentPage = null) { $copy = new Page(); $copy->setId($page->getId()); $copy->setRouteName($page->getRouteName()); $copy->setPageAlias($page->getPageAlias()); $copy->setType($page->getType()); $copy->setEnabled($page->getEnabled()); $copy->setName($page->getName()); $copy->setSlug($page->getSlug()); $copy->setUrl($page->getUrl()); $copy->setCustomUrl($page->getCustomUrl()); $copy->setMetaKeyword($page->getMetaKeyword()); $copy->setMetaDescription($page->getMetaDescription()); $copy->setJavascript($page->getJavascript()); $copy->setStylesheet($page->getStylesheet()); $copy->setCreatedAt($page->getCreatedAt()); $copy->setUpdatedAt($page->getUpdatedAt()); $copy->setTarget($page->getTarget()); $copy->setTemplateCode($page->getTemplateCode()); $copy->setDecorate($page->getDecorate()); $copy->setPosition($page->getPosition()); $copy->setRequestMethod($page->getRequestMethod()); $copy->setHeaders($page->getHeaders()); $copy->setSite($page->getSite()); $copy->setRawHeaders($page->getRawHeaders()); $copy->setEdited($page->getEdited()); $copy->setTitle($page->getTitle()); $copy->setParent($parentPage ? $parentPage : $page->getParent()); foreach ($page->getTranslations() as $translation) { $translationCopy = $this->deepCopyPageTranslation($translation, $copy); $copy->addTranslation($translationCopy); } foreach ($page->getBlocks() as $block) { if (!$block->getParent()) { $blockCopy = $this->deepCopyBlock($block, $copy); $this->entityManager->persist($blockCopy); } } $this->entityManager->persist($copy); return $copy; }
/** * Test the $page if it matches the $url * * @param Page $page * @param $url * @return bool */ protected function matches(Page $page, $url) { $purl = $page->getUrl(); $pattern = '#^' . $purl . '$#'; preg_match_all('/{[a-z]+}/', $purl, $matches); $tokens = $matches[0]; foreach ($tokens as $token) { $pattern = preg_replace('/' . $token . '/', '(.+)', $pattern); } if (preg_match($pattern, $url, $matches)) { // remove brackets from tokens $tokens = array_map(function ($a) { return substr($a, 1, -1); }, $tokens); // remove first (whole) match array_shift($matches); $page->parameters = array_combine($tokens, $matches); return true; } return false; }