Skip to content

Commit d416307

Browse files
committed
Created credentials socket handler
1 parent 4651d8d commit d416307

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "rubyqorn/web-socket",
3+
"description": "Socket layer over PHP socket api",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Anton Hideger",
9+
"email": "rubyqorn@example.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"WebSocket\\": "src/"
15+
}
16+
},
17+
"require": {}
18+
}

src/Socket.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace WebSocket;
4+
5+
class Socket
6+
{
7+
protected ?ICredential $credential;
8+
9+
/**
10+
* DI of SocketCredentials
11+
* @param ICredential $credential
12+
* @return void
13+
*/
14+
public function setCredentials(ICredential $credential)
15+
{
16+
$this->credential = $credential;
17+
}
18+
19+
/**
20+
* Return instance of SocketCredentials
21+
* @return SocketCredentials
22+
*/
23+
public function getCredentials()
24+
{
25+
return $this->credential;
26+
}
27+
}

src/credential/ICredential.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace WebSocket\Credential;
4+
5+
interface ICredential
6+
{
7+
/**
8+
* Set value for specified property name
9+
* @param string $name
10+
* @param string $value
11+
* @return void
12+
*/
13+
public function setCredential(string $name, string $value);
14+
15+
/**
16+
* Get value of property by specified property
17+
* name
18+
* @param string $name
19+
* @return mixed
20+
*/
21+
public function getCredential(string $name);
22+
}

src/credential/SocketCredentials.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace WebSocket\Credential;
4+
5+
class SocketCredentials implements ICredential
6+
{
7+
/**
8+
* Host name where will
9+
* be connected
10+
* @var string
11+
*/
12+
private string $host;
13+
14+
/**
15+
* Port for host
16+
* @var string
17+
*/
18+
private string $port;
19+
20+
/**
21+
* Set credentials for socket connection
22+
* @param string $name
23+
* @param string $value
24+
* @return void
25+
*/
26+
public function setCredential(string $name, string $value)
27+
{
28+
$this->$name = $value;
29+
}
30+
31+
/**
32+
* Get credentials for socket connection
33+
* @param string $name
34+
* @return string
35+
*/
36+
public function getCredential(string $name)
37+
{
38+
return $this->$name;
39+
}
40+
}

0 commit comments

Comments
 (0)