Ejemplo n.º 1
0
 /**
  * @dataProvider providerLog
  */
 public function testLog($level, $expected)
 {
     $runName = uniqid('', true);
     $fileName = 'testfile_log_' . date('Ymd_His') . '_' . $runName . '.log';
     if (file_exists('test_data/' . $fileName)) {
         $filesystem = new Filesystem();
         $filesystem->remove('test_data/' . $fileName);
     }
     $log = new Logger('tester');
     $log->pushHandler(new StreamHandler('test_data/' . $fileName, $level));
     $log->debug('test1');
     $log->info('test2');
     $log->notice('test3');
     $log->warning('test4');
     $log->error('test5');
     $log->critical('test6');
     $log->alert('test7');
     $log->emergency('test8');
     $this->assertRegExp('/^' . $expected . '/s', file_get_contents('test_data/' . $fileName));
 }
Ejemplo n.º 2
0
$log->pushHandler(new StreamHandler('php://stdout', Logger::INFO));
$log->pushHandler(new StreamHandler('log/bootstrap.log', Logger::DEBUG));
UriFactory::registerScheme('tcp', 'TheFox\\PhpChat\\TcpUri');
UriFactory::registerScheme('http', 'TheFox\\PhpChat\\HttpUri');
$settings = new Settings(__DIR__ . '/settings.yml');
if (isset($settings->data['datadir']) && !file_exists($settings->data['datadir'])) {
    $log->info('create datadir: ' . $settings->data['datadir']);
    $filesystem->mkdir($settings->data['datadir'], 0700);
}
if (!$settings->data['node']['sslKeyPrvPass']) {
    $sslKeyPrvPass = '';
    try {
        $log->info('ssl: generate private key password');
        $sslKeyPrvPass = (string) Uuid::uuid4();
    } catch (UnsatisfiedDependencyException $e) {
        $log->critical('uuid4: ' . $e->getMessage());
        exit(1);
    }
    $settings->data['node']['sslKeyPrvPass'] = hash('sha512', mt_rand(0, 999999) . '_' . time() . '_' . $sslKeyPrvPass);
    $settings->setDataChanged(true);
}
$keyPub = null;
if (file_exists($settings->data['node']['sslKeyPrvPath'])) {
    $sslPubKey = openssl_pkey_get_public(file_get_contents($settings->data['node']['sslKeyPubPath']));
    if ($sslPubKey) {
        $sslPubKeyDetails = openssl_pkey_get_details($sslPubKey);
        if (isset($sslPubKeyDetails['key'])) {
            $keyPub = $sslPubKeyDetails['key'];
        }
    }
} else {