* @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:----hq05aIX5pg5gNO2ayBtSFuuwEAIsujfrzsu2xVxV+m1+4dc364x8oedsb8AmJQg+TvcHlHN3CAYh93qVZyWl08Uvng3nnqIHwb23XdxrygDn6buHkzyojJd4AjDHca5Rr03Er/F/ArZjz7DelOj7BN5flFVF8rn2pb2dQ9K22guuJRPJWG3wxBBQDjF5SAsctplNcCCeP2LOj4KH0IhJSAiezBNDM8podatGr9FJP/oI6VsK00Kw9SZpMiT+xleCJwEcNV93BXQWnrZqxX18cKZqn96xsgWB1h8QgWR9YKQk80ZXqX8YbILd8e4wTNzFpdgfbvd6iMw8AEbO+GFE/TzdMIR+3LYCHuRjRIWwrIXRkimBGsBSPO46w32gPuAXh1GEt1+Piqr7yHBWJw0uaRoDfVxJMqLJQr4OHrSKi2MI3vElfSE+vwXIRS5ZqasarWdf1IT1NvTbWxhhX7eunzl05ShWvrsav5+WBRug8A8VYc/wQ1Cju/WhiqEazN2guKd6kd6e/0rIO4VyMzfT79zKHMV1/+tced9LJ03SRhzqJ4zlbcDKNYwE1x15pO7E5aIjZDPrnuSExnf01hXvpvJsX4qy52Tb8P6jwwQriANhVzjjlw0LGRDHn+I7c3z6bzWoEHSiBlB7E788eTChnf2EDZjKHWhtQlZIXgr4Lu4=----ATTACHMENT:----NTAxNDQ3OTU1NzY0NjQ4OCA2MjczMzc1NjMyMjY0NDczIDUwNDgxODA5NjQzNjI0MzQ=