diff --git a/src/Concerns/HasSeo.php b/src/Concerns/HasSeo.php index 5a45033..96fdb5d 100644 --- a/src/Concerns/HasSeo.php +++ b/src/Concerns/HasSeo.php @@ -6,5 +6,5 @@ interface HasSeo { - public function getSeo(): SeoManager; + public function applySeo(SeoManager $manager): SeoManager; } diff --git a/src/SeoManager.php b/src/SeoManager.php index 80b5a26..4404003 100644 --- a/src/SeoManager.php +++ b/src/SeoManager.php @@ -3,6 +3,7 @@ namespace Elegantly\Seo; use Closure; +use Elegantly\Seo\Concerns\HasSeo; use Elegantly\Seo\Contracts\Taggable; use Elegantly\Seo\OpenGraph\Locale; use Elegantly\Seo\OpenGraph\OpenGraph; @@ -43,6 +44,25 @@ public function current(): static return $this; } + public function apply(HasSeo $class): self + { + return $class->applySeo($this); + } + + /** + * @return $this + */ + public function set(SeoManager $manager): static + { + return $this + ->setStandard($manager->standard) + ->setOpengraph($manager->opengraph) + ->setTwitter($manager->twitter) + ->setWebpage($manager->webpage) + ->setSchemas($manager->schemas) + ->setCustomTags($manager->customTags); + } + /** * @param null|Standard|(Closure(Standard):(null|Standard)) $value * @return $this @@ -118,6 +138,21 @@ public function setSchemas(null|array|Closure $value): static return $this; } + /** + * @param null|SeoTags|(Closure(SeoTags):(null|SeoTags)) $value + * @return $this + */ + public function setCustomTags(null|SeoTags|Closure $value): static + { + if ($value instanceof Closure) { + $this->customTags = $value($this->customTags ?? new SeoTags); + } else { + $this->customTags = $value; + } + + return $this; + } + /** * @return $this */ diff --git a/src/helpers.php b/src/helpers.php index 77688e4..616f666 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -11,7 +11,7 @@ function seo(null|HasSeo|SeoManager $value = null): SeoManager } if ($value instanceof HasSeo) { - return $value->getSeo(); + return \Elegantly\Seo\Facades\SeoManager::current()->apply($value); } return $value;