Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RequestFsm.php
001 <?php
002 namespace GuzzleHttp;
003
004 use GuzzleHttp\Event\BeforeEvent;
005 use GuzzleHttp\Event\ErrorEvent;
006 use GuzzleHttp\Event\CompleteEvent;
007 use GuzzleHttp\Event\EndEvent;
008 use GuzzleHttp\Exception\StateException;
009 use GuzzleHttp\Exception\RequestException;
010 use GuzzleHttp\Message\FutureResponse;
011 use GuzzleHttp\Message\MessageFactoryInterface;
012 use GuzzleHttp\Ring\Future\FutureInterface;
013
014 /**
015 * Responsible for transitioning requests through lifecycle events.
016 */
017 class RequestFsm
018 {
019 private $handler;
020 private $mf;
021 private $maxTransitions;
022
023 public function __construct(
024 callable $handler,
025 MessageFactoryInterface $messageFactory,
026 $maxTransitions = 200
027 ) {
028 $this->mf = $messageFactory;
029 $this->maxTransitions = $maxTransitions;
030 $this->handler = $handler;
031 }
032
033 /**
034 * Runs the state machine until a terminal state is entered or the
035 * optionally supplied $finalState is entered.
036 *
037 * @param Transaction $trans Transaction being transitioned.
038 *
039 * @throws \Exception if a terminal state throws an exception.
040 */
041 public function __invoke(Transaction $trans)
042 {
043 $trans->_transitionCount = 0;
044
045 if (!$trans->state) {
046 $trans->state = 'before';
047 }
048
049 transition:
050
051 if (++$trans->_transitionCount > $this->maxTransitions) {
052 throw new StateException("Too many state transitions were "
053 . "encountered ({$trans->_transitionCount}). This likely "
054 . "means that a combination of event listeners are in an "
055 . "infinite loop.");
056 }
057
058 switch ($trans->state) {
059 case 'before': goto before;
060 case 'complete': goto complete;
061 case 'error': goto error;
062 case 'retry': goto retry;
063 case 'send': goto send;
064 case 'end': goto end;
065 default: throw new StateException("Invalid state: {$trans->state}");
066 }
067
068 before: {
069 try {
070 $trans->request->getEmitter()->emit('before', new BeforeEvent($trans));
071 $trans->state = 'send';
072 if ((bool) $trans->response) {
073 $trans->state = 'complete';
074 }
075 } catch (\Exception $e) {
076 $trans->state = 'error';
077 $trans->exception = $e;
078 }
079 goto transition;
080 }
081
082 complete: {
083 try {
084 if ($trans->response instanceof FutureInterface) {
085 // Futures will have their own end events emitted when
086 // dereferenced.
087 return;
088 }
089 $trans->state = 'end';
090 $trans->response->setEffectiveUrl($trans->request->getUrl());
091 $trans->request->getEmitter()->emit('complete', new CompleteEvent($trans));
092 } catch (\Exception $e) {
093 $trans->state = 'error';
094 $trans->exception = $e;
095 }
096 goto transition;
097 }
098
099 error: {
100 try {
101 // Convert non-request exception to a wrapped exception
102 $trans->exception = RequestException::wrapException(
103 $trans->request, $trans->exception
104 );
105 $trans->state = 'end';
106 $trans->request->getEmitter()->emit('error', new ErrorEvent($trans));
107 // An intercepted request (not retried) transitions to complete
108 if (!$trans->exception && $trans->state !== 'retry') {
109 $trans->state = 'complete';
110 }
111 } catch (\Exception $e) {
112 $trans->state = 'end';
113 $trans->exception = $e;
114 }
115 goto transition;
116 }
117
118 retry: {
119 $trans->retries++;
120 $trans->response = null;
121 $trans->exception = null;
122 $trans->state = 'before';
123 goto transition;
124 }
125
126 send: {
127 $fn = $this->handler;
128 $trans->response = FutureResponse::proxy(
129 $fn(RingBridge::prepareRingRequest($trans)),
130 function ($value) use ($trans) {
131 RingBridge::completeRingResponse($trans, $value, $this->mf, $this);
132 $this($trans);
133 return $trans->response;
134 }
135 );
136 return;
137 }
138
139 end: {
140 $trans->request->getEmitter()->emit('end', new EndEvent($trans));
141 // Throw exceptions in the terminal event if the exception
142 // was not handled by an "end" event listener.
143 if ($trans->exception) {
144 if (!($trans->exception instanceof RequestException)) {
145 $trans->exception = RequestException::wrapException(
146 $trans->request, $trans->exception
147 );
148 }
149 throw $trans->exception;
150 }
151 }
152 }
153 }
154