<commit_before><?php
/**
 * Static view responder
 *
 * @category Responder
 * @package  aaa
 *
 */
namespace Application\Responder;

use Aura\Payload_Interface\PayloadInterface;
use Aura\Payload\Payload;
use Aura\Payload_Interface\PayloadStatus;
use Aura\View\ViewFactory as ViewFactory;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Radar\Adr\Responder\ResponderAcceptsInterface;


/**
 *
 * Aura view Responder.
 *
 * @package radar.zombie
 *
 */
class AuraViewStaticPage implements ResponderAcceptsInterface
{
    /**
     * The domain payload (i.e. the output from the domain).
     * @var PayloadInterface
     */
    protected $payload;

    /**
     * The HTTP request.
     * @var Request
     */
    protected $request;

    /**
     * The HTTP response.
     * @var Response
     */
    protected $response;

    /**
     * Views file path
     * @var array
     * @access protected
     */
    protected $views;

	/**
     * __construct
     * @param array $rules Map of rules
     * @access public
     */
	// todo // get an array with the files
    public function __construct($views) // $viewDir
    {
        $this->views = $views;
        $this->path = $this->views['views']['path'];
    }

    /**
     * Returns the list of media types this Responder can generate.
     * @return array
     */
    public static function accepts()
    {
        return ['text/html'];
    }

    /**
     * Builds and returns the Response using the Request and Payload.
     * @param Request $request The HTTP request object.
     * @param Response $response The HTTP response object.
     * @param PayloadInterface $payload The domain payload object.
     * @return Response
     */
    public function __invoke(
        Request $request,
        Response $response,
        PayloadInterface $payload = null
    ) {
        $this->request = $request;
        $this->response = $response;
        $this->payload = $payload;
        $method = $this->getMethodForPayload();
        $this->$method();
        return $this->response;
    }

    /**
     * Returns the Responder method to call, based on the Payload status.
     * @return string
     */
    protected function getMethodForPayload()
    {
        if (! $this->payload) {
            return 'noContent';
        }

        $method = str_replace('_', '', strtolower($this->payload->getStatus()));
        return method_exists($this, $method) ? $method : 'unknown';
    }

    /**
     * Returns the Responder
     * @return string
     */
    protected function htmlBody($data)
    {

        // Aura.view setup
        $view_factory = new ViewFactory;
        $view = $view_factory->newInstance();

       	// get view registrys
        $layout_registry = $view->getLayoutRegistry();
		$view_registry = $view->getViewRegistry();

		// get slug for partial view
		$slug = $this->request->getAttribute('page');
		$partial = $this->path . '/staticPages/_' . $slug . '.php';

        // main view
        // render main layout file only if the request is NOT a pjax request
		// add templates to the view registry
        if( $this->is_pjax() )
        {
			$view_registry->set('_content', $partial);
        } else {
			$layout_registry->set('layout', $this->path . $this->views['views']['layout']);
        	$view_registry->set('_content', $partial);
        }
		// $layout_registry->set('layout', $this->path . $this->views['views']['layout']);
        // partial view
        // $view_registry->set('_content', $partial);

        // set data
        $dataset = [
            'data' => $data, // passing data array to view
            'partial' => 'partial', // passing partial view filename as string to layout
        ];

        // assign data to view
        $view->setData($dataset);

        // set views
        $view->setView('_content');
        $view->setLayout('layout');
        $output = $view->__invoke();

        // retun response
        $this->response = $this->response->withHeader('Content-Type', 'text/html');
        $this->response->getBody()->write($output);

    }


    /**
     * Checks for ajax request
     * @return bool
     */
    protected function is_pjax()
    {
        $serverparams = $this->request->getServerParams();

        if(isset( $serverparams['HTTP_X_PJAX'] ) && $serverparams['HTTP_X_PJAX'] == 'true')
        {
            echo 'pjax PSR-7 = true';
            echo '<pre>';
            $serverparams = $this->request->getServerParams();
            print_r($serverparams['HTTP_X_PJAX']);
            echo '</pre>';
            return TRUE;
        }
        // echo 'pjax PSR-7 = false';
        // echo '<pre>';
        $serverparams = $this->request->getServerParams();
        // print_r($serverparams['HTTP_X_PJAX']);
        // echo '</pre>';
        return FALSE;
    }

    /**
     * Builds a Response for PayloadStatus::SUCCESS.
     */
    protected function success()
    {<commit_msg>pax is now working<commit_after><?php
/**
 * Static view responder
 *
 * @category Responder
 * @package  Application
 *
 */
namespace Application\Responder;

use Aura\Payload_Interface\PayloadInterface;
use Aura\Payload\Payload;
use Aura\Payload_Interface\PayloadStatus;
use Aura\View\ViewFactory as ViewFactory;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Radar\Adr\Responder\ResponderAcceptsInterface;


/**
 *
 * Aura view Responder.
 *
 * @package radar.zombie
 *
 */
class AuraViewStaticPage implements ResponderAcceptsInterface
{
    /**
     * The domain payload (i.e. the output from the domain).
     * @var PayloadInterface
     */
    protected $payload;

    /**
     * The HTTP request.
     * @var Request
     */
    protected $request;

    /**
     * The HTTP response.
     * @var Response
     */
    protected $response;

    /**
     * Views file path
     * @var array
     * @access protected
     */
    protected $views;

	/**
     * __construct
     * @param array $rules Map of rules
     * @access public
     */
	// todo // get an array with the files
    public function __construct($views) // $viewDir
    {
        $this->views = $views;
        $this->path = $this->views['views']['path'];
    }

    /**
     * Returns the list of media types this Responder can generate.
     * @return array
     */
    public static function accepts()
    {
        return ['text/html'];
    }

    /**
     * Builds and returns the Response using the Request and Payload.
     * @param Request $request The HTTP request object.
     * @param Response $response The HTTP response object.
     * @param PayloadInterface $payload The domain payload object.
     * @return Response
     */
    public function __invoke(
        Request $request,
        Response $response,
        PayloadInterface $payload = null
    ) {
        $this->request = $request;
        $this->response = $response;
        $this->payload = $payload;
        $method = $this->getMethodForPayload();
        $this->$method();
        return $this->response;
    }

    /**
     * Returns the Responder method to call, based on the Payload status.
     * @return string
     */
    protected function getMethodForPayload()
    {
        if (! $this->payload) {
            return 'noContent';
        }

        $method = str_replace('_', '', strtolower($this->payload->getStatus()));
        return method_exists($this, $method) ? $method : 'unknown';
    }

    /**
     * Returns the Responder
     * @return string
     */
    protected function htmlBody($data)
    {
        // Aura.view setup
        $view_factory = new ViewFactory;
        $view = $view_factory->newInstance();

        // layout
        $layout_registry = $view->getLayoutRegistry();
        $layout_registry->set('layout', $this->path . $this->views['views']['layout']);

        // views
        $view_registry = $view->getViewRegistry();

        // get slug for partial view
        $slug = $this->request->getAttribute('page');
        $partial = $this->path . '/staticPages/_' . $slug . '.php';
        $view_registry->set('_content', $partial);

        // set data
        $dataset = [
            'data' => $data, // passing data array to view
            'partial' => 'partial', // passing partial view filename as string to layout
        ];

        // assign data to view
        $view->setData($dataset);

        // check for ajax request and set views accordingly
        if ( $this->is_pjax() )
        {
            // pjax request, set the view only
            $view->setView('_content');
        } else {
            // regular http request, set view and layout
            $view->setLayout('layout');
            $view->setView('_content');
        }

        $output = $view->__invoke();

        // retun response
        $this->response = $this->response->withHeader('Content-Type', 'text/html');
        $this->response->getBody()->write($output);
    }

    /**
     * Checks for ajax request
     * @return bool
     */
    protected function is_pjax()
    {
        $serverparams = $this->request->getServerParams();

        if(isset( $serverparams['HTTP_X_PJAX'] ) && $serverparams['HTTP_X_PJAX'] == 'true')
        {
            $serverparams = $this->request->getServerParams();
            return TRUE;
        }
        $serverparams = $this->request->getServerParams();
        return FALSE;
    }

    /**
     * Builds a Response for PayloadStatus::SUCCESS.
     */
    protected function success()
    {
{'fraction_non_alphanumeric': 0.13606866234038098, 'fraction_numerical': 0.00020933640360058616, 'mean_word_length': 2.1451612903225805, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 95, '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': '814690', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2657, 'n_words': 688}