<commit_before><?php
	declare(strict_types=1);

	namespace Edde\Ext\Rest;

	use Edde\Api\Container\LazyContainerTrait;
	use Edde\Api\Http\LazyHostUrlTrait;
	use Edde\Api\Protocol\IElement;
	use Edde\Api\Protocol\LazyProtocolServiceTrait;
	use Edde\Api\Url\IUrl;
	use Edde\Common\Protocol\Error;
	use Edde\Common\Protocol\Packet;
	use Edde\Common\Rest\AbstractService;
	use Edde\Common\Strings\StringUtils;
	use Edde\Ext\Protocol\ElementResponse;

	class ProtocolService extends AbstractService {
		use LazyProtocolServiceTrait;
		use LazyContainerTrait;
		use LazyHostUrlTrait;
		protected $action;
		protected $id;

		/**
		 * @inheritdoc
		 */
		public function match(IUrl $url): bool {
			if (($match = $url->match('~^/api/v1/protocol(/(?<action>.+?)(/(?<id>.+?))?)?$~')) === null) {
				return false;
			}
			$this->action = $match['action'] ?? null;
			$this->id = $match['id'] ?? null;
			return true;
		}

		/**
		 * @inheritdoc
		 */
		public function link($generate, ...$parameterList) {
			return parent::link('/api/v1/protocol', ...$parameterList);
		}

		protected function packetPacket(IElement $element = null) {
			return new ElementResponse($this->protocolService->execute($element));
		}

		protected function packet(string $action, array $allowed, bool $packet = false, string $id = null) {
			if (in_array($action, $allowed) === false) {
				$packet = new Packet($this->hostUrl->getAbsoluteUrl());
				$packet->addElement('elements', $error = new Error(0, sprintf('The action [%s] is not supported in the given context; try [%s] or another HTTP method.', $action, implode(', ', $allowed))));
				return new ElementResponse($packet);
			}
			if (method_exists($this, $method = sprintf('packet%s', StringUtils::firstUpper($action)))) {
				return $this->$method($packet = $packet ? $this->request->getContent([IElement::class]) : null);
			}
			$packet = new Packet($this->hostUrl->getAbsoluteUrl());
			$packet->addElement('elements', $error = new Error(0, sprintf('Calling unknown action [%s]; allowed are [%s].', $action, implode(', ', $allowed))));
			return new ElementResponse($packet);
		}

		public function restGet() {
			return $this->packet($this->action, [], false, $this->id);
		}

		public function restPost() {
			return $this->packet($this->action, [
				'packet',
			], true, $this->id);
		}
	}
<commit_msg>- making things more clear.... just kidding<commit_after><?php
	declare(strict_types=1);

	namespace Edde\Ext\Rest;

	use Edde\Api\Container\LazyContainerTrait;
	use Edde\Api\Http\LazyHostUrlTrait;
	use Edde\Api\Protocol\IElement;
	use Edde\Api\Protocol\LazyProtocolServiceTrait;
	use Edde\Api\Url\IUrl;
	use Edde\Common\Protocol\Error;
	use Edde\Common\Protocol\Packet;
	use Edde\Common\Rest\AbstractService;
	use Edde\Common\Strings\StringUtils;
	use Edde\Ext\Protocol\ElementResponse;

	class ProtocolService extends AbstractService {
		use LazyProtocolServiceTrait;
		use LazyContainerTrait;
		use LazyHostUrlTrait;
		protected $action;
		protected $id;

		/**
		 * @inheritdoc
		 */
		public function match(IUrl $url): bool {
			if (($match = $url->match('~^/api/v1/protocol(/(?<action>.+?)(/(?<id>.+?))?)?$~')) === null) {
				return false;
			}
			$this->action = $match['action'] ?? null;
			$this->id = $match['id'] ?? null;
			return true;
		}

		/**
		 * @inheritdoc
		 */
		public function link($generate, ...$parameterList) {
			return parent::link('/api/v1/protocol', ...$parameterList);
		}

		protected function packetPacket(IElement $element = null) {
			return new ElementResponse($this->protocolService->execute($element));
		}

		protected function packet(string $action, array $allowed, bool $packet = false, string $id = null) {
			if (in_array($action, $allowed) === false) {
				return new ElementResponse((new Packet($this->hostUrl->getAbsoluteUrl()))->element(new Error(0, sprintf('The action [%s] is not supported in the given context; try [%s] or another HTTP method.', $action, implode(', ', $allowed)))));
			}
			if (method_exists($this, $method = sprintf('packet%s', StringUtils::firstUpper($action)))) {
				return $this->$method($packet = $packet ? $this->request->getContent([IElement::class]) : null);
			}
			return new ElementResponse((new Packet($this->hostUrl->getAbsoluteUrl()))->element(new Error(0, sprintf('Calling unknown action [%s]; allowed are [%s].', $action, implode(', ', $allowed)))));
		}

		public function restGet() {
			return $this->packet($this->action, [], false, $this->id);
		}

		public function restPost() {
			return $this->packet($this->action, [
				'packet',
			], true, $this->id);
		}
	}

{'fraction_non_alphanumeric': 0.1781209221400609, 'fraction_numerical': 0.002174858634188778, 'mean_word_length': 4.385245901639344, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '233912', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1484, 'n_words': 324}