cleanup() public method

returns a clean string.
public cleanup ( string $dirty, string $languageCode = null ) : string
$dirty string dirty string to cleanup
$languageCode string
return string clean string
Ejemplo n.º 1
0
 /**
  * returns whole path for given ContentNode.
  *
  * @param string $title        title of new node
  * @param string $parentPath   parent path of new contentNode
  * @param string $webspaceKey  key of portal
  * @param string $languageCode
  * @param string $segmentKey
  *
  * @return string whole path
  */
 public function generate($title, $parentPath, $webspaceKey, $languageCode, $segmentKey = null)
 {
     // title should not have a slash
     $title = str_replace('/', '-', $title);
     // get generated path from childClass
     $path = $this->generatePath($title, $parentPath);
     // cleanup path
     $path = $this->cleaner->cleanup($path, $languageCode);
     // get unique path
     $path = $this->mapper->getUniquePath($path, $webspaceKey, $languageCode, $segmentKey);
     return $path;
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider provideSpecialCharacterFileName
  */
 public function testSpecialCharacterFileName($fileName, $cleanUpArgument)
 {
     /** @var UploadedFile $uploadedFile */
     $uploadedFile = $this->prophesize(UploadedFile::class)->willBeConstructedWith(['', 1, null, null, 1, true]);
     $uploadedFile->getClientOriginalName()->willReturn($fileName);
     $uploadedFile->getPathname()->willReturn('');
     $uploadedFile->getSize()->willReturn('123');
     $uploadedFile->getMimeType()->willReturn('img');
     $user = $this->prophesize(User::class)->willImplement(UserInterface::class);
     $this->userRepository->findUserById(1)->willReturn($user);
     $this->pathCleaner->cleanup(Argument::exact($cleanUpArgument))->shouldBeCalled();
     $this->mediaManager->save($uploadedFile->reveal(), ['locale' => 'en', 'title' => 'my title'], 1);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function generate($title, $parentUuid, $webspaceKey, $languageCode, $segmentKey = null)
 {
     // title should not have a slash
     $title = str_replace('/', '-', $title);
     if ($parentUuid !== null) {
         $parentDocument = $this->documentManager->find($parentUuid, $languageCode, ['load_ghost_content' => false]);
         // find uuid of published ancestor for generating parent-path-segment
         $resolvedParentUuid = $this->documentInspector->getUuid($this->getPublishedAncestorOrSelf($parentDocument));
         // using loadByContentUuid because loadByContent returns the wrong language for shadow-pages
         $parentPath = $this->loadByContentUuid($resolvedParentUuid, $webspaceKey, $languageCode);
     } else {
         $parentPath = '/';
     }
     // get generated path from childClass
     $path = $this->resourceLocatorGenerator->generate($title, $parentPath);
     // cleanup path
     $path = $this->cleaner->cleanup($path, $languageCode);
     // get unique path
     $path = $this->mapper->getUniquePath($path, $webspaceKey, $languageCode, $segmentKey);
     return $path;
 }
Ejemplo n.º 4
0
 /**
  * Returns file name without special characters and preserves file extension.
  *
  * @param $originalFileName
  *
  * @return string
  */
 private function getNormalizedFileName($originalFileName)
 {
     if (strpos($originalFileName, '.') !== false) {
         $pathParts = pathinfo($originalFileName);
         $fileName = $this->pathCleaner->cleanup($pathParts['filename']);
         $fileName .= '.' . $pathParts['extension'];
     } else {
         $fileName = $this->pathCleaner->cleanup($originalFileName);
     }
     return $fileName;
 }