<commit_before><?php

namespace SyntaxError\SocketBundle\Server;

use React\EventLoop\Factory;
use React\Socket\Server;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

class Creator
{
    private $server;

    private $informer;

    public function __construct()
    {
        $config = Config::create();
        $this->informer = new Informer( $this->createAbsoluteLogPath($config['log']) );

        $loop = Factory::create();

        $this->server = new IoServer(
            new HttpServer(
                new WsServer(
                    new $config['task']($loop, $this->informer, $config)
                )
            ),
            $this->createSocket($config['bind'], $config['port'], $loop), $loop
        );

        $this->informer->addInfo( 'SERVER', 'Created socket on '.$config['bind'] );
        $this->informer->addInfo( 'SERVER', 'Logged to '.$config['log']." file.");
    }

    private function createSocket($addr, $port, $loop)
    {
        $socket = new Server($loop);
        $socket->listen($port, $addr);
        return $socket;
    }

    private function createAbsoluteLogPath($path)
    {
        return preg_match('/\.\./', $path) ? __DIR__.$path : $path;
    }

    public function run()
    {
        $info = 'Server started at '.$this->server->socket->getPort()." port.";
        $this->informer->addInfo('SERVER', $info);
        Config::setPid();
        $this->server->run();
        return $this;
    }
}<commit_msg>add alert if cannot save pid file<commit_after><?php

namespace SyntaxError\SocketBundle\Server;

use React\EventLoop\Factory;
use React\Socket\Server;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

class Creator
{
    private $server;

    private $informer;

    public function __construct()
    {
        $config = Config::create();
        $this->informer = new Informer( $this->createAbsoluteLogPath($config['log']) );

        $loop = Factory::create();

        $this->server = new IoServer(
            new HttpServer(
                new WsServer(
                    new $config['task']($loop, $this->informer, $config)
                )
            ),
            $this->createSocket($config['bind'], $config['port'], $loop), $loop
        );

        $this->informer->addInfo( 'SERVER', 'Created socket on '.$config['bind'] );
        $this->informer->addInfo( 'SERVER', 'Logged to '.$config['log']." file.");
    }

    private function createSocket($addr, $port, $loop)
    {
        $socket = new Server($loop);
        $socket->listen($port, $addr);
        return $socket;
    }

    private function createAbsoluteLogPath($path)
    {
        return preg_match('/\.\./', $path) ? __DIR__.$path : $path;
    }

    public function run()
    {
        $info = 'Server started at '.$this->server->socket->getPort()." port.";
        $this->informer->addInfo('SERVER', $info);
        if( !(Config::setPid()) ) {
            $this->informer->addAlert('SERVER_NOTICE', 'Cannot save pid file. Check permissions.');
        };
        $this->server->run();
        return $this;
    }
}
{'fraction_non_alphanumeric': 0.16671969455933822, 'fraction_numerical': 0.0, 'mean_word_length': 2.40997830802603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5099889', 'n_tokens_mistral': 942, 'n_tokens_neox': 920, 'n_words': 200}