Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Validation;
4
 
5
use Illuminate\Foundation\Precognition;
6
 
7
/**
8
 * Provides default implementation of ValidatesWhenResolved contract.
9
 */
10
trait ValidatesWhenResolvedTrait
11
{
12
    /**
13
     * Validate the class instance.
14
     *
15
     * @return void
16
     */
17
    public function validateResolved()
18
    {
19
        $this->prepareForValidation();
20
 
21
        if (! $this->passesAuthorization()) {
22
            $this->failedAuthorization();
23
        }
24
 
25
        $instance = $this->getValidatorInstance();
26
 
27
        if ($this->isPrecognitive()) {
28
            $instance->after(Precognition::afterValidationHook($this));
29
        }
30
 
31
        if ($instance->fails()) {
32
            $this->failedValidation($instance);
33
        }
34
 
35
        $this->passedValidation();
36
    }
37
 
38
    /**
39
     * Prepare the data for validation.
40
     *
41
     * @return void
42
     */
43
    protected function prepareForValidation()
44
    {
45
        //
46
    }
47
 
48
    /**
49
     * Get the validator instance for the request.
50
     *
51
     * @return \Illuminate\Validation\Validator
52
     */
53
    protected function getValidatorInstance()
54
    {
55
        return $this->validator();
56
    }
57
 
58
    /**
59
     * Handle a passed validation attempt.
60
     *
61
     * @return void
62
     */
63
    protected function passedValidation()
64
    {
65
        //
66
    }
67
 
68
    /**
69
     * Handle a failed validation attempt.
70
     *
71
     * @param  \Illuminate\Validation\Validator  $validator
72
     * @return void
73
     *
74
     * @throws \Illuminate\Validation\ValidationException
75
     */
76
    protected function failedValidation(Validator $validator)
77
    {
78
        throw new ValidationException($validator);
79
    }
80
 
81
    /**
82
     * Determine if the request passes the authorization check.
83
     *
84
     * @return bool
85
     */
86
    protected function passesAuthorization()
87
    {
88
        if (method_exists($this, 'authorize')) {
89
            return $this->authorize();
90
        }
91
 
92
        return true;
93
    }
94
 
95
    /**
96
     * Handle a failed authorization attempt.
97
     *
98
     * @return void
99
     *
100
     * @throws \Illuminate\Validation\UnauthorizedException
101
     */
102
    protected function failedAuthorization()
103
    {
104
        throw new UnauthorizedException;
105
    }
106
}