Skip to content

Commit 0513dbe

Browse files
committed
Fix use stmts & embrace language message
1 parent 7a5d2b9 commit 0513dbe

6 files changed

Lines changed: 61 additions & 36 deletions

File tree

system/Language/en/RESTful.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* RESTful language strings.
4+
*
5+
* @package CodeIgniter
6+
* @author CodeIgniter Dev Team
7+
* @copyright 2014-2019 British Columbia Institute of Technology (https://bcit.ca/)
8+
* @license https://opensource.org/licenses/MIT MIT License
9+
* @link https://codeigniter.com
10+
* @since Version 3.0.0
11+
* @filesource
12+
*
13+
* @codeCoverageIgnore
14+
*/
15+
16+
return [
17+
'notImplemented' => "'{0}' action not implemented.",
18+
];

system/RESTful/ResourceController.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
use CodeIgniter\API\ResponseTrait;
4141
use CodeIgniter\Controller;
42+
use CodeIgniter\HTTP\RequestInterface;
43+
use CodeIgniter\HTTP\ResponseInterface;
44+
use Psr\Log\LoggerInterface;
4245

4346
/**
4447
* An extendable controller to provide a RESTful API for a resource.
@@ -70,7 +73,7 @@ class ResourceController extends Controller
7073

7174
//--------------------------------------------------------------------
7275

73-
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
76+
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
7477
{
7578
parent::initController($request, $response, $logger);
7679

@@ -97,7 +100,7 @@ public function initController(\CodeIgniter\HTTP\RequestInterface $request, \Cod
97100
*/
98101
public function index()
99102
{
100-
return $this->fail('Action not implemented', 501);
103+
return $this->fail(lang('RESTful.notImplemented', ['index']), 501);
101104
}
102105

103106
/**
@@ -107,7 +110,7 @@ public function index()
107110
*/
108111
public function show($id = null)
109112
{
110-
return $this->fail('Action not implemented', 501);
113+
return $this->fail(lang('RESTful.notImplemented', ['show']), 501);
111114
}
112115

113116
/**
@@ -117,7 +120,7 @@ public function show($id = null)
117120
*/
118121
public function new()
119122
{
120-
return $this->fail('Action not implemented', 501);
123+
return $this->fail(lang('RESTful.notImplemented', ['new']), 501);
121124
}
122125

123126
/**
@@ -127,7 +130,7 @@ public function new()
127130
*/
128131
public function create()
129132
{
130-
return $this->fail('Action not implemented', 501);
133+
return $this->fail(lang('RESTful.notImplemented', ['create']), 501);
131134
}
132135

133136
/**
@@ -137,7 +140,7 @@ public function create()
137140
*/
138141
public function edit($id = null)
139142
{
140-
return $this->fail('Action not implemented', 501);
143+
return $this->fail(lang('RESTful.notImplemented', ['edit']), 501);
141144
}
142145

143146
/**
@@ -147,7 +150,7 @@ public function edit($id = null)
147150
*/
148151
public function update($id = null)
149152
{
150-
return $this->fail('Action not implemented', 501);
153+
return $this->fail(lang('RESTful.notImplemented', ['update']), 501);
151154
}
152155

153156
/**
@@ -157,7 +160,7 @@ public function update($id = null)
157160
*/
158161
public function delete($id = null)
159162
{
160-
return $this->fail('Action not implemented', 501);
163+
return $this->fail(lang('RESTful.notImplemented', ['delete']), 501);
161164
}
162165

163166
//--------------------------------------------------------------------

system/RESTful/ResourcePresenter.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
use CodeIgniter\API\ResponseTrait;
4141
use CodeIgniter\Controller;
42+
use CodeIgniter\HTTP\RequestInterface;
43+
use CodeIgniter\HTTP\ResponseInterface;
44+
use Psr\Log\LoggerInterface;
4245

4346
/**
4447
* An extendable controller to help provide a UI for a resource.
@@ -60,11 +63,9 @@ class ResourcePresenter extends Controller
6063
*/
6164
protected $model = null;
6265

63-
const NOT_THERE = 'Action not implemented yet';
64-
6566
//--------------------------------------------------------------------
6667

67-
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
68+
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
6869
{
6970
parent::initController($request, $response, $logger);
7071

@@ -91,7 +92,7 @@ public function initController(\CodeIgniter\HTTP\RequestInterface $request, \Cod
9192
*/
9293
public function index()
9394
{
94-
return 'index: ' . NOT_THERE;
95+
return lang('RESTful.notImplemented', ['index']);
9596
}
9697

9798
/**
@@ -102,7 +103,7 @@ public function index()
102103
*/
103104
public function show($id = null)
104105
{
105-
return 'show: ' . NOT_THERE;
106+
return lang('RESTful.notImplemented', ['show']);
106107
}
107108

108109
/**
@@ -113,7 +114,7 @@ public function show($id = null)
113114
*/
114115
public function new()
115116
{
116-
return 'new: ' . NOT_THERE;
117+
return lang('RESTful.notImplemented', ['new']);
117118
}
118119

119120
/**
@@ -123,7 +124,7 @@ public function new()
123124
*/
124125
public function create()
125126
{
126-
return 'create: ' . NOT_THERE;
127+
return lang('RESTful.notImplemented', ['create']);
127128
}
128129

129130
/**
@@ -134,7 +135,7 @@ public function create()
134135
*/
135136
public function remove($id = null)
136137
{
137-
return 'remove: ' . NOT_THERE;
138+
return lang('RESTful.notImplemented', ['remove']);
138139
}
139140

140141
/**
@@ -145,7 +146,7 @@ public function remove($id = null)
145146
*/
146147
public function delete($id = null)
147148
{
148-
return 'delete: ' . NOT_THERE;
149+
return lang('RESTful.notImplemented', ['delete']);
149150
}
150151

151152
/**
@@ -156,7 +157,7 @@ public function delete($id = null)
156157
*/
157158
public function edit($id = null)
158159
{
159-
return 'edit: ' . NOT_THERE;
160+
return lang('RESTful.notImplemented', ['edit']);
160161
}
161162

162163
/**
@@ -167,7 +168,7 @@ public function edit($id = null)
167168
*/
168169
public function update($id = null)
169170
{
170-
return 'update: ' . NOT_THERE;
171+
return lang('RESTful.notImplemented', ['update']);
171172
}
172173

173174
//--------------------------------------------------------------------

system/Router/RouteCollection.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public function resource(string $name, array $options = null): RouteCollectionIn
893893
*
894894
* Example:
895895
*
896-
* $route->resource('photos');
896+
* $route->presenter('photos');
897897
*
898898
* // Generates the following routes:
899899
* HTTP Verb | Path | Action | Used for...
@@ -917,13 +917,13 @@ public function presenter(string $name, array $options = null): RouteCollectionI
917917
// In order to allow customization of the route the
918918
// resources are sent to, we need to have a new name
919919
// to store the values in.
920-
$new_name = ucfirst($name);
920+
$newName = ucfirst($name);
921921

922922
// If a new controller is specified, then we replace the
923923
// $name value with the name of the new controller.
924924
if (isset($options['controller']))
925925
{
926-
$new_name = ucfirst(filter_var($options['controller'], FILTER_SANITIZE_STRING));
926+
$newName = ucfirst(filter_var($options['controller'], FILTER_SANITIZE_STRING));
927927
}
928928

929929
// In order to allow customization of allowed id values
@@ -955,35 +955,35 @@ public function presenter(string $name, array $options = null): RouteCollectionI
955955

956956
if (in_array('index', $methods))
957957
{
958-
$this->get($name, $new_name . '::index', $options);
958+
$this->get($name, $newName . '::index', $options);
959959
}
960960
if (in_array('show', $methods))
961961
{
962-
$this->get($name . '/' . $id, $new_name . '::show/$1', $options);
962+
$this->get($name . '/' . $id, $newName . '::show/$1', $options);
963963
}
964964
if (in_array('new', $methods))
965965
{
966-
$this->get($name . '/new', $new_name . '::new', $options);
966+
$this->get($name . '/new', $newName . '::new', $options);
967967
}
968968
if (in_array('create', $methods))
969969
{
970-
$this->post($name, $new_name . '::create', $options);
970+
$this->post($name, $newName . '::create', $options);
971971
}
972972
if (in_array('edit', $methods))
973973
{
974-
$this->get($name . '/' . $id . '/edit', $new_name . '::edit/$1', $options);
974+
$this->get($name . '/' . $id . '/edit', $newName . '::edit/$1', $options);
975975
}
976976
if (in_array('update', $methods))
977977
{
978-
$this->post($name . '/' . $id, $new_name . '::update/$1', $options);
978+
$this->post($name . '/' . $id, $newName . '::update/$1', $options);
979979
}
980980
if (in_array('remove', $methods))
981981
{
982-
$this->get($name . '/' . $id, $new_name . '::remove/$1', $options);
982+
$this->get($name . '/' . $id, $newName . '::remove/$1', $options);
983983
}
984984
if (in_array('delete', $methods))
985985
{
986-
$this->post($name . '/' . $id, $new_name . '::delete/$1', $options);
986+
$this->post($name . '/' . $id, $newName . '::delete/$1', $options);
987987
}
988988

989989
return $this;

tests/system/RESTful/ResourceControllerTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
namespace CodeIgniter\RESTful;
33

44
use CodeIgniter\Config\Services;
5+
use CodeIgniter\HTTP\IncomingRequest;
6+
use CodeIgniter\HTTP\Response;
57
use CodeIgniter\HTTP\UserAgent;
8+
use CodeIgniter\HTTP\URI;
69
use CodeIgniter\Log\Logger;
710
use CodeIgniter\Router\RouteCollection;
811
use Config\App;
@@ -55,9 +58,9 @@ protected function setUp()
5558
parent::setUp();
5659

5760
$this->config = new App();
58-
$this->request = new \CodeIgniter\HTTP\IncomingRequest($this->config, new \CodeIgniter\HTTP\URI('https://somwhere.com'), null, new UserAgent());
59-
$this->response = new \CodeIgniter\HTTP\Response($this->config);
60-
$this->logger = \Config\Services::logger();
61+
$this->request = new IncomingRequest($this->config, new URI('https://somwhere.com'), null, new UserAgent());
62+
$this->response = new Response($this->config);
63+
$this->logger = Services::logger();
6164
$this->codeigniter = new MockCodeIgniter($this->config);
6265
}
6366

@@ -142,7 +145,7 @@ public function testIndex()
142145
$this->codeigniter->useSafeOutput(true)->run();
143146
$output = ob_get_clean();
144147

145-
$this->assertContains('Action not implemented', $output);
148+
$this->assertContains("'index' action not implemented", $output);
146149
}
147150

148151
// public function testShow()

tests/system/RESTful/ResourcePresenterFeatureTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use CodeIgniter\HTTP\UserAgent;
66
use CodeIgniter\Log\Logger;
77
use CodeIgniter\Router\RouteCollection;
8-
use CodeIgniter\Test\NakedFeatureTestCase;
8+
use CodeIgniter\Test\FeatureTestCase;
99
use Config\App;
1010
use Tests\Support\MockCodeIgniter;
1111

@@ -16,7 +16,7 @@
1616
*
1717
* @backupGlobals enabled
1818
*/
19-
class ResourcePresenterFeatureTest extends NakedFeatureTestCase
19+
class ResourcePresenterFeatureTest extends FeatureTestCase
2020
{
2121

2222
/**

0 commit comments

Comments
 (0)