Skip to content

Commit a93365b

Browse files
Merge pull request #74 from TheDragonCode/1.x
The expanded use section has been improved and generated examples have been added
2 parents 6d825e2 + 7726b70 commit a93365b

File tree

72 files changed

+1115
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1115
-306
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds\Items;
6+
7+
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
8+
9+
use function fake;
10+
11+
class ArrayDirectiveFeedItem extends FeedItem
12+
{
13+
public function toArray(): array
14+
{
15+
return [
16+
'name' => $this->model->name,
17+
18+
'@avatar' => [
19+
fake()->imageUrl(),
20+
fake()->imageUrl(),
21+
],
22+
23+
'@images' => [
24+
[
25+
'@attributes' => ['name' => fake()->words(asText: true)],
26+
'@value' => fake()->imageUrl(),
27+
],
28+
[
29+
'@attributes' => ['name' => fake()->words(asText: true)],
30+
'@value' => fake()->imageUrl(),
31+
],
32+
],
33+
];
34+
}
35+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<user>
3+
<name>Roberta Parker</name>
4+
<avatar>https://via.placeholder.com/640x480.png/000000?text=aut</avatar>
5+
<avatar>https://via.placeholder.com/640x480.png/008877?text=officia</avatar>
6+
<images name="non ipsum voluptatem">https://via.placeholder.com/640x480.png/00ccff?text=provident</images>
7+
<images name="et accusamus quod">https://via.placeholder.com/640x480.png/0022aa?text=quos</images>
8+
</user>
9+
<user>
10+
<name>Lorenza Turcotte</name>
11+
<avatar>https://via.placeholder.com/640x480.png/002288?text=nam</avatar>
12+
<avatar>https://via.placeholder.com/640x480.png/009944?text=nesciunt</avatar>
13+
<images name="fuga eaque voluptate">https://via.placeholder.com/640x480.png/00cc66?text=velit</images>
14+
<images name="deserunt odit sapiente">https://via.placeholder.com/640x480.png/0066ff?text=error</images>
15+
</user>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds\Info;
6+
7+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
8+
9+
class AttributesDirectiveFeedInfo extends FeedInfo
10+
{
11+
public function toArray(): array
12+
{
13+
return [
14+
'company' => [
15+
'@attributes' => ['since' => fake()->year],
16+
],
17+
18+
'url' => config('app.url'),
19+
];
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds\Items;
6+
7+
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
8+
9+
class AttributesDirectiveFeedItem extends FeedItem
10+
{
11+
public function toArray(): array
12+
{
13+
return [
14+
'name' => $this->model->name,
15+
16+
'contact' => [
17+
'@attributes' => [
18+
'email' => $this->model->email,
19+
'phone' => '555-000-' . $this->model->id,
20+
],
21+
],
22+
];
23+
}
24+
}

docs/snippets/advanced-directive-attributes.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Feeds\Items;
5+
namespace App\Feeds;
66

7+
use App\Feeds\Info\AttributesDirectiveFeedInfo;
8+
use App\Feeds\Items\AttributesDirectiveFeedItem;
9+
use App\Models\User;
10+
use DragonCode\LaravelFeed\Feeds\Feed;
11+
use DragonCode\LaravelFeed\Feeds\Info\FeedInfo;
712
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
13+
use Illuminate\Database\Eloquent\Builder;
14+
use Illuminate\Database\Eloquent\Model;
815

9-
class UserFeedItem extends FeedItem
16+
class AttributesDirectiveFeed extends Feed
1017
{
11-
protected ?string $name = 'users';
18+
public function builder(): Builder
19+
{
20+
return User::query();
21+
}
22+
23+
public function info(): FeedInfo
24+
{
25+
return new AttributesDirectiveFeedInfo;
26+
}
1227

13-
public function toArray(): array
28+
public function item(Model $model): FeedItem
1429
{
15-
return [
16-
'some' => [
17-
'@attributes' => [
18-
'foo' => 'bar',
19-
'qwe' => 'rty',
20-
],
21-
],
22-
];
30+
return new AttributesDirectiveFeedItem($model);
2331
}
2432
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
<users>
2-
<some foo="bar" qwe="rty" />
3-
</users>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<company since="2020"/>
3+
<url>https://example.com</url>
4+
5+
<user>
6+
<name>Carmela Marks</name>
7+
<contact email="[email protected]" phone="555-000-1"/>
8+
</user>
9+
<user>
10+
<name>George DuBuque III</name>
11+
<contact email="[email protected]" phone="555-000-2"/>
12+
</user>

docs/snippets/advanced-directive-cdata.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
88

9-
class UserFeedItem extends FeedItem
10-
{
11-
protected ?string $name = 'users';
9+
use function sprintf;
1210

11+
class CdataDirectiveFeedItem extends FeedItem
12+
{
1313
public function toArray(): array
1414
{
1515
return [
1616
'name' => [
17-
'@cdata' => '<h1>Sauron</h1>',
17+
'@cdata' => sprintf('<h1>%s</h1>', $this->model->name),
1818
],
1919

20-
'weapon' => 'Evil Eye',
20+
'email' => $this->model->email,
2121
];
2222
}
2323
}
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<users>
2-
<name><![CDATA[<h1>Sauron</h1>]]></name>
3-
<weapon>Evil Eye</weapon>
4-
</users>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<user>
3+
<name><![CDATA[<h1>Marianne Howell</h1>]]></name>
4+
<email>[email protected]</email>
5+
</user>
6+
<user>
7+
<name><![CDATA[<h1>Imogene Pouros V</h1>]]></name>
8+
<email>[email protected]</email>
9+
</user>

docs/snippets/advanced-directive-mixed.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@
66

77
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
88

9-
class UserFeedItem extends FeedItem
9+
class MixedDirectiveFeedItem extends FeedItem
1010
{
11-
protected ?string $name = 'users';
12-
1311
public function toArray(): array
1412
{
1513
return [
16-
'foo' => 'bar',
14+
'name' => $this->model->name,
1715

18-
'some' => [
19-
'@mixed' => <<<'XML'
20-
<first>value</first>
21-
<second>value</second>
22-
XML,
23-
],
16+
'@mixed' => <<<XML
17+
<some>
18+
<first>Foo</first>
19+
<second>{$this->model->email}</second>
20+
</some>
21+
XML,
2422
];
2523
}
2624
}
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
<users>
2-
<foo>bar</foo>
3-
<some>
4-
<first>value</first>
5-
<second>value</second>
6-
</some>
7-
</users>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<user>
3+
<name>Casey Batz</name>
4+
<some>
5+
<first>Foo</first>
6+
<second>[email protected]</second>
7+
</some>
8+
</user>
9+
<user>
10+
<name>Mrs. Eloise Christiansen</name>
11+
<some>
12+
<first>Foo</first>
13+
<second>[email protected]</second>
14+
</some>
15+
</user>

0 commit comments

Comments
 (0)