Skip to content

Commit 5b29fc5

Browse files
authored
Merge pull request #59 from jonathantullett/master
Implementation of two missing data accessors.
2 parents 3cdce8c + a04d227 commit 5b29fc5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Entity/Article.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,13 @@ public function getEstimatedDate()
275275
new \Carbon\Carbon($date, 'GMT') :
276276
$date;
277277
}
278+
279+
/**
280+
* Returns the canonical url from a page, if any.
281+
* @return string
282+
*/
283+
public function getCanonicalUrl()
284+
{
285+
return isset($this->data['canonicalUrl']) ? $this->data['canonicalUrl'] : null;
286+
}
278287
}

src/Traits/StandardEntity.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,23 @@ public function getDiffbotUri()
113113
return $this->data['diffbotUri'];
114114
}
115115

116+
/**
117+
* Returns the timestamp from the point in time the page was indexed by the engine
118+
* Example date: "Wed, 18 Dec 2013 00:00:00 GMT"
119+
* This will be a Carbon (https://github.com/briannesbitt/Carbon) instance if Carbon is installed.
120+
* @return \Carbon\Carbon | string
121+
*/
122+
public function getTimestamp()
123+
{
124+
return (class_exists('\Carbon\Carbon')) ?
125+
new \Carbon\Carbon($this->data['timestamp'], 'GMT') :
126+
$this->data['timestamp'];
127+
}
128+
116129
protected function getOrDefault($key, $default = null, $data = null)
117130
{
118131
$data = ($data !== null) ?: $this->data;
119132
return (isset($data[$key]) ? $data[$key] : $default);
120133
}
121134

122-
}
135+
}

0 commit comments

Comments
 (0)