Skip to content

Commit

Permalink
Implemented DSN Connection Strings Support
Browse files Browse the repository at this point in the history
This PR introduces support for DSN connection strings to simplify the configuration process. Users can now use a single string to determine the type of connection (`Network` or `Pipe`) and its details.

This PR resolves appwrite#28, closes appwrite#25, resolves appwrite#26, closes appwrite#27, closes appwrite#31

1. Added a static `createFromDSN` method to the `ClamAV` abstract class. This method parses the provided DSN string and returns an appropriate instance (`Network` or `Pipe`).
2. Updated the `ClamAVTest` unit test to cover the new DSN creation functionality.
3. Updated composer dependencies
4. Applied smaller code, and documentation optimizations
5. Improved code coverage
6. Updated README

Users can now initialize a connection using a DSN string:

```php
$clam = ClamAV::createFromDSN('tcp://localhost:3310');
$version = $clam->version();
```

This approach provides a more flexible and user-friendly way to set up a connection.

The existing unit tests have been updated accordingly.
  • Loading branch information
SoftCreatR committed Oct 10, 2023
1 parent f5f0078 commit d7ad1d6
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 443 deletions.
122 changes: 122 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('*/vendor/*')
->exclude('node_modules')
->in(__DIR__)
->notPath('lib/system/api');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@PSR12' => true,
'@PER' => true,

'array_push' => true,
'backtick_to_shell_exec' => true,
'no_alias_language_construct_call' => true,
'no_mixed_echo_print' => true,
'pow_to_exponentiation' => true,
'random_api_migration' => true,

'array_syntax' => ['syntax' => 'short'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'whitespace_after_comma_in_array' => true,

'non_printable_character' => ['use_escape_sequences_in_strings' => true],

'magic_constant_casing' => true,
'magic_method_casing' => true,
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,

'cast_spaces' => ['space' => 'none'],
'no_unset_cast' => true,

'class_attributes_separation' => true,
'no_null_property_initialization' => true,
'self_accessor' => true,
'single_class_element_per_statement' => true,

'no_empty_comment' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],

'native_constant_invocation' => ['strict' => false],

'no_alternative_syntax' => true,
'no_trailing_comma_in_list_call' => true,
'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']],
'no_unneeded_curly_braces' => ['namespaces' => true],
'switch_continue_to_break' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],

'function_typehint_space' => true,
'lambda_not_used_import' => true,
'native_function_invocation' => ['include' => ['@internal']],
'no_unreachable_default_argument_value' => true,
'nullable_type_declaration_for_default_null_value' => true,
'static_lambda' => true,

'fully_qualified_strict_types' => true,
'no_unused_imports' => true,

'dir_constant' => true,
'explicit_indirect_variable' => true,
'function_to_constant' => true,
'is_null' => true,
'no_unset_on_property' => true,

'list_syntax' => ['syntax' => 'short'],

'clean_namespace' => true,
'no_leading_namespace_whitespace' => true,

'no_homoglyph_names' => true,

'binary_operator_spaces' => true,
'concat_space' => ['spacing' => 'one'],
'increment_style' => ['style' => 'post'],
'logical_operators' => true,
'object_operator_without_whitespace' => true,
'operator_linebreak' => true,
'standardize_increment' => true,
'standardize_not_equals' => true,
'ternary_to_elvis_operator' => true,
'ternary_to_null_coalescing' => true,
'unary_operator_spaces' => true,

'no_useless_return' => true,
'return_assignment' => true,

'multiline_whitespace_before_semicolons' => true,
'no_empty_statement' => true,
'no_singleline_whitespace_before_semicolons' => true,
'space_after_semicolon' => ['remove_in_empty_for_expressions' => true],

'escape_implicit_backslashes' => true,
'explicit_string_variable' => true,
'heredoc_to_nowdoc' => true,
'no_binary_string' => true,
'simple_to_complex_string_variable' => true,

'array_indentation' => true,
'blank_line_before_statement' => ['statements' => ['return', 'exit']],
'method_chaining_indentation' => true,
'no_extra_blank_lines' => ['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']],
'no_spaces_around_offset' => true,

// SoftCreatR style
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => false,
],
'ordered_imports' => [
'imports_order' => ['class', 'function', 'const'],
],
])
->setFinder($finder);
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
dist: focal
dist: jammy

language: php

php:
- 8.0
- 8.1

notifications:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ Install using composer:
composer require appwrite/php-clamav
```

Example usage:
```php
<?php

require_once 'vendor/autoload.php';

use Appwrite\ClamAV\Network;
use Appwrite\ClamAV\ClamAV;

$clam = new Network('localhost', 3310); // Or use new Pipe() for unix socket
$clam = ClamAV::createFromDSN('tcp://localhost:3310');

$clam->ping(); // Check ClamAV is up and running

Expand All @@ -36,7 +37,7 @@ $clam->shutdown(); // Shutdown ClamAV

## System Requirements

This package requires PHP 7.1 or later. We recommend using the latest PHP version whenever possible.
This package requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible.

## Find Us

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ext-sockets": "*"
},
"require-dev": {
"phpunit/phpunit": "^9"
"phpunit/phpunit": ">=9"
},
"minimum-stability": "stable"
}
Loading

0 comments on commit d7ad1d6

Please sign in to comment.