for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Konsulting\Laravel\RuleRepository;
use Konsulting\Laravel\RuleRepository\Contracts\RuleRepository;
abstract class AbstractRepository implements RuleRepository
{
/**
* Prepend a rule to all fields. Rules expressed as pipe-delimited strings will be converted to arrays.
*
* @param string $rule
* @param array $baseRules
* @return array[]
*/
protected function prependRule($rule, $baseRules)
return array_map(function ($ruleLine) use ($rule) {
return array_merge([$rule], $this->ensureArray($ruleLine));
}, $baseRules);
}
* Append a rule to all fields. Rules expressed as pipe-delimited strings will be converted to arrays.
protected function appendRule($rule, $baseRules)
return array_merge($this->ensureArray($ruleLine), [$rule]);
* Make sure the rules are expressed in array format.
* @param array|string|mixed $ruleLine
* @return array
private function ensureArray($ruleLine)
if (empty($ruleLine)) {
return [];
} elseif (is_string($ruleLine)) {
return explode('|', $ruleLine);
return is_array($ruleLine) ? $ruleLine : [$ruleLine];