<commit_before><?php
namespace Rbs\Media\Avatar;

/**
 * @name \Rbs\Media\Avatar\AvatarManager
 * @api
 */
class AvatarManager implements \Zend\EventManager\EventsCapableInterface
{

	use \Change\Events\EventsCapableTrait;

	const AVATAR_MANAGER_IDENTIFIER = 'RbsMediaAvatarManager';
	const AVATAR_GET_AVATAR_URL = 'getAvatarUrl';

	/**
	 * @var \Change\Http\UrlManager
	 */
	protected $urlManager;

	/**
	 * @api
	 * @param \Change\Http\UrlManager $urlManager
	 */
	public function setUrlManager($urlManager)
	{
		$this->urlManager = $urlManager;
	}

	/**
	 * @api
	 * @return \Change\Http\UrlManager
	 */
	public function getUrlManager()
	{
		return $this->urlManager;
	}

	/**
	 * @api
	 * Get the Avatar URL
	 * @param integer $size
	 * @param string $email
	 * @param \Rbs\User\Documents\User $user
	 * @param mixed[] $params
	 * @throws \RuntimeException
	 * @return null|string
	 */
	public function getAvatarUrl($size, $email, $user = null, array $params = null)
	{
		if (! $this->urlManager instanceof \Change\Http\UrlManager)
		{
			throw new \RuntimeException('UrlManager must be defined', 999999);
		}

		if ($this->urlManager->getSelf()->getScheme() == 'https')
		{
			$params['secure'] = true;
		}
		else
		{
			$params['secure'] = false;
		}

		$em = $this->getEventManager();
		$args = $em->prepareArgs($params);

		$args['email'] = $email;
		$args['user'] = $user;
		$args['size'] = $size;

		$event = new \Change\Events\Event(static::AVATAR_GET_AVATAR_URL, $this, $args);
		$this->getEventManager()->trigger($event);

		return $event->getParam('url');
	}

	/**
	 * @return null|string|string[]
	 */
	protected function getEventManagerIdentifier()
	{
		return static::AVATAR_MANAGER_IDENTIFIER;
	}

	/**
	 * @param \Change\Events\EventManager $eventManager
	 */
	protected function attachEvents(\Change\Events\EventManager $eventManager)
	{
		$eventManager->attach(static::AVATAR_GET_AVATAR_URL, array($this, 'getGravatarUrl'), 5);
	}

	/**
	 * @return string[]
	 */
	protected function getListenerAggregateClassNames()
	{
		return $this->getEventManagerFactory()->getConfiguredListenerClassNames('Rbs/Media/AvatarManager');
	}

	/**
	 * @param \Change\Events\Event $event
	 */
	public function getGravatarUrl(\Change\Events\Event $event)
	{
		$url = null;

		/** @var \Rbs\User\Documents\User $user */
		$user = $event->getParam('user');
		if ($user !== null)
		{
			$email = $user->getEmail();
		}
		else
		{
			$email = $event->getParam('email');
		}

		if (!\Change\Stdlib\String::isEmpty($email))
		{
			$avatar = new Gravatar($email);

			if (!\Change\Stdlib\String::isEmpty($event->getParam('defaultImg')))
			{
				$avatar->setDefaultImg($event->getParam('defaultImg'));<commit_msg>Fix avatar manager<commit_after><?php
namespace Rbs\Media\Avatar;

/**
 * @name \Rbs\Media\Avatar\AvatarManager
 * @api
 */
class AvatarManager implements \Zend\EventManager\EventsCapableInterface
{

	use \Change\Events\EventsCapableTrait;

	const AVATAR_MANAGER_IDENTIFIER = 'RbsMediaAvatarManager';
	const AVATAR_GET_AVATAR_URL = 'getAvatarUrl';

	/**
	 * @var \Change\Http\UrlManager
	 */
	protected $urlManager;

	/**
	 * @api
	 * @param \Change\Http\UrlManager $urlManager
	 */
	public function setUrlManager($urlManager)
	{
		$this->urlManager = $urlManager;
	}

	/**
	 * @api
	 * @return \Change\Http\UrlManager
	 */
	public function getUrlManager()
	{
		return $this->urlManager;
	}

	/**
	 * @api
	 * Get the Avatar URL
	 * @param integer $size
	 * @param string $email
	 * @param \Rbs\User\Documents\User $user
	 * @param mixed[] $params
	 * @throws \RuntimeException
	 * @return null|string
	 */
	public function getAvatarUrl($size, $email, $user = null, array $params = null)
	{
		if (! $this->urlManager instanceof \Change\Http\UrlManager)
		{
			throw new \RuntimeException('UrlManager must be defined', 999999);
		}

		if ($this->urlManager->getSelf()->getScheme() == 'https')
		{
			$params['secure'] = true;
		}
		else
		{
			$params['secure'] = false;
		}

		$em = $this->getEventManager();
		$args = $em->prepareArgs($params);

		$args['email'] = $email;
		$args['user'] = $user;
		$args['size'] = $size;

		$event = new \Change\Events\Event(static::AVATAR_GET_AVATAR_URL, $this, $args);
		$this->getEventManager()->trigger($event);

		return $event->getParam('url');
	}

	/**
	 * @return null|string|string[]
	 */
	protected function getEventManagerIdentifier()
	{
		return static::AVATAR_MANAGER_IDENTIFIER;
	}

	/**
	 * @param \Change\Events\EventManager $eventManager
	 */
	protected function attachEvents(\Change\Events\EventManager $eventManager)
	{
		$eventManager->attach(static::AVATAR_GET_AVATAR_URL, array($this, 'onDefaultGetGravatarUrl'), 5);
	}

	/**
	 * @return string[]
	 */
	protected function getListenerAggregateClassNames()
	{
		return $this->getEventManagerFactory()->getConfiguredListenerClassNames('Rbs/Media/Events/AvatarManager');
	}

	/**
	 * @param \Change\Events\Event $event
	 */
	public function onDefaultGetGravatarUrl(\Change\Events\Event $event)
	{
		$url = null;

		/** @var \Rbs\User\Documents\User $user */
		$user = $event->getParam('user');
		if ($user !== null)
		{
			$email = $user->getEmail();
		}
		else
		{
			$email = $event->getParam('email');
		}

		if (!\Change\Stdlib\String::isEmpty($email))
		{
			$avatar = new Gravatar($email);

			if (!\Change\Stdlib\String::isEmpty($event->getParam('defaultImg')))
			{
				$avatar->setDefaultImg($event->getParam('defaultImg'));
{'fraction_non_alphanumeric': 0.17064658339456282, 'fraction_numerical': 0.002571638501102131, 'mean_word_length': 4.013812154696133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '7314392', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1856, 'n_words': 323}