Inheritance: extends JsonSerializable
 public function testNodeDelete()
 {
     $this->deleteEvent->getStructures()->willReturn([$this->structure]);
     $this->handler->invalidateStructure($this->structure->reveal())->shouldBeCalled();
     $this->subscriber->onContentNodePreDelete($this->deleteEvent->reveal());
     $this->subscriber->onContentNodePostDelete($this->deleteEvent->reveal());
 }
示例#2
0
 /**
  * Returns a rendered structure.
  *
  * @param StructureInterface $structure The structure, which has been loaded for rendering
  * @param array $attributes Additional attributes, which will be passed to twig
  * @param bool $preview Defines if the site is rendered in preview mode
  * @param bool $partial Defines if only the content block of the template should be rendered
  *
  * @return Response
  */
 protected function renderStructure(StructureInterface $structure, $attributes = [], $preview = false, $partial = false)
 {
     // extract format twig file
     if (!$preview) {
         $request = $this->getRequest();
         $requestFormat = $request->getRequestFormat();
     } else {
         $requestFormat = 'html';
     }
     $viewTemplate = $structure->getView() . '.' . $requestFormat . '.twig';
     try {
         // get attributes to render template
         $data = $this->getAttributes($attributes, $structure, $preview);
         // if partial render only content block else full page
         if ($partial) {
             $content = $this->renderBlock($viewTemplate, 'content', $data);
         } else {
             $content = parent::renderView($viewTemplate, $data);
         }
         return new Response($content);
     } catch (InvalidArgumentException $e) {
         // template not found
         throw new HttpException(406, 'Error encountered when rendering content', $e);
     }
 }
示例#3
0
 /**
  * extracts sequence information from property name.
  *
  * @param StructureInterface $content
  * @param string             $property sequence like (block,1,title,0)
  *
  * @return array|bool
  */
 public function getSequence(StructureInterface $content, $property)
 {
     if (false !== strpos($property, ',')) {
         $sequence = explode(',', $property);
         $propertyPath = [];
         $indexSequence = [];
         $propertyInstance = $content->getProperty($sequence[0]);
         for ($i = 1; $i < sizeof($sequence); ++$i) {
             // is not integer
             if (!ctype_digit(strval($sequence[$i]))) {
                 $propertyPath[] = $sequence[$i];
                 if ($propertyInstance instanceof BlockPropertyInterface) {
                     $lastIndex = $indexSequence[sizeof($indexSequence) - 1];
                     unset($indexSequence[sizeof($indexSequence) - 1]);
                     $indexSequence = array_values($indexSequence);
                     $propertyInstance = $propertyInstance->getProperties($lastIndex)->getProperty($sequence[$i]);
                 }
             } else {
                 $indexSequence[] = intval($sequence[$i]);
             }
         }
         return ['sequence' => $sequence, 'propertyPath' => $propertyPath, 'property' => $propertyInstance, 'index' => $indexSequence];
     }
     return false;
 }
示例#4
0
 public function testDisableCache()
 {
     // disable cache
     $this->structure->getCacheLifeTime()->willReturn(0);
     $this->response->setPublic()->shouldNotBeCalled();
     $this->response->setMaxAge($this->maxAge)->shouldNotBeCalled();
     $this->response->setSharedMaxAge($this->sharedMaxAge)->shouldNotBeCalled();
     $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal());
 }
示例#5
0
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     $tags = [$this->getBanKey($structure->getUuid())];
     foreach ($structure->getProperties(true) as $property) {
         foreach ($this->getReferencedUuids($property) as $uuid) {
             $tags[] = $this->getBanKey($uuid);
         }
     }
     $response->headers->set(self::TAGS_HEADER, implode(',', $tags));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->contactManager = $this->prophesize(ContactManagerInterface::class);
     $this->accountManager = $this->prophesize(ContactManagerInterface::class);
     $this->node = $this->prophesize(Node::class);
     $this->property = $this->prophesize(PropertyInterface::class);
     $this->structure = $this->prophesize(StructureInterface::class);
     $this->structure->getLanguageCode()->willReturn($this->locale);
     $this->structure->getWebspaceKey()->willReturn($this->webspaceKey);
     $this->property->getStructure()->willReturn($this->structure->reveal());
     $this->serializer = $this->prophesize(Serializer::class);
 }
示例#7
0
 /**
  * {@inheritDoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + intval($structure->getCacheLifeTime()) : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
 /**
  * Returns and caches excerpt-structure.
  *
  * @return StructureInterface
  */
 private function getExcerptStructure()
 {
     if ($this->excerptStructure === null) {
         $this->excerptStructure = $this->structureManager->getStructure(self::EXCERPT_EXTENSION_NAME);
         $this->excerptStructure->setLanguageCode($this->languageCode);
     }
     return $this->excerptStructure;
 }
 /**
  * @dataProvider provideLifecycle
  */
 public function testLifecycle($options, $shouldInvalidate)
 {
     if ($options['has_structure']) {
         $this->request->attributes->set('structure', $this->structure->reveal());
     }
     if ($options['preview']) {
         $this->request->query->set('preview', true);
     }
     $this->filterResponseEvent->getResponse()->willReturn($this->response);
     $this->filterResponseEvent->getRequest()->willReturn($this->request);
     $this->filterResponseEvent->isMasterRequest()->willReturn($options['is_master_request']);
     $invalidateProphecy = $this->handler->updateResponse($this->response, Argument::any());
     if ($shouldInvalidate) {
         $invalidateProphecy->shouldBeCalled();
     } else {
         $invalidateProphecy->shouldNotBeCalled();
     }
     $this->subscriber->onResponse($this->filterResponseEvent->reveal());
 }
示例#10
0
 /**
  * {@inheritdoc}
  */
 public function updateResponse(Response $response, StructureInterface $structure)
 {
     if (!$structure instanceof PageInterface) {
         return;
     }
     $cacheLifetimeData = $structure->getCacheLifeTime();
     $cacheLifetime = $this->cacheLifetimeResolver->resolve($cacheLifetimeData['type'], $cacheLifetimeData['value']);
     // when structure cache-lifetime disabled - return
     if (0 === $cacheLifetime) {
         return;
     }
     // mark the response as either public or private
     $response->setPublic();
     // set the private and shared max age
     $response->setMaxAge($this->maxAge);
     $response->setSharedMaxAge($this->sharedMaxAge);
     $proxyTtl = $this->usePageTtl ? $response->getAge() + $cacheLifetime : $response->getAge();
     // set reverse-proxy TTL (Symfony HttpCache, Varnish, ...)
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $proxyTtl);
 }
示例#11
0
 public function testInvalidate()
 {
     $this->structure->hasTag('sulu.rlp')->willReturn(true);
     $this->structure->getPropertyValueByTagName('sulu.rlp')->willReturn('/path/to');
     $this->structure->getLanguageCode()->willReturn($this->languageCode);
     $this->structure->getWebspaceKey()->willReturn($this->webspaceKey);
     $urls = ['/path/to/1', '/path/to/2'];
     $this->webspaceManager->findUrlsByResourceLocator('/path/to', $this->env, $this->languageCode, $this->webspaceKey)->willReturn($urls);
     $this->proxyClient->purge($urls[0])->shouldBeCalled();
     $this->proxyClient->purge($urls[1])->shouldBeCalled();
     $this->proxyClient->flush()->shouldBeCalled();
     $this->webspaceManager->findUrlsByResourceLocator(Argument::any())->shouldNotBeCalled();
     $this->handler->invalidateStructure($this->structure->reveal());
     $this->handler->flush();
 }
示例#12
0
 /**
  * checks if content should be displayed.
  *
  * @param StructureInterface $content
  * @param string|null        $context
  *
  * @return bool
  */
 public function inNavigation(StructureInterface $content, $context = null)
 {
     $contexts = $content->getNavContexts();
     if ($content->getNodeState() !== Structure::STATE_PUBLISHED) {
         // if node state is not published do not show page
         return false;
     }
     if (is_array($contexts) && ($context === null || in_array($context, $contexts))) {
         // all contexts or content has context
         return true;
     }
     // do not show
     return false;
 }
示例#13
0
 public function testUpdateResponse()
 {
     $this->handler1->updateResponse($this->response->reveal(), $this->structure->reveal())->shouldBeCalled();
     $this->handler2->updateResponse($this->response->reveal(), $this->structure->reveal())->shouldBeCalled();
     $this->handler->updateResponse($this->response->reveal(), $this->structure->reveal());
 }
示例#14
0
 /**
  * returns finished Node (with _links and _embedded).
  *
  * @param StructureInterface $structure
  * @param string             $webspaceKey
  * @param string             $languageCode
  * @param int                $depth
  * @param bool               $complete
  * @param bool               $excludeGhosts
  * @param string|null        $extension
  *
  * @return array
  */
 protected function prepareNode(StructureInterface $structure, $webspaceKey, $languageCode, $depth = 1, $complete = true, $excludeGhosts = false, $extension = null)
 {
     $result = $structure->toArray($complete);
     // add default embedded property with empty nodes array
     $result['_embedded'] = [];
     $result['_embedded']['nodes'] = [];
     // add api links
     $result['_links'] = ['self' => ['href' => $this->apiBasePath . '/' . $structure->getUuid() . ($extension !== null ? '/' . $extension : '')], 'children' => ['href' => $this->apiBasePath . '?parent=' . $structure->getUuid() . '&depth=' . $depth . '&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '')]];
     return $result;
 }
示例#15
0
 /**
  * {@inheritdoc}
  */
 public function load(NodeInterface $node, $webspaceKey, $languageCode)
 {
     $data = [];
     foreach ($this->excerptStructure->getProperties() as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $contentType->read($node, new TranslatedProperty($property, $languageCode . '-' . $this->additionalPrefix, $this->languageNamespace), $webspaceKey, $languageCode, null);
         $data[$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
示例#16
0
 /**
  * returns finished Node (with _links and _embedded).
  *
  * @param StructureInterface $structure
  * @param string $webspaceKey
  * @param string $languageCode
  * @param int $depth
  * @param bool $complete
  * @param bool $excludeGhosts
  * @param string|null $extension
  *
  * @return array
  *
  * @deprecated This part should be split into a serialization handler and using the hateoas bundle
  */
 protected function prepareNode(StructureInterface $structure, $webspaceKey, $languageCode, $depth = 1, $complete = true, $excludeGhosts = false, $extension = null)
 {
     $result = $structure->toArray($complete);
     // add default embedded property with empty nodes array
     $result['_embedded'] = [];
     $result['_embedded']['nodes'] = [];
     // add api links
     $result['_links'] = ['self' => ['href' => $this->apiBasePath . '/' . $structure->getUuid() . ($extension !== null ? '/' . $extension : '')], 'children' => ['href' => $this->apiBasePath . '?parent=' . $structure->getUuid() . '&depth=' . $depth . '&webspace=' . $webspaceKey . '&language=' . $languageCode . ($excludeGhosts === true ? '&exclude-ghosts=true' : '')]];
     if ($this->tokenStorage && ($token = $this->tokenStorage->getToken())) {
         $result['_permissions'] = $this->accessControlManager->getUserPermissions(new SecurityCondition('sulu.webspaces.' . $webspaceKey, $languageCode, SecurityBehavior::class, $structure->getUuid()), $token->getUser());
     }
     return $result;
 }
示例#17
0
 private function copyNode($srcLocale, $destLocale, StructureInterface $structure, $overwrite = false)
 {
     if (!$overwrite) {
         $destStructure = $this->contentMapper->load($structure->getUuid(), null, $destLocale, true);
         if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) {
             $this->output->writeln('<info>Processing aborted: </info>' . $structure->getNodeName() . ' <comment>(use overwrite option to force)</comment>');
             return;
         }
     }
     $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), null, $srcLocale, $destLocale, Structure::TYPE_SNIPPET);
     $this->output->writeln('<info>Processing: </info>' . $structure->getNodeName());
 }
 private function copyNode($webspaceKey, $srcLocale, $destLocale, StructureInterface $structure, $overwrite = false)
 {
     if (!$overwrite) {
         $destStructure = $this->contentMapper->load($structure->getUuid(), $webspaceKey, $destLocale, true);
         if (!($destStructure->getType() && $destStructure->getType()->getName() === 'ghost')) {
             $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(use overwrite option to force)</comment>');
             return;
         }
     }
     if ($structure->getType() && $structure->getType()->getName() === 'ghost') {
         $this->output->writeln('<info>Processing aborted: </info>' . $structure->getPath() . ' <comment>(source language does not exist)</comment>');
         return;
     }
     try {
         $this->contentMapper->copyLanguage($structure->getUuid(), $structure->getChanger(), $webspaceKey, $srcLocale, $destLocale);
         $this->output->writeln('<info>Processing: </info>' . $structure->getPath());
     } catch (ResourceLocatorAlreadyExistsException $e) {
         $this->output->writeln(sprintf('<info>Processing aborted: </info> %s <comment>Resource Locator "%s" already exists', $structure->getPath(), $structure->getResourceLocator()));
     }
 }
示例#19
0
 public function indexCallback(StructureInterface $structure, $preview = false, $partial = false)
 {
     return new Response($this->render($structure->getPropertyValue('title'), $structure->getPropertyValue('article'), $structure->getPropertyValue('block'), $partial));
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 public function copyFrom(StructureInterface $structure)
 {
     foreach ($this->getProperties(true) as $property) {
         if ($structure->hasProperty($property->getName())) {
             $property->setValue($structure->getPropertyValue($property->getName()));
         }
     }
     $this->setDocument($structure->getDocument());
 }
 /**
  * @param StructureInterface $structure
  * @param array              $parts
  * @param string             $separator default '-'
  *
  * @return string
  */
 private function implodeRlpParts(StructureInterface $structure, array $parts, $separator = '-')
 {
     $title = '';
     // concat rlp parts in sort of priority
     foreach ($structure->getPropertiesByTagName('sulu.rlp.part') as $property) {
         $title = $parts[$property->getName()] . $separator . $title;
     }
     $title = substr($title, 0, -1);
     return $title;
 }
示例#22
0
 /**
  * Returns select of a single structure with title and url selector.
  */
 private function buildSelectForStructure($locale, StructureInterface $structure, &$names)
 {
     $nodeNameProperty = $structure->getProperty('title');
     $result = '';
     $name = $this->getTranslatedProperty($nodeNameProperty, $locale)->getName();
     if (!in_array($name, $names)) {
         $names[] = $name;
         $result .= ', ' . $this->buildSelector($name);
     }
     if ($structure->hasTag('sulu.rlp')) {
         $urlProperty = $structure->getPropertyByTagName('sulu.rlp');
         $name = $this->getTranslatedProperty($urlProperty, $locale)->getName();
         if ($urlProperty->getContentTypeName() !== 'resource_locator' && !in_array($name, $names)) {
             $names[] = $name;
             $result .= ', ' . $this->buildSelector($name);
         }
     }
     return $result;
 }
示例#23
0
 /**
  * {@inheritDoc}
  */
 public function resolve(StructureInterface $structure)
 {
     $data = ['view' => [], 'content' => [], 'uuid' => $structure->getUuid(), 'creator' => $structure->getCreator(), 'changer' => $structure->getChanger(), 'created' => $structure->getCreated(), 'changed' => $structure->getChanged(), 'template' => $structure->getKey(), 'path' => $structure->getPath()];
     if ($structure instanceof PageBridge) {
         $data['extension'] = $structure->getExt()->toArray();
         $data['urls'] = $structure->getUrls();
         $data['published'] = $structure->getPublished();
         $data['shadowBaseLocale'] = $structure->getShadowBaseLanguage();
         foreach ($data['extension'] as $name => $value) {
             $extension = $this->structureManager->getExtension($structure->getKey(), $name);
             $data['extension'][$name] = $extension->getContentData($value);
         }
     }
     foreach ($structure->getProperties(true) as $property) {
         $contentType = $this->contentTypeManager->get($property->getContentTypeName());
         $data['view'][$property->getName()] = $contentType->getViewData($property);
         $data['content'][$property->getName()] = $contentType->getContentData($property);
     }
     return $data;
 }
示例#24
0
 /**
  * @param Request            $request
  * @param StructureInterface $content
  *
  * @return Route
  */
 protected function getStructureRoute(Request $request, $content)
 {
     return new Route($request->getPathInfo(), ['_controller' => $content->getController(), 'structure' => $content]);
 }
示例#25
0
文件: Structure.php 项目: sulu/sulu
 /**
  * {@inheritdoc}
  */
 public function copyFrom(StructureInterface $structure)
 {
     $this->setWebspaceKey($structure->getWebspaceKey());
     $this->setLanguageCode($structure->getLanguageCode());
     $this->setUuid($structure->getUuid());
     $this->setChanged($structure->getChanged());
     $this->setChanger($structure->getChanger());
     $this->setCreated($structure->getCreated());
     $this->setCreator($structure->getCreator());
     $this->setPublished($structure->getPublished());
     $this->setPath($structure->getPath());
     $this->setNodeType($structure->getNodeType());
     $this->setHasTranslation($structure->getHasTranslation());
 }