<commit_before><?php
/**
 * C83ExtensionBehavior class file.
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; <NAME> 2013-
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package vendor.crisu83.yii-extension
 */

/**
 * Example usage:
 *
 * $this->attachBehavior('extension', 'C83ExtensionBehavior');
 * $this->createPathAlias('myExtension', __DIR__);
 * $this->import('MyClass');
 * $myClass = new MyClass;
 */
class C83ExtensionBehavior extends CBehavior
{
	private $_assetsUrl;
	private $_path;
	private $_alias;

	/**
	 * Imports the a class or directory.
	 * The path alias is automatically prepended if applicable.
	 * @param string $alias path alias to be imported.
	 * @param boolean $forceInclude whether to include the class file immediately.
	 * @return string the class name or the directory that this alias refers to.
	 * @throws CException if the alias is invalid
	 */
	public function import($alias, $forceInclude = false)
	{
		if ($this->_alias !== null)
			$alias = $this->_alias . '.' . $alias;
		return Yii::import($alias, $forceInclude);
	}

	/**
	 * Creates a path alias for the extension.
	 * @param string $alias path alias to be imported.
	 * @param string $path path to the extension.
	 */
	public function createPathAlias($alias, $path)
	{
		$this->_alias = $alias;
		$this->_path = $path;
		Yii::setPathOfAlias($alias, $path);
	}

	/**
	 * Returns the path alias for the extension.
	 * @return string the alias.
	 */
	public function getAlias()
	{
		return $this->_alias;
	}

	/**
	 * Returns the assets url for the extension.
	 * @param string $path assets path.
	 * @param boolean $forceCopy whether we should copy the asset file or directory even if it is already
	 * published before.
	 * @return string the url.
	 */
	public function getAssetsUrl($path, $forceCopy = false)
	{
		if (isset($this->_assetsUrl))
			return $this->_assetsUrl;
		else
		{
			if (!Yii::app()->hasComponent('assetManager'))
				return false;
			/* @var CAssetManager $assetManager */
			$assetManager = Yii::app()->getComponent('assetManager');
			if ($this->_path !== null)
				$path = $this->_path . DIRECTORY_SEPARATOR . $path;
			$assetsUrl = $assetManager->publish($path, false, -1, $forceCopy);
			return $this->_assetsUrl = $assetsUrl;
		}
	}<commit_msg>Change the way assets are handled<commit_after><?php
/**
 * C83ExtensionBehavior class file.
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright &copy; <NAME> 2013-
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package vendor.crisu83.yii-extension.behaviors
 */

/**
 * Extension behavior for components.
 */
class C83ExtensionBehavior extends CBehavior
{
	private $_assetsUrl;
	private $_path;
	private $_alias;
	private $_clientScript;

	/**
	 * Creates a path alias for the extension.
	 * @param string $alias path alias to be imported.
	 * @param string $path path to the extension.
	 */
	public function createPathAlias($alias, $path)
	{
		$this->_alias = $alias;
		$this->_path = $path;
		Yii::setPathOfAlias($alias, $path);
	}

	/**
	 * Imports the a class or directory.
	 * The path alias is automatically prepended if applicable.
	 * @param string $alias path alias to be imported.
	 * @param boolean $forceInclude whether to include the class file immediately.
	 * @return string the class name or the directory that this alias refers to.
	 * @throws CException if the alias is invalid
	 */
	public function import($alias, $forceInclude = false)
	{
		if ($this->_alias !== null)
			$alias = $this->_alias . '.' . $alias;
		return Yii::import($alias, $forceInclude);
	}

	/**
	 * Publishes the extension assets.
	 * @param string $path assets path.
	 * @param boolean $forceCopy whether we should copy the asset file or directory even if it is already
	 * published before.
	 * @return string the url.
	 */
	public function publishAssets($path, $forceCopy = false)
	{
		if (!Yii::app()->hasComponent('assetManager'))
			return false;
		/* @var CAssetManager $assetManager */
		$assetManager = Yii::app()->getComponent('assetManager');
		if ($this->_path !== null)
			$path = $this->_path . DIRECTORY_SEPARATOR . $path;
		$assetsUrl = $assetManager->publish($path, false, -1, $forceCopy);
		return $this->_assetsUrl = $assetsUrl;
	}

	/**
	 * Registers a CSS file.
	 * @param string $url URL of the CSS file.
	 * @param string $media media that the CSS file should be applied to.
	 */
	public function registerCssFile($url, $media = '')
	{
		if (isset($this->_assetsUrl))
			$url = $this->_assetsUrl . '/' . ltrim($url, '/');
		$this->getClientScript()->registerCssFile($url, $media);
	}

	/**
	 * Registers a JavaScript file.
	 * @param string $url URL of the javascript file.
	 * @param integer $position the position of the JavaScript code.
	 */
	public function registerScriptFile($url, $position = null)
	{
		if (isset($this->_assetsUrl))
			$url = $this->_assetsUrl . '/' . ltrim($url, '/');
		$this->getClientScript()->registerScriptFile($url, $position);
	}

	/**
	 * Returns the path alias for the extension.
	 * @return string the alias or false if not set.
	 */
	public function getAlias()
	{
		return isset($this->_alias) ? $this->_alias : false;
	}

	/**
	 * Returns the client script component.
	 * @return CClientScript the component.
	 */
	protected function getClientScript()
	{
		if (isset($this->_clientScript))
			return $this->_clientScript;
		else
		{
			if (!Yii::app()->hasComponent('clientScript'))
				return false;
			return $this->_clientScript = Yii::app()->getComponent('clientScript');
		}
	}
{'fraction_non_alphanumeric': 0.14029743773517292, 'fraction_numerical': 0.004300304604909514, 'mean_word_length': 3.7750213857998287, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3480377', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1656, 'n_words': 536}