<commit_before><?php namespace Peakfijn\GetSomeRest\Routing;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Peakfijn\GetSomeRest\Http\Response;
use Peakfijn\GetSomeRest\Exceptions\UnsupportedEncoderException;
use Peakfijn\GetSomeRest\Exceptions\NotFoundResourceException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

class Router extends \Illuminate\Routing\Router {

	/**
	 * Holds the available mutators.
	 * 
	 * @var array
	 */
	public $mutators = [];

	/**
	 * Holds the available encoders.
	 * 
	 * @var array
	 */
	public $encoders = [];

	/**
	 * Holds the aliases for response formats.
	 * 
	 * @var array
	 */
	public $extensionAliases = [];

	/**
	 * Fail when an extension was supplied with an unsupported format.
	 *
	 * @var boolean
	 */
	public $failUnsupportedEncoder = true;

	/**
	 * The default actions for an api resourceful controller.
	 * 
	 * @var array
	 */
	protected $resourceApiDefaults = ['index', 'store', 'show', 'update', 'destroy'];

	/**
	 * These are some of the basic status code, related to the http method used.
	 * 
	 * @var array
	 */
	public static $verbs_status_codes = [
		'POST'   => 201, /* Always used for creating */
		'PUT'    => 204, /* Update something */
		'PATCH'  => 204, /* Same as PUT */
		'DELETE' => 204, /* Delete something */
	];

	/**
	 * Create a group of API routes.
	 * The routes will be prefixed with the given version.
	 * Please do not use an API group within another API group.
	 * 
	 * @param  mixed   $settings  Should match pattern /v[0-9]+/
	 * @param  Closure $callback
	 * @return coid
	 */
	public function api( $settings, Closure $callback )
	{
		if( !is_array($settings) )
		{
			$settings = ['version' => $settings, 'prefix' => $settings];
		}
		else if( array_key_exists('prefix', $settings) )
		{
			$settings['prefix'] = $settings['version'] .'/'. $settings['prefix'];
		}

		$settings['api'] = true;

		return $this->group($settings, $callback);
	}

	/**
	 * Try and execute the requested route.
	 * If the requested route is an API route,
	 * catch all HttpExceptions and make it a nice response.
	 *
	 * @param  Request $request
	 * @return \Illuminate\Http\Response
	 */<commit_msg>Fixed a little bug using the Route::api function.<commit_after><?php namespace Peakfijn\GetSomeRest\Routing;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response as IlluminateResponse;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Peakfijn\GetSomeRest\Http\Response;
use Peakfijn\GetSomeRest\Exceptions\UnsupportedEncoderException;
use Peakfijn\GetSomeRest\Exceptions\NotFoundResourceException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

class Router extends \Illuminate\Routing\Router {

	/**
	 * Holds the available mutators.
	 * 
	 * @var array
	 */
	public $mutators = [];

	/**
	 * Holds the available encoders.
	 * 
	 * @var array
	 */
	public $encoders = [];

	/**
	 * Holds the aliases for response formats.
	 * 
	 * @var array
	 */
	public $extensionAliases = [];

	/**
	 * Fail when an extension was supplied with an unsupported format.
	 *
	 * @var boolean
	 */
	public $failUnsupportedEncoder = true;

	/**
	 * The default actions for an api resourceful controller.
	 * 
	 * @var array
	 */
	protected $resourceApiDefaults = ['index', 'store', 'show', 'update', 'destroy'];

	/**
	 * These are some of the basic status code, related to the http method used.
	 * 
	 * @var array
	 */
	public static $verbs_status_codes = [
		'POST'   => 201, /* Always used for creating */
		'PUT'    => 204, /* Update something */
		'PATCH'  => 204, /* Same as PUT */
		'DELETE' => 204, /* Delete something */
	];

	/**
	 * Create a group of API routes.
	 * The routes will be prefixed with the given version.
	 * Please do not use an API group within another API group.
	 * 
	 * @param  array|string $settings  Should match pattern /v[0-9]+/
	 * @param  Closure      $callback
	 * @return coid
	 */
	public function api( $settings, Closure $callback )
	{
		if( !is_array($settings) )
		{
			$settings = ['version' => $settings, 'prefix' => $settings];
		}

		if( isset($settings['prefix']) && !empty($settings['prefix']) )
		{
			$settings['prefix'] = $settings['prefix'] .'/'. $settings['version'];
		}
		else
		{
			$settings['prefix'] = $settings['version'];
		}

		$settings['api'] = true;

		return $this->group($settings, $callback);
	}

	/**
	 * Try and execute the requested route.
	 * If the requested route is an API route,
	 * catch all HttpExceptions and make it a nice response.
	 *
	 * @param  Request $request
	 * @return \Illuminate\Http\Response
	 */
{'fraction_non_alphanumeric': 0.13142054574638845, 'fraction_numerical': 0.0056179775280898875, 'mean_word_length': 3.5318181818181817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4032013', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1490, 'n_words': 445}