diff --git a/src/helpers.php b/src/helpers.php index 80103780b3..5b21de4cf9 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -5,11 +5,22 @@ use Roots\Sage\Template\WrapperCollection; use Roots\Sage\Template\WrapperInterface; +/** + * @param WrapperInterface $wrapper + * @param string $slug + * @return string + * @throws \Exception + * @SuppressWarnings(PHPMD.StaticAccess) This is a helper function, so we can suppress this warning + */ function template_wrap(WrapperInterface $wrapper, $slug = 'base') { WrapperCollection::add($wrapper, $slug); return $wrapper->getWrapper(); } +/** + * @param string $slug + * @return string + */ function template_unwrap($slug = 'base') { return WrapperCollection::get($slug)->getTemplate(); } diff --git a/src/lib/Sage/Template/WrapperCollection.php b/src/lib/Sage/Template/WrapperCollection.php index c1a46e28d6..06437d3d99 100644 --- a/src/lib/Sage/Template/WrapperCollection.php +++ b/src/lib/Sage/Template/WrapperCollection.php @@ -30,14 +30,13 @@ public static function instance() /** * @param WrapperInterface $wrapper * @param string $slug - * @param bool $overwriteIfExists * @return $this * @throws \Exception */ - public static function add(WrapperInterface $wrapper, $slug = '', $overwriteIfExists = false) + public static function add(WrapperInterface $wrapper, $slug = '') { $slug = $slug ?: $wrapper->getSlug(); - if (self::instance()->exists($slug) && !$overwriteIfExists) { + if (self::instance()->exists($slug)) { throw new \Exception("Wrapper $slug already exists."); } self::instance()->wrappers[$slug] = $wrapper;