Skip to content

Commit 6ab58ec

Browse files
committed
deep clone
1 parent dbfbdcd commit 6ab58ec

File tree

11 files changed

+104
-0
lines changed

11 files changed

+104
-0
lines changed

src/OpenGraph/Locale.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
use Elegantly\Seo\Contracts\Taggable;
66
use Elegantly\Seo\SeoTags;
77
use Elegantly\Seo\Tags\Meta;
8+
use Elegantly\Seo\Traits\DeepClone;
89

910
class Locale implements Taggable
1011
{
12+
use DeepClone;
13+
1114
/**
1215
* @param string[] $alternate
1316
*/

src/OpenGraph/OpenGraph.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
use Elegantly\Seo\OpenGraph\Verticals\Website;
88
use Elegantly\Seo\SeoTags;
99
use Elegantly\Seo\Tags\Meta;
10+
use Elegantly\Seo\Traits\DeepClone;
1011
use Illuminate\Support\Facades\App;
1112
use Illuminate\Support\Facades\Request;
1213

1314
class OpenGraph implements Taggable
1415
{
16+
use DeepClone;
17+
1518
public function __construct(
1619
public string $title,
1720
public string $url,

src/OpenGraph/Verticals/Vertical.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
use Elegantly\Seo\Contracts\Taggable;
88
use Elegantly\Seo\SeoTags;
99
use Elegantly\Seo\Tags\Meta;
10+
use Elegantly\Seo\Traits\DeepClone;
1011
use Illuminate\Support\Arr;
1112

1213
abstract class Vertical implements Taggable
1314
{
15+
use DeepClone;
16+
1417
abstract public function getType(): string;
1518

1619
public function getNamespace(): string

src/Schemas/Schema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
use Elegantly\Seo\Contracts\Taggable;
66
use Elegantly\Seo\SeoTags;
77
use Elegantly\Seo\Tags\Script;
8+
use Elegantly\Seo\Traits\DeepClone;
89
use Illuminate\Support\Collection;
910

1011
/**
1112
* @extends Collection<int|string, mixed>
1213
*/
1314
class Schema extends Collection implements Taggable
1415
{
16+
use DeepClone;
17+
1518
public function toTags(): SeoTags
1619
{
1720
return new SeoTags([

src/SeoManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Elegantly\Seo\Schemas\WebPage;
1111
use Elegantly\Seo\Standard\Alternate;
1212
use Elegantly\Seo\Standard\Standard;
13+
use Elegantly\Seo\Traits\DeepClone;
1314
use Elegantly\Seo\Twitter\Cards\Card;
1415
use Elegantly\Seo\Twitter\Cards\Summary;
1516
use Illuminate\Contracts\Support\Htmlable;
@@ -20,6 +21,7 @@
2021
class SeoManager implements Htmlable, Stringable, Taggable
2122
{
2223
use Conditionable;
24+
use DeepClone;
2325

2426
/**
2527
* @param null|Schema[] $schemas

src/SeoTags.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Elegantly\Seo;
44

55
use Elegantly\Seo\Tags\TagVoid;
6+
use Elegantly\Seo\Traits\DeepClone;
67
use Illuminate\Contracts\Support\Htmlable;
78
use Illuminate\Support\Collection;
89

@@ -11,6 +12,8 @@
1112
*/
1213
class SeoTags extends Collection implements Htmlable
1314
{
15+
use DeepClone;
16+
1417
public function toHtml(): string
1518
{
1619
return $this->map(fn (TagVoid $tag) => $tag->toHtml())->join("\n");

src/Standard/Standard.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
use Elegantly\Seo\Tags\Link;
88
use Elegantly\Seo\Tags\Meta;
99
use Elegantly\Seo\Tags\Title;
10+
use Elegantly\Seo\Traits\DeepClone;
1011
use Illuminate\Support\Facades\Request;
1112

1213
/**
1314
* @see https://developer.mozilla.org/fr/docs/Web/HTML/Element/meta/name
1415
*/
1516
class Standard implements Taggable
1617
{
18+
use DeepClone;
19+
1720
/**
1821
* @param null|string|string[] $keywords
1922
* @param null|Alternate[] $alternates

src/Tags/TagVoid.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace Elegantly\Seo\Tags;
44

5+
use Elegantly\Seo\Traits\DeepClone;
56
use Illuminate\Contracts\Support\Htmlable;
67
use Illuminate\Support\Collection;
78

89
abstract class TagVoid implements Htmlable
910
{
11+
use DeepClone;
12+
1013
public string $tag;
1114

1215
/**

src/Traits/DeepClone.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Elegantly\Seo\Traits;
4+
5+
trait DeepClone
6+
{
7+
public function __clone()
8+
{
9+
foreach (get_object_vars($this) as $property => $value) {
10+
if (is_object($value)) {
11+
$this->{$property} = clone $value;
12+
}
13+
14+
if (is_array($value)) {
15+
$this->{$property} = array_map(function ($item) {
16+
if (is_object($item)) {
17+
return clone $item;
18+
}
19+
20+
return $item;
21+
}, $value);
22+
}
23+
}
24+
}
25+
}

src/Twitter/Cards/Card.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
use Elegantly\Seo\Contracts\Taggable;
66
use Elegantly\Seo\SeoTags;
77
use Elegantly\Seo\Tags\Meta;
8+
use Elegantly\Seo\Traits\DeepClone;
89
use Elegantly\Seo\Twitter\Image;
910

1011
abstract class Card implements Taggable
1112
{
13+
use DeepClone;
14+
1215
public function toTags(): SeoTags
1316
{
1417
$tags = new SeoTags;

0 commit comments

Comments
 (0)