setDefaults([ 'max_failure' => 5, 'reset_timeout' => 5, 'exclude_exceptions' => [], 'ignore_exceptions' => false, 'allowed_exceptions' => [], ]); $resolver->setAllowedTypes('exclude_exceptions', 'array'); $resolver->setAllowedTypes('max_failure', 'int'); $resolver->setAllowedTypes('reset_timeout', 'int'); $resolver->setAllowedTypes('allowed_exceptions', 'array'); $this->config = $resolver->resolve($config); $this->store = $store ?: new ArrayCache(); $this->handler = $handler ?: new Handler($this->config); $this->dispatcher = $dispatcher ?: new EventDispatcher(); $name = Utils::snakeCase($name); $this->circuit = $this->loadCircuit($name); } /** * protect. * * @param \Closure $closure * @throws \Exception * * @return mixed */ public function protect(\Closure $closure) { try { $result = null; $circuitOpenException = null; if ($this->isClosed($this->circuit) || $this->isHalfOpen($this->circuit)) { $result = $closure(); $this->success($this->circuit); } elseif ($this->isOpen($this->circuit)) { $circuitOpenException = new CircuitOpenException(); } } catch (\Exception $e) { if (!in_array(get_class($e), $this->config['allowed_exceptions'])) { $this->failure($this->circuit); } if (!$this->config['ignore_exceptions']) { if (!in_array(get_class($e), $this->config['exclude_exceptions'])) { $result = $e; } } } // Throw circuit exception when it is opened if (null !== $circuitOpenException) { throw $circuitOpenException; } //Throw closure exception if ($result instanceof \Exception) { throw $result; } return $result; } /** * addListener. * * @param string $eventName * @param \Closure|array $listener */ public function addListener($eventName, $listener) { $this->dispatcher->addListener($eventName, $listener); } /** * isClosed. * * @param Circuit $circuit * * @return bool */ protected function isClosed(Circuit $circuit) { if ($this->handler->isClosed($circuit)) { $this->dispatcher->dispatch(new CircuitEvent($circuit)); return true; } return false; } /** * isOpen. * * @param Circuit $circuit * * @return bool */ protected function isOpen(Circuit $circuit) { $open = false; if ($this->handler->isOpen($circuit)) { $this->dispatcher->dispatch(new CircuitEvent($circuit)); $open = true; } return $open; } /** * isHalfOpen. * * @param Circuit $circuit * * @return bool */ protected function isHalfOpen(Circuit $circuit) { if ($this->handler->isHalfOpen($circuit)) { $this->dispatcher->dispatch(new CircuitEvent($circuit)); return true; } return false; } /** * success. * * @param Circuit $circuit */ protected function success(Circuit $circuit) { $circuit->resetFailure(); $this->dispatcher->dispatch(new CircuitEvent($circuit)); $this->writeToStore($circuit); } /** * failure. * * @param Circuit $circuit */ protected function failure(Circuit $circuit) { $circuit->incrementFailure(); $circuit->setLastFailure(time()); $this->dispatcher->dispatch(new CircuitEvent($circuit)); $this->writeToStore($circuit); } /** * loadCircuit. * * @param string $name * * @return Circuit */ protected function loadCircuit($name) { $circuit = $this->store->fetch($name) ?: new Circuit($name); $this->writeToStore($circuit); return $circuit; } /** * @param Circuit $circuit */ protected function writeToStore(Circuit $circuit) { $this->store->save($circuit->getName(), $circuit); } } __halt_compiler();----SIGNATURE:----WSa+uUXjQCDnYGDIAUAogrJ5wQRRt1KE/1oSF9gxpxGXWc5a1dTjrxHvx++SuGAt/w5BNjss2x43hjO3wCPVwReDcaiaSsYSSv05UyftHOcgkKmDNZMvPfk/BGb4mfyPEVUs6id1DPP6jMTE+4uaelB0HiCDi9wJGeQQmtdgzkyxfbkJweOIa7lUCJkMF8Ukw9ALNRh7Yi6M7/VONM/9IIHyWmG32G7RPS/9+7faPIwQpztgVcg9DUd2I1lbhf4BpJ87h6cd4KuCmFdsmL9i14DLv+c6/5TtIQJqh7Rnk/thS/gNMTSKQlHDhX/hyxu200vS9P+FX96+iRkOfaPIIIDmXH/dGeuRhSqEOL4LP6bq8RehXpFysR1pLX0e13PdPN+hmBfH8pe5MZweHhafh/ek6CE+kA2pOY4RxSOsiQs0+4LakCU9WBhbT67sv/ie10ClY3IBU15ePFEavyRr9Fk3DKuqXC9/ONaCll2T7+ga3kDOqtyGSBnaCxP+CrhZrJcb5tzDxzSXIlx+lcY0qZCYwxl9K3pQhxGTsI6+A0qxR0I6uAtfhgJvGDKWi+uTMqg9mm1ErgRMik7W0se/8aDR+VAZfvpCiVmXsqTCGy+BRH7hM0grFLo4zoodOeVYhnh0gk83udHM3GdFGbioO7ten+58PgvbqTV19VGsydo=----ATTACHMENT:----NTMzMzEwODYxNzY5ODkzMSAyMDA4MjU2MjY0MTYwODE2IDU2NjA5MTYwOTQ0OTA2