<commit_before><?php namespace Cartalyst\Support\Traits;
/**
 * Part of the Support package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the Cartalyst PSL License.
 *
 * This source file is subject to the Cartalyst PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @package    Support
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    Cartalyst PSL
 * @copyright  (c) 2011-2014, Cartalyst LLC
 * @link       http://cartalyst.com
 */

use Illuminate\Support\Fluent;
use Illuminate\Support\Facades\Validator;

trait ValidationTrait {

	/**
	 * The registered scenarios
	 *
	 * @var array
	 */
	protected $scenarios = [];

	/**
	 * The registered bindings
	 *
	 * @var array
	 */
	protected $bindings = [];

	/**
	 * Create a scope scenario.
	 *
	 * @param  string  $scenario
	 * @param  array  $arguments
	 * @return ValidationTrait
	 */
	public function onScenario($scenario, array $arguments = [])
	{
		$method = 'on'.ucfirst($scenario);

		$this->scenarios = [
			'on'        => method_exists($this, $method) ? $method : null,
			'arguments' => $arguments,
		];

		return $this;
	}

	/**
	 * Register the bindings.
	 *
	 * @param  array  $bindings
	 * @return \Cartalyst\Support\Traits\ValidationTrait
	 */
	public function registerBindings(array $bindings)
	{
		$this->bindings = array_merge($this->bindings, $bindings);

		return $this;
	}

	/**
	 * Executes the data validation against the service rules.
	 *
	 * @param  array  $data
	 * @return \Illuminate\Validation\Validator
	 */
	public function executeValidation(array $data)
	{
		if (is_null($this->scenarios))
		{
			$this->onScenario('any');
		}

		if ( ! is_null($method = $this->scenarios['on']))
		{
			call_user_func_array([$this, $method], $this->scenarios['arguments']);
		}

		$rules = new Fluent($this->getBindedRules());

		return Validator::make($data, $rules->getAttributes());
	}

	/**
	 * Returns the validation rules.
	 *
	 * @return array
	 */
	public function getRules()
	{
		return [];
	}

	/**
	 * Returns the rules already binded.
	 *
	 * @return array<commit_msg>make scenario singular<commit_after><?php namespace Cartalyst\Support\Traits;
/**
 * Part of the Support package.
 *
 * NOTICE OF LICENSE
 *
 * Licensed under the Cartalyst PSL License.
 *
 * This source file is subject to the Cartalyst PSL License that is
 * bundled with this package in the license.txt file.
 *
 * @package    Support
 * @version    1.0.0
 * @author     Cartalyst LLC
 * @license    Cartalyst PSL
 * @copyright  (c) 2011-2014, Cartalyst LLC
 * @link       http://cartalyst.com
 */

use Illuminate\Support\Fluent;
use Illuminate\Support\Facades\Validator;

trait ValidationTrait {

	/**
	 * The registered scenario.
	 *
	 * @var array
	 */
	protected $scenario = [];

	/**
	 * The registered bindings
	 *
	 * @var array
	 */
	protected $bindings = [];

	/**
	 * Create a scope scenario.
	 *
	 * @param  string  $scenario
	 * @param  array  $arguments
	 * @return ValidationTrait
	 */
	public function onScenario($scenario, array $arguments = [])
	{
		$method = 'on'.ucfirst($scenario);

		$this->scenario = [
			'on'        => method_exists($this, $method) ? $method : null,
			'arguments' => $arguments,
		];

		return $this;
	}

	/**
	 * Register the bindings.
	 *
	 * @param  array  $bindings
	 * @return \Cartalyst\Support\Traits\ValidationTrait
	 */
	public function registerBindings(array $bindings)
	{
		$this->bindings = array_merge($this->bindings, $bindings);

		return $this;
	}

	/**
	 * Executes the data validation against the service rules.
	 *
	 * @param  array  $data
	 * @return \Illuminate\Validation\Validator
	 */
	public function executeValidation(array $data)
	{
		if (is_null($this->scenario))
		{
			$this->onScenario('any');
		}

		if ( ! is_null($method = $this->scenario['on']))
		{
			call_user_func_array([$this, $method], $this->scenario['arguments']);
		}

		$rules = new Fluent($this->getBindedRules());

		return Validator::make($data, $rules->getAttributes());
	}

	/**
	 * Returns the validation rules.
	 *
	 * @return array
	 */
	public function getRules()
	{
		return [];
	}

	/**
	 * Returns the rules already binded.
	 *
	 * @return array
{'fraction_non_alphanumeric': 0.14350525310410697, 'fraction_numerical': 0.0052531041069723014, 'mean_word_length': 3.1640159045725644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4987078', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1344, 'n_words': 339}