Skip to content

Commit

Permalink
Merge pull request #2 from sirn-se/extending
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
sirn-se committed Jul 5, 2023
2 parents 69863af + e6b9372 commit 83435f3
Show file tree
Hide file tree
Showing 20 changed files with 779 additions and 316 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.gitattributes export-ignore
.gitignore export-ignore
docs/ export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
tests/ export-ignore
23 changes: 19 additions & 4 deletions .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,31 @@ jobs:
- name: Test
run: make test

test-8-3:
runs-on: ubuntu-latest
name: Test PHP 8.3
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
- name: Composer
run: make deps-install
- name: Test
run: make test

cs-check:
runs-on: ubuntu-latest
name: Code standard
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.1
- name: Set up PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
- name: Composer
run: make deps-install
- name: Code standard
Expand All @@ -84,10 +99,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up PHP 8.1
- name: Set up PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
extensions: xdebug
- name: Composer
run: make deps-install
Expand Down
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Stream implements StreamInterface {
public function read(int $length): string;
public function getContents(): string;
public function getMetadata(?string $key = null): mixed;

// Additional methods

public function getResource(): resource;
}
```

Expand All @@ -56,9 +60,34 @@ class SocketStream extends Stream {

// Methods

public function isConnected(): bool; // If stream is connected to remote
public function getRemoteName(): ?string; // Returns remote name
public function getLocalName(): ?string; // Returns local name
public function getResourceType(): string; // Get resource type
public function isBlocking(): ?bool; // If stream is blocking or not
public function setBlocking(bool $enable): bool; // Change blocking mode
public function setTimeout(int $seconds, int $microseconds = 0): bool; // Set timeout
public function readLine(int $length): ?string // Read a line from stream, up to $length bytes
}
```

## SockeClient class

The `Phrity\Net\SockeClient` class enables a client for remote socket.

```php
class SocketClient {

// Constructor

public function __construct(UriInterface $uri);

// Methods

public function setPersistent(bool $persistent): self; // If client should use persisten connection
public function setTimeout(?int $timeout): self; // Set timeout
public function setContext(?array $options = null, ?array $params = null): self; // Set stream context
public function connect(): ?SocketStream; // Connect to remote
}
```

Expand All @@ -76,7 +105,7 @@ class SocketServer extends Stream {
// Methods

public function accept(?int $timeout = null): ?SocketStream; // Accept connection on socket server
public function getTransports(): array; // Ge available transports
public function getTransports(): array; // Get available transports
public function isBlocking(): ?bool; // If stream is blocking or not
public function setBlocking(bool $enable): bool; // Change blocking mode
}
Expand Down Expand Up @@ -136,14 +165,29 @@ class StreamFactory implements StreamFactoryInterface {
// Additional methods

public function createSocketStreamFromResource($resource): SocketStream; // Create a socket stream
public function createSocketClient(UriInterface $uri): SocketClient; / Create socket client
public function createSocketServer(UriInterface $uri, int $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN): SocketServer; // Create a socket server
public function createStreamCollection(): StreamCollection; // Create a stream collection
}
```

## StreamException class

The `Phrity\Net\StreamException` is thrown when astream related error occurs.

```php
class StreamException extends RuntimeException {

// Constructor

public function __construct(int $code, array $data = [], ?Throwable $previous = null)
}
```

## Versions

| Version | PHP | |
| --- | --- | --- |
| `1.0` | `^7.4\|^8.0` | Initial version |
| `1.2` | `^7.4\|^8.0` | Socket client |
| `1.1` | `^7.4\|^8.0` | Stream collection |
| `1.0` | `^7.4\|^8.0` | Initial version |
70 changes: 35 additions & 35 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
{
"name": "phrity/net-stream",
"type": "library",
"description": "Socket stream classes implementing PSR-7 Stream and PSR-17 StreamFactory",
"homepage": "https://phrity.sirn.se/net-stream",
"keywords": ["socket", "stream", "stream factory", "client", "server", "PSR-7", "PSR-17"],
"license": "MIT",
"authors": [
{
"name": "Sören Jensen",
"email": "sirn@sirn.se",
"homepage": "https://phrity.sirn.se"
"name": "phrity/net-stream",
"type": "library",
"description": "Socket stream classes implementing PSR-7 Stream and PSR-17 StreamFactory",
"homepage": "https://phrity.sirn.se/net-stream",
"keywords": ["socket", "stream", "stream factory", "client", "server", "PSR-7", "PSR-17"],
"license": "MIT",
"authors": [
{
"name": "Sören Jensen",
"email": "sirn@sirn.se",
"homepage": "https://phrity.sirn.se"
}
],
"autoload": {
"psr-4": {
"Phrity\\Net\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phrity\\Net\\Test\\": "tests/"
}
},
"require": {
"php": "^7.4 | ^8.0",
"phrity/util-errorhandler": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 | ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0 | ^10.0",
"php-coveralls/php-coveralls": "^2.0",
"phrity/net-uri": "^1.1",
"squizlabs/php_codesniffer": "^3.0"
}
],
"autoload": {
"psr-4": {
"": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Phrity\\Net\\": "tests/classes/"
}
},
"require": {
"php": "^7.4|^8.0",
"phrity/util-errorhandler": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"php-coveralls/php-coveralls": "^2.0",
"phrity/net-uri": "^1.1",
"squizlabs/php_codesniffer": "^3.0"
}
}
}
109 changes: 0 additions & 109 deletions src/Phrity/Net/SocketServer.php

This file was deleted.

48 changes: 0 additions & 48 deletions src/Phrity/Net/SocketStream.php

This file was deleted.

Loading

0 comments on commit 83435f3

Please sign in to comment.