-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use event name instead of const to be psr-14 compliant (#62)
* feat: use event name instead of const to be psr-14 compliant * chore: add typehints, update phpdoc format
- Loading branch information
Showing
10 changed files
with
313 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* Class AbstractGuzzleCacheEvent | ||
*/ | ||
abstract class AbstractGuzzleCacheEvent extends Event | ||
{ | ||
/** @const string Name of standard event */ | ||
const NAME = 'm6web.guzzlecache'; | ||
|
||
/** @const string Name of Error event */ | ||
const NAME_ERROR = 'm6web.guzzlecache.error'; | ||
|
||
/** @var RequestInterface */ | ||
protected $request; | ||
|
||
/** @var \Exception|null */ | ||
protected $exception; | ||
|
||
/** | ||
* GuzzleCacheEvent constructor. | ||
* | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* Get Request | ||
* | ||
* @return RequestInterface | ||
*/ | ||
public function getRequest(): RequestInterface | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* Set Exception | ||
* | ||
* @param \Exception $e | ||
*/ | ||
public function setException(\Exception $e) | ||
{ | ||
$this->exception = $e; | ||
} | ||
|
||
/** | ||
* Get Exception if isset | ||
* | ||
* @return \Exception|null | ||
*/ | ||
public function getException() : ?\Exception | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
/** | ||
* Get domain from Request, with graphite compatibility (remove point) | ||
* | ||
* @return string | ||
*/ | ||
public function getDomain(): string | ||
{ | ||
return str_replace('.', '_', $this->request->getUri()->getHost()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?php | ||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
/** | ||
* Class AbstractGuzzleHttpEvent | ||
*/ | ||
abstract class AbstractGuzzleHttpEvent extends Event | ||
{ | ||
const EVENT_NAME = 'm6web.guzzlehttp'; | ||
const EVENT_ERROR_NAME = 'm6web.guzzlehttp.error'; | ||
|
||
/** @var float Command start time */ | ||
protected $executionStart; | ||
|
||
/** @var float Command execution time */ | ||
protected $executionTime; | ||
|
||
/** @var Request */ | ||
protected $request; | ||
|
||
/** @var Response */ | ||
protected $response; | ||
|
||
/** @var \Exception|null */ | ||
protected $reason; | ||
|
||
/** @var string */ | ||
protected $clientId; | ||
|
||
/** | ||
* Set request | ||
* | ||
* @param Request $request | ||
* | ||
* @return static | ||
*/ | ||
public function setRequest(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Return request | ||
* | ||
* @return RequestInterface | ||
*/ | ||
public function getRequest() : RequestInterface | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* Set Response | ||
* | ||
* @param ResponseInterface $response | ||
* | ||
* @return static | ||
*/ | ||
public function setResponse(ResponseInterface $response) | ||
{ | ||
$this->response = $response; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Return response | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function getResponse() : ResponseInterface | ||
{ | ||
return $this->response; | ||
} | ||
|
||
/** | ||
* Set reason | ||
* | ||
* @param \Exception $reason | ||
* | ||
* @return static | ||
*/ | ||
public function setReason(\Exception $reason) | ||
{ | ||
$this->reason = $reason; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Return reason | ||
* | ||
* @return \Exception|null | ||
*/ | ||
public function getReason() : ?\Exception | ||
{ | ||
return $this->reason; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getExecutionStart() : float | ||
{ | ||
return $this->executionStart; | ||
} | ||
|
||
/** | ||
* Set execution start of a request | ||
* | ||
* @return static | ||
*/ | ||
public function setExecutionStart() | ||
{ | ||
$this->executionStart = microtime(true); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Stop the execution of a request | ||
* and set the request execution time | ||
* | ||
* @return static | ||
*/ | ||
public function setExecutionStop() | ||
{ | ||
$this->executionTime = microtime(true) - $this->executionStart; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getExecutionTime() : float | ||
{ | ||
return $this->executionTime; | ||
} | ||
|
||
/** | ||
* Return execution time in milliseconds | ||
* | ||
* @return float | ||
*/ | ||
public function getTiming() : float | ||
{ | ||
return $this->getExecutionTime() * 1000; | ||
} | ||
|
||
/** | ||
* Get client ID | ||
* | ||
* @return string | ||
*/ | ||
public function getClientId() : string | ||
{ | ||
return $this->clientId; | ||
} | ||
|
||
/** | ||
* Set client ID | ||
* | ||
* @param string $clientId | ||
* | ||
* @return static | ||
*/ | ||
public function setClientId($clientId) | ||
{ | ||
$this->clientId = $clientId; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
/** | ||
* Class GuzzleCacheErrorEvent | ||
*/ | ||
class GuzzleCacheErrorEvent extends AbstractGuzzleCacheEvent | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,12 @@ | ||
<?php | ||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
use Psr\Http\Message\RequestInterface; | ||
use Symfony\Component\EventDispatcher\Event; | ||
declare(strict_types=1); | ||
|
||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
/** | ||
* Class GuzzleHttpEvent | ||
* Class GuzzleCacheEvent | ||
*/ | ||
class GuzzleCacheEvent extends Event | ||
class GuzzleCacheEvent extends AbstractGuzzleCacheEvent | ||
{ | ||
/** @const string Name of standard event */ | ||
const NAME = 'm6web.guzzlecache'; | ||
|
||
/** @const string Name of Error event */ | ||
const NAME_ERROR = 'm6web.guzzlecache.error'; | ||
|
||
/** @var RequestInterface */ | ||
protected $request; | ||
/** @var \Exception|null */ | ||
protected $exception; | ||
|
||
/** | ||
* GuzzleCacheEvent constructor. | ||
* | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* Get Request | ||
* | ||
* @return RequestInterface | ||
*/ | ||
public function getRequest(): RequestInterface | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* Set Exception | ||
* | ||
* @param \Exception $e | ||
*/ | ||
public function setException(\Exception $e) | ||
{ | ||
$this->exception = $e; | ||
} | ||
|
||
/** | ||
* Get Exception if isset | ||
* | ||
* @return mixed | ||
*/ | ||
public function getException() | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
/** | ||
* Get domain from Request, with graphite compatibility (remove point) | ||
* | ||
* @return string | ||
*/ | ||
public function getDomain(): string | ||
{ | ||
return str_replace('.', '_', $this->request->getUri()->getHost()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher; | ||
|
||
/** | ||
* Class GuzzleHttpErrorEvent | ||
*/ | ||
class GuzzleHttpErrorEvent extends AbstractGuzzleHttpEvent | ||
{ | ||
} |
Oops, something went wrong.