From 1ab54993baebe12a47879e2224a7e070cf3a160b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20H=C3=A9lias?= Date: Thu, 29 Aug 2024 15:46:19 +0200 Subject: [PATCH] Add Stringable on storage attributes --- src/DirectoryAttributes.php | 7 ++++++- src/FileAttributes.php | 7 ++++++- src/StorageAttributes.php | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/DirectoryAttributes.php b/src/DirectoryAttributes.php index 3fe44c1b4..02533c610 100644 --- a/src/DirectoryAttributes.php +++ b/src/DirectoryAttributes.php @@ -4,7 +4,7 @@ namespace League\Flysystem; -class DirectoryAttributes implements StorageAttributes +class DirectoryAttributes implements StorageAttributes, \Stringable { use ProxyArrayAccessToProperties; private string $type = StorageAttributes::TYPE_DIRECTORY; @@ -84,4 +84,9 @@ public function jsonSerialize(): array StorageAttributes::ATTRIBUTE_EXTRA_METADATA => $this->extraMetadata, ]; } + + public function __toString(): string + { + return sprintf('%s(%s)', $this->type, $this->path); + } } diff --git a/src/FileAttributes.php b/src/FileAttributes.php index 42172f8c4..a2be0429a 100644 --- a/src/FileAttributes.php +++ b/src/FileAttributes.php @@ -4,7 +4,7 @@ namespace League\Flysystem; -class FileAttributes implements StorageAttributes +class FileAttributes implements StorageAttributes, \Stringable { use ProxyArrayAccessToProperties; private string $type = StorageAttributes::TYPE_FILE; @@ -97,4 +97,9 @@ public function jsonSerialize(): array StorageAttributes::ATTRIBUTE_EXTRA_METADATA => $this->extraMetadata, ]; } + + public function __toString(): string + { + return sprintf('%s(%s)', $this->type, $this->path); + } } diff --git a/src/StorageAttributes.php b/src/StorageAttributes.php index 6be6235bd..aebde8071 100644 --- a/src/StorageAttributes.php +++ b/src/StorageAttributes.php @@ -7,6 +7,9 @@ use ArrayAccess; use JsonSerializable; +/** + * @method string __toString() Stringable interface will be added in 4.0 + */ interface StorageAttributes extends JsonSerializable, ArrayAccess { public const ATTRIBUTE_PATH = 'path';