<commit_before><?php

namespace Api;

use Pagon\Route\Rest;
use Pagon\View;

class Api extends Rest
{
    /**
     * The API data
     *
     * @var array
     */
    protected $data = array();

    /**
     * The API format
     *
     * @var string
     */
    protected $_format = 'json';

    /**
     * Show error error message
     *
     * @param string $message
     * @param int    $error_code
     * @param int    $code
     */
    protected function error($message, $error_code = 400, $code = 400)
    {
        $this->dump(array('message' => $message, 'code' => $error_code), $code);
    }

    /**
     * Show ok message
     */
    protected function ok($message)
    {
        $this->dump(array('message' => $message, 'code' => '0'));
    }

    /**
     * Dump API data
     *
     * @param array        $data
     * @param int          $code
     * @param array|string $other_option
     */
    protected function dump(array $data, $code = 200, $other_option = null)
    {
        $this->output->status($code);

        switch ($this->_format) {
            case 'xml':
                $this->output->xml($data, (array)$other_option);
                break;
            case 'jsonp':
                $this->output->jsonp($data, (string)$other_option);
                break;
            default:
                $this->output->json($data);

        }
        $this->output->end();
    }

    /**
     * Before
     */
    protected function before()
    {
        $this->loadOrm();
    }

    /**
     * After
     */
    protected function after()
    {
        $this->dump($this->data);
    }

    /**
     * Load ORM and database
     */
    protected function loadOrm()
    {
        $this->app->loadOrm();
    }
}<commit_msg>Fix api dump xml option and jsonp callback<commit_after><?php

namespace Api;

use Pagon\Route\Rest;
use Pagon\View;

class Api extends Rest
{
    /**
     * The API data
     *
     * @var array
     */
    protected $data = array();

    /**
     * The API format
     *
     * @var string
     */
    protected $_format = 'json';

    /**
     * Xml option for dump
     *
     * @var array
     */
    protected $_xml_option = array();

    /**
     * Json callback function
     *
     * @var string
     */
    protected $_jsonp_callback = 'callback';

    /**
     * Show error error message
     *
     * @param string $message
     * @param int    $error_code
     * @param int    $code
     */
    protected function error($message, $error_code = 400, $code = 400)
    {
        $this->dump(array('message' => $message, 'code' => $error_code), $code);
    }

    /**
     * Show ok message
     */
    protected function ok($message)
    {
        $this->dump(array('message' => $message, 'code' => '0'));
    }

    /**
     * Dump API data
     *
     * @param array $data
     * @param int   $code
     */
    protected function dump(array $data, $code = 200)
    {
        $this->output->status($code);

        switch ($this->_format) {
            case 'xml':
                $this->output->xml($data, $this->_xml_option);
                break;
            case 'jsonp':
                $this->output->jsonp($data, $this->_jsonp_callback);
                break;
            default:
                $this->output->json($data);

        }
        $this->output->end();
    }

    /**
     * Before
     */
    protected function before()
    {
        $this->loadOrm();
    }

    /**
     * After
     */
    protected function after()
    {
        $this->dump($this->data);
    }

    /**
     * Load ORM and database
     */
    protected function loadOrm()
    {
        $this->app->loadOrm();
    }
}
{'fraction_non_alphanumeric': 0.15231607629427793, 'fraction_numerical': 0.005449591280653951, 'mean_word_length': 1.5299793246037217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '5588038', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1113, 'n_words': 251}