-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from inhere/master
update: add new tag ServerListener, some other update
- Loading branch information
Showing
23 changed files
with
338 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: inhere | ||
* Date: 2018/3/19 | ||
* Time: 上午11:43 | ||
*/ | ||
|
||
namespace Swoft\Bean\Annotation; | ||
|
||
/** | ||
* Class ServerListener | ||
* 跟 SwooleListener 差别不大,同样可用于监听Swoole的事件,是对 SwooleListener 的补充 | ||
* 区别是: | ||
* - SwooleListener 中事件的监听器只允许一个,并且是直接注册到 swoole server上的(监听相同事件将会被覆盖) | ||
* - ServerListener 允许对swoole事件添加多个监听器,会逐个通知 | ||
* - ServerListener 不影响 `/framework/src/Bootstrap/Server` 里基础swoole事件的绑定 | ||
* | ||
* @package Swoft\Bean\Annotation | ||
* | ||
* @Annotation | ||
* @Target("CLASS") | ||
*/ | ||
class ServerListener | ||
{ | ||
/** | ||
* the events of listener | ||
* | ||
* @var array | ||
*/ | ||
private $event; | ||
|
||
/** | ||
* AutoController constructor. | ||
* | ||
* @param array $values | ||
*/ | ||
public function __construct(array $values) | ||
{ | ||
if (isset($values['value'])) { | ||
$this->event = (array)$values['value']; | ||
} | ||
|
||
if (isset($values['event'])) { | ||
$this->event = (array)$values['event']; | ||
} | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getEvent(): array | ||
{ | ||
return $this->event ?: []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Swoft\Bean\Parser; | ||
|
||
use Swoft\Bean\Annotation\Scope; | ||
use Swoft\Bean\Annotation\ServerListener; | ||
use Swoft\Bean\Collector\ServerListenerCollector; | ||
|
||
/** | ||
* Class ServerListenerParser | ||
* @package Swoft\Bean\Parser | ||
* @author inhere <[email protected]> | ||
*/ | ||
class ServerListenerParser extends AbstractParser | ||
{ | ||
/** | ||
* @param string $className | ||
* @param ServerListener $objectAnnotation | ||
* @param string $propertyName | ||
* @param string $methodName | ||
* @param mixed $propertyValue | ||
* | ||
* @return array | ||
*/ | ||
public function parser(string $className, $objectAnnotation = null, string $propertyName = '', string $methodName = '', $propertyValue = null) | ||
{ | ||
$beanName = $className; | ||
$scope = Scope::SINGLETON; | ||
|
||
ServerListenerCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue); | ||
|
||
return [$beanName, $scope, '']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Swoft\Bean\Wrapper; | ||
|
||
use Swoft\Bean\Annotation\ServerListener; | ||
use Swoft\Bean\Annotation\Inject; | ||
|
||
/** | ||
* Class ServerListenerWrapper | ||
* @package Swoft\Bean\Wrapper | ||
* @author inhere <[email protected]> | ||
*/ | ||
class ServerListenerWrapper extends AbstractWrapper | ||
{ | ||
/** | ||
* Class annotation | ||
* | ||
* @var array | ||
*/ | ||
protected $classAnnotations = [ | ||
ServerListener::class, | ||
]; | ||
|
||
/** | ||
* Property annotations | ||
* | ||
* @var array | ||
*/ | ||
protected $propertyAnnotations = [ | ||
Inject::class, | ||
]; | ||
|
||
/** | ||
* 是否解析类注解 | ||
* | ||
* @param array $annotations | ||
* @return bool | ||
*/ | ||
public function isParseClassAnnotations(array $annotations): bool | ||
{ | ||
return isset($annotations[ServerListener::class]); | ||
} | ||
|
||
/** | ||
* 是否解析属性注解 | ||
* | ||
* @param array $annotations | ||
* @return bool | ||
*/ | ||
public function isParsePropertyAnnotations(array $annotations): bool | ||
{ | ||
return isset($annotations[Inject::class]); | ||
} | ||
|
||
/** | ||
* @param array $annotations | ||
* @return bool | ||
*/ | ||
public function isParseMethodAnnotations(array $annotations): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Bootstrap/Listeners/Interfaces/ManagerStartInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Swoft\Bootstrap\Listeners\Interfaces; | ||
|
||
use Swoole\Server; | ||
|
||
/** | ||
* Interface ManagerStartInterface | ||
* @package Swoft\Bootstrap\Listeners\Interfaces | ||
*/ | ||
interface ManagerStartInterface | ||
{ | ||
public function onManagerStart(Server $server); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Bootstrap/Listeners/Interfaces/WorkerStartInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Swoft\Bootstrap\Listeners\Interfaces; | ||
|
||
use Swoole\Server; | ||
|
||
/** | ||
* Interface WorkerStartInterface | ||
* @package Swoft\Bootstrap\Listeners\Interfaces | ||
*/ | ||
interface WorkerStartInterface | ||
{ | ||
public function onWorkerStart(Server $server, int $workerId, bool $isWorker); | ||
} |
Oops, something went wrong.