Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
update ...
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Sep 25, 2017
1 parent 7fbb791 commit ad31430
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 466 deletions.
3 changes: 2 additions & 1 deletion boot/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use inhere\library\di\Container;
use inhere\library\collections\Configuration;
use Sws\Async\StreamHandler;

// autoload
require dirname(__DIR__) . '/vendor/autoload.php';
Expand Down Expand Up @@ -37,7 +38,7 @@
$di->set('logger', function (Container $di) {
$opts = $di->get('config')->get('logger', []);

$fileHandler = new \Monolog\Handler\StreamHandler($opts['file']);
$fileHandler = new StreamHandler($opts['file']);
$mainHandler = new \Monolog\Handler\FingersCrossedHandler($fileHandler, (int)$opts['level'], $opts['bufferSize']);

$logger = new \Monolog\Logger($opts['name']);
Expand Down
2 changes: 1 addition & 1 deletion examples/asyn_mysql_pool_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require dirname(__DIR__) . '/vendor/autoload.php';

use Swoole\Http\Response;
use Sws\Components\AsyncMysqlPool;
use Sws\Async\AsyncMysqlPool;

$host = '127.0.0.1';
$port = 8399;
Expand Down
2 changes: 1 addition & 1 deletion examples/co_mysql_pool_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function debug($msg, array $data = [])
}


$pool = new \Sws\Components\CoroMysqlPool([
$pool = new \Sws\Coroutine\CoroMysqlPool([
'initSize' => 0,
'maxSize' => 1,
]);
Expand Down
22 changes: 15 additions & 7 deletions lib/sws/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
use inhere\console\utils\Show;
use Inhere\Http\Request;
use Inhere\Http\Response;
use inhere\library\collections\Configuration;
use inhere\library\log\Logger;
use Inhere\Route\ORouter;
use Inhere\Server\Helpers\StaticAccessHandler;
use Inhere\Server\Rpc\RpcDispatcher;
use Inhere\Server\Components\StaticResourceProcessor;
use Inhere\Server\Servers\HttpServer;
use Swoole\Http\Request as SwRequest;
use Swoole\Http\Response as SwResponse;
Expand All @@ -24,7 +20,6 @@
use Sws\Components\HttpHelper;
use Sws\Context\ContextManager;
use Sws\Context\HttpContext;
use Sws\Memory\Language;
use Sws\Module\ModuleInterface;
use Sws\Module\RootModule;
use Sws\WebSocket\Connection;
Expand Down Expand Up @@ -81,6 +76,19 @@ protected function beforeRun()
$this->options['assets'] = $this->get('config')->get('assets', []);
}

protected $middlewares = [];

/**
* @param callable $cb middleware :: (Context $ctx, $next) -> void
* @return $this
*/
public function use(callable $cb)
{
$this->middlewares[] = $cb;

return $this;
}

public function preLoading()
{
// collect routes
Expand Down Expand Up @@ -123,7 +131,7 @@ protected function beforeServerStart()
$config = $this->options['assets'];

// static handle
$this->staticAccessHandler = new StaticAccessHandler(BASE_PATH, $config['ext'], $config['dirMap']);
$this->staticAccessHandler = new StaticResourceProcessor(BASE_PATH, $config['ext'], $config['dirMap']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* Time: 16:30
*/

namespace Sws\Components;
namespace Sws\Async;

use Inhere\Pool\Swoole\ResourcePool;
use Inhere\Pool\Swoole\CoroSuspendPool;
use Swoole\MySQL;

/**
* Class AsyncMysqlPool
* @package Sws\Components
*/
class AsyncMysqlPool extends ResourcePool
class AsyncMysqlPool extends CoroSuspendPool
{
/**
* @var array
Expand Down
28 changes: 28 additions & 0 deletions lib/sws/Async/StreamHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Created by PhpStorm.
* User: inhere
* Date: 2017-09-25
* Time: 16:45
*/

namespace Sws\Async;

use Swoole\Async;

/**
* Class StreamHandler
* @package Sws\Async
*/
class StreamHandler extends \Monolog\Handler\StreamHandler
{
public $onWriteEnd;

/**
* {@inheritdoc}
*/
protected function write(array $record)
{
Async::writeFile($this->url, (string) $record['formatted'], $this->onWriteEnd, FILE_APPEND);
}
}
18 changes: 18 additions & 0 deletions lib/sws/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: inhere
* Date: 2017-09-25
* Time: 18:12
*/

namespace Sws\Cache;

/**
* Interface CacheInterface
* @package Sws\Cache
*/
interface CacheInterface
{
public static function __callStatic($method, array $args = []);
}
1 change: 1 addition & 0 deletions lib/sws/Context/ContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Inhere\Http\Request;
use Inhere\Http\Response;
use Sws\Coroutine\Coroutine;

/**
* Class ContextManager
Expand Down
1 change: 1 addition & 0 deletions lib/sws/Context/HttpContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Swoole\Http\Response as SwResponse;

use Sws\Components\HttpHelper;
use Sws\Coroutine\Coroutine;

/**
* Class HttpContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* Time: 15:11
*/

namespace Sws\Components;
namespace Sws\Coroutine;

use Inhere\Pool\Swoole\ResourcePool;
use Swoole\Coroutine;
use Inhere\Pool\Swoole\CoroSuspendPool;
use Swoole\Coroutine\MySQL;

/**
* Class CoroMysqlPool
* @package Sws\Components
*/
class CoroMysqlPool extends ResourcePool
class CoroMysqlPool extends CoroSuspendPool
{
/**
* @var array
Expand All @@ -40,11 +39,11 @@ public function create()
$conf = $this->options['db1'];
$db = new MySQL();

// debug('coId:' . Coroutine::getuid() . ' will create new db connection');
// debug('coId:' . Coroutine::id() . ' will create new db connection');

$db->connect($conf);

// debug('coId:' . Coroutine::getuid() . ' a new db connection created');
// debug('coId:' . Coroutine::id() . ' a new db connection created');

return $db;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
* Time: 15:11
*/

namespace Sws\Components;
namespace Sws\Coroutine;

use Inhere\Pool\Swoole\ResourcePool;
use Swoole\Coroutine;
use Inhere\Pool\Swoole\CoroSuspendPool;
use Swoole\Coroutine\Redis;

/**
* Class CoroRedisPool
* @package Sws\Components
*/
class CoroRedisPool extends ResourcePool
class CoroRedisPool extends CoroSuspendPool
{
/**
* 创建新的资源实例
Expand All @@ -26,11 +25,11 @@ public function create()
{
$rds = new Redis();

// debug('coId:' . Coroutine::getuid() . ' will create new redis connection');
// debug('coId:' . Coroutine::id() . ' will create new redis connection');

$rds->connect('redis', 6379);

// debug('coId:' . Coroutine::getuid() . ' a new redis connection created');
// debug('coId:' . Coroutine::id() . ' a new redis connection created');

return $rds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* Time: 14:33
*/

namespace Sws\Context;
namespace Sws\Coroutine;

use inhere\library\helpers\PhpHelper;
use Swoole\Coroutine as SwCoroutine;

/**
* Class Coroutine
* @package Sws\Context
* @package Sws\Coroutine
*/
class Coroutine
{
Expand Down
Loading

0 comments on commit ad31430

Please sign in to comment.