Skip to content

Commit 7649d0f

Browse files
committed
Fix another test 2
1 parent e824afb commit 7649d0f

File tree

18 files changed

+424
-23
lines changed

18 files changed

+424
-23
lines changed

src/lib/generators/RestActionGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function prepareAction(
154154
: null,
155155
'responseWrapper' => $responseWrapper,
156156
'prefix' => $routeData->getPrefix(),
157-
'prefixSettings' => $routeData->getPrefixSettings(),
157+
'prefixSettings' => $routeData->getPrefixSettings()
158158
],
159159
]);
160160
}

src/lib/items/OptionsRoutesTrait.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,28 @@ public static function finalOptionsRoute(string $prefix, string $controllerId):
6060
return trim($prefix, '/') . '/' . $controllerId . '/options';
6161
}
6262

63-
public function getRouteInfo(): array
64-
{
65-
/** @var ?array $modules */
66-
$modules = $controllerId = $path = $namespace = null;
67-
68-
if ($this->xRoute) {
69-
$routeParts = explode('/', $this->xRoute);
70-
$controllerId = $routeParts[count($routeParts)-2]; # last second part is controller ID
71-
// $actionId = $routeParts[count($routeParts)-1];
72-
unset($routeParts[count($routeParts)-1], $routeParts[count($routeParts)-2]);
73-
$modules = $routeParts;
74-
}
75-
76-
return [
77-
'modules' => $modules,
78-
'controller_id' => $controllerId,
79-
// 'action_id' => $actionId,
80-
'path' => $path,
81-
'namespace' => $namespace,
82-
];
83-
}
63+
// TODO remove
64+
// public function getRouteInfo(): array
65+
// {
66+
// /** @var ?array $modules */
67+
// $modules = $controllerId = $path = $namespace = null;
68+
//
69+
// if ($this->xRoute) {
70+
// $routeParts = explode('/', $this->xRoute);
71+
// $controllerId = $routeParts[count($routeParts)-2]; # last second part is controller ID
72+
//// $actionId = $routeParts[count($routeParts)-1];
73+
// unset($routeParts[count($routeParts)-1], $routeParts[count($routeParts)-2]);
74+
// $modules = $routeParts;
75+
// }
76+
//
77+
// return [
78+
// 'modules' => $modules,
79+
// 'controller_id' => $controllerId,
80+
//// 'action_id' => $actionId,
81+
// 'path' => $path,
82+
// 'namespace' => $namespace,
83+
// ];
84+
// }
8485

8586
// public function getRoute(): string
8687
// {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET api/v1/pets' => 'api/v1/pet/list',
9+
'POST api/v1/pets' => 'api/v1/pet/create',
10+
'GET animals/pets/<id:[\w-]+>' => 'pet/view',
11+
'DELETE animals/pets/<id:[\w-]+>' => 'pet/delete',
12+
'PATCH animals/pets/<id:[\w-]+>' => 'pet/update',
13+
'GET petComments' => 'pet-comment/list',
14+
'GET info/pet-details' => 'petinfo/pet-detail/list',
15+
'GET forum/pet2-details' => 'forum/pet2-detail/list',
16+
'GET forum2/pet3-details' => 'forum2/pet3-detail/list',
17+
'GET api/v2/comments' => 'api/v2/comment/list',
18+
'api/v1/pets' => 'some/pet/options',
19+
'animals/pets/<id:[\w-]+>' => 'pet/options',
20+
'petComments' => 'pet-comment/options',
21+
'info/pet-details' => 'petinfo/pet-detail/options',
22+
'forum/pet2-details' => 'forum/pet2-detail/options',
23+
'forum2/pet3-details' => 'forum2/pet3-detail/options',
24+
'api/v2/comments' => 'api/v2/comment/options',
25+
];
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
class PetCommentController extends \app\controllers\base\PetCommentController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\controllers;
4+
5+
class PetController extends \app\controllers\base\PetController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\controllers\base;
4+
5+
abstract class PetCommentController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionList();
31+
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace app\controllers\base;
4+
5+
abstract class PetController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'view' => [
11+
'class' => \yii\rest\ViewAction::class,
12+
'modelClass' => \app\models\Pet::class,
13+
'checkAccess' => [$this, 'checkAccess'],
14+
],
15+
'delete' => [
16+
'class' => \yii\rest\DeleteAction::class,
17+
'modelClass' => \app\models\Pet::class,
18+
'checkAccess' => [$this, 'checkAccess'],
19+
],
20+
'update' => [
21+
'class' => \yii\rest\UpdateAction::class,
22+
'modelClass' => \app\models\Pet::class,
23+
'checkAccess' => [$this, 'checkAccess'],
24+
],
25+
'options' => [
26+
'class' => \yii\rest\OptionsAction::class,
27+
],
28+
];
29+
}
30+
31+
/**
32+
* Checks the privilege of the current user.
33+
*
34+
* This method checks whether the current user has the privilege
35+
* to run the specified action against the specified data model.
36+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
37+
*
38+
* @param string $action the ID of the action to be executed
39+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
40+
* @param array $params additional parameters
41+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
42+
*/
43+
abstract public function checkAccess($action, $model = null, $params = []);
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\some\controllers;
4+
5+
class CommentController extends \app\some\controllers\base\CommentController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\some\controllers\base;
4+
5+
abstract class CommentController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionList();
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\modules\forum\controllers;
4+
5+
class Pet2DetailController extends \app\modules\forum\controllers\base\Pet2DetailController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionList()
14+
{
15+
//TODO implement actionList
16+
}
17+
18+
19+
}
20+

0 commit comments

Comments
 (0)