Skip to content

Commit 79dd2f2

Browse files
committed
1.) added: updates from dev
2 parents 7154ac7 + 2e093e4 commit 79dd2f2

File tree

3 files changed

+52
-63
lines changed

3 files changed

+52
-63
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
],
2121
"homepage": "https://github.com/solumdesignum/scenarios",
2222
"require": {
23-
"php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0",
24-
"illuminate/support": "~5|~6|~7|~8"
23+
"php": "^8.0|^8.1|^8.2",
24+
"illuminate/support": "~9|~10"
2525
},
2626
"require-dev": {
27-
"php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0",
28-
"illuminate/support": "~5|~6|~7|~8"
2927
},
3028
"autoload": {
3129
"psr-4": {

src/Scenarios.php

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,17 @@
44

55
namespace SolumDeSignum\Scenarios;
66

7-
use function config;
87
use Illuminate\Support\Facades\Route;
8+
use function config;
9+
use function is_bool;
910

1011
trait Scenarios
1112
{
12-
/**
13-
* @var string
14-
*/
15-
public $scenario;
13+
public string $scenario;
1614

17-
/**
18-
* @var string
19-
*/
20-
public $setMethodFromController;
15+
public mixed $setMethodFromController;
2116

22-
/**
23-
* @var string
24-
*/
25-
public $setMethodFromUrl;
17+
public mixed $setMethodFromUrl;
2618

2719
/**
2820
* Create a new rule instance.
@@ -58,18 +50,44 @@ public function __construct()
5850
}
5951
}
6052

53+
private function exceptionOneSetMethod(): void
54+
{
55+
if (
56+
!is_bool($this->setMethodFromController) ||
57+
!is_bool($this->setMethodFromUrl) ||
58+
($this->setMethodFromController === false && $this->setMethodFromUrl === false)
59+
) {
60+
throw new \Exception(
61+
'Please enable at least one setMethod function, LIKE RIGHT NOW !!!'
62+
);
63+
}
64+
}
65+
66+
private function exceptionOnlyOneSetMethod(): void
67+
{
68+
if (
69+
!is_bool($this->setMethodFromController) ||
70+
!is_bool($this->setMethodFromUrl) ||
71+
($this->setMethodFromController === true && $this->setMethodFromUrl === true)
72+
) {
73+
throw new \Exception(
74+
'Please enable only one setMethod function, LIKE RIGHT NOW !!!'
75+
);
76+
}
77+
}
78+
6179
/**
6280
* @param $method
6381
*
82+
* @return string
6483
* @throws \Exception
6584
*
66-
* @return string
6785
*/
6886
public function patternFilter($method): string
6987
{
70-
\preg_match_all(
88+
preg_match_all(
7189
config('scenarios.methods.pattern'),
72-
\mb_strtolower($method),
90+
strtolower($method),
7391
$matches
7492
);
7593

@@ -78,6 +96,20 @@ public function patternFilter($method): string
7896
return $matches[0][0];
7997
}
8098

99+
/**
100+
* @param mixed $matches
101+
*
102+
* @throws \Exception
103+
*/
104+
private function exceptionScenarioPattern($matches): void
105+
{
106+
if (!isset($matches)) {
107+
throw new \Exception(
108+
'Scenarios patternFilter failed finding match, check $scenarioPattern , LIKE RIGHT NOW !!!'
109+
);
110+
}
111+
}
112+
81113
/**
82114
* @return string|null
83115
*/
@@ -97,44 +129,4 @@ public function currentRequestUri(): ?string
97129
Route::getCurrentRequest()->getRequestUri() :
98130
null;
99131
}
100-
101-
/**
102-
* @param mixed $matches
103-
*
104-
* @throws \Exception
105-
*/
106-
private function exceptionScenarioPattern($matches): void
107-
{
108-
if (isset($matches) === false) {
109-
throw new \Exception(
110-
'Scenarios patternFilter failed finding match, check $scenarioPattern , LIKE RIGHT NOW !!!'
111-
);
112-
}
113-
}
114-
115-
private function exceptionOneSetMethod(): void
116-
{
117-
if (
118-
\is_bool($this->setMethodFromController) === false ||
119-
\is_bool($this->setMethodFromUrl) === false ||
120-
($this->setMethodFromController === false && $this->setMethodFromUrl === false)
121-
) {
122-
throw new \Exception(
123-
'Please enable at least one setMethod function, LIKE RIGHT NOW !!!'
124-
);
125-
}
126-
}
127-
128-
private function exceptionOnlyOneSetMethod(): void
129-
{
130-
if (
131-
\is_bool($this->setMethodFromController) === false ||
132-
\is_bool($this->setMethodFromUrl) === false ||
133-
($this->setMethodFromController === true && $this->setMethodFromUrl === true)
134-
) {
135-
throw new \Exception(
136-
'Please enable only one setMethod function, LIKE RIGHT NOW !!!'
137-
);
138-
}
139-
}
140132
}

src/ScenariosServiceProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace SolumDeSignum\Scenarios;
66

7-
use function config_path;
87
use Illuminate\Support\ServiceProvider;
98

109
class ScenariosServiceProvider extends ServiceProvider
@@ -19,7 +18,7 @@ public function boot(): void
1918
if ($this->app->runningInConsole()) {
2019
$this->publishes(
2120
[
22-
__DIR__.'/../config/scenarios.php' => config_path(
21+
__DIR__ . '/../config/scenarios.php' => config_path(
2322
'scenarios.php'
2423
),
2524
],
@@ -36,7 +35,7 @@ public function boot(): void
3635
public function register(): void
3736
{
3837
$this->mergeConfigFrom(
39-
__DIR__.'/../config/scenarios.php',
38+
__DIR__ . '/../config/scenarios.php',
4039
'scenarios'
4140
);
4241
}

0 commit comments

Comments
 (0)