1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\System;
9:
10: use Illuminate\Validation;
11: use Illuminate\Filesystem;
12: use Illuminate\Translation;
13:
14: /**
15: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
16: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
17: * @copyright Copyright (c) 2019, Afterlogic Corp.
18: *
19: * @package Api
20: */
21: class Validator
22: {
23: public static function validate(array $aInputs, array $aRules, $aMessages = [])
24: {
25: $filesystem = new Filesystem\Filesystem();
26: $fileLoader = new Translation\FileLoader($filesystem, '');
27: $translator = new Translation\Translator($fileLoader, 'en_US');
28: $factory = new Validation\Factory($translator);
29:
30: $validator = $factory->make($aInputs, $aRules, $aMessages);
31:
32: if ($validator->fails()) {
33: $errors = $validator->errors();
34: throw new \Aurora\System\Exceptions\ValidationException(implode("; ", $errors->all()), \Aurora\System\Notifications::InvalidInputParameter);
35: }
36: }
37: }
38: