<commit_before><?php

namespace Grid\Core\Controller;

use Zend\Mvc\Controller\AbstractActionController;

/**
 * IndexController
 *
 * @author <NAME> <<EMAIL>>
 */
class IndexController extends AbstractActionController
{

    /**
     * Get sub-domain model
     *
     * @return \Core\Model\SubDomain\Model
     */
    protected function getSubDomainModel()
    {
        return $this->getServiceLocator()
                    ->get( 'Grid\Core\Model\SubDomain\Model' );
    }

    /**
     * Get uri model
     *
     * @return \Core\Model\Uri\Model
     */
    protected function getUriModel()
    {
        return $this->getServiceLocator()
                    ->get( 'Grid\Core\Model\Uri\Model' );
    }

    /**
     * Index action
     */
    public function indexAction()
    {
        $actual = $this->getSubDomainModel()
                       ->findActual();

        if ( empty( $actual ) )
        {
            $this->getResponse()
                 ->setStatusCode( 404 );

            return;
        }

        $locales = array();
        $request = $this->getRequest();
        $accept  = $request->getHeader( 'Accept-Language' );

        if ( $accept )
        {
            $locales = $this->locale()
                            ->parseHeader( $accept );
        }

        if ( empty( $locales[$actual->locale] ) )
        {
            $locales[$actual->locale] = 0.01;
        }

        // the browser gives us in the right order usually,
        // but we cannot depend on it
        arsort( $locales, SORT_NUMERIC );

        $uri = $this->getUriModel()
                    ->findDefaultByContentSubdomain(
                           $actual->defaultContentId,
                           $actual->id,
                           $locales
                       );

        if ( empty( $uri ) )
        {
            $uri = $this->url()
                        ->fromRoute( 'Grid\Paragraph\Render\Paragraph', array(
                            'locale'        => (string) $this->locale(),
                            'paragraphId'   => $actual->defaultContentId,
                        ) );
        }
        else
        {
            $uri = '/' . $uri->safeUri;
        }

        $response = $this->getResponse();

        $response->getHeaders()
                 ->addHeaderLine( 'Location', $uri );

        // Temporary redirect
        return $response->setStatusCode( 307 );
    }

    /**
     * Content-uri action
     */
    public function contentUriAction()
    {
        $actual = $this->getSubDomainModel()
                       ->findActual();

        if ( empty( $actual ) )
        {
            $this->getResponse()<commit_msg>IndexController now redirects with 302 (instead of 307)<commit_after><?php

namespace Grid\Core\Controller;

use Zend\Mvc\Controller\AbstractActionController;

/**
 * IndexController
 *
 * @author <NAME> <<EMAIL>>
 */
class IndexController extends AbstractActionController
{

    /**
     * Get sub-domain model
     *
     * @return \Core\Model\SubDomain\Model
     */
    protected function getSubDomainModel()
    {
        return $this->getServiceLocator()
                    ->get( 'Grid\Core\Model\SubDomain\Model' );
    }

    /**
     * Get uri model
     *
     * @return \Core\Model\Uri\Model
     */
    protected function getUriModel()
    {
        return $this->getServiceLocator()
                    ->get( 'Grid\Core\Model\Uri\Model' );
    }

    /**
     * Index action
     */
    public function indexAction()
    {
        $actual = $this->getSubDomainModel()
                       ->findActual();

        if ( empty( $actual ) )
        {
            $this->getResponse()
                 ->setStatusCode( 404 );

            return;
        }

        $locales = array();
        $request = $this->getRequest();
        $accept  = $request->getHeader( 'Accept-Language' );

        if ( $accept )
        {
            $locales = $this->locale()
                            ->parseHeader( $accept );
        }

        if ( empty( $locales[$actual->locale] ) )
        {
            $locales[$actual->locale] = 0.01;
        }

        // the browser gives us in the right order usually,
        // but we cannot depend on it
        arsort( $locales, SORT_NUMERIC );

        $uri = $this->getUriModel()
                    ->findDefaultByContentSubdomain(
                           $actual->defaultContentId,
                           $actual->id,
                           $locales
                       );

        if ( empty( $uri ) )
        {
            $uri = $this->url()
                        ->fromRoute( 'Grid\Paragraph\Render\Paragraph', array(
                            'locale'        => (string) $this->locale(),
                            'paragraphId'   => $actual->defaultContentId,
                        ) );
        }
        else
        {
            $uri = '/' . $uri->safeUri;
        }

        $response = $this->getResponse();

        $response->getHeaders()
                 ->addHeaderLine( 'Location', $uri );

        // Found
        return $response->setStatusCode( 302 );
    }

    /**
     * Content-uri action
     */
    public function contentUriAction()
    {
        $actual = $this->getSubDomainModel()
                       ->findActual();

        if ( empty( $actual ) )
        {
            $this->getResponse()
{'fraction_non_alphanumeric': 0.13102549785966872, 'fraction_numerical': 0.00446677833612507, 'mean_word_length': 1.3094112591319296, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 73, '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': '3223890', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1418, 'n_words': 273}