Webmozart\PathUtil\Path::getFilename PHP Method

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.
    public static function getFilename($path)
    {
        if ('' === $path) {
            return '';
        }
        Assert::string($path, 'The path must be a string. Got: %s');
        return basename($path);
    }

Usage Example

Ejemplo 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);
 }
All Usage Examples Of Webmozart\PathUtil\Path::getFilename