Skip to content

Commit

Permalink
Add Request::getCommand(). Add Command::getParam().
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Nikolaev committed Jan 27, 2021
1 parent ac38225 commit 341a193
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
6.2.1: Remove command names.

6.2.2: Add discount type ID constants to product row model.

6.2.3:

- Add Request::getCommand();

- Add Command::getParam();
15 changes: 15 additions & 0 deletions Request/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,19 @@ public function setParams(array $params): Command

return $this;
}

/**
* @param string $name Parameter name
* @param mixed $default Default value
*
* @return mixed
*/
public function getParam(string $name, $default = null)
{
if (array_key_exists($name, $this->params)) {
return $this->params[$name];
}

return $default;
}
}
15 changes: 15 additions & 0 deletions Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ public function removeCommand(string $method): Request
return $this;
}

/**
* @param string $method Command method
*
* @return \Darvin\Bitrix24Bundle\Request\Command\Command
* @throws \InvalidArgumentException
*/
public function getCommand(string $method): Command
{
if (!isset($this->commands[$method])) {
throw new \InvalidArgumentException(sprintf('Request does not contain command "%s".', $method));
}

return $this->commands[$method];
}

/**
* @param string $method Command method
*
Expand Down

0 comments on commit 341a193

Please sign in to comment.