Commit ebb97a44 authored by keven's avatar keven
Browse files

Added nested Stream creation

parent af77d5b5
......@@ -326,6 +326,10 @@ $stream = $client->push($stream, $media)
// or:
$stream = $media->addStream($stream)
// Create a nested stream
$stream->addChild($otherStream) // Create a sub stream in a stream
$media->addStream($stream, $parentStream)
// Modify a stream
$stream->description = 'All the talks from the 2015 conference'
$client->push($stream)
......@@ -340,6 +344,7 @@ $stream->visibility // Visibility of the stream (public, hidden, protected)
$stream->resources() // List the resources in the stream
$stream->hasParent() // Whether or not the Stream has a parent stream
$stream->parent() // Retrieve the parent stream, or NULL if no parent
$stream->media() // Retrieve the media of the stream
```
### Resource
......
......@@ -278,4 +278,15 @@ abstract class Command implements CommandInterface
{
return substr(strrchr($href, "/"), 1);
}
/**
*
* @param string $str
*
* @return boolean
*/
protected function isURL($str)
{
return (bool) preg_match('/^https?:\/\//', $str);
}
}
......@@ -17,10 +17,14 @@ class CreateStream extends StreamCommand
*
* @param StreamInterface $stream Stream instance
* @param MediaInterface $media Media instance, media URL or media unique name
* @param StreamInterface|slug $stream Parent stream
*/
public function __construct(StreamInterface $stream, $media)
public function __construct(StreamInterface $stream, $media, $parentStream = null)
{
$this->setMedia($media);
$this->buildPayload($stream);
// This MUST come after buildPayload() or it will be lost
$this->setParent($parentStream);
}
}
......@@ -40,6 +40,31 @@ abstract class StreamCommand extends Command
}
}
/**
*
* @param StreamInterface $stream Stream instance, stream URL or stream unique slug
*/
protected function setParent($stream)
{
if (is_null($stream)) {
return;
}
if ($stream instanceof StreamInterface) {
$stream = $this->getSlugFromHref($stream->getHref());
}
if (!is_string($stream)) {
throw new \InvalidArgumentException('The parent stream must be an instance of StreamInterface, a stream URL or a stream slug.');
}
if ($this->isURL($stream)) {
$this->payload['parent_stream'] = $this->getSlugFromHref($stream);
} else {
$this->payload['parent_stream'] = $stream;
}
}
/**
*
* @param StreamInterface $stream
......
......@@ -128,11 +128,13 @@ class Media extends Entity implements MediaInterface
* Create a new stream in the media
*
* @param StreamInterface $stream
* @param StreamInterface $parentStream Optional parent stream
*
* @return Stream
*/
public function addStream(StreamInterface $stream)
public function addStream(StreamInterface $stream, $parentStream = null)
{
return $this->client->createStream($stream, $this);
return $this->client->createStream($stream, $this, $parentStream);
}
// Deprecated API
......
......@@ -233,4 +233,15 @@ class Stream extends Entity implements StreamInterface
return $this->_parent;
}
/**
*
* @param StreamInterface $stream
*
* @return Streaminterface
*/
public function addChild(StreamInterface $stream)
{
return $this->client->createStream($stream, $this->media(), $this);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment