<commit_before><?php
/*
 * This file is part of the vxPHP/vxWeb framework
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


namespace vxPHP\Form\FormElement\FormElementWithOptions;

use vxPHP\Form\FormElement\LabelElement;

/**
 * a single option belonging to a group of <input type="option"> elements
 * sharing the same name
 *
 * @author <NAME>
 * @version 0.7.0 2019-01-03
 */
class RadioOptionElement extends FormElementFragment {

	/**
	 * initialize option with value, label and parent RadioElement
	 * 
	 * @param string $value
	 * @param LabelElement $label
	 * @param RadioElement $formElement
	 */
	public function __construct($value, LabelElement $label, RadioElement $formElement = null) {

		parent::__construct($value, null, $label, $formElement);

	}

    /**
     * render element; when $force is FALSE a cached element rendering is re-used
     *
     * @param boolean $force
     * @return string
     */
	public function render($force = false) {

		if(empty($this->html) || $force) {

			$formId = $this->parentElement->getForm()->getAttribute('id');
			$name = $this->parentElement->getName();
			$value = $this->getValue();
			$id = ($formId ? ($formId . '_') : '') . $name . '_' . $value;

			$this->html = sprintf(
				'<input id="%s" name="%s" type="radio" value="%s"%s>',
				$id,
				$name,
				$value,
				$this->selected ? " checked='checked'" : ''
			);

			if($this->label) {
			    $this->html .= $this->label->setAttribute('for', $id)->render();
            }

		}

		return $this->html;

	}
}
<commit_msg>Radio options render additional attributes<commit_after><?php
/*
 * This file is part of the vxPHP/vxWeb framework
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


namespace vxPHP\Form\FormElement\FormElementWithOptions;

use vxPHP\Form\FormElement\LabelElement;

/**
 * a single option belonging to a group of <input type="option"> elements
 * sharing the same name
 *
 * @author <NAME>
 * @version 0.8.0 2019-01-04
 */
class RadioOptionElement extends FormElementFragment {

	/**
	 * initialize option with value, label and parent RadioElement
	 * 
	 * @param string $value
	 * @param LabelElement $label
	 * @param RadioElement $formElement
	 */
	public function __construct($value, LabelElement $label, RadioElement $formElement = null) {

		parent::__construct($value, null, $label, $formElement);

	}

    /**
     * render element; when $force is FALSE a cached element rendering is re-used
     *
     * @param boolean $force
     * @return string
     */
	public function render($force = false) {

		if(empty($this->html) || $force) {

			$name = $this->parentElement->getName();
			$value = $this->getValue();

            if($this->selected) {
                $this->attributes['checked'] = 'checked';
            }
            else {
                unset($this->attributes['checked']);
            }

            if(!isset($this->attributes['id'])) {
                $formId = $this->parentElement->getForm()->getAttribute('id');
                $this->attributes['id'] = ($formId ? ($formId . '_') : '') . $name . '_' . $value;
            }

            $this->attributes['value'] = $this->getValue();
            $this->attributes['name'] = $this->parentElement->getName();

            $attr = [];

            foreach($this->attributes as $k => $v) {
                $attr[] = sprintf('%s="%s"', $k, $v);
            }

			$this->html = sprintf(
				'<input type="radio" %s>',
                implode(' ', $attr)
			);

			if($this->label) {
			    $this->html .= $this->label->setAttribute('for', $this->attributes['id'])->render();
            }

		}

		return $this->html;

	}
}

{'fraction_non_alphanumeric': 0.1619244697361614, 'fraction_numerical': 0.005690636316606311, 'mean_word_length': 2.780058651026393, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 57, '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': '4555545', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1135, 'n_words': 298}