<commit_before><?php
/**
 * Created by PhpStorm.
 * Author: ljt
 * DateTime: 2016/10/27 16:51
 * Description:
 */

namespace backend\behaviors;


use yii\base\Behavior;
use yii\helpers\ArrayHelper;

class DynamicFormBehavior extends Behavior
{

    /**
     * ['attribute' => ['type' => 'text', 'items' => [], 'options' => []]
     * @var array
     */
    public $formAttributes = [];

    public function supportAttributeTypes()
    {
        return [
            'text',
            'array',
            'password',
            'textarea',
            'select',
            'checkbox',
            'radio',
            'image',
            'editor',
            'date',
            'datetime',
            'file',
            'city'
        ];
    }

    public function init()
    {
        parent::init();
        if (empty($this->formAttributes)) {
            $formAttributes = $this->owner->attributes();
            $formAttributes = array_combine($formAttributes, $formAttributes);
            ArrayHelper::remove($formAttributes, $this->owner->primaryKey()[0]);
            $this->formAttributes = $formAttributes;
        }
    }

    public function getAttributeType($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            if(is_string($this->formAttributes[$attribute])) {
                return $this->formAttributes[$attribute];
            } else {
                return isset($this->formAttributes[$attribute]['type']) ? $this->formAttributes[$attribute]['type'] : 'text';
            }
        }
    }

    public function getAttributeItems($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            return $this->formAttributes[$attribute]['items'] ? $this->formAttributes[$attribute]['items'] : [];
        }
    }

    public function getAttributeOptions($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            return isset($this->formAttributes[$attribute]['options']) ? $this->formAttributes[$attribute]['options'] : [];
        }
    }

    public function formAttributes()
    {
        return array_filter(array_keys($this->formAttributes), function ($value) {
            if (!in_array($this->getAttributeType($value), $this->supportAttributeTypes())) {
                return false;
            }
            return true;
        });
    }

}<commit_msg>修复articlemodule一个bug<commit_after><?php
/**
 * Created by PhpStorm.
 * Author: ljt
 * DateTime: 2016/10/27 16:51
 * Description:
 */

namespace backend\behaviors;


use yii\base\Behavior;
use yii\helpers\ArrayHelper;

class DynamicFormBehavior extends Behavior
{

    /**
     * ['attribute' => ['type' => 'text', 'items' => [], 'options' => []]
     * @var array
     */
    public $formAttributes = [];

    public function supportAttributeTypes()
    {
        return [
            'text',
            'array',
            'password',
            'textarea',
            'select',
            'checkbox',
            'radio',
            'image',
            'editor',
            'date',
            'datetime',
            'file',
            'city'
        ];
    }

    public function init()
    {
        parent::init();
        if (empty($this->formAttributes)) {
            $formAttributes = $this->owner->attributes();
            $formAttributes = array_combine($formAttributes, $formAttributes);
            ArrayHelper::remove($formAttributes, $this->owner->primaryKey()[0]);
            $this->formAttributes = $formAttributes;
        }
    }

    public function getAttributeType($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            if(is_string($this->formAttributes[$attribute])) {
                return $this->formAttributes[$attribute];
            } else {
                return isset($this->formAttributes[$attribute]['type']) ? $this->formAttributes[$attribute]['type'] : 'text';
            }
        }
    }

    public function getAttributeItems($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            return ArrayHelper::getValue($this->formAttributes[$attribute], 'items', []);
        }
    }

    public function getAttributeOptions($attribute)
    {
        if(isset($this->formAttributes[$attribute])) {
            return ArrayHelper::getValue($this->formAttributes[$attribute], 'options', []);
        }
    }

    public function formAttributes()
    {
        return array_filter(array_keys($this->formAttributes), function ($value) {
            if (!in_array($this->getAttributeType($value), $this->supportAttributeTypes())) {
                return false;
            }
            return true;
        });
    }

}
{'fraction_non_alphanumeric': 0.1514505119453925, 'fraction_numerical': 0.005546075085324232, 'mean_word_length': 2.107355864811133, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '119674', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1210, 'n_words': 202}