-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
305 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGallerySynchronization\Model\Filesystem; | ||
|
||
/** | ||
* Class for getting image file information. | ||
*/ | ||
class FileInfo | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $path; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $filename; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $extension; | ||
|
||
/** | ||
* @var $basename | ||
*/ | ||
private $basename; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $size; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $mTime; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $cTime; | ||
|
||
/** | ||
* FileInfo constructor. | ||
* | ||
* @param string $path | ||
* @param string $filename | ||
* @param string $extension | ||
* @param string $basename | ||
* @param int $size | ||
* @param int $mTime | ||
* @param int $cTime | ||
*/ | ||
public function __construct( | ||
string $path, | ||
string $filename, | ||
string $extension, | ||
string $basename, | ||
int $size, | ||
int $mTime, | ||
int $cTime | ||
) { | ||
$this->path = $path; | ||
$this->filename = $filename; | ||
$this->extension = $extension; | ||
$this->basename = $basename; | ||
$this->size = $size; | ||
$this->mTime = $mTime; | ||
$this->cTime = $cTime; | ||
} | ||
|
||
/** | ||
* Get path without filename. | ||
* | ||
* @return string | ||
*/ | ||
public function getPath(): string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
/** | ||
* Get filename. | ||
* | ||
* @return string | ||
*/ | ||
public function getFilename(): string | ||
{ | ||
return $this->filename; | ||
} | ||
|
||
/** | ||
* Get file extension. | ||
* | ||
* @return string | ||
*/ | ||
public function getExtension(): string | ||
{ | ||
return $this->extension; | ||
} | ||
|
||
/** | ||
* Get file basename. | ||
* | ||
* @return string | ||
*/ | ||
public function getBasename(): string | ||
{ | ||
return $this->basename; | ||
} | ||
|
||
/** | ||
* Get file size. | ||
* | ||
* @return int | ||
*/ | ||
public function getSize(): int | ||
{ | ||
return $this->size; | ||
} | ||
|
||
/** | ||
* Get last modified time. | ||
* | ||
* @return int | ||
*/ | ||
public function getMTime(): int | ||
{ | ||
return $this->mTime; | ||
} | ||
|
||
/** | ||
* Get inode change time. | ||
* | ||
* @return int | ||
*/ | ||
public function getCTime(): int | ||
{ | ||
return $this->cTime; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGallerySynchronization\Model\Filesystem; | ||
|
||
use Magento\MediaGallerySynchronization\Model\Filesystem\FileInfoFactory; | ||
|
||
/** | ||
* Get file information | ||
*/ | ||
class GetFileInfo | ||
{ | ||
/** | ||
* @var FileInfoFactory | ||
*/ | ||
private $fileInfoFactory; | ||
|
||
/** | ||
* GetFileInfo constructor. | ||
* @param FileInfoFactory $fileInfoFactory | ||
*/ | ||
public function __construct( | ||
FileInfoFactory $fileInfoFactory | ||
) { | ||
$this->fileInfoFactory = $fileInfoFactory; | ||
} | ||
|
||
/** | ||
* Get file information based on path provided. | ||
* | ||
* @param string $path | ||
* @return FileInfo | ||
*/ | ||
public function execute(string $path): FileInfo | ||
{ | ||
$splFileInfo = new \SplFileInfo($path); | ||
|
||
return $this->fileInfoFactory->create([ | ||
'path' => $splFileInfo->getPath(), | ||
'filename' => $splFileInfo->getFilename(), | ||
'extension' => $splFileInfo->getExtension(), | ||
'basename' => $splFileInfo->getBasename('.' . $splFileInfo->getExtension()), | ||
'size' => $splFileInfo->getSize(), | ||
'mTime' => $splFileInfo->getMTime(), | ||
'cTime' => $splFileInfo->getCTime() | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.