Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CakePHP 2.x release 1.4.0 #14

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
.gitattributes export-ignore
.gitignore export-ignore
.github/ export-ignore
tests/ export-ignore
vendor/ export-ignore
.travis.yml export-ignore
composer.* export-ignore
phpunit.xml export-ignore
phpstan.neon export-ignore
README.* export-ignore
LICENSE export-ignore
stubs/ export-ignore
69 changes: 69 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events
push:
pull_request:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Composer config validation
composer:
name: "Composer config validation"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: "Validate composer.json"
run: "composer validate --strict"

# PHP syntax validation
php:
name: "PHP syntax validation"
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.0, 8.1, 8.2 ]
steps:
- uses: "actions/checkout@v3"
- uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php_version }}"
- name: "Check PHP syntax of plugin code"
run: |
php -l Lib/
php -l tests/

phpunit:
name: "PHPUnit tests"
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.0, 8.1, 8.2 ]
steps:
- uses: "actions/checkout@v3"
- uses: "php-actions/composer@v6"
with:
php_version: "${{ matrix.php_version }}"
- run: "vendor/bin/phpunit --coverage-clover clover.xml"

# phpstan for several php versions
phpstan:
runs-on: "ubuntu-latest"
strategy:
matrix:
php_version: [ 8.0, 8.1, 8.2 ]
steps:
- uses: "actions/checkout@v3"
- uses: "php-actions/composer@v6"
with:
php_version: "${{ matrix.php_version }}"
- name: "PHPStan Static Analysis"
uses: "php-actions/phpstan@v3"
with:
php_version: "${{ matrix.php_version }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
/composer.lock
33 changes: 12 additions & 21 deletions Lib/Log/Engine/GraylogLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Gelf\Transport\SslOptions;
use Gelf\Transport\TcpTransport;
use Gelf\Transport\TransportInterface;
use Gelf\Transport\AbstractTransport;
use Gelf\Transport\UdpTransport;
use kbATeam\GraylogUtilities\LogTypes;
use kbATeam\GraylogUtilities\Obfuscator;
Expand All @@ -29,7 +30,7 @@ class GraylogLog extends BaseLog
private $loop = false;

/**
* @var array Configuration array containing sane defaults.
* @var array<mixed> Configuration array containing sane defaults.
*/
protected $_config = [
'scheme' => 'udp',
Expand All @@ -39,7 +40,6 @@ class GraylogLog extends BaseLog
'chunk_size' => UdpTransport::CHUNK_SIZE_LAN,
'ssl_options' => null,
'facility' => 'CakePHP',
'add_file_and_line' => true,
'append_backtrace' => false,
'append_session' => false,
'append_post' => false,
Expand Down Expand Up @@ -162,7 +162,7 @@ public function write($type, $message)
* @throws \LogicException
* @throws \InvalidArgumentException
*/
protected function getPublisher()
protected function getPublisher(): Publisher
{
if ($this->publisher === null) {
$this->publisher = new Publisher($this->getTransport());
Expand All @@ -175,7 +175,7 @@ protected function getPublisher()
* @throws \LogicException
* @throws \InvalidArgumentException
*/
protected function getTransport()
protected function getTransport(): TransportInterface
{
if ($this->transport === null) {
$this->transport = $this->initTransport();
Expand All @@ -191,7 +191,7 @@ protected function getTransport()
* @throws InvalidArgumentException
* @throws LogicException
*/
private function initTransport()
private function initTransport(): TransportInterface
{
if ($this->_config['ignore_transport_errors'] === false) {
return $this->buildTransport();
Expand All @@ -201,11 +201,11 @@ private function initTransport()

/**
* Initialize the transport class for sending greylog messages.
* @return TransportInterface
* @return AbstractTransport
* @throws \LogicException Connection scheme configuration error.
* @throws \InvalidArgumentException UdpTransport or TcpTransport config errors.
*/
private function buildTransport()
private function buildTransport(): AbstractTransport
{
if ($this->_config['scheme'] === 'udp') {
return new UdpTransport(
Expand All @@ -221,7 +221,7 @@ private function buildTransport()
$this->_config['ssl_options']
);
}
throw new LogicException('Unkown transport scheme for GreyLog!');
throw new LogicException('Unknown transport scheme for GreyLog!');
}

/**
Expand All @@ -231,7 +231,7 @@ private function buildTransport()
* @return GelfMessage
* @throws \RuntimeException
*/
protected function createMessage($type, $message)
protected function createMessage(string $type, string $message): GelfMessage
{
$gelfMessage = (new GelfMessage())
->setVersion('1.1')
Expand All @@ -244,7 +244,6 @@ protected function createMessage($type, $message)
}
$gelfMessage->setAdditional('request_uri', $request->url);
}
$add_file_and_line = $this->_config['add_file_and_line'] === true;
/**
* Append backtrace in case it's not already in the message.
*/
Expand All @@ -253,22 +252,14 @@ protected function createMessage($type, $message)
/**
* Create a debug backtrace.
*/
if ($add_file_and_line || $append_backtrace) {
$trace = null;
if ($append_backtrace) {
$trace = new ClassicBacktrace(
$this->_config['trace_level_offset'],
$this->_config['file_root_dir']
);
}

/**
* In case the log didn't happen in memory (like with reflections), add
* the filename and line to the message.
*/
if ($add_file_and_line && $trace->lastStep('file') !== null) {
$gelfMessage->setFile($trace->lastStep('file'));
$gelfMessage->setLine($trace->lastStep('line'));
}

/**
* Append function output to the message.
*/
Expand All @@ -285,7 +276,7 @@ protected function createMessage($type, $message)
/**
* Append backtrace in case it's not already in the message.
*/
if ($append_backtrace) {
if ($append_backtrace && (null !== $trace)) {
/**
* Append backtrace to message.
*/
Expand Down
63 changes: 34 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
{
"name": "kba-team/cakephp-graylog",
"description": "Graylog engine for CakePHP",
"type": "cakephp-plugin",
"license": "MIT",
"minimum-stability": "stable",
"require": {
"php": "^7.2",
"ext-json": "*",
"cakephp/cakephp": "^2.4",
"graylog2/gelf-php": "^1.6",
"composer/installers": "^1.9",
"kba-team/php-backtrace": "^1.0",
"kba-team/graylog-utilities": "^1.0"
},
"extra": {
"installer-name": "Graylog"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
"autoload-dev": {
"classmap": [
"vendor/cakephp/cakephp/lib/Cake/Core/App.php",
"vendor/cakephp/cakephp/lib/Cake/Log/CakeLogInterface.php",
"vendor/cakephp/cakephp/lib/Cake/Log/Engine/BaseLog.php",
"vendor/cakephp/cakephp/lib/Cake/Utility/Hash.php",
"Lib/Log/Engine/GraylogLog.php",
"tests/PublicGraylogLog.php"
]
"name": "kba-team/cakephp-graylog",
"description": "Graylog engine for CakePHP",
"type": "cakephp-plugin",
"license": "MIT",
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"ext-json": "*",
"kba-team/cakephp": "^2.11",
"graylog2/gelf-php": "^1.6",
"composer/installers": "^1.9",
"kba-team/php-backtrace": "^1.0",
"kba-team/graylog-utilities": "^2.0"
},
"extra": {
"installer-name": "Graylog"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
"classmap": [
"vendor/kba-team/cakephp/lib/Cake/Core/App.php",
"vendor/kba-team/cakephp/lib/Cake/Log/CakeLogInterface.php",
"vendor/kba-team/cakephp/lib/Cake/Log/Engine/BaseLog.php",
"vendor/kba-team/cakephp/lib/Cake/Utility/Hash.php",
"Lib/Log/Engine/GraylogLog.php",
"tests/PublicGraylogLog.php"
]
},
"config": {
"allow-plugins": {
"composer/installers": true
}
}
}
Loading
Loading