Skip to content

Commit e45613d

Browse files
authored
Merge pull request #2 from micilini/phase-01-composer-foundation
phase 01: add composer library foundation
2 parents ab1bc54 + 62472c9 commit e45613d

11 files changed

Lines changed: 470 additions & 12 deletions

File tree

.github/workflows/tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
name: PHP ${{ matrix.php-version }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version:
18+
- '8.2'
19+
- '8.3'
20+
- '8.4'
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.php-version }}
30+
extensions: sockets, json, pdo
31+
coverage: none
32+
33+
- name: Install dependencies
34+
run: composer install --no-interaction --prefer-dist
35+
36+
- name: Validate Composer package
37+
run: composer validate --strict
38+
39+
- name: Check code style
40+
run: composer cs:check
41+
42+
- name: Run static analysis
43+
run: composer analyse
44+
45+
- name: Run tests
46+
run: composer test

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/vendor/
2+
/composer.lock
3+
4+
/.phpunit.cache/
5+
/.php-cs-fixer.cache
6+
/.phpstan.cache
7+
/coverage/
8+
/build/
9+
/dist/
10+
11+
.zip
12+
.env
13+
.env.*
14+
!.env.example
15+
16+
*.log
17+
*.tmp
18+
*.temp
19+
*.cache
20+
21+
.DS_Store
22+
Thumbs.db
23+
desktop.ini
24+
25+
.idea/
26+
.vscode/
27+
*.sublime-project
28+
*.sublime-workspace
29+
30+
.phpunit.result.cache
31+
32+
/storage/*.sqlite
33+
/storage/*.sqlite3
34+
/storage/*.db
35+
36+
node_modules/
37+
npm-debug.log*
38+
yarn-debug.log*
39+
yarn-error.log*
40+
pnpm-debug.log*
41+
42+
/.phpunit.cache

.php-cs-fixer.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests')
6+
->name('*.php');
7+
8+
return (new PhpCsFixer\Config())
9+
->setRiskyAllowed(true)
10+
->setRules([
11+
'@PSR12' => true,
12+
'array_syntax' => ['syntax' => 'short'],
13+
'declare_strict_types' => true,
14+
'no_unused_imports' => true,
15+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
16+
'single_quote' => true,
17+
])
18+
->setFinder($finder);

README.md

Lines changed: 130 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,116 @@
11
# PHPSockets With WebSockets
22

3-
PHPSockets With WebSockets is being reborn as a modern native PHP WebSocket and realtime chat library.
3+
> **Maintenance notice:** this repository is being actively rebuilt as a modern native PHP WebSocket and realtime chat library. The legacy 2016 implementation is preserved for historical reference, while the new Composer-based library is being implemented phase by phase.
44
5-
The original project was created in 2016 as a simple educational experiment showing how to build a WebSocket server with PHP sockets, without Node.js and without socket.io.
5+
PHPSockets With WebSockets was originally created in 2016 as an educational experiment showing how to build a WebSocket server with PHP sockets, without Node.js and without socket.io.
66

7-
This repository is now being progressively redesigned as a Composer package with a clean architecture, modern PHP support, examples, tests, storage adapters, CLI commands, Laravel integration, and a stronger chat-focused developer experience.
7+
The project is now being progressively redesigned as a Composer package with a clean architecture, modern PHP support, examples, tests, storage adapters, CLI commands, optional Laravel integration, and a stronger chat-focused developer experience.
88

99
## Current status
1010

11-
This repository is currently in the legacy preservation phase.
11+
The project is currently in the **Composer foundation phase**.
1212

13-
The original 2016 implementation has been moved to the `legacy/` directory so it can be preserved as historical reference while the new library is built from scratch in future phases.
13+
This means the repository already has the initial Composer package structure, PSR-4 namespace configuration, base configuration classes, PHPUnit setup, PHPStan setup, PHP CS Fixer setup, and GitHub Actions workflow.
14+
15+
The modern WebSocket runtime is not implemented yet.
16+
17+
## Installation for development
18+
19+
Clone the repository and install dependencies:
20+
21+
```bash
22+
composer install
23+
```
24+
25+
Validate the Composer package:
26+
27+
```bash
28+
composer validate --strict
29+
```
30+
31+
Run the test suite:
32+
33+
```bash
34+
composer test
35+
```
36+
37+
Run static analysis:
38+
39+
```bash
40+
composer analyse
41+
```
42+
43+
Check code style:
44+
45+
```bash
46+
composer cs:check
47+
```
48+
49+
Run all quality checks:
50+
51+
```bash
52+
composer quality
53+
```
54+
55+
Fix code style automatically:
56+
57+
```bash
58+
composer cs:fix
59+
```
60+
61+
## Requirements
62+
63+
The modern version targets:
64+
65+
- PHP 8.2 or higher.
66+
- `ext-sockets`.
67+
- `ext-json`.
68+
- Composer.
69+
70+
Optional future features may require:
71+
72+
- `ext-pdo` for SQL storage adapters.
73+
- Laravel packages for optional Laravel integration.
74+
75+
## Namespace
76+
77+
The modern library uses the following namespace:
78+
79+
```txt
80+
Micilini\PhpSockets\
81+
```
82+
83+
The current public entry point is:
84+
85+
```php
86+
use Micilini\PhpSockets\WebSocket;
87+
88+
echo WebSocket::version();
89+
```
90+
91+
## Current structure
92+
93+
```txt
94+
src/
95+
WebSocket.php
96+
Config/
97+
ServerConfig.php
98+
ChatConfig.php
99+
100+
tests/
101+
Unit/
102+
SanityTest.php
103+
104+
legacy/
105+
EasyChat/
106+
MediumChat/
107+
README-2016.md
108+
NOTES.md
109+
```
14110

15111
## Legacy code
16112

17-
The original code is available here:
113+
The original 2016 implementation is preserved here:
18114

19115
```txt
20116
legacy/EasyChat
@@ -26,6 +122,8 @@ legacy/README-2016.md
26122

27123
`MediumChat` contains the more advanced object-oriented version with callbacks and a better separation between the WebSocket server and the chat behavior.
28124

125+
The legacy implementation is kept for historical and educational purposes only. The modern library will be implemented separately and should not depend on the old code structure.
126+
29127
## Why the legacy code was moved
30128

31129
The old project was designed for PHP 5 and browser-based local testing. At that time, the server could be started by opening `server.php` in the browser or by running it manually.
@@ -53,16 +151,36 @@ The new implementation will be developed gradually and will include:
53151
- Laravel integration.
54152
- Tests, static analysis, and CI.
55153

56-
## Roadmap
154+
## Roadmap phases
155+
156+
The project is being implemented phase by phase:
157+
158+
```txt
159+
Phase 00: Legacy preservation.
160+
Phase 01: Composer foundation, namespace, quality tools, and CI.
161+
Phase 02: WebSocket protocol core.
162+
Phase 03: Server runtime and events.
163+
Phase 04: Chat core and unique usernames.
164+
Phase 05: Modern EasyChat example.
165+
Phase 06: MediumChat example with callbacks.
166+
Phase 07: Private direct messaging.
167+
Phase 08: Private group rooms.
168+
Phase 09: Storage adapters and migrations.
169+
Phase 10: CLI runtime commands.
170+
Phase 11: Small attachments and emoji-safe payloads.
171+
Phase 12: Bot hooks and automation events.
172+
Phase 13: Laravel integration.
173+
Phase 14: Release documentation and Packagist preparation.
174+
```
57175

58-
Implementation will follow the project roadmap phase by phase.
176+
## Production readiness
59177

60-
The first phase preserves the legacy code and creates a clean baseline.
178+
This package is not production-ready yet.
61179

62-
Future phases will introduce Composer, source code structure, WebSocket protocol handling, server runtime, chat features, examples, persistence, CLI tooling, and release documentation.
180+
The repository is currently being rebuilt. The modern WebSocket protocol, server runtime, chat system, examples, storage adapters, CLI commands, and Laravel integration will be added in future phases.
63181

64182
## Important note
65183

66-
The legacy implementation is kept for historical and educational purposes.
184+
The goal is not only to restore an old chat demo.
67185

68-
The new library will be implemented separately and should not depend on the old code structure.
186+
The goal is to transform PHPSockets With WebSockets into a modern, educational, extensible, native PHP realtime library.

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "micilini/php-sockets-with-websockets",
3+
"description": "Native PHP WebSocket and realtime chat library built from scratch. Works standalone or with Laravel.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"websocket",
8+
"sockets",
9+
"chat",
10+
"realtime",
11+
"php",
12+
"laravel"
13+
],
14+
"require": {
15+
"php": "^8.2",
16+
"ext-sockets": "*",
17+
"ext-json": "*"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^10.0|^11.0",
21+
"phpstan/phpstan": "^1.10|^2.0",
22+
"friendsofphp/php-cs-fixer": "^3.0"
23+
},
24+
"suggest": {
25+
"ext-pdo": "Required for SQL storage adapters and migrations.",
26+
"illuminate/support": "Required for Laravel integration."
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Micilini\\PhpSockets\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Micilini\\PhpSockets\\Tests\\": "tests/"
36+
}
37+
},
38+
"scripts": {
39+
"test": "phpunit",
40+
"analyse": "phpstan analyse src tests --memory-limit=512M",
41+
"cs:check": "php-cs-fixer fix --dry-run --diff",
42+
"cs:fix": "php-cs-fixer fix",
43+
"quality": [
44+
"@cs:check",
45+
"@analyse",
46+
"@test"
47+
]
48+
},
49+
"minimum-stability": "stable",
50+
"prefer-stable": true
51+
}

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
- tests

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
cacheDirectory=".phpunit.cache">
7+
<testsuites>
8+
<testsuite name="PHPSockets Test Suite">
9+
<directory>tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>

0 commit comments

Comments
 (0)