BaseAnalyse.php 820 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace common\logic\analyse;
  3. use common\traits\ErrorTrait;
  4. class BaseAnalyse{
  5. use ErrorTrait;
  6. public function getHandlers(){
  7. return [
  8. // CardAnalyse::class, // 名片分析处理
  9. ];
  10. }
  11. /**
  12. * 运行
  13. * @param $list
  14. * @return object|mixed
  15. */
  16. public function run($list)
  17. {
  18. try{
  19. $handlers = $this->getHandlers();
  20. if ($handlers) {
  21. foreach ($handlers as $key => $handler) {
  22. $item = $handler::analyse($list);
  23. if($item === false) throw new \Exception($handler::getStaticError());
  24. }
  25. }
  26. return true;
  27. }catch(\Exception $e){
  28. $this->setError($e->getMessage());
  29. return false;
  30. }
  31. }
  32. }