getFilename() public static method

Returns the file name from a file path.
Since: 1.1 Added method.
Since: 2.0 Method now fails if $path is not a string.
public static getFilename ( string $path ) : string
$path string The path string.
return string The file name.
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function installResource(Resource $resource, InstallationParams $params)
 {
     $targetPath = Path::makeAbsolute($params->getTargetLocation(), $params->getRootDirectory());
     if (!file_exists($targetPath)) {
         mkdir($targetPath, 0777, true);
     }
     $repoPath = $params->getWebPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($targetPath, $this->symlinks, $relative);
     if ('/' === $repoPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($repoPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($repoPath);
     }
     $filesystemRepo->add($repoPath, $resource);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function installResource(PuliResource $resource, InstallationParams $params)
 {
     $documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory());
     if (!file_exists($documentRoot)) {
         mkdir($documentRoot, 0777, true);
     }
     $serverPath = $params->getServerPathForResource($resource);
     $parameterValues = $params->getParameterValues();
     $relative = !isset($parameterValues['relative']) || $parameterValues['relative'];
     $filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative);
     if ('/' === $serverPath) {
         foreach ($resource->listChildren() as $child) {
             $name = $child->getName();
             // If the resource is not attached, the name is empty
             if (!$name && $child instanceof FilesystemResource) {
                 $name = Path::getFilename($child->getFilesystemPath());
             }
             if ($name) {
                 $filesystemRepo->remove($serverPath . '/' . $name);
             }
         }
     } else {
         $filesystemRepo->remove($serverPath);
     }
     // Don't attach the original resource to the repository we just created
     $filesystemRepo->add($serverPath, clone $resource);
 }
Exemplo n.º 3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The path must be a string. Got: array
  */
 public function testGetFilenameFailsIfInvalidPath()
 {
     Path::getFilename(array());
 }
Exemplo n.º 4
0
 /**
  * Return autocomplete data for a file name.
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function filesAutoComplete(Request $request)
 {
     $term = $request->query->get('term', '.*');
     $dir = Path::getDirectory($term);
     $term = Path::getFilename($term);
     $term = preg_quote($term);
     $extensions = implode('|', explode(',', $request->query->get('ext', '.*')));
     $regex = sprintf('/.*(%s).*\\.(%s)$/', $term, $extensions);
     $files = $this->filesystem()->find()->in('files://' . $dir)->name($regex);
     $result = [];
     /** @var \Bolt\Filesystem\Handler\File $file */
     foreach ($files as $file) {
         $result[] = $file->toJs();
     }
     return $this->json($result);
 }
Exemplo n.º 5
0
 /**
  * Sets the absolute file path of the factory class file.
  *
  * @param string $filePath The absolute file path.
  *
  * @return static The current instance.
  */
 public function setFilePath($filePath)
 {
     Assert::stringNotEmpty($filePath, 'The factory file path must be a non-empty string. Got: %s');
     $this->setDirectory(Path::getDirectory($filePath));
     $this->setFileName(Path::getFilename($filePath));
     return $this;
 }