workerman 兼容linux和windows的方法

2017-07-30  本文已影响0人  Hawind
<?php 
/**
 * 这个文件自动识别win和linux平台
 * 使用方式: 把vendor/autoload.php 导入的代码换成此文件,并修改相关的路径
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @author    Hawind<hawind@qq.com>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
 */

if (DIRECTORY_SEPARATOR === '/') {
    // linux:
    $workermanDir = '/workerman';
    $gatewayDir   = '/gateway-worker/src';
} else {
    // windows:
    $workermanDir = '/workerman-for-win';
    $gatewayDir   = '/gateway-worker-for-win/src';
}

$vendorDir = __DIR__ . '/vendor';

// 自动加载类
$loader = require_once $vendorDir . '/autoload.php';

// 重新设置 Workerman 相关路径
$loader->setPsr4('Workerman\\', $vendorDir. '/workerman'. $workermanDir);
$loader->setPsr4('GatewayWorker\\', $vendorDir .'/workerman'. $gatewayDir);
上一篇下一篇

猜你喜欢

热点阅读