Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ echo OpenGraph::website('Example')
<meta property="og:type" content="website" />
<meta property="og:title" content="Example" />
<meta property="og:url" content="https://example.com" />
<meta property="og:image:url" content="https://example.com/image1.jpg" />
<meta property="og:image:url" content="https://example.com/image2.jpg" />
<meta property="og:image" content="https://example.com/image1.jpg" />
<meta property="og:image" content="https://example.com/image2.jpg" />
<meta property="og:image:width" content="600" />
```

Expand Down
5 changes: 3 additions & 2 deletions src/BaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ abstract class BaseObject
/** @var BaseObject[] */
protected $tags = [];

public function setProperty(string $prefix, string $property, string $content)
public function setProperty(string $prefix, ?string $property, string $content)
{
$this->tags[$prefix.':'.$property] = Property::make($prefix, $property, $content);
$key = $property ? $prefix.':'.$property : $prefix;
$this->tags[$key] = Property::make($prefix, $property, $content);
}

public function addProperty(string $prefix, string $property, string $content)
Expand Down
10 changes: 6 additions & 4 deletions src/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ class Property
/** @var string */
protected $prefix = 'og';

/** @var string */
/** @var string|null */
protected $property;

/** @var string */
protected $content;

public function __construct(string $prefix, string $property, string $content)
public function __construct(string $prefix, ?string $property, string $content)
{
$this->prefix = $prefix;
$this->property = $property;
$this->content = $content;
}

public static function make(string $prefix, string $property, string $content)
public static function make(string $prefix, ?string $property, string $content)
{
return new static($prefix, $property, $content);
}

public function __toString(): string
{
return "<meta property=\"{$this->prefix}:{$this->property}\" content=\"{$this->content}\">";
$property = $this->property ? "$this->prefix:$this->property" : $this->prefix;

return "<meta property=\"{$property}\" content=\"{$this->content}\">";
}
}
2 changes: 1 addition & 1 deletion src/StructuredProperties/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Image extends BaseObject

public function __construct(string $url)
{
$this->setProperty(self::PREFIX, 'url', $url);
$this->setProperty(self::PREFIX, null, $url);
}

public static function make(string $url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="og:image:url" content="http://www.example.com/image2.jpg">
<meta property="og:image" content="http://www.example.com/image2.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1080">
<meta property="og:image:type" content="image/jpg">
Expand Down