-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add error Stack * add ErrorStack
- Loading branch information
Showing
7 changed files
with
161 additions
and
75 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
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,71 @@ | ||
<?php | ||
|
||
namespace ethercap\apiBase\components; | ||
|
||
use yii\base\Component; | ||
use yii\base\Model; | ||
|
||
/** | ||
* Class ResBuilderErrorStack | ||
* @package ethercap\apiBase\components | ||
* | ||
* @property string $creator | ||
* @property Model $errorModel | ||
* @property Model[] $errors | ||
*/ | ||
class ResBuilderErrorStack extends Component | ||
{ | ||
private $_creator; | ||
|
||
private $_stack = []; | ||
|
||
private static $_stacks = []; | ||
|
||
private static $_instance; | ||
|
||
public static function getInstance(string $creator) | ||
{ | ||
if (self::$_instance === null) { | ||
self::$_instance = new self(); | ||
self::$_instance->_creator = $creator; | ||
} | ||
return self::$_instance; | ||
} | ||
|
||
public function getCreator() | ||
{ | ||
return $this->_creator; | ||
} | ||
|
||
public function pushError($errorModels) | ||
{ | ||
if (!is_array($errorModels)) { | ||
$errorModels = [$errorModels]; | ||
} | ||
return array_push($this->_stack, ...$errorModels); | ||
} | ||
|
||
public function getErrorModel() | ||
{ | ||
return reset($this->_stack); | ||
} | ||
|
||
public function getErrors() | ||
{ | ||
return $this->_stack; | ||
} | ||
|
||
public function hasError() | ||
{ | ||
return (bool) count($this->_stack); | ||
} | ||
|
||
/** | ||
* 释放当前builder的error信息 | ||
*/ | ||
public function clear() | ||
{ | ||
self::$_stacks[$this->_creator] = $this->_stack; | ||
self::$_instance = null; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.