/** * @param mixed $object * @param string $routeName #Route * @param string $separator * @param array $query * * @return string */ public function generateObjectUrl($object, $routeName, $separator = '_', array $query = array()) { $parameters = array(); $accessor = PropertyAccess::createPropertyAccessor(); $pattern = $this->router->getRouteCollection()->get($routeName)->getPath(); if (preg_match_all('/\\{([a-z]+)\\}/', $pattern, $matches)) { foreach ($matches[1] as $holder) { $value = $accessor->getValue($object, $holder); if (!is_numeric($value)) { $value = $this->slugify->slugify($value, $separator); } $parameters[$holder] = $value; } } return $this->router->generate($routeName, $parameters, $query); }
/** * {@inheritdoc} */ public function close(Filesystem $filesystem, $label = null) { /** @var ZipArchiveAdapter $adapter */ $adapter = $filesystem->getAdapter(); $filename = $adapter->getArchive()->filename; // close zip file $adapter->getArchive()->close(); $path = sprintf('%s/%s%s.zip', $this->name, date('H-i-s-Y-m-d'), !empty($label) ? '_' . $this->slugify->slugify($label) : ''); $this->localFilesystem->putStream($path, fopen($filename, 'r')); return pathinfo($path, PATHINFO_FILENAME); }
/** * @param string * @param string * * @return string */ public function slugify($string, $separator = '-') { return $this->slugify->slugify($string, $separator); }
/** * @param string $string * @param string|null $separator * * @return string */ public function __invoke($string, $separator = null) { return $this->slugify->slugify($string, $separator); }
public function testRemoteListingNoRemote() { $this->setExpectedException(RemoteStorageNotConfiguredException::class); $storage = new LocalStorage($this->name, $this->temporaryFileSystem->reveal(), $this->slugify->reveal(), $this->filesystem->reveal(), $this->localFilesystem->reveal()); $storage->remoteListing(); }
/** * @param Node $node * @param bool $nonConflict * * @return Route */ public function build(Node $node, $nonConflict = true) { $class = get_class($node); $routeMapping = $this->nodeRouteManager->getNodeMapping($class); $router = $this->nodeRouteManager->getRouter(); $i = 0; $path = null; $fullPath = $node->getPath(); $route = new Route(); $route->setVariablePattern(""); if ($fullPath) { $urlVars = []; $route->setStaticPrefix($fullPath); } else { $route->setStaticPrefix($routeMapping['path']); $compiledRoute = $route->compile(); $urlVars = $compiledRoute->getPathVariables(); } $routeName = 'node_route'; $route->setName($routeName); $routeCollection = new RouteCollection(); $routeCollection->add($routeName, $route); $urlGenerator = new UrlGenerator($routeCollection, new RequestContext('')); $urlVarCount = count($urlVars) - 1; while (true) { $params = []; foreach ($urlVars as $vi => $var) { $method = new \ReflectionMethod($class, "get{$var}"); $value = $method->invoke($node); // if ($i > 0 && $urlVarCount == $vi) { $value .= " {$i}"; } $params[$var] = $this->slugger->slugify($value); } if ($fullPath) { $path = $this->slugify($fullPath, $i); } else { $path = $urlGenerator->generate($routeName, $params); } // if we don't care about conflicts, skip if (!$nonConflict) { break; } ++$i; try { $match = $router->match($path); // if we've fallen back to the original route, stop searching for an existing route, or if we've found // the node's route if (isset($match['nodeId'])) { if ($match['nodeId'] != $node->getId()) { continue; } else { break; } } else { break; } } catch (ResourceNotFoundException $e) { break; } } $route = new Route(); $route->setDefaults(['_controller' => 'Gravity\\CmsBundle\\Controller\\NodeController::viewAction', 'nodeId' => $node->getId(), 'type' => $class]); $route->setVariablePattern(""); $route->setStaticPrefix($path); $route->setName($this->buildRouteName($route)); $node->setPath($path); return $route; }
/** * Slugify filter. * * @param string $string * @param string|null $separator * * @return string */ public function slugifyFilter($string, $separator = null) { return $this->slugify->slugify($string, $separator); }
/** * @test * @covers Cocur\Slugify\Bridge\Twig\SlugifyExtension::slugifyFilter() */ public function slugifyFilter() { $this->slugify->shouldReceive('slugify')->with('hällo wörld', '_')->once()->andReturn('haello_woerld'); $this->assertEquals('haello_woerld', $this->extension->slugifyFilter('hällo wörld', '_')); }