Commit 2ed1de65 authored by Keven's avatar Keven
Browse files

Added a utility method to retrieve the name of the current command

parent 1d6b0ca0
......@@ -27,7 +27,7 @@ abstract class AccessCommand extends Command
protected $objectClass = 'Libcast\Client\Entity\Access';
/**
*
*
* @param \Libcast\Client\Entity\Entity $entity
*/
protected function setEntity($entity)
......@@ -72,9 +72,9 @@ abstract class AccessCommand extends Command
}
/**
*
*
* It's a bit hacky...
*
*
* @param \Libcast\Client\Model\AccessInterface $access
*/
protected function buildPayload(AccessInterface $access)
......@@ -92,7 +92,7 @@ abstract class AccessCommand extends Command
$this->setVar('entity', 'user');
break;
default:
throw new BadParameterException(sprintf('"%s" command requires a valid subject: group or user.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid subject: group or user.', $this->getName()));
}
$payload[$key] = basename($access->getSubject()->getHref());
......@@ -112,7 +112,7 @@ abstract class AccessCommand extends Command
$key = 'resource';
break;
default:
throw new BadParameterException(sprintf('"%s" command requires a valid object: platform, media, stream or publication.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid object: platform, media, stream or publication.', $this->getName()));
}
$payload[$key] = basename($access->getObject()->getHref());
......
......@@ -21,14 +21,14 @@ abstract class ChannelCommand extends Command
protected $objectClass = 'Libcast\Client\Entity\Channel';
/**
*
*
* @param MediaInterface $media Media instance, media URL or media unique name
*/
protected function setMedia($media)
{
if ($media instanceof MediaInterface) {
if (!$href = $media->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid media.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid media.', $this->getName()));
}
$this->fullPath = $href.'/channels';
}
......
......@@ -293,13 +293,28 @@ abstract class Command implements CommandInterface
}
/**
*
*
* @param string $str
*
*
* @return boolean
*/
protected function isURL($str)
{
return (bool) preg_match('/^https?:\/\//', $str);
}
/**
*
* @return string
*/
protected function getName()
{
if (isset($this->commandName)) {
return $this->commandName;
}
$r = new \ReflectionClass($this);
return $r->getShortName();
}
}
......@@ -20,7 +20,7 @@ class DeleteFile extends FileCommand
public function __construct(FileInterface $file)
{
if (!$file->href) {
throw new BadParameterException(__CLASS__.' requires a File hyperlink, none given.');
throw new BadParameterException($this->getName().' requires a File hyperlink, none given.');
}
$this->fullPath = $file->href;
......
......@@ -20,7 +20,7 @@ class DeleteFolder extends FolderCommand
public function __construct(FolderInterface $folder)
{
if (!$folder->getHref()) {
throw new BadParameterException(__CLASS__.' requires a Folder hyperlink, none given.');
throw new BadParameterException($this->getName().' requires a Folder hyperlink, none given.');
}
$this->fullPath = $folder->getHref();
......
......@@ -26,13 +26,13 @@ class DeletePlatform extends Command
protected $objectClass = 'Libcast\Client\Entity\Platform';
/**
*
*
* @param PlatformInterface $platform
*/
public function __construct(PlatformInterface $platform)
{
if (!$platform->getHref()) {
throw new BadParameterException(__CLASS__.' requires a Platform hyperlink, none given.');
throw new BadParameterException($this->getName().' requires a Platform hyperlink, none given.');
}
$this->fullPath = $platform->getHref();
......
......@@ -20,7 +20,7 @@ class DeleteResource extends ResourceCommand
public function __construct(ResourceInterface $resource)
{
if (!$resource->href) {
throw new BadParameterException(__CLASS__.' requires a Resource hyperlink, none given.');
throw new BadParameterException($this->getName().' requires a Resource hyperlink, none given.');
}
$this->fullPath = $resource->href;
......
......@@ -20,7 +20,7 @@ class DeleteStream extends StreamCommand
public function __construct(StreamInterface $stream)
{
if (!$stream->href) {
throw new BadParameterException(__CLASS__.' requires a Stream hyperlink, none given.');
throw new BadParameterException($this->getName().' requires a Stream hyperlink, none given.');
}
$this->fullPath = $stream->href;
......
......@@ -27,7 +27,7 @@ abstract class FileCommand extends Command
{
if ($file instanceof FileInterface) {
if (!$href = $file->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid file.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid file.', $this->getName()));
}
$this->fullPath = $href;
} elseif ('http' == substr($file, 0, 4)) {
......@@ -35,5 +35,7 @@ abstract class FileCommand extends Command
} else {
$this->setVar('file', $file);
}
throw new BadParameterException(sprintf('"%s" command requires a valid file.', $this->getName()));
}
}
......@@ -29,7 +29,7 @@ abstract class FolderCommand extends Command
$this->path = '/files';
} else if ($folder instanceof FolderInterface) {
if (!$href = $folder->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid folder.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid folder.', $this->getName()));
}
$this->fullPath = $href;
} elseif ('http' == substr($folder, 0, 4)) {
......
......@@ -27,7 +27,7 @@ abstract class PlayerBehaviorCommand extends Command {
{
if ($platform instanceof PlatformInterface) {
if (!$slug = $platform->getSlug()) {
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', $this->getName()));
}
$this->setVar('platform', $slug);
}
......
......@@ -27,7 +27,7 @@ abstract class PlayerThemeCommand extends Command {
{
if ($platform instanceof PlatformInterface) {
if (!$slug = $platform->getSlug()) {
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', $this->getName()));
}
$this->setVar('platform', $slug);
}
......
......@@ -21,7 +21,7 @@ abstract class ProfileCommand extends Command
protected $objectClass = 'Libcast\Client\Entity\Profile';
/**
*
*
* @param PlatformInterface $platform Platform instance, platform URL or platform unique name
* @throws BadParameterException
*/
......@@ -29,7 +29,7 @@ abstract class ProfileCommand extends Command
{
if ($platform instanceof PlatformInterface) {
if (!$href = $platform->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid platform.', $this->getName()));
}
$this->fullPath = $href.'/profiles';
}
......
......@@ -23,7 +23,7 @@ class RemoveSubtitle extends Command
} elseif(is_string($subtitle)) {
$this->fullPath = $subtitle;
} else {
throw new \BadParameterException(__CLASS__.' command requires a Subtitle instance or a subtitle API URL.');
throw new \BadParameterException($this->getName().' command requires a Subtitle instance or a subtitle API URL.');
}
}
}
......@@ -41,7 +41,7 @@ abstract class ResourceCommand extends Command
{
if ($stream instanceof StreamInterface) {
if (!$href = $stream->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid stream.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid stream.', $this->getName()));
}
$this->fullPath = $href.'/resources';
}
......@@ -51,7 +51,7 @@ abstract class ResourceCommand extends Command
$this->setVar('stream', $stream);
}
}
/**
*
* @param UsageCollection $usages
......@@ -71,7 +71,7 @@ abstract class ResourceCommand extends Command
/**
* Build and set the payload for the command
*
*
* @param ResourceInterface $resource
*/
protected function buildPayload(ResourceInterface $resource)
......
......@@ -29,7 +29,7 @@ abstract class StreamCommand extends Command
{
if ($media instanceof MediaInterface) {
if (!$href = $media->getHref()) {
throw new BadParameterException(sprintf('"%s" command requires a valid media.', __CLASS__));
throw new BadParameterException(sprintf('"%s" command requires a valid media.', $this->getName()));
}
$this->fullPath = $href.'/streams';
}
......
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