public function testGetSet() { $uriContext = new UriContext($this->subjectObject, '/uri/', array('default1' => 'value1'), array('token'), array('conflict'), 'fr'); // locales $this->assertEquals('fr', $uriContext->getLocale()); /// uri $this->assertEquals(null, $uriContext->getUri()); $uriContext->setUri('/foo/bar'); $this->assertEquals('/foo/bar', $uriContext->getUri()); // subject object $this->assertEquals($this->subjectObject, $uriContext->getSubjectObject()); // auto route $uriContext->setAutoRoute($this->autoRoute); $this->assertEquals($this->autoRoute, $uriContext->getAutoRoute()); // the translated subject should be initially set as the original subject $this->assertSame($this->subjectObject, $uriContext->getTranslatedSubjectObject()); $transSubject = new \stdClass(); $uriContext->setTranslatedSubjectObject($transSubject); $this->assertSame($transSubject, $uriContext->getTranslatedSubjectObject()); // uri schema $this->assertEquals('/uri/', $uriContext->getUriSchema()); // token provider configs $this->assertEquals(array('token'), $uriContext->getTokenProviderConfigs()); // conflict resolver configs $this->assertEquals(array('conflict'), $uriContext->getConflictResolverConfig()); // defaults $this->assertEquals(array('default1' => 'value1'), $uriContext->getDefaults()); }
/** * {@inheritdoc} */ public function provideValue(UriContext $uriContext, $options) { $object = $uriContext->getSubjectObject(); $method = $options['method']; $this->checkMethodExists($object, $method); return $this->normalizeValue($object->{$method}(), $uriContext, $options); }
/** * {@inheritdoc} */ protected function normalizeValue($date, UriContext $uriContext, $options) { if (!$date instanceof \DateTime) { throw new \RuntimeException(sprintf('Method %s:%s must return an instance of DateTime.', get_class($uriContext->getSubjectObject()), $options['method'])); } return $date->format($options['date_format']); }
/** * {@inheritDoc} */ public function resolveConflict(UriContext $uriContext) { $realClassName = $this->driver->getRealClassName(get_class($uriContext->getSubjectObject())); $metadata = $this->metadataFactory->getMetadataForClass($realClassName); $conflictResolverConfig = $metadata->getConflictResolver(); $conflictResolver = $this->serviceRegistry->getConflictResolver($conflictResolverConfig['name'], $conflictResolverConfig['options']); $uri = $conflictResolver->resolveConflict($uriContext); return $uri; }
/** * {@inheritDoc} */ public function provideValue(UriContext $uriContext, $options) { $object = $uriContext->getSubjectObject(); $method = $options['method']; $this->checkMethodExists($object, $method); $value = $object->{$method}(); if ($options['slugify']) { $value = $this->slugifier->slugify($value); } return $value; }
/** * {@inheritDoc} */ public function provideValue(UriContext $uriContext, $options) { $object = $uriContext->getSubjectObject(); $method = $options['method']; $this->checkMethodExists($object, $method); $date = $object->{$method}(); if (!$date instanceof \DateTime) { throw new \RuntimeException(sprintf('Method %s:%s must return an instance of DateTime.', get_class($object), $method)); } $string = $date->format($options['date_format']); return $string; }
/** * Return a token value for the given configuration and * document. * * @param UriContext $uriContext * @param array $options * @return string */ public function provideValue(UriContext $uriContext, $options) { $path = array(); $subject = $uriContext->getSubjectObject(); $this->traversePath($subject, $path); if (empty($path)) { return ''; } $path = array_map(function ($item) { return $this->slugifier->slugify($item); }, $path); $path = array_reverse($path); return implode('/', $path); }
public function testGetSet() { $uriContext = new UriContext($this->subjectObject, 'fr'); // locales $this->assertEquals('fr', $uriContext->getLocale()); /// uri $this->assertEquals(null, $uriContext->getUri()); $uriContext->setUri('/foo/bar'); $this->assertEquals('/foo/bar', $uriContext->getUri()); // subject object $this->assertEquals($this->subjectObject, $uriContext->getSubjectObject()); // auto route $uriContext->setAutoRoute($this->autoRoute); $this->assertEquals($this->autoRoute, $uriContext->getAutoRoute()); }
/** * Handle the case where the generated path already exists. * Either if it does not reference the same content then we * have a conflict which needs to be resolved. * * @param Route $route * @param UriContext $uriContext */ private function handleExistingRoute($existingRoute, $uriContext) { $isSameContent = $this->adapter->compareAutoRouteContent($existingRoute, $uriContext->getSubjectObject()); if ($isSameContent) { $autoRoute = $existingRoute; $autoRoute->setType(AutoRouteInterface::TYPE_PRIMARY); return $autoRoute; } $uri = $this->uriGenerator->resolveConflict($uriContext); $uriContext->setUri($uri); return; }