<commit_before><?php
/*
 * Created by <NAME> on 2009-09-05.
 * Copyright (c) 2009 <NAME>.
 * All rights reserved.
 */

/**
 * Adds an automatic slug conversion from one column to another.
 * 
 * Example:
 * <code>
 * $descriptor->add($descriptor->newColumn('title'));
 * $descriptor->add($descriptor->newColumn('slug'));
 * 
 * $descriptor->applyPlugin(new Db_Plugin_Sluggable(array('title' => 'slug')));
 * </code>
 */
class Db_Plugin_Sluggable extends Db_Plugin
{
	/**
	 * The callable to use when converting column values to slugs.
	 * 
	 * @var string
	 */
	protected $callable;
	
	/**
	 * The columns to apply the sluggable plugin to.
	 * 
	 * @var array
	 */
	protected $columns = array();
	
	/**
	 * A list to keep track of the decorators we've added.
	 * 
	 * @var array
	 */
	protected $decorators = array();
	
	/**
	 * @param  array			Contains an associative array with the $source_column => $slug_column
	 * @param  string|array		Contains the callable to call, must be public and static
	 */
	function __construct(array $columns, $callable = 'Db_Plugin_Sluggable::filterString')
	{
		// validate the callable
		if( ! is_callable($callable))
		{
			throw new Db_Exception('Erroneous callable format');
		}
		
		if( ! is_array($callable))
		{
			$callable = array($callable);
		}
		
		if(count($callable) == 2)
		{
			$ref = new ReflectionMethod(array_shift($callable), array_shift($callable));
			
			if( ! $ref->isStatic() OR ! $ref->isPublic())
			{
				throw new Db_Exception('Callable is not possible to call from the generated mapper.');
			}
			
			$callable = $ref->class.'::'.$ref->name;
		}
		elseif( ! function_exists($m = array_shift($callable)))
		{
			$ref = new ReflectionMethod($m);
			
			if( ! $ref->isStatic() OR ! $ref->isPublic())
			{
				throw new Db_Exception('Callable is not possible to call from the generated mapper.');
			}
			
			$callable = $ref->class.'::'.$ref->name;
		}
		elseif(function_exists($m))
		{
			$callable = $m;
		}
		else
		{
			throw new Db_Exception('Callable can not be found.');
		}
		<commit_msg>Prefixed all exception messages from Db_Plugin_Sluggable with "Db_Plugin_Sluggable: "<commit_after><?php
/*
 * Created by <NAME> on 2009-09-05.
 * Copyright (c) 2009 <NAME>.
 * All rights reserved.
 */

/**
 * Adds an automatic slug conversion from one column to another.
 * 
 * Example:
 * <code>
 * $descriptor->add($descriptor->newColumn('title'));
 * $descriptor->add($descriptor->newColumn('slug'));
 * 
 * $descriptor->applyPlugin(new Db_Plugin_Sluggable(array('title' => 'slug')));
 * </code>
 */
class Db_Plugin_Sluggable extends Db_Plugin
{
	/**
	 * The callable to use when converting column values to slugs.
	 * 
	 * @var string
	 */
	protected $callable;
	
	/**
	 * The columns to apply the sluggable plugin to.
	 * 
	 * @var array
	 */
	protected $columns = array();
	
	/**
	 * A list to keep track of the decorators we've added.
	 * 
	 * @var array
	 */
	protected $decorators = array();
	
	/**
	 * @param  array			Contains an associative array with the $source_column => $slug_column
	 * @param  string|array		Contains the callable to call, must be public and static
	 */
	function __construct(array $columns, $callable = 'Db_Plugin_Sluggable::filterString')
	{
		// validate the callable
		if( ! is_callable($callable))
		{
			throw new Db_Exception('Db_Plugin_Sluggable: Erroneous callable format');
		}
		
		if( ! is_array($callable))
		{
			$callable = array($callable);
		}
		
		if(count($callable) == 2)
		{
			$ref = new ReflectionMethod(array_shift($callable), array_shift($callable));
			
			if( ! $ref->isStatic() OR ! $ref->isPublic())
			{
				throw new Db_Exception('Db_Plugin_Sluggable: Callable is not possible to call from the generated mapper.');
			}
			
			$callable = $ref->class.'::'.$ref->name;
		}
		elseif( ! function_exists($m = array_shift($callable)))
		{
			$ref = new ReflectionMethod($m);
			
			if( ! $ref->isStatic() OR ! $ref->isPublic())
			{
				throw new Db_Exception('Db_Plugin_Sluggable: Callable is not possible to call from the generated mapper.');
			}
			
			$callable = $ref->class.'::'.$ref->name;
		}
		elseif(function_exists($m))
		{
			$callable = $m;
		}
		else
		{
			throw new Db_Exception('Db_Plugin_Sluggable: Callable can not be found.');
		}
		
{'fraction_non_alphanumeric': 0.15011709601873535, 'fraction_numerical': 0.006088992974238876, 'mean_word_length': 3.4167528438469494, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, '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': '92638', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1395, 'n_words': 366}