You are here

public function AbstractFeed::setGenerator in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Writer/AbstractFeed.php \Zend\Feed\Writer\AbstractFeed::setGenerator()

Set the feed generator entry

Parameters

array|string $name:

null|string $version:

null|string $uri:

Return value

AbstractFeed

Throws

Exception\InvalidArgumentException

File

vendor/zendframework/zend-feed/src/Writer/AbstractFeed.php, line 217

Class

AbstractFeed

Namespace

Zend\Feed\Writer

Code

public function setGenerator($name, $version = null, $uri = null) {
  if (is_array($name)) {
    $data = $name;
    if (empty($data['name']) || !is_string($data['name'])) {
      throw new Exception\InvalidArgumentException('Invalid parameter: "name" must be a non-empty string');
    }
    $generator = [
      'name' => $data['name'],
    ];
    if (isset($data['version'])) {
      if (empty($data['version']) || !is_string($data['version'])) {
        throw new Exception\InvalidArgumentException('Invalid parameter: "version" must be a non-empty string');
      }
      $generator['version'] = $data['version'];
    }
    if (isset($data['uri'])) {
      if (empty($data['uri']) || !is_string($data['uri']) || !Uri::factory($data['uri'])
        ->isValid()) {
        throw new Exception\InvalidArgumentException('Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI');
      }
      $generator['uri'] = $data['uri'];
    }
  }
  else {
    if (empty($name) || !is_string($name)) {
      throw new Exception\InvalidArgumentException('Invalid parameter: "name" must be a non-empty string');
    }
    $generator = [
      'name' => $name,
    ];
    if (isset($version)) {
      if (empty($version) || !is_string($version)) {
        throw new Exception\InvalidArgumentException('Invalid parameter: "version" must be a non-empty string');
      }
      $generator['version'] = $version;
    }
    if (isset($uri)) {
      if (empty($uri) || !is_string($uri) || !Uri::factory($uri)
        ->isValid()) {
        throw new Exception\InvalidArgumentException('Invalid parameter: "uri" must be a non-empty string and a valid URI/IRI');
      }
      $generator['uri'] = $uri;
    }
  }
  $this->data['generator'] = $generator;
  return $this;
}