Skip to content

Commit 0fe3b9c

Browse files
committed
⭐ First commit!
1 parent a96bea6 commit 0fe3b9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2390
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.editorconfig
2+
.phpunit.result.cache
3+
reports
4+
vendor
5+
composer.lock

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
env:
2+
global:
3+
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
4+
5+
language: php
6+
7+
php:
8+
- '7.4'
9+
- nightly
10+
11+
before_script:
12+
- composer install
13+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14+
- chmod +x ./cc-test-reporter
15+
- ./cc-test-reporter before-build
16+
- echo "xdebug.mode=coverage" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
17+
18+
script:
19+
- php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src
20+
- php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true
21+
- php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist --coverage-text --coverage-clover build/logs/clover.xml
22+
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 rtckit
3+
Copyright (c) 2022 Ciprian Dosoftei
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# FreeSWITCH Event Socket Layer library for PHP
2+
3+
[![Build Status](https://travis-ci.com/rtckit/php-esl.svg?branch=main)](https://travis-ci.com/rtckit/php-esl)
4+
[![Latest Stable Version](https://poser.pugx.org/rtckit/esl/v/stable.png)](https://packagist.org/packages/rtckit/esl)
5+
[![Test Coverage](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/test_coverage)](https://codeclimate.com/github/rtckit/php-esl/test_coverage)
6+
[![Maintainability](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/maintainability)](https://codeclimate.com/github/rtckit/php-esl/maintainability)
7+
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
8+
9+
## Quickstart
10+
11+
[FreeSWITCH](https://github.com/signalwire/freeswitch)'s Event Socket Layer is a TCP control interface enabling the development of complex dynamic dialplans/workflows. You can learn more about its [inbound mode](https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket) as well as its [outbound mode](https://freeswitch.org/confluence/display/FREESWITCH/Event+Socket+Outbound) on the FreeSWITCH website.
12+
13+
This library provides an I/O agnostic implementation of the ESL protocol.
14+
15+
#### ESL Message Parsing
16+
17+
The authentication stage of an ESL connection can be summarized as follows:
18+
19+
```php
20+
/* This is a typical FreeSWITCH ESL server greeting */
21+
$response = \RTCKit\ESL\Response::Parse("Content-Type: auth/request\n\n");
22+
23+
echo 'A server sends: ' . get_class($response) . PHP_EOL;
24+
25+
/* Since we've been told to authenticate, let's prepare our auth request */
26+
$request = \RTCKit\ESL\Request::parse("auth ClueCon\n\n");
27+
28+
echo 'A client responds with: ' . get_class($request) . '; ';
29+
echo 'password: ' . $request->getParameters() . PHP_EOL;
30+
31+
/* If our secret is correct, the ESL server should confirm that */
32+
$followup = \RTCKit\ESL\Response::parse("Content-Type: command/reply\nReply-Text: +OK accepted\n\n");
33+
34+
echo 'Then the server replies with: ' . get_class($followup) . '; ';
35+
echo ($followup->isSuccessful() ? 'Success!' : 'Yikes!') . PHP_EOL;
36+
```
37+
38+
#### ESL Message Rendering
39+
40+
The reverse procedure, rendering to string, is straightforward:
41+
42+
```php
43+
$response = new \RTCKit\ESL\Response\AuthRequest;
44+
45+
echo 'A server sends: "' . $response->render() . '"' . PHP_EOL;
46+
47+
$request = new \RTCKit\ESL\Request\Auth;
48+
$request->setParameters('ClueCon');
49+
50+
echo 'A client responds with: "' . $request->render() . '"' . PHP_EOL;
51+
52+
$followup = new \RTCKit\ESL\Response\CommandReply;
53+
$followup->setHeader('reply-text', '+OK accepted');
54+
55+
echo 'Then the server replies with: "' . $followup->render() . '"' . PHP_EOL;
56+
```
57+
58+
#### ESL Connection
59+
60+
Although this library is I/O independent, a Connection [interface](src/ConnectionInterface.php) and [base class](src/Connection.php) are being provided; since ESL runs over TCP, a stream oriented transport, it behooves to handle the message framing in a higher level library. An implementing project would simply invoke the `ConnectionInterface::consume()` method when input is available and would implement a `ConnectionInterface::emitBytes()` method which performs the corresponding I/O-specific write operations.
61+
62+
The Connection constructor requires a `$role` argument, which must be one of the following:
63+
64+
* `ConnectionInterface::INBOUND_CLIENT` to be used by ESL clients connecting to FreeSWITCH ESL servers;
65+
* `ConnectionInterface::OUTBOUND_SERVER` to be used by ESL servers FreeSWITCH connects to in outbound mode;
66+
67+
The other two options are less common:
68+
69+
* `ConnectionInterface::INBOUND_SERVER` to impersonate a FreeSWITCH ESL server;
70+
* `ConnectionInterface::OUTBOUND_CLIENT` to impersonate FreeSWITCH connecting to a remote ESL endpoint in outbound mode;
71+
72+
The latter two roles can be useful in test suites, implementing message relays, security research etc. Please note the inbound and outbound terms are relative to the FreeSWITCH endpoint (matching the [mod_event_socket mode](https://freeswitch.org/confluence/display/FREESWITCH/mod_event_socket) nomenclature).
73+
74+
## Requirements
75+
76+
**RTCKit\ESL** is compatible with PHP 7.4+ and has no external library and extension dependencies.
77+
78+
## Installation
79+
80+
You can add the library as project dependency using [Composer](https://getcomposer.org/):
81+
82+
```sh
83+
composer require rtckit/esl
84+
```
85+
86+
If you only need the library during development, for instance when used in your test suite, then you should add it as a development-only dependency:
87+
88+
```sh
89+
composer require --dev rtckit/esl
90+
```
91+
92+
## Tests
93+
94+
To run the test suite, clone this repository and then install dependencies via Composer:
95+
96+
```sh
97+
composer install
98+
```
99+
100+
Then, go to the project root and run:
101+
102+
```bash
103+
composer phpunit
104+
```
105+
106+
### Static Analysis
107+
108+
In order to ensure high code quality, **RTCKit\ESL** uses [PHPStan](https://github.com/phpstan/phpstan) and [Psalm](https://github.com/vimeo/psalm):
109+
110+
```sh
111+
composer phpstan
112+
composer psalm
113+
```
114+
115+
## License
116+
117+
MIT, see [LICENSE file](LICENSE).
118+
119+
### Acknowledgments
120+
121+
* [FreeSWITCH](https://github.com/signalwire/freeswitch), FreeSWITCH is a registered trademark of Anthony Minessale II
122+
123+
### Contributing
124+
125+
Bug reports (and small patches) can be submitted via the [issue tracker](https://github.com/rtckit/php-esl/issues). Forking the repository and submitting a Pull Request is preferred for substantial patches.

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "rtckit/esl",
3+
"description": "FreeSWITCH Event Socket Layer (ESL) Library",
4+
"version": "0.8.0",
5+
"type": "library",
6+
"keywords": [
7+
"freeswitch",
8+
"event socket layer",
9+
"esl",
10+
"telephony",
11+
"telco"
12+
],
13+
"homepage": "https://github.com/rtckit/php-esl",
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Ciprian Dosoftei"
18+
}
19+
],
20+
"support": {
21+
"email": "hello@rtckit.io",
22+
"issues": "https://github.com/rtckit/php-esl/issues"
23+
},
24+
"require": {
25+
"php": ">=7.4.0"
26+
},
27+
"require-dev": {
28+
"phpstan/phpstan": "^1.4",
29+
"phpunit/phpunit": "^9.5",
30+
"vimeo/psalm": "^4.18"
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"RTCKit\\ESL\\": "src"
35+
}
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"RTCKit\\ESL\\Tests\\": "tests"
40+
}
41+
},
42+
"scripts": {
43+
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src",
44+
"psalm": "php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true",
45+
"phpunit": "php -d memory_limit=-1 ./vendor/bin/phpunit --debug -c ./etc/phpunit.xml.dist",
46+
"coverage": "php -d memory_limit=-1 ./vendor/bin/phpunit --debug -c ./etc/phpunit.xml.dist --coverage-text --coverage-html=reports/coverage"
47+
}
48+
}

0 commit comments

Comments
 (0)