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

/**
 * A decorator which checks if the source column is changed, and if so it gets
 * its content and filters it through the callable to finally assign it to the column of the decorated object.
 */
class Db_Plugin_Sluggable_Decorator extends Db_Decorator
{
	protected $source;
	
	protected $callable;
	
	function __construct(Db_Descriptor_Column $destination, Db_Descriptor_Column $source, $callable)
	{
		$this->setDecoratedObject($destination);
		$this->source = $source;
		$this->callable = $callable;
	}
	
	public function getFromObjectToDataCode($object_var, $dest_var, $is_update = false)
	{
		// only assign the columns which are allowed to be updated
		if(( ! $is_update && $this->isInsertable()) OR $is_update && $this->isUpdatable())
		{
			return 'Db::isChanged('.$object_var.', '.$this->source->getProperty().') && '.$dest_var.'[\''.$this->getColumn().'\'] = '.$this->callable.'('.$this->source->getCastFromPhpCode($this->source->getFromObjectCode($object_var)).');';
		}
		else
		{
			return '';
		}
	}
}

/* End of file Decorator.php */
/* Location: ./lib/Db/Plugin/Sluggable */<commit_msg>PHPdoc<commit_after><?php
/*
 * Created by <NAME> on 2009-09-05.
 * Copyright (c) 2009 <NAME>.
 * All rights reserved.
 */

/**
 * A decorator which checks if the source column is changed, and if so it gets
 * its content and filters it through the callable to finally assign it to the column of the decorated object.
 */
class Db_Plugin_Sluggable_Decorator extends Db_Decorator
{
	/**
	 * The source column.
	 * 
	 * @var Db_Descriptor_Column
	 */
	protected $source;
	
	/**
	 * The callable which converts the title-ish column data to an url-friendly string.
	 * 
	 * @var string
	 */
	protected $callable;
	
	/**
	 * @param  Db_Descriptor_Column
	 * @param  Db_Descriptor_Column
	 * @param  string
	 */
	function __construct(Db_Descriptor_Column $destination, Db_Descriptor_Column $source, $callable)
	{
		$this->setDecoratedObject($destination);
		$this->source = $source;
		$this->callable = $callable;
	}
	
	/**
	 * Overridden method of Db_Descriptor_Column::getFromObjectToDataCode().
	 * 
	 * It will add specific logic which converts the source column value to an
	 * url-friendly value.
	 * 
	 * @see Db_Descriptor_Column::getFromObjectToDataCode()
	 * @param  string
	 * @param  string
	 * @param  bool
	 * @return string
	 */
	public function getFromObjectToDataCode($object_var, $dest_var, $is_update = false)
	{
		// only assign the columns which are allowed to be updated
		if(( ! $is_update && $this->isInsertable()) OR $is_update && $this->isUpdatable())
		{
			return 'Db::isChanged('.$object_var.', '.$this->source->getProperty().') && '.$dest_var.'[\''.$this->getColumn().'\'] = '.$this->callable.'('.$this->source->getCastFromPhpCode($this->source->getFromObjectCode($object_var)).');';
		}
		else
		{
			return '';
		}
	}
}

/* End of file Decorator.php */
/* Location: ./lib/Db/Plugin/Sluggable */
{'fraction_non_alphanumeric': 0.15050936575747617, 'fraction_numerical': 0.007886953664147224, 'mean_word_length': 3.9176090468497575, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '1993922', 'n_tokens_mistral': 1062, 'n_tokens_neox': 969, 'n_words': 256}