当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::extendImplicit方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Validator::extendImplicit方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::extendImplicit方法的具体用法?PHP Validator::extendImplicit怎么用?PHP Validator::extendImplicit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Validator的用法示例。


在下文中一共展示了Validator::extendImplicit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: function

 function __construct()
 {
     Validator::extend('multiple_value_in', function ($attribute, $value, $parameters, $validator) {
         $inputs = explode(';', $value);
         foreach ($inputs as $input) {
             if (!in_array($input, $parameters)) {
                 return false;
             }
         }
         return true;
     });
     Validator::extendImplicit('required_any', function ($attribute, $value, $parameters, $validator) {
         for ($i = 1; $i < count($parameters); $i = $i + 2) {
             $values = $parameters[$i];
             if (!empty($values)) {
                 return true;
             }
         }
         return false;
     });
     Validator::extendImplicit('required_only_one', function ($attribute, $value, $parameters, $validator) {
         $counter = 0;
         foreach ($parameters as $parameterIndex => $parameter) {
             if ($parameterIndex % 2 != 0 && !empty($parameter)) {
                 $counter++;
             }
         }
         if ($counter == self::REQUIRED_NONEMPTY_FIELD) {
             return true;
         }
         return false;
     });
     Validator::extendImplicit('unique_validation', function ($attribute, $value, $parameters, $validator) {
         $csvDatas = Excel::load($parameters[2])->get()->toArray();
         $counter = 0;
         $csvFiled = $parameters[3];
         foreach ($csvDatas as $csvDataIndex => $csvData) {
             if ($csvData[$csvFiled] == $parameters[1]) {
                 $counter++;
             }
         }
         if ($counter == self::IDENTICAL_INTERNAL_REFERENCE) {
             return true;
         }
         return false;
     });
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:47,代码来源:CsvImportValidator.php

示例2: function

 function __construct()
 {
     Validator::extendImplicit('unique_lang', function ($attribute, $value, $parameters, $validator) {
         $languages = [];
         foreach ($value as $narrative) {
             $language = $narrative['language'];
             if (in_array($language, $languages)) {
                 return false;
             }
             $languages[] = $language;
         }
         return true;
     });
     Validator::extendImplicit('required_with_language', function ($attribute, $value, $parameters, $validator) {
         $language = preg_replace('/([^~]+).narrative/', '$1.language', $attribute);
         return !(Input::get($language) && !Input::get($attribute));
     });
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:18,代码来源:OrganizationBaseRequest.php

示例3: __construct

 public function __construct()
 {
     Validator::extendImplicit('required_any', function ($attribute, $value, $parameters, $validator) {
         for ($i = 1; $i < count($parameters); $i = $i + 2) {
             $value = $parameters[$i];
             if (!empty($value)) {
                 return true;
             }
         }
         return false;
     });
     Validator::extend('code_list', function ($attribute, $value, $parameters, $validator) {
         $listName = $parameters[1];
         $listType = $parameters[0];
         $codeList = $this->getCodes($listName, $listType);
         return !array_diff(explode(';', $value), $codeList);
     });
     Validator::extend('unique_activity_identifier', function ($attribute, $value, $parameters, $validator) {
         $table = 'activity_data';
         $column = 'identifier';
         $jsonPath = '{activity_identifier}';
         $orgId = session('org_id');
         $builder = DB::table($table)->whereRaw(sprintf("%s #>> '{%s}' = ?", $column, str_replace('.', ',', $jsonPath)), [$value])->where('organization_id', $orgId);
         $count = $builder->count();
         $validator->addReplacer('unique_activity_identifier', function ($message, $attribute, $rule, $parameters) use($validator, $builder) {
             $activity = $builder->first();
             if ($activity) {
                 $activityId = $activity->id;
                 $identifier = json_decode($activity->identifier, true);
                 $activityTitle = $activity->title ? json_decode($activity->title, true)[0]['narrative'] : $identifier['iati_identifier_text'];
                 $message = str_replace(':activity_identifier', $identifier['activity_identifier'], $message);
                 $message = str_replace(':activity_id', $activityId, $message);
                 $message = str_replace(':activity_title', $activityTitle, $message);
             }
             return $message;
         });
         return $count === 0;
     });
     Validator::extend('is_single_value', function ($attribute, $value, $parameters, $validator) {
         return count(explode(';', $value)) == 1;
     });
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:42,代码来源:ActivityCsvFieldChecker.php

示例4: rules

 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     Validator::extendImplicit('diff', function ($attribute, $value, $parameters, $validator) {
         return false;
     });
     $req = $this;
     $this->reporting_organization_info = $req->get('reporting_organization_info')[0];
     $rules = [];
     foreach ($this->reporting_organization_info as $key => $val) {
         $rules["reporting_organization_info.0.{$key}"] = 'required';
         $rules["reporting_organization_info.0.narrative"] = "unique_lang|unique_default_lang";
     }
     $rules["reporting_organization_info.0.narrative.0.narrative"] = 'required';
     $rules["default_field_values.0.linked_data_uri"] = 'url';
     $rules["default_field_values.0.default_currency"] = 'required';
     $rules["default_field_values.0.default_language"] = 'required';
     $rules["default_field_values.0.default_hierarchy"] = 'numeric';
     $rules = array_merge($rules, $this->getRulesForReportingOrganization($this->reporting_organization_info));
     return $rules;
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:25,代码来源:SettingsRequest.php

示例5: function

 function __construct()
 {
     parent::__construct();
     Validator::extendImplicit('year_value_narrative_validation', function ($attribute, $value, $parameters, $validator) {
         $narratives = $value['comment'][0]['narrative'];
         $hasNarrative = false;
         foreach ($narratives as $narrative) {
             if ($narrative['narrative']) {
                 $hasNarrative = true;
                 break;
             }
         }
         if (!$hasNarrative) {
             return true;
         }
         isset($value['year']) ?: ($value['year'] = null);
         isset($value['value']) ?: ($value['value'] = null);
         return $hasNarrative && ($value['year'] || $value['value']);
     });
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:20,代码来源:Result.php

示例6: function

 function __construct()
 {
     Validator::extendImplicit('unique_lang', function ($attribute, $value, $parameters, $validator) {
         $languages = [];
         foreach ($value as $narrative) {
             $language = $narrative['language'];
             if (in_array($language, $languages)) {
                 return false;
             }
             $languages[] = $language;
         }
         return true;
     });
     Validator::extendImplicit('unique_default_lang', function ($attribute, $value, $parameters, $validator) {
         $languages = [];
         $defaultLanguage = getDefaultLanguage();
         $validator->addReplacer('unique_default_lang', function ($message, $attribute, $rule, $parameters) use($validator, $defaultLanguage) {
             return str_replace(':language', app(GetCodeName::class)->getActivityCodeName('Language', $defaultLanguage), $message);
         });
         $check = true;
         foreach ($value as $narrative) {
             $languages[] = $narrative['language'];
         }
         if (count($languages) === count(array_unique($languages))) {
             if (in_array("", $languages) && in_array($defaultLanguage, $languages)) {
                 $check = false;
             }
         }
         return $check;
     });
     Validator::extendImplicit('sum', function ($attribute, $value, $parameters, $validator) {
         return false;
     });
     Validator::extendImplicit('required_with_language', function ($attribute, $value, $parameters, $validator) {
         $language = preg_replace('/([^~]+).narrative/', '$1.language', $attribute);
         return !(Input::get($language) && !Input::get($attribute));
     });
     Validator::extend('exclude_operators', function ($attribute, $value, $parameters, $validator) {
         return !preg_match('/[\\/\\&\\|\\?|]+/', $value);
     });
 }
开发者ID:younginnovations,项目名称:aidstream,代码行数:41,代码来源:ActivityBaseRequest.php


注:本文中的Illuminate\Support\Facades\Validator::extendImplicit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。