Skip to content

Commit c4bcfc3

Browse files
Sebastian SulinskiSebastian Sulinski
Sebastian Sulinski
authored and
Sebastian Sulinski
committed
Initial commit
0 parents  commit c4bcfc3

File tree

118 files changed

+32608
-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.

118 files changed

+32608
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.env.example

+39
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+
QUEUE_CONNECTION=sync
19+
SESSION_DRIVER=file
20+
SESSION_LIFETIME=120
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

+5
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

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/storage/*.key
5+
/vendor
6+
.env
7+
.phpunit.result.cache
8+
Homestead.json
9+
Homestead.yaml
10+
npm-debug.log
11+
yarn-error.log
12+
.idea/

app/Category.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\HasMany;
7+
8+
class Category extends Model
9+
{
10+
/**
11+
* The table associated with the model.
12+
*
13+
* @var string
14+
*/
15+
protected $table = 'categories';
16+
17+
/**
18+
* Get children relationship.
19+
*
20+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
21+
*/
22+
public function children(): HasMany
23+
{
24+
return $this->hasMany(static::class, 'cat_parent_id', 'id');
25+
}
26+
}

app/Components/Validation/Factory.php

+284
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+
}

0 commit comments

Comments
 (0)