Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Entities/Itunes/AbstractChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lukaswhite\FeedWriter\Entities\Itunes;

use Lukaswhite\FeedWriter\Traits\Itunes\HasCategories;
use Lukaswhite\FeedWriter\Traits\Itunes\HasAuthor;
use Lukaswhite\FeedWriter\Traits\Itunes\HasBlock;
use Lukaswhite\FeedWriter\Traits\Itunes\HasExplicit;
Expand All @@ -19,6 +20,7 @@ abstract class AbstractChannel extends \Lukaswhite\FeedWriter\Entities\Rss\Chann
use HasSubtitle,
HasSummary,
HasAuthor,
HasCategories,
HasImage,
HasExplicit,
HasBlock;
Expand Down
47 changes: 47 additions & 0 deletions src/Entities/Itunes/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Lukaswhite\FeedWriter\Entities\Itunes;

use Lukaswhite\FeedWriter\Traits\Itunes\HasCategories;

/**
* Class Category
*
* @package Lukaswhite\FeedWriter\Entities\Media
*/
class Category extends \Lukaswhite\FeedWriter\Entities\Atom\Category
{
use HasCategories;
/**
* @var string
*/
protected $text;

/**
* Create a DOM element that represents this entity.
*
* @return \DOMElement
*/
public function element( ) : \DOMElement
{
$category = $this->createElement( 'itunes:category' );

if ( $this->text ) {
$category->setAttribute( 'text', $this->text );
}

$this->addCategoryElements( $category );

return $category;
}

/**
* @param string $text
* @return Category
*/
public function text( string $text ) : self
{
$this->text = $text;
return $this;
}
}
13 changes: 13 additions & 0 deletions src/Entities/Itunes/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Lukaswhite\FeedWriter\Entities\Itunes;


/**
* Class Channel
*
Expand All @@ -21,4 +22,16 @@ public function addItem( ) : Item
$this->items[ ] = $item;
return $item;
}

/**
* Add an item
*
* @return Item
*/
public function addCategory( ) : Category
{
$category = new Category( $this->feed );
$this->categories[ ] = $category;
return $category;
}
}
49 changes: 49 additions & 0 deletions src/Traits/Itunes/HasCategories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Lukaswhite\FeedWriter\Traits\Itunes;

use Lukaswhite\FeedWriter\Entities\Itunes\Category;


/**
* Trait HasCategories
*
* @package Lukaswhite\FeedWriter\Traits\Itunes
*/
trait HasCategories
{
/**
* The categories for this entry / channel
*
* @var array
*/
protected $categories = [ ];

/**
* Add a contributor
*
* @return Category
*/
public function addCategory( )
{
$category = ( new Category( $this->feed ) );
$this->categories[ ] = $category;
return $category;
}

/**
* Add the authors to the specified element.
*
* @param \DOMElement $el
* @return void
*/
protected function addCategoryElements( \DOMElement $el ) : void
{
if ( count( $this->categories ) ) {
foreach( $this->categories as $category ) {
/** @var Category $category */
$el->appendChild( $category->element( ) );
}
}
}
}