MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.123.2.lve.el8.x86_64 #1 SMP Thu May 7 23:17:13 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/snap.cafsinfotech.in/vendor/itsgoingd/clockwork/Clockwork/Request/ShouldRecord.php
<?php namespace Clockwork\Request;

// Filter requests before recording
class ShouldRecord
{
	// Enable collecting of errors only (requests with 4xx or 5xx responses)
	protected $errorsOnly = false;
	// Enable collecting of slow requests only, slow response time threshold in ms
	protected $slowOnly = false;

	// Custom filter callback
	protected $callback;

	// Merge multiple settings from array
	public function merge(array $data = [])
	{
		foreach ($data as $key => $val) $this->$key = $val;
	}

	// Apply the filter to a request
	public function filter(Request $request)
	{
		return $this->passErrorsOnly($request)
			&& $this->passSlowOnly($request)
			&& $this->passCallback($request);
	}

	protected function passErrorsOnly(Request $request)
	{
		if (! $this->errorsOnly) return true;

		return 400 <= $request->responseStatus && $request->responseStatus <= 599;
	}

	protected function passSlowOnly(Request $request)
	{
		if (! $this->slowOnly) return true;

		return $request->getResponseDuration() >= $this->slowOnly;
	}

	protected function passCallback(Request $request)
	{
		if (! $this->callback) return true;

		return call_user_func($this->callback, $request);
	}

	// Fluent API
	public function __call($method, $parameters)
	{
		if (! count($parameters)) return $this->$method;

		$this->$method = count($parameters) ? $parameters[0] : true;

		return $this;
	}
}