40        $urlInfo = parse_url(
$url);
 
   42        if (!isset($urlInfo[
'scheme'], $urlInfo[
'host'], $urlInfo[
'port'])) {
 
   43            throw new \UnexpectedValueException(
'URL "'.
$url.
'" is not valid');
 
   46        if (!in_array($urlInfo[
'scheme'], $this->acceptedSchemes)) {
 
   47            throw new \UnexpectedValueException(
 
   48                'Invalid protocol (' . $urlInfo[
'scheme']  . 
').' 
   49                . 
' Valid options are ' . implode(
', ', $this->acceptedSchemes));
 
   52        $this->scheme = $urlInfo[
'scheme'];
 
   53        $this->host = $urlInfo[
'host'];
 
   54        $this->port = $urlInfo[
'port'];
 
   67        if (!extension_loaded(
'sockets')) {
 
   71        $this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0);
 
   72        if (!$this->udpConnection) {
 
   73            throw new \LogicException(
'Unable to create a socket');
 
   76        if (!socket_connect($this->udpConnection, $this->host, $this->port)) {
 
   77            throw new \LogicException(
'Unable to connect to the socket at ' . $this->host . 
':' . $this->port);
 
   87        if (!extension_loaded(
'curl')) {
 
   88            throw new \LogicException(
'The curl extension is needed to use http URLs with the CubeHandler');
 
   91        $this->httpConnection = curl_init(
'http://'.$this->host.
':'.$this->port.
'/1.0/event/put');
 
   93        if (!$this->httpConnection) {
 
   94            throw new \LogicException(
'Unable to connect to ' . $this->host . 
':' . $this->port);
 
   97        curl_setopt($this->httpConnection, CURLOPT_CUSTOMREQUEST, 
"POST");
 
   98        curl_setopt($this->httpConnection, CURLOPT_RETURNTRANSFER, 
true);
 
  104    protected function write(array $record)
 
  106        $date = $record[
'datetime'];
 
  108        $data = array(
'time' => $date->format(
'Y-m-d\TH:i:s.uO'));
 
  109        unset($record[
'datetime']);
 
  111        if (isset($record[
'context'][
'type'])) {
 
  112            $data[
'type'] = $record[
'context'][
'type'];
 
  113            unset($record[
'context'][
'type']);
 
  115            $data[
'type'] = $record[
'channel'];
 
  118        $data[
'data'] = $record[
'context'];
 
  119        $data[
'data'][
'level'] = $record[
'level'];
 
  121        if ($this->scheme === 
'http') {
 
  130        if (!$this->udpConnection) {
 
  134        socket_send($this->udpConnection, 
$data, strlen(
$data), 0);
 
  139        if (!$this->httpConnection) {
 
  143        curl_setopt($this->httpConnection, CURLOPT_POSTFIELDS, 
'['.
$data.
']');
 
  144        curl_setopt($this->httpConnection, CURLOPT_HTTPHEADER, array(
 
  145            'Content-Type: application/json',
 
  146            'Content-Length: ' . strlen(
'['.
$data.
']'),
 
An exception for terminatinating execution or to throw for unit testing.
Base Handler class providing the Handler structure.
write(array $record)
{Writes the record down to the log of the implementing handler.void}
__construct($url, $level=Logger::DEBUG, $bubble=true)
Create a Cube handler.
connectUdp()
Establish a connection to an UDP socket.
connectHttp()
Establish a connection to a http server.
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Exception can be thrown if an extension for an handler is missing.
const DEBUG
Detailed debug information.