Skip to content

Commit

Permalink
add compat for Laravel 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 1, 2016
1 parent fb8f0c8 commit 6cf0e41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-sitemap` will be documented in this file

## 1.1.0 - 2016-12-01

- add compatibility for Laravel 5.2

## 1.0.1 - 2016-10-09

- remove unused config file
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
],
"require": {
"php": "^7.0",
"illuminate/support": "~5.3.0",
"illuminate/support": "~5.3.0|~5.2.0",
"nesbot/carbon": "^1.21",
"spatie/crawler": "^1.3"
},
"require-dev": {
"phpunit/phpunit": "5.*",
"orchestra/testbench": "^3.3"
"orchestra/testbench": "~3.2.0|~3.3.0"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 11 additions & 0 deletions src/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public function add($tag)
*/
public function getUrl(string $url)
{
if ($this->runningLaravelVersion('5.2')) {
return collect($this->tags)->first(function (int $index, Tag $tag) use ($url) {
return $tag->getType() === 'url' && $tag->url;
});
}

return collect($this->tags)->first(function (Tag $tag) use ($url) {
return $tag->getType() === 'url' && $tag->url;
});
Expand Down Expand Up @@ -71,4 +77,9 @@ public function writeToFile(string $path)

return $this;
}

protected function runningLaravelVersion(string $version): bool
{
return strpos(\App::version(), $version) === 0;
}
}

0 comments on commit 6cf0e41

Please sign in to comment.