Skip to content

Commit 4010420

Browse files
committed
introduce apply
1 parent 6ab58ec commit 4010420

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Diff for: src/Concerns/HasSeo.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface HasSeo
88
{
9-
public function getSeo(): SeoManager;
9+
public function applySeo(SeoManager $manager): SeoManager;
1010
}

Diff for: src/SeoManager.php

+35
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Elegantly\Seo;
44

55
use Closure;
6+
use Elegantly\Seo\Concerns\HasSeo;
67
use Elegantly\Seo\Contracts\Taggable;
78
use Elegantly\Seo\OpenGraph\Locale;
89
use Elegantly\Seo\OpenGraph\OpenGraph;
@@ -43,6 +44,25 @@ public function current(): static
4344
return $this;
4445
}
4546

47+
public function apply(HasSeo $class): self
48+
{
49+
return $class->applySeo($this);
50+
}
51+
52+
/**
53+
* @return $this
54+
*/
55+
public function set(SeoManager $manager): static
56+
{
57+
return $this
58+
->setStandard($manager->standard)
59+
->setOpengraph($manager->opengraph)
60+
->setTwitter($manager->twitter)
61+
->setWebpage($manager->webpage)
62+
->setSchemas($manager->schemas)
63+
->setCustomTags($manager->customTags);
64+
}
65+
4666
/**
4767
* @param null|Standard|(Closure(Standard):(null|Standard)) $value
4868
* @return $this
@@ -118,6 +138,21 @@ public function setSchemas(null|array|Closure $value): static
118138
return $this;
119139
}
120140

141+
/**
142+
* @param null|SeoTags|(Closure(SeoTags):(null|SeoTags)) $value
143+
* @return $this
144+
*/
145+
public function setCustomTags(null|SeoTags|Closure $value): static
146+
{
147+
if ($value instanceof Closure) {
148+
$this->customTags = $value($this->customTags ?? new SeoTags);
149+
} else {
150+
$this->customTags = $value;
151+
}
152+
153+
return $this;
154+
}
155+
121156
/**
122157
* @return $this
123158
*/

Diff for: src/helpers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function seo(null|HasSeo|SeoManager $value = null): SeoManager
1111
}
1212

1313
if ($value instanceof HasSeo) {
14-
return $value->getSeo();
14+
return \Elegantly\Seo\Facades\SeoManager::current()->apply($value);
1515
}
1616

1717
return $value;

0 commit comments

Comments
 (0)