-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
697 additions
and
43 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Terminal42\NotificationCenterBundle\BulkyItem; | ||
|
||
use Contao\CoreBundle\Filesystem\FilesystemItem; | ||
use Contao\CoreBundle\Filesystem\VirtualFilesystemInterface; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Mime\MimeTypeGuesserInterface; | ||
use Terminal42\NotificationCenterBundle\Exception\BulkyItem\InvalidFileItemException; | ||
|
||
class FileItemFactory | ||
{ | ||
public function __construct(private readonly MimeTypeGuesserInterface|null $mimeTypeGuesser = null) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws InvalidFileItemException if the information cannot be fetched automatically (e.g. missing mime type guesser service) | ||
*/ | ||
public function createFromLocalPath(string $path): FileItem | ||
{ | ||
if (!(new Filesystem())->exists($path)) { | ||
throw new InvalidFileItemException(\sprintf('The file "%s" does not exist.', $path)); | ||
} | ||
|
||
$name = basename($path); | ||
$mimeType = (string) $this->mimeTypeGuesser?->guessMimeType($path); | ||
$size = (int) filesize($path); | ||
|
||
return FileItem::fromPath($path, $name, $mimeType, $size); | ||
} | ||
|
||
/** | ||
* @throws InvalidFileItemException | ||
*/ | ||
public function createFromVfsFilesystemItem(FilesystemItem $file, VirtualFilesystemInterface $virtualFilesystem): FileItem | ||
{ | ||
$stream = $virtualFilesystem->readStream($file->getPath()); | ||
|
||
return FileItem::fromStream($stream, $file->getName(), $file->getMimeType(), $file->getFileSize()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Terminal42\NotificationCenterBundle\Config; | ||
|
||
class FormConfig extends AbstractConfig | ||
{ | ||
} |
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
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Terminal42\NotificationCenterBundle\Exception\BulkyItem; | ||
|
||
class InvalidFileItemException extends \InvalidArgumentException | ||
{ | ||
} |
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.