Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2018-03-03 17:23:27 +00:00 committed by StyleCI Bot
parent 9014506ef5
commit 28921b4db4
3 changed files with 28 additions and 16 deletions

View File

@ -1,4 +1,3 @@
<?php <?php
require 'vendor/autoload.php'; require 'vendor/autoload.php';

View File

@ -20,10 +20,14 @@ class Server
{ {
private $settings; private $settings;
private $pids = []; private $pids = [];
public function __construct($settings) {
public function __construct($settings)
{
$this->settings = $settings; $this->settings = $settings;
} }
public function start() {
public function start()
{
pcntl_signal(SIGTERM, [$this, 'sig_handler']); pcntl_signal(SIGTERM, [$this, 'sig_handler']);
pcntl_signal(SIGINT, [$this, 'sig_handler']); pcntl_signal(SIGINT, [$this, 'sig_handler']);
pcntl_signal(SIGCHLD, [$this, 'sig_handler']); pcntl_signal(SIGCHLD, [$this, 'sig_handler']);
@ -36,26 +40,30 @@ class Server
$this->handle($this->sock->accept()); $this->handle($this->sock->accept());
} }
} }
private function handle($socket) {
private function handle($socket)
{
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid == -1) { if ($pid == -1) {
die('could not fork'); die('could not fork');
} else if ($pid) { } elseif ($pid) {
return $this->pids[] = $pid; return $this->pids[] = $pid;
} }
$handler = new \danog\MadelineProto\Server\Handler($socket); $handler = new \danog\MadelineProto\Server\Handler($socket);
$handler->loop(); $handler->loop();
die; die;
} }
public function __destruct() {
public function __destruct()
{
foreach ($this->pid as $pid) { foreach ($this->pid as $pid) {
pcntl_wait($pid); pcntl_wait($pid);
} }
} }
public function sig_handler($sig) public function sig_handler($sig)
{ {
switch($sig) switch ($sig) {
{
case SIGTERM: case SIGTERM:
case SIGINT: case SIGINT:
exit(); exit();

View File

@ -19,16 +19,21 @@ namespace danog\MadelineProto\Server;
class Handler class Handler
{ {
private $socket; private $socket;
public function __construct($socket) {
public function __construct($socket)
{
$this->socket = $socket; $this->socket = $socket;
} }
public function loop() {
public function loop()
{
} }
public function read_payload() {
public function read_payload()
{
} }
public function write_payload($payload) {
public function write_payload($payload)
{
} }
} }