Вход Регистрация
Файл: gapps/vendor/prettus/l5-repository/src/Prettus/Repository/Generators/Migrations/RulesParser.php
Строк: 64
<?php
namespace PrettusRepositoryGeneratorsMigrations;

use 
IlluminateContractsSupportArrayable;

/**
 * Class RulesParser
 * @package PrettusRepositoryGeneratorsMigrations
 */
class RulesParser implements Arrayable
{

    
/**
     * The set of rules.
     *
     * @var string
     */
    
protected $rules;


    
/**
     * Create new instance.
     *
     * @param string|null $rules
     */
    
public function __construct($rules null)
    {
        
$this->rules $rules;
    }

    
/**
     * Convert string migration to array.
     *
     * @return array
     */
    
public function toArray()
    {
        return 
$this->parse($this->rules);
    }

    
/**
     * Parse a string to array of formatted rules.
     *
     * @param  string $rules
     *
     * @return array
     */
    
public function parse($rules)
    {
        
$this->rules $rules;
        
$parsed = [];
        foreach (
$this->getRules() as $rulesArray) {
            
$column $this->getColumn($rulesArray);
            
$attributes $this->getAttributes($column$rulesArray);
            
$parsed[$column] = $attributes;
        }

        return 
$parsed;
    }

    
/**
     * Get array of rules.
     *
     * @return array
     */
    
public function getRules()
    {
        if (
is_null($this->rules)) {
            return [];
        }

        return 
explode(','str_replace(' '''$this->rules));
    }

    
/**
     * Get column name from rules.
     *
     * @param  string $rules
     *
     * @return string
     */
    
public function getColumn($rules)
    {
        return 
array_first(explode('=>'$rules), function ($key$value) {
            return 
$value;
        });
    }


    
/**
     * Get column attributes.
     *
     * @param  string $column
     * @param  string $rules
     *
     * @return array
     */
    
public function getAttributes($column$rules)
    {

        return 
str_replace($column '=>'''$rules);
    }

}
Онлайн: 1
Реклама