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

fix: config 周りの修正 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require 'vendor/autoload.php';

$scanner = \Niisan\ClamAV\ScannerFactory::create([
'driver' => 'remote',
'url' => 'example.com'
'host' => 'example.com'
]);

if (! $scanner->scan($_FILE['userfile']['tmp_name'])) {
Expand All @@ -37,7 +37,7 @@ When yor select 'remote', the config need 'host' or 'remote.host' that means cla
```php
[
'driver' => 'remote',
'url' => 'examle.com'
'host' => 'examle.com'
];
```

Expand All @@ -59,6 +59,15 @@ Or you select 'local', the config need 'path' or 'local.path', that means a unix
]
```

```php
[
'driver' => 'local',
'local' => [
'path' => '/var/run/clamav/clamd.ctl'
]
]
```

# for developing
If you want to develop this package, some tests will fail for not starting clamd server.
So you command `clamd start` to start clamav daemon before testing.
So you command `clamd start` to start clamav daemon before testing.
10 changes: 5 additions & 5 deletions src/Scanners/RemoteScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class RemoteScanner implements Scanner
{

private $port = 3310;
private $url;
private $host;

public function __construct(array $option)
{
if (empty($option['url'])) {
if (empty($option['host'])) {
throw new \RuntimeException('ClamAV server host is not input.');
}

$this->url = $option['url'];
$this->host = $option['host'];
$this->port = $option['port'] ?? $this->port;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ public function scan(string $file_path): bool
*/
private function execWithSocket(callable $callback): string
{
$address = sprintf("tcp://%s:%s", $this->url, $this->port);
$address = sprintf("tcp://%s:%s", $this->host, $this->port);
$socket = stream_socket_client($address);
if (! $socket) {
throw new \RuntimeException('Connection failed: ' . $address);
Expand Down Expand Up @@ -107,4 +107,4 @@ private function splitFile(string $path): Generator

yield pack('N', 0);
}
}
}
4 changes: 2 additions & 2 deletions tests/ScannerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getRemoteScanner()
$config = [
'driver' => 'remote',
'remote' => [
'url' => 'example.com'
'host' => 'example.com'
]
];

Expand All @@ -39,4 +39,4 @@ public function getLocalScanner()
$obj = ScannerFactory::create($config);
$this->assertTrue($obj instanceof LocalScanner);
}
}
}
8 changes: 4 additions & 4 deletions tests/Scanners/RemoteScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function scanNormalFile()
}
$temp = tempnam(__DIR__, 'test');
file_put_contents($temp, $str);
$manager = new RemoteScanner(['url' => 'clamav']);
$manager = new RemoteScanner(['host' => 'clamav']);
$result = $manager->scan($temp);

$this->assertTrue($result);
Expand All @@ -33,7 +33,7 @@ public function scanErroFile()
$rus = '-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*';
$temp = tempnam('/tmp', 'test');
file_put_contents($temp, $vi.$rus);
$manager = new RemoteScanner(['url' => 'clamav']);
$manager = new RemoteScanner(['host' => 'clamav']);
$result = $manager->scan($temp);

$this->assertFalse($result);
Expand All @@ -45,7 +45,7 @@ public function scanErroFile()
*/
public function weSendPingAndGetPong()
{
$manager = new RemoteScanner(['url' => 'clamav']);
$manager = new RemoteScanner(['host' => 'clamav']);
$this->assertTrue($manager->ping());
}
}
}