diff --git a/CHANGELOG.md b/CHANGELOG.md index a727c20a3..4beeb2748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ 1. [](#new) * Added `Uri::method()` to get current HTTP method (GET/POST etc) - * Added `FormatterInterface::getSupportedFileExtensions()` method, deprecated `getFileExtension()` + * `FormatterInterface`: Added `getSupportedFileExtensions()` and `getDefaultFileExtension()` methods # v1.5.0-rc.1 ## 07/31/2018 diff --git a/system/src/Grav/Framework/File/Formatter/FormatterInterface.php b/system/src/Grav/Framework/File/Formatter/FormatterInterface.php index 35ceccfde..273bf7873 100644 --- a/system/src/Grav/Framework/File/Formatter/FormatterInterface.php +++ b/system/src/Grav/Framework/File/Formatter/FormatterInterface.php @@ -10,6 +10,15 @@ namespace Grav\Framework\File\Formatter; interface FormatterInterface { + /** + * Get default file extension from current formatter (with dot). + * + * Default file extension is the first defined extension. + * + * @return string File extension (can be empty). + */ + public function getDefaultFileExtension(); + /** * Get file extensions supported by current formatter (with dot). * diff --git a/system/src/Grav/Framework/File/Formatter/IniFormatter.php b/system/src/Grav/Framework/File/Formatter/IniFormatter.php index 15d67c4e2..f79e007c2 100644 --- a/system/src/Grav/Framework/File/Formatter/IniFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/IniFormatter.php @@ -25,12 +25,21 @@ class IniFormatter implements FormatterInterface } /** - * @deprecated - * @internal + * @deprecated 1.5 Use $formatter->getDefaultFileExtension() instead. */ public function getFileExtension() { - return $this->getSupportedFileExtensions()[0]; + return $this->getDefaultFileExtension(); + } + + /** + * {@inheritdoc} + */ + public function getDefaultFileExtension() + { + $extensions = $this->getSupportedFileExtensions(); + + return (string) reset($extensions); } /** diff --git a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php index bd01b8307..f5705e381 100644 --- a/system/src/Grav/Framework/File/Formatter/JsonFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/JsonFormatter.php @@ -23,12 +23,21 @@ class JsonFormatter implements FormatterInterface } /** - * @deprecated - * @internal + * @deprecated 1.5 Use $formatter->getDefaultFileExtension() instead. */ public function getFileExtension() { - return $this->getSupportedFileExtensions()[0]; + return $this->getDefaultFileExtension(); + } + + /** + * {@inheritdoc} + */ + public function getDefaultFileExtension() + { + $extensions = $this->getSupportedFileExtensions(); + + return (string) reset($extensions); } /** diff --git a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php index c38f691f1..9cccba990 100644 --- a/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/MarkdownFormatter.php @@ -29,12 +29,21 @@ class MarkdownFormatter implements FormatterInterface } /** - * @deprecated - * @internal + * @deprecated 1.5 Use $formatter->getDefaultFileExtension() instead. */ public function getFileExtension() { - return $this->getSupportedFileExtensions()[0]; + return $this->getDefaultFileExtension(); + } + + /** + * {@inheritdoc} + */ + public function getDefaultFileExtension() + { + $extensions = $this->getSupportedFileExtensions(); + + return (string) reset($extensions); } /** diff --git a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php index 95744104c..5fd20eb89 100644 --- a/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/SerializeFormatter.php @@ -25,12 +25,21 @@ class SerializeFormatter implements FormatterInterface } /** - * @deprecated - * @internal + * @deprecated 1.5 Use $formatter->getDefaultFileExtension() instead. */ public function getFileExtension() { - return $this->getSupportedFileExtensions()[0]; + return $this->getDefaultFileExtension(); + } + + /** + * {@inheritdoc} + */ + public function getDefaultFileExtension() + { + $extensions = $this->getSupportedFileExtensions(); + + return (string) reset($extensions); } /** diff --git a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php index ee18061ea..858fbea5f 100644 --- a/system/src/Grav/Framework/File/Formatter/YamlFormatter.php +++ b/system/src/Grav/Framework/File/Formatter/YamlFormatter.php @@ -30,12 +30,21 @@ class YamlFormatter implements FormatterInterface } /** - * @deprecated - * @internal + * @deprecated 1.5 Use $formatter->getDefaultFileExtension() instead. */ public function getFileExtension() { - return $this->getSupportedFileExtensions()[0]; + return $this->getDefaultFileExtension(); + } + + /** + * {@inheritdoc} + */ + public function getDefaultFileExtension() + { + $extensions = $this->getSupportedFileExtensions(); + + return (string) reset($extensions); } /**