cleanDirname() public static method

Get the directory name of path, trimming unecessary . and / characters.
public static cleanDirname ( string $path ) : string
$path string
return string
Example #1
0
 public function test_it_provides_a_cleaned_dirname()
 {
     $this->assertEquals('', File::cleanDirname(''));
     $this->assertEquals('', File::cleanDirname('/'));
     $this->assertEquals('', File::cleanDirname('foo.jpg'));
     $this->assertEquals('foo', File::cleanDirname('/foo/bar/'));
     $this->assertEquals('foo/bar', File::cleanDirname('/foo/bar/baz.jpg'));
 }
 /**
  * Search through the record list for one matching the provided path.
  * @param  string $path
  * @param  \Illuminate\Database\Eloquent\Collection $existing_media
  * @return \Plank\Mediable\Media|null
  */
 protected function getRecordForFile($path, $existing_media)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $existing_media->filter(function (Media $media) use($directory, $filename, $extension) {
         return $media->directory == $directory && $media->filename == $filename && $media->extension == $extension;
     })->first();
 }
Example #3
0
 /**
  * Create a `Media` record for a file already on a disk.
  * @param  string $disk
  * @param  string $path Path to file, relative to disk root
  * @return \Plank\Mediable\Media
  */
 public function importPath($disk, $path)
 {
     $directory = File::cleanDirname($path);
     $filename = pathinfo($path, PATHINFO_FILENAME);
     $extension = pathinfo($path, PATHINFO_EXTENSION);
     return $this->import($disk, $directory, $filename, $extension);
 }
Example #4
0
 /**
  * Query scope finding media at a path relative to a disk.
  * @param  \Illuminate\Database\Eloquent\Builder $q
  * @param  string                                $disk
  * @param  string                                $path directory, filename and extension
  * @return void
  */
 public function scopeForPathOnDisk(Builder $q, $disk, $path)
 {
     $q->where('disk', $disk)->where('directory', File::cleanDirname($path))->where('filename', pathinfo($path, PATHINFO_FILENAME))->where('extension', pathinfo($path, PATHINFO_EXTENSION));
 }