src/BotManFactory.php
public static function createForSocket(
        array $config,
        LoopInterface $loop,
        CacheInterface $cache = null,
        StorageInterface $storageDriver = null
    ) {
        $port = isset($config['port']) ? $config['port'] : 8080;

        $socket = new Server($loop);

        if (empty($cache)) {
            $cache = new ArrayCache();
        }

        if (empty($storageDriver)) {
            $storageDriver = new FileStorage(__DIR__);
        }

        $driverManager = new DriverManager($config, new Curl());

        $botman = new BotMan($cache, DriverManager::loadFromName('Null', $config), $config, $storageDriver);
        $botman->runsOnSocket(true);

        $socket->on('connection', function ($conn) use ($botman, $driverManager) {
            $conn->on('data', function ($data) use ($botman, $driverManager) {
                $requestData = json_decode($data, true);
                $request = new Request($requestData['query'], $requestData['request'], $requestData['attributes'], [], [], [], $requestData['content']);
                $driver = $driverManager->getMatchingDriver($request);
                $botman->setDriver($driver);
                $botman->listen();
            });
        });
        $socket->listen($port);

        return $botman;
    }
public static function createForSocket(
        array $config,
        LoopInterface $loop,
        CacheInterface $cache = null,
        StorageInterface $storageDriver = null
    ) {
        $port = isset($config['port']) ? $config['port'] : 8080;

        $socket = new Server($loop);

        if (empty($cache)) {
            $cache = new ArrayCache();
        }

        if (empty($storageDriver)) {
            $storageDriver = new FileStorage(__DIR__);
        }

        $driverManager = new DriverManager($config, new Curl());

        $botman = new BotMan($cache, DriverManager::loadFromName('Null', $config), $config, $storageDriver);
        $botman->runsOnSocket(true);

        $socket->on('connection', function ($conn) use ($botman, $driverManager) {
            $conn->on('data', function ($data) use ($botman, $driverManager) {
                $requestData = json_decode($data, true);
                $request = new Request($requestData['query'], $requestData['request'], $requestData['attributes'], [], [], [], $requestData['content']);
                $driver = $driverManager->getMatchingDriver($request);
                $botman->setDriver($driver);
                $botman->listen();
            });
        });
        $socket->listen($port);

        return $botman;
    }
public static function createForSocket ( array $ config , LoopInterface $ loop , CacheInterface $ cache = null , StorageInterface $ storageDriver = null ) { $ port = isset ( $ config [ 'port' ] ) ? $ config [ 'port' ] : 8080 ; $ socket = new Server ( $ loop ) ; if ( empty ( $ cache ) ) { $ cache = new ArrayCache ( ) ; } if ( empty ( $ storageDriver ) ) { $ storageDriver = new FileStorage ( __DIR__ ) ; } $ driverManager = new DriverManager ( $ config , new Curl ( ) ) ; $ botman = new BotMan ( $ cache , DriverManager :: loadFromName ( 'Null' , $ config ) , $ config , $ storageDriver ) ; $ botman -> runsOnSocket ( true ) ; $ socket -> on ( 'connection' , function ( $ conn ) use ( $ botman , $ driverManager ) { $ conn -> on ( 'data' , function ( $ data ) use ( $ botman , $ driverManager ) { $ requestData = json_decode ( $ data , true ) ; $ request = new Request ( $ requestData [ 'query' ] , $ requestData [ 'request' ] , $ requestData [ 'attributes' ] , [ ] , [ ] , [ ] , $ requestData [ 'content' ] ) ; $ driver = $ driverManager -> getMatchingDriver ( $ request ) ; $ botman -> setDriver ( $ driver ) ; $ botman -> listen ( ) ; } ) ; } ) ; $ socket -> listen ( $ port ) ; return $ botman ; }
Create a new BotMan instance that listens on a socket.

@param array $config
@param LoopInterface $loop
@param CacheInterface $cache
@param StorageInterface $storageDriver
@return \BotMan\BotMan\BotMan
Create a new BotMan instance that listens on a socket .