Skip to content

Commit

Permalink
introduce apply
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Sep 14, 2024
1 parent 6ab58ec commit 4010420
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Concerns/HasSeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface HasSeo
{
public function getSeo(): SeoManager;
public function applySeo(SeoManager $manager): SeoManager;
}
35 changes: 35 additions & 0 deletions src/SeoManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4010420

Please sign in to comment.