Skip to content

Commit

Permalink
Check that apiClass is a string before passing it to class_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Nov 6, 2023
1 parent 16ce9b1 commit fb7cdd4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ApiAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait ApiAwareTrait
protected $api;

/**
* @var string
* @var string|object
*/
protected $apiClass;

Expand All @@ -24,11 +24,12 @@ public function setApi($api)
if (empty($this->apiClass)) {
throw new LogicException(sprintf('You must configure apiClass in __constructor method of the class the trait is applied to.'));
}
if (false == (class_exists($this->apiClass) || interface_exists($this->apiClass))) {

if (is_string($this->apiClass) && !(class_exists($this->apiClass) || interface_exists($this->apiClass))) {
throw new LogicException(sprintf('Api class not found or invalid class. "%s", $this->apiClass', $this->apiClass));
}
if (false == $api instanceof $this->apiClass) {

if (!$api instanceof $this->apiClass) {
throw new UnsupportedApiException(sprintf('Not supported api given. It must be an instance of %s', $this->apiClass));
}

Expand Down

0 comments on commit fb7cdd4

Please sign in to comment.