Movatterモバイル変換


[0]ホーム

URL:


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

Commit122de08

Browse files
committed
Improve lodash structure and code style
1 parent0015f79 commit122de08

File tree

7 files changed

+1119
-850
lines changed

7 files changed

+1119
-850
lines changed

‎composer.lock‎

Lines changed: 1078 additions & 804 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/Lodash/Http/Requests/RestrictsExtraAttributes.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ private function checkForNotAllowedProperties(): void
6060
// Ignore marked properties
6161
if (!empty($this->ignoreExtraProperties)) {
6262
foreach ($this->ignoreExtraPropertiesas$deleleValue) {
63-
if (($key =array_search($deleleValue,$validationData)) !==false) {
63+
$key =array_search($deleleValue,$validationData);
64+
if ($key !==false) {
6465
unset($validationData[$key]);
6566
}
6667
}

‎src/Lodash/Http/Resources/JsonResource.php‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,39 @@ abstract class JsonResource extends BaseResource
3636
publicfunctiongetTransformed():array
3737
{
3838
if ($this->resourceinstanceof TransformableContract) {
39-
return$this->transformToApi($this->resource);
39+
returnstatic::transformToApi($this->resource);
4040
}
4141

4242
return [];
4343
}
4444

45+
publicfunctionsetWith(array$data):self
46+
{
47+
$this->with =$data;
48+
49+
return$this;
50+
}
51+
52+
publicfunctiongetWith():array
53+
{
54+
return$this->with;
55+
}
56+
57+
publicfunctionappendWith(array$data):self
58+
{
59+
$this->with =array_merge_recursive($this->with,$data);
60+
61+
return$this;
62+
}
63+
4564
publicfunctiontoArray($request):array
4665
{
4766
$data =$this->getResourceData();
4867

68+
if (!empty($this->with)) {
69+
$data += Arr::except($this->with, ['id','type','attributes']);
70+
}
71+
4972
$relationsData =$this->getRelationsData();
5073

5174
if (!empty($relationsData)) {

‎src/Lodash/ServiceProvider.php‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
useLongman\LaravelLodash\Validation\StrictTypeValidator;
1919
useLongman\LaravelLodash\Validation\Validator;
2020

21-
usefunctionapp;
2221
usefunctionarray_keys;
23-
usefunctionarray_pad;
2422
usefunctionconfig;
2523
usefunctionconfig_path;
26-
usefunctionpreg_split;
2724
usefunctionresource_path;
2825
usefunctionstr_replace;
29-
usefunctiontrim;
3026

3127
class ServiceProviderextends LaravelServiceProvider
3228
{
@@ -75,8 +71,6 @@ function (Translator $translator, array $data, array $rules, array $messages): V
7571
},
7672
);
7773

78-
$this->registerBladeDirectives();
79-
8074
$this->loadTranslations();
8175
//$this->loadValidations();
8276
}
@@ -103,28 +97,6 @@ protected function registerCommands(): void
10397
$this->commands(array_keys($this->commands));
10498
}
10599

106-
protectedfunctionregisterBladeDirectives():void
107-
{
108-
if (!config('lodash.register.blade_directives')) {
109-
return;
110-
}
111-
112-
// Display relative time
113-
app('blade.compiler')->directive('datetime',staticfunction ($expression) {
114-
return"<?php echo '<time datetime=\'' . with($expression)->toIso8601String()
115-
. '\' title=\'' .$expression . '\'>'
116-
. with($expression)->diffForHumans() . '</time>' ?>";
117-
});
118-
119-
// Pluralization helper
120-
app('blade.compiler')->directive('plural',staticfunction ($expression) {
121-
$expression =trim($expression,'()');
122-
[$count,$str,$spacer] =array_pad(preg_split('/,\s*/',$expression),3,"' '");
123-
124-
return"<?php echo$count .$spacer . str_plural($str,$count) ?>";
125-
});
126-
}
127-
128100
protectedfunctionregisterRequestMacros():void
129101
{
130102
if (!config('lodash.register.request_macros')) {

‎src/Lodash/Testing/Attributes.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
usefunctionarray_key_exists;
1212
usefunctionarray_replace_recursive;
13+
usefunctioncount;
1314
usefunctionexplode;
1415
usefunctionstr_starts_with;
1516

‎src/Lodash/Testing/DataStructuresProvider.php‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
usefunctionarray_shift;
1111
usefunctioncall_user_func_array;
1212
usefunctionexplode;
13-
usefunctionget_called_class;
1413
usefunctionis_callable;
1514
usefunctionlcfirst;
1615
usefunctionproperty_exists;
@@ -20,20 +19,6 @@
2019

2120
abstractclass DataStructuresProvider
2221
{
23-
publicstaticfunction__callStatic(string$name,array$arguments):mixed
24-
{
25-
$property =lcfirst(Str::substr($name,3));
26-
if (!property_exists(get_called_class(),$property)) {
27-
thrownewInvalidArgumentException('Property "' .$property .'" does not exists');
28-
}
29-
$structure =static::$$property;
30-
31-
$parameters = [&$structure,$arguments[0] ?? []];
32-
call_user_func_array([get_called_class(),'includeNestedRelations'],$parameters);
33-
34-
return$structure;
35-
}
36-
3722
protectedstaticfunctionincludeNestedRelations(array &$item,array$relations):void
3823
{
3924
if (empty($relations)) {
@@ -90,4 +75,18 @@ protected static function getItemStructure(string $relationItem): array
9075

9176
returnstatic::$method();
9277
}
78+
79+
publicstaticfunction__callStatic(string$name,array$arguments):mixed
80+
{
81+
$property =lcfirst(Str::substr($name,3));
82+
if (!property_exists(static::class,$property)) {
83+
thrownewInvalidArgumentException('Property "' .$property .'" does not exists');
84+
}
85+
$structure =static::$$property;
86+
87+
$parameters = [&$structure,$arguments[0] ?? []];
88+
call_user_func_array([static::class,'includeNestedRelations'],$parameters);
89+
90+
return$structure;
91+
}
9392
}

‎src/config/config.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
],
3535

3636
'register' => [
37-
'blade_directives' =>false,
3837
'request_macros' =>false,
3938
'translations' =>true,
4039
'validation_rules' =>true,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp