Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e01c74b

Browse files
Initial commit
0 parents commit e01c74b

File tree

144 files changed

+21323
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+21323
-0
lines changed

‎.env.example

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
LOG_CHANNEL=stack
8+
9+
DB_CONNECTION=mysql
10+
DB_HOST=127.0.0.1
11+
DB_PORT=3306
12+
DB_DATABASE=homestead
13+
DB_USERNAME=homestead
14+
DB_PASSWORD=secret
15+
16+
BROADCAST_DRIVER=log
17+
CACHE_DRIVER=file
18+
SESSION_DRIVER=file
19+
SESSION_LIFETIME=120
20+
QUEUE_DRIVER=sync
21+
22+
REDIS_HOST=127.0.0.1
23+
REDIS_PASSWORD=null
24+
REDIS_PORT=6379
25+
26+
MAIL_DRIVER=smtp
27+
MAIL_HOST=smtp.mailtrap.io
28+
MAIL_PORT=2525
29+
MAIL_USERNAME=null
30+
MAIL_PASSWORD=null
31+
MAIL_ENCRYPTION=null
32+
33+
PUSHER_APP_ID=
34+
PUSHER_APP_KEY=
35+
PUSHER_APP_SECRET=
36+
PUSHER_APP_CLUSTER=mt1
37+
38+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
39+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

‎.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

‎.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/public/js
5+
/public/css
6+
/storage/*.key
7+
/vendor
8+
/.idea
9+
/.vscode
10+
/.vagrant
11+
mix-manifest.json
12+
Homestead.json
13+
Homestead.yaml
14+
npm-debug.log
15+
yarn-error.log
16+
.env

‎app/Components/Validation/Factory.php

Lines changed: 284 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,284 @@
1+
<?php
2+
3+
namespace App\Components\Validation;
4+
5+
use Closure;
6+
use Illuminate\Support\Str;
7+
use Illuminate\Contracts\Container\Container;
8+
use Illuminate\Contracts\Translation\Translator;
9+
use Illuminate\Validation\PresenceVerifierInterface;
10+
use Illuminate\Contracts\Validation\Factory as FactoryContract;
11+
12+
class Factory implements FactoryContract
13+
{
14+
/**
15+
* The Translator implementation.
16+
*
17+
* @var \Illuminate\Contracts\Translation\Translator
18+
*/
19+
protected $translator;
20+
21+
/**
22+
* The Presence Verifier implementation.
23+
*
24+
* @var \Illuminate\Validation\PresenceVerifierInterface
25+
*/
26+
protected $verifier;
27+
28+
/**
29+
* The IoC container instance.
30+
*
31+
* @var \Illuminate\Contracts\Container\Container
32+
*/
33+
protected $container;
34+
35+
/**
36+
* All of the custom validator extensions.
37+
*
38+
* @var array
39+
*/
40+
protected $extensions = [];
41+
42+
/**
43+
* All of the custom implicit validator extensions.
44+
*
45+
* @var array
46+
*/
47+
protected $implicitExtensions = [];
48+
49+
/**
50+
* All of the custom dependent validator extensions.
51+
*
52+
* @var array
53+
*/
54+
protected $dependentExtensions = [];
55+
56+
/**
57+
* All of the custom validator message replacers.
58+
*
59+
* @var array
60+
*/
61+
protected $replacers = [];
62+
63+
/**
64+
* All of the fallback messages for custom rules.
65+
*
66+
* @var array
67+
*/
68+
protected $fallbackMessages = [];
69+
70+
/**
71+
* The Validator resolver instance.
72+
*
73+
* @var Closure
74+
*/
75+
protected $resolver;
76+
77+
/**
78+
* Create a new Validator factory instance.
79+
*
80+
* @param \Illuminate\Contracts\Translation\Translator $translator
81+
* @param \Illuminate\Contracts\Container\Container $container
82+
* @return void
83+
*/
84+
public function __construct(Translator $translator, Container $container = null)
85+
{
86+
$this->container = $container;
87+
$this->translator = $translator;
88+
}
89+
90+
/**
91+
* Create a new Validator instance.
92+
*
93+
* @param array $data
94+
* @param array $rules
95+
* @param array $messages
96+
* @param array $customAttributes
97+
* @return \Illuminate\Validation\Validator
98+
*/
99+
public function make(array $data, array $rules, array $messages = [], array $customAttributes = [])
100+
{
101+
// The presence verifier is responsible for checking the unique and exists data
102+
// for the validator. It is behind an interface so that multiple versions of
103+
// it may be written besides database. We'll inject it into the validator.
104+
$validator = $this->resolve(
105+
$data, $rules, $messages, $customAttributes
106+
);
107+
108+
if (! is_null($this->verifier)) {
109+
$validator->setPresenceVerifier($this->verifier);
110+
}
111+
112+
// Next we'll set the IoC container instance of the validator, which is used to
113+
// resolve out class based validator extensions. If it is not set then these
114+
// types of extensions will not be possible on these validation instances.
115+
if (! is_null($this->container)) {
116+
$validator->setContainer($this->container);
117+
}
118+
119+
$this->addExtensions($validator);
120+
121+
return $validator;
122+
}
123+
124+
/**
125+
* Validate the given data against the provided rules.
126+
*
127+
* @param array $data
128+
* @param array $rules
129+
* @param array $messages
130+
* @param array $customAttributes
131+
* @return void
132+
*
133+
* @throws \Illuminate\Validation\ValidationException
134+
*/
135+
public function validate(array $data, array $rules, array $messages = [], array $customAttributes = [])
136+
{
137+
$this->make($data, $rules, $messages, $customAttributes)->validate();
138+
}
139+
140+
/**
141+
* Resolve a new Validator instance.
142+
*
143+
* @param array $data
144+
* @param array $rules
145+
* @param array $messages
146+
* @param array $customAttributes
147+
* @return \Illuminate\Validation\Validator
148+
*/
149+
protected function resolve(array $data, array $rules, array $messages, array $customAttributes)
150+
{
151+
if (is_null($this->resolver)) {
152+
return new Validator($this->translator, $data, $rules, $messages, $customAttributes);
153+
}
154+
155+
return call_user_func($this->resolver, $this->translator, $data, $rules, $messages, $customAttributes);
156+
}
157+
158+
/**
159+
* Add the extensions to a validator instance.
160+
*
161+
* @param \App\Components\Validation\Validator $validator
162+
* @return void
163+
*/
164+
protected function addExtensions(Validator $validator)
165+
{
166+
$validator->addExtensions($this->extensions);
167+
168+
// Next, we will add the implicit extensions, which are similar to the required
169+
// and accepted rule in that they are run even if the attributes is not in a
170+
// array of data that is given to a validator instances via instantiation.
171+
$validator->addImplicitExtensions($this->implicitExtensions);
172+
173+
$validator->addDependentExtensions($this->dependentExtensions);
174+
175+
$validator->addReplacers($this->replacers);
176+
177+
$validator->setFallbackMessages($this->fallbackMessages);
178+
}
179+
180+
/**
181+
* Register a custom validator extension.
182+
*
183+
* @param string $rule
184+
* @param \Closure|string $extension
185+
* @param string $message
186+
* @return void
187+
*/
188+
public function extend($rule, $extension, $message = null)
189+
{
190+
$this->extensions[$rule] = $extension;
191+
192+
if ($message) {
193+
$this->fallbackMessages[Str::snake($rule)] = $message;
194+
}
195+
}
196+
197+
/**
198+
* Register a custom implicit validator extension.
199+
*
200+
* @param string $rule
201+
* @param \Closure|string $extension
202+
* @param string $message
203+
* @return void
204+
*/
205+
public function extendImplicit($rule, $extension, $message = null)
206+
{
207+
$this->implicitExtensions[$rule] = $extension;
208+
209+
if ($message) {
210+
$this->fallbackMessages[Str::snake($rule)] = $message;
211+
}
212+
}
213+
214+
/**
215+
* Register a custom dependent validator extension.
216+
*
217+
* @param string $rule
218+
* @param \Closure|string $extension
219+
* @param string $message
220+
* @return void
221+
*/
222+
public function extendDependent($rule, $extension, $message = null)
223+
{
224+
$this->dependentExtensions[$rule] = $extension;
225+
226+
if ($message) {
227+
$this->fallbackMessages[Str::snake($rule)] = $message;
228+
}
229+
}
230+
231+
/**
232+
* Register a custom validator message replacer.
233+
*
234+
* @param string $rule
235+
* @param \Closure|string $replacer
236+
* @return void
237+
*/
238+
public function replacer($rule, $replacer)
239+
{
240+
$this->replacers[$rule] = $replacer;
241+
}
242+
243+
/**
244+
* Set the Validator instance resolver.
245+
*
246+
* @param \Closure $resolver
247+
* @return void
248+
*/
249+
public function resolver(Closure $resolver)
250+
{
251+
$this->resolver = $resolver;
252+
}
253+
254+
/**
255+
* Get the Translator implementation.
256+
*
257+
* @return \Illuminate\Contracts\Translation\Translator
258+
*/
259+
public function getTranslator()
260+
{
261+
return $this->translator;
262+
}
263+
264+
/**
265+
* Get the Presence Verifier implementation.
266+
*
267+
* @return \Illuminate\Validation\PresenceVerifierInterface
268+
*/
269+
public function getPresenceVerifier()
270+
{
271+
return $this->verifier;
272+
}
273+
274+
/**
275+
* Set the Presence Verifier implementation.
276+
*
277+
* @param \Illuminate\Validation\PresenceVerifierInterface $presenceVerifier
278+
* @return void
279+
*/
280+
public function setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)
281+
{
282+
$this->verifier = $presenceVerifier;
283+
}
284+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Components\Validation;
4+
5+
use Illuminate\Contracts\Validation\Rule;
6+
7+
interface RuleContract extends Rule
8+
{
9+
/**
10+
* Get the validation rule.
11+
*
12+
* @return string
13+
*/
14+
public function rule(): string;
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /