* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Resource implements IteratorAggregate, \JsonSerializable { use TagableTrait; const STATUS_ACTIVE = 0x1; const STATUS_DEPRECATED = 0x2; const STATUS_CLOSED = 0x3; const STATUS_DEVELOPMENT = 0x4; const CODE_INFORMATIONAL = 199; const CODE_SUCCESS = 299; const CODE_REDIRECTION = 399; const CODE_CLIENT_ERROR = 499; const CODE_SERVER_ERROR = 599; /** @var integer */ protected $status; /** @var string */ protected $path; /** @var string */ protected $title; /** @var string */ protected $description; /** @var string */ protected $pathParameters; /** @var \PSX\Api\Resource\MethodAbstract[] */ protected $methods; /** * @param integer $status * @param string $path */ public function __construct(int $status, string $path) { $this->status = $status; $this->path = $path; $this->methods = []; } /** * @return boolean */ public function isActive(): bool { return $this->status == self::STATUS_ACTIVE; } /** * @return boolean */ public function isDeprecated(): bool { return $this->status == self::STATUS_DEPRECATED; } /** * @return boolean */ public function isClosed(): bool { return $this->status == self::STATUS_CLOSED; } /** * @return boolean */ public function isDevelopment(): bool { return $this->status == self::STATUS_DEVELOPMENT; } /** * @return integer */ public function getStatus(): int { return $this->status; } /** * @return string */ public function getPath(): string { return $this->path; } /** * @param string $title */ public function setTitle(?string $title) { $this->title = $title; } /** * @return string */ public function getTitle(): ?string { return $this->title; } /** * @param string $description */ public function setDescription(?string $description) { $this->description = $description; } /** * @return string */ public function getDescription(): ?string { return $this->description; } /** * @param string $typeName */ public function setPathParameters(?string $typeName) { $this->pathParameters = $typeName; } /** * @return string */ public function getPathParameters(): ?string { return $this->pathParameters; } /** * @return bool */ public function hasPathParameters(): bool { return !empty($this->pathParameters); } /** * @param MethodAbstract $method */ public function addMethod(MethodAbstract $method) { $this->methods[$method->getName()] = $method; } /** * @param string $method * @return \PSX\Api\Resource\MethodAbstract */ public function getMethod($method): ?MethodAbstract { if (isset($this->methods[$method])) { return $this->methods[$method]; } else { throw new \RuntimeException('Method ' . $method . ' is not available for this resource'); } } /** * @return \PSX\Api\Resource\MethodAbstract[] */ public function getMethods(): array { return $this->methods; } /** * @return array */ public function getAllowedMethods(): array { return array_keys($this->methods); } /** * @param string $method * @return boolean */ public function hasMethod($method): bool { return isset($this->methods[$method]); } /** * @inheritdoc */ public function getIterator() { return new ArrayIterator($this->methods); } public function toArray(): array { $methods = []; foreach ($this->methods as $methodName => $method) { $methods[$methodName] = $method->toArray(); } return array_filter([ 'status' => $this->status, 'path' => $this->path, 'title' => $this->title, 'description' => $this->description, 'pathParameters' => $this->pathParameters, 'methods' => $methods, ], function($value){ return $value !== null; }); } public function jsonSerialize() { return $this->toArray(); } } __halt_compiler();----SIGNATURE:----gqH7/nDBfu3KECW7c9lZCb723ahVox5X9au2uc35JW3KyHdF+59e5buj5y0rCIkYQDbuLpX+J4gdv0vVpd9Dehf9w4Z+Hh87oKlY5q8H1f0kPHYi3oTr2sZ5aT4Id0rK6Ej2rbMl6MnW6UVTol3xDZVieH+f92vmrbfaTuIwvJuZ4pTNDZdbykNZuphjvxoQvjkS8jmAeKF1EEbTNqaif80RDF2K68N8aHme6ShP3+lMWP8f1PK2+3lngGSp8G7pkFiA+XXwbBL8qzQLb0sb6PU7usEhm80yTQRf9XbULnaeIoc9gdNPQevw0NjJOynW6MW/GKSNoHlbACTUp0YInsQJka10uufncV1uw43hAILiEMvERz1dzqfG/fOOQlRUhiDXvf44vHZWyCdqhqBw4yF97v7QgkSzBbqlPruIz8RNPWfmUKK4AWMKzl5TVVq/6xCHJ/EiYBe3eRLR4UvOtaq7sLUjJdM9hHNTM5UOwbbK067KBz9NAAs/0XfF5m2Oon9jevWXlIuh/0o22+HMw9oJPpk1VU28QLLyXerpg3aZQtVOz1fJlCzL8yVEhalUzQIsy4m1r1ju+XZqd8IVgefNFyfCSa++2uKvZVX5E5fkGJZNYxeVmRD+V/fh4XJnahbGWU+lxvBo0Z9sL354i8yaeBtloSegH5WpDWs9txo=----ATTACHMENT:----NDc4MDYzMjM0MTI0MTM0MCA3NjM3Mzk4NDgzNDU1MjMxIDQxNTA0MjA1MTEwNTQwODM=