<commit_before><?php

abstract class CM_Http_Response_View_Abstract extends CM_Http_Response_Abstract {

    /**
     * @param array|null $additionalParams
     */
    public function reloadComponent(array $additionalParams = null) {
        $componentInfo = $this->_getViewInfo('CM_Component_Abstract');
        $componentId = $componentInfo['id'];
        $componentClassName = $componentInfo['className'];
        $componentParams = CM_Params::factory($componentInfo['params']);

        if ($additionalParams) {
            foreach ($additionalParams as $key => $value) {
                $componentParams->set($key, $value);
            }
        }
        $component = CM_Component_Abstract::factory($componentClassName, $componentParams);
        $renderAdapter = CM_RenderAdapter_Component::factory($this->getRender(), $component);
        $html = $renderAdapter->fetch();

        $frontend = $this->getRender()->getGlobalResponse();
        $autoId = $frontend->getTreeRoot()->getValue()->getAutoId();

        $componentReferenceOld = 'cm.views["' . $componentId . '"]';
        $componentReferenceNew = 'cm.views["' . $autoId . '"]';
        $frontend->getOnloadHeaderJs()->append('cm.window.appendHidden(' . json_encode($html) . ');');
        $frontend->getOnloadPrepareJs()->append($componentReferenceOld . '.getParent().registerChild(' . $componentReferenceNew . ');');
        $frontend->getOnloadPrepareJs()->append($componentReferenceOld . '.replaceWithHtml(' . $componentReferenceNew . '.$el);');
        $frontend->getOnloadReadyJs()->append('cm.views["' . $autoId . '"]._ready();');
    }

    /**
     * @param CM_Params $params
     * @return array
     */
    public function loadComponent(CM_Params $params) {
        $component = CM_Component_Abstract::factory($params->getString('className'), $params);
        $renderAdapter = new CM_RenderAdapter_Component($this->getRender(), $component);
        $html = $renderAdapter->fetch();

        $frontend = $this->getRender()->getGlobalResponse();
        $data = array(
            'autoId' => $frontend->getTreeRoot()->getValue()->getAutoId(),
            'html'   => $html,
            'js'     => $frontend->getJs()
        );
        $frontend->clear();
        return $data;
    }

    /**
     * @param CM_Params             $params
     * @param CM_Http_Response_View_Ajax $response
     * @throws CM_Exception_Invalid
     * @return array
     */
    public function loadPage(CM_Params $params, CM_Http_Response_View_Ajax $response) {
        $request = new CM_Http_Request_Get($params->getString('path'), $this->getRequest()->getHeaders(), $this->getRequest()->getServer(), $this->getRequest()->getViewer());

        $count = 0;
        $paths = array($request->getPath());
        do {
            $url = $this->getRender()->getUrl(CM_Util::link($request->getPath(), $request->getQuery()));
            if ($count++ > 10) {
                throw new CM_Exception_Invalid('Page redirect loop detected (' . implode(' -> ', $paths) . ').');
            }
            $responsePage = new CM_Http_Response_Page_Embed($request);
            $responsePage->process();
            $paths[] = $request->getPath();

            if ($redirectUrl = $responsePage->getRedirectUrl()) {
                $redirectExternal = (0 !== mb_stripos($redirectUrl, $this->getRender()->getUrl()));
                if ($redirectExternal) {
                    return array('redirectExternal' => $redirectUrl);
                }
            }
        } while ($redirectUrl);

        foreach ($responsePage->getCookies() as $name => $cookieParameters) {
            $response->setCookie($name, $cookieParameters['value'], $cookieParameters['expire'], $cookieParameters['path']);
        }
        $page = $responsePage->getPage();

        $this->_setStringRepresentation(get_class($page));

        $frontend = $responsePage->getRender()->getGlobalResponse();
        $html = $responsePage->getContent();
        $js = implode(PHP_EOL, array_filter([$frontend->getJs(), $response->getRender()->getServiceManager()->getTrackings()->getJs()]));
        $autoId = $frontend->getTreeRoot()->getValue()->getAutoId();

        $frontend->clear();

        $title = $responsePage->getTitle();
        $layoutClass = get_class($page->getLayout($this->getRender()->getEnvironment()));
        $menuList = array_merge($this->getSite()->getMenus(), $responsePage->getRender()->getMenuList());
        $menuEntryHashList = $this->_getMenuEntryHashList($menuList, get_class($page), $responsePage->getPageParams());

        return array('autoId'            => $autoId, 'html' => $html, 'js' => $js, 'title' => $title, 'url' => $url,
                     'layoutClass'       => $layoutClass,
                     'menuEntryHashList' => $menuEntryHashList);
    }

    public function popinComponent() {
        $componentInfo = $this->_getViewInfo('CM_Component_Abstract');
        $this->getRender()->getGlobalResponse()->getOnloadJs()->append('cm.views["' . $componentInfo['id'] . '"].popIn();');
    }

    /**<commit_msg>Formatting<commit_after><?php

abstract class CM_Http_Response_View_Abstract extends CM_Http_Response_Abstract {

    /**
     * @param array|null $additionalParams
     */
    public function reloadComponent(array $additionalParams = null) {
        $componentInfo = $this->_getViewInfo('CM_Component_Abstract');
        $componentId = $componentInfo['id'];
        $componentClassName = $componentInfo['className'];
        $componentParams = CM_Params::factory($componentInfo['params']);

        if ($additionalParams) {
            foreach ($additionalParams as $key => $value) {
                $componentParams->set($key, $value);
            }
        }
        $component = CM_Component_Abstract::factory($componentClassName, $componentParams);
        $renderAdapter = CM_RenderAdapter_Component::factory($this->getRender(), $component);
        $html = $renderAdapter->fetch();

        $frontend = $this->getRender()->getGlobalResponse();
        $autoId = $frontend->getTreeRoot()->getValue()->getAutoId();

        $componentReferenceOld = 'cm.views["' . $componentId . '"]';
        $componentReferenceNew = 'cm.views["' . $autoId . '"]';
        $frontend->getOnloadHeaderJs()->append('cm.window.appendHidden(' . json_encode($html) . ');');
        $frontend->getOnloadPrepareJs()->append($componentReferenceOld . '.getParent().registerChild(' . $componentReferenceNew . ');');
        $frontend->getOnloadPrepareJs()->append($componentReferenceOld . '.replaceWithHtml(' . $componentReferenceNew . '.$el);');
        $frontend->getOnloadReadyJs()->append('cm.views["' . $autoId . '"]._ready();');
    }

    /**
     * @param CM_Params $params
     * @return array
     */
    public function loadComponent(CM_Params $params) {
        $component = CM_Component_Abstract::factory($params->getString('className'), $params);
        $renderAdapter = new CM_RenderAdapter_Component($this->getRender(), $component);
        $html = $renderAdapter->fetch();

        $frontend = $this->getRender()->getGlobalResponse();
        $data = array(
            'autoId' => $frontend->getTreeRoot()->getValue()->getAutoId(),
            'html'   => $html,
            'js'     => $frontend->getJs(),
        );
        $frontend->clear();
        return $data;
    }

    /**
     * @param CM_Params                  $params
     * @param CM_Http_Response_View_Ajax $response
     * @throws CM_Exception_Invalid
     * @return array
     */
    public function loadPage(CM_Params $params, CM_Http_Response_View_Ajax $response) {
        $request = new CM_Http_Request_Get($params->getString('path'), $this->getRequest()->getHeaders(), $this->getRequest()->getServer(), $this->getRequest()->getViewer());

        $count = 0;
        $paths = array($request->getPath());
        do {
            $url = $this->getRender()->getUrl(CM_Util::link($request->getPath(), $request->getQuery()));
            if ($count++ > 10) {
                throw new CM_Exception_Invalid('Page redirect loop detected (' . implode(' -> ', $paths) . ').');
            }
            $responsePage = new CM_Http_Response_Page_Embed($request);
            $responsePage->process();
            $paths[] = $request->getPath();

            if ($redirectUrl = $responsePage->getRedirectUrl()) {
                $redirectExternal = (0 !== mb_stripos($redirectUrl, $this->getRender()->getUrl()));
                if ($redirectExternal) {
                    return array('redirectExternal' => $redirectUrl);
                }
            }
        } while ($redirectUrl);

        foreach ($responsePage->getCookies() as $name => $cookieParameters) {
            $response->setCookie($name, $cookieParameters['value'], $cookieParameters['expire'], $cookieParameters['path']);
        }
        $page = $responsePage->getPage();

        $this->_setStringRepresentation(get_class($page));

        $frontend = $responsePage->getRender()->getGlobalResponse();
        $html = $responsePage->getContent();
        $js = implode(PHP_EOL, array_filter([$frontend->getJs(), $response->getRender()->getServiceManager()->getTrackings()->getJs()]));
        $autoId = $frontend->getTreeRoot()->getValue()->getAutoId();

        $frontend->clear();

        $title = $responsePage->getTitle();
        $layoutClass = get_class($page->getLayout($this->getRender()->getEnvironment()));
        $menuList = array_merge($this->getSite()->getMenus(), $responsePage->getRender()->getMenuList());
        $menuEntryHashList = $this->_getMenuEntryHashList($menuList, get_class($page), $responsePage->getPageParams());

        return array(
            'autoId'            => $autoId,
            'html'              => $html,
            'js'                => $js,
            'title'             => $title,
            'url'               => $url,
            'layoutClass'       => $layoutClass,
            'menuEntryHashList' => $menuEntryHashList,
        );
    }

    public function popinComponent() {
        $componentInfo = $this->_getViewInfo('CM_Component_Abstract');
        $this->getRender()->getGlobalResponse()->getOnloadJs()->append('cm.views["' . $componentInfo['id'] . '"].popIn();');
    }

    /**
{'fraction_non_alphanumeric': 0.1730731707317073, 'fraction_numerical': 0.0007804878048780488, 'mean_word_length': 2.8770801815431164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 183, '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': '7047612', 'n_tokens_mistral': 2824, 'n_tokens_neox': 2757, 'n_words': 421}