<commit_before><?php
namespace watoki\qrator\web;

use watoki\collections\Map;
use watoki\curir\cookie\Cookie;
use watoki\curir\cookie\CookieStore;
use watoki\curir\protocol\Url;
use watoki\curir\Responder;
use watoki\curir\responder\Redirecter;
use watoki\dom\Element;
use watoki\factory\exception\InjectionException;
use watoki\factory\Factory;
use watoki\qrator\representer\ActionLink;
use watoki\qrator\representer\Property;
use watoki\qrator\RepresenterRegistry;
use watoki\tempan\model\ListModel;

class ExecuteResource extends ActionResource {

    const LAST_ACTION_COOKIE = 'lastAction';
    const BREADCRUMB_COOKIE = 'breadcrumbs';

    /** @var \watoki\curir\cookie\CookieStore */
    private $cookies;

    /**
     * @param Factory $factory <-
     * @param RepresenterRegistry $registry <-
     * @param \watoki\curir\cookie\CookieStore $cookies <-
     */
    function __construct(Factory $factory, RepresenterRegistry $registry, CookieStore $cookies) {
        parent::__construct($factory, $registry);
        $this->cookies = $cookies;
    }

    /**
     * @param string $action
     * @param \watoki\collections\Map|null $args
     * @param bool $prepared
     * @return array
     */
    public function doGet($action, Map $args = null, $prepared = false) {
        $args = $args ?: new Map();

        $crumbs = $this->readBreadcrumbs();

        $representer = $this->registry->getActionRepresenter($action);

        try {
            $object = $representer->create($args);
        } catch (InjectionException $e) {
            return $this->redirectToPrepare($action, $args);
        }

        if (!$prepared && $representer->hasMissingProperties($object)) {
            return $this->redirectToPrepare($action, $args);
        }

        $result = $representer->execute($object);

        $followUpAction = $representer->getFollowUpAction($result);
        if ($followUpAction) {
            return new Redirecter($this->urlOfAction($followUpAction));
        } else if (is_null($result) && $this->cookies->hasKey(ExecuteResource::LAST_ACTION_COOKIE)) {
            return new Redirecter($this->urlOfLastAction());
        } else {
            $this->storeLastAction($action, $args);
            $crumbs = $this->updateBreadcrumb($crumbs, $object, $args);

            $entityModel = $this->assembleResult($result);
            if ($entityModel) {
                $noShow = count($entityModel) > 1 ? 'list' : 'table';<commit_msg>Throw HttpError is action execution fails<commit_after><?php
namespace watoki\qrator\web;

use watoki\collections\Map;
use watoki\curir\cookie\Cookie;
use watoki\curir\cookie\CookieStore;
use watoki\curir\delivery\WebResponse;
use watoki\curir\error\HttpError;
use watoki\curir\protocol\Url;
use watoki\curir\Responder;
use watoki\curir\responder\Redirecter;
use watoki\dom\Element;
use watoki\factory\exception\InjectionException;
use watoki\factory\Factory;
use watoki\qrator\representer\ActionLink;
use watoki\qrator\representer\Property;
use watoki\qrator\RepresenterRegistry;
use watoki\tempan\model\ListModel;

class ExecuteResource extends ActionResource {

    const LAST_ACTION_COOKIE = 'lastAction';
    const BREADCRUMB_COOKIE = 'breadcrumbs';

    /** @var \watoki\curir\cookie\CookieStore */
    private $cookies;

    /**
     * @param Factory $factory <-
     * @param RepresenterRegistry $registry <-
     * @param \watoki\curir\cookie\CookieStore $cookies <-
     */
    function __construct(Factory $factory, RepresenterRegistry $registry, CookieStore $cookies) {
        parent::__construct($factory, $registry);
        $this->cookies = $cookies;
    }

    /**
     * @param string $action
     * @param \watoki\collections\Map|null $args
     * @param bool $prepared
     * @throws HttpError If error occurs during execution of the action
     * @return array
     */
    public function doGet($action, Map $args = null, $prepared = false) {
        $args = $args ?: new Map();

        $crumbs = $this->readBreadcrumbs();

        $representer = $this->registry->getActionRepresenter($action);

        try {
            $object = $representer->create($args);
        } catch (InjectionException $e) {
            return $this->redirectToPrepare($action, $args);
        }

        if (!$prepared && $representer->hasMissingProperties($object)) {
            return $this->redirectToPrepare($action, $args);
        }

        try {
            $result = $representer->execute($object);
        } catch (\Exception $e) {
            throw new HttpError(WebResponse::STATUS_SERVER_ERROR, $e->getMessage(), null, 0, $e);
        }

        $followUpAction = $representer->getFollowUpAction($result);
        if ($followUpAction) {
            return new Redirecter($this->urlOfAction($followUpAction));
        } else if (is_null($result) && $this->cookies->hasKey(ExecuteResource::LAST_ACTION_COOKIE)) {
            return new Redirecter($this->urlOfLastAction());
        } else {
            $this->storeLastAction($action, $args);
            $crumbs = $this->updateBreadcrumb($crumbs, $object, $args);

            $entityModel = $this->assembleResult($result);
            if ($entityModel) {
                $noShow = count($entityModel) > 1 ? 'list' : 'table';
{'fraction_non_alphanumeric': 0.1340324118207817, 'fraction_numerical': 0.0005719733079122975, 'mean_word_length': 3.076146076146076, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 40, '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': '4140869', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1564, 'n_words': 303}